diff -Nru esorex-3.13.5+ds/acinclude.m4 esorex-3.13.6+ds/acinclude.m4 --- esorex-3.13.5+ds/acinclude.m4 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/acinclude.m4 2022-04-29 16:21:07.000000000 +0000 @@ -91,12 +91,12 @@ [ AC_ARG_WITH(avcall-include, - AC_HELP_STRING([--with-avcall-include], + AS_HELP_STRING([--with-avcall-include], [location of the avcall.h header file]), esorex_with_avcall_include=$withval) AC_ARG_WITH(avcall-lib, - AC_HELP_STRING([--with-avcall-lib], + AS_HELP_STRING([--with-avcall-lib], [full path to the libavcall.a library]), esorex_with_avcall_lib=$withval) @@ -219,17 +219,17 @@ [ AC_ARG_WITH(libffi, - AC_HELP_STRING([--with-libffi], + AS_HELP_STRING([--with-libffi], [location of where libffi is installed]), esorex_with_libffi=$withval) AC_ARG_WITH(libffi-includes, - AC_HELP_STRING([--with-libffi-includes], + AS_HELP_STRING([--with-libffi-includes], [location of the libffi header files]), esorex_with_libffi_includes=$withval) AC_ARG_WITH(libffi-libs, - AC_HELP_STRING([--with-libffi-libs], + AS_HELP_STRING([--with-libffi-libs], [location of the libffi libraries]), esorex_with_libffi_libs=$withval) @@ -360,7 +360,7 @@ [Define if Python based recipes should be supported.]) AC_ARG_ENABLE(python-recipes, - AC_HELP_STRING([--enable-python-recipes], + AS_HELP_STRING([--enable-python-recipes], [enables Python based recipes [default=yes]]), esorex_enable_pyrecipes=$enableval, esorex_enable_pyrecipes=default) diff -Nru esorex-3.13.5+ds/admin/doxygen.am esorex-3.13.6+ds/admin/doxygen.am --- esorex-3.13.5+ds/admin/doxygen.am 2021-06-02 15:06:13.000000000 +0000 +++ esorex-3.13.6+ds/admin/doxygen.am 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,4 @@ DOXYGEN_BUILD_DIR = $(top_builddir) -DOXYGEN_HTML_DIR = $(top_builddir)/html -DOXYGEN_HTML_INSTDIR = $(apidocdir) if MAINTAINER_MODE @@ -8,12 +6,12 @@ doxygen: doxygen-am -doxygen-am: +doxygen-am: Doxyfile @if test -f $(DOXYGEN_BUILD_DIR)/Doxyfile; then \ echo "cd $(DOXYGEN_BUILD_DIR) && $(DOXYGEN)"; \ d=`pwd`; cd $(DOXYGEN_BUILD_DIR) && $(DOXYGEN); cd $$d; \ if test -n "$(POST_DOXYGEN_CLEANFILES)"; then \ - cd $(DOXYGEN_HTML_DIR) && rm -f $(POST_DOXYGEN_CLEANFILES); \ + cd $(DOXYGEN_BUILD_DIR)/html && rm -f $(POST_DOXYGEN_CLEANFILES); \ fi; \ else \ echo "Nothing to be done for \`$@'."; \ @@ -22,7 +20,7 @@ clean-doxygen: clean-doxygen-am clean-doxygen-am: - -rm -rf $(DOXYGEN_HTML_DIR) + -rm -rf $(DOXYGEN_BUILD_DIR)/html DOXYGEN_INSTALL_TARGETS = doxygen-am install-doxygen-generic @@ -31,38 +29,50 @@ DOXYGEN_RECURSIVE_TARGETS = install-doxygen-recursive DOXYGEN_INSTALL_TARGETS = install-doxygen-generic -doxygen-am: - endif install-doxygen: install-doxygen-recursive install-doxygen-am: $(DOXYGEN_INSTALL_TARGETS) -install-doxygen-generic: doxygen-am +install-doxygen-generic: @$(NORMAL_INSTALL) - @if test -d $(DOXYGEN_HTML_DIR); then \ - echo "$(mkinstalldirs) $(DESTDIR)$(DOXYGEN_HTML_INSTDIR)"; \ - $(mkinstalldirs) $(DESTDIR)$(DOXYGEN_HTML_INSTDIR); \ - list="`ls -1 $(DOXYGEN_HTML_DIR)`"; \ - for p in $$list; do \ - if test -f $(DOXYGEN_HTML_DIR)/$$p; then \ - echo " $(INSTALL_DATA) $(DOXYGEN_HTML_DIR)/$$p $(DESTDIR)$(DOXYGEN_HTML_INSTDIR)/$$p"; \ - $(INSTALL_DATA) $(DOXYGEN_HTML_DIR)/$$p $(DESTDIR)$(DOXYGEN_HTML_INSTDIR)/$$p; \ + @if test -d $(DOXYGEN_BUILD_DIR)/html; then \ + echo "$(mkinstalldirs) $(DESTDIR)$(apidocdir)"; \ + $(mkinstalldirs) $(DESTDIR)$(apidocdir) || exit 1; \ + basedirstrip=`echo "$(DOXYGEN_BUILD_DIR)/html" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list="`find $(DOXYGEN_BUILD_DIR)/html -type f`"; \ + docfiles="`for f in $$list; do echo $$f; done | sed -e \"s|^$$basedirstrip/||;t\"`"; \ + case $$docfiles in \ + */*) $(mkinstalldirs) `echo "$$docfiles" | \ + sed '/\//!d;s|^|$(DESTDIR)$(apidocdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for p in $$docfiles; do \ + if test -f $(DOXYGEN_BUILD_DIR)/html/$$p; then \ + echo " $(INSTALL_DATA) $(DOXYGEN_BUILD_DIR)/html/$$p $(DESTDIR)$(apidocdir)/$$p"; \ + $(INSTALL_DATA) $(DOXYGEN_BUILD_DIR)/html/$$p $(DESTDIR)$(apidocdir)/$$p; \ else if test -f $$p; then \ - echo " $(INSTALL_DATA) $$p $(DESTDIR)$(DOXYGEN_HTML_INSTDIR)/$$p"; \ - $(INSTALL_DATA) $$p $(DESTDIR)$(DOXYGEN_HTML_INSTDIR)/$$p; \ + echo " $(INSTALL_DATA) $$p $(DESTDIR)$(apidocdir)/$$p"; \ + $(INSTALL_DATA) $$p $(DESTDIR)$(apidocdir)/$$p; \ fi; fi; \ done; \ fi uninstall-doxygen: @$(NORMAL_UNINSTALL) - @if test -d $(DESTDIR)$(DOXYGEN_HTML_INSTDIR); then \ - list="`ls -1 $(DESTDIR)$(DOXYGEN_HTML_INSTDIR)`"; \ + @if test -d $(DESTDIR)$(apidocdir); then \ + list="`ls -1 $(DESTDIR)$(apidocdir)`"; \ for p in $$list; do \ - echo " rm -f $(DESTDIR)$(DOXYGEN_HTML_INSTDIR)/$$p"; \ - rm -f $(DESTDIR)$(DOXYGEN_HTML_INSTDIR)/$$p; \ - done \ + if test -d $(DESTDIR)$(apidocdir)/$$p; then \ + echo " rm -rf $(DESTDIR)$(apidocdir)/$$p"; \ + rm -rf $(DESTDIR)$(apidocdir)/$$p; \ + else \ + echo " rm -f $(DESTDIR)$(apidocdir)/$$p"; \ + rm -f $(DESTDIR)$(apidocdir)/$$p; \ + fi; \ + done; \ + else \ + echo "Nothing to be done for \`$@'."; \ fi $(DOXYGEN_RECURSIVE_TARGETS): diff -Nru esorex-3.13.5+ds/BUGS esorex-3.13.6+ds/BUGS --- esorex-3.13.5+ds/BUGS 2021-06-02 15:06:13.000000000 +0000 +++ esorex-3.13.6+ds/BUGS 2022-04-29 16:21:07.000000000 +0000 @@ -7,7 +7,7 @@ Reporting Bugs -------------- -Please report any EsoRex problems to usd-help@eso.org . +To report any EsoRex problems please submit a ticket to https://support.eso.org When reporting bugs, please indicate the package and version. For example "EsoRex 3.6.8". To determine the version of the distribution diff -Nru esorex-3.13.5+ds/configure esorex-3.13.6+ds/configure --- esorex-3.13.5+ds/configure 2021-06-02 15:06:41.000000000 +0000 +++ esorex-3.13.6+ds/configure 2022-04-29 16:21:28.000000000 +0000 @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.71 for ESO Recipe Execution Tool 3.13.5. +# Generated by GNU Autoconf 2.71 for ESO Recipe Execution Tool 3.13.6. # # Report bugs to . # @@ -625,8 +625,8 @@ # Identity of this package. PACKAGE_NAME='ESO Recipe Execution Tool' PACKAGE_TARNAME='esorex' -PACKAGE_VERSION='3.13.5' -PACKAGE_STRING='ESO Recipe Execution Tool 3.13.5' +PACKAGE_VERSION='3.13.6' +PACKAGE_STRING='ESO Recipe Execution Tool 3.13.6' PACKAGE_BUGREPORT='cpl-help@eso.org' PACKAGE_URL='' @@ -1453,7 +1453,7 @@ # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures ESO Recipe Execution Tool 3.13.5 to adapt to many kinds of systems. +\`configure' configures ESO Recipe Execution Tool 3.13.6 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1525,7 +1525,7 @@ if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of ESO Recipe Execution Tool 3.13.5:";; + short | recursive ) echo "Configuration of ESO Recipe Execution Tool 3.13.6:";; esac cat <<\_ACEOF @@ -1670,7 +1670,7 @@ test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -ESO Recipe Execution Tool configure 3.13.5 +ESO Recipe Execution Tool configure 3.13.6 generated by GNU Autoconf 2.71 Copyright (C) 2021 Free Software Foundation, Inc. @@ -2262,7 +2262,7 @@ This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by ESO Recipe Execution Tool $as_me 3.13.5, which was +It was created by ESO Recipe Execution Tool $as_me 3.13.6, which was generated by GNU Autoconf 2.71. Invocation command line was $ $0$ac_configure_args_raw @@ -3879,7 +3879,7 @@ # Define the identity of the package. PACKAGE='esorex' - VERSION='3.13.5' + VERSION='3.13.6' printf "%s\n" "#define PACKAGE \"$PACKAGE\"" >>confdefs.h @@ -20862,83 +20862,6 @@ # Checks for header files. -# Autoupdate added the next two lines to ensure that your configure -# script's behavior did not change. They are probably safe to remove. - -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 -printf %s "checking for egrep... " >&6; } -if test ${ac_cv_path_EGREP+y} -then : - printf %s "(cached) " >&6 -else $as_nop - if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 - then ac_cv_path_EGREP="$GREP -E" - else - if test -z "$EGREP"; then - ac_path_EGREP_found=false - # Loop through the user's path and test for each of PROGNAME-LIST - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin -do - IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac - for ac_prog in egrep - do - for ac_exec_ext in '' $ac_executable_extensions; do - ac_path_EGREP="$as_dir$ac_prog$ac_exec_ext" - as_fn_executable_p "$ac_path_EGREP" || continue -# Check for GNU ac_path_EGREP and select it if it is found. - # Check for GNU $ac_path_EGREP -case `"$ac_path_EGREP" --version 2>&1` in -*GNU*) - ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; -*) - ac_count=0 - printf %s 0123456789 >"conftest.in" - while : - do - cat "conftest.in" "conftest.in" >"conftest.tmp" - mv "conftest.tmp" "conftest.in" - cp "conftest.in" "conftest.nl" - printf "%s\n" 'EGREP' >> "conftest.nl" - "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break - diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break - as_fn_arith $ac_count + 1 && ac_count=$as_val - if test $ac_count -gt ${ac_path_EGREP_max-0}; then - # Best one so far, save it but keep looking for a better one - ac_cv_path_EGREP="$ac_path_EGREP" - ac_path_EGREP_max=$ac_count - fi - # 10*(2^10) chars as input seems more than enough - test $ac_count -gt 10 && break - done - rm -f conftest.in conftest.tmp conftest.nl conftest.out;; -esac - - $ac_path_EGREP_found && break 3 - done - done - done -IFS=$as_save_IFS - if test -z "$ac_cv_path_EGREP"; then - as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 - fi -else - ac_cv_path_EGREP=$EGREP -fi - - fi -fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 -printf "%s\n" "$ac_cv_path_EGREP" >&6; } - EGREP="$ac_cv_path_EGREP" - - - ac_header_dirent=no for ac_hdr in dirent.h sys/ndir.h sys/dir.h ndir.h; do as_ac_Header=`printf "%s\n" "ac_cv_header_dirent_$ac_hdr" | $as_tr_sh` @@ -23330,7 +23253,7 @@ # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by ESO Recipe Execution Tool $as_me 3.13.5, which was +This file was extended by ESO Recipe Execution Tool $as_me 3.13.6, which was generated by GNU Autoconf 2.71. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -23398,7 +23321,7 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config='$ac_cs_config_escaped' ac_cs_version="\\ -ESO Recipe Execution Tool config.status 3.13.5 +ESO Recipe Execution Tool config.status 3.13.6 configured by $0, generated by GNU Autoconf 2.71, with options \\"\$ac_cs_config\\" diff -Nru esorex-3.13.5+ds/configure.ac esorex-3.13.6+ds/configure.ac --- esorex-3.13.5+ds/configure.ac 2021-06-02 15:06:13.000000000 +0000 +++ esorex-3.13.6+ds/configure.ac 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ # Process this file with autoconf to produce a configure script. -AC_INIT([ESO Recipe Execution Tool], [3.13.5], [cpl-help@eso.org], [esorex]) +AC_INIT([ESO Recipe Execution Tool], [3.13.6], [cpl-help@eso.org], [esorex]) AC_PREREQ([2.59]) LT_PREREQ([2.2.6]) @@ -52,7 +52,6 @@ ESOREX_LIBAVCALL_OR_LIBFFI # Checks for header files. -AC_HEADER_STDC AC_HEADER_DIRENT AC_HEADER_STAT AC_CHECK_HEADERS([fcntl.h stdlib.h string.h unistd.h sys/stat.h sys/types.h pwd.h]) diff -Nru esorex-3.13.5+ds/debian/changelog esorex-3.13.6+ds/debian/changelog --- esorex-3.13.5+ds/debian/changelog 2021-10-04 09:21:42.000000000 +0000 +++ esorex-3.13.6+ds/debian/changelog 2022-05-12 11:52:59.000000000 +0000 @@ -1,3 +1,16 @@ +esorex (3.13.6+ds-1) unstable; urgency=medium + + [ Debian Janitor ] + * Set field Upstream-Contact in debian/copyright. + * Remove obsolete fields Contact, Name from d/u/metadata + * Update standards version to 4.6.0, no changes needed. + + [ Ole Streicher ] + * New upstream version 3.13.6+ds + * Rediff patches + + -- Ole Streicher Thu, 12 May 2022 13:52:59 +0200 + esorex (3.13.5+ds-2) unstable; urgency=medium * Temporarily disable python support (Closes: #995044) diff -Nru esorex-3.13.5+ds/debian/control esorex-3.13.6+ds/debian/control --- esorex-3.13.5+ds/debian/control 2021-10-04 09:12:50.000000000 +0000 +++ esorex-3.13.6+ds/debian/control 2022-05-12 11:47:40.000000000 +0000 @@ -10,7 +10,7 @@ libffi-dev, libltdl-dev, wcslib-dev -Standards-Version: 4.5.1 +Standards-Version: 4.6.0 Vcs-Browser: https://salsa.debian.org/debian-astro-team/esorex Vcs-Git: https://salsa.debian.org/debian-astro-team/esorex.git Homepage: https://www.eso.org/sci/software/cpl/esorex.html diff -Nru esorex-3.13.5+ds/debian/copyright esorex-3.13.6+ds/debian/copyright --- esorex-3.13.5+ds/debian/copyright 2021-02-10 15:04:24.000000000 +0000 +++ esorex-3.13.6+ds/debian/copyright 2022-05-12 11:52:33.000000000 +0000 @@ -6,6 +6,7 @@ Neil Ferguson , Ralf Palsa $log_file 2>&1 @@ -50,17 +50,17 @@ 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/er_json.c b/src/er_json.c -index 40ffccd..8cd9954 100644 +index 8a17ff0..6bb1b42 100644 --- a/src/er_json.c +++ b/src/er_json.c -@@ -3713,8 +3713,8 @@ static cpl_parameter * json_to_parameter(const er_json_node * parsetree, - || type == CPL_TYPE_STRING); +@@ -3627,8 +3627,8 @@ json_to_parameter(const er_json_node *parsetree, const char *json) + type == CPL_TYPE_STRING); break; } - if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, nargs, &ffi_type_pointer, -- argtypes) +- argtypes) == FFI_OK) { + if (ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 4, nargs, -+ &ffi_type_pointer, argtypes) - == FFI_OK) - { - ffi_call(&cif, (void (*)(void))&cpl_parameter_new_enum, ¶m, ++ &ffi_type_pointer, argtypes) == FFI_OK) { + ffi_call(&cif, (void (*)(void)) & cpl_parameter_new_enum, + ¶m, (void **)args); + } diff -Nru esorex-3.13.5+ds/debian/patches/Generate-a-manpage-for-esorex.patch esorex-3.13.6+ds/debian/patches/Generate-a-manpage-for-esorex.patch --- esorex-3.13.5+ds/debian/patches/Generate-a-manpage-for-esorex.patch 2021-10-04 09:12:50.000000000 +0000 +++ esorex-3.13.6+ds/debian/patches/Generate-a-manpage-for-esorex.patch 2022-05-12 11:52:33.000000000 +0000 @@ -9,7 +9,7 @@ create mode 100644 src/esorex_create_man.sh diff --git a/src/Makefile.am b/src/Makefile.am -index f246186..1d89099 100644 +index 171e3c5..5ff8515 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -98,3 +98,8 @@ esorex_LDFLAGS = $(CPL_LDFLAGS) $(LIBLTDL) diff -Nru esorex-3.13.5+ds/debian/patches/Set-the-default-plugin-path.patch esorex-3.13.6+ds/debian/patches/Set-the-default-plugin-path.patch --- esorex-3.13.5+ds/debian/patches/Set-the-default-plugin-path.patch 2021-10-04 09:18:03.000000000 +0000 +++ esorex-3.13.6+ds/debian/patches/Set-the-default-plugin-path.patch 2022-05-12 11:52:33.000000000 +0000 @@ -10,7 +10,7 @@ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 -index 16268f0..10c4fca 100644 +index 27df1e4..3dd9a01 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -36,7 +36,10 @@ AC_DEFUN([ESOREX_SET_PATHS], diff -Nru esorex-3.13.5+ds/debian/upstream/metadata esorex-3.13.6+ds/debian/upstream/metadata --- esorex-3.13.5+ds/debian/upstream/metadata 2020-11-28 16:20:08.000000000 +0000 +++ esorex-3.13.6+ds/debian/upstream/metadata 2022-05-12 11:01:53.000000000 +0000 @@ -1,5 +1,3 @@ ASCL-Id: 1504.003 Bug-Submit: cpl-help@eso.org -Contact: cpl-help@eso.org FAQ: https://www.eso.org/sci/software/cpl/faq.html -Name: EsoRex diff -Nru esorex-3.13.5+ds/Doxyfile.in esorex-3.13.6+ds/Doxyfile.in --- esorex-3.13.5+ds/Doxyfile.in 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/Doxyfile.in 2022-04-29 16:21:07.000000000 +0000 @@ -1,4 +1,4 @@ -# Doxyfile 1.8.10 +# Doxyfile 1.8.20 #--------------------------------------------------------------------------- # Project related configuration options @@ -12,6 +12,7 @@ CREATE_SUBDIRS = NO ALLOW_UNICODE_NAMES = NO OUTPUT_LANGUAGE = English +OUTPUT_TEXT_DIRECTION = None BRIEF_MEMBER_DESC = YES REPEAT_BRIEF = YES ABBREVIATE_BRIEF = @@ -22,19 +23,22 @@ STRIP_FROM_INC_PATH = SHORT_NAMES = NO JAVADOC_AUTOBRIEF = NO +JAVADOC_BANNER = NO QT_AUTOBRIEF = NO MULTILINE_CPP_IS_BRIEF = NO +PYTHON_DOCSTRING = YES INHERIT_DOCS = YES SEPARATE_MEMBER_PAGES = NO TAB_SIZE = 4 ALIASES = -TCL_SUBST = OPTIMIZE_OUTPUT_FOR_C = NO OPTIMIZE_OUTPUT_JAVA = NO OPTIMIZE_FOR_FORTRAN = NO OPTIMIZE_OUTPUT_VHDL = NO +OPTIMIZE_OUTPUT_SLICE = NO EXTENSION_MAPPING = MARKDOWN_SUPPORT = YES +TOC_INCLUDE_HEADINGS = 5 AUTOLINK_SUPPORT = YES BUILTIN_STL_SUPPORT = NO CPP_CLI_SUPPORT = NO @@ -47,11 +51,13 @@ INLINE_SIMPLE_STRUCTS = NO TYPEDEF_HIDES_STRUCT = NO LOOKUP_CACHE_SIZE = 0 +NUM_PROC_THREADS = 1 #--------------------------------------------------------------------------- # Build related configuration options #--------------------------------------------------------------------------- EXTRACT_ALL = NO EXTRACT_PRIVATE = NO +EXTRACT_PRIV_VIRTUAL = NO EXTRACT_PACKAGE = NO EXTRACT_STATIC = NO EXTRACT_LOCAL_CLASSES = YES @@ -95,6 +101,7 @@ WARN_IF_UNDOCUMENTED = YES WARN_IF_DOC_ERROR = YES WARN_NO_PARAMDOC = NO +WARN_AS_ERROR = NO WARN_FORMAT = WARN_LOGFILE = #--------------------------------------------------------------------------- @@ -132,6 +139,9 @@ SOURCE_TOOLTIPS = YES USE_HTAGS = NO VERBATIM_HEADERS = NO +CLANG_ASSISTED_PARSING = NO +CLANG_OPTIONS = +CLANG_DATABASE_PATH = #--------------------------------------------------------------------------- # Configuration options related to the alphabetical class index #--------------------------------------------------------------------------- @@ -153,6 +163,7 @@ HTML_COLORSTYLE_SAT = 100 HTML_COLORSTYLE_GAMMA = 80 HTML_TIMESTAMP = NO +HTML_DYNAMIC_MENUS = YES HTML_DYNAMIC_SECTIONS = NO HTML_INDEX_NUM_ENTRIES = 100 GENERATE_DOCSET = NO @@ -182,8 +193,10 @@ ENUM_VALUES_PER_LINE = 1 TREEVIEW_WIDTH = 250 EXT_LINKS_IN_WINDOW = NO +HTML_FORMULA_FORMAT = png FORMULA_FONTSIZE = 10 FORMULA_TRANSPARENT = YES +FORMULA_MACROFILE = USE_MATHJAX = NO MATHJAX_FORMAT = HTML-CSS MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest @@ -203,8 +216,9 @@ LATEX_OUTPUT = latex LATEX_CMD_NAME = latex MAKEINDEX_CMD_NAME = makeindex +LATEX_MAKEINDEX_CMD = makeindex COMPACT_LATEX = YES -PAPER_TYPE = a4wide +PAPER_TYPE = a4 EXTRA_PACKAGES = times LATEX_HEADER = LATEX_FOOTER = @@ -216,6 +230,8 @@ LATEX_HIDE_INDICES = NO LATEX_SOURCE_CODE = NO LATEX_BIB_STYLE = plain +LATEX_TIMESTAMP = NO +LATEX_EMOJI_DIRECTORY = #--------------------------------------------------------------------------- # Configuration options related to the RTF output #--------------------------------------------------------------------------- @@ -240,6 +256,7 @@ GENERATE_XML = NO XML_OUTPUT = xml XML_PROGRAMLISTING = YES +XML_NS_MEMB_FILE_SCOPE = NO #--------------------------------------------------------------------------- # Configuration options related to the DOCBOOK output #--------------------------------------------------------------------------- @@ -279,12 +296,10 @@ ALLEXTERNALS = NO EXTERNAL_GROUPS = YES EXTERNAL_PAGES = YES -PERL_PATH = #--------------------------------------------------------------------------- # Configuration options related to the dot tool #--------------------------------------------------------------------------- CLASS_DIAGRAMS = YES -MSCGEN_PATH = DIA_PATH = HIDE_UNDOC_RELATIONS = YES HAVE_DOT = NO @@ -311,6 +326,7 @@ MSCFILE_DIRS = DIAFILE_DIRS = PLANTUML_JAR_PATH = +PLANTUML_CFG_FILE = PLANTUML_INCLUDE_PATH = DOT_GRAPH_MAX_NODES = 50 MAX_DOT_GRAPH_DEPTH = 0 diff -Nru esorex-3.13.5+ds/etc/Makefile.am esorex-3.13.6+ds/etc/Makefile.am --- esorex-3.13.5+ds/etc/Makefile.am 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/etc/Makefile.am 2022-04-29 16:21:07.000000000 +0000 @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in ## This file is part of the ESO Recipe Execution Tool -## Copyright (C) 2002-2017 European Southern Observatory +## Copyright (C) 2002-2022 European Southern Observatory ## 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 diff -Nru esorex-3.13.5+ds/Makefile.am esorex-3.13.6+ds/Makefile.am --- esorex-3.13.5+ds/Makefile.am 2021-06-02 15:06:13.000000000 +0000 +++ esorex-3.13.6+ds/Makefile.am 2022-04-29 16:21:07.000000000 +0000 @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in ## This file is part of the ESO Recipe Execution Tool -## Copyright (C) 2002-2017 European Southern Observatory +## Copyright (C) 2002-2022 European Southern Observatory ## 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 diff -Nru esorex-3.13.5+ds/Makefile.in esorex-3.13.6+ds/Makefile.in --- esorex-3.13.5+ds/Makefile.in 2021-06-02 15:06:42.000000000 +0000 +++ esorex-3.13.6+ds/Makefile.in 2022-04-29 16:21:29.000000000 +0000 @@ -402,8 +402,6 @@ @MAINTAINER_MODE_TRUE@ $(top_builddir)/config.log $(top_builddir)/config.status DOXYGEN_BUILD_DIR = $(top_builddir) -DOXYGEN_HTML_DIR = $(top_builddir)/html -DOXYGEN_HTML_INSTDIR = $(apidocdir) @MAINTAINER_MODE_FALSE@DOXYGEN_RECURSIVE_TARGETS = install-doxygen-recursive @MAINTAINER_MODE_TRUE@DOXYGEN_RECURSIVE_TARGETS = install-doxygen-recursive @MAINTAINER_MODE_FALSE@DOXYGEN_INSTALL_TARGETS = install-doxygen-generic @@ -927,12 +925,12 @@ @MAINTAINER_MODE_TRUE@doxygen: doxygen-am -@MAINTAINER_MODE_TRUE@doxygen-am: +@MAINTAINER_MODE_TRUE@doxygen-am: Doxyfile @MAINTAINER_MODE_TRUE@ @if test -f $(DOXYGEN_BUILD_DIR)/Doxyfile; then \ @MAINTAINER_MODE_TRUE@ echo "cd $(DOXYGEN_BUILD_DIR) && $(DOXYGEN)"; \ @MAINTAINER_MODE_TRUE@ d=`pwd`; cd $(DOXYGEN_BUILD_DIR) && $(DOXYGEN); cd $$d; \ @MAINTAINER_MODE_TRUE@ if test -n "$(POST_DOXYGEN_CLEANFILES)"; then \ -@MAINTAINER_MODE_TRUE@ cd $(DOXYGEN_HTML_DIR) && rm -f $(POST_DOXYGEN_CLEANFILES); \ +@MAINTAINER_MODE_TRUE@ cd $(DOXYGEN_BUILD_DIR)/html && rm -f $(POST_DOXYGEN_CLEANFILES); \ @MAINTAINER_MODE_TRUE@ fi; \ @MAINTAINER_MODE_TRUE@ else \ @MAINTAINER_MODE_TRUE@ echo "Nothing to be done for \`$@'."; \ @@ -941,38 +939,50 @@ @MAINTAINER_MODE_TRUE@clean-doxygen: clean-doxygen-am @MAINTAINER_MODE_TRUE@clean-doxygen-am: -@MAINTAINER_MODE_TRUE@ -rm -rf $(DOXYGEN_HTML_DIR) - -@MAINTAINER_MODE_FALSE@doxygen-am: +@MAINTAINER_MODE_TRUE@ -rm -rf $(DOXYGEN_BUILD_DIR)/html install-doxygen: install-doxygen-recursive install-doxygen-am: $(DOXYGEN_INSTALL_TARGETS) -install-doxygen-generic: doxygen-am +install-doxygen-generic: @$(NORMAL_INSTALL) - @if test -d $(DOXYGEN_HTML_DIR); then \ - echo "$(mkinstalldirs) $(DESTDIR)$(DOXYGEN_HTML_INSTDIR)"; \ - $(mkinstalldirs) $(DESTDIR)$(DOXYGEN_HTML_INSTDIR); \ - list="`ls -1 $(DOXYGEN_HTML_DIR)`"; \ - for p in $$list; do \ - if test -f $(DOXYGEN_HTML_DIR)/$$p; then \ - echo " $(INSTALL_DATA) $(DOXYGEN_HTML_DIR)/$$p $(DESTDIR)$(DOXYGEN_HTML_INSTDIR)/$$p"; \ - $(INSTALL_DATA) $(DOXYGEN_HTML_DIR)/$$p $(DESTDIR)$(DOXYGEN_HTML_INSTDIR)/$$p; \ + @if test -d $(DOXYGEN_BUILD_DIR)/html; then \ + echo "$(mkinstalldirs) $(DESTDIR)$(apidocdir)"; \ + $(mkinstalldirs) $(DESTDIR)$(apidocdir) || exit 1; \ + basedirstrip=`echo "$(DOXYGEN_BUILD_DIR)/html" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list="`find $(DOXYGEN_BUILD_DIR)/html -type f`"; \ + docfiles="`for f in $$list; do echo $$f; done | sed -e \"s|^$$basedirstrip/||;t\"`"; \ + case $$docfiles in \ + */*) $(mkinstalldirs) `echo "$$docfiles" | \ + sed '/\//!d;s|^|$(DESTDIR)$(apidocdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for p in $$docfiles; do \ + if test -f $(DOXYGEN_BUILD_DIR)/html/$$p; then \ + echo " $(INSTALL_DATA) $(DOXYGEN_BUILD_DIR)/html/$$p $(DESTDIR)$(apidocdir)/$$p"; \ + $(INSTALL_DATA) $(DOXYGEN_BUILD_DIR)/html/$$p $(DESTDIR)$(apidocdir)/$$p; \ else if test -f $$p; then \ - echo " $(INSTALL_DATA) $$p $(DESTDIR)$(DOXYGEN_HTML_INSTDIR)/$$p"; \ - $(INSTALL_DATA) $$p $(DESTDIR)$(DOXYGEN_HTML_INSTDIR)/$$p; \ + echo " $(INSTALL_DATA) $$p $(DESTDIR)$(apidocdir)/$$p"; \ + $(INSTALL_DATA) $$p $(DESTDIR)$(apidocdir)/$$p; \ fi; fi; \ done; \ fi uninstall-doxygen: @$(NORMAL_UNINSTALL) - @if test -d $(DESTDIR)$(DOXYGEN_HTML_INSTDIR); then \ - list="`ls -1 $(DESTDIR)$(DOXYGEN_HTML_INSTDIR)`"; \ + @if test -d $(DESTDIR)$(apidocdir); then \ + list="`ls -1 $(DESTDIR)$(apidocdir)`"; \ for p in $$list; do \ - echo " rm -f $(DESTDIR)$(DOXYGEN_HTML_INSTDIR)/$$p"; \ - rm -f $(DESTDIR)$(DOXYGEN_HTML_INSTDIR)/$$p; \ - done \ + if test -d $(DESTDIR)$(apidocdir)/$$p; then \ + echo " rm -rf $(DESTDIR)$(apidocdir)/$$p"; \ + rm -rf $(DESTDIR)$(apidocdir)/$$p; \ + else \ + echo " rm -f $(DESTDIR)$(apidocdir)/$$p"; \ + rm -f $(DESTDIR)$(apidocdir)/$$p; \ + fi; \ + done; \ + else \ + echo "Nothing to be done for \`$@'."; \ fi $(DOXYGEN_RECURSIVE_TARGETS): diff -Nru esorex-3.13.5+ds/README esorex-3.13.6+ds/README --- esorex-3.13.5+ds/README 2021-06-02 15:06:13.000000000 +0000 +++ esorex-3.13.6+ds/README 2022-04-29 16:21:07.000000000 +0000 @@ -3,7 +3,7 @@ About EsoRex ------------- -This is version 3.13.5 of the EsoRex application. This package includes +This is version 3.13.6 of the EsoRex application. This package includes source files to build the "esorex" executable, which allows the running of Common Pipeline Library (CPL) plugins. Also included is the documentation and the installation procedures. diff -Nru esorex-3.13.5+ds/src/er_fileutils.c esorex-3.13.6+ds/src/er_fileutils.c --- esorex-3.13.5+ds/src/er_fileutils.c 2021-06-02 15:06:13.000000000 +0000 +++ esorex-3.13.6+ds/src/er_fileutils.c 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 European Southern Observatory * * 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 @@ -44,9 +44,9 @@ #include "er_plugin.h" #include "er_fileutils.h" -#define DEV_BLOCKSIZE 4096 +#define DEV_BLOCKSIZE 4096 -#define Xspace(x) (x == ' ') || (x == '\t') || (x == '\n') +#define Xspace(x) (x == ' ') || (x == '\t') || (x == '\n') /** @@ -76,40 +76,41 @@ */ /**********************************************************************/ -char *er_fileutils_env_replace (const char *path) +char * +er_fileutils_env_replace(const char *path) { - static char expanded_path[PATHSET_MAX + 1]; char tpath[PATHSET_MAX + 1]; wordexp_t pwordexp; - (void) strncpy (expanded_path, path, PATHSET_MAX); + (void)strncpy(expanded_path, path, PATHSET_MAX); /* Perform tilde and environment variable expansion */ - if (wordexp (path, &pwordexp, WRDE_NOCMD | WRDE_UNDEF) != 0) - { - cpl_msg_warning (er_func, "Unable to expand path '%s'\n", path); + if (wordexp(path, &pwordexp, WRDE_NOCMD | WRDE_UNDEF) != 0) { + cpl_msg_warning(er_func, "Unable to expand path '%s'\n", path); - if (pwordexp.we_wordc > 0) wordfree (&pwordexp); + if (pwordexp.we_wordc > 0) + wordfree(&pwordexp); return expanded_path; } - if (!pwordexp.we_wordv[0] || strlen (pwordexp.we_wordv[0]) > PATHSET_MAX) - { - cpl_msg_warning (er_func, "Buffer overflow while expanding " - "path '%s'\n", path); - wordfree (&pwordexp); + if (!pwordexp.we_wordv[0] || strlen(pwordexp.we_wordv[0]) > PATHSET_MAX) { + cpl_msg_warning(er_func, + "Buffer overflow while expanding " + "path '%s'\n", + path); + wordfree(&pwordexp); return expanded_path; } - (void) strcpy (expanded_path, pwordexp.we_wordv[0]); - wordfree (&pwordexp); + (void)strcpy(expanded_path, pwordexp.we_wordv[0]); + wordfree(&pwordexp); /* Return a pointer to the amended (if at all) string */ @@ -144,90 +145,86 @@ */ /**********************************************************************/ -const char *er_fileutils_tilde_replace (const char * name) +const char * +er_fileutils_tilde_replace(const char *name) { static char str[PATHSET_MAX]; char *marker, *cpp; - int len, lname; + int len, lname; - if (name == NULL) return NULL; + if (name == NULL) + return NULL; - lname = (int) strlen(name); + lname = (int)strlen(name); /* Only do this, if we start with a tilde (~) */ - if (*name != '~') - { - if (lname > (PATHSET_MAX-1)) - { + if (*name != '~') { + if (lname > (PATHSET_MAX - 1)) { cpl_msg_error(er_func, "Buffer overflow in filename '%s' - fatal error", name); - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); } return (name); } - else - { /* get HOME env. var., if we start with a tilde */ - cpp = getenv ("HOME"); - if (cpp == NULL) - { + else { /* get HOME env. var., if we start with a tilde */ + cpp = getenv("HOME"); + if (cpp == NULL) { cpl_msg_error(er_func, "Env. variable HOME not set, could not replace `~'"); - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); } - len = (int) strlen(cpp); - if (len > (PATHSET_MAX-1)) - { - cpl_msg_error (er_func, - "Buffer overflow in filename '%s' - fatal error", - name); - exit (EXIT_FAILURE); + len = (int)strlen(cpp); + if (len > (PATHSET_MAX - 1)) { + cpl_msg_error(er_func, + "Buffer overflow in filename '%s' - fatal error", + name); + exit(EXIT_FAILURE); } - (void) strcpy (str,cpp); + (void)strcpy(str, cpp); - len += lname; /* +1 for \0 */ - if (len > PATHSET_MAX) /* -1 for (name+1) below */ + len += lname; /* +1 for \0 */ + if (len > PATHSET_MAX) /* -1 for (name+1) below */ { cpl_msg_error(er_func, "Buffer overflow in filename '%s' - fatal error", name); - exit (EXIT_FAILURE); + exit(EXIT_FAILURE); } - (void) strcat (str, name + 1); + (void)strcat(str, name + 1); } /* Remove any multiple slashes */ - marker = strstr (str, "//"); - while (marker != NULL) - { - memmove (marker, marker + 1, strlen (marker)); - marker = strstr (str, "//"); + marker = strstr(str, "//"); + while (marker != NULL) { + memmove(marker, marker + 1, strlen(marker)); + marker = strstr(str, "//"); } /* Remove any trailing slashes */ - marker = str - 1 + (int) strlen(str); /* last char of `str' */ - if ((*marker) == '/') *marker = '\0'; + marker = str - 1 + (int)strlen(str); /* last char of `str' */ + if ((*marker) == '/') + *marker = '\0'; #ifdef HAVE_WORDEXP - return (er_fileutils_env_replace (str)); + return (er_fileutils_env_replace(str)); #else return (str); #endif - -} +} /**********************************************************************/ @@ -252,29 +249,29 @@ */ /**********************************************************************/ -const char *er_fileutils_dot_replace (const char * name) +const char * +er_fileutils_dot_replace(const char *name) { static char str[PATHSET_MAX]; - char *cpp; + char *cpp; - int len, lname; + int len, lname; - if (name == NULL) return NULL; + if (name == NULL) + return NULL; - lname = (int) strlen(name); + lname = (int)strlen(name); /* if we don't start with a dot (.) just pass the name on */ - if (*name != '.') - { - if (lname > (PATHSET_MAX-1)) - { - cpl_msg_error (er_func, - "Buffer overflow in filename '%s' - fatal error", - name); - exit (EXIT_FAILURE); + if (*name != '.') { + if (lname > (PATHSET_MAX - 1)) { + cpl_msg_error(er_func, + "Buffer overflow in filename '%s' - fatal error", + name); + exit(EXIT_FAILURE); } return (name); @@ -285,43 +282,40 @@ cpp = getcwd(str, PATHSET_MAX); - if (cpp == NULL) - { + if (cpp == NULL) { cpl_msg_error(er_func, "Buffer overflow in filename '%s' - fatal error", name); exit(EXIT_FAILURE); } - len = (int) strlen(cpp); + len = (int)strlen(cpp); /* Handle the ".." case (add a "/." as the "." replacement) */ - if (*(name + 1) == '.') - { - if ((len+2) > (PATHSET_MAX-1)) - { - cpl_msg_error (er_func, - "Buffer overflow in filename '%s' - fatal error", - name); - exit (EXIT_FAILURE); + if (*(name + 1) == '.') { + if ((len + 2) > (PATHSET_MAX - 1)) { + cpl_msg_error(er_func, + "Buffer overflow in filename '%s' - fatal error", + name); + exit(EXIT_FAILURE); } - (void) strcat (str, "/."); + (void)strcat(str, "/."); len += 2; } - len += lname; /* +1 for \0 */ - if (len > PATHSET_MAX) /* -1 for (name+1) below */ + len += lname; /* +1 for \0 */ + if (len > PATHSET_MAX) /* -1 for (name+1) below */ { - cpl_msg_error (er_func, "Buffer overflow in filename '%s'", name); - cpl_msg_error (er_func, "Fatal error replacing current working " - "directory symbol due to buffer overflow"); - exit (EXIT_FAILURE); + cpl_msg_error(er_func, "Buffer overflow in filename '%s'", name); + cpl_msg_error(er_func, "Fatal error replacing current working " + "directory symbol due to buffer overflow"); + exit(EXIT_FAILURE); } - (void) strcat(str, name + 1); /* Add the rest of the file name */ + (void)strcat(str, name + 1); /* Add the rest of the file name */ return (str); -} +} /**********************************************************************/ @@ -335,24 +329,23 @@ */ /**********************************************************************/ -int fileutils_directory_exists (const char * directory_name) +int +fileutils_directory_exists(const char *directory_name) { DIR *dp; - if (directory_name != NULL) - { /* no need to save the pointer, here! */ - dp = opendir (er_fileutils_tilde_replace (directory_name)); - if (dp != NULL) - { - (void) closedir (dp); - return 1; /* that's TRUE */ + if (directory_name != NULL) { /* no need to save the pointer, here! */ + dp = opendir(er_fileutils_tilde_replace(directory_name)); + if (dp != NULL) { + (void)closedir(dp); + return 1; /* that's TRUE */ } } - return 0; /* that's FALSE */ -} + return 0; /* that's FALSE */ +} /**********************************************************************/ @@ -366,7 +359,8 @@ */ /**********************************************************************/ -int fileutils_file_exists (const char * file_name) +int +fileutils_file_exists(const char *file_name) { int file_descriptor; @@ -374,20 +368,19 @@ const char *resname; - if (file_name != NULL) - { /* no need to save the pointer, here! */ - resname = er_fileutils_dot_replace (er_fileutils_tilde_replace (file_name)); - - file_descriptor = open (resname, O_RDONLY); - if (file_descriptor > -1) - { - (void) close (file_descriptor); + if (file_name != NULL) { /* no need to save the pointer, here! */ + resname = + er_fileutils_dot_replace(er_fileutils_tilde_replace(file_name)); + + file_descriptor = open(resname, O_RDONLY); + if (file_descriptor > -1) { + (void)close(file_descriptor); return 1; } } - return 0; /* that's FALSE */ -} + return 0; /* that's FALSE */ +} /**********************************************************************/ @@ -403,7 +396,8 @@ */ /**********************************************************************/ -char *fileutils_create_fqfname (char * dir_name, char * file_name) +char * +fileutils_create_fqfname(char *dir_name, char *file_name) { char *fqfn = NULL; @@ -412,26 +406,29 @@ int ldn = 0, lfn = 0, lextra = 2; - if (file_name == NULL) return NULL; + if (file_name == NULL) + return NULL; - if (dir_name != NULL) - { - ldn = (int) strlen (dir_name); - if (dir_name[ldn] == '/') lextra = 1; - } - - lfn = (int) strlen (file_name); - n = sizeof (char) * (ldn + lfn + lextra); - fqfn = (char *) cpl_malloc ((size_t) n); - if (fqfn == NULL) return NULL; - - (void) strcpy (fqfn, dir_name); - if (lextra == 2) (void) strcat (fqfn, "/"); - (void) strcat (fqfn, file_name); + if (dir_name != NULL) { + ldn = (int)strlen(dir_name); + if (dir_name[ldn] == '/') + lextra = 1; + } + + lfn = (int)strlen(file_name); + n = sizeof(char) * (ldn + lfn + lextra); + fqfn = (char *)cpl_malloc((size_t)n); + if (fqfn == NULL) + return NULL; + + (void)strcpy(fqfn, dir_name); + if (lextra == 2) + (void)strcat(fqfn, "/"); + (void)strcat(fqfn, file_name); return fqfn; -} /* End of fileutils_create_fqfname() */ +} /* End of fileutils_create_fqfname() */ /**********************************************************************/ @@ -445,36 +442,38 @@ */ /**********************************************************************/ -char *fileutils_fqfname_filename (const char * path) +char * +fileutils_fqfname_filename(const char *path) { - char *fname; + char *fname; const char *pc; int len, j; - if (path == NULL) return NULL; + if (path == NULL) + return NULL; - len = (int) strlen (path); + len = (int)strlen(path); j = len; pc = path + len; - while ((j >= 0) && (*pc != '/')) - { + while ((j >= 0) && (*pc != '/')) { pc--; j--; } - fname = (char *) cpl_calloc ((size_t) (len - j), (size_t) sizeof (char)); - if (fname == NULL) return NULL; + fname = (char *)cpl_calloc((size_t)(len - j), (size_t)sizeof(char)); + if (fname == NULL) + return NULL; - (void) strncpy (fname, &path[j + 1], (size_t) (len-j-1)); + (void)strncpy(fname, &path[j + 1], (size_t)(len - j - 1)); return fname; -} /* End of fileutils_fqfname_filename() */ +} /* End of fileutils_fqfname_filename() */ /**********************************************************************/ @@ -488,36 +487,37 @@ */ /**********************************************************************/ -char *fileutils_fqfname_dirname (const char * path) +char * +fileutils_fqfname_dirname(const char *path) { - char *dname; + char *dname; const char *pc; int len, j; - if (path == NULL) return NULL; + if (path == NULL) + return NULL; - len = (int) strlen (path); + len = (int)strlen(path); j = len; pc = path + len; - while ((j >= 0) && (*pc != '/')) - { + while ((j >= 0) && (*pc != '/')) { pc--; j--; } - dname = (char *) cpl_calloc ((size_t) (j+1), (size_t) sizeof (char)); - if (dname == NULL) return NULL; + dname = (char *)cpl_calloc((size_t)(j + 1), (size_t)sizeof(char)); + if (dname == NULL) + return NULL; - (void) strncpy (dname, path, (size_t) j); + (void)strncpy(dname, path, (size_t)j); return dname; - -} +} /* @@ -542,7 +542,8 @@ * returns. */ -int fileutils_copy (const char * srcpath, const char * dstpath) +int +fileutils_copy(const char *srcpath, const char *dstpath) { char *buf; @@ -555,72 +556,64 @@ struct stat sb, db; - if ((stat(srcpath,&sb) == 0) && (stat(dstpath,&db) == 0)) - { + if ((stat(srcpath, &sb) == 0) && (stat(dstpath, &db) == 0)) { if (sb.st_ino == db.st_ino) - return 99; /* if inodes are the same we are done already... */ + return 99; /* if inodes are the same we are done already... */ } - if ((src = open (srcpath, O_RDONLY)) == -1) return (-1); + if ((src = open(srcpath, O_RDONLY)) == -1) + return (-1); - if ((fstat (src, &sb) == -1) || (!S_ISREG (sb.st_mode))) - { - (void) close (src); + if ((fstat(src, &sb) == -1) || (!S_ISREG(sb.st_mode))) { + (void)close(src); return -2; } - if ((dst = open (dstpath, O_CREAT | O_WRONLY | O_TRUNC, sb.st_mode)) == -1) - { - (void) close (src); + if ((dst = open(dstpath, O_CREAT | O_WRONLY | O_TRUNC, sb.st_mode)) == -1) { + (void)close(src); return -3; } - if ((fstat (dst, &db) == -1) || (!S_ISREG (db.st_mode))) - { - (void) close (src); - (void) close (dst); - (void) unlink (dstpath); + if ((fstat(dst, &db) == -1) || (!S_ISREG(db.st_mode))) { + (void)close(src); + (void)close(dst); + (void)unlink(dstpath); return -4; } #ifdef HAVE_ST_BLKSIZE blksize = db.st_blksize; #else -# ifdef DEV_BSIZE +#ifdef DEV_BSIZE blksize = DEV_BSIZE; -# endif +#endif #endif - if ((buf = (char *) cpl_malloc ((size_t)blksize)) == NULL) - { - (void) close (src); - (void) close (dst); - (void) unlink (dstpath); + if ((buf = (char *)cpl_malloc((size_t)blksize)) == NULL) { + (void)close(src); + (void)close(dst); + (void)unlink(dstpath); return -5; } - while ((rbytes = (int) read (src, buf, (size_t)blksize)) > 0) - { - if ((wbytes = (int) write (dst, buf, (size_t)rbytes)) != rbytes) - { + while ((rbytes = (int)read(src, buf, (size_t)blksize)) > 0) { + if ((wbytes = (int)write(dst, buf, (size_t)rbytes)) != rbytes) { wbytes = -1; break; } } - (void) close (src); - (void) close (dst); - cpl_free (buf); + (void)close(src); + (void)close(dst); + cpl_free(buf); - if ((rbytes == -1) || (wbytes == -1)) - { - (void) unlink (dstpath); + if ((rbytes == -1) || (wbytes == -1)) { + (void)unlink(dstpath); return -6; } return 0; - } @@ -642,19 +635,18 @@ */ - -int fileutils_move (const char *srcpath, const char *dstpath) +int +fileutils_move(const char *srcpath, const char *dstpath) { - int ii; + int ii; struct stat sb; - if ((ii = fileutils_copy (srcpath, dstpath)) != 0) - { - if (ii == 99) /* different path name, but same inode */ - return 99; /* => it's the same file - do nothing */ + if ((ii = fileutils_copy(srcpath, dstpath)) != 0) { + if (ii == 99) /* different path name, but same inode */ + return 99; /* => it's the same file - do nothing */ else return (-2); } @@ -665,16 +657,14 @@ * writable revert to the original state, i.e. remove the file copy. */ - if (stat (srcpath, &sb) == -1 || !(sb.st_mode & S_IWUSR)) - { - (void) unlink (dstpath); + if (stat(srcpath, &sb) == -1 || !(sb.st_mode & S_IWUSR)) { + (void)unlink(dstpath); return -1; } - (void) unlink (srcpath); + (void)unlink(srcpath); return 0; - -} +} /* @@ -706,53 +696,51 @@ * */ -int er_fileutils_link (const char *link_path, const char *file_path) +int +er_fileutils_link(const char *link_path, const char *file_path) { char linkname[FILEMAX + 1]; const char *s; - int len; + int len; struct stat lb; /* Check if the input file is readable */ - if (access (file_path, R_OK)) - { - cpl_msg_error (er_func, "Product file is unreadable: %s", file_path); + if (access(file_path, R_OK)) { + cpl_msg_error(er_func, "Product file is unreadable: %s", file_path); return EXIT_FAILURE; } /* pull out the file name */ - s = strrchr (file_path, '/'); /* points to last '/' */ - if (s == NULL) - { + s = strrchr(file_path, '/'); /* points to last '/' */ + if (s == NULL) { s = file_path; } - else - { + else { ++s; } - len = (int) strlen(s); - len = (int) strlen(link_path) + len + 1; - if (len > FILEMAX) - { - cpl_msg_error (er_func, "Buffer overflow - fatal error"); + len = (int)strlen(s); + len = (int)strlen(link_path) + len + 1; + if (len > FILEMAX) { + cpl_msg_error(er_func, "Buffer overflow - fatal error"); return EXIT_FAILURE; } - (void) snprintf (linkname, (size_t)FILEMAX, "%s/%s", link_path, s); + (void)snprintf(linkname, (size_t)FILEMAX, "%s/%s", link_path, s); /* check if link already there... */ /* if (fileutils_file_is_there (linkname) == 1) */ - if (fileutils_file_exists (linkname) == 1) - { - cpl_msg_warning (er_func, "the link %s already exists - will be overwritten!",linkname); + if (fileutils_file_exists(linkname) == 1) { + cpl_msg_warning(er_func, + "the link %s already exists - will be overwritten!", + linkname); } @@ -766,54 +754,46 @@ #if defined HAVE_LSTAT && defined HAVE_SYMLINK - if (lstat (linkname, &lb)) - { - if (errno != ENOENT) - { - cpl_msg_error (er_func, "Cannot get file status: %s", linkname); + if (lstat(linkname, &lb)) { + if (errno != ENOENT) { + cpl_msg_error(er_func, "Cannot get file status: %s", linkname); return EXIT_FAILURE; } } - else - { - if (S_ISLNK (lb.st_mode)) - (void) unlink (linkname); - else - { - cpl_msg_error (er_func, "Not a symbolic link: %s", linkname); + else { + if (S_ISLNK(lb.st_mode)) + (void)unlink(linkname); + else { + cpl_msg_error(er_func, "Not a symbolic link: %s", linkname); return EXIT_FAILURE; } } - if (symlink (file_path, linkname) != 0) - { - cpl_msg_error (er_func, "Cannot create symbolic link for %s", file_path); + if (symlink(file_path, linkname) != 0) { + cpl_msg_error(er_func, "Cannot create symbolic link for %s", file_path); return EXIT_FAILURE; } #else - if (stat (linkname, &lb)) - { - if (errno != ENOENT) - { - cpl_msg_error (er_func, "Cannot get file status: %s", linkname); + if (stat(linkname, &lb)) { + if (errno != ENOENT) { + cpl_msg_error(er_func, "Cannot get file status: %s", linkname); return EXIT_FAILURE; } } else - (void) unlink (linkname); + (void)unlink(linkname); - if (fileutils_copy (file_path, linkname) < 0) - { - cpl_msg_error (er_func, "Cannot copy %s", file_path); + if (fileutils_copy(file_path, linkname) < 0) { + cpl_msg_error(er_func, "Cannot copy %s", file_path); return EXIT_FAILURE; } #endif return EXIT_SUCCESS; -} /* End of er_fileutils_link() */ +} /* End of er_fileutils_link() */ /*----------------------------------------------------------------------------*/ @@ -825,51 +805,46 @@ */ /*----------------------------------------------------------------------------*/ -int er_fileutils_file_is_fits(const char *name) +int +er_fileutils_file_is_fits(const char *name) { FILE *fp; - char *line, *keyw, *eqchar, *kval; + char *line, *keyw, *eqchar, *kval; int is_fits = 0; - int i, j, n; + int i, j, n; int mysscanf(); - - - if (!(fp = fopen (name, "r"))) - { - cpl_msg_error (er_func, "Unable to open FITS file '%s'", name); + if (!(fp = fopen(name, "r"))) { + cpl_msg_error(er_func, "Unable to open FITS file '%s'", name); return (-2); } - line = (char *) cpl_calloc((size_t) 82, (size_t) 1); - keyw = (char *) cpl_calloc((size_t) 80, (size_t) 1); - eqchar = (char *) cpl_calloc((size_t) 80, (size_t) 1); - kval = (char *) cpl_calloc((size_t) 80, (size_t) 1); + line = (char *)cpl_calloc((size_t)82, (size_t)1); + keyw = (char *)cpl_calloc((size_t)80, (size_t)1); + eqchar = (char *)cpl_calloc((size_t)80, (size_t)1); + kval = (char *)cpl_calloc((size_t)80, (size_t)1); /* Loop over first few lines in the file */ - for (i=0; i<10; i++) - { + for (i = 0; i < 10; i++) { line[0] = '\0'; - if (fgets (line, 80, fp) == NULL) - { - cpl_msg_error (er_func, "Failed to read file '%s'", name); + if (fgets(line, 80, fp) == NULL) { + cpl_msg_error(er_func, "Failed to read file '%s'", name); goto close_file; } j = 0; - while (Xspace(line[j])) /* omit leading space */ + while (Xspace(line[j])) /* omit leading space */ { - j ++; - if (line[j] == '\0') - { - cpl_msg_error (er_func, "%s not a FITS file!", name); + j++; + if (line[j] == '\0') { + cpl_msg_error(er_func, "%s not a FITS file!", name); goto close_file; } } @@ -880,28 +855,27 @@ * FITS file. */ - n = mysscanf (&line[j], keyw, eqchar, kval); /* split up line */ + n = mysscanf(&line[j], keyw, eqchar, kval); /* split up line */ /* printf("we get n = %d, keyw = %s, %s, %s\n",n,keyw,kval, eqchar); */ - if ((n == 3) && (strcmp(keyw,"SIMPLE") == 0) - && (*eqchar == '=') && (*kval == 'T')) - { + if ((n == 3) && (strcmp(keyw, "SIMPLE") == 0) && (*eqchar == '=') && + (*kval == 'T')) { is_fits = 1; goto close_file; } } /* first 10 lines indicate no FITS header ... */ - cpl_msg_error (er_func, "%s not a FITS file!", name); + cpl_msg_error(er_func, "%s not a FITS file!", name); - close_file: +close_file: cpl_free(line); cpl_free(keyw); cpl_free(eqchar); cpl_free(kval); - fclose (fp); + fclose(fp); return is_fits; } diff -Nru esorex-3.13.5+ds/src/er_fileutils.h esorex-3.13.6+ds/src/er_fileutils.h --- esorex-3.13.5+ds/src/er_fileutils.h 2021-06-02 15:06:13.000000000 +0000 +++ esorex-3.13.6+ds/src/er_fileutils.h 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 European Southern Observatory * * 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 @@ -33,9 +33,9 @@ int fileutils_copy(const char *, const char *); int fileutils_move(const char *, const char *); int er_fileutils_link(const char *, const char *); -int er_fileutils_file_is_fits(const char * self); +int er_fileutils_file_is_fits(const char *self); -#define FILEMAX 4096 +#define FILEMAX 4096 CPL_END_DECLS diff -Nru esorex-3.13.5+ds/src/er_help.c esorex-3.13.6+ds/src/er_help.c --- esorex-3.13.5+ds/src/er_help.c 2021-06-02 15:06:13.000000000 +0000 +++ esorex-3.13.6+ds/src/er_help.c 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 European Southern Observatory * * 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 @@ -39,17 +39,15 @@ #include "er_fileutils.h" #include "er_json.h" -#define SIZE_X 1024 +#define SIZE_X 1024 -static char *wdsc = NULL; /* space for help description */ -static char *entrx = NULL; /* space for help entry */ +static char *wdsc = NULL; /* space for help description */ +static char *entrx = NULL; /* space for help entry */ static int wdsclen = 0; static int entrlen = 0; - - /** * @defgroup er_help EsoRex help functions. * @@ -70,68 +68,64 @@ */ /**********************************************************************/ -static void er_help_create_description (cpl_parameter *param, - int print_default) +static void +er_help_create_description(cpl_parameter *param, int print_default) { - const char *cpp, *cstr = NULL; - char *cptr; + const char *cpp, *cstr = NULL; + char *cptr; - int indx; - int countr, n, str_len; + int indx; + int countr, n, str_len; - cpl_type type; /* Parameter type */ + cpl_type type; /* Parameter type */ - int f_env_active; /* Flag for if an ENV variable is available */ + int f_env_active; /* Flag for if an ENV variable is available */ - if (param == NULL) - { + if (param == NULL) { cpl_msg_warning(er_func, "A NULL-parameter was found"); return; } - if (wdsclen == 0) - { - wdsc = (char *) cpl_malloc((size_t) SIZE_X); - if (wdsc == NULL) - { - cpl_msg_warning (er_func, - "Could not allocate initial %d bytes for help description", - SIZE_X); + if (wdsclen == 0) { + wdsc = (char *)cpl_malloc((size_t)SIZE_X); + if (wdsc == NULL) { + cpl_msg_warning( + er_func, + "Could not allocate initial %d bytes for help description", + SIZE_X); return; } wdsclen = SIZE_X; } cpp = cpl_parameter_get_help(param); - if (cpp == NULL) - { + if (cpp == NULL) { cpl_msg_warning(er_func, "cpl_parameter_get_help failed "); return; } - str_len = (int) strlen(cpp); + str_len = (int)strlen(cpp); n = str_len + 1; - if (n > wdsclen) - { /* allocate already more space */ + if (n > wdsclen) { /* allocate already more space */ wdsclen = n + 160; - er_enlarge("help_create",&wdsc,wdsclen); + er_enlarge("help_create", &wdsc, wdsclen); } - (void) strcpy(wdsc, cpp); + (void)strcpy(wdsc, cpp); cptr = wdsc + str_len - 1; - for (n=str_len; n>0; n--) - { + for (n = str_len; n > 0; n--) { if (isspace((int)*cptr)) - cptr --; + cptr--; else break; } - if (*cptr != '.') *++cptr = '.'; /* append a full-stop, if none */ + if (*cptr != '.') + *++cptr = '.'; /* append a full-stop, if none */ *++cptr = '\0'; - countr = (int) strlen(wdsc); /* length counter for wdsc */ + countr = (int)strlen(wdsc); /* length counter for wdsc */ /* Add environment variable, if any */ @@ -139,73 +133,68 @@ f_env_active = FALSE; f_env_active = cpl_parameter_is_enabled(param, CPL_PARAMETER_MODE_ENV); - if (f_env_active == TRUE) - { - const char *env_par; - char *pt1, *pt2; + if (f_env_active == TRUE) { + const char *env_par; + char *pt1, *pt2; /* get name for eventual env. variable (a.b.c if nothing defined) */ env_par = cpl_parameter_get_alias(param, CPL_PARAMETER_MODE_ENV); - pt1 = strchr(env_par,'.'); /* get first '.' */ - pt2 = strrchr(env_par,'.'); /* get last '.' */ + pt1 = strchr(env_par, '.'); /* get first '.' */ + pt2 = strrchr(env_par, '.'); /* get last '.' */ if ((pt1 != NULL) && (pt2 != NULL) && (pt1 < pt2)) { - ; /* it's the a.b.c string - no variable defined */ + ; /* it's the a.b.c string - no variable defined */ } - else - { - char tmp[512]; + else { + char tmp[512]; - (void)strcpy(tmp, - " This option may also be set using the environment variable "); + (void)strcpy( + tmp, + " This option may also be set using the environment variable "); (void)strcat(tmp, env_par); (void)strcat(tmp, "."); - n = (int) strlen(tmp) + 1; + n = (int)strlen(tmp) + 1; countr += n; - if (countr > wdsclen) - { /* allocate already more space */ + if (countr > wdsclen) { /* allocate already more space */ wdsclen = countr + 160; - er_enlarge("help_create",&wdsc,wdsclen); + er_enlarge("help_create", &wdsc, wdsclen); } - (void) strcat(wdsc,tmp); + (void)strcat(wdsc, tmp); } } /* Add options, depending on the type */ type = cpl_parameter_get_type(param); - switch(type) - { + switch (type) { case CPL_TYPE_BOOL: - case CPL_TYPE_INT: /* ????? - Need to add enumeration/range handling */ - case CPL_TYPE_DOUBLE: /* ????? - Need to add enumeration/range handling */ + case CPL_TYPE_INT: /* ????? - Need to add enumeration/range handling */ + case CPL_TYPE_DOUBLE: /* ????? - Need to add enumeration/range handling */ break; case CPL_TYPE_STRING: - if (cpl_parameter_get_class(param) == CPL_PARAMETER_CLASS_ENUM) - { - int klen; - char tmp[SIZE_X]; + if (cpl_parameter_get_class(param) == CPL_PARAMETER_CLASS_ENUM) { + int klen; + char tmp[SIZE_X]; (void)strcpy(tmp, " <"); - klen = 4; /* the < and > chars */ - for(indx = 0; indx < cpl_parameter_get_enum_size(param); indx++) - { - if (indx != 0) - { + klen = 4; /* the < and > chars */ + for (indx = 0; indx < cpl_parameter_get_enum_size(param); + indx++) { + if (indx != 0) { klen += 3; (void)strcat(tmp, " | "); } cstr = cpl_parameter_get_enum_string(param, indx); - if (cstr == NULL) - { - cpl_msg_warning(er_func, "cpl_parameter_get_enum_string failed "); + if (cstr == NULL) { + cpl_msg_warning( + er_func, "cpl_parameter_get_enum_string failed "); return; } - klen += 4 + (int) strlen(cstr); /* for the ` | ' above */ - if (klen > SIZE_X) - { - cpl_msg_warning(er_func, "internal options overflow..."); + klen += 4 + (int)strlen(cstr); /* for the ` | ' above */ + if (klen > SIZE_X) { + cpl_msg_warning(er_func, + "internal options overflow..."); return; } else @@ -213,14 +202,13 @@ } (void)strcat(tmp, ">"); - n = (int) strlen(tmp) + 1; + n = (int)strlen(tmp) + 1; countr += n; - if (countr > wdsclen) - { /* allocate more space */ + if (countr > wdsclen) { /* allocate more space */ wdsclen = countr + 160; - er_enlarge("help_create",&wdsc,wdsclen); + er_enlarge("help_create", &wdsc, wdsclen); } - (void) strcat(wdsc,tmp); + (void)strcat(wdsc, tmp); } break; @@ -232,16 +220,13 @@ /* Add defaults, if required */ - if (print_default == TRUE) - { - char tmp[MAXSTRLENCONF]; + if (print_default == TRUE) { + char tmp[MAXSTRLENCONF]; const char *cppp; - switch(type) - { + switch (type) { case CPL_TYPE_BOOL: - switch(cpl_parameter_get_bool(param)) - { + switch (cpl_parameter_get_bool(param)) { case TRUE: (void)strcpy(tmp, " [TRUE]"); countr += 7; @@ -259,51 +244,52 @@ } break; - case CPL_TYPE_INT: - n = snprintf(tmp,(size_t)80, " [%d]", cpl_parameter_get_int(param)); - countr += n; - break; + case CPL_TYPE_INT: + n = snprintf(tmp, (size_t)80, " [%d]", + cpl_parameter_get_int(param)); + countr += n; + break; - case CPL_TYPE_DOUBLE: - (void)strcpy(tmp, " ["); - cppp = er_strutils_dblstr(cpl_parameter_get_double(param)); - if ((int)strlen(cppp) > (MAXSTRLENCONF - 4)) - { - cpl_msg_warning(er_func, "cpl_parameter_get_double(param) > 1000 chars..."); - break; - } - (void)strcat(tmp, cppp); - (void)strcat(tmp, "]"); - countr += (int) strlen(tmp); - break; + case CPL_TYPE_DOUBLE: + (void)strcpy(tmp, " ["); + cppp = er_strutils_dblstr(cpl_parameter_get_double(param)); + if ((int)strlen(cppp) > (MAXSTRLENCONF - 4)) { + cpl_msg_warning( + er_func, + "cpl_parameter_get_double(param) > 1000 chars..."); + break; + } + (void)strcat(tmp, cppp); + (void)strcat(tmp, "]"); + countr += (int)strlen(tmp); + break; - case CPL_TYPE_STRING: - (void)strcpy(tmp, " ["); - cppp = cpl_parameter_get_string(param); - if ((int)strlen(cppp) > (MAXSTRLENCONF - 4)) - { - cpl_msg_warning(er_func, "cpl_parameter_get_string(param) > 1000 chars..."); - break; - } - (void)strcat(tmp, cppp); - (void)strcat(tmp, "]"); - countr += (int) strlen(tmp); - break; + case CPL_TYPE_STRING: + (void)strcpy(tmp, " ["); + cppp = cpl_parameter_get_string(param); + if ((int)strlen(cppp) > (MAXSTRLENCONF - 4)) { + cpl_msg_warning( + er_func, + "cpl_parameter_get_string(param) > 1000 chars..."); + break; + } + (void)strcat(tmp, cppp); + (void)strcat(tmp, "]"); + countr += (int)strlen(tmp); + break; - default: - cpl_msg_warning(er_func, "Unrecognized parameter type"); - break; + default: + cpl_msg_warning(er_func, "Unrecognized parameter type"); + break; } - if (countr > wdsclen) - { /* allocate more space */ + if (countr > wdsclen) { /* allocate more space */ wdsclen = countr + 160; - er_enlarge(er_func,&wdsc,wdsclen); + er_enlarge(er_func, &wdsc, wdsclen); } - (void) strcat(wdsc,tmp); + (void)strcat(wdsc, tmp); } return; - } @@ -320,50 +306,46 @@ */ /**********************************************************************/ -static void er_help_create_entry (cpl_parameter *param) +static void +er_help_create_entry(cpl_parameter *param) { - char value[SIZE_X-80]; /* Default value of an option */ + char value[SIZE_X - 80]; /* Default value of an option */ const char *cpp; - int n; + int n; - cpl_type type; /* Parameter type */ + cpl_type type; /* Parameter type */ value[0] = '\0'; - if (param == NULL) - { + if (param == NULL) { cpl_msg_warning(er_func, "A NULL-parameter was found"); return; } cpp = cpl_parameter_get_name(param); - if (cpp == NULL) - { + if (cpp == NULL) { cpl_msg_warning(er_func, "cpl_parameter_get_name failed "); return; } - n = (int) strlen(cpp) + 24; /* for the stuff below, except TYPE_STRING */ - if (n > entrlen) - { + n = (int)strlen(cpp) + 24; /* for the stuff below, except TYPE_STRING */ + if (n > entrlen) { entrlen = n; - er_enlarge("help_create_entry",&entrx,entrlen); + er_enlarge("help_create_entry", &entrx, entrlen); } - (void) strcpy(entrx, cpp); - (void) strcat(entrx, "="); + (void)strcpy(entrx, cpp); + (void)strcat(entrx, "="); /* Add the default value, depending on type */ type = cpl_parameter_get_type(param); - switch(type) - { + switch (type) { case CPL_TYPE_BOOL: - switch(cpl_parameter_get_bool(param)) - { + switch (cpl_parameter_get_bool(param)) { case TRUE: (void)strcat(entrx, "TRUE"); break; @@ -373,39 +355,39 @@ break; default: - cpl_msg_warning(er_func, "Unable to set one of the parameter values"); + cpl_msg_warning( + er_func, "Unable to set one of the parameter values"); (void)strcat(entrx, "???"); break; } break; - case CPL_TYPE_INT: - (void)snprintf(value,(size_t)80, "%d", cpl_parameter_get_int(param)); - (void)strcat(entrx,value); - break; + case CPL_TYPE_INT: + (void)snprintf(value, (size_t)80, "%d", + cpl_parameter_get_int(param)); + (void)strcat(entrx, value); + break; - case CPL_TYPE_DOUBLE: - (void)strcat(entrx, - er_strutils_dblstr(cpl_parameter_get_double(param)) ); - break; + case CPL_TYPE_DOUBLE: + (void)strcat(entrx, + er_strutils_dblstr(cpl_parameter_get_double(param))); + break; - case CPL_TYPE_STRING: - cpp = cpl_parameter_get_string(param); - ForceNull(cpp) - if (cpp == NULL) break; - - n = (int) strlen(cpp) + 1; - if (n > entrlen) - { - entrlen = n; - er_enlarge("help_create_entry",&entrx,entrlen); - } - (void)strcat(entrx, cpp); - break; + case CPL_TYPE_STRING: + cpp = cpl_parameter_get_string(param); + ForceNull(cpp) if (cpp == NULL) break; - default: - cpl_msg_warning(er_func, "Unrecognized parameter type"); - break; + n = (int)strlen(cpp) + 1; + if (n > entrlen) { + entrlen = n; + er_enlarge("help_create_entry", &entrx, entrlen); + } + (void)strcat(entrx, cpp); + break; + + default: + cpl_msg_warning(er_func, "Unrecognized parameter type"); + break; } return; @@ -422,10 +404,9 @@ */ /**********************************************************************/ -static void er_help_print_paramlist(cpl_parameterlist *param_list, - int show_all) +static void +er_help_print_paramlist(cpl_parameterlist *param_list, int show_all) { - /* * Loop through all the parameters in the list and create the * description text. @@ -433,10 +414,9 @@ cpl_parameter *param = cpl_parameterlist_get_first(param_list); - while (param != NULL) - { - const char *alias = cpl_parameter_get_alias(param, - CPL_PARAMETER_MODE_CLI); + while (param != NULL) { + const char *alias = + cpl_parameter_get_alias(param, CPL_PARAMETER_MODE_CLI); int enabled = cpl_parameter_is_enabled(param, CPL_PARAMETER_MODE_CLI); @@ -453,9 +433,8 @@ } /* Pad with an additional blank line */ - printf( "\n" ); - -} + printf("\n"); +} /**********************************************************************/ @@ -468,26 +447,25 @@ */ /**********************************************************************/ -static int er_help_count_paramlist ( cpl_parameterlist *param_list) +static int +er_help_count_paramlist(cpl_parameterlist *param_list) { - int num_params = 0; /* Counter */ + int num_params = 0; /* Counter */ - cpl_parameter *param = NULL; /* Parameter within the list */ + cpl_parameter *param = NULL; /* Parameter within the list */ /* Loop through all the parameters in the list */ param = cpl_parameterlist_get_first(param_list); - while (param != NULL) - { + while (param != NULL) { num_params++; param = cpl_parameterlist_get_next(param_list); } /* Return the number of parameters counted */ return (num_params); - } @@ -502,15 +480,17 @@ */ /**********************************************************************/ -void er_help_display(const char *plugin_name, cpl_parameterlist *param_list, - int flag_show_all) +void +er_help_display(const char *plugin_name, + cpl_parameterlist *param_list, + int flag_show_all) { /* Print some header text */ - (void) printf("Usage: %s [%s-options] %s [%s-options] sof\n\n", - PACKAGE, PACKAGE, plugin_name, plugin_name); + (void)printf("Usage: %s [%s-options] %s [%s-options] sof\n\n", PACKAGE, + PACKAGE, plugin_name, plugin_name); - (void) printf("Options:\n\n"); + (void)printf("Options:\n\n"); er_help_print_paramlist(param_list, flag_show_all); } @@ -525,25 +505,26 @@ */ /**********************************************************************/ -void er_help_manpage(cpl_recipe *recipe, int flag_show_all) +void +er_help_manpage(cpl_recipe *recipe, int flag_show_all) { - int left_margin; /* Column of left margin */ - int right_margin; /* Column of right margin */ - int margin = 2; /* Size of margins from either side */ - int num_params; /* Number of options provided by the recipe */ - int n, strsize; + int left_margin; /* Column of left margin */ + int right_margin; /* Column of right margin */ + int margin = 2; /* Size of margins from either side */ + int num_params; /* Number of options provided by the recipe */ + int n, strsize; - char *version_str; /* Plugin version (as a string) */ + char *version_str; /* Plugin version (as a string) */ char *str = NULL; - const char *cpp; + const char *cpp; /* Check that we can actually do something */ - if (recipe == NULL) - { - cpl_msg_warning(er_func, "Unable to print documentation for the recipe"); + if (recipe == NULL) { + cpl_msg_warning(er_func, + "Unable to print documentation for the recipe"); return; } @@ -551,87 +532,81 @@ /* Determine the right hand margin */ right_margin = er_strutils_termwidth(); - if (right_margin < 1) right_margin = 80; + if (right_margin < 1) + right_margin = 80; right_margin -= margin; - str = (char *) cpl_malloc((size_t) SIZE_X); - if ( str == NULL) - { - cpl_msg_error (er_func, "Could not allocate %d bytes for str",SIZE_X); - return ; + str = (char *)cpl_malloc((size_t)SIZE_X); + if (str == NULL) { + cpl_msg_error(er_func, "Could not allocate %d bytes for str", SIZE_X); + return; } - strsize = SIZE_X; /* dynamic size */ + strsize = SIZE_X; /* dynamic size */ /* Plugin name */ - (void) printf("\nNAME\n"); - (void) strcpy(str, " "); + (void)printf("\nNAME\n"); + (void)strcpy(str, " "); cpp = cpl_plugin_get_name((cpl_plugin *)recipe); - if (cpp == NULL) - { - cpl_msg_error (er_func, "cpl_plugin_get_name() failed"); + if (cpp == NULL) { + cpl_msg_error(er_func, "cpl_plugin_get_name() failed"); goto free_str; } - n = 12 + (int) strlen(cpp); /* add the constant char stuff before + after */ - if (n > strsize) - { + n = 12 + (int)strlen(cpp); /* add the constant char stuff before + after */ + if (n > strsize) { strsize = n; - er_enlarge("help_manpage",&str,strsize); + er_enlarge("help_manpage", &str, strsize); } - (void) strcat(str, cpp); + (void)strcat(str, cpp); - (void) strcat(str, " -- "); - left_margin = (int) strlen(str); /* new length of string */ + (void)strcat(str, " -- "); + left_margin = (int)strlen(str); /* new length of string */ cpp = cpl_plugin_get_synopsis((cpl_plugin *)recipe); - if (cpp == NULL) - { - cpl_msg_error (er_func, "cpl_plugin_get_synopsis() failed"); + if (cpp == NULL) { + cpl_msg_error(er_func, "cpl_plugin_get_synopsis() failed"); goto free_str; } - n = (int) strlen(cpp) + left_margin; - if (n > strsize) - { + n = (int)strlen(cpp) + left_margin; + if (n > strsize) { strsize = n; - er_enlarge("help_manpage",&str,strsize); + er_enlarge("help_manpage", &str, strsize); } - (void) strcat(str, cpp); + (void)strcat(str, cpp); - (void) printf("%s\n\n", er_strutils_split(str , left_margin, right_margin) ); + (void)printf("%s\n\n", er_strutils_split(str, left_margin, right_margin)); left_margin = margin; /* Print some header text */ - (void) printf("SYNOPSIS\n"); - (void) printf(" %s [%s-options] %s [%s-options] sof\n\n", - PACKAGE, PACKAGE, cpl_plugin_get_name((cpl_plugin *)recipe), - cpl_plugin_get_name((cpl_plugin *)recipe)); + (void)printf("SYNOPSIS\n"); + (void)printf(" %s [%s-options] %s [%s-options] sof\n\n", PACKAGE, PACKAGE, + cpl_plugin_get_name((cpl_plugin *)recipe), + cpl_plugin_get_name((cpl_plugin *)recipe)); /* Description of the plugin */ - (void) printf("DESCRIPTION\n"); - (void) strcpy(str, " "); + (void)printf("DESCRIPTION\n"); + (void)strcpy(str, " "); cpp = cpl_plugin_get_description((cpl_plugin *)recipe); - if (cpp == NULL) - { - cpl_msg_error (er_func, "cpl_plugin_get_description() failed"); + if (cpp == NULL) { + cpl_msg_error(er_func, "cpl_plugin_get_description() failed"); goto free_str; } - n = 4 + (int) strlen(cpp); - if (n > strsize) - { + n = 4 + (int)strlen(cpp); + if (n > strsize) { strsize = n; - er_enlarge("help_manpage",&str,strsize); + er_enlarge("help_manpage", &str, strsize); } - (void) strcat(str, cpp); + (void)strcat(str, cpp); - (void) printf("%s\n\n", er_strutils_indent( str, left_margin) ); + (void)printf("%s\n\n", er_strutils_indent(str, left_margin)); /* Plugin options */ @@ -641,22 +616,24 @@ if (num_params < 1) printf(" No options are provided by this recipe.\n\n"); - else - { - char tmp[256]; /* actually 194 are needed... */ + else { + char tmp[256]; /* actually 194 are needed... */ if (num_params > 1) - (void) printf(" The following options are provided by this recipe.\n\n"); + (void)printf( + " The following options are provided by this recipe.\n\n"); else - (void) printf(" A single option is provided by this recipe.\n\n"); + (void)printf(" A single option is provided by this recipe.\n\n"); er_help_print_paramlist(recipe->parameters, flag_show_all); - (void) strcpy(tmp, " Note that it is also possible to create a " - "configuration file containing these options, along with suitable " - "default values. Please refer to the " - "details provided by the '" PACKAGE " --help' command."); - printf("%s\n\n", er_strutils_split(tmp , left_margin, right_margin) ); + (void)strcpy( + tmp, + " Note that it is also possible to create a " + "configuration file containing these options, along with suitable " + "default values. Please refer to the " + "details provided by the '" PACKAGE " --help' command."); + printf("%s\n\n", er_strutils_split(tmp, left_margin, right_margin)); } @@ -666,96 +643,87 @@ strcpy(str, " "); cpp = cpl_plugin_get_author((cpl_plugin *)recipe); - if (cpp == NULL) - { - cpl_msg_error (er_func, "cpl_plugin_get_author() failed"); + if (cpp == NULL) { + cpl_msg_error(er_func, "cpl_plugin_get_author() failed"); goto free_str; } - n = 4 + (int) strlen(cpp); - if (n > strsize) - { + n = 4 + (int)strlen(cpp); + if (n > strsize) { strsize = n; - er_enlarge("help_manpage",&str,strsize); + er_enlarge("help_manpage", &str, strsize); } - (void) strcat(str, cpp); - printf("%s\n\n", er_strutils_split(str , left_margin, right_margin) ); + (void)strcat(str, cpp); + printf("%s\n\n", er_strutils_split(str, left_margin, right_margin)); /* Bugs and E-mail address */ - (void) printf("BUGS\n"); - (void) strcpy(str, " Please report any problems with this recipe to "); - n = 2 + (int) strlen(str); /* don't forget the \0 */ + (void)printf("BUGS\n"); + (void)strcpy(str, " Please report any problems with this recipe to "); + n = 2 + (int)strlen(str); /* don't forget the \0 */ cpp = cpl_plugin_get_email((cpl_plugin *)recipe); - if (cpp == NULL) - { - cpl_msg_error (er_func, "cpl_plugin_get_email() failed"); + if (cpp == NULL) { + cpl_msg_error(er_func, "cpl_plugin_get_email() failed"); goto free_str; } - n += (int) strlen(cpp); - if (n > strsize) - { + n += (int)strlen(cpp); + if (n > strsize) { strsize = n; - er_enlarge("help_manpage",&str,strsize); + er_enlarge("help_manpage", &str, strsize); } - (void) strcat(str, cpp); - (void) printf("%s\n\n", er_strutils_split(str , left_margin, right_margin) ); + (void)strcat(str, cpp); + (void)printf("%s\n\n", er_strutils_split(str, left_margin, right_margin)); /* Version */ - (void) printf("RELEASE\n"); - (void) strcpy(str, " "); + (void)printf("RELEASE\n"); + (void)strcpy(str, " "); - cpp = cpl_plugin_get_name((cpl_plugin *)recipe); /* already checked above */ + cpp = cpl_plugin_get_name((cpl_plugin *)recipe); /* already checked above */ - n = 24 + (int) strlen(cpp); /* const chars before + after ... */ - if (n > strsize) - { + n = 24 + (int)strlen(cpp); /* const chars before + after ... */ + if (n > strsize) { strsize = n; - er_enlarge("help_manpage",&str,strsize); + er_enlarge("help_manpage", &str, strsize); } - (void) strcat(str, cpp); - (void) strcat(str, " -- version "); + (void)strcat(str, cpp); + (void)strcat(str, " -- version "); version_str = cpl_plugin_get_version_string((cpl_plugin *)recipe); - if (version_str == NULL) - { - cpl_msg_error (er_func, "cpl_plugin_get_version_string() failed"); + if (version_str == NULL) { + cpl_msg_error(er_func, "cpl_plugin_get_version_string() failed"); goto free_str; } - n += (int) strlen(version_str); - if (n > strsize) - { + n += (int)strlen(version_str); + if (n > strsize) { strsize = n; - er_enlarge("help_manpage",&str,strsize); + er_enlarge("help_manpage", &str, strsize); } - (void) strcat(str, version_str); + (void)strcat(str, version_str); cpl_free(version_str); - (void) printf("%s\n\n", er_strutils_split( str , left_margin, right_margin) ); + (void)printf("%s\n\n", er_strutils_split(str, left_margin, right_margin)); /* License */ - (void) printf("LICENSE\n"); + (void)printf("LICENSE\n"); cpp = cpl_plugin_get_copyright((cpl_plugin *)recipe); - if (cpp == NULL) - { - cpl_msg_error (er_func, "cpl_plugin_get_copyright() failed"); + if (cpp == NULL) { + cpl_msg_error(er_func, "cpl_plugin_get_copyright() failed"); goto free_str; } - (void) printf(" %s\n", er_strutils_indent(cpp , left_margin)); + (void)printf(" %s\n", er_strutils_indent(cpp, left_margin)); - free_str: +free_str: cpl_free(str); return; - } @@ -770,13 +738,14 @@ */ /**********************************************************************/ -static void er_help_create_config_header (FILE *fp, const char *file_name) +static void +er_help_create_config_header(FILE *fp, const char *file_name) { time_t epoch; - struct tm *timestruct; /* Time structure */ + struct tm *timestruct; /* Time structure */ - char timestr[MAXSTRLENCONF]; /* String with date/time */ + char timestr[MAXSTRLENCONF]; /* String with date/time */ fprintf(fp, "# File: %s\n", file_name); @@ -793,7 +762,6 @@ fprintf(fp, "#\n"); fprintf(fp, "#\n\n"); - } @@ -807,26 +775,26 @@ */ /**********************************************************************/ -static void er_help_create_paramlist (FILE *fp, cpl_parameterlist *param_list) +static void +er_help_create_paramlist(FILE *fp, cpl_parameterlist *param_list) { - cpl_parameter *param = NULL; /* Parameter */ + cpl_parameter *param = NULL; /* Parameter */ - char *split_str = NULL; /* Split string */ - char **value_str = NULL; /* String of just the parameter value */ + char *split_str = NULL; /* Split string */ + char **value_str = NULL; /* String of just the parameter value */ - int c; /* Loop counter */ + int c; /* Loop counter */ /* Loop through all the parameters in the list */ - if (entrlen == 0) - { - entrx = (char *) cpl_malloc((size_t) SIZE_X); - if (entrx == NULL) - { - cpl_msg_warning (er_func, "Could not allocate initial %d bytes for help entry", - SIZE_X); + if (entrlen == 0) { + entrx = (char *)cpl_malloc((size_t)SIZE_X); + if (entrx == NULL) { + cpl_msg_warning( + er_func, "Could not allocate initial %d bytes for help entry", + SIZE_X); return; } entrlen = SIZE_X; @@ -834,16 +802,13 @@ param = cpl_parameterlist_get_first(param_list); - while (param != NULL) - { + while (param != NULL) { /* * Only parameters which are not disabled are written to * the configuration file. */ - if (cpl_parameter_is_enabled(param, CPL_PARAMETER_MODE_CFG)) - { - + if (cpl_parameter_is_enabled(param, CPL_PARAMETER_MODE_CFG)) { /* * Create the comment and entry text */ @@ -858,19 +823,18 @@ fprintf(fp, "# %s%s\n", COMMAND_LINE_PREFIX, cpl_parameter_get_alias(param, CPL_PARAMETER_MODE_CLI)); - split_str = er_strutils_split((const char *) wdsc, 2, - DEFAULT_TERM_WIDTH-2); + split_str = er_strutils_split((const char *)wdsc, 2, + DEFAULT_TERM_WIDTH - 2); /* * Parse the string and replace any space following a * new-line with a # */ - for (c = 0; c < (int)(strlen(split_str)-1); c++) - { - if (*(split_str+c) == '\n') - { - if (*(split_str+c+1) == ' ') *(split_str+c+1) = '#'; + for (c = 0; c < (int)(strlen(split_str) - 1); c++) { + if (*(split_str + c) == '\n') { + if (*(split_str + c + 1) == ' ') + *(split_str + c + 1) = '#'; } } @@ -886,18 +850,17 @@ */ value_str = cx_strsplit(entrx, "=", 0); - if ( ( value_str == NULL ) || - ( *(value_str+1) == NULL ) || - ( **(value_str+1) == '\0')) - { + if ((value_str == NULL) || (*(value_str + 1) == NULL) || + (**(value_str + 1) == '\0')) { const char *alias = - cpl_parameter_get_alias(param, CPL_PARAMETER_MODE_CLI); + cpl_parameter_get_alias(param, CPL_PARAMETER_MODE_CLI); cpl_msg_warning(er_func, "No sensible default available for '%s%s'. " "The entry will be inserted into the " "configuration file, but will be commented " - "out.", COMMAND_LINE_PREFIX, alias); + "out.", + COMMAND_LINE_PREFIX, alias); fprintf(fp, "#"); } @@ -905,7 +868,8 @@ /* Get the next parameter */ - cx_strfreev(value_str); value_str = NULL; + cx_strfreev(value_str); + value_str = NULL; } param = cpl_parameterlist_get_next(param_list); @@ -935,17 +899,18 @@ */ /**********************************************************************/ -void er_help_create_config ( int def_flag, - const char *context_name, - const char *file_name, - cpl_parameterlist *caller_parlist, - cpl_parameterlist *config_parlist) +void +er_help_create_config(int def_flag, + const char *context_name, + const char *file_name, + cpl_parameterlist *caller_parlist, + cpl_parameterlist *config_parlist) { - char final_file_name[FILEMAX+1]; - char command_str[2*FILEMAX]; - char *cpp; + char final_file_name[FILEMAX + 1]; + char command_str[2 * FILEMAX]; + char *cpp; - int file_exists = TRUE; + int file_exists = TRUE; FILE *fp = NULL; @@ -956,73 +921,70 @@ /* check if default (=> $HOME/.esorex/esorex.rc) or user specified config file */ - if (def_flag == 11) - { - (void) strcpy(final_file_name, file_name); - goto filename_complete; /* skip the default stuff */ + if (def_flag == 11) { + (void)strcpy(final_file_name, file_name); + goto filename_complete; /* skip the default stuff */ } /* First, generate the global directory name, and establish the directory */ cpp = getenv("HOME"); if (cpp == NULL) - (void)strcpy( final_file_name, "/" ); - else - { - (void) strcpy(final_file_name,cpp); - (void) strcat( final_file_name, "/" ); - } - (void)strcat( final_file_name, GLOBAL_RC_DIR ); - - if (fileutils_directory_exists(final_file_name) == FALSE) - { - cpl_msg_warning(er_func, "No global configuration directory exists. " + (void)strcpy(final_file_name, "/"); + else { + (void)strcpy(final_file_name, cpp); + (void)strcat(final_file_name, "/"); + } + (void)strcat(final_file_name, GLOBAL_RC_DIR); + + if (fileutils_directory_exists(final_file_name) == FALSE) { + cpl_msg_warning(er_func, + "No global configuration directory exists. " "Creating global configuration directory '%s'", final_file_name); - (void) strcpy(command_str,"mkdir "); - (void) strcat(command_str,final_file_name); + (void)strcpy(command_str, "mkdir "); + (void)strcat(command_str, final_file_name); status = system(command_str); - if(status != 0) cpl_msg_error(er_func, "Error creating directory '%s'", - command_str); - if (fileutils_directory_exists(final_file_name) == FALSE) - { - cpl_msg_error(er_func, "Unable to create global configuration " - "directory '%s'\n", final_file_name ); + if (status != 0) + cpl_msg_error(er_func, "Error creating directory '%s'", + command_str); + if (fileutils_directory_exists(final_file_name) == FALSE) { + cpl_msg_error(er_func, + "Unable to create global configuration " + "directory '%s'\n", + final_file_name); return; } } /* Now complete the filename */ - (void)strcat( final_file_name, "/" ); - (void)strcat( final_file_name, context_name); - (void)strcat( final_file_name, GLOBAL_RC_EXTENSION); + (void)strcat(final_file_name, "/"); + (void)strcat(final_file_name, context_name); + (void)strcat(final_file_name, GLOBAL_RC_EXTENSION); - filename_complete: +filename_complete: /* Check for file existence */ file_exists = fileutils_file_exists(final_file_name); /* Make a copy of the old configuration file */ - if (file_exists == TRUE) - { - (void) strcpy(command_str,"cp "); - (void)strcat(command_str,final_file_name); - (void)strcat(command_str," "); - (void)strcat(command_str,final_file_name); + if (file_exists == TRUE) { + (void)strcpy(command_str, "cp "); + (void)strcat(command_str, final_file_name); + (void)strcat(command_str, " "); + (void)strcat(command_str, final_file_name); (void)strcat(command_str, GLOBAL_RC_BACKUP); - if (system(command_str) != 0) - { + if (system(command_str) != 0) { cpl_msg_error(er_func, "Unable to make a backup copy of the " - "configuration file."); + "configuration file."); cpl_msg_warning(er_func, "No attempt made to create a " - "new configuration file."); + "new configuration file."); return; } - else - { + else { cpl_msg_info(er_func, "Old configuration file copied to '%s%s'", final_file_name, GLOBAL_RC_BACKUP); } @@ -1031,22 +993,20 @@ /* If we're clear to go, then report it, and being the generation process */ cpl_msg_info(er_func, "Creating configuration file '%s'", final_file_name); - if(strlen(final_file_name)>5 && - strncmp(final_file_name + strlen(final_file_name) - 5, ".json", 5) == 0 ) - { + if (strlen(final_file_name) > 5 && + strncmp(final_file_name + strlen(final_file_name) - 5, ".json", 5) == + 0) { /* We write a JSON format configuration file */ cpl_msg_info(cpl_func, "Writing configuration file in JSON format"); er_recipe_parameterlist_to_json(config_parlist, context_name, final_file_name); } - else - { + else { /* We write a plain text configuration file */ /* Open the file */ fp = fopen(final_file_name, "w"); - if (fp == NULL) - { + if (fp == NULL) { cpl_msg_error(er_func, "Unable to create configuration file '%s'", final_file_name); return; @@ -1061,14 +1021,16 @@ /* Close the file and remove the filename string */ fclose(fp); } - } -void er_help_free(void) +void +er_help_free(void) { - if (entrlen > 0) cpl_free(entrx); - if (wdsclen > 0) cpl_free(wdsc); + if (entrlen > 0) + cpl_free(entrx); + if (wdsclen > 0) + cpl_free(wdsc); } /**@}*/ diff -Nru esorex-3.13.5+ds/src/er_help.h esorex-3.13.6+ds/src/er_help.h --- esorex-3.13.5+ds/src/er_help.h 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/er_help.h 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 European Southern Observatory * * 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 @@ -20,7 +20,7 @@ #ifndef EP_HELP_H #define EP_HELP_H -#include +#include #include @@ -33,7 +33,7 @@ * er_params.c */ -#define ER_HELP_CFG_VER "# generated by the " PACKAGE " (v" +#define ER_HELP_CFG_VER "# generated by the " PACKAGE " (v" CPL_BEGIN_DECLS @@ -42,8 +42,11 @@ void er_help_manpage(cpl_recipe *, int); void er_help_free(void); -void er_help_create_config(int, const char *, const char *, - cpl_parameterlist *, cpl_parameterlist *); +void er_help_create_config(int, + const char *, + const char *, + cpl_parameterlist *, + cpl_parameterlist *); CPL_END_DECLS diff -Nru esorex-3.13.5+ds/src/er_json.c esorex-3.13.6+ds/src/er_json.c --- esorex-3.13.5+ds/src/er_json.c 2021-06-02 15:06:13.000000000 +0000 +++ esorex-3.13.6+ds/src/er_json.c 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 European Southern Observatory * * 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 @@ -34,9 +34,9 @@ #ifdef HAVE_LIBAVCALL #include #else - #ifdef HAVE_LIBFFI - #include - #endif +#ifdef HAVE_LIBFFI +#include +#endif #endif @@ -83,21 +83,21 @@ * ] * */ -cpl_error_code er_frameset_to_json(const cpl_frameset * frameset, - const char* json_file) +cpl_error_code +er_frameset_to_json(const cpl_frameset *frameset, const char *json_file) { - FILE * fjson; - cpl_size nframes; - cpl_size iframe; + FILE *fjson; + cpl_size nframes; + cpl_size iframe; - /* Sanity checks */ - if(!frameset || !json_file) + /* Sanity checks */ + if (!frameset || !json_file) return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Null input"); /* Open the output file */ fjson = fopen(json_file, "w"); - if(!fjson) + if (!fjson) return cpl_error_set_message(cpl_func, CPL_ERROR_FILE_NOT_CREATED, "Cannot open JSON file for writing"); @@ -108,11 +108,10 @@ nframes = cpl_frameset_get_size(frameset); iframe = 0; - for(iframe = 0 ; iframe < nframes; iframe++) - { - const cpl_frame * frame; - char * filename; - char * category; + for (iframe = 0; iframe < nframes; iframe++) { + const cpl_frame *frame; + char *filename; + char *category; /* Get this frame */ frame = cpl_frameset_get_position_const(frameset, iframe); @@ -123,13 +122,13 @@ fprintf(fjson, " {\n"); /* Write this frame fields */ - if(strlen(filename) > 0) - fprintf(fjson, " \"name\": \"%s\",\n",filename); - if(strlen(category) > 0) - fprintf(fjson, " \"category\": \"%s\"\n",category); + if (strlen(filename) > 0) + fprintf(fjson, " \"name\": \"%s\",\n", filename); + if (strlen(category) > 0) + fprintf(fjson, " \"category\": \"%s\"\n", category); /* Close JSON item */ - if(iframe == cpl_frameset_get_size(frameset) - 1) + if (iframe == cpl_frameset_get_size(frameset) - 1) fprintf(fjson, " }\n"); else fprintf(fjson, " },\n"); @@ -160,33 +159,33 @@ * ifu_transmission.fits IFU_TRANSMISSION * */ -cpl_error_code er_frameset_to_text(const cpl_frameset * frameset, - const char* text_file) +cpl_error_code +er_frameset_to_text(const cpl_frameset *frameset, const char *text_file) { - FILE * ftext; - cpl_size nframes; - cpl_size iframe; + FILE *ftext; + cpl_size nframes; + cpl_size iframe; - /* Sanity checks */ - if(!frameset || !text_file) + /* Sanity checks */ + if (!frameset || !text_file) return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Null input"); /* Open the output file */ ftext = fopen(text_file, "w"); - if(!ftext) + if (!ftext) return cpl_error_set_message(cpl_func, CPL_ERROR_FILE_NOT_CREATED, - "Cannot open file %s for writing", text_file); + "Cannot open file %s for writing", + text_file); /* Loop on frames */ nframes = cpl_frameset_get_size(frameset); iframe = 0; - for(iframe = 0 ; iframe < nframes; iframe++) - { - const cpl_frame * frame; - const char * filename; - const char * category; + for (iframe = 0; iframe < nframes; iframe++) { + const cpl_frame *frame; + const char *filename; + const char *category; /* Get this frame */ frame = cpl_frameset_get_position_const(frameset, iframe); @@ -195,9 +194,8 @@ /* Writing a frame*/ fprintf(ftext, "%s %s", filename, category); - if(iframe != cpl_frameset_get_size(frameset) - 1) + if (iframe != cpl_frameset_get_size(frameset) - 1) fprintf(ftext, "\n"); - } fclose(ftext); @@ -235,21 +233,22 @@ * ] * */ -cpl_error_code er_recipe_parameterlist_to_json(const cpl_parameterlist * plist, - const char * recipe_name, - const char * json_file) +cpl_error_code +er_recipe_parameterlist_to_json(const cpl_parameterlist *plist, + const char *recipe_name, + const char *json_file) { - FILE * fjson; - const cpl_parameter * param; + FILE *fjson; + const cpl_parameter *param; - /* Sanity checks */ - if(!plist || !recipe_name || !json_file) + /* Sanity checks */ + if (!plist || !recipe_name || !json_file) return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Null input"); /* Open the output file */ fjson = fopen(json_file, "w"); - if(!fjson) + if (!fjson) return cpl_error_set_message(cpl_func, CPL_ERROR_FILE_NOT_CREATED, "Cannot open JSON file for writing"); @@ -259,30 +258,28 @@ /* Loop on parameters */ param = cpl_parameterlist_get_first_const(plist); - while (param != NULL) - { - if (cpl_parameter_is_enabled(param, CPL_PARAMETER_MODE_CFG)) - { - char * description; - char * name; - char * display_name; - cpl_type valtype; + while (param != NULL) { + if (cpl_parameter_is_enabled(param, CPL_PARAMETER_MODE_CFG)) { + char *description; + char *name; + char *display_name; + cpl_type valtype; cpl_parameter_class partype; - int ivalue; - int bvalue; - double dvalue; - char * svalue; - int enum_size; - int ienum; + int ivalue; + int bvalue; + double dvalue; + char *svalue; + int enum_size; + int ienum; description = er_json_escape_string(cpl_parameter_get_help(param)); name = er_json_escape_string(cpl_parameter_get_name(param)); display_name = er_json_escape_string( - cpl_parameter_get_alias(param, CPL_PARAMETER_MODE_CLI)); - if(display_name == NULL) - { + cpl_parameter_get_alias(param, CPL_PARAMETER_MODE_CLI)); + if (display_name == NULL) { cpl_error_reset(); - display_name = er_json_escape_string(cpl_parameter_get_name(param)); + display_name = + er_json_escape_string(cpl_parameter_get_name(param)); } valtype = cpl_parameter_get_type(param); partype = cpl_parameter_get_class(param); @@ -291,11 +288,10 @@ fprintf(fjson, " {\n"); /* Write this parameter fields */ - if(strlen(name) > 0) - fprintf(fjson, " \"name\": \"%s\",\n",name); + if (strlen(name) > 0) + fprintf(fjson, " \"name\": \"%s\",\n", name); /* Write value and value type */ - switch (valtype) - { + switch (valtype) { case CPL_TYPE_BOOL: bvalue = cpl_parameter_get_bool(param); if (bvalue == 0) @@ -307,32 +303,34 @@ case CPL_TYPE_INT: ivalue = cpl_parameter_get_int(param); - fprintf(fjson, " \"value\": %d,\n",ivalue); + fprintf(fjson, " \"value\": %d,\n", ivalue); fprintf(fjson, " \"valtype\": \"int\",\n"); break; case CPL_TYPE_DOUBLE: dvalue = cpl_parameter_get_double(param); - fprintf(fjson, " \"value\": %.17g,\n",dvalue); //IEEE 754 double + fprintf(fjson, " \"value\": %.17g,\n", + dvalue); //IEEE 754 double fprintf(fjson, " \"valtype\": \"double\",\n"); break; case CPL_TYPE_STRING: - svalue = er_json_escape_string(cpl_parameter_get_string(param)); - fprintf(fjson, " \"value\": \"%s\",\n",svalue); + svalue = + er_json_escape_string(cpl_parameter_get_string(param)); + fprintf(fjson, " \"value\": \"%s\",\n", svalue); fprintf(fjson, " \"valtype\": \"string\",\n"); cpl_free(svalue); break; default: - return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, - "Type not supported for cpl_propertylist"); + return cpl_error_set_message( + cpl_func, CPL_ERROR_TYPE_MISMATCH, + "Type not supported for cpl_propertylist"); break; } /* Write parameter type (called class inside CPL) */ - switch (partype) - { + switch (partype) { case CPL_PARAMETER_CLASS_VALUE: fprintf(fjson, " \"partype\": \"value\",\n"); break; @@ -341,83 +339,88 @@ Only integers and doubles are supported */ case CPL_PARAMETER_CLASS_RANGE: fprintf(fjson, " \"partype\": \"range\",\n"); - switch (valtype) - { + switch (valtype) { case CPL_TYPE_INT: ivalue = cpl_parameter_get_range_min_int(param); - fprintf(fjson, " \"valmin\": %d,\n",ivalue); + fprintf(fjson, " \"valmin\": %d,\n", ivalue); ivalue = cpl_parameter_get_range_max_int(param); - fprintf(fjson, " \"valmax\": %d,\n",ivalue); + fprintf(fjson, " \"valmax\": %d,\n", ivalue); break; case CPL_TYPE_DOUBLE: dvalue = cpl_parameter_get_range_min_double(param); - fprintf(fjson, " \"valmin\": %.17g,\n",dvalue); + fprintf(fjson, " \"valmin\": %.17g,\n", dvalue); dvalue = cpl_parameter_get_range_max_double(param); - fprintf(fjson, " \"valmax\": %.17g,\n",dvalue); + fprintf(fjson, " \"valmax\": %.17g,\n", dvalue); break; default: - return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, - "Range parameters not supported for this type"); + return cpl_error_set_message( + cpl_func, CPL_ERROR_TYPE_MISMATCH, + "Range parameters not supported for this type"); break; } break; /* If an enum, write the list of alternatives as a JSON list. Only integers, doubles and strings are supported */ - case CPL_PARAMETER_CLASS_ENUM: - fprintf(fjson, " \"partype\": \"enum\",\n"); - enum_size = cpl_parameter_get_enum_size(param); - fprintf(fjson, " \"valenum\": ["); - for(ienum = 0; ienum < enum_size; ienum++) - { - switch (valtype) - { - case CPL_TYPE_INT: - ivalue = cpl_parameter_get_enum_int(param, ienum); - fprintf(fjson, " %d ",ivalue); - break; - - case CPL_TYPE_DOUBLE: - dvalue = cpl_parameter_get_enum_double(param, ienum); - fprintf(fjson, " %.17g ",dvalue); - break; - - case CPL_TYPE_STRING: - svalue = er_json_escape_string( - cpl_parameter_get_enum_string(param, ienum)); - fprintf(fjson, " \"%s\" ",svalue); - cpl_free(svalue); - break; - default: - return cpl_error_set_message(cpl_func, - CPL_ERROR_TYPE_MISMATCH, - "Enum parameters not supported for this type"); - break; - } - if(ienum != enum_size - 1) - fprintf(fjson, ","); - } - fprintf(fjson, "],\n"); - break; - default: - return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, - "Parameter class not supported for cpl_propertylist"); - break; + case CPL_PARAMETER_CLASS_ENUM: + fprintf(fjson, " \"partype\": \"enum\",\n"); + enum_size = cpl_parameter_get_enum_size(param); + fprintf(fjson, " \"valenum\": ["); + for (ienum = 0; ienum < enum_size; ienum++) { + switch (valtype) { + case CPL_TYPE_INT: + ivalue = + cpl_parameter_get_enum_int(param, ienum); + fprintf(fjson, " %d ", ivalue); + break; + + case CPL_TYPE_DOUBLE: + dvalue = + cpl_parameter_get_enum_double(param, ienum); + fprintf(fjson, " %.17g ", dvalue); + break; + + case CPL_TYPE_STRING: + svalue = er_json_escape_string( + cpl_parameter_get_enum_string(param, + ienum)); + fprintf(fjson, " \"%s\" ", svalue); + cpl_free(svalue); + break; + default: + return cpl_error_set_message( + cpl_func, CPL_ERROR_TYPE_MISMATCH, + "Enum parameters not supported for this " + "type"); + break; + } + if (ienum != enum_size - 1) + fprintf(fjson, ","); + } + fprintf(fjson, "],\n"); + break; + default: + return cpl_error_set_message( + cpl_func, CPL_ERROR_TYPE_MISMATCH, + "Parameter class not supported for cpl_propertylist"); + break; } - if(strlen(display_name) > 0) - fprintf(fjson, " \"display_name\": \"%s\",\n",display_name); - if(strlen(description) > 0) - { - if(strlen(recipe_name) > 0) //Description is not the last field - fprintf(fjson, " \"description\": \"%s\",\n",description); - else //Description is the last field - fprintf(fjson, " \"description\": \"%s\"\n",description); + if (strlen(display_name) > 0) + fprintf(fjson, " \"display_name\": \"%s\",\n", display_name); + if (strlen(description) > 0) { + if (strlen(recipe_name) > + 0) //Description is not the last field + fprintf(fjson, " \"description\": \"%s\",\n", + description); + else //Description is the last field + fprintf(fjson, " \"description\": \"%s\"\n", + description); } - if(strlen(recipe_name) > 0) - fprintf(fjson, " \"recipe\": \"%s\"\n",recipe_name); + if (strlen(recipe_name) > 0) + fprintf(fjson, " \"recipe\": \"%s\"\n", recipe_name); /* Close JSON item */ - if(param == cpl_parameterlist_get_last_const(plist)) + if (param == cpl_parameterlist_get_last_const(plist)) fprintf(fjson, " }\n"); else fprintf(fjson, " },\n"); @@ -428,7 +431,6 @@ } param = cpl_parameterlist_get_next_const(plist); - } /* Close JSON list */ fprintf(fjson, "]\n"); @@ -437,50 +439,44 @@ return CPL_ERROR_NONE; } -char * er_json_escape_string(const char * str) +char * +er_json_escape_string(const char *str) { - char * escaped_str; + char *escaped_str; size_t i, j; - if(str == NULL) + if (str == NULL) return NULL; - escaped_str = cpl_malloc(2*strlen(str) * sizeof(char)+1); - for(i = 0, j = 0; i < strlen(str); i++) - { - if(str[i] == 0x22 || str[i] == 0x5C || str[i] == 0x2F ) - { + escaped_str = cpl_malloc(2 * strlen(str) * sizeof(char) + 1); + for (i = 0, j = 0; i < strlen(str); i++) { + if (str[i] == 0x22 || str[i] == 0x5C || str[i] == 0x2F) { escaped_str[j++] = '\\'; escaped_str[j++] = str[i]; } - else if(str[i] == 0x08) - { + else if (str[i] == 0x08) { escaped_str[j++] = '\\'; escaped_str[j++] = 'b'; } - else if(str[i] == 0x09) - { + else if (str[i] == 0x09) { escaped_str[j++] = '\\'; escaped_str[j++] = 't'; } - else if(str[i] == 0x0A) - { + else if (str[i] == 0x0A) { escaped_str[j++] = '\\'; escaped_str[j++] = 'n'; } - else if(str[i] == 0x0C) - { + else if (str[i] == 0x0C) { escaped_str[j++] = '\\'; escaped_str[j++] = 'f'; } - else if(str[i] == 0x0D) - { + else if (str[i] == 0x0D) { escaped_str[j++] = '\\'; escaped_str[j++] = 'r'; } else escaped_str[j++] = str[i]; } - escaped_str[j++]='\0'; + escaped_str[j++] = '\0'; escaped_str = cpl_realloc(escaped_str, j); return escaped_str; @@ -490,17 +486,16 @@ * Creates and returns a properly escaped JSON string surrounded by quotes. * The result must be deleted with cpl_free(). */ -static char * prepare_escaped_string(const char * string) +static char * +prepare_escaped_string(const char *string) { - if (string != NULL) - { - char * tmp = er_json_escape_string(string); - char * result = cpl_sprintf("\"%s\"", tmp); + if (string != NULL) { + char *tmp = er_json_escape_string(string); + char *result = cpl_sprintf("\"%s\"", tmp); cpl_free(tmp); return result; } - else - { + else { return cpl_strdup("null"); } } @@ -511,42 +506,45 @@ * If an error occurred then NULL is returned. Otherwise the result must be * cleaned up by the caller with cpl_free(). */ -static char * parameter_to_json(const cpl_parameter * param) +static char * +parameter_to_json(const cpl_parameter *param) { assert(param != NULL); - const char * present = cpl_parameter_get_default_flag(param) ? "true" - : "false"; + const char *present = + cpl_parameter_get_default_flag(param) ? "true" : "false"; int param_id = cpl_parameter_get_id(param); - const char * tag = cpl_parameter_get_tag(param); - const char * cli_enabled - = cpl_parameter_is_enabled(param, CPL_PARAMETER_MODE_CLI) ? "true" - : "false"; - const char * env_enabled - = cpl_parameter_is_enabled(param, CPL_PARAMETER_MODE_ENV) ? "true" - : "false"; - const char * cfg_enabled - = cpl_parameter_is_enabled(param, CPL_PARAMETER_MODE_CFG) ? "true" - : "false"; - const char * cli_alias = cpl_parameter_get_alias(param, - CPL_PARAMETER_MODE_CLI); - const char * env_alias = cpl_parameter_get_alias(param, - CPL_PARAMETER_MODE_ENV); - const char * cfg_alias = cpl_parameter_get_alias(param, - CPL_PARAMETER_MODE_CFG); - if (cpl_error_get_code() != CPL_ERROR_NONE) return NULL; - - char * tmp = NULL; - char * value = NULL; - char * default_value = NULL; + const char *tag = cpl_parameter_get_tag(param); + const char *cli_enabled = + cpl_parameter_is_enabled(param, CPL_PARAMETER_MODE_CLI) ? "true" + : "false"; + const char *env_enabled = + cpl_parameter_is_enabled(param, CPL_PARAMETER_MODE_ENV) ? "true" + : "false"; + const char *cfg_enabled = + cpl_parameter_is_enabled(param, CPL_PARAMETER_MODE_CFG) ? "true" + : "false"; + const char *cli_alias = + cpl_parameter_get_alias(param, CPL_PARAMETER_MODE_CLI); + const char *env_alias = + cpl_parameter_get_alias(param, CPL_PARAMETER_MODE_ENV); + const char *cfg_alias = + cpl_parameter_get_alias(param, CPL_PARAMETER_MODE_CFG); + if (cpl_error_get_code() != CPL_ERROR_NONE) + return NULL; + + char *tmp = NULL; + char *value = NULL; + char *default_value = NULL; cpl_type value_type = cpl_parameter_get_type(param); - switch (value_type) - { + switch (value_type) { case CPL_TYPE_BOOL: value = (cpl_parameter_get_bool(param) == TRUE) - ? cpl_strdup("true") : cpl_strdup("false"); + ? cpl_strdup("true") + : cpl_strdup("false"); default_value = (cpl_parameter_get_default_bool(param) == TRUE) - ? cpl_strdup("true") : cpl_strdup("false"); + ? cpl_strdup("true") + : cpl_strdup("false"); break; case CPL_TYPE_INT: @@ -565,8 +563,8 @@ tmp = er_json_escape_string(cpl_parameter_get_string(param)); value = cpl_sprintf("\"%s\"", tmp); cpl_free(tmp); - tmp = er_json_escape_string( - cpl_parameter_get_default_string(param)); + tmp = + er_json_escape_string(cpl_parameter_get_default_string(param)); default_value = cpl_sprintf("\"%s\"", tmp); cpl_free(tmp); break; @@ -577,13 +575,12 @@ return NULL; } - const char * class_name = NULL; - char * range_min = NULL; - char * range_max = NULL; - char * choices = NULL; + const char *class_name = NULL; + char *range_min = NULL; + char *range_max = NULL; + char *choices = NULL; int n = 0; - switch (cpl_parameter_get_class(param)) - { + switch (cpl_parameter_get_class(param)) { case CPL_PARAMETER_CLASS_VALUE: class_name = "value"; break; @@ -592,19 +589,22 @@ /* If parameter is a range then prepare the minimum and maximum values. Only integers and doubles are supported */ class_name = "range"; - switch (value_type) - { + switch (value_type) { case CPL_TYPE_INT: - range_min = cpl_sprintf("%d", + range_min = + cpl_sprintf("%d", cpl_parameter_get_range_min_int(param)); - range_max = cpl_sprintf("%d", + range_max = + cpl_sprintf("%d", cpl_parameter_get_range_max_int(param)); break; case CPL_TYPE_DOUBLE: - range_min = cpl_sprintf("%.17e", + range_min = + cpl_sprintf("%.17e", cpl_parameter_get_range_min_double(param)); - range_max = cpl_sprintf("%.17e", + range_max = + cpl_sprintf("%.17e", cpl_parameter_get_range_max_double(param)); break; default: @@ -621,20 +621,16 @@ /* If parameter is an enum then prepare the list of choices. Only integers, doubles and strings are supported. */ class_name = "enum"; - for (n = 0; n < cpl_parameter_get_enum_size(param); ++n) - { + for (n = 0; n < cpl_parameter_get_enum_size(param); ++n) { /* For each enum we print the value and add it to the 'choices' string. These must be comma separated. */ - switch (value_type) - { + switch (value_type) { case CPL_TYPE_INT: - if (n == 0) - { + if (n == 0) { int val = cpl_parameter_get_enum_int(param, n); choices = cpl_sprintf("[\n %d", val); } - else - { + else { int val = cpl_parameter_get_enum_int(param, n); tmp = cpl_sprintf("%s,\n %d", choices, val); @@ -644,16 +640,14 @@ break; case CPL_TYPE_DOUBLE: - if (n == 0) - { - double val = cpl_parameter_get_enum_double(param, - n); + if (n == 0) { + double val = + cpl_parameter_get_enum_double(param, n); choices = cpl_sprintf("[\n %.17e", val); } - else - { - double val = cpl_parameter_get_enum_double(param, - n); + else { + double val = + cpl_parameter_get_enum_double(param, n); tmp = cpl_sprintf("%s,\n %.17e", choices, val); cpl_free(choices); @@ -662,19 +656,17 @@ break; case CPL_TYPE_STRING: - if (n == 0) - { - char * val = er_json_escape_string( - cpl_parameter_get_enum_string(param, n)); + if (n == 0) { + char *val = er_json_escape_string( + cpl_parameter_get_enum_string(param, n)); choices = cpl_sprintf("[\n \"%s\"", val); cpl_free(val); } - else - { - char * val = er_json_escape_string( - cpl_parameter_get_enum_string(param, n)); + else { + char *val = er_json_escape_string( + cpl_parameter_get_enum_string(param, n)); tmp = cpl_sprintf("%s,\n \"%s\"", - choices, val); + choices, val); cpl_free(choices); cpl_free(val); choices = tmp; @@ -690,8 +682,7 @@ return NULL; } } - if (choices == NULL) - { + if (choices == NULL) { cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "At least one enumeration choice must be" " given for cpl_parameter."); @@ -699,8 +690,7 @@ cpl_free(default_value); return NULL; } - else - { + else { /* End the JSON list of choices with a ']'. */ tmp = cpl_sprintf("%s\n ]", choices); cpl_free(choices); @@ -721,97 +711,91 @@ /* Prepare the tag and alias strings. We have to take into account that these might be NULL. */ - char * tagstr = prepare_escaped_string(tag); - char * cli_alias_str = prepare_escaped_string(cli_alias); - char * env_alias_str = prepare_escaped_string(env_alias); - char * cfg_alias_str = prepare_escaped_string(cfg_alias); + char *tagstr = prepare_escaped_string(tag); + char *cli_alias_str = prepare_escaped_string(cli_alias); + char *env_alias_str = prepare_escaped_string(env_alias); + char *cfg_alias_str = prepare_escaped_string(cfg_alias); /* Create the full JSON output text for the parameter object. */ - char * json = NULL; - if (choices != NULL) - { - json = cpl_sprintf( - "{\n" - " \"name\": \"%s\",\n" - " \"class\": \"%s\",\n" - " \"id\": %d,\n" - " \"description\": \"%s\",\n" - " \"context\": \"%s\",\n" - " \"value\": %s,\n" - " \"default\": %s,\n" - " \"choices\": %s,\n" - " \"present\": %s,\n" - " \"tag\": %s,\n" - " \"cli_enabled\": %s,\n" - " \"cli_alias\": %s,\n" - " \"env_enabled\": %s,\n" - " \"env_alias\": %s,\n" - " \"cfg_enabled\": %s,\n" - " \"cfg_alias\": %s\n" - " }", - cpl_parameter_get_name(param), class_name, param_id, - cpl_parameter_get_help(param), cpl_parameter_get_context(param), - value, default_value, choices, present, tagstr, - cli_enabled, cli_alias_str, env_enabled, env_alias_str, - cfg_enabled, cfg_alias_str - ); + char *json = NULL; + if (choices != NULL) { + json = + cpl_sprintf("{\n" + " \"name\": \"%s\",\n" + " \"class\": \"%s\",\n" + " \"id\": %d,\n" + " \"description\": \"%s\",\n" + " \"context\": \"%s\",\n" + " \"value\": %s,\n" + " \"default\": %s,\n" + " \"choices\": %s,\n" + " \"present\": %s,\n" + " \"tag\": %s,\n" + " \"cli_enabled\": %s,\n" + " \"cli_alias\": %s,\n" + " \"env_enabled\": %s,\n" + " \"env_alias\": %s,\n" + " \"cfg_enabled\": %s,\n" + " \"cfg_alias\": %s\n" + " }", + cpl_parameter_get_name(param), class_name, param_id, + cpl_parameter_get_help(param), + cpl_parameter_get_context(param), value, default_value, + choices, present, tagstr, cli_enabled, cli_alias_str, + env_enabled, env_alias_str, cfg_enabled, cfg_alias_str); } - else if (range_min != NULL) - { + else if (range_min != NULL) { assert(range_max != NULL); - json = cpl_sprintf( - "{\n" - " \"name\": \"%s\",\n" - " \"class\": \"%s\",\n" - " \"id\": %d,\n" - " \"description\": \"%s\",\n" - " \"context\": \"%s\",\n" - " \"value\": %s,\n" - " \"default\": %s,\n" - " \"min\": %s,\n" - " \"max\": %s,\n" - " \"present\": %s,\n" - " \"tag\": %s,\n" - " \"cli_enabled\": %s,\n" - " \"cli_alias\": %s,\n" - " \"env_enabled\": %s,\n" - " \"env_alias\": %s,\n" - " \"cfg_enabled\": %s,\n" - " \"cfg_alias\": %s\n" - " }", - cpl_parameter_get_name(param), class_name, param_id, - cpl_parameter_get_help(param), cpl_parameter_get_context(param), - value, default_value, range_min, range_max, present, - tagstr, cli_enabled, cli_alias_str, env_enabled, env_alias_str, - cfg_enabled, cfg_alias_str - ); - } - else - { - json = cpl_sprintf( - "{\n" - " \"name\": \"%s\",\n" - " \"class\": \"%s\",\n" - " \"id\": %d,\n" - " \"description\": \"%s\",\n" - " \"context\": \"%s\",\n" - " \"value\": %s,\n" - " \"default\": %s,\n" - " \"present\": %s,\n" - " \"tag\": %s,\n" - " \"cli_enabled\": %s,\n" - " \"cli_alias\": %s,\n" - " \"env_enabled\": %s,\n" - " \"env_alias\": %s,\n" - " \"cfg_enabled\": %s,\n" - " \"cfg_alias\": %s\n" - " }", - cpl_parameter_get_name(param), class_name, param_id, - cpl_parameter_get_help(param), cpl_parameter_get_context(param), - value, default_value, present, tagstr, - cli_enabled, cli_alias_str, env_enabled, env_alias_str, - cfg_enabled, cfg_alias_str - ); + json = cpl_sprintf("{\n" + " \"name\": \"%s\",\n" + " \"class\": \"%s\",\n" + " \"id\": %d,\n" + " \"description\": \"%s\",\n" + " \"context\": \"%s\",\n" + " \"value\": %s,\n" + " \"default\": %s,\n" + " \"min\": %s,\n" + " \"max\": %s,\n" + " \"present\": %s,\n" + " \"tag\": %s,\n" + " \"cli_enabled\": %s,\n" + " \"cli_alias\": %s,\n" + " \"env_enabled\": %s,\n" + " \"env_alias\": %s,\n" + " \"cfg_enabled\": %s,\n" + " \"cfg_alias\": %s\n" + " }", + cpl_parameter_get_name(param), class_name, param_id, + cpl_parameter_get_help(param), + cpl_parameter_get_context(param), value, + default_value, range_min, range_max, present, tagstr, + cli_enabled, cli_alias_str, env_enabled, + env_alias_str, cfg_enabled, cfg_alias_str); + } + else { + json = + cpl_sprintf("{\n" + " \"name\": \"%s\",\n" + " \"class\": \"%s\",\n" + " \"id\": %d,\n" + " \"description\": \"%s\",\n" + " \"context\": \"%s\",\n" + " \"value\": %s,\n" + " \"default\": %s,\n" + " \"present\": %s,\n" + " \"tag\": %s,\n" + " \"cli_enabled\": %s,\n" + " \"cli_alias\": %s,\n" + " \"env_enabled\": %s,\n" + " \"env_alias\": %s,\n" + " \"cfg_enabled\": %s,\n" + " \"cfg_alias\": %s\n" + " }", + cpl_parameter_get_name(param), class_name, param_id, + cpl_parameter_get_help(param), + cpl_parameter_get_context(param), value, default_value, + present, tagstr, cli_enabled, cli_alias_str, + env_enabled, env_alias_str, cfg_enabled, cfg_alias_str); } /* Cleaning up allocated memory. NOTE: it is safe to pass NULL to cpl_free @@ -834,26 +818,25 @@ * If an error occurred then NULL is returned. Otherwise the result must be * cleaned up by the caller with cpl_free(). */ -static char * frame_to_json(const cpl_frame * frame) +static char * +frame_to_json(const cpl_frame *frame) { assert(frame != NULL); - char * filename = er_json_escape_string(cpl_frame_get_filename(frame)); - char * tag = er_json_escape_string(cpl_frame_get_tag(frame)); - unsigned int type = (unsigned int) cpl_frame_get_type(frame); - unsigned int group = (unsigned int) cpl_frame_get_group(frame); - unsigned int level = (unsigned int) cpl_frame_get_level(frame); - - char * json = cpl_sprintf( - "{\n" - " \"filename\": \"%s\",\n" - " \"tag\": \"%s\",\n" - " \"type\": %u,\n" - " \"group\": %u,\n" - " \"level\": %u\n" - " }", - filename, tag, type, group, level - ); + char *filename = er_json_escape_string(cpl_frame_get_filename(frame)); + char *tag = er_json_escape_string(cpl_frame_get_tag(frame)); + unsigned int type = (unsigned int)cpl_frame_get_type(frame); + unsigned int group = (unsigned int)cpl_frame_get_group(frame); + unsigned int level = (unsigned int)cpl_frame_get_level(frame); + + char *json = cpl_sprintf("{\n" + " \"filename\": \"%s\",\n" + " \"tag\": \"%s\",\n" + " \"type\": %u,\n" + " \"group\": %u,\n" + " \"level\": %u\n" + " }", + filename, tag, type, group, level); cpl_free(tag); cpl_free(filename); @@ -914,35 +897,31 @@ * @note The caller must free the result with @c cpl_free() once it is no longer * needed. */ -char * er_plugin_to_json(const cpl_plugin * plugin) +char * +er_plugin_to_json(const cpl_plugin *plugin) { cpl_error_ensure(plugin != NULL, CPL_ERROR_NULL_INPUT, return NULL, "Plugin is NULL."); /* Identify the needed parts of the recipe data that have to be serialised into JSON and sent to the Python interpreter. */ - cpl_parameterlist * params = NULL; - cpl_frameset * frames = NULL; - cpl_recipeconfig * config = NULL; + cpl_parameterlist *params = NULL; + cpl_frameset *frames = NULL; + cpl_recipeconfig *config = NULL; unsigned long plugin_type = cpl_plugin_get_type(plugin); - switch (plugin_type) - { - case CPL_PLUGIN_TYPE_RECIPE: - { - cpl_recipe * recipe = (cpl_recipe *) plugin; - params = recipe->parameters; - frames = recipe->frames; - } - break; - - case CPL_PLUGIN_TYPE_RECIPE_V2: - { - cpl_recipe2 * recipe = (cpl_recipe2 *) plugin; - params = recipe->base.parameters; - frames = recipe->base.frames; - config = recipe->config; - } - break; + switch (plugin_type) { + case CPL_PLUGIN_TYPE_RECIPE: { + cpl_recipe *recipe = (cpl_recipe *)plugin; + params = recipe->parameters; + frames = recipe->frames; + } break; + + case CPL_PLUGIN_TYPE_RECIPE_V2: { + cpl_recipe2 *recipe = (cpl_recipe2 *)plugin; + params = recipe->base.parameters; + frames = recipe->base.frames; + config = recipe->config; + } break; default: cpl_error_set_message(cpl_func, CPL_ERROR_UNSUPPORTED_MODE, @@ -954,37 +933,30 @@ /* Construct a properly formatted JSON array of parameters from the plugin's CPL parameter list. If no parameters are given then '[]' is used for the JSON text. */ - char * itemsjson = NULL; - if (params != NULL) - { - const cpl_parameter * firstpar - = cpl_parameterlist_get_first_const(params); - const cpl_parameter * p = NULL; - for (p = firstpar; - p != NULL; - p = cpl_parameterlist_get_next_const(params)) - { - char * paramjson = parameter_to_json(p); - if (p != firstpar) - { - char * tmp = cpl_sprintf("%s,\n %s", itemsjson, paramjson); + char *itemsjson = NULL; + if (params != NULL) { + const cpl_parameter *firstpar = + cpl_parameterlist_get_first_const(params); + const cpl_parameter *p = NULL; + for (p = firstpar; p != NULL; + p = cpl_parameterlist_get_next_const(params)) { + char *paramjson = parameter_to_json(p); + if (p != firstpar) { + char *tmp = cpl_sprintf("%s,\n %s", itemsjson, paramjson); cpl_free(paramjson); cpl_free(itemsjson); itemsjson = tmp; } - else - { + else { itemsjson = paramjson; } } } - char * parlistjson; - if (itemsjson != NULL) - { + char *parlistjson; + if (itemsjson != NULL) { parlistjson = cpl_sprintf("[\n %s\n ]", itemsjson); } - else - { + else { parlistjson = cpl_strdup("[]"); } cpl_free(itemsjson); @@ -993,91 +965,78 @@ frameset object. If there are not frames then '[]' is used for the JSON text. */ itemsjson = NULL; - if (frames != NULL) - { - cpl_frameset_iterator * frameiter = cpl_frameset_iterator_new(frames); - const cpl_frame * firstframe - = cpl_frameset_iterator_get_const(frameiter); - const cpl_frame * frame = NULL; + if (frames != NULL) { + cpl_frameset_iterator *frameiter = cpl_frameset_iterator_new(frames); + const cpl_frame *firstframe = + cpl_frameset_iterator_get_const(frameiter); + const cpl_frame *frame = NULL; for (frame = firstframe; (frame = cpl_frameset_iterator_get_const(frameiter)) != NULL; - cpl_frameset_iterator_advance(frameiter, 1)) - { - char * framejson = frame_to_json(frame); - if (frame != firstframe) - { - char * tmp = cpl_sprintf("%s,\n %s", itemsjson, framejson); + cpl_frameset_iterator_advance(frameiter, 1)) { + char *framejson = frame_to_json(frame); + if (frame != firstframe) { + char *tmp = cpl_sprintf("%s,\n %s", itemsjson, framejson); cpl_free(framejson); cpl_free(itemsjson); itemsjson = tmp; } - else - { + else { itemsjson = framejson; } } cpl_frameset_iterator_delete(frameiter); } - char * framelistjson; - if (itemsjson != NULL) - { + char *framelistjson; + if (itemsjson != NULL) { framelistjson = cpl_sprintf("[\n %s\n ]", itemsjson); } - else - { + else { framelistjson = cpl_strdup("[]"); } cpl_free(itemsjson); /* Convert the recipe configuration object into JSON text if we are dealing with a recipe v2 structure. */ - char * configjson = NULL; - if (config != NULL) - { + char *configjson = NULL; + if (config != NULL) { itemsjson = NULL; - char ** tags = cpl_recipeconfig_get_tags(config); - if (tags == NULL) - { + char **tags = cpl_recipeconfig_get_tags(config); + if (tags == NULL) { cpl_free(parlistjson); cpl_free(framelistjson); return NULL; } - char ** tag = NULL; - for (tag = tags; *tag != NULL; ++tag) - { - char * tmp; + char **tag = NULL; + for (tag = tags; *tag != NULL; ++tag) { + char *tmp; cpl_size min, max; /* Encode the primary tag's input list as a JSON array of objects. */ - char * inputitems = NULL; - char ** inputs = cpl_recipeconfig_get_inputs(config, *tag); - if (inputs != NULL) - { + char *inputitems = NULL; + char **inputs = cpl_recipeconfig_get_inputs(config, *tag); + if (inputs != NULL) { inputitems = cpl_strdup("["); - char ** input = NULL; - for (input = inputs; *input != NULL; ++input) - { + char **input = NULL; + for (input = inputs; *input != NULL; ++input) { min = cpl_recipeconfig_get_min_count(config, *tag, *input); max = cpl_recipeconfig_get_max_count(config, *tag, *input); - char * inputstr = er_json_escape_string(*input); + char *inputstr = er_json_escape_string(*input); cpl_boolean first_item = (input == inputs); - tmp = cpl_sprintf( - "%s%s\n" - " {\n" - " \"tag\": \"%s\",\n" + tmp = cpl_sprintf("%s%s\n" + " {\n" + " \"tag\": \"%s\",\n" #if defined CPL_SIZE_BITS && CPL_SIZE_BITS == 32 - " \"min\": %d,\n" - " \"max\": %d\n" + " \"min\": %d,\n" + " \"max\": %d\n" #else - " \"min\": %lld,\n" - " \"max\": %lld\n" + " \"min\": %lld,\n" + " \"max\": %lld\n" #endif - " }", - inputitems, (first_item ? "" : ","), inputstr, - min, max - ); + " }", + inputitems, (first_item ? "" : ","), + inputstr, min, max); cpl_free(inputstr); cpl_free(inputitems); inputitems = tmp; @@ -1091,15 +1050,13 @@ /* Encode the primary tag's output list as a JSON array of strings. */ - char * outputitems = NULL; - char ** outputs = cpl_recipeconfig_get_outputs(config, *tag); - if (outputs != NULL) - { + char *outputitems = NULL; + char **outputs = cpl_recipeconfig_get_outputs(config, *tag); + if (outputs != NULL) { outputitems = cpl_strdup("["); - char ** output = NULL; - for (output = outputs; *output != NULL; ++output) - { - char * outputstr = er_json_escape_string(*output); + char **output = NULL; + for (output = outputs; *output != NULL; ++output) { + char *outputstr = er_json_escape_string(*output); cpl_boolean first_item = (output == outputs); tmp = cpl_sprintf("%s%s\n \"%s\"", outputitems, (first_item ? "" : ","), outputstr); @@ -1117,53 +1074,47 @@ /* If not the first tag entry in the list then add a comma and space prefix. Otherwise we create a new empty string for itemsjson. */ - if (tag != tags) - { + if (tag != tags) { tmp = cpl_sprintf("%s,\n ", itemsjson); cpl_free(itemsjson); itemsjson = tmp; } - else - { + else { itemsjson = cpl_strdup(""); } min = cpl_recipeconfig_get_min_count(config, *tag, *tag); max = cpl_recipeconfig_get_max_count(config, *tag, *tag); - char * tagstr = er_json_escape_string(*tag); + char *tagstr = er_json_escape_string(*tag); /* Start a new JSON object for the current tag. */ - tmp = cpl_sprintf( - "%s{\n" - " \"tag\": \"%s\",\n" + tmp = cpl_sprintf("%s{\n" + " \"tag\": \"%s\",\n" #if defined CPL_SIZE_BITS && CPL_SIZE_BITS == 32 - " \"min\": %d,\n" - " \"max\": %d", + " \"min\": %d,\n" + " \"max\": %d", #else - " \"min\": %lld,\n" - " \"max\": %lld", + " \"min\": %lld,\n" + " \"max\": %lld", #endif - itemsjson, tagstr, min, max - ); + itemsjson, tagstr, min, max); cpl_free(tagstr); cpl_free(itemsjson); itemsjson = tmp; /* Add the inputs if any are available. */ - if (inputitems != NULL) - { - tmp = cpl_sprintf("%s,\n \"inputs\": %s", - itemsjson, inputitems); + if (inputitems != NULL) { + tmp = cpl_sprintf("%s,\n \"inputs\": %s", itemsjson, + inputitems); cpl_free(itemsjson); itemsjson = tmp; cpl_free(inputitems); } /* Add the outputs if any are available. */ - if (outputitems != NULL) - { - tmp = cpl_sprintf("%s,\n \"outputs\": %s", - itemsjson, outputitems); + if (outputitems != NULL) { + tmp = cpl_sprintf("%s,\n \"outputs\": %s", itemsjson, + outputitems); cpl_free(itemsjson); itemsjson = tmp; cpl_free(outputitems); @@ -1180,64 +1131,56 @@ /* Create the final top level array if any tag items were available. Otherwise just use and empty JSON array. */ - if (itemsjson != NULL) - { + if (itemsjson != NULL) { configjson = cpl_sprintf("[\n %s\n ]", itemsjson); } - else - { + else { configjson = cpl_strdup("[]"); } cpl_free(itemsjson); } - char * name = er_json_escape_string(cpl_plugin_get_name(plugin)); + char *name = er_json_escape_string(cpl_plugin_get_name(plugin)); unsigned long version = cpl_plugin_get_version(plugin); - char * synopsis = er_json_escape_string(cpl_plugin_get_synopsis(plugin)); - char * desc = er_json_escape_string(cpl_plugin_get_description(plugin)); - char * author = er_json_escape_string(cpl_plugin_get_author(plugin)); - char * email = er_json_escape_string(cpl_plugin_get_email(plugin)); - char * copyright = er_json_escape_string(cpl_plugin_get_copyright(plugin)); - - char * json; - if (configjson == NULL) - { - json = cpl_sprintf( - "{\n" - " \"class\": \"unknown\",\n" - " \"name\": \"%s\",\n" - " \"version\": %lu,\n" - " \"synopsis\": \"%s\",\n" - " \"description\": \"%s\",\n" - " \"author\": \"%s\",\n" - " \"email\": \"%s\",\n" - " \"copyright\": \"%s\",\n" - " \"parameters\": %s,\n" - " \"frames\": %s\n" - " }", - name, version, synopsis, desc, author, email, copyright, - parlistjson, framelistjson - ); - } - else - { - json = cpl_sprintf( - "{\n" - " \"class\": \"unknown\",\n" - " \"name\": \"%s\",\n" - " \"version\": %lu,\n" - " \"synopsis\": \"%s\",\n" - " \"description\": \"%s\",\n" - " \"author\": \"%s\",\n" - " \"email\": \"%s\",\n" - " \"copyright\": \"%s\",\n" - " \"parameters\": %s,\n" - " \"frames\": %s,\n" - " \"recipeconfig\": %s\n" - " }", - name, version, synopsis, desc, author, email, copyright, - parlistjson, framelistjson, configjson - ); + char *synopsis = er_json_escape_string(cpl_plugin_get_synopsis(plugin)); + char *desc = er_json_escape_string(cpl_plugin_get_description(plugin)); + char *author = er_json_escape_string(cpl_plugin_get_author(plugin)); + char *email = er_json_escape_string(cpl_plugin_get_email(plugin)); + char *copyright = er_json_escape_string(cpl_plugin_get_copyright(plugin)); + + char *json; + if (configjson == NULL) { + json = cpl_sprintf("{\n" + " \"class\": \"unknown\",\n" + " \"name\": \"%s\",\n" + " \"version\": %lu,\n" + " \"synopsis\": \"%s\",\n" + " \"description\": \"%s\",\n" + " \"author\": \"%s\",\n" + " \"email\": \"%s\",\n" + " \"copyright\": \"%s\",\n" + " \"parameters\": %s,\n" + " \"frames\": %s\n" + " }", + name, version, synopsis, desc, author, email, + copyright, parlistjson, framelistjson); + } + else { + json = cpl_sprintf("{\n" + " \"class\": \"unknown\",\n" + " \"name\": \"%s\",\n" + " \"version\": %lu,\n" + " \"synopsis\": \"%s\",\n" + " \"description\": \"%s\",\n" + " \"author\": \"%s\",\n" + " \"email\": \"%s\",\n" + " \"copyright\": \"%s\",\n" + " \"parameters\": %s,\n" + " \"frames\": %s,\n" + " \"recipeconfig\": %s\n" + " }", + name, version, synopsis, desc, author, email, + copyright, parlistjson, framelistjson, configjson); } cpl_free(copyright); @@ -1261,16 +1204,16 @@ */ struct _er_json_node_ { - er_json_type type; /* Identifies which union member is active. */ + er_json_type type; /* Identifies which union member is active. */ union { - cx_map * object; - cx_list * array; - char * string; + cx_map *object; + cx_list *array; + char *string; double number; cpl_boolean bool; } value; - const char * location; /* Corresponding position in the JSON text. */ + const char *location; /* Corresponding position in the JSON text. */ }; /** @@ -1299,10 +1242,11 @@ * parsed from. * @return New node object. cpl_malloc() will abort if out of memory. */ -static er_json_node * er_json_node_new_null(const char * location) +static er_json_node * +er_json_node_new_null(const char *location) { assert(location != NULL); - er_json_node * obj = cpl_malloc(sizeof(er_json_node)); + er_json_node *obj = cpl_malloc(sizeof(er_json_node)); obj->type = JSON_NULL; obj->value.object = NULL; obj->location = location; @@ -1310,7 +1254,8 @@ } -static cxint _string_key_compare(cxcptr a, cxcptr b) +static cxint +_string_key_compare(cxcptr a, cxcptr b) { return (strcmp(a, b) < 0) ? TRUE : FALSE; } @@ -1322,10 +1267,11 @@ * @return New node corresponding to a mapping/dictionary. cpl_malloc() will * abort if out of memory. */ -static er_json_node * er_json_node_new_object(const char * location) +static er_json_node * +er_json_node_new_object(const char *location) { assert(location != NULL); - er_json_node * obj = cpl_malloc(sizeof(er_json_node)); + er_json_node *obj = cpl_malloc(sizeof(er_json_node)); obj->type = JSON_OBJECT; obj->value.object = cx_map_new(_string_key_compare, cpl_free, (cx_free_func)er_json_node_delete); @@ -1340,10 +1286,11 @@ * @return New node corresponding to a JSON array. cpl_malloc() will abort if * out of memory. */ -static er_json_node * er_json_node_new_array(const char * location) +static er_json_node * +er_json_node_new_array(const char *location) { assert(location != NULL); - er_json_node * obj = cpl_malloc(sizeof(er_json_node)); + er_json_node *obj = cpl_malloc(sizeof(er_json_node)); obj->type = JSON_ARRAY; obj->value.array = cx_list_new(); obj->location = location; @@ -1357,11 +1304,11 @@ * parsed from. * @return New node object. cpl_malloc() will abort if out of memory. */ -static er_json_node * er_json_node_new_string(const char * string, - const char * location) +static er_json_node * +er_json_node_new_string(const char *string, const char *location) { assert(location != NULL); - er_json_node * obj = cpl_malloc(sizeof(er_json_node)); + er_json_node *obj = cpl_malloc(sizeof(er_json_node)); obj->type = JSON_STRING; obj->value.string = cpl_strdup(string); obj->location = location; @@ -1375,11 +1322,11 @@ * parsed from. * @return New node storing a double. cpl_malloc() will abort if out of memory. */ -static er_json_node * er_json_node_new_number(double number, - const char * location) +static er_json_node * +er_json_node_new_number(double number, const char *location) { assert(location != NULL); - er_json_node * obj = cpl_malloc(sizeof(er_json_node)); + er_json_node *obj = cpl_malloc(sizeof(er_json_node)); obj->type = JSON_NUMBER; obj->value.number = number; obj->location = location; @@ -1393,11 +1340,11 @@ * parsed from. * @return New boolean node object. cpl_malloc() will abort if out of memory. */ -static er_json_node * er_json_node_new_bool(cpl_boolean bool, - const char * location) +static er_json_node * +er_json_node_new_bool(cpl_boolean bool, const char *location) { assert(location != NULL); - er_json_node * obj = cpl_malloc(sizeof(er_json_node)); + er_json_node *obj = cpl_malloc(sizeof(er_json_node)); obj->type = JSON_BOOL; obj->value.bool = bool; obj->location = location; @@ -1413,11 +1360,12 @@ * er_json_parse() function when it is no longer needed. * This will free the allocated buffers. */ -void er_json_node_delete(er_json_node * obj) +void +er_json_node_delete(er_json_node *obj) { - if (obj == NULL) return; - switch (obj->type) - { + if (obj == NULL) + return; + switch (obj->type) { case JSON_NULL: case JSON_NUMBER: case JSON_BOOL: @@ -1434,14 +1382,9 @@ cpl_free(obj->value.string); break; default: - assert( - obj->type == JSON_NULL || - obj->type == JSON_OBJECT || - obj->type == JSON_ARRAY || - obj->type == JSON_STRING || - obj->type == JSON_NUMBER || - obj->type == JSON_BOOL - ); + assert(obj->type == JSON_NULL || obj->type == JSON_OBJECT || + obj->type == JSON_ARRAY || obj->type == JSON_STRING || + obj->type == JSON_NUMBER || obj->type == JSON_BOOL); } cpl_free(obj); } @@ -1468,7 +1411,8 @@ *
  • JSON_OBJECT
  • * */ -er_json_type er_json_node_type(const er_json_node * obj) +er_json_type +er_json_node_type(const er_json_node *obj) { cpl_error_ensure(obj != NULL, CPL_ERROR_NULL_INPUT, return JSON_NULL, "JSON node is NULL."); @@ -1487,7 +1431,8 @@ * was parsed from. Allows to calculate the line and column numbers for error * messages using er_json_find_line_column(). */ -const char * er_json_node_location(const er_json_node * obj) +const char * +er_json_node_location(const er_json_node *obj) { cpl_error_ensure(obj != NULL, CPL_ERROR_NULL_INPUT, return NULL, "JSON node is NULL."); @@ -1507,7 +1452,8 @@ * For boolean JSON nodes this function will return its value as a * @c cpl_boolean. */ -cpl_boolean er_json_node_get_bool(const er_json_node * obj) +cpl_boolean +er_json_node_get_bool(const er_json_node *obj) { cpl_error_ensure(obj != NULL, CPL_ERROR_NULL_INPUT, return CPL_FALSE, "JSON node is NULL."); @@ -1529,7 +1475,8 @@ * For a number type JSON node this function will return its value as a double * precision floating point number. */ -double er_json_node_get_number(const er_json_node * obj) +double +er_json_node_get_number(const er_json_node *obj) { cpl_error_ensure(obj != NULL, CPL_ERROR_NULL_INPUT, return NAN, "JSON node is NULL."); @@ -1550,7 +1497,8 @@ * For a string type JSON node this function will return its value as a null * terminated character string. */ -const char * er_json_node_get_string(const er_json_node * obj) +const char * +er_json_node_get_string(const er_json_node *obj) { cpl_error_ensure(obj != NULL, CPL_ERROR_NULL_INPUT, return NULL, "JSON node is NULL."); @@ -1571,7 +1519,8 @@ * For array type JSON nodes this will return the number of elements in the * array. */ -cpl_size er_json_node_array_size(const er_json_node * obj) +cpl_size +er_json_node_array_size(const er_json_node *obj) { cpl_error_ensure(obj != NULL, CPL_ERROR_NULL_INPUT, return -1, "JSON node is NULL."); @@ -1592,7 +1541,8 @@ * * For array type JSON nodes this function will test if the array is empty. */ -cpl_boolean er_json_node_array_empty(const er_json_node * obj) +cpl_boolean +er_json_node_array_empty(const er_json_node *obj) { cpl_error_ensure(obj != NULL, CPL_ERROR_NULL_INPUT, return CPL_TRUE, "JSON node is NULL."); @@ -1613,7 +1563,8 @@ * For an array type node this function returns an iterator to the first element * of the array. */ -er_json_array_iterator er_json_node_array_begin(const er_json_node * obj) +er_json_array_iterator +er_json_node_array_begin(const er_json_node *obj) { cpl_error_ensure(obj != NULL, CPL_ERROR_NULL_INPUT, return NULL, "JSON node is NULL."); @@ -1644,7 +1595,8 @@ * } * @endcode */ -er_json_array_iterator er_json_node_array_end(const er_json_node * obj) +er_json_array_iterator +er_json_node_array_end(const er_json_node *obj) { cpl_error_ensure(obj != NULL, CPL_ERROR_NULL_INPUT, return NULL, "JSON node is NULL."); @@ -1666,8 +1618,8 @@ * For array type nodes this will increment an iterator object that was created * from the node. i.e. move the iterator to the next position in the array. */ -er_json_array_iterator er_json_node_array_next(const er_json_node * obj, - er_json_array_iterator current) +er_json_array_iterator +er_json_node_array_next(const er_json_node *obj, er_json_array_iterator current) { cpl_error_ensure(obj != NULL, CPL_ERROR_NULL_INPUT, return NULL, "JSON node is NULL."); @@ -1691,9 +1643,9 @@ * For array type nodes this will decrement an iterator object that was created * from the node. i.e. move the iterator to the previous position in the array. */ -er_json_array_iterator er_json_node_array_previous( - const er_json_node * obj, - er_json_array_iterator current) +er_json_array_iterator +er_json_node_array_previous(const er_json_node *obj, + er_json_array_iterator current) { cpl_error_ensure(obj != NULL, CPL_ERROR_NULL_INPUT, return NULL, "JSON node is NULL."); @@ -1718,8 +1670,8 @@ * given iterator. The iterator must have been created from the given array * node. */ -const er_json_node * er_json_node_array_get(const er_json_node * obj, - er_json_array_iterator iterator) +const er_json_node * +er_json_node_array_get(const er_json_node *obj, er_json_array_iterator iterator) { cpl_error_ensure(obj != NULL, CPL_ERROR_NULL_INPUT, return NULL, "JSON node is NULL."); @@ -1727,7 +1679,7 @@ "Iterator is NULL."); cpl_error_ensure(obj->type == JSON_ARRAY, CPL_ERROR_ILLEGAL_INPUT, return NULL, "JSON node is not an array."); - return (er_json_node *) cx_list_get(obj->value.array, iterator); + return (er_json_node *)cx_list_get(obj->value.array, iterator); } /* @@ -1738,7 +1690,8 @@ * NOTE: Takes ownership of value. i.e. the caller should no longer call * er_json_node_delete() for value after invoking this function. */ -static void er_json_node_array_append(er_json_node * obj, er_json_node * value) +static void +er_json_node_array_append(er_json_node *obj, er_json_node *value) { assert(obj != NULL); assert(obj->type == JSON_ARRAY); @@ -1757,7 +1710,8 @@ * For object type JSON nodes this will return the number of attributes for the * object. */ -cpl_size er_json_node_object_size(const er_json_node * obj) +cpl_size +er_json_node_object_size(const er_json_node *obj) { cpl_error_ensure(obj != NULL, CPL_ERROR_NULL_INPUT, return -1, "JSON node is NULL."); @@ -1779,7 +1733,8 @@ * For object type JSON nodes this function will test if the object contains any * attributes. */ -cpl_boolean er_json_node_object_empty(const er_json_node * obj) +cpl_boolean +er_json_node_object_empty(const er_json_node *obj) { cpl_error_ensure(obj != NULL, CPL_ERROR_NULL_INPUT, return CPL_TRUE, "JSON node is NULL."); @@ -1800,7 +1755,8 @@ * For an object type node this function returns an iterator to the first * attribute of the object. */ -er_json_object_iterator er_json_node_object_begin(const er_json_node * obj) +er_json_object_iterator +er_json_node_object_begin(const er_json_node *obj) { cpl_error_ensure(obj != NULL, CPL_ERROR_NULL_INPUT, return NULL, "JSON node is NULL."); @@ -1832,7 +1788,8 @@ * } * @endcode */ -er_json_object_iterator er_json_node_object_end(const er_json_node * obj) +er_json_object_iterator +er_json_node_object_end(const er_json_node *obj) { cpl_error_ensure(obj != NULL, CPL_ERROR_NULL_INPUT, return NULL, "JSON node is NULL."); @@ -1855,9 +1812,9 @@ * from the node. i.e. move the iterator to the next position in the object's * attribute list. */ -er_json_object_iterator er_json_node_object_next( - const er_json_node * obj, - er_json_object_iterator current) +er_json_object_iterator +er_json_node_object_next(const er_json_node *obj, + er_json_object_iterator current) { cpl_error_ensure(obj != NULL, CPL_ERROR_NULL_INPUT, return NULL, "JSON node is NULL."); @@ -1882,9 +1839,9 @@ * from the node. i.e. move the iterator to the previous position in the * object's attribute list. */ -er_json_object_iterator er_json_node_object_previous( - const er_json_node * obj, - er_json_object_iterator current) +er_json_object_iterator +er_json_node_object_previous(const er_json_node *obj, + er_json_object_iterator current) { cpl_error_ensure(obj != NULL, CPL_ERROR_NULL_INPUT, return NULL, "JSON node is NULL."); @@ -1909,8 +1866,9 @@ * to by the given iterator. The iterator must have been created from the given * object node. */ -const char * er_json_node_object_get_key(const er_json_node * obj, - er_json_object_iterator iterator) +const char * +er_json_node_object_get_key(const er_json_node *obj, + er_json_object_iterator iterator) { cpl_error_ensure(obj != NULL, CPL_ERROR_NULL_INPUT, return NULL, "JSON node is NULL."); @@ -1918,7 +1876,7 @@ "Iterator is NULL."); cpl_error_ensure(obj->type == JSON_OBJECT, CPL_ERROR_ILLEGAL_INPUT, return NULL, "JSON node is not an object."); - return (const char *) cx_map_get_key(obj->value.object, iterator); + return (const char *)cx_map_get_key(obj->value.object, iterator); } /** @@ -1935,9 +1893,9 @@ * by the given iterator. The iterator must have been created from the given * object node. */ -const er_json_node * er_json_node_object_get_value( - const er_json_node * obj, - er_json_object_iterator iterator) +const er_json_node * +er_json_node_object_get_value(const er_json_node *obj, + er_json_object_iterator iterator) { cpl_error_ensure(obj != NULL, CPL_ERROR_NULL_INPUT, return NULL, "JSON node is NULL."); @@ -1945,7 +1903,7 @@ "Iterator is NULL."); cpl_error_ensure(obj->type == JSON_OBJECT, CPL_ERROR_ILLEGAL_INPUT, return NULL, "JSON node is not an object."); - return (er_json_node *) cx_map_get_value(obj->value.object, iterator); + return (er_json_node *)cx_map_get_value(obj->value.object, iterator); } /** @@ -1964,8 +1922,8 @@ * attribute is named by the given key. If such an attribute is found it's * corresponding value is returned or @c NULL if no such attribute can be found. */ -const er_json_node * er_json_node_object_get(const er_json_node * obj, - const char * key) +const er_json_node * +er_json_node_object_get(const er_json_node *obj, const char *key) { cpl_error_ensure(obj != NULL, CPL_ERROR_NULL_INPUT, return NULL, "JSON node is NULL."); @@ -1974,12 +1932,10 @@ cpl_error_ensure(obj->type == JSON_OBJECT, CPL_ERROR_ILLEGAL_INPUT, return NULL, "JSON node is not an object."); er_json_object_iterator item = cx_map_find(obj->value.object, key); - if (item != cx_map_end(obj->value.object)) - { - return (er_json_node *) cx_map_get_value(obj->value.object, item); + if (item != cx_map_end(obj->value.object)) { + return (er_json_node *)cx_map_get_value(obj->value.object, item); } - else - { + else { return NULL; } } @@ -1993,8 +1949,10 @@ * NOTE: Takes ownership of value. i.e. the caller should no longer call * er_json_node_delete() for value after invoking this function. */ -static void er_json_node_object_insert(er_json_node * obj, - const char * key, er_json_node * value) +static void +er_json_node_object_insert(er_json_node *obj, + const char *key, + er_json_node *value) { assert(obj != NULL); assert(obj->type == JSON_OBJECT); @@ -2007,23 +1965,25 @@ */ typedef struct _json_parser_context_ { - const char * json; /* Original JSON text to parse. */ - char * buffer; /* Working buffer for parsing functions. + const char *json; /* Original JSON text to parse. */ + char *buffer; /* Working buffer for parsing functions. Will be big enough to fit the remainder of the JSON string pointed to by 'current'. */ - const char * current; /* The current parse position. */ - char * error; /* The error message to use if JSON is invalid. */ - er_json_node * tree; /* The parse tree built by the parser. */ + const char *current; /* The current parse position. */ + char *error; /* The error message to use if JSON is invalid. */ + er_json_node *tree; /* The parse tree built by the parser. */ } json_parser_context; /* * Skips any white space from the current parsing position. * @param ctx Pointer to the parsing context data for the current parse. */ -static void parse_whitespace(json_parser_context * ctx) +static void +parse_whitespace(json_parser_context *ctx) { assert(ctx != NULL); - while (*ctx->current != '\0' && isspace(*ctx->current)) ++ctx->current; + while (*ctx->current != '\0' && isspace(*ctx->current)) + ++ctx->current; } /* @@ -2032,27 +1992,24 @@ * @return A new node object corresponding to the null terminal. NULL is * returned on parse errors. */ -static er_json_node * parse_null(json_parser_context * ctx) +static er_json_node * +parse_null(json_parser_context *ctx) { assert(ctx != NULL); - er_json_node * value = NULL; - const char * nullstr = "null"; - if (strncmp(ctx->current, nullstr, strlen(nullstr)) == 0) - { + er_json_node *value = NULL; + const char *nullstr = "null"; + if (strncmp(ctx->current, nullstr, strlen(nullstr)) == 0) { value = er_json_node_new_null(ctx->current); ctx->current += strlen(nullstr); } - else - { - if (strlen(ctx->current) > 20) - { - ctx->error = cpl_sprintf("Expected null but found '%.20s...'", - ctx->current); - } - else - { - ctx->error = cpl_sprintf("Expected null but found '%.20s'", - ctx->current); + else { + if (strlen(ctx->current) > 20) { + ctx->error = + cpl_sprintf("Expected null but found '%.20s...'", ctx->current); + } + else { + ctx->error = + cpl_sprintf("Expected null but found '%.20s'", ctx->current); } } return value; @@ -2064,31 +2021,28 @@ * @return A new node object corresponding to the boolean terminal. NULL is * returned on parse errors. */ -static er_json_node * parse_boolean(json_parser_context * ctx) +static er_json_node * +parse_boolean(json_parser_context *ctx) { assert(ctx != NULL); - er_json_node * value = NULL; - const char * truestr = "true"; - const char * falsestr = "false"; - if (strncmp(ctx->current, truestr, strlen(truestr)) == 0) - { + er_json_node *value = NULL; + const char *truestr = "true"; + const char *falsestr = "false"; + if (strncmp(ctx->current, truestr, strlen(truestr)) == 0) { value = er_json_node_new_bool(CPL_TRUE, ctx->current); ctx->current += strlen(truestr); } - else if (strncmp(ctx->current, falsestr, strlen(falsestr)) == 0) - { + else if (strncmp(ctx->current, falsestr, strlen(falsestr)) == 0) { value = er_json_node_new_bool(CPL_FALSE, ctx->current); ctx->current += strlen(falsestr); } - else - { - if (strlen(ctx->current) > 20) - { + else { + if (strlen(ctx->current) > 20) { ctx->error = cpl_sprintf("Expected true or false but found" - " '%.20s...'", ctx->current); + " '%.20s...'", + ctx->current); } - else - { + else { ctx->error = cpl_sprintf("Expected true or false but found '%.20s'", ctx->current); } @@ -2105,50 +2059,44 @@ * @return A new number node corresponding to the null terminal. NULL is * returned on parse errors. */ -static er_json_node * parse_number(json_parser_context * ctx) +static er_json_node * +parse_number(json_parser_context *ctx) { assert(ctx != NULL); - er_json_node * value = NULL; - const char * special_value_str[8] = { + er_json_node *value = NULL; + const char *special_value_str[8] = { /* NOTE: The order of these strings matters. Must have substrings after the longer strings. i.e. Infinity after Inf etc. */ "nan", "NaN", "inf", "Infinity", "Inf", "-inf", "-Infinity", "-Inf" }; - double special_value[8] = { - NAN, NAN, INFINITY, INFINITY, INFINITY, -INFINITY, -INFINITY, -INFINITY - }; + double special_value[8] = { NAN, NAN, INFINITY, INFINITY, + INFINITY, -INFINITY, -INFINITY, -INFINITY }; int i = 0; - for (i = 0; i < 8; ++i) - { - const char * str = special_value_str[i]; - if (strncmp(ctx->current, str, strlen(str)) == 0) - { + for (i = 0; i < 8; ++i) { + const char *str = special_value_str[i]; + if (strncmp(ctx->current, str, strlen(str)) == 0) { value = er_json_node_new_number(special_value[i], ctx->current); ctx->current += strlen(str); return value; } } - errno = 0; /* Clear errno before checking strtod for errors. */ - char * endptr = NULL; + errno = 0; /* Clear errno before checking strtod for errors. */ + char *endptr = NULL; double number = strtod(ctx->current, &endptr); /* NOTE: we ignore floating point overflow and underflows (ERANGE). */ - if (errno == 0 || errno == ERANGE) - { + if (errno == 0 || errno == ERANGE) { value = er_json_node_new_number(number, ctx->current); ctx->current = endptr; } - else - { - if (strlen(ctx->current) > 20) - { + else { + if (strlen(ctx->current) > 20) { ctx->error = cpl_sprintf("Expected a number but found '%.20s...'", ctx->current); } - else - { - ctx->error = cpl_sprintf("Expected number but found '%.20s'", - ctx->current); + else { + ctx->error = + cpl_sprintf("Expected number but found '%.20s'", ctx->current); } } return value; @@ -2160,7 +2108,8 @@ * @param ctx Pointer to the parsing context data for the current parse. * @return The corresponding character code or -1 on a parse error. */ -static long parse_unicode_character(json_parser_context * ctx, char * buffer) +static long +parse_unicode_character(json_parser_context *ctx, char *buffer) { assert(ctx != NULL); assert(buffer != NULL); @@ -2171,35 +2120,31 @@ buffer[4] = '\0'; strncpy(buffer, ctx->current, 4); - if (strlen(buffer) != 4) - { + if (strlen(buffer) != 4) { ctx->error = cpl_strdup("A unicode escape sequence requires four" " hexadecimal digits"); return -1; } /* Decode the hex digits. */ - errno = 0; /* Clear errno before checking strtol for errors. */ - char * endptr = NULL; + errno = 0; /* Clear errno before checking strtol for errors. */ + char *endptr = NULL; long charcode = strtol(buffer, &endptr, 16); - if (errno != 0 || endptr != buffer + 4) - { - if (strlen(ctx->current) > 20) - { + if (errno != 0 || endptr != buffer + 4) { + if (strlen(ctx->current) > 20) { ctx->error = cpl_sprintf("Expected a four character hexadecimal" " number but found '%.20s...'", ctx->current); } - else - { + else { ctx->error = cpl_sprintf("Expected a four character hexadecimal" - " number but found '%.20s'", ctx->current); + " number but found '%.20s'", + ctx->current); } return -1; } - if (charcode == 0 || charcode > 255) - { + if (charcode == 0 || charcode > 255) { ctx->error = cpl_strdup("Unicode value is outside the supported range"); return -1; } @@ -2219,53 +2164,66 @@ * @param ctx Pointer to the parsing context data for the current parse. * @return The converted null terminated string or NULL on parse errors. */ -static const char * parse_string_characters(json_parser_context * ctx) +static const char * +parse_string_characters(json_parser_context *ctx) { assert(ctx != NULL); assert(ctx->buffer != NULL); - char * result = ctx->buffer; + char *result = ctx->buffer; /* The following variable keeps track of the current character position to write to in the output buffer. */ - char * output = result; + char *output = result; - for (; *ctx->current != '\0' && *ctx->current != '"'; ++ctx->current) - { + for (; *ctx->current != '\0' && *ctx->current != '"'; ++ctx->current) { char char_to_use; /* Check if we found the start of an escape sequence. */ - if (*ctx->current != '\\') - { + if (*ctx->current != '\\') { char_to_use = *ctx->current; } - else - { + else { long charcode; - ++ctx->current; /* Move past the '\' character. */ - if (*ctx->current == '\0') - { + ++ctx->current; /* Move past the '\' character. */ + if (*ctx->current == '\0') { ctx->error = cpl_strdup("Missing escape character after '\\'"); return NULL; } - switch (*ctx->current) - { - case '"': char_to_use = '"'; break; - case '\\': char_to_use = '\\'; break; - case '/': char_to_use = '/'; break; - case 'b': char_to_use = '\b'; break; - case 'f': char_to_use = '\f'; break; - case 'n': char_to_use = '\n'; break; - case 'r': char_to_use = '\r'; break; - case 't': char_to_use = '\t'; break; + switch (*ctx->current) { + case '"': + char_to_use = '"'; + break; + case '\\': + char_to_use = '\\'; + break; + case '/': + char_to_use = '/'; + break; + case 'b': + char_to_use = '\b'; + break; + case 'f': + char_to_use = '\f'; + break; + case 'n': + char_to_use = '\n'; + break; + case 'r': + char_to_use = '\r'; + break; + case 't': + char_to_use = '\t'; + break; case 'u': - ++ctx->current; /* Move past the 'u' character. */ + ++ctx->current; /* Move past the 'u' character. */ /* NOTE: we let parse_unicode_character use the buffer space just after out current output location, which will not jet contain any usable data. */ charcode = parse_unicode_character(ctx, output); - if (charcode == -1) return NULL; + if (charcode == -1) + return NULL; char_to_use = (char)(0xFF & charcode); break; @@ -2293,7 +2251,8 @@ * @param ctx Pointer to the parsing context data for the current parse. * @return The null terminated string value or NULL if there were parse errors. */ -static const char * parse_string(json_parser_context * ctx) +static const char * +parse_string(json_parser_context *ctx) { assert(ctx != NULL); @@ -2301,16 +2260,15 @@ assert(*ctx->current == '"'); ++ctx->current; - const char * string = parse_string_characters(ctx); - if (string == NULL) return NULL; + const char *string = parse_string_characters(ctx); + if (string == NULL) + return NULL; /* Make sure we reached the end of the string. */ - if (*ctx->current == '"') - { + if (*ctx->current == '"') { ++ctx->current; } - else - { + else { /* NOTE: the parse_string_characters function will always get to the end of the input if there is no '"' character to terminate the string. Therefore there is no point in trying to print an error @@ -2329,13 +2287,15 @@ * @param ctx Pointer to the parsing context data for the current parse. * @return A new string node or NULL if there was a parsing error. */ -static er_json_node * parse_string_as_object(json_parser_context * ctx) +static er_json_node * +parse_string_as_object(json_parser_context *ctx) { assert(ctx != NULL); - const char * location = ctx->current; /* Start location of string. */ + const char *location = ctx->current; /* Start location of string. */ - const char * string = parse_string(ctx); - if (string == NULL) return NULL; + const char *string = parse_string(ctx); + if (string == NULL) + return NULL; return er_json_node_new_string(string, location); } @@ -2343,18 +2303,19 @@ /* Need to forward declare this function which is called recursively in the parse_array and parse_object functions. */ -static er_json_node * parse_value(json_parser_context * ctx); +static er_json_node *parse_value(json_parser_context *ctx); /* * Parses a JSON array from the current parse position. * @param ctx Pointer to the parsing context data for the current parse. * @return A new array node object or NULL if there was a parsing error. */ -static er_json_node * parse_array(json_parser_context * ctx) +static er_json_node * +parse_array(json_parser_context *ctx) { assert(ctx != NULL); - er_json_node * array = er_json_node_new_array(ctx->current); + er_json_node *array = er_json_node_new_array(ctx->current); /* Move past the first '[' character. */ assert(*ctx->current == '['); @@ -2363,46 +2324,40 @@ /* Check for white space in case this is an empty array. */ parse_whitespace(ctx); - if (*ctx->current != ']') /* Check if the array was empty. */ + if (*ctx->current != ']') /* Check if the array was empty. */ { - do - { - if (*ctx->current == ',') ++ctx->current; + do { + if (*ctx->current == ',') + ++ctx->current; - parse_whitespace(ctx); /* White space before a JSON value. */ - if (*ctx->current == '\0') - { + parse_whitespace(ctx); /* White space before a JSON value. */ + if (*ctx->current == '\0') { ctx->error = cpl_sprintf("Expected the start of a new value"); er_json_node_delete(array); return NULL; } - er_json_node * item = parse_value(ctx); - if (item == NULL) - { + er_json_node *item = parse_value(ctx); + if (item == NULL) { er_json_node_delete(array); return NULL; } er_json_node_array_append(array, item); - parse_whitespace(ctx); /* White space after a JSON value. */ - } - while (*ctx->current == ','); + parse_whitespace(ctx); /* White space after a JSON value. */ + } while (*ctx->current == ','); } /* Make sure we reached the end of the array. */ - if (*ctx->current == ']') - { + if (*ctx->current == ']') { ++ctx->current; } - else - { - if (*ctx->current == '\0') - { + else { + if (*ctx->current == '\0') { ctx->error = cpl_sprintf("Expected ']' character to end the array"); } - else - { + else { ctx->error = cpl_sprintf("Expected ']' character to end the array," - " but found '%c' instead,", *ctx->current); + " but found '%c' instead,", + *ctx->current); } er_json_node_delete(array); return NULL; @@ -2416,11 +2371,12 @@ * @param ctx Pointer to the parsing context data for the current parse. * @return A new object node or NULL if there was a parsing error. */ -static er_json_node * parse_object(json_parser_context * ctx) +static er_json_node * +parse_object(json_parser_context *ctx) { assert(ctx != NULL); - er_json_node * object = er_json_node_new_object(ctx->current); + er_json_node *object = er_json_node_new_object(ctx->current); /* Move past the first '{' character. */ assert(*ctx->current == '{'); @@ -2429,98 +2385,87 @@ /* Check for white space in case this is an empty object. */ parse_whitespace(ctx); - if (*ctx->current != '}') /* Check if the JSON object was empty. */ + if (*ctx->current != '}') /* Check if the JSON object was empty. */ { - do - { - if (*ctx->current == ',') ++ctx->current; + do { + if (*ctx->current == ',') + ++ctx->current; /* First parse the key string. */ - parse_whitespace(ctx); /* White space before the key string. */ - if (*ctx->current != '"') - { - if (*ctx->current == '\0') - { + parse_whitespace(ctx); /* White space before the key string. */ + if (*ctx->current != '"') { + if (*ctx->current == '\0') { ctx->error = cpl_sprintf("Expected a key string"); } - else if (strlen(ctx->current) > 20) - { + else if (strlen(ctx->current) > 20) { ctx->error = cpl_sprintf("Expected a key string, but found" " '%.20s...' instead,", ctx->current); } - else - { + else { ctx->error = cpl_sprintf("Expected a key string, but found" - " '%.20s' instead,", ctx->current); + " '%.20s' instead,", + ctx->current); } er_json_node_delete(object); return NULL; } - const char * key = parse_string(ctx); - if (key == NULL) - { + const char *key = parse_string(ctx); + if (key == NULL) { er_json_node_delete(object); return NULL; } - parse_whitespace(ctx); /* White space after the key string. */ + parse_whitespace(ctx); /* White space after the key string. */ /* The next character must be the separator ':'. */ - if (*ctx->current != ':') - { - if (strlen(ctx->current) > 20) - { + if (*ctx->current != ':') { + if (strlen(ctx->current) > 20) { ctx->error = cpl_sprintf("Expected ':' but found '%.20s...'" - " instead,", ctx->current); + " instead,", + ctx->current); } - else - { + else { ctx->error = cpl_sprintf("Expected ':' but found '%.20s'" - " instead,", ctx->current); + " instead,", + ctx->current); } er_json_node_delete(object); return NULL; } - ++ctx->current; /* Move past the ':' character. */ + ++ctx->current; /* Move past the ':' character. */ /* Now the value part should follow. */ - parse_whitespace(ctx); /* White space before the JSON value. */ - if (*ctx->current == '\0') - { + parse_whitespace(ctx); /* White space before the JSON value. */ + if (*ctx->current == '\0') { ctx->error = cpl_sprintf("Expected the start of a new value"); er_json_node_delete(object); return NULL; } - er_json_node * item = parse_value(ctx); - if (item == NULL) - { + er_json_node *item = parse_value(ctx); + if (item == NULL) { er_json_node_delete(object); return NULL; } er_json_node_object_insert(object, key, item); - parse_whitespace(ctx); /* White space after the JSON value. */ - } - while (*ctx->current == ','); + parse_whitespace(ctx); /* White space after the JSON value. */ + } while (*ctx->current == ','); /* Check for left over white space before the last '}'. */ parse_whitespace(ctx); } /* Make sure we reached the end of the JSON object. */ - if (*ctx->current == '}') - { + if (*ctx->current == '}') { ++ctx->current; } - else - { - if (*ctx->current == '\0') - { + else { + if (*ctx->current == '\0') { ctx->error = cpl_sprintf("Expected '}' character to end a object"); } - else - { + else { ctx->error = cpl_sprintf("Expected '}' character to end a object," - " but found '%c' instead,", *ctx->current); + " but found '%c' instead,", + *ctx->current); } er_json_node_delete(object); return NULL; @@ -2536,37 +2481,38 @@ * @param ctx Pointer to the parsing context data for the current parse. * @return A new JSON node or NULL if there was a parsing error. */ -static er_json_node * parse_value(json_parser_context * ctx) +static er_json_node * +parse_value(json_parser_context *ctx) { assert(ctx != NULL); assert(*ctx->current != '\0'); /* If the current character is a digit then this should be a number. */ - if (isdigit(*ctx->current)) - { + if (isdigit(*ctx->current)) { return parse_number(ctx); } /* Identify the type of value we are dealing with by the current character. We then invoke the appropriate parsing function. */ - switch (*ctx->current) - { + switch (*ctx->current) { case 'n': /* If the first character is a 'n' we might be dealing with either a 'null' terminal or 'nan' number terminal. We need to check what the character after the 'n' is to decide which one we are dealing with. */ - if (*(ctx->current+1) == 'u') - { + if (*(ctx->current + 1) == 'u') { return parse_null(ctx); } - else - { + else { return parse_number(ctx); } - case 't': case 'f': + case 't': + case 'f': return parse_boolean(ctx); - case '-': case 'i': case 'I': case 'N': + case '-': + case 'i': + case 'I': + case 'N': return parse_number(ctx); case '"': return parse_string_as_object(ctx); @@ -2575,14 +2521,12 @@ case '{': return parse_object(ctx); default: - if (strlen(ctx->current) > 20) - { + if (strlen(ctx->current) > 20) { ctx->error = cpl_sprintf("Expected the start of a JSON value," " but found '%.20s...' instead,", ctx->current); } - else - { + else { ctx->error = cpl_sprintf("Expected the start of a JSON value," " but found '%.20s' instead,", ctx->current); @@ -2599,22 +2543,23 @@ * @param ctx Pointer to the parsing context data for the current parse. * @return CPL_TRUE if the parse was successful or CPL_FALSE otherwise. */ -static cpl_boolean parse_json(json_parser_context * ctx) +static cpl_boolean +parse_json(json_parser_context *ctx) { parse_whitespace(ctx); - if (*ctx->current == '\0') - { + if (*ctx->current == '\0') { /* Special case, where the text only contains white space. */ ctx->tree = er_json_node_new_null(ctx->json); return CPL_TRUE; } ctx->tree = parse_value(ctx); - if (ctx->tree == NULL) return CPL_FALSE; + if (ctx->tree == NULL) + return CPL_FALSE; parse_whitespace(ctx); - if (*ctx->current != '\0') - { + if (*ctx->current != '\0') { ctx->error = cpl_sprintf("Unexpected character '%c' after a JSON value" - " node", *ctx->current); + " node", + *ctx->current); return CPL_FALSE; } return CPL_TRUE; @@ -2636,12 +2581,14 @@ * This function will compute the line and column number corresponding to the * given character location within the JSON text. */ -cpl_error_code er_json_find_line_column(const char * json, - const char * location, - int * line, int * column) +cpl_error_code +er_json_find_line_column(const char *json, + const char *location, + int *line, + int *column) { - cpl_error_ensure(json != NULL && location != NULL && - line != NULL && column != NULL, + cpl_error_ensure(json != NULL && location != NULL && line != NULL && + column != NULL, CPL_ERROR_NULL_INPUT, return CPL_ERROR_NULL_INPUT, "Used NULL pointer."); @@ -2654,16 +2601,13 @@ assert(location <= json + strlen(json) + 1); /* Find the line, column position of the error. */ - const char * c = NULL; - for (c = json; c != location; ++c) - { - if (*c == '\n') - { + const char *c = NULL; + for (c = json; c != location; ++c) { + if (*c == '\n') { ++(*line); *column = 1; } - else - { + else { ++(*column); } } @@ -2685,7 +2629,8 @@ * information. The tree can be navigated to extract the converted string, * boolean and floating point number data. */ -er_json_node * er_json_parse(const char * json) +er_json_node * +er_json_parse(const char *json) { cpl_error_ensure(json != NULL, CPL_ERROR_NULL_INPUT, return NULL, "JSON text is NULL."); @@ -2694,7 +2639,7 @@ NOTE: The extra 8 bytes guarantee there is space for a NULL terminating character or room for the parse_unicode_character to copy too in case we are near the end of the JSON string. */ - char * buffer = cpl_malloc(strlen(json) + 8); + char *buffer = cpl_malloc(strlen(json) + 8); json_parser_context ctx; ctx.json = json; ctx.buffer = buffer; @@ -2703,8 +2648,7 @@ ctx.tree = NULL; /* Perform the parse. */ - if (! parse_json(&ctx)) - { + if (!parse_json(&ctx)) { /* If an error occurred then delete the parse tree, generate the appropriate error code/message and return NULL. */ er_json_node_delete(ctx.tree); @@ -2740,8 +2684,8 @@ * the subnodes of the resultant parse tree from er_json_parse() can be used * instead, if we only want to convert a child element from the JSON text. */ -er_stringarray_t * er_json_to_string_array(const er_json_node * parsetree, - const char * json) +er_stringarray_t * +er_json_to_string_array(const er_json_node *parsetree, const char *json) { cpl_error_ensure(parsetree != NULL, CPL_ERROR_NULL_INPUT, return NULL, "Input JSON parse tree is NULL."); @@ -2749,35 +2693,34 @@ "JSON text is NULL."); /* Make sure the type of the top level node is an array. */ - if (er_json_node_type(parsetree) != JSON_ARRAY) - { + if (er_json_node_type(parsetree) != JSON_ARRAY) { int line, col; - er_json_find_line_column(json, er_json_node_location(parsetree), - &line, &col); + er_json_find_line_column(json, er_json_node_location(parsetree), &line, + &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Expected an array of strings at line %d column" - " %d.", line, col); + " %d.", + line, col); return NULL; } - er_stringarray_t * array = er_stringarray_new(); + er_stringarray_t *array = er_stringarray_new(); /* Add all the items in the parsed array to the er_stringarray_t object, making sure that what we parsed for each item is actually a string. */ er_json_array_iterator iter = NULL; - for (iter = er_json_node_array_begin(parsetree); + for (iter = er_json_node_array_begin(parsetree); iter != er_json_node_array_end(parsetree); - iter = er_json_node_array_next(parsetree, iter)) - { - const er_json_node * item = er_json_node_array_get(parsetree, iter); - if (er_json_node_type(item) != JSON_STRING) - { + iter = er_json_node_array_next(parsetree, iter)) { + const er_json_node *item = er_json_node_array_get(parsetree, iter); + if (er_json_node_type(item) != JSON_STRING) { int line, col; - er_json_find_line_column(json, er_json_node_location(item), - &line, &col); + er_json_find_line_column(json, er_json_node_location(item), &line, + &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Expected a string item in the array at" - " line %d column %d.", line, col); + " line %d column %d.", + line, col); er_stringarray_delete(array); return NULL; } @@ -2800,23 +2743,24 @@ * @return The JSON value node corresponding to the given key. @c NULL is * returned if the child node could not be found. */ -static const er_json_node * get_value_from_object(const er_json_node * object, - const char * key, - const char * json) +static const er_json_node * +get_value_from_object(const er_json_node *object, + const char *key, + const char *json) { assert(object != NULL); assert(key != NULL); assert(json != NULL); - const er_json_node * value = er_json_node_object_get(object, key); - if (value == NULL) - { + const er_json_node *value = er_json_node_object_get(object, key); + if (value == NULL) { int line, col; - er_json_find_line_column(json, er_json_node_location(object), - &line, &col); + er_json_find_line_column(json, er_json_node_location(object), &line, + &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Failed to find key '%s' in object at line %d" - " column %d.", key, line, col); + " column %d.", + key, line, col); } return value; } @@ -2836,36 +2780,37 @@ * if the given key does not exist in the JSON object or the value is not a * string. */ -static const char * get_string_from_object(const er_json_node * object, - const char * key, const char * json, - cpl_boolean must_exist) +static const char * +get_string_from_object(const er_json_node *object, + const char *key, + const char *json, + cpl_boolean must_exist) { assert(object != NULL); assert(key != NULL); assert(json != NULL); - const er_json_node * value = er_json_node_object_get(object, key); - if (value == NULL) - { - if (must_exist) - { + const er_json_node *value = er_json_node_object_get(object, key); + if (value == NULL) { + if (must_exist) { int line, col; - er_json_find_line_column(json, er_json_node_location(object), - &line, &col); + er_json_find_line_column(json, er_json_node_location(object), &line, + &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Failed to find key '%s' in object at line %d" - " column %d.", key, line, col); + " column %d.", + key, line, col); } return NULL; } - if (er_json_node_type(value) != JSON_STRING) - { + if (er_json_node_type(value) != JSON_STRING) { int line, col; - er_json_find_line_column(json, er_json_node_location(value), - &line, &col); + er_json_find_line_column(json, er_json_node_location(value), &line, + &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Expected a string for key '%s' at line %d" - " column %d.", key, line, col); + " column %d.", + key, line, col); return NULL; } return er_json_node_get_string(value); @@ -2886,36 +2831,37 @@ * if the given key does not exist in the JSON object or the value is not a * number. */ -static double get_number_from_object(const er_json_node * object, - const char * key, const char * json, - cpl_boolean must_exist) +static double +get_number_from_object(const er_json_node *object, + const char *key, + const char *json, + cpl_boolean must_exist) { assert(object != NULL); assert(key != NULL); assert(json != NULL); - const er_json_node * value = er_json_node_object_get(object, key); - if (value == NULL) - { - if (must_exist) - { + const er_json_node *value = er_json_node_object_get(object, key); + if (value == NULL) { + if (must_exist) { int line, col; - er_json_find_line_column(json, er_json_node_location(object), - &line, &col); + er_json_find_line_column(json, er_json_node_location(object), &line, + &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Failed to find key '%s' in object at line %d" - " column %d.", key, line, col); + " column %d.", + key, line, col); } return 0; } - if (er_json_node_type(value) != JSON_NUMBER) - { + if (er_json_node_type(value) != JSON_NUMBER) { int line, col; - er_json_find_line_column(json, er_json_node_location(value), - &line, &col); + er_json_find_line_column(json, er_json_node_location(value), &line, + &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Expected a number for key '%s' at line %d" - " column %d.", key, line, col); + " column %d.", + key, line, col); return 0; } return er_json_node_get_number(value); @@ -2936,12 +2882,13 @@ * returned if the given key does not exist in the JSON object or the value * is not a number. */ -static unsigned long get_ulong_from_object(const er_json_node * object, - const char * key, const char * json, - cpl_boolean must_exist) +static unsigned long +get_ulong_from_object(const er_json_node *object, + const char *key, + const char *json, + cpl_boolean must_exist) { - return (unsigned long) get_number_from_object(object, key, json, - must_exist); + return (unsigned long)get_number_from_object(object, key, json, must_exist); } /* @@ -2957,10 +2904,12 @@ * @c NULL is returned if the given key does not exist in the JSON object * or the value is not a number. */ -static cpl_size get_cpl_size_from_object(const er_json_node * object, - const char * key, const char * json) +static cpl_size +get_cpl_size_from_object(const er_json_node *object, + const char *key, + const char *json) { - return (cpl_size) get_number_from_object(object, key, json, CPL_TRUE); + return (cpl_size)get_number_from_object(object, key, json, CPL_TRUE); } /* @@ -2973,25 +2922,26 @@ * @return The JSON array node called 'choices'. @c NULL is returned if the * node could not be found or does not correspond to an array type. */ -static const er_json_node * get_choices_array(const er_json_node * object, - const char * json) +static const er_json_node * +get_choices_array(const er_json_node *object, const char *json) { assert(object != NULL); assert(json != NULL); /* Fetch the "choices" JSON node from the given object parse tree and make sure it is an array type. */ - const char * key = "choices"; - const er_json_node * array_node = get_value_from_object(object, key, json); - if (array_node == NULL) return NULL; - if (er_json_node_type(array_node) != JSON_ARRAY) - { + const char *key = "choices"; + const er_json_node *array_node = get_value_from_object(object, key, json); + if (array_node == NULL) + return NULL; + if (er_json_node_type(array_node) != JSON_ARRAY) { int line, col; - er_json_find_line_column(json, er_json_node_location(array_node), - &line, &col); + er_json_find_line_column(json, er_json_node_location(array_node), &line, + &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Expected an array for key '%s' at line %d" - " column %d.", key, line, col); + " column %d.", + key, line, col); return NULL; } return array_node; @@ -3002,14 +2952,15 @@ * pure integer. i.e. this is to check if a number was represented as an integer * or floating point. */ -static cpl_boolean node_is_integer(const er_json_node * object) +static cpl_boolean +node_is_integer(const er_json_node *object) { - const char * text = er_json_node_location(object); + const char *text = er_json_node_location(object); cpl_boolean result = CPL_TRUE; - const char * c = NULL; - for (c = text; *c != '\0' && *c != ']' && *c != '}' && *c != ','; ++c) - { - if (isspace(*c) || isdigit(*c) || *c == '-' || *c == '+') continue; + const char *c = NULL; + for (c = text; *c != '\0' && *c != ']' && *c != '}' && *c != ','; ++c) { + if (isspace(*c) || isdigit(*c) || *c == '-' || *c == '+') + continue; result = CPL_FALSE; break; } @@ -3039,12 +2990,13 @@ * @note The caller must call @c cpl_free on the @p choices array if this * function returned a @c CPL_ERROR_NONE error code. */ -static cpl_error_code get_ints_from_choices(const er_json_node * object, - const char * json, - int default_value, - int * choices_count, - int ** choices, - const er_json_node ** mismatch) +static cpl_error_code +get_ints_from_choices(const er_json_node *object, + const char *json, + int default_value, + int *choices_count, + int **choices, + const er_json_node **mismatch) { assert(object != NULL); assert(json != NULL); @@ -3052,8 +3004,9 @@ assert(choices != NULL); assert(mismatch != NULL); - const er_json_node * array_node = get_choices_array(object, json); - if (array_node == NULL) return cpl_error_get_code(); + const er_json_node *array_node = get_choices_array(object, json); + if (array_node == NULL) + return cpl_error_get_code(); /* Check every element in the array to make sure that it is a integer. We also check that at least one of the choices corresponds to the default @@ -3062,37 +3015,34 @@ er_json_array_iterator iter = NULL; for (iter = er_json_node_array_begin(array_node); iter != er_json_node_array_end(array_node); - iter = er_json_node_array_next(array_node, iter)) - { - const er_json_node * item = er_json_node_array_get(array_node, iter); - if (er_json_node_type(item) != JSON_NUMBER) - { + iter = er_json_node_array_next(array_node, iter)) { + const er_json_node *item = er_json_node_array_get(array_node, iter); + if (er_json_node_type(item) != JSON_NUMBER) { /* Mark the JSON node that has a type mismatch, this should be later handled by the called. */ *mismatch = item; return CPL_ERROR_TYPE_MISMATCH; } double num = er_json_node_get_number(item); - if (! node_is_integer(item)) /* Check if num is an integer. */ + if (!node_is_integer(item)) /* Check if num is an integer. */ { *mismatch = item; return CPL_ERROR_TYPE_MISMATCH; } int inum = (int)num; - if (inum == default_value) - { + if (inum == default_value) { default_not_found = CPL_FALSE; } } - if (default_not_found) - { + if (default_not_found) { int line, col; - er_json_find_line_column(json, er_json_node_location(array_node), - &line, &col); + er_json_find_line_column(json, er_json_node_location(array_node), &line, + &col); return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "The default value %d was not found in" " the array of choices at line %d column" - " %d.", default_value, line, col); + " %d.", + default_value, line, col); } /* We now allocate memory and construct the output array. */ @@ -3102,9 +3052,8 @@ int n; for (iter = er_json_node_array_begin(array_node), n = 0; iter != er_json_node_array_end(array_node); - iter = er_json_node_array_next(array_node, iter), ++n) - { - const er_json_node * item = er_json_node_array_get(array_node, iter); + iter = er_json_node_array_next(array_node, iter), ++n) { + const er_json_node *item = er_json_node_array_get(array_node, iter); (*choices)[n] = (int)er_json_node_get_number(item); } return CPL_ERROR_NONE; @@ -3115,12 +3064,13 @@ * choices that are of floating point type. * See get_ints_from_choices for details. */ -static cpl_error_code get_doubles_from_choices(const er_json_node * object, - const char * json, - double default_value, - int * choices_count, - double ** choices, - const er_json_node ** mismatch) +static cpl_error_code +get_doubles_from_choices(const er_json_node *object, + const char *json, + double default_value, + int *choices_count, + double **choices, + const er_json_node **mismatch) { assert(object != NULL); assert(json != NULL); @@ -3128,8 +3078,9 @@ assert(choices != NULL); assert(mismatch != NULL); - const er_json_node * array_node = get_choices_array(object, json); - if (array_node == NULL) return cpl_error_get_code(); + const er_json_node *array_node = get_choices_array(object, json); + if (array_node == NULL) + return cpl_error_get_code(); /* Check every element in the array to make sure that it is a double floating point. We also check that at least one of the choices @@ -3138,30 +3089,27 @@ er_json_array_iterator iter = NULL; for (iter = er_json_node_array_begin(array_node); iter != er_json_node_array_end(array_node); - iter = er_json_node_array_next(array_node, iter)) - { - const er_json_node * item = er_json_node_array_get(array_node, iter); - if (er_json_node_type(item) != JSON_NUMBER) - { + iter = er_json_node_array_next(array_node, iter)) { + const er_json_node *item = er_json_node_array_get(array_node, iter); + if (er_json_node_type(item) != JSON_NUMBER) { /* Mark the JSON node that has a type mismatch, this should be later handled by the called. */ *mismatch = item; return CPL_ERROR_TYPE_MISMATCH; } - if (er_json_node_get_number(item) == default_value) - { + if (er_json_node_get_number(item) == default_value) { default_not_found = CPL_FALSE; } } - if (default_not_found) - { + if (default_not_found) { int line, col; - er_json_find_line_column(json, er_json_node_location(array_node), - &line, &col); + er_json_find_line_column(json, er_json_node_location(array_node), &line, + &col); return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "The default value %.17g was not found in" " the array of choices at line %d column" - " %d.", default_value, line, col); + " %d.", + default_value, line, col); } /* We now allocate memory and construct the output array. */ @@ -3171,9 +3119,8 @@ int n; for (iter = er_json_node_array_begin(array_node), n = 0; iter != er_json_node_array_end(array_node); - iter = er_json_node_array_next(array_node, iter), ++n) - { - const er_json_node * item = er_json_node_array_get(array_node, iter); + iter = er_json_node_array_next(array_node, iter), ++n) { + const er_json_node *item = er_json_node_array_get(array_node, iter); (*choices)[n] = er_json_node_get_number(item); } return CPL_ERROR_NONE; @@ -3184,12 +3131,13 @@ * choices that are of string type. * See get_ints_from_choices for details. */ -static cpl_error_code get_strings_from_choices(const er_json_node * object, - const char * json, - const char * default_value, - int * choices_count, - const char *** choices, - const er_json_node ** mismatch) +static cpl_error_code +get_strings_from_choices(const er_json_node *object, + const char *json, + const char *default_value, + int *choices_count, + const char ***choices, + const er_json_node **mismatch) { assert(object != NULL); assert(json != NULL); @@ -3198,8 +3146,9 @@ assert(choices != NULL); assert(mismatch != NULL); - const er_json_node * array_node = get_choices_array(object, json); - if (array_node == NULL) return cpl_error_get_code(); + const er_json_node *array_node = get_choices_array(object, json); + if (array_node == NULL) + return cpl_error_get_code(); /* Check every element in the array to make sure that it is a string. We also check that at least one of the choices corresponds to the default @@ -3208,30 +3157,27 @@ er_json_array_iterator iter = NULL; for (iter = er_json_node_array_begin(array_node); iter != er_json_node_array_end(array_node); - iter = er_json_node_array_next(array_node, iter)) - { - const er_json_node * item = er_json_node_array_get(array_node, iter); - if (er_json_node_type(item) != JSON_STRING) - { + iter = er_json_node_array_next(array_node, iter)) { + const er_json_node *item = er_json_node_array_get(array_node, iter); + if (er_json_node_type(item) != JSON_STRING) { /* Mark the JSON node that has a type mismatch, this should be later handled by the called. */ *mismatch = item; return CPL_ERROR_TYPE_MISMATCH; } - if (strcmp(er_json_node_get_string(item), default_value) == 0) - { + if (strcmp(er_json_node_get_string(item), default_value) == 0) { default_not_found = CPL_FALSE; } } - if (default_not_found) - { + if (default_not_found) { int line, col; - er_json_find_line_column(json, er_json_node_location(array_node), - &line, &col); + er_json_find_line_column(json, er_json_node_location(array_node), &line, + &col); return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "The default value '%s' was not found in" " the array of choices at line %d column" - " %d.", default_value, line, col); + " %d.", + default_value, line, col); } /* We now allocate memory and construct the output array. */ @@ -3241,9 +3187,8 @@ int n; for (iter = er_json_node_array_begin(array_node), n = 0; iter != er_json_node_array_end(array_node); - iter = er_json_node_array_next(array_node, iter), ++n) - { - const er_json_node * item = er_json_node_array_get(array_node, iter); + iter = er_json_node_array_next(array_node, iter), ++n) { + const er_json_node *item = er_json_node_array_get(array_node, iter); (*choices)[n] = er_json_node_get_string(item); } return CPL_ERROR_NONE; @@ -3266,35 +3211,33 @@ * @return @c CPL_ERROR_NONE on success and an appropriate error code * otherwise. */ -static cpl_error_code set_param_enable_flag(cpl_parameter * param, - const er_json_node * parsetree, - const char * json, - const char * key, - cpl_parameter_mode mode) +static cpl_error_code +set_param_enable_flag(cpl_parameter *param, + const er_json_node *parsetree, + const char *json, + const char *key, + cpl_parameter_mode mode) { assert(param != NULL); assert(parsetree != NULL); assert(json != NULL); assert(key != NULL); - const er_json_node * node = er_json_node_object_get(parsetree, key); - if (node != NULL) - { - if (er_json_node_type(node) != JSON_BOOL) - { + const er_json_node *node = er_json_node_object_get(parsetree, key); + if (node != NULL) { + if (er_json_node_type(node) != JSON_BOOL) { int line, col; - er_json_find_line_column(json, er_json_node_location(node), - &line, &col); + er_json_find_line_column(json, er_json_node_location(node), &line, + &col); return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Expected a boolean at line %d column" - " %d.", line, col); + " %d.", + line, col); } - if (er_json_node_get_bool(node)) - { + if (er_json_node_get_bool(node)) { cpl_parameter_enable(param, mode); } - else - { + else { cpl_parameter_disable(param, mode); } } @@ -3317,36 +3260,34 @@ * @return @c CPL_ERROR_NONE on success and an appropriate error code * otherwise. */ -static cpl_error_code set_param_alias(cpl_parameter * param, - const er_json_node * parsetree, - const char * json, - const char * key, - cpl_parameter_mode mode) +static cpl_error_code +set_param_alias(cpl_parameter *param, + const er_json_node *parsetree, + const char *json, + const char *key, + cpl_parameter_mode mode) { assert(param != NULL); assert(parsetree != NULL); assert(json != NULL); assert(key != NULL); - const er_json_node * node = er_json_node_object_get(parsetree, key); - if (node != NULL) - { - if (er_json_node_type(node) == JSON_STRING) - { + const er_json_node *node = er_json_node_object_get(parsetree, key); + if (node != NULL) { + if (er_json_node_type(node) == JSON_STRING) { cpl_parameter_set_alias(param, mode, er_json_node_get_string(node)); } - else if (er_json_node_type(node) == JSON_NULL) - { + else if (er_json_node_type(node) == JSON_NULL) { cpl_parameter_set_alias(param, mode, NULL); } - else - { + else { int line, col; - er_json_find_line_column(json, er_json_node_location(node), - &line, &col); + er_json_find_line_column(json, er_json_node_location(node), &line, + &col); return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Expected a string or null at line %d" - " column %d.", line, col); + " column %d.", + line, col); } } return CPL_ERROR_NONE; @@ -3364,77 +3305,77 @@ * @c NULL if an error occurred. Errors indicate that the parsed JSON does * not correspond to a proper CPL parameter object. */ -static cpl_parameter * json_to_parameter(const er_json_node * parsetree, - const char * json) +static cpl_parameter * +json_to_parameter(const er_json_node *parsetree, const char *json) { int line, col; - if (er_json_node_type(parsetree) != JSON_OBJECT) - { - er_json_find_line_column(json, er_json_node_location(parsetree), - &line, &col); + if (er_json_node_type(parsetree) != JSON_OBJECT) { + er_json_find_line_column(json, er_json_node_location(parsetree), &line, + &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, - "Expected an object at line %d column %d.", - line, col); + "Expected an object at line %d column %d.", line, + col); return NULL; } /* Find the common attributes for the parameter object in the JSON parse tree. For the description and context we use empty strings as default values if they were not found in the parse tree. */ - const char * name = get_string_from_object(parsetree, "name", json, - CPL_TRUE); - const char * class_name = get_string_from_object(parsetree, "class", json, - CPL_TRUE); - const char * desc = get_string_from_object(parsetree, "description", json, - CPL_FALSE); - if (desc == NULL) desc = ""; - const char * context = get_string_from_object(parsetree, "context", json, - CPL_FALSE); - if (context == NULL) context = ""; - - const er_json_node * node = get_value_from_object(parsetree, "default", - json); - if (node == NULL) return NULL; - if (cpl_error_get_code() != CPL_ERROR_NONE) return NULL; + const char *name = + get_string_from_object(parsetree, "name", json, CPL_TRUE); + const char *class_name = + get_string_from_object(parsetree, "class", json, CPL_TRUE); + const char *desc = + get_string_from_object(parsetree, "description", json, CPL_FALSE); + if (desc == NULL) + desc = ""; + const char *context = + get_string_from_object(parsetree, "context", json, CPL_FALSE); + if (context == NULL) + context = ""; + + const er_json_node *node = + get_value_from_object(parsetree, "default", json); + if (node == NULL) + return NULL; + if (cpl_error_get_code() != CPL_ERROR_NONE) + return NULL; /* Construct the CPL parameter object. We have to perform a custom invocation of one of cpl_parameter_new_value, cpl_parameter_new_range or cpl_parameter_new_enum, depending on the class indicated in the JSON parse tree (i.e. the value of class_name). */ - const er_json_node * mismatch_node = NULL; - cpl_parameter * param = NULL; - if (strcmp(class_name, "value") == 0) - { + const er_json_node *mismatch_node = NULL; + cpl_parameter *param = NULL; + if (strcmp(class_name, "value") == 0) { double num = NAN; /* We have to select the appropriate CPL type for the parameter object based on the JSON type of the default value's JSON node. */ - switch (er_json_node_type(node)) - { + switch (er_json_node_type(node)) { case JSON_BOOL: - param = cpl_parameter_new_value(name, CPL_TYPE_BOOL, - desc, context, - er_json_node_get_bool(node)); + param = + cpl_parameter_new_value(name, CPL_TYPE_BOOL, desc, context, + er_json_node_get_bool(node)); break; case JSON_NUMBER: num = er_json_node_get_number(node); - if (node_is_integer(node)) /* Check if num is an integer. */ + if (node_is_integer(node)) /* Check if num is an integer. */ { int inum = (int)num; param = cpl_parameter_new_value(name, CPL_TYPE_INT, desc, context, inum); } - else - { + else { param = cpl_parameter_new_value(name, CPL_TYPE_DOUBLE, desc, context, num); } break; case JSON_STRING: - param = cpl_parameter_new_value(name, CPL_TYPE_STRING, - desc, context, + param = cpl_parameter_new_value(name, CPL_TYPE_STRING, desc, + context, er_json_node_get_string(node)); break; @@ -3443,49 +3384,45 @@ &line, &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Type not supported for value at line %d" - " column %d.", line, col); + " column %d.", + line, col); return NULL; } } - else if (strcmp(class_name, "range") == 0) - { + else if (strcmp(class_name, "range") == 0) { double num = NAN; double min = NAN; double max = NAN; /* Fetch the JSON nodes corresponding to the minimum and maximum values of the range. */ - const er_json_node * min_node = get_value_from_object(parsetree, "min", - json); - const er_json_node * max_node = get_value_from_object(parsetree, "max", - json); - if (min_node == NULL || max_node == NULL) return NULL; + const er_json_node *min_node = + get_value_from_object(parsetree, "min", json); + const er_json_node *max_node = + get_value_from_object(parsetree, "max", json); + if (min_node == NULL || max_node == NULL) + return NULL; - switch (er_json_node_type(node)) - { + switch (er_json_node_type(node)) { case JSON_NUMBER: - if (er_json_node_type(min_node) != JSON_NUMBER) - { + if (er_json_node_type(min_node) != JSON_NUMBER) { mismatch_node = min_node; break; } - if (er_json_node_type(max_node) != JSON_NUMBER) - { + if (er_json_node_type(max_node) != JSON_NUMBER) { mismatch_node = max_node; break; } num = er_json_node_get_number(node); min = er_json_node_get_number(min_node); max = er_json_node_get_number(max_node); - if (node_is_integer(node)) /* Check if num is an integer. */ + if (node_is_integer(node)) /* Check if num is an integer. */ { /* Check that min and max are also integers. */ - if (! node_is_integer(min_node)) - { + if (!node_is_integer(min_node)) { mismatch_node = min_node; break; } - if (! node_is_integer(max_node)) - { + if (!node_is_integer(max_node)) { mismatch_node = max_node; break; } @@ -3498,8 +3435,7 @@ param = cpl_parameter_new_range(name, CPL_TYPE_INT, desc, context, inum, imin, imax); } - else - { + else { /* The number is already a double in this case so no typecasting is needed. */ param = cpl_parameter_new_range(name, CPL_TYPE_DOUBLE, desc, @@ -3512,51 +3448,48 @@ &line, &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Type not supported for range at line %d" - " column %d.", line, col); + " column %d.", + line, col); return NULL; } } - else if (strcmp(class_name, "enum") == 0) - { + else if (strcmp(class_name, "enum") == 0) { int type = CPL_TYPE_INVALID; int choices_count = 0; double num = NAN; int default_int = 0; - int * int_choices = NULL; + int *int_choices = NULL; double default_num = NAN; - double * num_choices = NULL; - const char * default_str = NULL; - const char ** str_choices = NULL; + double *num_choices = NULL; + const char *default_str = NULL; + const char **str_choices = NULL; /* Have to parse the choices list appropriately depending on the type of the default value (i.e. depending on whether is was an integer, double or string. */ - switch (er_json_node_type(node)) - { + switch (er_json_node_type(node)) { case JSON_NUMBER: num = er_json_node_get_number(node); - if (node_is_integer(node)) - { + if (node_is_integer(node)) { type = CPL_TYPE_INT; default_int = (int)num; if (get_ints_from_choices(parsetree, json, default_int, &choices_count, &int_choices, - &mismatch_node) - != CPL_ERROR_NONE) - { - if (mismatch_node == NULL) return NULL; + &mismatch_node) != + CPL_ERROR_NONE) { + if (mismatch_node == NULL) + return NULL; } } - else - { + else { type = CPL_TYPE_DOUBLE; default_num = num; if (get_doubles_from_choices(parsetree, json, default_num, &choices_count, &num_choices, - &mismatch_node) - != CPL_ERROR_NONE) - { - if (mismatch_node == NULL) return NULL; + &mismatch_node) != + CPL_ERROR_NONE) { + if (mismatch_node == NULL) + return NULL; } } break; @@ -3566,10 +3499,10 @@ default_str = er_json_node_get_string(node); if (get_strings_from_choices(parsetree, json, default_str, &choices_count, &str_choices, - &mismatch_node) - != CPL_ERROR_NONE) - { - if (mismatch_node == NULL) return NULL; + &mismatch_node) != + CPL_ERROR_NONE) { + if (mismatch_node == NULL) + return NULL; } break; @@ -3578,24 +3511,23 @@ &line, &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Type not supported for value at line %d" - " column %d.", line, col); + " column %d.", + line, col); return NULL; } - if (mismatch_node == NULL) - { + if (mismatch_node == NULL) { #ifdef HAVE_LIBAVCALL /* Prepare the dynamic argument list and make a call to the cpl_parameter_new_enum function to construct the CPL object. */ av_alist alist; - av_start_ptr(alist, &cpl_parameter_new_enum, - cpl_parameter *, ¶m); + av_start_ptr(alist, &cpl_parameter_new_enum, cpl_parameter *, + ¶m); av_ptr(alist, const char *, name); av_int(alist, type); av_ptr(alist, const char *, desc); av_ptr(alist, const char *, context); - switch (type) - { + switch (type) { case CPL_TYPE_INT: av_int(alist, default_int); break; @@ -3606,35 +3538,31 @@ av_ptr(alist, const char *, default_str); break; default: - assert(type == CPL_TYPE_INT || type == CPL_TYPE_DOUBLE - || type == CPL_TYPE_STRING); + assert(type == CPL_TYPE_INT || type == CPL_TYPE_DOUBLE || + type == CPL_TYPE_STRING); break; } av_int(alist, choices_count); int n = 0; - switch (type) - { + switch (type) { case CPL_TYPE_INT: - for (n = 0; n < choices_count; ++n) - { + for (n = 0; n < choices_count; ++n) { av_int(alist, int_choices[n]); } break; case CPL_TYPE_DOUBLE: - for (n = 0; n < choices_count; ++n) - { + for (n = 0; n < choices_count; ++n) { av_double(alist, num_choices[n]); } break; case CPL_TYPE_STRING: - for (n = 0; n < choices_count; ++n) - { + for (n = 0; n < choices_count; ++n) { av_ptr(alist, const char *, str_choices[n]); } break; default: - assert(type == CPL_TYPE_INT || type == CPL_TYPE_DOUBLE - || type == CPL_TYPE_STRING); + assert(type == CPL_TYPE_INT || type == CPL_TYPE_DOUBLE || + type == CPL_TYPE_STRING); break; } av_call(alist); @@ -3644,8 +3572,8 @@ cpl_parameter_new_enum function to construct the CPL object. */ ffi_cif cif; unsigned int nargs = 6 + choices_count; - ffi_type ** argtypes = cpl_malloc(nargs*sizeof(ffi_type *)); - const void ** args = cpl_malloc(nargs*sizeof(const void *)); + ffi_type **argtypes = cpl_malloc(nargs * sizeof(ffi_type *)); + const void **args = cpl_malloc(nargs * sizeof(const void *)); argtypes[0] = &ffi_type_pointer; args[0] = &name; argtypes[1] = &ffi_type_sint; @@ -3654,8 +3582,7 @@ args[2] = &desc; argtypes[3] = &ffi_type_pointer; args[3] = &context; - switch (type) - { + switch (type) { case CPL_TYPE_INT: argtypes[4] = &ffi_type_sint; args[4] = &default_int; @@ -3669,50 +3596,43 @@ args[4] = &default_str; break; default: - assert(type == CPL_TYPE_INT || type == CPL_TYPE_DOUBLE - || type == CPL_TYPE_STRING); + assert(type == CPL_TYPE_INT || type == CPL_TYPE_DOUBLE || + type == CPL_TYPE_STRING); break; } argtypes[5] = &ffi_type_sint; args[5] = &choices_count; int n = 0; - switch (type) - { + switch (type) { case CPL_TYPE_INT: - for (n = 0; n < choices_count; ++n) - { - argtypes[6+n] = &ffi_type_sint; - args[6+n] = &int_choices[n]; + for (n = 0; n < choices_count; ++n) { + argtypes[6 + n] = &ffi_type_sint; + args[6 + n] = &int_choices[n]; } break; case CPL_TYPE_DOUBLE: - for (n = 0; n < choices_count; ++n) - { - argtypes[6+n] = &ffi_type_double; - args[6+n] = &num_choices[n]; + for (n = 0; n < choices_count; ++n) { + argtypes[6 + n] = &ffi_type_double; + args[6 + n] = &num_choices[n]; } break; case CPL_TYPE_STRING: - for (n = 0; n < choices_count; ++n) - { - argtypes[6+n] = &ffi_type_pointer; - args[6+n] = &str_choices[n]; + for (n = 0; n < choices_count; ++n) { + argtypes[6 + n] = &ffi_type_pointer; + args[6 + n] = &str_choices[n]; } break; default: - assert(type == CPL_TYPE_INT || type == CPL_TYPE_DOUBLE - || type == CPL_TYPE_STRING); + assert(type == CPL_TYPE_INT || type == CPL_TYPE_DOUBLE || + type == CPL_TYPE_STRING); break; } if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, nargs, &ffi_type_pointer, - argtypes) - == FFI_OK) - { - ffi_call(&cif, (void (*)(void))&cpl_parameter_new_enum, ¶m, - (void**)args); + argtypes) == FFI_OK) { + ffi_call(&cif, (void (*)(void)) & cpl_parameter_new_enum, + ¶m, (void **)args); } - else - { + else { cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_OUTPUT, "Failed to make dynamic call to" " cpl_parameter_new_enum."); @@ -3720,7 +3640,7 @@ cpl_free(args); cpl_free(argtypes); #else /* HAVE_LIBFFI */ - /* Since we do not have either libavcall or libffi available generate a + /* Since we do not have either libavcall or libffi available generate a compiler error. */ #error Must have libavcall or libffi available. #endif /* HAVE_LIBFFI */ @@ -3734,11 +3654,10 @@ cpl_free(str_choices); } } - else - { + else { node = er_json_node_object_get(parsetree, "class"); - er_json_find_line_column(json, er_json_node_location(node), - &line, &col); + er_json_find_line_column(json, er_json_node_location(node), &line, + &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Invalid value for 'class' at line %d column %d." " Must be one of 'value', 'range' or 'enum'.", @@ -3746,41 +3665,37 @@ return NULL; } - if (mismatch_node != NULL) - { + if (mismatch_node != NULL) { er_json_find_line_column(json, er_json_node_location(mismatch_node), &line, &col); cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, - "Type mismatch between value at line %d" - " column %d and the type used for the" - " parameter's default value.", line, col); + "Type mismatch between value at line %d" + " column %d and the type used for the" + " parameter's default value.", + line, col); return NULL; } - if (param == NULL) return NULL; + if (param == NULL) + return NULL; /* Parse the value node and make sure that its type is compatible with the default value's type. The parameter is updated with the parsed value if one is found. Otherwise it is left as the default value. */ node = er_json_node_object_get(parsetree, "value"); - if (node != NULL) - { + if (node != NULL) { cpl_boolean type_mismatch = CPL_TRUE; - switch (cpl_parameter_get_type(param)) - { + switch (cpl_parameter_get_type(param)) { case CPL_TYPE_BOOL: - if (er_json_node_type(node) == JSON_BOOL) - { + if (er_json_node_type(node) == JSON_BOOL) { cpl_parameter_set_bool(param, er_json_node_get_bool(node)); type_mismatch = CPL_FALSE; } break; case CPL_TYPE_INT: - if (er_json_node_type(node) == JSON_NUMBER) - { + if (er_json_node_type(node) == JSON_NUMBER) { double num = er_json_node_get_number(node); - if (node_is_integer(node)) - { + if (node_is_integer(node)) { int inum = (int)num; cpl_parameter_set_int(param, inum); type_mismatch = CPL_FALSE; @@ -3789,8 +3704,7 @@ break; case CPL_TYPE_DOUBLE: - if (er_json_node_type(node) == JSON_NUMBER) - { + if (er_json_node_type(node) == JSON_NUMBER) { cpl_parameter_set_double(param, er_json_node_get_number(node)); type_mismatch = CPL_FALSE; @@ -3798,8 +3712,7 @@ break; case CPL_TYPE_STRING: - if (er_json_node_type(node) == JSON_STRING) - { + if (er_json_node_type(node) == JSON_STRING) { cpl_parameter_set_string(param, er_json_node_get_string(node)); type_mismatch = CPL_FALSE; @@ -3809,14 +3722,14 @@ default: type_mismatch = CPL_TRUE; } - if (type_mismatch) - { - er_json_find_line_column(json, er_json_node_location(node), - &line, &col); + if (type_mismatch) { + er_json_find_line_column(json, er_json_node_location(node), &line, + &col); cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "Type mismatch between value at line %d" " column %d and the type used for the" - " parameter's default value.", line, col); + " parameter's default value.", + line, col); cpl_parameter_delete(param); return NULL; } @@ -3825,12 +3738,10 @@ /* Update the flag indicating presence if it is available in the parse tree. */ node = er_json_node_object_get(parsetree, "present"); - if (node != NULL) - { - if (er_json_node_type(node) != JSON_BOOL) - { - er_json_find_line_column(json, er_json_node_location(node), - &line, &col); + if (node != NULL) { + if (er_json_node_type(node) != JSON_BOOL) { + er_json_find_line_column(json, er_json_node_location(node), &line, + &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Expected a boolean at line %d column %d.", line, col); @@ -3842,12 +3753,10 @@ /* Update the ID if it is available in the parse tree. */ node = er_json_node_object_get(parsetree, "id"); - if (node != NULL) - { - if (er_json_node_type(node) != JSON_NUMBER) - { - er_json_find_line_column(json, er_json_node_location(node), - &line, &col); + if (node != NULL) { + if (er_json_node_type(node) != JSON_NUMBER) { + er_json_find_line_column(json, er_json_node_location(node), &line, + &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Expected an integer at line %d column %d.", line, col); @@ -3860,25 +3769,22 @@ /* Update the tag if it is available in the parse tree and not NULL. */ node = er_json_node_object_get(parsetree, "tag"); - if (node != NULL) - { - if (er_json_node_type(node) == JSON_STRING) - { + if (node != NULL) { + if (er_json_node_type(node) == JSON_STRING) { cpl_parameter_set_tag(param, er_json_node_get_string(node)); } - else if (er_json_node_type(node) == JSON_NULL) - { + else if (er_json_node_type(node) == JSON_NULL) { /* Nothing to do in this case. The tag is set by default and calling cpl_parameter_set_tag() with a NULL value for the new tag will generate a CPL error. */ } - else - { - er_json_find_line_column(json, er_json_node_location(node), - &line, &col); + else { + er_json_find_line_column(json, er_json_node_location(node), &line, + &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Expected a string or null at line %d column" - " %d.", line, col); + " %d.", + line, col); cpl_parameter_delete(param); return NULL; } @@ -3886,46 +3792,34 @@ /* Update the enable flags if they are available in the parse tree. */ if (set_param_enable_flag(param, parsetree, json, "cli_enabled", - CPL_PARAMETER_MODE_CLI) - != CPL_ERROR_NONE) - { + CPL_PARAMETER_MODE_CLI) != CPL_ERROR_NONE) { cpl_parameter_delete(param); return NULL; } if (set_param_enable_flag(param, parsetree, json, "env_enabled", - CPL_PARAMETER_MODE_ENV) - != CPL_ERROR_NONE) - { + CPL_PARAMETER_MODE_ENV) != CPL_ERROR_NONE) { cpl_parameter_delete(param); return NULL; } if (set_param_enable_flag(param, parsetree, json, "cfg_enabled", - CPL_PARAMETER_MODE_CFG) - != CPL_ERROR_NONE) - { + CPL_PARAMETER_MODE_CFG) != CPL_ERROR_NONE) { cpl_parameter_delete(param); return NULL; } /* Update the aliases if they are available in the parse tree. */ if (set_param_alias(param, parsetree, json, "cli_alias", - CPL_PARAMETER_MODE_CLI) - != CPL_ERROR_NONE) - { + CPL_PARAMETER_MODE_CLI) != CPL_ERROR_NONE) { cpl_parameter_delete(param); return NULL; } if (set_param_alias(param, parsetree, json, "env_alias", - CPL_PARAMETER_MODE_ENV) - != CPL_ERROR_NONE) - { + CPL_PARAMETER_MODE_ENV) != CPL_ERROR_NONE) { cpl_parameter_delete(param); return NULL; } if (set_param_alias(param, parsetree, json, "cfg_alias", - CPL_PARAMETER_MODE_CFG) - != CPL_ERROR_NONE) - { + CPL_PARAMETER_MODE_CFG) != CPL_ERROR_NONE) { cpl_parameter_delete(param); return NULL; } @@ -3945,21 +3839,20 @@ * if an error occurred. Errors indicate that the parsed JSON does not * correspond to a proper CPL parameter list. */ -static cpl_parameterlist * json_to_parameterlist(const er_json_node * parsetree, - const char * json) +static cpl_parameterlist * +json_to_parameterlist(const er_json_node *parsetree, const char *json) { - if (er_json_node_type(parsetree) != JSON_ARRAY) - { + if (er_json_node_type(parsetree) != JSON_ARRAY) { int line, col; - er_json_find_line_column(json, er_json_node_location(parsetree), - &line, &col); + er_json_find_line_column(json, er_json_node_location(parsetree), &line, + &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, - "Expected an array at line %d column %d.", - line, col); + "Expected an array at line %d column %d.", line, + col); return NULL; } - cpl_parameterlist * list = cpl_parameterlist_new(); + cpl_parameterlist *list = cpl_parameterlist_new(); /* Traverse every element in the JSON array and convert it into a CPL parameter object. Add the new parameter object to the output list and @@ -3967,13 +3860,11 @@ er_json_array_iterator iter = NULL; for (iter = er_json_node_array_begin(parsetree); iter != er_json_node_array_end(parsetree); - iter = er_json_node_array_next(parsetree, iter)) - { - const er_json_node * item = er_json_node_array_get(parsetree, iter); - cpl_parameter * param = json_to_parameter(item, json); + iter = er_json_node_array_next(parsetree, iter)) { + const er_json_node *item = er_json_node_array_get(parsetree, iter); + cpl_parameter *param = json_to_parameter(item, json); if (param == NULL || - cpl_parameterlist_append(list, param) != CPL_ERROR_NONE) - { + cpl_parameterlist_append(list, param) != CPL_ERROR_NONE) { cpl_parameter_delete(param); cpl_parameterlist_delete(list); return NULL; @@ -3995,44 +3886,44 @@ * if an error occurred. Errors indicate that the parsed JSON does not * correspond to a proper CPL frame object. */ -static cpl_frame * json_to_frame(const er_json_node * parsetree, - const char * json) +static cpl_frame * +json_to_frame(const er_json_node *parsetree, const char *json) { int line, col; - if (er_json_node_type(parsetree) != JSON_OBJECT) - { - er_json_find_line_column(json, er_json_node_location(parsetree), - &line, &col); + if (er_json_node_type(parsetree) != JSON_OBJECT) { + er_json_find_line_column(json, er_json_node_location(parsetree), &line, + &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, - "Expected an object at line %d column %d.", - line, col); + "Expected an object at line %d column %d.", line, + col); return NULL; } - const char * filename = get_string_from_object(parsetree, "filename", json, - CPL_TRUE); - if (filename == NULL) return NULL; - const char * tag = get_string_from_object(parsetree, "tag", json, CPL_TRUE); - if (tag == NULL) return NULL; - unsigned long type = get_ulong_from_object(parsetree, "type", json, - CPL_TRUE); - unsigned long group = get_ulong_from_object(parsetree, "group", json, - CPL_TRUE); - unsigned long level = get_ulong_from_object(parsetree, "level", json, - CPL_TRUE); - if (cpl_error_get_code() != CPL_ERROR_NONE) - { + const char *filename = + get_string_from_object(parsetree, "filename", json, CPL_TRUE); + if (filename == NULL) + return NULL; + const char *tag = get_string_from_object(parsetree, "tag", json, CPL_TRUE); + if (tag == NULL) + return NULL; + unsigned long type = + get_ulong_from_object(parsetree, "type", json, CPL_TRUE); + unsigned long group = + get_ulong_from_object(parsetree, "group", json, CPL_TRUE); + unsigned long level = + get_ulong_from_object(parsetree, "level", json, CPL_TRUE); + if (cpl_error_get_code() != CPL_ERROR_NONE) { /* Stop here if we had any parse errors. */ return NULL; } - cpl_frame * frame = cpl_frame_new(); + cpl_frame *frame = cpl_frame_new(); cpl_frame_set_filename(frame, filename); cpl_frame_set_tag(frame, tag); - cpl_frame_set_type(frame, (cpl_frame_type) type); - cpl_frame_set_group(frame, (cpl_frame_group) group); - cpl_frame_set_level(frame, (cpl_frame_level) level); + cpl_frame_set_type(frame, (cpl_frame_type)type); + cpl_frame_set_group(frame, (cpl_frame_group)group); + cpl_frame_set_level(frame, (cpl_frame_level)level); return frame; } @@ -4048,21 +3939,20 @@ * if an error occurred. Errors indicate that the parsed JSON does not * correspond to a proper CPL frame set. */ -static cpl_frameset * json_to_frameset(const er_json_node * parsetree, - const char * json) +static cpl_frameset * +json_to_frameset(const er_json_node *parsetree, const char *json) { - if (er_json_node_type(parsetree) != JSON_ARRAY) - { + if (er_json_node_type(parsetree) != JSON_ARRAY) { int line, col; - er_json_find_line_column(json, er_json_node_location(parsetree), - &line, &col); + er_json_find_line_column(json, er_json_node_location(parsetree), &line, + &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, - "Expected an array at line %d column %d.", - line, col); + "Expected an array at line %d column %d.", line, + col); return NULL; } - cpl_frameset * frameset = cpl_frameset_new(); + cpl_frameset *frameset = cpl_frameset_new(); /* Traverse every element in the JSON array and convert it into a CPL frame object. Add the new frame to the output frameset and return the @@ -4070,13 +3960,11 @@ er_json_array_iterator iter = NULL; for (iter = er_json_node_array_begin(parsetree); iter != er_json_node_array_end(parsetree); - iter = er_json_node_array_next(parsetree, iter)) - { - const er_json_node * item = er_json_node_array_get(parsetree, iter); - cpl_frame * frame = json_to_frame(item, json); + iter = er_json_node_array_next(parsetree, iter)) { + const er_json_node *item = er_json_node_array_get(parsetree, iter); + cpl_frame *frame = json_to_frame(item, json); if (frame == NULL || - cpl_frameset_insert(frameset, frame) != CPL_ERROR_NONE) - { + cpl_frameset_insert(frameset, frame) != CPL_ERROR_NONE) { cpl_frame_delete(frame); cpl_frameset_delete(frameset); return NULL; @@ -4102,10 +3990,11 @@ * Errors indicate that the parsed JSON does not correspond to a proper * list of input entries. */ -static cpl_error_code add_recipeconfig_inputs(const er_json_node * parsetree, - const char * json, - cpl_recipeconfig * config, - const char * tag) +static cpl_error_code +add_recipeconfig_inputs(const er_json_node *parsetree, + const char *json, + cpl_recipeconfig *config, + const char *tag) { assert(parsetree != NULL); assert(json != NULL); @@ -4113,10 +4002,9 @@ assert(tag != NULL); int line, col; - if (er_json_node_type(parsetree) != JSON_ARRAY) - { - er_json_find_line_column(json, er_json_node_location(parsetree), - &line, &col); + if (er_json_node_type(parsetree) != JSON_ARRAY) { + er_json_find_line_column(json, er_json_node_location(parsetree), &line, + &col); return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Expected an array at line %d column %d.", line, col); @@ -4126,39 +4014,38 @@ er_json_array_iterator iter = NULL; for (iter = er_json_node_array_begin(parsetree); iter != er_json_node_array_end(parsetree); - iter = er_json_node_array_next(parsetree, iter)) - { - const er_json_node * item = er_json_node_array_get(parsetree, iter); + iter = er_json_node_array_next(parsetree, iter)) { + const er_json_node *item = er_json_node_array_get(parsetree, iter); - if (er_json_node_type(item) != JSON_OBJECT) - { - er_json_find_line_column(json, er_json_node_location(item), - &line, &col); + if (er_json_node_type(item) != JSON_OBJECT) { + er_json_find_line_column(json, er_json_node_location(item), &line, + &col); return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Expected an object at line %d column" - " %d.", line, col); + " %d.", + line, col); } /* Extract the input's tag string, check that it is not an empty string and that it does not equal the primary tag. We do these extra checks, since the recipeconfig object does not allow empty strings for the inputs or tag == input. */ - const char * input = get_string_from_object(item, "tag", json, CPL_TRUE); - if (input == NULL) return cpl_error_get_code(); - if (strcmp(input, "") == 0) - { - const er_json_node * node = er_json_node_object_get(item, "tag"); - er_json_find_line_column(json, er_json_node_location(node), - &line, &col); + const char *input = get_string_from_object(item, "tag", json, CPL_TRUE); + if (input == NULL) + return cpl_error_get_code(); + if (strcmp(input, "") == 0) { + const er_json_node *node = er_json_node_object_get(item, "tag"); + er_json_find_line_column(json, er_json_node_location(node), &line, + &col); return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Input tag is an empty string at line" - " %d column %d.", line, col); + " %d column %d.", + line, col); } - if (strcmp(input, tag) == 0) - { - const er_json_node * node = er_json_node_object_get(item, "tag"); - er_json_find_line_column(json, er_json_node_location(node), - &line, &col); + if (strcmp(input, tag) == 0) { + const er_json_node *node = er_json_node_object_get(item, "tag"); + er_json_find_line_column(json, er_json_node_location(node), &line, + &col); return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Input tag at line %d column %d cannot" " be the same as the primary tag.", @@ -4168,15 +4055,13 @@ /* Extract the minimum and maximum frame counts for the input. */ cpl_size min = get_cpl_size_from_object(item, "min", json); cpl_size max = get_cpl_size_from_object(item, "max", json); - if (cpl_error_get_code() != CPL_ERROR_NONE) - { + if (cpl_error_get_code() != CPL_ERROR_NONE) { /* Stop here if we had any parse errors. */ return cpl_error_get_code(); } - if (cpl_recipeconfig_set_input(config, tag, input, - (cpl_size)min, (cpl_size)max) != 0) - { + if (cpl_recipeconfig_set_input(config, tag, input, (cpl_size)min, + (cpl_size)max) != 0) { return cpl_error_get_code(); } } @@ -4200,10 +4085,11 @@ * Errors indicate that the parsed JSON does not correspond to a proper * list of output entries. */ -static cpl_error_code add_recipeconfig_outputs(const er_json_node * parsetree, - const char * json, - cpl_recipeconfig * config, - const char * tag) +static cpl_error_code +add_recipeconfig_outputs(const er_json_node *parsetree, + const char *json, + cpl_recipeconfig *config, + const char *tag) { assert(parsetree != NULL); assert(json != NULL); @@ -4211,10 +4097,9 @@ assert(tag != NULL); int line, col; - if (er_json_node_type(parsetree) != JSON_ARRAY) - { - er_json_find_line_column(json, er_json_node_location(parsetree), - &line, &col); + if (er_json_node_type(parsetree) != JSON_ARRAY) { + er_json_find_line_column(json, er_json_node_location(parsetree), &line, + &col); return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Expected an array at line %d column %d.", line, col); @@ -4224,32 +4109,30 @@ er_json_array_iterator iter = NULL; for (iter = er_json_node_array_begin(parsetree); iter != er_json_node_array_end(parsetree); - iter = er_json_node_array_next(parsetree, iter)) - { - const er_json_node * item = er_json_node_array_get(parsetree, iter); + iter = er_json_node_array_next(parsetree, iter)) { + const er_json_node *item = er_json_node_array_get(parsetree, iter); - if (er_json_node_type(item) != JSON_STRING) - { - er_json_find_line_column(json, er_json_node_location(item), - &line, &col); + if (er_json_node_type(item) != JSON_STRING) { + er_json_find_line_column(json, er_json_node_location(item), &line, + &col); return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Expected a string at line %d column" - " %d.", line, col); + " %d.", + line, col); } - const char * output = er_json_node_get_string(item); + const char *output = er_json_node_get_string(item); /* Make sure the output tag is not an empty string since the cpl_recipeconfig object does not accept empty strings. */ - if (strcmp(output, "") == 0) - { - er_json_find_line_column(json, er_json_node_location(item), - &line, &col); + if (strcmp(output, "") == 0) { + er_json_find_line_column(json, er_json_node_location(item), &line, + &col); return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Output tag is an empty string at line" - " %d column %d.", line, col); + " %d column %d.", + line, col); } - if (cpl_recipeconfig_set_output(config, tag, output) != 0) - { + if (cpl_recipeconfig_set_output(config, tag, output) != 0) { return cpl_error_get_code(); } } @@ -4271,21 +4154,21 @@ * Errors indicate that the parsed JSON does not correspond to a proper * tag entry. */ -static cpl_error_code add_recipeconfig_tag(const er_json_node * parsetree, - const char * json, - cpl_recipeconfig * config) +static cpl_error_code +add_recipeconfig_tag(const er_json_node *parsetree, + const char *json, + cpl_recipeconfig *config) { assert(parsetree != NULL); assert(json != NULL); assert(config != NULL); - const er_json_node * node; + const er_json_node *node; int line, col; - if (er_json_node_type(parsetree) != JSON_OBJECT) - { - er_json_find_line_column(json, er_json_node_location(parsetree), - &line, &col); + if (er_json_node_type(parsetree) != JSON_OBJECT) { + er_json_find_line_column(json, er_json_node_location(parsetree), &line, + &col); return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Expected an object at line %d column %d.", line, col); @@ -4294,48 +4177,45 @@ /* Extract the tag string and check that it is not an empty string. We do this check since the recipeconfig object does not allow empty strings for the tags. */ - const char * tag = get_string_from_object(parsetree, "tag", json, CPL_TRUE); - if (tag == NULL) return cpl_error_get_code(); - if (strcmp(tag, "") == 0) - { + const char *tag = get_string_from_object(parsetree, "tag", json, CPL_TRUE); + if (tag == NULL) + return cpl_error_get_code(); + if (strcmp(tag, "") == 0) { node = er_json_node_object_get(parsetree, "tag"); - er_json_find_line_column(json, er_json_node_location(node), - &line, &col); + er_json_find_line_column(json, er_json_node_location(node), &line, + &col); return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Tag is an empty string at line %d column" - " %d.", line, col); + " %d.", + line, col); } /* Extract the minimum and maximum frame counts corresponding to the tag, then actually add the new tag entry to the configuration. */ cpl_size min = get_cpl_size_from_object(parsetree, "min", json); cpl_size max = get_cpl_size_from_object(parsetree, "max", json); - if (cpl_error_get_code() != CPL_ERROR_NONE) - { + if (cpl_error_get_code() != CPL_ERROR_NONE) { /* Stop here if we had any parse errors. */ return cpl_error_get_code(); } - if (cpl_recipeconfig_set_tag(config, tag, (cpl_size)min, (cpl_size)max) - != 0) - { + if (cpl_recipeconfig_set_tag(config, tag, (cpl_size)min, (cpl_size)max) != + 0) { return cpl_error_get_code(); } /* Convert and add the input and output arrays if they were given. */ node = er_json_node_object_get(parsetree, "inputs"); - if (node != NULL) - { - if (add_recipeconfig_inputs(node, json, config, tag) != CPL_ERROR_NONE) - { + if (node != NULL) { + if (add_recipeconfig_inputs(node, json, config, tag) != + CPL_ERROR_NONE) { return cpl_error_get_code(); } } node = er_json_node_object_get(parsetree, "outputs"); - if (node != NULL) - { - if (add_recipeconfig_outputs(node, json, config, tag) != CPL_ERROR_NONE) - { + if (node != NULL) { + if (add_recipeconfig_outputs(node, json, config, tag) != + CPL_ERROR_NONE) { return cpl_error_get_code(); } } @@ -4355,32 +4235,29 @@ * JSON or @c NULL if an error occurred. Errors indicate that the parsed * JSON does not correspond to a proper recipe configuration object. */ -static cpl_recipeconfig * json_to_recipeconfig(const er_json_node * parsetree, - const char * json) +static cpl_recipeconfig * +json_to_recipeconfig(const er_json_node *parsetree, const char *json) { int line, col; - if (er_json_node_type(parsetree) != JSON_ARRAY) - { - er_json_find_line_column(json, er_json_node_location(parsetree), - &line, &col); + if (er_json_node_type(parsetree) != JSON_ARRAY) { + er_json_find_line_column(json, er_json_node_location(parsetree), &line, + &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, - "Expected an array at line %d column %d.", - line, col); + "Expected an array at line %d column %d.", line, + col); return NULL; } - cpl_recipeconfig * config = cpl_recipeconfig_new(); + cpl_recipeconfig *config = cpl_recipeconfig_new(); /* Traverse the JSON array and convert each tag, adding the information to the configuration object as we go. */ er_json_array_iterator iter = NULL; for (iter = er_json_node_array_begin(parsetree); iter != er_json_node_array_end(parsetree); - iter = er_json_node_array_next(parsetree, iter)) - { - const er_json_node * item = er_json_node_array_get(parsetree, iter); - if (add_recipeconfig_tag(item, json, config) != CPL_ERROR_NONE) - { + iter = er_json_node_array_next(parsetree, iter)) { + const er_json_node *item = er_json_node_array_get(parsetree, iter); + if (add_recipeconfig_tag(item, json, config) != CPL_ERROR_NONE) { cpl_recipeconfig_delete(config); return NULL; } @@ -4394,10 +4271,11 @@ * The er_json_to_plugin function will assign the plugin's destructor method to * this function when it is creating a new v1 type recipe. */ -static int recipe_deinitialize(cpl_plugin * plugin) +static int +recipe_deinitialize(cpl_plugin *plugin) { assert(plugin != NULL); - cpl_recipe * recipe = (cpl_recipe *) plugin; + cpl_recipe *recipe = (cpl_recipe *)plugin; cpl_parameterlist_delete(recipe->parameters); cpl_frameset_delete(recipe->frames); return 0; @@ -4408,10 +4286,11 @@ * The er_json_to_plugin function will assign the plugin's destructor method to * this function when it is creating a new v2 type recipe. */ -static int recipe2_deinitialize(cpl_plugin * plugin) +static int +recipe2_deinitialize(cpl_plugin *plugin) { assert(plugin != NULL); - cpl_recipe2 * recipe = (cpl_recipe2 *) plugin; + cpl_recipe2 *recipe = (cpl_recipe2 *)plugin; cpl_parameterlist_delete(recipe->base.parameters); cpl_frameset_delete(recipe->base.frames); cpl_recipeconfig_delete(recipe->config); @@ -4447,8 +4326,8 @@ * cpl_plugin_delete(plugin); * @endcode */ -cpl_plugin * er_json_to_plugin(const er_json_node * parsetree, - const char * json) +cpl_plugin * +er_json_to_plugin(const er_json_node *parsetree, const char *json) { cpl_error_ensure(parsetree != NULL, CPL_ERROR_NULL_INPUT, return NULL, "Input JSON parse tree is NULL."); @@ -4456,35 +4335,33 @@ "JSON text is NULL."); /* Make sure the top level node in the parse tree is an object. */ - if (er_json_node_type(parsetree) != JSON_OBJECT) - { + if (er_json_node_type(parsetree) != JSON_OBJECT) { int line, col; - er_json_find_line_column(json, er_json_node_location(parsetree), - &line, &col); + er_json_find_line_column(json, er_json_node_location(parsetree), &line, + &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, - "Expected an object at line %d column %d.", - line, col); + "Expected an object at line %d column %d.", line, + col); return NULL; } - const char * classname = get_string_from_object(parsetree, "class", json, - CPL_TRUE); - const char * name = get_string_from_object(parsetree, "name", json, - CPL_FALSE); - unsigned long version = get_ulong_from_object(parsetree, "version", json, - CPL_FALSE); - const char * synopsis = get_string_from_object(parsetree, "synopsis", json, - CPL_FALSE); - const char * desc = get_string_from_object(parsetree, "description", json, - CPL_FALSE); - const char * author = get_string_from_object(parsetree, "author", json, - CPL_FALSE); - const char * email = get_string_from_object(parsetree, "email", json, - CPL_FALSE); - const char * cpright = get_string_from_object(parsetree, "copyright", json, - CPL_FALSE); - if (cpl_error_get_code() != CPL_ERROR_NONE) - { + const char *classname = + get_string_from_object(parsetree, "class", json, CPL_TRUE); + const char *name = + get_string_from_object(parsetree, "name", json, CPL_FALSE); + unsigned long version = + get_ulong_from_object(parsetree, "version", json, CPL_FALSE); + const char *synopsis = + get_string_from_object(parsetree, "synopsis", json, CPL_FALSE); + const char *desc = + get_string_from_object(parsetree, "description", json, CPL_FALSE); + const char *author = + get_string_from_object(parsetree, "author", json, CPL_FALSE); + const char *email = + get_string_from_object(parsetree, "email", json, CPL_FALSE); + const char *cpright = + get_string_from_object(parsetree, "copyright", json, CPL_FALSE); + if (cpl_error_get_code() != CPL_ERROR_NONE) { /* Stop here if we had any parse errors. */ return NULL; } @@ -4493,38 +4370,43 @@ assert(classname != NULL); /* Set default values if they were not found in the object node. */ - if (name == NULL) name = classname; - if (synopsis == NULL) synopsis = "unknown"; - if (desc == NULL) desc = "unknown"; - if (author == NULL) author = "unknown"; - if (email == NULL) email = "unknown"; - if (cpright == NULL) cpright = "unknown"; - - const er_json_node * params = er_json_node_object_get(parsetree, - "parameters"); - if (params == NULL) - { + if (name == NULL) + name = classname; + if (synopsis == NULL) + synopsis = "unknown"; + if (desc == NULL) + desc = "unknown"; + if (author == NULL) + author = "unknown"; + if (email == NULL) + email = "unknown"; + if (cpright == NULL) + cpright = "unknown"; + + const er_json_node *params = + er_json_node_object_get(parsetree, "parameters"); + if (params == NULL) { int line, col; - er_json_find_line_column(json, er_json_node_location(parsetree), - &line, &col); + er_json_find_line_column(json, er_json_node_location(parsetree), &line, + &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Object starting at line %d column %d does not" - " have a key called 'parameters'.", line, col); + " have a key called 'parameters'.", + line, col); return NULL; } /* Convert the parameter list to a cpl_parameterlist object. */ - cpl_parameterlist * paramlist = json_to_parameterlist(params, json); - if (paramlist == NULL) return NULL; + cpl_parameterlist *paramlist = json_to_parameterlist(params, json); + if (paramlist == NULL) + return NULL; /* Convert the frames list to a cpl_frameset object. */ - const er_json_node * frames = er_json_node_object_get(parsetree, "frames"); - cpl_frameset * frameset = NULL; - if (frames != NULL) - { + const er_json_node *frames = er_json_node_object_get(parsetree, "frames"); + cpl_frameset *frameset = NULL; + if (frames != NULL) { frameset = json_to_frameset(frames, json); - if (frameset == NULL) - { + if (frameset == NULL) { cpl_parameterlist_delete(paramlist); return NULL; } @@ -4535,58 +4417,51 @@ NOTE: this parameter will have to be stripped later on before giving this plugin object to the upper EsoRex code. */ - cpl_parameter * param = cpl_parameter_new_value("__class__", - CPL_TYPE_STRING, - "Python class name", - "__python__", - classname); - if (param == NULL) - { + cpl_parameter *param = + cpl_parameter_new_value("__class__", CPL_TYPE_STRING, + "Python class name", "__python__", classname); + if (param == NULL) { cpl_parameterlist_delete(paramlist); cpl_frameset_delete(frameset); return NULL; } - if (cpl_parameterlist_append(paramlist, param) != CPL_ERROR_NONE) - { + if (cpl_parameterlist_append(paramlist, param) != CPL_ERROR_NONE) { cpl_parameter_delete(param); cpl_parameterlist_delete(paramlist); cpl_frameset_delete(frameset); return NULL; } - cpl_plugin * plugin = NULL; + cpl_plugin *plugin = NULL; unsigned long plugin_type = CPL_PLUGIN_TYPE_NONE; cpl_plugin_func deinitfunc = NULL; /* Decide what kind of recipe plugin we need to create. If the parse tree contains 'recipeconfig' then its a version 2 recipe, otherwise it must be a version 1 recipe. */ - const er_json_node * recipeconfig = er_json_node_object_get(parsetree, - "recipeconfig"); - if (recipeconfig == NULL) - { - cpl_recipe * recipe = cpl_calloc(1, sizeof(cpl_recipe)); + const er_json_node *recipeconfig = + er_json_node_object_get(parsetree, "recipeconfig"); + if (recipeconfig == NULL) { + cpl_recipe *recipe = cpl_calloc(1, sizeof(cpl_recipe)); plugin = &recipe->interface; plugin_type = CPL_PLUGIN_TYPE_RECIPE; deinitfunc = recipe_deinitialize; recipe->parameters = paramlist; recipe->frames = frameset; } - else - { + else { /* Parse the recipeconfig object first before allocating memory for the plugin object. In case there are parsing errors, will have less to cleanup. */ - cpl_recipeconfig * config = json_to_recipeconfig(recipeconfig, json); - if (config == NULL) - { + cpl_recipeconfig *config = json_to_recipeconfig(recipeconfig, json); + if (config == NULL) { cpl_parameterlist_delete(paramlist); /* The following is safe because NULL is implicitly checked for. */ cpl_frameset_delete(frameset); return NULL; } - cpl_recipe2 * recipe = cpl_calloc(1, sizeof(cpl_recipe2)); + cpl_recipe2 *recipe = cpl_calloc(1, sizeof(cpl_recipe2)); plugin = &recipe->base.interface; plugin_type = CPL_PLUGIN_TYPE_RECIPE_V2; deinitfunc = recipe2_deinitialize; @@ -4595,12 +4470,11 @@ recipe->config = config; } - cpl_error_code result = cpl_plugin_init(plugin, CPL_PLUGIN_API, version, - plugin_type, name, synopsis, desc, - author, email, cpright, - NULL, NULL, deinitfunc); - if (result != CPL_ERROR_NONE) - { + cpl_error_code result = + cpl_plugin_init(plugin, CPL_PLUGIN_API, version, plugin_type, name, + synopsis, desc, author, email, cpright, NULL, NULL, + deinitfunc); + if (result != CPL_ERROR_NONE) { cpl_parameterlist_delete(paramlist); cpl_frameset_delete(frameset); /* Do not call deinitialize since we never got to complete @@ -4631,8 +4505,8 @@ * @note The returned object must be freed with er_json_pluginlist_delete() * by the caller when it is no longer needed. */ -cpl_pluginlist * er_json_to_pluginlist(const er_json_node * parsetree, - const char * json) +cpl_pluginlist * +er_json_to_pluginlist(const er_json_node *parsetree, const char *json) { cpl_error_ensure(parsetree != NULL, CPL_ERROR_NULL_INPUT, return NULL, "Input JSON parse tree is NULL."); @@ -4640,38 +4514,34 @@ "JSON text is NULL."); /* Make sure the top level node in the parse tree is an array. */ - if (er_json_node_type(parsetree) != JSON_ARRAY) - { + if (er_json_node_type(parsetree) != JSON_ARRAY) { int line, col; - er_json_find_line_column(json, er_json_node_location(parsetree), - &line, &col); + er_json_find_line_column(json, er_json_node_location(parsetree), &line, + &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, - "Expected an array at line %d column %d.", - line, col); + "Expected an array at line %d column %d.", line, + col); return NULL; } - cpl_pluginlist * plugins = cpl_pluginlist_new(); + cpl_pluginlist *plugins = cpl_pluginlist_new(); /* Convert and add every plugin found in the array to the plugins list. */ er_json_array_iterator iter = NULL; for (iter = er_json_node_array_begin(parsetree); iter != er_json_node_array_end(parsetree); - iter = er_json_node_array_next(parsetree, iter)) - { - const er_json_node * item = er_json_node_array_get(parsetree, iter); - cpl_plugin * plugin = er_json_to_plugin(item, json); - if (plugin == NULL) - { + iter = er_json_node_array_next(parsetree, iter)) { + const er_json_node *item = er_json_node_array_get(parsetree, iter); + cpl_plugin *plugin = er_json_to_plugin(item, json); + if (plugin == NULL) { er_json_pluginlist_delete(plugins); return NULL; } - if (cpl_pluginlist_append(plugins, plugin) != CPL_ERROR_NONE) - { + if (cpl_pluginlist_append(plugins, plugin) != CPL_ERROR_NONE) { /* Ignore result from deinitialize because we are already handling another error. */ int result = plugin->deinitialize(plugin); - (void) result; /* Avoid warnings if the NDEBUG macro is set. */ + (void)result; /* Avoid warnings if the NDEBUG macro is set. */ cpl_plugin_delete(plugin); er_json_pluginlist_delete(plugins); return NULL; @@ -4686,20 +4556,19 @@ * * @param list The list of CPL plugins to delete. */ -void er_json_pluginlist_delete(cpl_pluginlist * list) +void +er_json_pluginlist_delete(cpl_pluginlist *list) { - cpl_plugin * plugin = NULL; - if (list == NULL) return; - for (plugin = cpl_pluginlist_get_first(list); - plugin != NULL; - plugin = cpl_pluginlist_get_next(list)) - { + cpl_plugin *plugin = NULL; + if (list == NULL) + return; + for (plugin = cpl_pluginlist_get_first(list); plugin != NULL; + plugin = cpl_pluginlist_get_next(list)) { /* Call the plugin's destructor if it has one. NOTE: we ignore the output because in our context it should always succeed. */ - if (plugin->deinitialize != NULL) - { + if (plugin->deinitialize != NULL) { int result = plugin->deinitialize(plugin); - (void) result; /* Avoid warnings if the NDEBUG macro is set. */ + (void)result; /* Avoid warnings if the NDEBUG macro is set. */ assert(result == 0); } } diff -Nru esorex-3.13.5+ds/src/er_json.h esorex-3.13.6+ds/src/er_json.h --- esorex-3.13.5+ds/src/er_json.h 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/er_json.h 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 European Southern Observatory * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif #ifndef ER_JSON_H @@ -33,10 +33,10 @@ * Functions for converting CPL objects to JSON. */ -cpl_error_code er_frameset_to_json(const cpl_frameset *frameset, - const char *json_file); -cpl_error_code er_frameset_to_text(const cpl_frameset *frameset, - const char *text_file); +cpl_error_code +er_frameset_to_json(const cpl_frameset *frameset, const char *json_file); +cpl_error_code +er_frameset_to_text(const cpl_frameset *frameset, const char *text_file); cpl_error_code er_recipe_parameterlist_to_json(const cpl_parameterlist *plist, const char *recipe_name, const char *json_file); @@ -58,64 +58,64 @@ } er_json_type; typedef struct _er_json_node_ er_json_node; -typedef const struct _cx_lnode_ * er_json_array_iterator; -typedef const struct _cx_tnode_ * er_json_object_iterator; +typedef const struct _cx_lnode_ *er_json_array_iterator; +typedef const struct _cx_tnode_ *er_json_object_iterator; -er_json_node * er_json_parse(const char * json); +er_json_node *er_json_parse(const char *json); -void er_json_node_delete(er_json_node * obj); -er_json_type er_json_node_type(const er_json_node * obj); -const char * er_json_node_location(const er_json_node * obj); -cpl_boolean er_json_node_get_bool(const er_json_node * obj); -double er_json_node_get_number(const er_json_node * obj); -const char * er_json_node_get_string(const er_json_node * obj); -cpl_size er_json_node_array_size(const er_json_node * obj); -cpl_boolean er_json_node_array_empty(const er_json_node * obj); -er_json_array_iterator er_json_node_array_begin(const er_json_node * obj); -er_json_array_iterator er_json_node_array_end(const er_json_node * obj); -er_json_array_iterator er_json_node_array_next(const er_json_node * obj, +void er_json_node_delete(er_json_node *obj); +er_json_type er_json_node_type(const er_json_node *obj); +const char *er_json_node_location(const er_json_node *obj); +cpl_boolean er_json_node_get_bool(const er_json_node *obj); +double er_json_node_get_number(const er_json_node *obj); +const char *er_json_node_get_string(const er_json_node *obj); +cpl_size er_json_node_array_size(const er_json_node *obj); +cpl_boolean er_json_node_array_empty(const er_json_node *obj); +er_json_array_iterator er_json_node_array_begin(const er_json_node *obj); +er_json_array_iterator er_json_node_array_end(const er_json_node *obj); +er_json_array_iterator er_json_node_array_next(const er_json_node *obj, er_json_array_iterator current); -er_json_array_iterator er_json_node_array_previous( - const er_json_node * obj, - er_json_array_iterator current); -const er_json_node * er_json_node_array_get(const er_json_node * obj, - er_json_array_iterator iterator); -cpl_size er_json_node_object_size(const er_json_node * obj); -cpl_boolean er_json_node_object_empty(const er_json_node * obj); -er_json_object_iterator er_json_node_object_begin(const er_json_node * obj); -er_json_object_iterator er_json_node_object_end(const er_json_node * obj); -er_json_object_iterator er_json_node_object_next( - const er_json_node * obj, - er_json_object_iterator current); -er_json_object_iterator er_json_node_object_previous( - const er_json_node * obj, - er_json_object_iterator current); -const char * er_json_node_object_get_key(const er_json_node * obj, - er_json_object_iterator iterator); -const er_json_node * er_json_node_object_get_value( - const er_json_node * obj, - er_json_object_iterator iterator); -const er_json_node * er_json_node_object_get(const er_json_node * obj, - const char * key); - -cpl_error_code er_json_find_line_column(const char * json, - const char * location, - int * line, int * column); +er_json_array_iterator +er_json_node_array_previous(const er_json_node *obj, + er_json_array_iterator current); +const er_json_node *er_json_node_array_get(const er_json_node *obj, + er_json_array_iterator iterator); +cpl_size er_json_node_object_size(const er_json_node *obj); +cpl_boolean er_json_node_object_empty(const er_json_node *obj); +er_json_object_iterator er_json_node_object_begin(const er_json_node *obj); +er_json_object_iterator er_json_node_object_end(const er_json_node *obj); +er_json_object_iterator +er_json_node_object_next(const er_json_node *obj, + er_json_object_iterator current); +er_json_object_iterator +er_json_node_object_previous(const er_json_node *obj, + er_json_object_iterator current); +const char *er_json_node_object_get_key(const er_json_node *obj, + er_json_object_iterator iterator); +const er_json_node * +er_json_node_object_get_value(const er_json_node *obj, + er_json_object_iterator iterator); +const er_json_node * +er_json_node_object_get(const er_json_node *obj, const char *key); + +cpl_error_code er_json_find_line_column(const char *json, + const char *location, + int *line, + int *column); /* * Utility functions for converting a parsed JSON node into actual objects. */ -er_stringarray_t * er_json_to_string_array(const er_json_node * parsetree, - const char * json); +er_stringarray_t * +er_json_to_string_array(const er_json_node *parsetree, const char *json); #ifdef ENABLE_PYTHON_RECIPES -cpl_plugin * er_json_to_plugin(const er_json_node * parsetree, - const char * json); -cpl_pluginlist * er_json_to_pluginlist(const er_json_node * parsetree, - const char * json); -void er_json_pluginlist_delete(cpl_pluginlist * list); +cpl_plugin *er_json_to_plugin(const er_json_node *parsetree, const char *json); +cpl_pluginlist * +er_json_to_pluginlist(const er_json_node *parsetree, const char *json); +void er_json_pluginlist_delete(cpl_pluginlist *list); #endif diff -Nru esorex-3.13.5+ds/src/er_macros.h esorex-3.13.6+ds/src/er_macros.h --- esorex-3.13.5+ds/src/er_macros.h 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/er_macros.h 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 European Southern Observatory * * 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 @@ -21,12 +21,14 @@ #define ER_MACROS_H #ifdef HAVE_CONFIG_H -# include +#include #endif -#define MAXSTRLENCONF 1024 +#define MAXSTRLENCONF 1024 -#define ForceNull(x) if (*x == '\0') x = NULL; +#define ForceNull(x) \ + if (*x == '\0') \ + x = NULL; #if defined HAVE_DECL___FUNC__ && HAVE_DECL___FUNC__ #define er_func __func__ @@ -39,32 +41,32 @@ * use of global configuration files. */ -#define GLOBAL_RC_EXTENSION ".rc" -#define GLOBAL_RC_BACKUP ".bak" -#define GLOBAL_RC_DIR "." PACKAGE -#define GLOBAL_RC_NAME PACKAGE GLOBAL_RC_EXTENSION +#define GLOBAL_RC_EXTENSION ".rc" +#define GLOBAL_RC_BACKUP ".bak" +#define GLOBAL_RC_DIR "." PACKAGE +#define GLOBAL_RC_NAME PACKAGE GLOBAL_RC_EXTENSION /* * Name of resource-prefix to be used in EsoRex configuration files. */ -#define PACKAGE_RESOURCE PACKAGE ".caller" +#define PACKAGE_RESOURCE PACKAGE ".caller" /* * Prefix to use for environment variables containing configuration settings - */ + */ -#define PACKAGE_ENV "ESOREX" +#define PACKAGE_ENV "ESOREX" /* * Presentation definitions */ -#define COMMENT_TAB_POSITION 24 -#define COMMAND_LINE_PREFIX "--" +#define COMMENT_TAB_POSITION 24 +#define COMMAND_LINE_PREFIX "--" /* needed because of the er_fileutils replace functions */ -#define PATHSET_MAX 1024 +#define PATHSET_MAX 1024 #endif /* ER_MACROS_H */ diff -Nru esorex-3.13.5+ds/src/er_main.cpp esorex-3.13.6+ds/src/er_main.cpp --- esorex-3.13.5+ds/src/er_main.cpp 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/er_main.cpp 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 European Southern Observatory * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif #include @@ -33,7 +33,7 @@ #include "ltdl.h" #include -#include /* should be fixed */ +#include /* should be fixed */ #include "er_macros.h" #include "er_help.h" @@ -78,454 +78,424 @@ * help */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".help", - CPL_TYPE_BOOL, - "Display this help and exit. " - "If a recipe name is also given, then " - "help will be given for it as well.", - PACKAGE_RESOURCE, FALSE); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "help"); - cpl_parameter_disable (p, CPL_PARAMETER_MODE_CFG); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_value(PACKAGE_RESOURCE ".help", CPL_TYPE_BOOL, + "Display this help and exit. " + "If a recipe name is also given, then " + "help will be given for it as well.", + PACKAGE_RESOURCE, FALSE); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "help"); + cpl_parameter_disable(p, CPL_PARAMETER_MODE_CFG); + cpl_parameterlist_append(param_list, p); /* * version */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".version", - CPL_TYPE_BOOL, - "Display version information and exit.", - PACKAGE_RESOURCE, FALSE); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "version"); - cpl_parameter_disable (p, CPL_PARAMETER_MODE_CFG); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_value(PACKAGE_RESOURCE ".version", CPL_TYPE_BOOL, + "Display version information and exit.", + PACKAGE_RESOURCE, FALSE); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "version"); + cpl_parameter_disable(p, CPL_PARAMETER_MODE_CFG); + cpl_parameterlist_append(param_list, p); /* * check-sof-exist */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".check-sof-exist", - CPL_TYPE_BOOL, - "When TRUE, all the input files must exist " - "and be readable before calling the recipe. ", - PACKAGE_RESOURCE, FALSE); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "check-sof-exist"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_CHECK_SOF_EXIST"); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_value(PACKAGE_RESOURCE ".check-sof-exist", + CPL_TYPE_BOOL, + "When TRUE, all the input files must exist " + "and be readable before calling the recipe. ", + PACKAGE_RESOURCE, FALSE); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "check-sof-exist"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, + PACKAGE_ENV "_CHECK_SOF_EXIST"); + cpl_parameterlist_append(param_list, p); /* * config */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".config", - CPL_TYPE_STRING, - "Configuration file to be used for EsoRex.", - PACKAGE_RESOURCE, NULL); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "config"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_CONFIG"); - cpl_parameter_disable (p, CPL_PARAMETER_MODE_CFG); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_value(PACKAGE_RESOURCE ".config", CPL_TYPE_STRING, + "Configuration file to be used for EsoRex.", + PACKAGE_RESOURCE, NULL); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "config"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, PACKAGE_ENV "_CONFIG"); + cpl_parameter_disable(p, CPL_PARAMETER_MODE_CFG); + cpl_parameterlist_append(param_list, p); /* * create-config */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".create-config", - /* + p = cpl_parameter_new_value( + PACKAGE_RESOURCE ".create-config", + /* CPL_TYPE_BOOL, */ - CPL_TYPE_STRING, - "Creates a configuration file for Esorex. " - "If set to TRUE a config file 'esorex.rc' is created " - "in the '.esorex' directory in $HOME of the user." - "If a filename is specified, a config file will be " - "created accordingly. " - "If a recipe is specified in the command line, then the " - "configuration file will " - "be created for the recipe instead (called " - "'recipename.rc')" - " Note that an existing file will be " - "overwritten, but a backup file will be " - "copied to 'filename.rc.bak' in " - "the same directory. If the filename ends with " - "extension .json then a machine-readable " - "JSON format will be used", - PACKAGE_RESOURCE, "FALSE"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "create-config"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_CREATE_CONFIG"); - cpl_parameter_disable (p, CPL_PARAMETER_MODE_CFG); - cpl_parameterlist_append (param_list, p); + CPL_TYPE_STRING, + "Creates a configuration file for Esorex. " + "If set to TRUE a config file 'esorex.rc' is created " + "in the '.esorex' directory in $HOME of the user." + "If a filename is specified, a config file will be " + "created accordingly. " + "If a recipe is specified in the command line, then the " + "configuration file will " + "be created for the recipe instead (called " + "'recipename.rc')" + " Note that an existing file will be " + "overwritten, but a backup file will be " + "copied to 'filename.rc.bak' in " + "the same directory. If the filename ends with " + "extension .json then a machine-readable " + "JSON format will be used", + PACKAGE_RESOURCE, "FALSE"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "create-config"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, + PACKAGE_ENV "_CREATE_CONFIG"); + cpl_parameter_disable(p, CPL_PARAMETER_MODE_CFG); + cpl_parameterlist_append(param_list, p); /* * link-dir */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".link-dir", - CPL_TYPE_STRING, - "The directory in which a symbolic link " - "to each of the product files should be " - "written. The " - "enable/disable switch to control " - "whether the link is actually made is " - "the '--suppress-link' option.", - PACKAGE_RESOURCE, "/tmp"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "link-dir"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_LINK_DIR"); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_value(PACKAGE_RESOURCE ".link-dir", CPL_TYPE_STRING, + "The directory in which a symbolic link " + "to each of the product files should be " + "written. The " + "enable/disable switch to control " + "whether the link is actually made is " + "the '--suppress-link' option.", + PACKAGE_RESOURCE, "/tmp"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "link-dir"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, PACKAGE_ENV "_LINK_DIR"); + cpl_parameterlist_append(param_list, p); /* * log-dir */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".log-dir", - CPL_TYPE_STRING, - "Directory where to place the logfile.", - PACKAGE_RESOURCE, "."); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "log-dir"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_LOG_DIR"); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_value(PACKAGE_RESOURCE ".log-dir", CPL_TYPE_STRING, + "Directory where to place the logfile.", + PACKAGE_RESOURCE, "."); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "log-dir"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, PACKAGE_ENV "_LOG_DIR"); + cpl_parameterlist_append(param_list, p); /* * log-file */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".log-file", - CPL_TYPE_STRING, - "Filename of logfile.", - PACKAGE_RESOURCE, PACKAGE ".log"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "log-file"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_LOG_FILE"); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_value(PACKAGE_RESOURCE ".log-file", CPL_TYPE_STRING, + "Filename of logfile.", PACKAGE_RESOURCE, + PACKAGE ".log"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "log-file"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, PACKAGE_ENV "_LOG_FILE"); + cpl_parameterlist_append(param_list, p); /* * log-level */ - p = cpl_parameter_new_enum (PACKAGE_RESOURCE ".log-level", - CPL_TYPE_STRING, - "Controls the severity level of messages " - "that will be printed to the logfile.", - PACKAGE_RESOURCE, - "info", 5, "debug", "info", "warning", - "error", "off"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "log-level"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_LOG_LEVEL"); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_enum(PACKAGE_RESOURCE ".log-level", CPL_TYPE_STRING, + "Controls the severity level of messages " + "that will be printed to the logfile.", + PACKAGE_RESOURCE, "info", 5, "debug", "info", + "warning", "error", "off"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "log-level"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, + PACKAGE_ENV "_LOG_LEVEL"); + cpl_parameterlist_append(param_list, p); /* * no-datamd5 and no-checksum */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".no-datamd5", - CPL_TYPE_BOOL, - "Disables the computation of the MD5 data hash " - "for FITS product files.", PACKAGE_RESOURCE, - FALSE); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "no-datamd5"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_NO_DATAMD5"); - cpl_parameterlist_append (param_list, p); - - - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".no-checksum", - CPL_TYPE_BOOL, - "Disables the computation of the standard " - "FITS product checksums.", PACKAGE_RESOURCE, - FALSE); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "no-checksum"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_NO_CHECKSUM"); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_value(PACKAGE_RESOURCE ".no-datamd5", CPL_TYPE_BOOL, + "Disables the computation of the MD5 data hash " + "for FITS product files.", + PACKAGE_RESOURCE, FALSE); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "no-datamd5"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, + PACKAGE_ENV "_NO_DATAMD5"); + cpl_parameterlist_append(param_list, p); + + + p = cpl_parameter_new_value(PACKAGE_RESOURCE ".no-checksum", CPL_TYPE_BOOL, + "Disables the computation of the standard " + "FITS product checksums.", + PACKAGE_RESOURCE, FALSE); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "no-checksum"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, + PACKAGE_ENV "_NO_CHECKSUM"); + cpl_parameterlist_append(param_list, p); /* * man-page */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".man-page", - CPL_TYPE_BOOL, - "Display a manual page for the specified " - "recipe, and then exit. Note that this option " - "only applies to recipes, and that it does " - "nothing for " PACKAGE - " by itself. See also " - "the '--help' option.", PACKAGE_RESOURCE, - FALSE); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "man-page"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_MAN_PAGE"); - cpl_parameter_disable (p, CPL_PARAMETER_MODE_CFG); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_value(PACKAGE_RESOURCE ".man-page", CPL_TYPE_BOOL, + "Display a manual page for the specified " + "recipe, and then exit. Note that this option " + "only applies to recipes, and that it does " + "nothing for " PACKAGE " by itself. See also " + "the '--help' option.", + PACKAGE_RESOURCE, FALSE); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "man-page"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, PACKAGE_ENV "_MAN_PAGE"); + cpl_parameter_disable(p, CPL_PARAMETER_MODE_CFG); + cpl_parameterlist_append(param_list, p); /* * memcheck */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".mem-check", - CPL_TYPE_BOOL, - "Report on memory status at completion " - "of recipe execution.", - PACKAGE_RESOURCE, FALSE); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "mem-check"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_MEM_CHECK"); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_value(PACKAGE_RESOURCE ".mem-check", CPL_TYPE_BOOL, + "Report on memory status at completion " + "of recipe execution.", + PACKAGE_RESOURCE, FALSE); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "mem-check"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, + PACKAGE_ENV "_MEM_CHECK"); + cpl_parameterlist_append(param_list, p); /* * msg-level */ - p = cpl_parameter_new_enum (PACKAGE_RESOURCE ".msg-level", - CPL_TYPE_STRING, - "Controls the severity level of messages " - "that will be printed to the terminal.", - PACKAGE_RESOURCE, - "info", 5, "debug", "info", "warning", - "error", "off"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "msg-level"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_MSG_LEVEL"); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_enum(PACKAGE_RESOURCE ".msg-level", CPL_TYPE_STRING, + "Controls the severity level of messages " + "that will be printed to the terminal.", + PACKAGE_RESOURCE, "info", 5, "debug", "info", + "warning", "error", "off"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "msg-level"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, + PACKAGE_ENV "_MSG_LEVEL"); + cpl_parameterlist_append(param_list, p); /* * output-dir */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".output-dir", - CPL_TYPE_STRING, - "The directory where the product " - "files should be finally moved to " - "(all products are first created in the " - "current dir).", - PACKAGE_RESOURCE, "."); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "output-dir"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_OUTPUT_DIR"); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_value(PACKAGE_RESOURCE ".output-dir", CPL_TYPE_STRING, + "The directory where the product " + "files should be finally moved to " + "(all products are first created in the " + "current dir).", + PACKAGE_RESOURCE, "."); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "output-dir"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, + PACKAGE_ENV "_OUTPUT_DIR"); + cpl_parameterlist_append(param_list, p); /* * output-prefix */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".output-prefix", - CPL_TYPE_STRING, - "Prefix applied to any output file. " - "For example, specifying 'pre' would translate " - "'filename.fits' to 'pre_0000.fits'. See also " - "the '--suppress-prefix' option.", - PACKAGE_RESOURCE, "out"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "output-prefix"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_OUTPUT_PREFIX"); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_value(PACKAGE_RESOURCE ".output-prefix", + CPL_TYPE_STRING, + "Prefix applied to any output file. " + "For example, specifying 'pre' would translate " + "'filename.fits' to 'pre_0000.fits'. See also " + "the '--suppress-prefix' option.", + PACKAGE_RESOURCE, "out"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "output-prefix"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, + PACKAGE_ENV "_OUTPUT_PREFIX"); + cpl_parameterlist_append(param_list, p); /* * output-readonly (replaces in some ways the old "output-overwrite") */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".output-readonly", - CPL_TYPE_BOOL, - "When TRUE, any existing product files " - "in the specified output directory will be " - "set to read-only, for user, group and other. " - "If FALSE, then EsoRex will use the default " - "permissions for that account/directory. " - "destroy any pre-existing files. " - "This option exists for the Paranal operations " - "environment. This option can additionally be " - "used to prevent EsoRex from overwriting " - "pre-existing files.", - PACKAGE_RESOURCE, FALSE); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "output-readonly"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_OUTPUT_READONLY"); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_value(PACKAGE_RESOURCE ".output-readonly", + CPL_TYPE_BOOL, + "When TRUE, any existing product files " + "in the specified output directory will be " + "set to read-only, for user, group and other. " + "If FALSE, then EsoRex will use the default " + "permissions for that account/directory. " + "destroy any pre-existing files. " + "This option exists for the Paranal operations " + "environment. This option can additionally be " + "used to prevent EsoRex from overwriting " + "pre-existing files.", + PACKAGE_RESOURCE, FALSE); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "output-readonly"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, + PACKAGE_ENV "_OUTPUT_READONLY"); + cpl_parameterlist_append(param_list, p); /* * paf-config */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".paf-config", - CPL_TYPE_STRING, - "Configuration file for creation of PAF files.", - PACKAGE_RESOURCE, ""); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "paf-config"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_PAF_CONFIG"); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_value(PACKAGE_RESOURCE ".paf-config", CPL_TYPE_STRING, + "Configuration file for creation of PAF files.", + PACKAGE_RESOURCE, ""); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "paf-config"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, + PACKAGE_ENV "_PAF_CONFIG"); + cpl_parameterlist_append(param_list, p); /* * params */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".params", - CPL_TYPE_BOOL, - "List the input parameters and their current " - "settings (whether from the command line or a " - "configuration file) for the " PACKAGE - " application. Parameters are " - "labelled using the parameter's alias. " - "If a recipe is also specified, then the " - "list of its parameters will also be generated " - "in the same way.", - PACKAGE_RESOURCE, FALSE); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "params"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_PARAMS"); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_value(PACKAGE_RESOURCE ".params", CPL_TYPE_BOOL, + "List the input parameters and their current " + "settings (whether from the command line or a " + "configuration file) for the " PACKAGE + " application. Parameters are " + "labelled using the parameter's alias. " + "If a recipe is also specified, then the " + "list of its parameters will also be generated " + "in the same way.", + PACKAGE_RESOURCE, FALSE); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "params"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, PACKAGE_ENV "_PARAMS"); + cpl_parameterlist_append(param_list, p); /* * products-sof */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".products-sof", - CPL_TYPE_STRING, - "Output file which contains the FITS files " - "created by the recipe. If the filename ends with " - "extension .json then a machine-readable JSON format" - "will be used", - PACKAGE_RESOURCE, ""); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "products-sof"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_PRODUCTS_SOF"); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_value( + PACKAGE_RESOURCE ".products-sof", CPL_TYPE_STRING, + "Output file which contains the FITS files " + "created by the recipe. If the filename ends with " + "extension .json then a machine-readable JSON format" + "will be used", + PACKAGE_RESOURCE, ""); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "products-sof"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, + PACKAGE_ENV "_PRODUCTS_SOF"); + cpl_parameterlist_append(param_list, p); /* * recipes */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".recipes", - CPL_TYPE_BOOL, - "Display a list of all available recipes " - "(that are available in the directory tree " - "specified with '--recipe-dir').", - PACKAGE_RESOURCE, FALSE); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "recipes"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_RECIPES"); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_value(PACKAGE_RESOURCE ".recipes", CPL_TYPE_BOOL, + "Display a list of all available recipes " + "(that are available in the directory tree " + "specified with '--recipe-dir').", + PACKAGE_RESOURCE, FALSE); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "recipes"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, PACKAGE_ENV "_RECIPES"); + cpl_parameterlist_append(param_list, p); /* * recipe-config */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".recipe-config", - CPL_TYPE_STRING, - "Configuration file for any selected recipe.", - PACKAGE_RESOURCE, NULL); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "recipe-config"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_RECIPE_CONFIG"); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_value(PACKAGE_RESOURCE ".recipe-config", + CPL_TYPE_STRING, + "Configuration file for any selected recipe.", + PACKAGE_RESOURCE, NULL); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "recipe-config"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, + PACKAGE_ENV "_RECIPE_CONFIG"); + cpl_parameterlist_append(param_list, p); /* * recipe-dir */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".recipe-dir", - CPL_TYPE_STRING, - "Directory containing recipe libraries. Note " - "that " PACKAGE - " will recursively search not " - "only the specified directory, but all " - "sub-directories below it as well. " - "Multiple directory heads may be " - "specified, by separating the " - "starting paths with colons (:).", - PACKAGE_RESOURCE, "."); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "recipe-dir"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_PLUGIN_DIR"); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_value(PACKAGE_RESOURCE ".recipe-dir", CPL_TYPE_STRING, + "Directory containing recipe libraries. Note " + "that " PACKAGE " will recursively search not " + "only the specified directory, but all " + "sub-directories below it as well. " + "Multiple directory heads may be " + "specified, by separating the " + "starting paths with colons (:).", + PACKAGE_RESOURCE, "."); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "recipe-dir"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, + PACKAGE_ENV "_PLUGIN_DIR"); + cpl_parameterlist_append(param_list, p); /* * show hidden */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".show-hidden", - CPL_TYPE_BOOL, - "When TRUE recipe parameters which are " - "declared as hidden by the recipe are shown " - "in the output of help and man page options.", - PACKAGE_RESOURCE, FALSE); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "show-hidden"); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_value(PACKAGE_RESOURCE ".show-hidden", CPL_TYPE_BOOL, + "When TRUE recipe parameters which are " + "declared as hidden by the recipe are shown " + "in the output of help and man page options.", + PACKAGE_RESOURCE, FALSE); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "show-hidden"); + cpl_parameterlist_append(param_list, p); /* * suppress_link */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".suppress-link", - CPL_TYPE_BOOL, - "When TRUE, no symbolic link is created " - "to the output product. However, " - "if FALSE, then a symbolic link is created " - "in the directory specified with the " - "option '--link-dir' for each product " - "that is created by the recipe.", - PACKAGE_RESOURCE, TRUE); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "suppress-link"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_SUPPRESS_LINK"); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_value(PACKAGE_RESOURCE ".suppress-link", + CPL_TYPE_BOOL, + "When TRUE, no symbolic link is created " + "to the output product. However, " + "if FALSE, then a symbolic link is created " + "in the directory specified with the " + "option '--link-dir' for each product " + "that is created by the recipe.", + PACKAGE_RESOURCE, TRUE); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "suppress-link"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, + PACKAGE_ENV "_SUPPRESS_LINK"); + cpl_parameterlist_append(param_list, p); /* * suppress_prefix */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".suppress-prefix", - CPL_TYPE_BOOL, - "When TRUE, the original name of the " - "output product, as produced by the " - "recipe, is maintained. " - "If FALSE, then the name of the output " - "file is changed to the \"prefix_number\" " - "format. The prefix can be altered using the " - "'--output-prefix' option.", - PACKAGE_RESOURCE, FALSE); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "suppress-prefix"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_SUPPRESS_PREFIX"); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_value(PACKAGE_RESOURCE ".suppress-prefix", + CPL_TYPE_BOOL, + "When TRUE, the original name of the " + "output product, as produced by the " + "recipe, is maintained. " + "If FALSE, then the name of the output " + "file is changed to the \"prefix_number\" " + "format. The prefix can be altered using the " + "'--output-prefix' option.", + PACKAGE_RESOURCE, FALSE); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "suppress-prefix"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, + PACKAGE_ENV "_SUPPRESS_PREFIX"); + cpl_parameterlist_append(param_list, p); /* * time */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".time", - CPL_TYPE_BOOL, - "Measure and show the recipe's execution time.", - PACKAGE_RESOURCE, FALSE); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "time"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_TIME"); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_value(PACKAGE_RESOURCE ".time", CPL_TYPE_BOOL, + "Measure and show the recipe's execution time.", + PACKAGE_RESOURCE, FALSE); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "time"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, PACKAGE_ENV "_TIME"); + cpl_parameterlist_append(param_list, p); /* * unload-plugin */ - p = cpl_parameter_new_value (PACKAGE_RESOURCE ".unload-plugin", - CPL_TYPE_BOOL, - "When TRUE, the plugin is unloaded " - "after execution. " - "If FALSE, the plugin is not unloaded " - "after processing, so that a software " - "like, e.g. valgrind, can be used " - "for debugging the executed recipe. ", - PACKAGE_RESOURCE, TRUE); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "unload-plugin"); - cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_ENV, - PACKAGE_ENV "_UNLOAD_PLUGIN"); - cpl_parameterlist_append (param_list, p); + p = cpl_parameter_new_value(PACKAGE_RESOURCE ".unload-plugin", + CPL_TYPE_BOOL, + "When TRUE, the plugin is unloaded " + "after execution. " + "If FALSE, the plugin is not unloaded " + "after processing, so that a software " + "like, e.g. valgrind, can be used " + "for debugging the executed recipe. ", + PACKAGE_RESOURCE, TRUE); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "unload-plugin"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_ENV, + PACKAGE_ENV "_UNLOAD_PLUGIN"); + cpl_parameterlist_append(param_list, p); /* @@ -534,19 +504,18 @@ * all parameters in this list are the EsoRex defaults. */ - p = cpl_parameterlist_get_first (param_list); - while (p != NULL) - { + p = cpl_parameterlist_get_first(param_list); + while (p != NULL) { char *cptr, def_str[] = PACKAGE " default"; - cptr = def_str; /* save source of this param */ - er_manage_sources(1,cpl_parameter_get_name(p),&cptr); + cptr = def_str; /* save source of this param */ + er_manage_sources(1, cpl_parameter_get_name(p), &cptr); /* Get the next parameter in the list */ - p = cpl_parameterlist_get_next (param_list); - } /* End of loop through all parameters in the list */ + p = cpl_parameterlist_get_next(param_list); + } /* End of loop through all parameters in the list */ -} /* End of er_init_parameters() */ +} /* End of er_init_parameters() */ /** @@ -557,8 +526,8 @@ static void er_print_header(void) { - fprintf(stdout, "\n ***** %s, version %s *****\n\n", - PACKAGE_NAME, PACKAGE_VERSION); + fprintf(stdout, "\n ***** %s, version %s *****\n\n", PACKAGE_NAME, + PACKAGE_VERSION); fflush(stdout); return; @@ -568,13 +537,11 @@ inline static int _esorex_config_value_get(FILE *fp, const char *key, char *value, size_t sz) { - int has_key = 0; char buffer[MAXSTRLENCONF]; while (fgets(buffer, MAXSTRLENCONF, fp) != NULL) { - char *s = buffer; while (isspace(*s)) { @@ -582,12 +549,10 @@ } if ((s[0] != '\0') && (s[0] != '#') && - (strncmp(s, key, strlen(key)) == 0)) { - + (strncmp(s, key, strlen(key)) == 0)) { s = strchr(s, '='); if (s != NULL) { - char v[MAXSTRLENCONF]; int nitems = sscanf(s + 1, "%s", v); @@ -601,15 +566,12 @@ has_key = -1; break; } - } else { has_key = -1; break; } - } - } return has_key; @@ -617,18 +579,16 @@ inline static void -_esorex_config_files_set(int argc, char *argv[], - char **syscfg, char **cfg) +_esorex_config_files_set(int argc, char *argv[], char **syscfg, char **cfg) { - const char *env_config = getenv("ESOREX_CONFIG"); int iarg; - const char *_home = getenv("HOME"); + const char *_home = getenv("HOME"); const char *_cfg = NULL; - char *_path = NULL; + char *_path = NULL; struct stat sb; @@ -638,21 +598,19 @@ * separator, and another one for the string terminator. */ - size_t sz = strlen(GLOBAL_RC_NAME) + 2; + size_t sz = strlen(GLOBAL_RC_NAME) + 2; size_t _sz = 0; if (_home == NULL) { - struct passwd *pw = getpwuid(getuid()); _home = pw->pw_dir; - } _sz = strlen(_home) + strlen(GLOBAL_RC_DIR) + 1; sz += (_sz > strlen(SYSCONFDIR)) ? _sz : strlen(SYSCONFDIR); - _path = static_cast(malloc(sz)); + _path = static_cast(malloc(sz)); /* @@ -693,18 +651,14 @@ } for (iarg = 1; iarg < argc; ++iarg) { - if ((strlen(argv[iarg]) > 2) && - (strncmp(argv[iarg] + 2, "config", 6) == 0)) { - + (strncmp(argv[iarg] + 2, "config", 6) == 0)) { const char *s = strchr(argv[iarg] + 2, '='); if ((s != NULL) && (*(s + 1) != '\0')) { _cfg = ++s; } - } - } if (_cfg != NULL) { @@ -712,7 +666,6 @@ } return; - } @@ -726,8 +679,10 @@ // are started. inline static int -_esorex_memory_mode_get(int argc, char *argv[], - const char *syscfg, const char *cfg) +_esorex_memory_mode_get(int argc, + char *argv[], + const char *syscfg, + const char *cfg) { int iarg; int set_memory_mode = 0; @@ -736,7 +691,6 @@ if ((syscfg != NULL) && (syscfg[0] != '\0')) { - const char *key = PACKAGE_RESOURCE ".mem-check"; char value[MAXSTRLENCONF]; @@ -744,23 +698,18 @@ FILE *fp = fopen(syscfg, "r"); if (fp != NULL) { - if (_esorex_config_value_get(fp, key, value, MAXSTRLENCONF) == 1) { - if ((strncmp(value, "TRUE", 4) == 0) || - strncmp(value, "true", 4) == 0) { + strncmp(value, "true", 4) == 0) { set_memory_mode = 1; } } fclose(fp); - } - } if ((cfg != NULL) && (cfg[0] != '\0')) { - const char *key = PACKAGE_RESOURCE ".mem-check"; char value[MAXSTRLENCONF]; @@ -768,60 +717,52 @@ FILE *fp = fopen(cfg, "r"); if (fp != NULL) { - if (_esorex_config_value_get(fp, key, value, MAXSTRLENCONF) == 1) { - if ((strncmp(value, "TRUE", 4) == 0) || - strncmp(value, "true", 4) == 0) { + strncmp(value, "true", 4) == 0) { set_memory_mode = 1; } } fclose(fp); } - } - if ((env_memcheck != NULL) && - ((strncmp(env_memcheck, "TRUE", 4) == 0) || - (strncmp(env_memcheck, "true", 4) == 0))) { + if ((env_memcheck != NULL) && ((strncmp(env_memcheck, "TRUE", 4) == 0) || + (strncmp(env_memcheck, "true", 4) == 0))) { set_memory_mode = 1; } for (iarg = 1; iarg < argc; ++iarg) { - if ((strlen(argv[iarg]) > 2) && - (strncmp(argv[iarg] + 2, "mem-check", 9) == 0)) { - + (strncmp(argv[iarg] + 2, "mem-check", 9) == 0)) { if (strstr(argv[iarg], "TRUE") || strstr(argv[iarg], "true")) { - const char *memory_mode = getenv("CPL_MEMORY_MODE"); - if ((memory_mode == NULL) || (strncmp(memory_mode, "0", 1) == 0)) { + if ((memory_mode == NULL) || + (strncmp(memory_mode, "0", 1) == 0)) { set_memory_mode = 1; } - } - else if (strstr(argv[iarg], "FALSE") || strstr(argv[iarg], "false")) { + else if (strstr(argv[iarg], "FALSE") || + strstr(argv[iarg], "false")) { set_memory_mode = 0; } - } - } return set_memory_mode; - } -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { const char *fn = "EsoRex"; - char plugin_name[FILEMAX+2]; - char *conf_file_global=NULL, *conf_file_local=NULL; + char plugin_name[FILEMAX + 2]; + char *conf_file_global = NULL, *conf_file_local = NULL; const char *cdescr; @@ -835,48 +776,47 @@ int e_code2 = 0; int flag_mem_check = 1; - unsigned init_flag = CPL_INIT_DEFAULT; + unsigned init_flag = CPL_INIT_DEFAULT; /* check that we're not somebody else... */ - if (getuid() != geteuid()) - { - fprintf(stderr, "effective user ID not the same as real user ID => no EsoRex...\n"); + if (getuid() != geteuid()) { + fprintf( + stderr, + "effective user ID not the same as real user ID => no EsoRex...\n"); exit(EXIT_FAILURE); } /* print version of Esorex */ - er_print_header (); + er_print_header(); _esorex_config_files_set(argc, argv, &conf_file_global, &conf_file_local); - if (_esorex_memory_mode_get(argc, argv, - conf_file_global, conf_file_local) != 0) { + if (_esorex_memory_mode_get(argc, argv, conf_file_global, + conf_file_local) != 0) { setenv("CPL_MEMORY_MODE", "1", 0); } /* Initialization and setup */ - cpl_init (init_flag); /* also does cpl_msg_init() stuff */ - - cpl_msg_set_domain (PACKAGE); - cpl_msg_set_time_off (); - cpl_msg_set_threadid_off (); - cpl_msg_set_domain_on (); - cpl_msg_set_component_off (); + cpl_init(init_flag); /* also does cpl_msg_init() stuff */ + cpl_msg_set_domain(PACKAGE); + cpl_msg_set_time_off(); + cpl_msg_set_threadid_off(); + cpl_msg_set_domain_on(); + cpl_msg_set_component_off(); /* Main processing */ - if (lt_dlinit () != 0) - { - cpl_msg_error (fn, "Unable to initialise ltdl; aborting program"); - cpl_end (); /* stop subsystems of CPL */ + if (lt_dlinit() != 0) { + cpl_msg_error(fn, "Unable to initialise ltdl; aborting program"); + cpl_end(); /* stop subsystems of CPL */ e_code = -1; goto clean_up; } @@ -884,35 +824,34 @@ /* Create list of parameters for EsoRex */ - caller_parameter_list = cpl_parameterlist_new (); - set_of_frames_filenames = er_stringarray_new (); + caller_parameter_list = cpl_parameterlist_new(); + set_of_frames_filenames = er_stringarray_new(); - er_init_parameters (caller_parameter_list); + er_init_parameters(caller_parameter_list); /* Process caller configuration information */ plugin_name[0] = '\0'; - e_code = params_process_configuration (caller_parameter_list, - conf_file_global, conf_file_local, - argc, argv, - plugin_name, set_of_frames_filenames); + e_code = + params_process_configuration(caller_parameter_list, conf_file_global, + conf_file_local, argc, argv, plugin_name, + set_of_frames_filenames); /* Process Plugin */ - if (e_code == 0 && plugin_name[0] != '\0') - { + if (e_code == 0 && plugin_name[0] != '\0') { // FIXME: Error handling is non-local here and hard to trace. // This has to be improved! - e_code = plugin_process_plugin (caller_parameter_list, - plugin_name, set_of_frames_filenames, - argc, argv); + e_code = plugin_process_plugin(caller_parameter_list, plugin_name, + set_of_frames_filenames, argc, argv); } - else if(e_code !=-99999) /* entering just Esorex yields the library versions */ + else if (e_code != + -99999) /* entering just Esorex yields the library versions */ { cdescr = cpl_get_description(CPL_DESCRIPTION_DEFAULT); - (void) printf("\nLibraries used: %s\n\n",cdescr); + (void)printf("\nLibraries used: %s\n\n", cdescr); // Shutdown ltdl as this is not done by cleanup lt_dlexit(); @@ -921,77 +860,73 @@ } msg_level = cpl_msg_get_level(); /* test, if we are in debug mode */ - if (msg_level == CPL_MSG_DEBUG) - { /* if debug level set, */ - e_code2 = cpl_error_get_code (); /* check the CPL_error subsystem */ - if (e_code2 != CPL_ERROR_NONE) - { - cpl_msg_error (fn, "CPL-error '%s' was set in '%s'", - cpl_error_get_message (), cpl_error_get_where ()); - if (e_code == 0) - { - cpl_msg_error (fn, "recipe %s returned status: %d\n",plugin_name,e_code); + if (msg_level == CPL_MSG_DEBUG) { /* if debug level set, */ + e_code2 = cpl_error_get_code(); /* check the CPL_error subsystem */ + if (e_code2 != CPL_ERROR_NONE) { + cpl_msg_error(fn, "CPL-error '%s' was set in '%s'", + cpl_error_get_message(), cpl_error_get_where()); + if (e_code == 0) { + cpl_msg_error(fn, "recipe %s returned status: %d\n", + plugin_name, e_code); } } } - p = cpl_parameterlist_find (caller_parameter_list, - PACKAGE_RESOURCE ".unload-plugin"); + p = cpl_parameterlist_find(caller_parameter_list, + PACKAGE_RESOURCE ".unload-plugin"); if (cpl_parameter_get_bool(p) != 0) { - if (lt_dlexit () != 0) { - cpl_msg_error (fn, "Unable to deinitialize ltdl"); + if (lt_dlexit() != 0) { + cpl_msg_error(fn, "Unable to deinitialize ltdl"); } } else { cpl_msg_warning(fn, "unloading of plugins is inhibited by program " - "option 'unload-plugin'!"); + "option 'unload-plugin'!"); } - p = cpl_parameterlist_find (caller_parameter_list, PACKAGE_RESOURCE ".mem-check"); - flag_mem_check = cpl_parameter_get_bool (p); + p = cpl_parameterlist_find(caller_parameter_list, + PACKAGE_RESOURCE ".mem-check"); + flag_mem_check = cpl_parameter_get_bool(p); /* cleanup allocated structures and memory */ - clean_up: +clean_up: if (caller_parameter_list) { - cpl_parameterlist_delete (caller_parameter_list); + cpl_parameterlist_delete(caller_parameter_list); } if (set_of_frames_filenames) { - er_stringarray_delete (set_of_frames_filenames); + er_stringarray_delete(set_of_frames_filenames); } - if (conf_file_local != NULL) - { + if (conf_file_local != NULL) { free(conf_file_local); } - if (conf_file_global != NULL) - { + if (conf_file_global != NULL) { free(conf_file_global); } - (void) er_help_free(); - (void) er_manage_sources(3, "", NULL); /* free buffer of sources */ + (void)er_help_free(); + (void)er_manage_sources(3, "", NULL); /* free buffer of sources */ #ifdef ENABLE_PYTHON_RECIPES /* Free any buffers allocated by er_python_* functions. */ er_python_cleanup(); #endif - if (flag_mem_check != 0) /* see if we should check the memory */ + if (flag_mem_check != 0) /* see if we should check the memory */ { cpl_memory_dump(); } - cpl_end (); /* stop subsystems of CPL */ + cpl_end(); /* stop subsystems of CPL */ // Reset error code -99999 used for non-executing options // like --version - if (e_code == -99999) - { + if (e_code == -99999) { e_code = 0; } diff -Nru esorex-3.13.5+ds/src/er_paf.c esorex-3.13.6+ds/src/er_paf.c --- esorex-3.13.5+ds/src/er_paf.c 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/er_paf.c 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 European Southern Observatory * * 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 @@ -34,9 +34,10 @@ #include "er_fileutils.h" #include "er_paf.h" -#define ER_PAF_MANDATORY_KEYS_MAIN_EXT "PRO CATG|INSTRUME|MJD-OBS|ESO TPL ID|DATE-OBS|ESO OBS ID" -#define ER_PAF_MANDATORY_KEYS_EXT "EXTNAME" -#define ER_PAF_QC_KEYS "ESO QC" +#define ER_PAF_MANDATORY_KEYS_MAIN_EXT \ + "PRO CATG|INSTRUME|MJD-OBS|ESO TPL ID|DATE-OBS|ESO OBS ID" +#define ER_PAF_MANDATORY_KEYS_EXT "EXTNAME" +#define ER_PAF_QC_KEYS "ESO QC" /** * @defgroup er_paf PAF files handling @@ -65,50 +66,47 @@ */ /**********************************************************************/ -int er_create_recipe_pafs -(const cpl_frameset * frames, - const char * recipe_name, - const char * paf_config_filename) -{ - const cpl_frame * frame = NULL; - struct er_paf_config * paf_configuration = NULL; - int paf_err = CPL_ERROR_NONE; - char * arcfile = NULL; - int idx_paf = 0; +int +er_create_recipe_pafs(const cpl_frameset *frames, + const char *recipe_name, + const char *paf_config_filename) +{ + const cpl_frame *frame = NULL; + struct er_paf_config *paf_configuration = NULL; + int paf_err = CPL_ERROR_NONE; + char *arcfile = NULL; + int idx_paf = 0; cpl_msg_info(er_func, "Creating PAF files"); /* Read the configuration file */ paf_configuration = er_paf_read_config_file(paf_config_filename); - if(paf_configuration == NULL) - { + if (paf_configuration == NULL) { cpl_msg_error(er_func, "Could not parse the PAF configuration file"); return CPL_ERROR_BAD_FILE_FORMAT; } /* Loop into all the products */ - cpl_msg_debug(__func__,"Looping into all the products"); + cpl_msg_debug(__func__, "Looping into all the products"); cpl_frameset_iterator *it = cpl_frameset_iterator_new(frames); - while ((frame = cpl_frameset_iterator_get_const(it)) != NULL) - { - const char * filename; + while ((frame = cpl_frameset_iterator_get_const(it)) != NULL) { + const char *filename; filename = cpl_frame_get_filename(frame); if (cpl_frame_get_group(frame) == CPL_FRAME_GROUP_PRODUCT && - er_fileutils_file_is_fits(filename)) - { - struct er_paf_config_item * config_item = NULL; - const char * this_pro_catg = NULL; - cpl_propertylist * procatg_proplist = NULL; + er_fileutils_file_is_fits(filename)) { + struct er_paf_config_item *config_item = NULL; + const char *this_pro_catg = NULL; + cpl_propertylist *procatg_proplist = NULL; /* Get PRO CATG of this product */ procatg_proplist = cpl_propertylist_load(filename, 0); - this_pro_catg = cpl_propertylist_get_string(procatg_proplist, CPL_DFS_PRO_CATG); + this_pro_catg = + cpl_propertylist_get_string(procatg_proplist, CPL_DFS_PRO_CATG); - if(this_pro_catg == NULL) - { - cpl_msg_error(er_func,"Could not get PRO CATG in file %s", + if (this_pro_catg == NULL) { + cpl_msg_error(er_func, "Could not get PRO CATG in file %s", filename); cpl_frameset_iterator_delete(it); er_paf_config_delete(paf_configuration); @@ -122,10 +120,9 @@ cpl_msg_indent_more(); /* Get the corresponding matching in the config file (if there is) */ - config_item = er_paf_get_matching_item - (paf_configuration, this_pro_catg); - if(config_item != NULL) - { + config_item = + er_paf_get_matching_item(paf_configuration, this_pro_catg); + if (config_item != NULL) { int next; cpl_msg_debug(er_func, "Matched with regexp =%s", @@ -137,14 +134,13 @@ * set. */ - arcfile = cpl_strdup(cpl_propertylist_get_string(procatg_proplist, - "ESO PRO ANCESTOR")); + arcfile = + cpl_strdup(cpl_propertylist_get_string(procatg_proplist, + "ESO PRO ANCESTOR")); - if(arcfile == NULL) - { + if (arcfile == NULL) { arcfile = er_paf_get_arcfile(frames); - if(arcfile == NULL) - { + if (arcfile == NULL) { cpl_msg_error(er_func, "Could not read ARCFILE information from " "raw frames"); @@ -156,18 +152,17 @@ /* Decide what to do depending on number of extensions */ next = cpl_frame_get_nextensions(frame); - if(next == 0) - { - paf_err = er_paf_single_hdu_fill_write - (frame, config_item, idx_paf, recipe_name, arcfile); + if (next == 0) { + paf_err = er_paf_single_hdu_fill_write(frame, config_item, + idx_paf, recipe_name, + arcfile); } - else if(next != 0) - { - paf_err = er_paf_multi_hdu_fill_write - (frame, config_item, idx_paf, recipe_name, arcfile); + else if (next != 0) { + paf_err = + er_paf_multi_hdu_fill_write(frame, config_item, idx_paf, + recipe_name, arcfile); } - if(paf_err != CPL_ERROR_NONE) - { + if (paf_err != CPL_ERROR_NONE) { cpl_propertylist_delete(procatg_proplist); cpl_frameset_iterator_delete(it); er_paf_config_delete(paf_configuration); @@ -179,19 +174,17 @@ cpl_propertylist_delete(procatg_proplist); } else { - cpl_msg_debug(__func__,"File is not a FITS product %s", - filename); + cpl_msg_debug(__func__, "File is not a FITS product %s", filename); } cpl_frameset_iterator_advance(it, 1); - } cpl_frameset_iterator_delete(it); /* Cleanup */ er_paf_config_delete(paf_configuration); - if(arcfile != NULL) + if (arcfile != NULL) cpl_free(arcfile); return paf_err; @@ -213,35 +206,33 @@ */ /**********************************************************************/ -int er_paf_single_hdu_fill_write -(const cpl_frame * frame, - struct er_paf_config_item * config_item, - int idx_paf, - const char * recipe_name, - char * arcfile) +int +er_paf_single_hdu_fill_write(const cpl_frame *frame, + struct er_paf_config_item *config_item, + int idx_paf, + const char *recipe_name, + char *arcfile) { - cpl_propertylist * paf_proplist = NULL; - char * paf_filename; + cpl_propertylist *paf_proplist = NULL; + char *paf_filename; /* Get the keywords to write */ - paf_proplist = - er_paf_fill_paf_proplist_single_hdu(frame, config_item, arcfile); - if(paf_proplist == NULL) - { - cpl_msg_debug(__func__,"No keywords found for file %s. " - "Skipping writing of paf", cpl_frame_get_filename(frame)); + paf_proplist = + er_paf_fill_paf_proplist_single_hdu(frame, config_item, arcfile); + if (paf_proplist == NULL) { + cpl_msg_debug(__func__, + "No keywords found for file %s. " + "Skipping writing of paf", + cpl_frame_get_filename(frame)); return CPL_ERROR_NONE; } /* Get the PAF filename */ - paf_filename = cpl_sprintf("qc_%04d.paf",idx_paf); + paf_filename = cpl_sprintf("qc_%04d.paf", idx_paf); /* Writing PAF file */ - cpl_dfs_save_paf(cpl_propertylist_get_string - (paf_proplist,"INSTRUME"), - recipe_name, - paf_proplist, - paf_filename); + cpl_dfs_save_paf(cpl_propertylist_get_string(paf_proplist, "INSTRUME"), + recipe_name, paf_proplist, paf_filename); /* Cleaning */ cpl_free(paf_filename); @@ -266,34 +257,33 @@ */ /**********************************************************************/ -int er_paf_multi_hdu_fill_write -(const cpl_frame * frame, - struct er_paf_config_item * config_item, - int idx_paf, - const char * recipe_name, - char * arcfile) +int +er_paf_multi_hdu_fill_write(const cpl_frame *frame, + struct er_paf_config_item *config_item, + int idx_paf, + const char *recipe_name, + char *arcfile) { - int iext; - int next; + int iext; + int next; next = cpl_frame_get_nextensions(frame); - for(iext = 0 ; iext <= next ; ++iext) - { - cpl_propertylist * paf_proplist; - char * paf_filename; + for (iext = 0; iext <= next; ++iext) { + cpl_propertylist *paf_proplist; + char *paf_filename; /* Get the keywords to write */ - paf_proplist = - er_paf_fill_paf_proplist_multi_hdu(frame,config_item, iext, arcfile); - if(paf_proplist == NULL) - { - cpl_msg_warning(__func__,"Problem reading headers in file %s, extension %d", + paf_proplist = er_paf_fill_paf_proplist_multi_hdu(frame, config_item, + iext, arcfile); + if (paf_proplist == NULL) { + cpl_msg_warning(__func__, + "Problem reading headers in file %s, extension %d", cpl_frame_get_filename(frame), iext); return CPL_ERROR_ILLEGAL_INPUT; } - if(cpl_propertylist_get_size(paf_proplist) == 0) - { - cpl_msg_debug(__func__,"Skipping writing of paf for file %s, " + if (cpl_propertylist_get_size(paf_proplist) == 0) { + cpl_msg_debug(__func__, + "Skipping writing of paf for file %s, " "extension %d (starting in 0).", cpl_frame_get_filename(frame), iext); cpl_propertylist_delete(paf_proplist); @@ -301,14 +291,11 @@ } /* Get the PAF filename */ - paf_filename = cpl_sprintf("qc_%04d_%04d.paf",idx_paf, iext); + paf_filename = cpl_sprintf("qc_%04d_%04d.paf", idx_paf, iext); /* Writing PAF file */ - cpl_dfs_save_paf(cpl_propertylist_get_string - (paf_proplist,"INSTRUME"), - recipe_name, - paf_proplist, - paf_filename); + cpl_dfs_save_paf(cpl_propertylist_get_string(paf_proplist, "INSTRUME"), + recipe_name, paf_proplist, paf_filename); /* Cleaning */ cpl_free(paf_filename); cpl_propertylist_delete(paf_proplist); @@ -331,48 +318,45 @@ * return the first match */ /**********************************************************************/ -struct er_paf_config_item * er_paf_get_matching_item -(struct er_paf_config * paf_configuration, const char * this_pro_catg) +struct er_paf_config_item * +er_paf_get_matching_item(struct er_paf_config *paf_configuration, + const char *this_pro_catg) { - struct er_paf_config_item * config_item = NULL; - unsigned int item; + struct er_paf_config_item *config_item = NULL; + unsigned int item; - cpl_msg_indent_more(); - /* Loop through the config pro catg regular expressions */ - for(item = 0; item < paf_configuration->nitems; ++item) - { - regex_t pattern; - int regstatus; - - cpl_msg_debug(er_func, "Comparing PRO CATG with %s", - paf_configuration->items[item].pro_catg_regexp); - - regstatus = regcomp(&pattern, - paf_configuration->items[item].pro_catg_regexp, - REG_EXTENDED|REG_NOSUB); - if(regstatus) - { - cpl_msg_error(er_func, "Bad formatted PRO CATG regular expression"); - cpl_error_set(er_func, CPL_ERROR_ILLEGAL_INPUT); - cpl_msg_indent_less(); - regfree(&pattern); - return NULL; - } - regstatus = - regexec(&pattern, this_pro_catg, (size_t)0, NULL, 0); - if (regstatus != REG_NOMATCH) - { - config_item = paf_configuration->items+item; - cpl_msg_indent_less(); - regfree(&pattern); - return config_item; - } + cpl_msg_indent_more(); + /* Loop through the config pro catg regular expressions */ + for (item = 0; item < paf_configuration->nitems; ++item) { + regex_t pattern; + int regstatus; + + cpl_msg_debug(er_func, "Comparing PRO CATG with %s", + paf_configuration->items[item].pro_catg_regexp); + + regstatus = + regcomp(&pattern, paf_configuration->items[item].pro_catg_regexp, + REG_EXTENDED | REG_NOSUB); + if (regstatus) { + cpl_msg_error(er_func, "Bad formatted PRO CATG regular expression"); + cpl_error_set(er_func, CPL_ERROR_ILLEGAL_INPUT); + cpl_msg_indent_less(); regfree(&pattern); + return NULL; } - cpl_msg_indent_less(); + regstatus = regexec(&pattern, this_pro_catg, (size_t)0, NULL, 0); + if (regstatus != REG_NOMATCH) { + config_item = paf_configuration->items + item; + cpl_msg_indent_less(); + regfree(&pattern); + return config_item; + } + regfree(&pattern); + } + cpl_msg_indent_less(); - /* Return */ - return config_item; + /* Return */ + return config_item; } @@ -390,45 +374,45 @@ */ /**********************************************************************/ -struct er_paf_config * er_paf_read_config_file -(const char * paf_config_filename) +struct er_paf_config * +er_paf_read_config_file(const char *paf_config_filename) { - struct er_paf_config * paf_configuration; - er_stringarray_t * file_buffer; - er_stringarray_t * file_stripped; - int iline; - - cpl_msg_debug(__func__,"Reading configuration file %s",paf_config_filename); - - /* Allocate and init the structure */ - paf_configuration = cpl_malloc(sizeof(struct er_paf_config)); - paf_configuration->items = NULL; - paf_configuration->nitems = 0; - - /* Read the whole file */ - file_buffer = er_paf_read_whole_file(paf_config_filename); - if(file_buffer == NULL) - return NULL; - - /* Strip the comments and blank lines */ - cpl_msg_debug(__func__,"Stripping comments and blank lines"); - file_stripped = er_stringarray_new(); - for (iline = 0; iline < er_stringarray_size(file_buffer); ++iline) - { - char * line; - line = er_stringarray_get(file_buffer, iline); - cx_strstrip(line); - if (strcmp(line, "") != 0 && line[0] != '#' ) - er_stringarray_append(file_stripped, line); - } - - /* Parse the configuration lines and store it in a convenient structure */ - er_paf_parse_config(file_stripped, paf_configuration); + struct er_paf_config *paf_configuration; + er_stringarray_t *file_buffer; + er_stringarray_t *file_stripped; + int iline; + + cpl_msg_debug(__func__, "Reading configuration file %s", + paf_config_filename); + + /* Allocate and init the structure */ + paf_configuration = cpl_malloc(sizeof(struct er_paf_config)); + paf_configuration->items = NULL; + paf_configuration->nitems = 0; + + /* Read the whole file */ + file_buffer = er_paf_read_whole_file(paf_config_filename); + if (file_buffer == NULL) + return NULL; - /* clean and return */ - er_stringarray_delete(file_buffer); - er_stringarray_delete(file_stripped); - return paf_configuration; + /* Strip the comments and blank lines */ + cpl_msg_debug(__func__, "Stripping comments and blank lines"); + file_stripped = er_stringarray_new(); + for (iline = 0; iline < er_stringarray_size(file_buffer); ++iline) { + char *line; + line = er_stringarray_get(file_buffer, iline); + cx_strstrip(line); + if (strcmp(line, "") != 0 && line[0] != '#') + er_stringarray_append(file_stripped, line); + } + + /* Parse the configuration lines and store it in a convenient structure */ + er_paf_parse_config(file_stripped, paf_configuration); + + /* clean and return */ + er_stringarray_delete(file_buffer); + er_stringarray_delete(file_stripped); + return paf_configuration; } /**********************************************************************/ @@ -451,54 +435,53 @@ */ /**********************************************************************/ -cpl_propertylist* er_paf_fill_paf_proplist_single_hdu -(const cpl_frame * frame, - struct er_paf_config_item * config_item, - char * arcfile) -{ - cpl_propertylist * paf_proplist; - cpl_propertylist * all_keywords; - const char * filename; - int ikey; - int nkeys; +cpl_propertylist * +er_paf_fill_paf_proplist_single_hdu(const cpl_frame *frame, + struct er_paf_config_item *config_item, + char *arcfile) +{ + cpl_propertylist *paf_proplist; + cpl_propertylist *all_keywords; + const char *filename; + int ikey; + int nkeys; /* Get All keywords from FITS header */ filename = cpl_frame_get_filename(frame); all_keywords = cpl_propertylist_load(filename, 0); paf_proplist = cpl_propertylist_new(); - if(all_keywords == NULL) - { - cpl_msg_error(er_func,"Could not read the main header of %s", filename); + if (all_keywords == NULL) { + cpl_msg_error(er_func, "Could not read the main header of %s", + filename); return NULL; } /* Retrieve mandatory keywords */ - cpl_propertylist_copy_property_regexp - (paf_proplist, all_keywords, ER_PAF_MANDATORY_KEYS_MAIN_EXT, 0); + cpl_propertylist_copy_property_regexp(paf_proplist, all_keywords, + ER_PAF_MANDATORY_KEYS_MAIN_EXT, 0); cpl_propertylist_append_string(paf_proplist, "ARCFILE", arcfile); /* Retrieve requested keywords in configuration */ nkeys = er_stringarray_size(config_item->requested_keywords); - for(ikey = 0 ; ikey < nkeys; ++ikey) - { - char * key = er_stringarray_get(config_item->requested_keywords, ikey); - cpl_propertylist * matched_keys; + for (ikey = 0; ikey < nkeys; ++ikey) { + char *key = er_stringarray_get(config_item->requested_keywords, ikey); + cpl_propertylist *matched_keys; matched_keys = cpl_propertylist_new(); - cpl_propertylist_copy_property_regexp(matched_keys, all_keywords,key,0); - if(cpl_propertylist_get_size(matched_keys) == 0) + cpl_propertylist_copy_property_regexp(matched_keys, all_keywords, key, + 0); + if (cpl_propertylist_get_size(matched_keys) == 0) cpl_msg_debug(er_func, "Cannot find keywords matching %s", key); cpl_propertylist_append(paf_proplist, matched_keys); cpl_propertylist_delete(matched_keys); } /* Retrieve QC keywords */ - cpl_propertylist_copy_property_regexp - (paf_proplist, all_keywords, ER_PAF_QC_KEYS, 0); + cpl_propertylist_copy_property_regexp(paf_proplist, all_keywords, + ER_PAF_QC_KEYS, 0); /* Bad return if there are no keywords at all */ - if(cpl_propertylist_get_size(paf_proplist) == 0) - { + if (cpl_propertylist_get_size(paf_proplist) == 0) { cpl_msg_error(er_func, "Could not get any keyword from file %s", filename); cpl_propertylist_delete(paf_proplist); @@ -535,60 +518,57 @@ */ /**********************************************************************/ -cpl_propertylist* er_paf_fill_paf_proplist_multi_hdu -(const cpl_frame * frame, - struct er_paf_config_item * config_item, - int iext, - char * arcfile) -{ - cpl_propertylist * paf_proplist; - cpl_propertylist * all_keywords_hdu_main; - cpl_propertylist * all_keywords_hdu_ext; - cpl_propertylist * qc_keywords; - const char * filename; - int ikey; - int nkeys; +cpl_propertylist * +er_paf_fill_paf_proplist_multi_hdu(const cpl_frame *frame, + struct er_paf_config_item *config_item, + int iext, + char *arcfile) +{ + cpl_propertylist *paf_proplist; + cpl_propertylist *all_keywords_hdu_main; + cpl_propertylist *all_keywords_hdu_ext; + cpl_propertylist *qc_keywords; + const char *filename; + int ikey; + int nkeys; /* Read All keywords from FITS headers */ paf_proplist = cpl_propertylist_new(); filename = cpl_frame_get_filename(frame); all_keywords_hdu_main = cpl_propertylist_load(filename, 0); - if(all_keywords_hdu_main == NULL) - { - cpl_msg_error(er_func,"Could not read the main header of %s", filename); + if (all_keywords_hdu_main == NULL) { + cpl_msg_error(er_func, "Could not read the main header of %s", + filename); return NULL; } all_keywords_hdu_ext = cpl_propertylist_load(filename, iext); - if(all_keywords_hdu_ext == NULL) - { - cpl_msg_error(er_func,"Could not read header of extension %d in %s", + if (all_keywords_hdu_ext == NULL) { + cpl_msg_error(er_func, "Could not read header of extension %d in %s", iext, filename); return NULL; } /* Retrieve mandatory keywords from main header */ - cpl_propertylist_copy_property_regexp - (paf_proplist, all_keywords_hdu_main, - ER_PAF_MANDATORY_KEYS_MAIN_EXT, 0); + cpl_propertylist_copy_property_regexp(paf_proplist, all_keywords_hdu_main, + ER_PAF_MANDATORY_KEYS_MAIN_EXT, 0); cpl_propertylist_append_string(paf_proplist, "ARCFILE", arcfile); /* Retrieve mandatory keywords from extension */ - cpl_propertylist_copy_property_regexp - (paf_proplist, all_keywords_hdu_ext, ER_PAF_MANDATORY_KEYS_EXT, 0); + cpl_propertylist_copy_property_regexp(paf_proplist, all_keywords_hdu_ext, + ER_PAF_MANDATORY_KEYS_EXT, 0); /* Retrieve requested keywords in configuration */ nkeys = er_stringarray_size(config_item->requested_keywords); - for(ikey = 0 ; ikey < nkeys; ++ikey) - { - char * key = er_stringarray_get(config_item->requested_keywords, ikey); - cpl_propertylist * matched_keys; + for (ikey = 0; ikey < nkeys; ++ikey) { + char *key = er_stringarray_get(config_item->requested_keywords, ikey); + cpl_propertylist *matched_keys; matched_keys = cpl_propertylist_new(); cpl_propertylist_copy_property_regexp(matched_keys, - all_keywords_hdu_main,key,0); + all_keywords_hdu_main, key, 0); cpl_propertylist_copy_property_regexp(matched_keys, - all_keywords_hdu_ext,key,0); - if(cpl_propertylist_get_size(matched_keys) == 0) + all_keywords_hdu_ext, key, 0); + if (cpl_propertylist_get_size(matched_keys) == 0) cpl_msg_debug(er_func, "Cannot find keywords matching %s", key); cpl_propertylist_append(paf_proplist, matched_keys); cpl_propertylist_delete(matched_keys); @@ -596,10 +576,9 @@ /* Retrieve QC keywords */ qc_keywords = cpl_propertylist_new(); - cpl_propertylist_copy_property_regexp - (qc_keywords, all_keywords_hdu_ext, ER_PAF_QC_KEYS, 0); - if(cpl_propertylist_get_size(qc_keywords) == 0) - { + cpl_propertylist_copy_property_regexp(qc_keywords, all_keywords_hdu_ext, + ER_PAF_QC_KEYS, 0); + if (cpl_propertylist_get_size(qc_keywords) == 0) { cpl_msg_debug(er_func, "No QC keywords found in file %s, extension %d", filename, iext); cpl_propertylist_delete(paf_proplist); @@ -611,8 +590,7 @@ cpl_propertylist_delete(qc_keywords); /* Bad return if there are no keywords at all */ - if(cpl_propertylist_get_size(paf_proplist) == 0) - { + if (cpl_propertylist_get_size(paf_proplist) == 0) { cpl_msg_warning(er_func, "Could not get any keyword from file %s", filename); cpl_propertylist_delete(all_keywords_hdu_main); @@ -626,41 +604,42 @@ return paf_proplist; } -char * er_paf_get_arcfile(const cpl_frameset * frames) +char * +er_paf_get_arcfile(const cpl_frameset *frames) { - const cpl_frame * frame; - char * arcfile = NULL; - cpl_propertylist * all_keywords; - const char * filename; + const cpl_frame *frame; + char *arcfile = NULL; + cpl_propertylist *all_keywords; + const char *filename; /* Loop into all the products */ cpl_frameset_iterator *it = cpl_frameset_iterator_new(frames); - while ((frame = cpl_frameset_iterator_get_const(it)) != NULL) - { - if (cpl_frame_get_group(frame) == CPL_FRAME_GROUP_RAW) - { + while ((frame = cpl_frameset_iterator_get_const(it)) != NULL) { + if (cpl_frame_get_group(frame) == CPL_FRAME_GROUP_RAW) { filename = cpl_frame_get_filename(frame); all_keywords = cpl_propertylist_load(filename, 0); - if(all_keywords == NULL) - { + if (all_keywords == NULL) { cpl_frameset_iterator_delete(it); - cpl_msg_error(er_func,"Could not read the main header of %s", + cpl_msg_error(er_func, "Could not read the main header of %s", filename); return NULL; } - const char *_arcfile = cpl_propertylist_get_string(all_keywords, - "ESO PRO ANCESTOR"); + const char *_arcfile = + cpl_propertylist_get_string(all_keywords, "ESO PRO ANCESTOR"); - if (!_arcfile && !cpl_propertylist_has(all_keywords, "ESO PRO CATG")) { + if (!_arcfile && + !cpl_propertylist_has(all_keywords, "ESO PRO CATG")) { _arcfile = cpl_propertylist_get_string(all_keywords, "ARCFILE"); } if (!_arcfile) { - cpl_msg_error(er_func,"Could not get ARCFILE information from " - "the main header of %s", filename); + cpl_msg_error(er_func, + "Could not get ARCFILE information from " + "the main header of %s", + filename); cpl_frameset_iterator_delete(it); cpl_propertylist_delete(all_keywords); return NULL; @@ -675,14 +654,12 @@ } cpl_frameset_iterator_advance(it, 1); - } cpl_frameset_iterator_delete(it); - cpl_msg_error(er_func,"There are no RAW frames"); + cpl_msg_error(er_func, "There are no RAW frames"); return arcfile; - } @@ -695,11 +672,12 @@ * */ /**********************************************************************/ -er_stringarray_t * er_paf_read_whole_file(const char * paf_config_filename) +er_stringarray_t * +er_paf_read_whole_file(const char *paf_config_filename) { - FILE * file_descriptor; + FILE *file_descriptor; char line[MAXSTRLENCONF]; - er_stringarray_t * file_buffer; + er_stringarray_t *file_buffer; /* Allocate string array */ file_buffer = er_stringarray_new(); @@ -710,8 +688,7 @@ return NULL; memset(line, 0, MAXSTRLENCONF); - while (fgets(line, MAXSTRLENCONF -1, file_descriptor) != NULL) - { + while (fgets(line, MAXSTRLENCONF - 1, file_descriptor) != NULL) { /* Fill the array with this new line */ er_stringarray_append(file_buffer, line); /* Reinitialize buffer */ @@ -732,78 +709,74 @@ * */ /**********************************************************************/ -int er_paf_parse_config -(er_stringarray_t * config_lines, - struct er_paf_config * paf_configuration) -{ - unsigned int iline = 0; - unsigned int nlines; - unsigned int nitem = 0; - struct er_paf_config_item * items; +int +er_paf_parse_config(er_stringarray_t *config_lines, + struct er_paf_config *paf_configuration) +{ + unsigned int iline = 0; + unsigned int nlines; + unsigned int nitem = 0; + struct er_paf_config_item *items; - cpl_msg_debug(__func__,"Parsing the paf configuration file"); + cpl_msg_debug(__func__, "Parsing the paf configuration file"); /* Alias for the items structure */ items = paf_configuration->items; /* Parse all the lines */ nlines = er_stringarray_size(config_lines); - cpl_msg_debug(__func__,"Number of lines in pkd file: %d", nlines); - while(iline < nlines) - { - char * current_line = er_stringarray_get(config_lines, (int)iline); - if(strncmp(current_line, "PRO CATG",8) == 0) - { - struct er_paf_config_item* new_item; - char * pro_catg_regexp = NULL; + cpl_msg_debug(__func__, "Number of lines in pkd file: %d", nlines); + while (iline < nlines) { + char *current_line = er_stringarray_get(config_lines, (int)iline); + if (strncmp(current_line, "PRO CATG", 8) == 0) { + struct er_paf_config_item *new_item; + char *pro_catg_regexp = NULL; /* Allocate space for the new config item */ ++nitem; - items = cpl_realloc(items, - nitem*sizeof(struct er_paf_config_item)); - new_item = items + nitem -1; - new_item->pro_catg_regexp = cpl_malloc(MAXSTRLENCONF*sizeof(char)); + items = + cpl_realloc(items, nitem * sizeof(struct er_paf_config_item)); + new_item = items + nitem - 1; + new_item->pro_catg_regexp = + cpl_malloc(MAXSTRLENCONF * sizeof(char)); new_item->requested_keywords = er_stringarray_new(); paf_configuration->nitems = nitem; /* Get the regexp for PRO CATG */ pro_catg_regexp = strchr(current_line, '='); - if(pro_catg_regexp == NULL || strlen(pro_catg_regexp) < 2) - { - cpl_msg_error(er_func,"Parse error in PAF config. " - "No '=' delimiter"); + if (pro_catg_regexp == NULL || strlen(pro_catg_regexp) < 2) { + cpl_msg_error(er_func, "Parse error in PAF config. " + "No '=' delimiter"); return -1; } - strncpy(new_item->pro_catg_regexp, - pro_catg_regexp + 1, MAXSTRLENCONF); + strncpy(new_item->pro_catg_regexp, pro_catg_regexp + 1, + MAXSTRLENCONF); /* Remove leading and trailing characters */ cx_strstrip(new_item->pro_catg_regexp); ++iline; - while(iline < nlines) - { - char * keyword = er_stringarray_get(config_lines, (int)iline); - if(strncmp(keyword, "PRO CATG",8) == 0) + while (iline < nlines) { + char *keyword = er_stringarray_get(config_lines, (int)iline); + if (strncmp(keyword, "PRO CATG", 8) == 0) break; /* Remove leading and trailing characters */ cx_strstrip(keyword); /* If it is a keyword containing only spaces, do not count it */ - if(strcmp(keyword,"") != 0) - { + if (strcmp(keyword, "") != 0) { /* Add this keyword to the requested keywords */ - er_stringarray_append(new_item->requested_keywords, keyword); + er_stringarray_append(new_item->requested_keywords, + keyword); } ++iline; } } - else - { + else { cpl_msg_error(er_func, "Error parsing PAF configuration file"); return CPL_ERROR_BAD_FILE_FORMAT; } } - cpl_msg_debug(__func__,"Number of pro catg definitions found in file: %d", + cpl_msg_debug(__func__, "Number of pro catg definitions found in file: %d", paf_configuration->nitems); /* Get the alias back */ @@ -824,15 +797,15 @@ */ /**********************************************************************/ -int er_paf_config_delete(struct er_paf_config* paf_configuration) +int +er_paf_config_delete(struct er_paf_config *paf_configuration) { unsigned int item; /* Deallocate the items */ - for (item = 0; item < paf_configuration->nitems; ++item) - { - er_stringarray_delete - (paf_configuration->items[item].requested_keywords); + for (item = 0; item < paf_configuration->nitems; ++item) { + er_stringarray_delete( + paf_configuration->items[item].requested_keywords); cpl_free(paf_configuration->items[item].pro_catg_regexp); } cpl_free(paf_configuration->items); diff -Nru esorex-3.13.5+ds/src/er_paf.h esorex-3.13.6+ds/src/er_paf.h --- esorex-3.13.5+ds/src/er_paf.h 2021-06-02 15:06:13.000000000 +0000 +++ esorex-3.13.6+ds/src/er_paf.h 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 European Southern Observatory * * 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 @@ -29,14 +29,14 @@ struct er_paf_config_item { - char *pro_catg_regexp; + char *pro_catg_regexp; er_stringarray_t *requested_keywords; }; struct er_paf_config { struct er_paf_config_item *items; - unsigned int nitems; + unsigned int nitems; }; extern int er_create_recipe_pafs(const cpl_frameset *frames, @@ -55,10 +55,8 @@ const char *recipe_name, char *arcfile); -extern struct er_paf_config *er_paf_read_config_file -( - const char *val_paf_config -); +extern struct er_paf_config * +er_paf_read_config_file(const char *val_paf_config); extern cpl_propertylist * er_paf_fill_paf_proplist_single_hdu(const cpl_frame *frame, @@ -78,8 +76,7 @@ er_paf_get_matching_item(struct er_paf_config *paf_configuration, const char *this_pro_catg); -extern er_stringarray_t * -er_paf_read_whole_file(const char *val_paf_config); +extern er_stringarray_t *er_paf_read_whole_file(const char *val_paf_config); extern int er_paf_config_delete(struct er_paf_config *paf_configuration); diff -Nru esorex-3.13.5+ds/src/er_params.c esorex-3.13.6+ds/src/er_params.c --- esorex-3.13.5+ds/src/er_params.c 2021-06-02 15:06:13.000000000 +0000 +++ esorex-3.13.6+ds/src/er_params.c 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 European Southern Observatory * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif #include @@ -27,9 +27,9 @@ #include #ifdef HAVE_GETOPT_LONG_ONLY -# include +#include #else -# include "getopt.h" +#include "getopt.h" #endif #include "ltdl.h" @@ -72,13 +72,13 @@ */ /**********************************************************************/ -int params_parse_config_file (cpl_parameterlist *param_list, - const char *file_name) +int +params_parse_config_file(cpl_parameterlist *param_list, const char *file_name) { const char *f_file_kw; char input[MAXSTRLENCONF]; - char temp[MAXSTRLENCONF]; /* Temporary copy of "input" */ + char temp[MAXSTRLENCONF]; /* Temporary copy of "input" */ char **kv_pair; cpl_parameter *p; @@ -86,71 +86,69 @@ size_t value_length, i; int f_file_active; - int num_values; /* The number of values read with sscanf() */ - int maj_cfg_version; /* Maj.version No. from config file */ - int maj_pkg_version; /* Maj.version No. of this executable */ + int num_values; /* The number of values read with sscanf() */ + int maj_cfg_version; /* Maj.version No. from config file */ + int maj_pkg_version; /* Maj.version No. of this executable */ FILE *file_descriptor; - if (file_name == NULL) return -1; + if (file_name == NULL) + return -1; - file_descriptor = fopen (file_name, "r"); - if (file_descriptor == NULL) return -1; + file_descriptor = fopen(file_name, "r"); + if (file_descriptor == NULL) + return -1; /* Initialize buffer */ temp[0] = '\0'; - memset (input, 0, MAXSTRLENCONF); + memset(input, 0, MAXSTRLENCONF); /* Start reading lines from file */ - while (fgets (input, MAXSTRLENCONF, file_descriptor) != NULL) - { + while (fgets(input, MAXSTRLENCONF, file_descriptor) != NULL) { /* Strip leading and trailing whitespace from entire line */ - (void) cx_strstrip (input); + (void)cx_strstrip(input); /* Check if we have an old configuration file */ - if (strncmp (input, ER_HELP_CFG_VER, strlen (ER_HELP_CFG_VER)) == 0) - { + if (strncmp(input, ER_HELP_CFG_VER, strlen(ER_HELP_CFG_VER)) == 0) { /* * If we get to this part, then we have the comment * about the version */ - strcpy (temp, input); + strcpy(temp, input); /* Convert all the non-numbers to white space */ - for (i = 0; i < strlen (temp); i++) - { - if (!isdigit ((int) temp[i])) + for (i = 0; i < strlen(temp); i++) { + if (!isdigit((int)temp[i])) temp[i] = ' '; } - num_values = sscanf (temp, "%d", &maj_cfg_version); - if (num_values == 1) - { - num_values = sscanf (VERSION, "%d", &maj_pkg_version); + num_values = sscanf(temp, "%d", &maj_cfg_version); + if (num_values == 1) { + num_values = sscanf(VERSION, "%d", &maj_pkg_version); if (num_values != 1) - cpl_msg_error (er_func, "Unidentifed " PACKAGE " version"); - if (maj_pkg_version > maj_cfg_version) - { - cpl_msg_warning (er_func, - "The configuration file '%s' appears " - "to have been created with an older " - "version of EsoRex.", file_name); + cpl_msg_error(er_func, "Unidentifed " PACKAGE " version"); + if (maj_pkg_version > maj_cfg_version) { + cpl_msg_warning(er_func, + "The configuration file '%s' appears " + "to have been created with an older " + "version of EsoRex.", + file_name); } - if (maj_pkg_version < maj_cfg_version) - { - cpl_msg_warning (er_func, - "The configuration file '%s' appears " - "to have been created with a more " - "recent version of EsoRex.", file_name); + if (maj_pkg_version < maj_cfg_version) { + cpl_msg_warning(er_func, + "The configuration file '%s' appears " + "to have been created with a more " + "recent version of EsoRex.", + file_name); } } - } /* End of configuration version checking */ + } /* End of configuration version checking */ /* @@ -159,36 +157,38 @@ * otherwise try to find keyword=value */ - if ((input[0] != '#') && (input[0] != '\0')) - { + if ((input[0] != '#') && (input[0] != '\0')) { /* Try to split this line into a key-value pair at an "=" sign */ - if ((kv_pair = cx_strsplit (input, "=", 2))) - { + if ((kv_pair = cx_strsplit(input, "=", 2))) { /* * Strip leading and trailing whitespace from keyword and * value */ - if (kv_pair[0]) (void) cx_strstrip (kv_pair[0]); - if (kv_pair[1]) (void) cx_strstrip (kv_pair[1]); + if (kv_pair[0]) + (void)cx_strstrip(kv_pair[0]); + if (kv_pair[1]) + (void)cx_strstrip(kv_pair[1]); } /* Ensure that key-value splitting was successful */ /* Ensure that both the key and the value are set to something */ - if ((kv_pair == NULL) - || (kv_pair[0] == NULL) || (kv_pair[1] == NULL) - || (kv_pair[0][0] == '\0') || (kv_pair[1][0] == '\0')) - { - cpl_msg_error (er_func, "'%s' does not fit 'key=value' " - "format in configuration file '%s'", input, - file_name); - - cpl_msg_error (er_func, "Unable to continue parsing " - "configuration file '%s'", - file_name); + if ((kv_pair == NULL) || (kv_pair[0] == NULL) || + (kv_pair[1] == NULL) || (kv_pair[0][0] == '\0') || + (kv_pair[1][0] == '\0')) { + cpl_msg_error(er_func, + "'%s' does not fit 'key=value' " + "format in configuration file '%s'", + input, file_name); + + cpl_msg_error(er_func, + "Unable to continue parsing " + "configuration file '%s'", + file_name); - fclose (file_descriptor); + fclose(file_descriptor); - if (kv_pair) cx_strfreev (kv_pair); /* free array */ + if (kv_pair) + cx_strfreev(kv_pair); /* free array */ return -2; } @@ -201,96 +201,93 @@ p = cpl_parameterlist_get_first(param_list); - while (p != NULL) - { + while (p != NULL) { /* Over-ride them with values */ - f_file_active = cpl_parameter_is_enabled(p, CPL_PARAMETER_MODE_CFG); + f_file_active = + cpl_parameter_is_enabled(p, CPL_PARAMETER_MODE_CFG); f_file_kw = cpl_parameter_get_name(p); - if (strcmp(kv_pair[0], f_file_kw) == 0) - { - if (f_file_active != 0) - { + if (strcmp(kv_pair[0], f_file_kw) == 0) { + if (f_file_active != 0) { f_unknown_param = 0; - value_length = strlen (kv_pair[1]); + value_length = strlen(kv_pair[1]); /* Handle quoted values */ - if (kv_pair[1][0] == '"') - { - if ((kv_pair[1][value_length - 1] == '"') - && (kv_pair[1][value_length - 2] != '\\')) - { + if (kv_pair[1][0] == '"') { + if ((kv_pair[1][value_length - 1] == '"') && + (kv_pair[1][value_length - 2] != '\\')) { /* Matching quotes at start and end - remove them */ - memmove (&kv_pair[1][0], &kv_pair[1][1], - value_length - 2); + memmove(&kv_pair[1][0], &kv_pair[1][1], + value_length - 2); kv_pair[1][value_length - 2] = '\0'; value_length -= 2; } - else - { + else { /* Quotes are mismatched */ - cpl_msg_error (er_func, - "Quoting mismatch within value " - "'%s' for parameter '%s' in " - "configuration file '%s'", - kv_pair[1], kv_pair[0], file_name); - - cpl_msg_error (er_func, "Unable to continue " - "parsing configuration file '%s'", - file_name); + cpl_msg_error(er_func, + "Quoting mismatch within value " + "'%s' for parameter '%s' in " + "configuration file '%s'", + kv_pair[1], kv_pair[0], + file_name); + + cpl_msg_error(er_func, + "Unable to continue " + "parsing configuration file '%s'", + file_name); - fclose (file_descriptor); + fclose(file_descriptor); - cx_strfreev (kv_pair); + cx_strfreev(kv_pair); return -3; } } /* Strip backslash-escaping out of the value string */ - for (i=0; i 0) - { - cpl_msg_warning(er_func, "Parameter '%s' should not appear " + else if (f_unknown_param > 0) { + cpl_msg_warning(er_func, + "Parameter '%s' should not appear " "in a configuration file, but is present in " - "'%s'", kv_pair[0], file_name); + "'%s'", + kv_pair[0], file_name); } cx_strfreev(kv_pair); @@ -330,7 +330,7 @@ return 0; -} /* End of params_parse_config_file() */ +} /* End of params_parse_config_file() */ /**********************************************************************/ @@ -349,7 +349,8 @@ */ /**********************************************************************/ -int params_parse_config_environment (cpl_parameterlist * param_list) +int +params_parse_config_environment(cpl_parameterlist *param_list) { char *value; @@ -359,40 +360,37 @@ int f_env_active; - p = cpl_parameterlist_get_first (param_list); + p = cpl_parameterlist_get_first(param_list); - while (p != NULL) - { + while (p != NULL) { f_env_active = 0; - f_env_active = cpl_parameter_is_enabled (p, CPL_PARAMETER_MODE_ENV); + f_env_active = cpl_parameter_is_enabled(p, CPL_PARAMETER_MODE_ENV); - if (f_env_active != 0) - { /* we have an env-var for that parameter */ - const char *envvar; + if (f_env_active != 0) { /* we have an env-var for that parameter */ + const char *envvar; - envvar = cpl_parameter_get_alias (p, CPL_PARAMETER_MODE_ENV); - value = getenv (envvar); /* get value of that variable */ + envvar = cpl_parameter_get_alias(p, CPL_PARAMETER_MODE_ENV); + value = getenv(envvar); /* get value of that variable */ - if (value != NULL) - { - int err; - char str[256]; - - err = (int) strlen(envvar); - if (err > 220) - { - cpl_msg_warning (er_func, "Name of env. variable > " - "220 chars - skipped"); + if (value != NULL) { + int err; + char str[256]; + + err = (int)strlen(envvar); + if (err > 220) { + cpl_msg_warning(er_func, "Name of env. variable > " + "220 chars - skipped"); return err; } - (void) sprintf (str, "environment variable '%s'", envvar); - err = paramutils_set_from_string (p, value, str); - if (err != 0) return err; + (void)sprintf(str, "environment variable '%s'", envvar); + err = paramutils_set_from_string(p, value, str); + if (err != 0) + return err; } } - p = cpl_parameterlist_get_next (param_list); + p = cpl_parameterlist_get_next(param_list); } return 0; @@ -412,77 +410,76 @@ /**********************************************************************/ static struct option * -param_list_to_cmdl_opt_list (cpl_parameterlist * param_list) +param_list_to_cmdl_opt_list(cpl_parameterlist *param_list) { - int countparam = 0, i = 0; - int alias_flag = 0; + int countparam = 0, i = 0; + int alias_flag = 0; - char *cptr; + char *cptr; - size_t strlength = 0; + size_t strlength = 0; - struct option *newoptions = NULL; - cpl_parameter *p; + struct option *newoptions = NULL; + cpl_parameter *p; - /* + /* * if env. var ESOREX_USE_PARAM_NAME is defined, we use not the * alias but the full name of parameters */ - cptr = getenv ("ESOREX_USE_PARAM_NAME"); - if (cptr == NULL) - alias_flag = 1; - else - alias_flag = 0; - - countparam = cpl_parameterlist_get_size (param_list); + cptr = getenv("ESOREX_USE_PARAM_NAME"); + if (cptr == NULL) + alias_flag = 1; + else + alias_flag = 0; - newoptions = (struct option *) - cpl_malloc ((size_t) sizeof (struct option) * (countparam + 1)); + countparam = cpl_parameterlist_get_size(param_list); - if (newoptions != NULL) - { - p = cpl_parameterlist_get_first (param_list); + newoptions = (struct option *)cpl_malloc((size_t)sizeof(struct option) * + (countparam + 1)); - while (p != NULL) - { - if (alias_flag == 1) - strlength = - strlen (cpl_parameter_get_alias (p, CPL_PARAMETER_MODE_CLI)); - else - strlength = strlen (cpl_parameter_get_name (p)); + if (newoptions != NULL) { + p = cpl_parameterlist_get_first(param_list); - newoptions[i].name = - (char *) cpl_malloc ((size_t) (sizeof (char) * (strlength + 1))); + while (p != NULL) { + if (alias_flag == 1) + strlength = + strlen(cpl_parameter_get_alias(p, CPL_PARAMETER_MODE_CLI)); + else + strlength = strlen(cpl_parameter_get_name(p)); - if (alias_flag == 1) - (void) strcpy ((char *) newoptions[i].name, - cpl_parameter_get_alias (p, CPL_PARAMETER_MODE_CLI)); - else - (void) strcpy ((char *) newoptions[i].name, - cpl_parameter_get_name (p)); + newoptions[i].name = + (char *)cpl_malloc((size_t)(sizeof(char) * (strlength + 1))); - newoptions[i].has_arg = optional_argument; - newoptions[i].flag = NULL; - newoptions[i].val = cpl_parameter_get_id (p); + if (alias_flag == 1) + (void)strcpy((char *)newoptions[i].name, + cpl_parameter_get_alias(p, + CPL_PARAMETER_MODE_CLI)); + else + (void)strcpy((char *)newoptions[i].name, + cpl_parameter_get_name(p)); - p = cpl_parameterlist_get_next (param_list); + newoptions[i].has_arg = optional_argument; + newoptions[i].flag = NULL; + newoptions[i].val = cpl_parameter_get_id(p); - i++; - } + p = cpl_parameterlist_get_next(param_list); - /* add closing entry to option list */ - newoptions[i].name = 0; - newoptions[i].has_arg = 0; - newoptions[i].flag = 0; - newoptions[i].val = 0; + i++; } - return newoptions; + /* add closing entry to option list */ + newoptions[i].name = 0; + newoptions[i].has_arg = 0; + newoptions[i].flag = 0; + newoptions[i].val = 0; + } -} /* End of param_list_to_cmdl_opt_list() */ + return newoptions; + +} /* End of param_list_to_cmdl_opt_list() */ /**********************************************************************/ @@ -496,9 +493,9 @@ * @param f_caller Boolean indicating if parsing should begin from the * recipe name argument or not. * - * @retval recipe_name Name of the recipe given on the command line - * @retval set_of_frames_filenames Set of strings containing filenames of - * set of frames + * @param recipe_name Name of the recipe given on the command line + * @param set_of_frames_filenames Set of strings containing filenames of + * set of frames * @return None * * Function parses command file arguments given in @em argv for keyword-value @@ -515,7 +512,8 @@ params_parse_config_commandline(cpl_parameterlist *param_list, char *recipe_name, er_stringarray_t *set_of_frames_filenames, - int argc, char *argv[], + int argc, + char *argv[], int f_caller) { @@ -530,45 +528,42 @@ /* Number all parameters uniquely so we can find them using getopt */ - p = cpl_parameterlist_get_first (param_list); + p = cpl_parameterlist_get_first(param_list); i = 0; - while (p != NULL) - { - cpl_parameter_set_id (p, i++); - p = cpl_parameterlist_get_next (param_list); + while (p != NULL) { + cpl_parameter_set_id(p, i++); + p = cpl_parameterlist_get_next(param_list); } /* Generate temporary opt array so we can use getopt */ - getopt_input_list = param_list_to_cmdl_opt_list (param_list); + getopt_input_list = param_list_to_cmdl_opt_list(param_list); - opterr = 0; /* suppress getopt_warnings */ - optind = 0; /* make sure we can enter this routine multiple times */ + opterr = 0; /* suppress getopt_warnings */ + optind = 0; /* make sure we can enter this routine multiple times */ /* * If called for plugin options, advance argv and reduce argc so that * getopt() will start processing from the plugin name. */ - if (f_caller == 0) - { - const char* tmp_name_ptr = recipe_name; + if (f_caller == 0) { + const char *tmp_name_ptr = recipe_name; - for (i=0; i FILEMAX) - { - cpl_msg_error (er_func, "length of recipe name " - "(= %d chars)\n(name: %44.44s...)\nis > max. " - "size (= %d)", n, recipe_name,FILEMAX); + for (i = 0; i < argc; ++i) { + n = (int)strlen(argv[i]); + if (n > FILEMAX) { + cpl_msg_error(er_func, + "length of recipe name " + "(= %d chars)\n(name: %44.44s...)\nis > max. " + "size (= %d)", + n, recipe_name, FILEMAX); return -1; } - if (!strcmp (argv[i], tmp_name_ptr)) - { + if (!strcmp(argv[i], tmp_name_ptr)) { argv += i; argc -= i; break; @@ -576,12 +571,12 @@ } } - while (1) - { - option_id = getopt_long_only(argc, argv, "+", - getopt_input_list, &option_index); + while (1) { + option_id = + getopt_long_only(argc, argv, "+", getopt_input_list, &option_index); - if (option_id == -1) break; /* end of --option list */ + if (option_id == -1) + break; /* end of --option list */ f_unknown_param = 1; @@ -589,13 +584,11 @@ if (option_id != option_index) goto check_getopt; - p = cpl_parameterlist_get_first (param_list); + p = cpl_parameterlist_get_first(param_list); - while (p != NULL) - { /* Found keyword in list */ - if ((int) cpl_parameter_get_id (p) == option_id) - { - ptype = cpl_parameter_get_type (p); + while (p != NULL) { /* Found keyword in list */ + if ((int)cpl_parameter_get_id(p) == option_id) { + ptype = cpl_parameter_get_type(p); f_unknown_param = 0; /* @@ -606,100 +599,94 @@ * --blah=xxxxx optarg = "xxxxx" (string length > 0) */ - if (optarg == NULL) - { - if (ptype == CPL_TYPE_BOOL) - { - (void) paramutils_set_from_string (p, "TRUE", - "command line"); + if (optarg == NULL) { + if (ptype == CPL_TYPE_BOOL) { + (void)paramutils_set_from_string(p, "TRUE", + "command line"); } - else if (ptype == CPL_TYPE_STRING) - { - (void) paramutils_set_from_string (p, "", - "command line"); + else if (ptype == CPL_TYPE_STRING) { + (void)paramutils_set_from_string(p, "", "command line"); } - else - { - cpl_msg_error (er_func, - "'--%s' needs an argument but none was specified...", - cpl_parameter_get_alias (p, CPL_PARAMETER_MODE_CLI)); + else { + cpl_msg_error( + er_func, + "'--%s' needs an argument but none was " + "specified...", + cpl_parameter_get_alias(p, CPL_PARAMETER_MODE_CLI)); } } - else if (strlen (optarg) == 0) - { - if (ptype == CPL_TYPE_STRING) - { - (void) paramutils_set_from_string (p, "", - "command line"); + else if (strlen(optarg) == 0) { + if (ptype == CPL_TYPE_STRING) { + (void)paramutils_set_from_string(p, "", "command line"); } - else - { - cpl_msg_error (er_func, - "'--%s' needs an argument but none was " - "specified after the equals sign (\"=\").", - cpl_parameter_get_alias (p, CPL_PARAMETER_MODE_CLI)); - - countparam = cpl_parameterlist_get_size (param_list); - for (iparam = 0; iparam < countparam; iparam++) - { - cpl_free ((char *) getopt_input_list[iparam].name); + else { + cpl_msg_error( + er_func, + "'--%s' needs an argument but none was " + "specified after the equals sign (\"=\").", + cpl_parameter_get_alias(p, CPL_PARAMETER_MODE_CLI)); + + countparam = cpl_parameterlist_get_size(param_list); + for (iparam = 0; iparam < countparam; iparam++) { + cpl_free((char *)getopt_input_list[iparam].name); } - cpl_free (getopt_input_list); + cpl_free(getopt_input_list); - cpl_msg_error (er_func, "'%s' during processing of '%s'", - cpl_error_get_message (), - cpl_parameter_get_alias (p, CPL_PARAMETER_MODE_CLI)); + cpl_msg_error( + er_func, "'%s' during processing of '%s'", + cpl_error_get_message(), + cpl_parameter_get_alias(p, CPL_PARAMETER_MODE_CLI)); return -1; } } - else - { - err = paramutils_set_from_string (p, optarg, "command line"); - if (err != 0) - { - countparam = cpl_parameterlist_get_size (param_list); - for (iparam = 0; iparam < countparam; iparam++) - { - cpl_free ((char *) getopt_input_list[iparam].name); + else { + err = paramutils_set_from_string(p, optarg, "command line"); + if (err != 0) { + countparam = cpl_parameterlist_get_size(param_list); + for (iparam = 0; iparam < countparam; iparam++) { + cpl_free((char *)getopt_input_list[iparam].name); } - cpl_free (getopt_input_list); + cpl_free(getopt_input_list); - cpl_msg_error (er_func, - "CPL error '%s' occurred during the processing of the " - "option '--%s'", - cpl_error_get_message (), - cpl_parameter_get_alias (p, CPL_PARAMETER_MODE_CLI)); - - cpl_msg_warning (er_func, - "Check that the supplied value is of a " - "suitable type for the parameter (e.g. enum, string, " - "boolean, etc.) and is within any required range."); + cpl_msg_error( + er_func, + "CPL error '%s' occurred during the processing of " + "the " + "option '--%s'", + cpl_error_get_message(), + cpl_parameter_get_alias(p, CPL_PARAMETER_MODE_CLI)); + + cpl_msg_warning( + er_func, + "Check that the supplied value is of a " + "suitable type for the parameter (e.g. enum, " + "string, " + "boolean, etc.) and is within any required range."); return err; } - } } - p = cpl_parameterlist_get_next (param_list); + p = cpl_parameterlist_get_next(param_list); } - check_getopt: - if (f_unknown_param) - { - countparam = cpl_parameterlist_get_size (param_list); - for (iparam = 0; iparam < countparam; iparam++) - { - cpl_free ((char *) getopt_input_list[iparam].name); + check_getopt: + if (f_unknown_param) { + countparam = cpl_parameterlist_get_size(param_list); + for (iparam = 0; iparam < countparam; iparam++) { + cpl_free((char *)getopt_input_list[iparam].name); } - cpl_free (getopt_input_list); - cpl_msg_error(er_func,"Command line parameter '%s' not " - "recognized", argv[optind - 1]); - cpl_msg_error (er_func, "Unable to continue parsing command " - "line options"); + cpl_free(getopt_input_list); + cpl_msg_error(er_func, + "Command line parameter '%s' not " + "recognized", + argv[optind - 1]); + cpl_msg_error(er_func, "Unable to continue parsing command " + "line options"); return -1; } @@ -707,41 +694,35 @@ /* Deallocate the parameter list */ - countparam = cpl_parameterlist_get_size (param_list); - for (iparam = 0; iparam < countparam; iparam++) - { - cpl_free ((char *) getopt_input_list[iparam].name); + countparam = cpl_parameterlist_get_size(param_list); + for (iparam = 0; iparam < countparam; iparam++) { + cpl_free((char *)getopt_input_list[iparam].name); } - cpl_free (getopt_input_list); + cpl_free(getopt_input_list); /* Start checking for the plugin name */ - if (optind < argc) - { - if (f_caller != 0) - { /* Assume first non-cmdl parameter is plugin name */ - n = (int) strlen(argv[optind]); - if (n > FILEMAX) - { - cpl_msg_error (er_func, - "length of recipe name (= %d chars)\n" - "(name: %44.44s...)\nis > max. size (= %d)", - n,argv[optind],FILEMAX); + if (optind < argc) { + if (f_caller != + 0) { /* Assume first non-cmdl parameter is plugin name */ + n = (int)strlen(argv[optind]); + if (n > FILEMAX) { + cpl_msg_error(er_func, + "length of recipe name (= %d chars)\n" + "(name: %44.44s...)\nis > max. size (= %d)", + n, argv[optind], FILEMAX); return -1; } - (void) strcpy(recipe_name, argv[optind]); + (void)strcpy(recipe_name, argv[optind]); } - else - { /* Assume all remaining cmdl parameter are set of frame filenames */ - while (optind < argc) - { - er_stringarray_append (set_of_frames_filenames, argv[optind]); + else { /* Assume all remaining cmdl parameter are set of frame filenames */ + while (optind < argc) { + er_stringarray_append(set_of_frames_filenames, argv[optind]); optind++; } } - } return 0; @@ -783,53 +764,47 @@ double d_default; - p = cpl_parameterlist_get_first (param_list); + p = cpl_parameterlist_get_first(param_list); - while (p != NULL) - { - f_is_present = cpl_parameter_get_default_flag (p); + while (p != NULL) { + f_is_present = cpl_parameter_get_default_flag(p); - if (!f_is_present) - { - ptype = cpl_parameter_get_type (p); + if (!f_is_present) { + ptype = cpl_parameter_get_type(p); - switch (ptype) - { + switch (ptype) { case CPL_TYPE_BOOL: - b_default = cpl_parameter_get_default_bool (p); - cpl_parameter_set_bool (p, b_default); + b_default = cpl_parameter_get_default_bool(p); + cpl_parameter_set_bool(p, b_default); break; case CPL_TYPE_INT: - i_default = cpl_parameter_get_default_int (p); - cpl_parameter_set_int (p, i_default); + i_default = cpl_parameter_get_default_int(p); + cpl_parameter_set_int(p, i_default); break; case CPL_TYPE_DOUBLE: - d_default = cpl_parameter_get_default_double (p); - cpl_parameter_set_double (p, d_default); + d_default = cpl_parameter_get_default_double(p); + cpl_parameter_set_double(p, d_default); break; case CPL_TYPE_STRING: - s_default = cpl_parameter_get_default_string (p); - if (s_default == NULL) - { - cpl_parameter_set_string (p, ""); + s_default = cpl_parameter_get_default_string(p); + if (s_default == NULL) { + cpl_parameter_set_string(p, ""); } - else - { - cpl_parameter_set_string (p, s_default); + else { + cpl_parameter_set_string(p, s_default); } break; default: break; - } /* End of switch(ptype) */ - + } /* End of switch(ptype) */ } - p = cpl_parameterlist_get_next (param_list); + p = cpl_parameterlist_get_next(param_list); } } /* End of params_parse_config_postprocess() */ @@ -878,42 +853,27 @@ char **val_recipe_dirs = NULL; int err = 0; - int f_val_config = 0, - f_val_recipe_dirs = 0, - f_val_plugin_config = 0, - f_val_version = 0, - f_val_plugins = 0, - f_val_help = 0, - f_val_create = 0, - f_val_params = 0, - f_val_nolink = 0, - f_val_noprefix = 0, - f_val_output_dir = 0, - f_val_link_dir = 0, - f_val_output_mask = 0, - f_val_log_file = 0, - f_val_log_dir = 0, - f_val_paf_config = 0, - f_val_products_sof = 0, - f_continue = 1; + int f_val_config = 0, f_val_recipe_dirs = 0, f_val_plugin_config = 0, + f_val_version = 0, f_val_plugins = 0, f_val_help = 0, f_val_create = 0, + f_val_params = 0, f_val_nolink = 0, f_val_noprefix = 0, + f_val_output_dir = 0, f_val_link_dir = 0, f_val_output_mask = 0, + f_val_log_file = 0, f_val_log_dir = 0, f_val_paf_config = 0, + f_val_products_sof = 0, f_continue = 1; - p = cpl_parameterlist_find (param_list, PACKAGE_RESOURCE ".create-config"); - if (cpl_parameter_get_default_flag (p)) - { - val_create = cpl_parameter_get_string (p); + p = cpl_parameterlist_find(param_list, PACKAGE_RESOURCE ".create-config"); + if (cpl_parameter_get_default_flag(p)) { + val_create = cpl_parameter_get_string(p); ForceNull(val_create) - /* --create-config=bla.bla found */ - if (val_create != NULL) + /* --create-config=bla.bla found */ + if (val_create != NULL) { /* handle FALSE and TRUE from boolean history of this param */ - if (strcmp(val_create,"TRUE") == 0) - { + if (strcmp(val_create, "TRUE") == 0) { f_val_create = 1; } - else if (strcmp(val_create,"FALSE") != 0) - { - f_val_create = 11; /* indicates filename is given */ + else if (strcmp(val_create, "FALSE") != 0) { + f_val_create = 11; /* indicates filename is given */ } } else @@ -924,151 +884,133 @@ } - p = cpl_parameterlist_find (param_list, PACKAGE_RESOURCE ".config"); - if (cpl_parameter_get_default_flag (p)) - { - val_config = cpl_parameter_get_string (p); - ForceNull(val_config) - if (val_config != NULL) + p = cpl_parameterlist_find(param_list, PACKAGE_RESOURCE ".config"); + if (cpl_parameter_get_default_flag(p)) { + val_config = cpl_parameter_get_string(p); + ForceNull(val_config) if (val_config != NULL) { - f_val_config = fileutils_file_exists (val_config); + f_val_config = fileutils_file_exists(val_config); } } else f_val_config = 1; - p = cpl_parameterlist_find (param_list, PACKAGE_RESOURCE ".recipe-dir"); - val_string_tmp = cpl_parameter_get_string (p); - if ((val_string_tmp != NULL) && (*val_string_tmp != '\0')) - { + p = cpl_parameterlist_find(param_list, PACKAGE_RESOURCE ".recipe-dir"); + val_string_tmp = cpl_parameter_get_string(p); + if ((val_string_tmp != NULL) && (*val_string_tmp != '\0')) { char **dir_str; - int nodirs, single; + int nodirs, single; /* extract the individual directories from command-line argument */ - val_recipe_dirs = cx_strsplit (val_string_tmp, ":", -1); + val_recipe_dirs = cx_strsplit(val_string_tmp, ":", -1); - nodirs = single = 0; /* get total no. of recipe dirs */ - for (dir_str = val_recipe_dirs; *dir_str != NULL; dir_str++) - { - single ++; /* total count of dirs */ - f_val_recipe_dirs = fileutils_directory_exists (*dir_str); - if (f_val_recipe_dirs != 0) - { /* one more existing directory */ - nodirs ++; + nodirs = single = 0; /* get total no. of recipe dirs */ + for (dir_str = val_recipe_dirs; *dir_str != NULL; dir_str++) { + single++; /* total count of dirs */ + f_val_recipe_dirs = fileutils_directory_exists(*dir_str); + if (f_val_recipe_dirs != 0) { /* one more existing directory */ + nodirs++; } } - if (nodirs < 1) - { - char blastr[16]; + if (nodirs < 1) { + char blastr[16]; if (single < 2) - (void) strcpy(blastr,"directory"); + (void)strcpy(blastr, "directory"); else - (void) strcpy(blastr,"directories"); - cpl_msg_warning (er_func, "Only non-existent %s, '%s', specified " - "as argument to '--recipe-dir'. " - "(Hint: use the '--params' option to check on how " - "EsoRex or the shell interpreted any environment " - "variables, etc.)", blastr,val_string_tmp); + (void)strcpy(blastr, "directories"); + cpl_msg_warning(er_func, + "Only non-existent %s, '%s', specified " + "as argument to '--recipe-dir'. " + "(Hint: use the '--params' option to check on how " + "EsoRex or the shell interpreted any environment " + "variables, etc.)", + blastr, val_string_tmp); } } - p = cpl_parameterlist_find (param_list, PACKAGE_RESOURCE ".recipe-config"); - if (cpl_parameter_get_default_flag (p)) - { - val_plugin_config = cpl_parameter_get_string (p); - ForceNull(val_plugin_config) - if (val_plugin_config != NULL) + p = cpl_parameterlist_find(param_list, PACKAGE_RESOURCE ".recipe-config"); + if (cpl_parameter_get_default_flag(p)) { + val_plugin_config = cpl_parameter_get_string(p); + ForceNull(val_plugin_config) if (val_plugin_config != NULL) { - f_val_plugin_config = fileutils_file_exists (val_plugin_config); + f_val_plugin_config = fileutils_file_exists(val_plugin_config); } } else f_val_plugin_config = 1; - p = cpl_parameterlist_find (param_list, PACKAGE_RESOURCE ".version"); - f_val_version = cpl_parameter_get_bool (p); + p = cpl_parameterlist_find(param_list, PACKAGE_RESOURCE ".version"); + f_val_version = cpl_parameter_get_bool(p); + + p = cpl_parameterlist_find(param_list, PACKAGE_RESOURCE ".recipes"); + f_val_plugins = cpl_parameter_get_bool(p); - p = cpl_parameterlist_find (param_list, PACKAGE_RESOURCE ".recipes"); - f_val_plugins = cpl_parameter_get_bool (p); + p = cpl_parameterlist_find(param_list, PACKAGE_RESOURCE ".help"); + f_val_help = cpl_parameter_get_bool(p); - p = cpl_parameterlist_find (param_list, PACKAGE_RESOURCE ".help"); - f_val_help = cpl_parameter_get_bool (p); + p = cpl_parameterlist_find(param_list, PACKAGE_RESOURCE ".params"); + f_val_params = cpl_parameter_get_bool(p); - p = cpl_parameterlist_find (param_list, PACKAGE_RESOURCE ".params"); - f_val_params = cpl_parameter_get_bool (p); - - p = cpl_parameterlist_find (param_list, PACKAGE_RESOURCE ".output-dir"); - val_output_dir = cpl_parameter_get_string (p); - ForceNull(val_output_dir) - if (val_output_dir != NULL) + p = cpl_parameterlist_find(param_list, PACKAGE_RESOURCE ".output-dir"); + val_output_dir = cpl_parameter_get_string(p); + ForceNull(val_output_dir) if (val_output_dir != NULL) { - f_val_output_dir = fileutils_directory_exists ( val_output_dir); + f_val_output_dir = fileutils_directory_exists(val_output_dir); } - p = cpl_parameterlist_find (param_list, PACKAGE_RESOURCE ".output-prefix"); - val_output_mask = cpl_parameter_get_string (p); - ForceNull(val_output_mask) - if (val_output_mask != NULL) + p = cpl_parameterlist_find(param_list, PACKAGE_RESOURCE ".output-prefix"); + val_output_mask = cpl_parameter_get_string(p); + ForceNull(val_output_mask) if (val_output_mask != NULL) { f_val_output_mask = 1; } - p = cpl_parameterlist_find (param_list, PACKAGE_RESOURCE ".suppress-prefix"); - f_val_noprefix = cpl_parameter_get_bool (p); + p = cpl_parameterlist_find(param_list, PACKAGE_RESOURCE ".suppress-prefix"); + f_val_noprefix = cpl_parameter_get_bool(p); - p = cpl_parameterlist_find (param_list, PACKAGE_RESOURCE ".link-dir"); - val_link_dir = cpl_parameter_get_string (p); - ForceNull(val_link_dir) - if (val_link_dir != NULL) + p = cpl_parameterlist_find(param_list, PACKAGE_RESOURCE ".link-dir"); + val_link_dir = cpl_parameter_get_string(p); + ForceNull(val_link_dir) if (val_link_dir != NULL) { - f_val_link_dir = fileutils_directory_exists (val_link_dir); + f_val_link_dir = fileutils_directory_exists(val_link_dir); } - p = cpl_parameterlist_find (param_list, PACKAGE_RESOURCE ".suppress-link"); - f_val_nolink = cpl_parameter_get_bool (p); + p = cpl_parameterlist_find(param_list, PACKAGE_RESOURCE ".suppress-link"); + f_val_nolink = cpl_parameter_get_bool(p); - p = cpl_parameterlist_find (param_list, PACKAGE_RESOURCE ".log-file"); - val_log_file = cpl_parameter_get_string (p); - ForceNull(val_log_file) - if (val_log_file != NULL) - { - f_val_log_file = 1; - } + p = cpl_parameterlist_find(param_list, PACKAGE_RESOURCE ".log-file"); + val_log_file = cpl_parameter_get_string(p); + ForceNull(val_log_file) if (val_log_file != NULL) { f_val_log_file = 1; } - p = cpl_parameterlist_find (param_list, PACKAGE_RESOURCE ".log-dir"); - val_log_dir = cpl_parameter_get_string (p); - ForceNull(val_log_dir) - if (val_log_dir != NULL) + p = cpl_parameterlist_find(param_list, PACKAGE_RESOURCE ".log-dir"); + val_log_dir = cpl_parameter_get_string(p); + ForceNull(val_log_dir) if (val_log_dir != NULL) { - f_val_log_dir = fileutils_directory_exists (val_log_dir); + f_val_log_dir = fileutils_directory_exists(val_log_dir); } - p = cpl_parameterlist_find (param_list, PACKAGE_RESOURCE ".paf-config"); - if (cpl_parameter_get_default_flag (p)) - { - val_paf_config = cpl_parameter_get_string (p); - ForceNull(val_paf_config) - if (val_paf_config != NULL) + p = cpl_parameterlist_find(param_list, PACKAGE_RESOURCE ".paf-config"); + if (cpl_parameter_get_default_flag(p)) { + val_paf_config = cpl_parameter_get_string(p); + ForceNull(val_paf_config) if (val_paf_config != NULL) { - f_val_paf_config = fileutils_file_exists (val_paf_config); + f_val_paf_config = fileutils_file_exists(val_paf_config); } } else f_val_paf_config = 1; - p = cpl_parameterlist_find (param_list, PACKAGE_RESOURCE ".products-sof"); - if (cpl_parameter_get_default_flag (p)) - { - val_products_sof = cpl_parameter_get_string (p); - ForceNull(val_products_sof ) - if (val_products_sof != NULL) + p = cpl_parameterlist_find(param_list, PACKAGE_RESOURCE ".products-sof"); + if (cpl_parameter_get_default_flag(p)) { + val_products_sof = cpl_parameter_get_string(p); + ForceNull(val_products_sof) if (val_products_sof != NULL) { - f_val_products_sof = fileutils_file_exists (val_products_sof ); + f_val_products_sof = fileutils_file_exists(val_products_sof); } } else @@ -1078,33 +1020,30 @@ /* esorex.caller.msg-level */ - msg_level = message_severity (param_list,2); - cpl_msg_set_level (msg_level); + msg_level = message_severity(param_list, 2); + cpl_msg_set_level(msg_level); /* esorex.caller.version */ - if ((f_continue != 0) && (f_val_version != 0)) - { + if ((f_continue != 0) && (f_val_version != 0)) { const char *cdescr; f_continue = 0; err = -99999; cdescr = cpl_get_description(CPL_DESCRIPTION_DEFAULT); - (void) printf("Libraries used: %s\n\n", cdescr); + (void)printf("Libraries used: %s\n\n", cdescr); - (void) printf("Copyright 2003-2018, European Southern Observatory.\n"); - (void) printf("Report bugs to .\n\n"); + (void)printf("Copyright 2003-2018, European Southern Observatory.\n"); + (void)printf("Report bugs to .\n\n"); } /* esorex.caller.help */ - if ((f_continue != 0) && (f_val_help != 0)) - { - if (*plugin_name == '\0') - { - er_help_display ("recipe", param_list, 0); + if ((f_continue != 0) && (f_val_help != 0)) { + if (*plugin_name == '\0') { + er_help_display("recipe", param_list, 0); } } @@ -1113,27 +1052,24 @@ * esorex.caller.params */ - if ((f_continue != 0) && (f_val_params != 0)) - { - (void) er_paramutils_print_list (param_list, "Caller Parameters"); + if ((f_continue != 0) && (f_val_params != 0)) { + (void)er_paramutils_print_list(param_list, "Caller Parameters"); } /* * esorex.caller.config */ - if ((f_continue != 0) && (f_val_config == 0)) - { - if (val_config == NULL) - { - cpl_msg_error (er_func, "'--config' was specified, but no argument " - "was given."); - } - else - { - cpl_msg_error (er_func, "'--config=%s' was specified, but the file " - "'%s' could not be found.", - val_config, val_config); + if ((f_continue != 0) && (f_val_config == 0)) { + if (val_config == NULL) { + cpl_msg_error(er_func, "'--config' was specified, but no argument " + "was given."); + } + else { + cpl_msg_error(er_func, + "'--config=%s' was specified, but the file " + "'%s' could not be found.", + val_config, val_config); } f_continue = 0; err = -1; @@ -1144,20 +1080,16 @@ * esorex.caller.recipe-config */ - if ((f_continue != 0) && (f_val_plugin_config == 0)) - { - if (val_plugin_config == NULL) - { - cpl_msg_error (er_func, - "'--recipe-config' was specified, but no " - "argument given."); - } - else - { - cpl_msg_error (er_func, - "'--recipe-config=%s' was specified, but the file " - "'%s' could not be found.", val_plugin_config, - val_plugin_config); + if ((f_continue != 0) && (f_val_plugin_config == 0)) { + if (val_plugin_config == NULL) { + cpl_msg_error(er_func, "'--recipe-config' was specified, but no " + "argument given."); + } + else { + cpl_msg_error(er_func, + "'--recipe-config=%s' was specified, but the file " + "'%s' could not be found.", + val_plugin_config, val_plugin_config); } f_continue = 0; err = -1; @@ -1168,21 +1100,20 @@ * esorex.caller.log-dir */ - if ((f_continue != 0) && (f_val_log_dir == 0)) - { - if (val_log_dir == NULL) - { - cpl_msg_error (er_func, "'--log-dir' is a mandatory option, but " - "no argument was given. Check that there is only " - "an equals sign (\"=\") between the '--log-dir' " - "and the directory path, and that all environment " - "variables are resolved."); - } - else - { - cpl_msg_error (er_func, "'--log-dir=%s' specified, but '%s' is " - "not a valid directory.", val_log_dir, - val_log_dir); + if ((f_continue != 0) && (f_val_log_dir == 0)) { + if (val_log_dir == NULL) { + cpl_msg_error(er_func, + "'--log-dir' is a mandatory option, but " + "no argument was given. Check that there is only " + "an equals sign (\"=\") between the '--log-dir' " + "and the directory path, and that all environment " + "variables are resolved."); + } + else { + cpl_msg_error(er_func, + "'--log-dir=%s' specified, but '%s' is " + "not a valid directory.", + val_log_dir, val_log_dir); } f_continue = 0; err = -1; @@ -1193,16 +1124,15 @@ * esorex.caller.log-file */ - if ((f_continue != 0) && (f_val_log_file == 0)) - { + if ((f_continue != 0) && (f_val_log_file == 0)) { err = -99999; - if (val_log_file == NULL) - { - cpl_msg_error (er_func, "'--log-file' is a mandatory option, but " - "no argument was given. Check that there is only " - "an equals sign (\"=\") between the '--log-file' " - "and the file path, and that all environment " - "variables are resolved."); + if (val_log_file == NULL) { + cpl_msg_error(er_func, + "'--log-file' is a mandatory option, but " + "no argument was given. Check that there is only " + "an equals sign (\"=\") between the '--log-file' " + "and the file path, and that all environment " + "variables are resolved."); f_continue = 0; err = -1; goto clean_up; @@ -1221,21 +1151,19 @@ * esorex.caller.recipes */ - if ((f_continue != 0) && (f_val_plugins != 0)) - { - plugin_list = er_stringarray_new (); + if ((f_continue != 0) && (f_val_plugins != 0)) { + plugin_list = er_stringarray_new(); pllib_list = NULL; - pllib_list = er_pluginlist_create_list (val_recipe_dirs); + pllib_list = er_pluginlist_create_list(val_recipe_dirs); - er_pluginlist_create_cache (pllib_list, plugin_list); - er_pluginlist_print_list (pllib_list); + er_pluginlist_create_cache(pllib_list, plugin_list); + er_pluginlist_print_list(pllib_list); - er_stringarray_delete (plugin_list); - er_stringarray_delete (pllib_list); + er_stringarray_delete(plugin_list); + er_stringarray_delete(pllib_list); err = -99999; f_continue = 0; - } /* @@ -1245,41 +1173,38 @@ * esorex.caller.output-rbs */ - if ((f_continue != 0) && (f_val_help == 0)) - { - if (f_val_output_dir == 0) - { - if ((val_output_dir != NULL) && (strlen (val_output_dir) > 0)) - { - cpl_msg_error (er_func, "The argument to '--output-dir' [%s] " - "is not a valid directory", val_output_dir); - } - else - { - cpl_msg_error (er_func, "No destination given for program " - "output (use the option '--output-dir')."); + if ((f_continue != 0) && (f_val_help == 0)) { + if (f_val_output_dir == 0) { + if ((val_output_dir != NULL) && (strlen(val_output_dir) > 0)) { + cpl_msg_error(er_func, + "The argument to '--output-dir' [%s] " + "is not a valid directory", + val_output_dir); + } + else { + cpl_msg_error(er_func, + "No destination given for program " + "output (use the option '--output-dir')."); } f_continue = 0; err = -1; goto clean_up; } - if ((f_val_output_mask == 0) && (f_val_noprefix == 0)) - { - cpl_msg_warning (er_func, - "Output file prefixes have been disabled using " - "the '--suppress-prefix' option."); - cpl_msg_error (er_func, - "However, no valid prefix has been given using the " - "'--output-prefix' option."); - cpl_msg_error (er_func, - "Use '--help' (without specifying any recipe) " - "for help on these command options"); + if ((f_val_output_mask == 0) && (f_val_noprefix == 0)) { + cpl_msg_warning(er_func, + "Output file prefixes have been disabled using " + "the '--suppress-prefix' option."); + cpl_msg_error(er_func, + "However, no valid prefix has been given using the " + "'--output-prefix' option."); + cpl_msg_error(er_func, + "Use '--help' (without specifying any recipe) " + "for help on these command options"); f_continue = 0; err = -1; goto clean_up; } - } /* @@ -1287,18 +1212,16 @@ * esorex.caller.suppress-link */ - if ((f_continue != 0) && (f_val_help == 0) && (f_val_nolink == 0)) - { - if (f_val_link_dir == 0) - { - if (val_link_dir != NULL) - { - cpl_msg_error (er_func, - "The argument to '--link-dir' [%s] is not a " - "valid directory", val_link_dir); + if ((f_continue != 0) && (f_val_help == 0) && (f_val_nolink == 0)) { + if (f_val_link_dir == 0) { + if (val_link_dir != NULL) { + cpl_msg_error(er_func, + "The argument to '--link-dir' [%s] is not a " + "valid directory", + val_link_dir); } - cpl_msg_error (er_func, - "Non-valid directory given for symbolic links."); + cpl_msg_error(er_func, + "Non-valid directory given for symbolic links."); f_continue = 0; err = -1; goto clean_up; @@ -1309,37 +1232,34 @@ * esorex.caller.create-config */ - if ((f_continue != 0) && (f_val_create != 0)) - { - if (*plugin_name == '\0') - { /* no plugin (recipe) given */ + if ((f_continue != 0) && (f_val_create != 0)) { + if (*plugin_name == '\0') { /* no plugin (recipe) given */ cpl_parameter *param; - size_t k; + size_t k; char *saved_name; /* Deactivate the "create-config" parameter while we do this */ - param = cpl_parameterlist_find (param_list, - PACKAGE_RESOURCE ".create-config"); + param = cpl_parameterlist_find(param_list, + PACKAGE_RESOURCE ".create-config"); - if (f_val_create == 11) /* Generate the configuration file */ + if (f_val_create == 11) /* Generate the configuration file */ { - k = strlen(val_create)+1; + k = strlen(val_create) + 1; saved_name = malloc(k); - (void) strcpy(saved_name,val_create); - cpl_parameter_set_string (param, "FALSE"); - er_help_create_config (f_val_create,plugin_name, saved_name, - param_list, param_list); + (void)strcpy(saved_name, val_create); + cpl_parameter_set_string(param, "FALSE"); + er_help_create_config(f_val_create, plugin_name, saved_name, + param_list, param_list); } - else - { + else { saved_name = malloc(8); - (void) strcpy(saved_name,"TRUE"); - cpl_parameter_set_string (param, "FALSE"); - er_help_create_config (f_val_create,PACKAGE, "", - param_list, param_list); + (void)strcpy(saved_name, "TRUE"); + cpl_parameter_set_string(param, "FALSE"); + er_help_create_config(f_val_create, PACKAGE, "", param_list, + param_list); } - cpl_parameter_set_string (param, saved_name); + cpl_parameter_set_string(param, saved_name); free(saved_name); } } @@ -1348,21 +1268,20 @@ * esorex.caller.paf-config */ - if ((f_continue != 0) && (f_val_paf_config == 0)) - { - if (val_paf_config == NULL) - { - cpl_msg_error (er_func, "'--paf-config' was specified, but no " - "argument given. Check that there is only an " - "equals sign (\"=\") between the '--paf-config' " - "and the directory path, and that all environment " - "variables are resolved."); - } - else - { - cpl_msg_error (er_func, "'--paf-config=%s' specified, but '%s' " - "could not be opened for reading.", val_paf_config, - val_paf_config); + if ((f_continue != 0) && (f_val_paf_config == 0)) { + if (val_paf_config == NULL) { + cpl_msg_error(er_func, + "'--paf-config' was specified, but no " + "argument given. Check that there is only an " + "equals sign (\"=\") between the '--paf-config' " + "and the directory path, and that all environment " + "variables are resolved."); + } + else { + cpl_msg_error(er_func, + "'--paf-config=%s' specified, but '%s' " + "could not be opened for reading.", + val_paf_config, val_paf_config); } f_continue = 0; err = -1; @@ -1373,15 +1292,14 @@ * esorex.caller.products-sof */ - if ((f_continue != 0) && (f_val_products_sof == 0)) - { - if (val_products_sof == NULL) - { - cpl_msg_error (er_func, "'--products-sof' was specified, but no " - "argument given. Check that there is only an " - "equals sign (\"=\") between the '--products-sof' " - "and the directory path, and that all environment " - "variables are resolved."); + if ((f_continue != 0) && (f_val_products_sof == 0)) { + if (val_products_sof == NULL) { + cpl_msg_error(er_func, + "'--products-sof' was specified, but no " + "argument given. Check that there is only an " + "equals sign (\"=\") between the '--products-sof' " + "and the directory path, and that all environment " + "variables are resolved."); f_continue = 0; err = -1; goto clean_up; @@ -1392,9 +1310,11 @@ * Clean-up */ - clean_up: - if (val_recipe_dirs != NULL) cx_strfreev (val_recipe_dirs); - if (val_plugin_dir != NULL) cpl_free (val_plugin_dir); +clean_up: + if (val_recipe_dirs != NULL) + cx_strfreev(val_recipe_dirs); + if (val_plugin_dir != NULL) + cpl_free(val_plugin_dir); return err; @@ -1413,9 +1333,9 @@ * @param argc Count of commandline arguments * @param argv Handle to commandline aguments * - * @retval plugin_name Name of recipe specified on command line - * @retval set_of_frames_filenames Array of SOF filenames specified on - * commandline + * @param plugin_name Name of recipe specified on command line + * @param set_of_frames_filenames Array of SOF filenames specified on + * commandline * * @returns 0 if successfull, !=0 otherwise */ @@ -1438,36 +1358,39 @@ so we discard the error code! */ /* Parse the global configuration file */ - err2 = params_parse_config_file (caller_parameter_list, global_conf_file); - if (err2 == -5) return err; + err2 = params_parse_config_file(caller_parameter_list, global_conf_file); + if (err2 == -5) + return err; - er_paramutils_tilde_convert (caller_parameter_list); + er_paramutils_tilde_convert(caller_parameter_list); /* Parse the local configuration file */ - err2 = params_parse_config_file (caller_parameter_list, local_conf_file); - if (err2 == -5) return err; + err2 = params_parse_config_file(caller_parameter_list, local_conf_file); + if (err2 == -5) + return err; - er_paramutils_tilde_convert (caller_parameter_list); + er_paramutils_tilde_convert(caller_parameter_list); /* Parse any enviroment variables */ - err2 = params_parse_config_environment (caller_parameter_list); - if (err2 != 0) return err; + err2 = params_parse_config_environment(caller_parameter_list); + if (err2 != 0) + return err; - er_paramutils_tilde_convert (caller_parameter_list); + er_paramutils_tilde_convert(caller_parameter_list); /* Now parse the command line variables */ - err = params_parse_config_commandline (caller_parameter_list, - plugin_name, - set_of_frames_filenames, - argc, argv, 1); + err = + params_parse_config_commandline(caller_parameter_list, plugin_name, + set_of_frames_filenames, argc, argv, 1); /* Check the error code from parsing the command line */ - if (err != 0) return err; + if (err != 0) + return err; - er_paramutils_tilde_convert (caller_parameter_list); + er_paramutils_tilde_convert(caller_parameter_list); - params_parse_config_postprocess (caller_parameter_list); - er_paramutils_tilde_convert (caller_parameter_list); + params_parse_config_postprocess(caller_parameter_list); + er_paramutils_tilde_convert(caller_parameter_list); /* @@ -1475,10 +1398,10 @@ and return a flag indicating whether or not we should run the plugin */ - err = params_handle_parameters (plugin_name, caller_parameter_list); + err = params_handle_parameters(plugin_name, caller_parameter_list); return err; -} /* End of params_process_configuration() */ +} /* End of params_process_configuration() */ /**@}*/ diff -Nru esorex-3.13.5+ds/src/er_params.h esorex-3.13.6+ds/src/er_params.h --- esorex-3.13.5+ds/src/er_params.h 2021-06-02 15:06:13.000000000 +0000 +++ esorex-3.13.6+ds/src/er_params.h 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 European Southern Observatory * * 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 @@ -29,16 +29,23 @@ extern int params_parse_config_environment(cpl_parameterlist *); -extern int params_parse_config_commandline(cpl_parameterlist *, char *, - er_stringarray_t *, int, - char **argv, int); +extern int params_parse_config_commandline(cpl_parameterlist *, + char *, + er_stringarray_t *, + int, + char **argv, + int); extern void params_parse_config_postprocess(cpl_parameterlist *); extern int params_handle_parameters(char *, cpl_parameterlist *); -extern int params_process_configuration(cpl_parameterlist *, char *, - char *, int, char **, char *, +extern int params_process_configuration(cpl_parameterlist *, + char *, + char *, + int, + char **, + char *, er_stringarray_t *); CPL_END_DECLS diff -Nru esorex-3.13.5+ds/src/er_paramutils.c esorex-3.13.6+ds/src/er_paramutils.c --- esorex-3.13.5+ds/src/er_paramutils.c 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/er_paramutils.c 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 European Southern Observatory * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include "config.h" #endif #include @@ -34,8 +34,8 @@ #include "er_paramutils.h" #include "er_stringutils.h" -#define SIZE_X 200 -#define MAXSTR MAXSTRLENCONF - 4 +#define SIZE_X 200 +#define MAXSTR MAXSTRLENCONF - 4 /** * @defgroup er_params_utils EsoRex Parameter Utility Functions @@ -61,69 +61,61 @@ */ /**********************************************************************/ -void er_paramutils_tilde_convert (cpl_parameterlist * param_list) +void +er_paramutils_tilde_convert(cpl_parameterlist *param_list) { cpl_parameter *p = NULL; cpl_type ptype; - int f_is_present = 0; /* FALSE */ + int f_is_present = 0; /* FALSE */ const char *old_str = NULL; - p = cpl_parameterlist_get_first (param_list); + p = cpl_parameterlist_get_first(param_list); - while (p != NULL) - { - f_is_present = cpl_parameter_get_default_flag (p); + while (p != NULL) { + f_is_present = cpl_parameter_get_default_flag(p); - if (f_is_present) - { - ptype = cpl_parameter_get_type (p); - if (ptype == CPL_TYPE_STRING) - { - old_str = cpl_parameter_get_string (p); - if (*old_str == '~') - { - char *cpp; - wordexp_t result; + if (f_is_present) { + ptype = cpl_parameter_get_type(p); + if (ptype == CPL_TYPE_STRING) { + old_str = cpl_parameter_get_string(p); + if (*old_str == '~') { + char *cpp; + wordexp_t result; /* * use C library (glibc) routine wordexp() to expand * ~/ or ~name/ */ - if (wordexp(old_str,&result,0) != 0) - { - cpl_msg_error (er_func, - "Expansion of ~ (tilde) failed..."); + if (wordexp(old_str, &result, 0) != 0) { + cpl_msg_error(er_func, + "Expansion of ~ (tilde) failed..."); return; } /* use 1st and only result word */ cpp = *result.we_wordv; - if (cpp == NULL) - { - cpl_msg_error (er_func, "Env. variable HOME not set"); + if (cpp == NULL) { + cpl_msg_error(er_func, "Env. variable HOME not set"); return; } - cpl_parameter_set_string (p, cpp); + cpl_parameter_set_string(p, cpp); wordfree(&result); } } } /* Get the next parameter in the list */ - p = cpl_parameterlist_get_next (param_list); - } /* End of loop through all parameters in the list */ - + p = cpl_parameterlist_get_next(param_list); + } /* End of loop through all parameters in the list */ } - - /**********************************************************************/ /** * @brief Neatly print a parameter and its description. @@ -145,7 +137,8 @@ /**********************************************************************/ void -er_paramutils_print_key_desc(const char *flag_prefix, const char *keyword, +er_paramutils_print_key_desc(const char *flag_prefix, + const char *keyword, const char *description) { int i, ii, tab = COMMENT_TAB_POSITION; @@ -153,37 +146,41 @@ char *mystr, *ptr, *mykeyword; - mystr = (char *) cpl_malloc((size_t) SIZE_X); - if (mystr == NULL) - { - cpl_msg_warning (er_func, "Could not allocate initial %d bytes " - "for help description", SIZE_X); + mystr = (char *)cpl_malloc((size_t)SIZE_X); + if (mystr == NULL) { + cpl_msg_warning(er_func, + "Could not allocate initial %d bytes " + "for help description", + SIZE_X); return; } /* store the indent, optional flag ("--") and keyword */ - i = (int) strlen(flag_prefix); - ii = (int) strlen(keyword); - if ((i+ii) > (SIZE_X-4)) - { - cpl_msg_warning (er_func, "Size of keyword (= %d) too large - will " - "be truncated...", ii); - mykeyword = (char *) cpl_malloc((size_t) SIZE_X); - (void) strncpy(mykeyword,keyword,(SIZE_X-6)); - mykeyword[SIZE_X-6] = '\0'; + i = (int)strlen(flag_prefix); + ii = (int)strlen(keyword); + if ((i + ii) > (SIZE_X - 4)) { + cpl_msg_warning(er_func, + "Size of keyword (= %d) too large - will " + "be truncated...", + ii); + mykeyword = (char *)cpl_malloc((size_t)SIZE_X); + (void)strncpy(mykeyword, keyword, (SIZE_X - 6)); + mykeyword[SIZE_X - 6] = '\0'; } else - mykeyword = (char *) keyword; + mykeyword = (char *)keyword; - i = sprintf(mystr," %s%s",flag_prefix,mykeyword); - if (tab < i) tab = i + 2; /* if keyword quite long, move the tab */ + i = sprintf(mystr, " %s%s", flag_prefix, mykeyword); + if (tab < i) + tab = i + 2; /* if keyword quite long, move the tab */ /* pad out to the tab-point, then append ": " */ ptr = mystr + i; - for (ii = i; ii < tab; ii++) *ptr++ = ' '; + for (ii = i; ii < tab; ii++) + *ptr++ = ' '; *ptr++ = ':'; *ptr++ = ' '; *ptr = '\0'; @@ -191,21 +188,20 @@ /* append description */ - i = tab + (int) strlen(description) + 2; - if (i > SIZE_X) - { - er_enlarge("paramutils_print_key_desc",&mystr,i); + i = tab + (int)strlen(description) + 2; + if (i > SIZE_X) { + er_enlarge("paramutils_print_key_desc", &mystr, i); } - (void) strcpy(mystr+tab, description); /* append full description */ + (void)strcpy(mystr + tab, description); /* append full description */ /* finally, print the nicely wrapped string */ - (void) printf("%s\n", - er_strutils_split(mystr, tab, er_strutils_termwidth())); + (void)printf("%s\n", + er_strutils_split(mystr, tab, er_strutils_termwidth())); cpl_free(mystr); -} +} /**********************************************************************/ @@ -238,60 +234,55 @@ int offset, n, m, indx, lp; static int no_sources = -1; - static char *ptr, *p_sources[MAX_SRC]; - static char p_names[MAX_SRC*PAR_LEN]; - - size_t slen; - + static char *ptr, *p_sources[MAX_SRC]; + static char p_names[MAX_SRC * PAR_LEN]; + size_t slen; /* write parameter + source into save buffer */ - if (flag == 1) - { - if (no_sources < 0) /* first time */ + if (flag == 1) { + if (no_sources < 0) /* first time */ { no_sources = 1; indx = 0; offset = 0; } - else - { /* loop through existing list */ + else { /* loop through existing list */ indx = -1; - lp = PAR_LEN-1; - for (n=0; n 80) - { - cpl_msg_error (er_func, "Size of prefix (= %d), keyword (= %d) too " - "large", i, ii); - cpl_error_set (er_func, CPL_ERROR_ILLEGAL_INPUT); + i = (int)strlen(flag_prefix); + ii = (int)strlen(keyword); + if ((i + ii) > 80) { + cpl_msg_error(er_func, + "Size of prefix (= %d), keyword (= %d) too " + "large", + i, ii); + cpl_error_set(er_func, CPL_ERROR_ILLEGAL_INPUT); return; } - i = sprintf (spc, " %s%s", flag_prefix, keyword); + i = sprintf(spc, " %s%s", flag_prefix, keyword); /* if the keyword is quite long, move the tab */ - if (tab < i) tab = i + 2; + if (tab < i) + tab = i + 2; /* for the real string, pad out to the tab-point */ - memset ((void *) str, 32,(size_t) tab); /* int 32 = ' ' */ + memset((void *)str, 32, (size_t)tab); /* int 32 = ' ' */ str[tab] = '\0'; /* build up string with the description */ - (void) strcat (str, " (source = "); - i = (int) strlen(description); - if (i > 900) - { - ii = (int) strlen(str); + (void)strcat(str, " (source = "); + i = (int)strlen(description); + if (i > 900) { + ii = (int)strlen(str); /* truncate description */ - (void) sprintf (&str[ii], "%900.900s", description); + (void)sprintf(&str[ii], "%900.900s", description); } else - (void) strcat (str, description); - (void) strcat (str, ")"); + (void)strcat(str, description); + (void)strcat(str, ")"); /* finally, print the nicely wrapped string */ - (void) printf("%s\n", - er_strutils_split(str, (tab + 2), er_strutils_termwidth())); - -} - + (void)printf("%s\n", + er_strutils_split(str, (tab + 2), er_strutils_termwidth())); +} /**********************************************************************/ @@ -420,7 +406,7 @@ /**********************************************************************/ int -er_paramutils_print_list (cpl_parameterlist *param_list, const char *header) +er_paramutils_print_list(cpl_parameterlist *param_list, const char *header) { cpl_parameter *p; @@ -440,54 +426,53 @@ /* Check that the inputs are valid */ - if (param_list == NULL) return -1; - if (header == NULL) return -1; + if (param_list == NULL) + return -1; + if (header == NULL) + return -1; /* Determine the message level (for printing auxiliary information) */ - msg_level = cpl_msg_get_level (); + msg_level = cpl_msg_get_level(); /* Print some header text */ - (void) printf ("%s :\n\n", header); + (void)printf("%s :\n\n", header); /* Get the first parameter from the list */ - p = cpl_parameterlist_get_first (param_list); + p = cpl_parameterlist_get_first(param_list); /* Loop through all the parameters in the list */ - while (p != NULL) - { /* Get and print the keyword */ - tmp_cmdl_keywd = cpl_parameter_get_alias (p, CPL_PARAMETER_MODE_CLI); + while (p != NULL) { /* Get and print the keyword */ + tmp_cmdl_keywd = cpl_parameter_get_alias(p, CPL_PARAMETER_MODE_CLI); /* Determine the type of the parameter */ - ptype = cpl_parameter_get_type (p); + ptype = cpl_parameter_get_type(p); /* Depending on the parameter type, print the parameter appropriately */ - switch (ptype) - { + switch (ptype) { case CPL_TYPE_BOOL: - (void) sprintf (tmp_cmdl_descr, "%s", - cpl_parameter_get_bool (p) ? "TRUE" : "FALSE"); + (void)sprintf(tmp_cmdl_descr, "%s", + cpl_parameter_get_bool(p) ? "TRUE" : "FALSE"); break; case CPL_TYPE_INT: - tmp_int = cpl_parameter_get_int (p); - (void) sprintf (tmp_cmdl_descr, "%d", tmp_int); + tmp_int = cpl_parameter_get_int(p); + (void)sprintf(tmp_cmdl_descr, "%d", tmp_int); break; case CPL_TYPE_DOUBLE: - tmp_double = cpl_parameter_get_double (p); - (void) sprintf (tmp_cmdl_descr, "%s", - er_strutils_dblstr(tmp_double)); + tmp_double = cpl_parameter_get_double(p); + (void)sprintf(tmp_cmdl_descr, "%s", + er_strutils_dblstr(tmp_double)); break; case CPL_TYPE_STRING: - tmp_string = cpl_parameter_get_string (p); - i = (int) strlen(tmp_string); + tmp_string = cpl_parameter_get_string(p); + i = (int)strlen(tmp_string); if (i > MAXSTR) - (void) snprintf (tmp_cmdl_descr, MAXSTR, "%s", - tmp_string); + (void)snprintf(tmp_cmdl_descr, MAXSTR, "%s", tmp_string); else - (void) sprintf (tmp_cmdl_descr, "%s", - tmp_string ? tmp_string : "-"); + (void)sprintf(tmp_cmdl_descr, "%s", + tmp_string ? tmp_string : "-"); break; default: @@ -495,34 +480,32 @@ } /* Actually print the parameter pair */ - er_paramutils_print_key_desc ("", tmp_cmdl_keywd, tmp_cmdl_descr); + er_paramutils_print_key_desc("", tmp_cmdl_keywd, tmp_cmdl_descr); /* * If we are set to DEBUG level, then print the source * of the value too */ - if (msg_level == CPL_MSG_DEBUG) - { - char *myptr; + if (msg_level == CPL_MSG_DEBUG) { + char *myptr; - i = er_manage_sources(2,cpl_parameter_get_name (p),&myptr); + i = er_manage_sources(2, cpl_parameter_get_name(p), &myptr); if (i == 0) - er_paramutils_print_aux_info ("", tmp_cmdl_keywd, myptr); + er_paramutils_print_aux_info("", tmp_cmdl_keywd, myptr); else - er_paramutils_print_aux_info ("", tmp_cmdl_keywd, - "ambiguous..."); + er_paramutils_print_aux_info("", tmp_cmdl_keywd, + "ambiguous..."); } /* Determine the next parameter in the list */ - p = cpl_parameterlist_get_next (param_list); + p = cpl_parameterlist_get_next(param_list); } - printf ("\n"); + printf("\n"); return 0; -} /* End of er_paramutils_print_list() */ - +} /* End of er_paramutils_print_list() */ /**********************************************************************/ @@ -542,14 +525,15 @@ /**********************************************************************/ int -paramutils_set_from_string(cpl_parameter *p, const char *value, +paramutils_set_from_string(cpl_parameter *p, + const char *value, const char *source) { cpl_parameter_class pclass; cpl_type ptype; - int f_found = 0; /* FALSE */ + int f_found = 0; /* FALSE */ int scanlen = 0, tmp_int = 0, i = 0; double tmp_double = 0.0; @@ -557,22 +541,21 @@ char **pptr; - if (p == NULL) - { - cpl_error_set (er_func, CPL_ERROR_NULL_INPUT); + if (p == NULL) { + cpl_error_set(er_func, CPL_ERROR_NULL_INPUT); return 1; } /* save for later where the value came from */ - pptr = (char **) &source; - er_manage_sources(1,cpl_parameter_get_name(p),pptr); + pptr = (char **)&source; + er_manage_sources(1, cpl_parameter_get_name(p), pptr); - cpl_parameter_set_default_flag (p, TRUE); + cpl_parameter_set_default_flag(p, TRUE); - pclass = cpl_parameter_get_class (p); - ptype = cpl_parameter_get_type (p); + pclass = cpl_parameter_get_class(p); + ptype = cpl_parameter_get_type(p); /* * ????? - This is a mess. The following switch blocks should be a @@ -581,57 +564,48 @@ * do the actual processing. */ - switch (pclass) - { + switch (pclass) { case CPL_PARAMETER_CLASS_VALUE: - switch (ptype) - { + switch (ptype) { case CPL_TYPE_BOOL: - if ((strcmp (value, "TRUE") == 0) || - (strcmp (value, "true") == 0)) - { - cpl_parameter_set_bool (p, TRUE); - } - else if ((strcmp (value, "FALSE") == 0) || - (strcmp (value, "false") == 0)) - { - cpl_parameter_set_bool (p, FALSE); - } - else - { - cpl_error_set (er_func, CPL_ERROR_TYPE_MISMATCH); + if ((strcmp(value, "TRUE") == 0) || + (strcmp(value, "true") == 0)) { + cpl_parameter_set_bool(p, TRUE); + } + else if ((strcmp(value, "FALSE") == 0) || + (strcmp(value, "false") == 0)) { + cpl_parameter_set_bool(p, FALSE); + } + else { + cpl_error_set(er_func, CPL_ERROR_TYPE_MISMATCH); return -1; } break; case CPL_TYPE_INT: - scanlen = sscanf (value, " %d ", &tmp_int); - if (scanlen == 1) - { - cpl_parameter_set_int (p, tmp_int); - } - else - { - cpl_error_set (er_func, CPL_ERROR_TYPE_MISMATCH); + scanlen = sscanf(value, " %d ", &tmp_int); + if (scanlen == 1) { + cpl_parameter_set_int(p, tmp_int); + } + else { + cpl_error_set(er_func, CPL_ERROR_TYPE_MISMATCH); return -1; } break; case CPL_TYPE_DOUBLE: - scanlen = sscanf (value, " %le ", &tmp_double); - if (scanlen == 1) - { - cpl_parameter_set_double (p, tmp_double); - } - else - { - cpl_error_set (er_func, CPL_ERROR_TYPE_MISMATCH); + scanlen = sscanf(value, " %le ", &tmp_double); + if (scanlen == 1) { + cpl_parameter_set_double(p, tmp_double); + } + else { + cpl_error_set(er_func, CPL_ERROR_TYPE_MISMATCH); return -1; } break; case CPL_TYPE_STRING: - cpl_parameter_set_string (p, value); + cpl_parameter_set_string(p, value); break; default: @@ -641,196 +615,187 @@ break; - case CPL_PARAMETER_CLASS_RANGE: + case CPL_PARAMETER_CLASS_RANGE: - switch (ptype) - { - case CPL_TYPE_BOOL: - break; - - case CPL_TYPE_INT: - scanlen = sscanf (value, " %d ", &tmp_int); - if (scanlen == 1) - { - if ((tmp_int <= cpl_parameter_get_range_max_int (p)) && - (tmp_int >= cpl_parameter_get_range_min_int (p))) - { - cpl_parameter_set_int (p, tmp_int); - } - else - { - cpl_error_set(er_func, CPL_ERROR_ILLEGAL_INPUT); - cpl_msg_error(er_func, - "Specified 'int' value (%d) for the parameter " - "'%s' was outside the permitted range %d to %d\n", - tmp_int, - cpl_parameter_get_alias(p, CPL_PARAMETER_MODE_CLI), - cpl_parameter_get_range_min_int(p), - cpl_parameter_get_range_max_int(p)); - return -1; - } - } - else - { - cpl_error_set (er_func, CPL_ERROR_TYPE_MISMATCH); + switch (ptype) { + case CPL_TYPE_BOOL: + break; + + case CPL_TYPE_INT: + scanlen = sscanf(value, " %d ", &tmp_int); + if (scanlen == 1) { + if ((tmp_int <= cpl_parameter_get_range_max_int(p)) && + (tmp_int >= cpl_parameter_get_range_min_int(p))) { + cpl_parameter_set_int(p, tmp_int); + } + else { + cpl_error_set(er_func, CPL_ERROR_ILLEGAL_INPUT); + cpl_msg_error( + er_func, + "Specified 'int' value (%d) for the parameter " + "'%s' was outside the permitted range %d to " + "%d\n", + tmp_int, + cpl_parameter_get_alias(p, + CPL_PARAMETER_MODE_CLI), + cpl_parameter_get_range_min_int(p), + cpl_parameter_get_range_max_int(p)); + return -1; + } + } + else { + cpl_error_set(er_func, CPL_ERROR_TYPE_MISMATCH); + return -1; + } + break; + + case CPL_TYPE_DOUBLE: + scanlen = sscanf(value, " %le ", &tmp_double); + if (scanlen == 1) { + if ((tmp_double <= + cpl_parameter_get_range_max_double(p)) && + (tmp_double >= + cpl_parameter_get_range_min_double(p))) { + cpl_parameter_set_double(p, tmp_double); + } + else { + char *tmp; + + + cpl_error_set(er_func, CPL_ERROR_ILLEGAL_INPUT); + + + tmp = (char *)cpl_malloc((size_t)1024); + if (tmp == NULL) { + cpl_msg_error( + er_func, + "Could not allocate 1024 bytes for tmp"); return -1; } - break; - - case CPL_TYPE_DOUBLE: - scanlen = sscanf (value, " %le ", &tmp_double); - if (scanlen == 1) - { - if ((tmp_double <= cpl_parameter_get_range_max_double (p)) && - (tmp_double >= cpl_parameter_get_range_min_double (p))) - { - cpl_parameter_set_double (p, tmp_double); - } - else - { - char *tmp; - - - cpl_error_set (er_func, CPL_ERROR_ILLEGAL_INPUT); - - - tmp = (char *) cpl_malloc((size_t) 1024); - if ( tmp == NULL) - { - cpl_msg_error (er_func, "Could not allocate 1024 bytes for tmp"); - return -1; - } - /* + /* * formulate the error message in steps... * er_strutils_dblstr() uses an internal static buffer! */ - (void) strcpy (tmp, "Specified 'double' value ("); - (void) strcat (tmp, er_strutils_dblstr (tmp_double)); - (void) strcat (tmp, ") for the parameter '"); - (void) strcat (tmp, cpl_parameter_get_alias (p, CPL_PARAMETER_MODE_CLI)); - (void) strcat (tmp, "' was outside the permitted range "); - (void) strcat (tmp, er_strutils_dblstr (cpl_parameter_get_range_min_double (p))); - (void) strcat (tmp, " to "); - (void) strcat (tmp, er_strutils_dblstr (cpl_parameter_get_range_max_double (p))); - (void) strcat (tmp, ".\n"); - cpl_msg_error (er_func, "%s", tmp); - - cpl_free(tmp); - return -1; - } - } - else - { - cpl_error_set (er_func, CPL_ERROR_TYPE_MISMATCH); - return -1; - } - break; - - case CPL_TYPE_STRING: - break; - - default: - break; + (void)strcpy(tmp, "Specified 'double' value ("); + (void)strcat(tmp, er_strutils_dblstr(tmp_double)); + (void)strcat(tmp, ") for the parameter '"); + (void)strcat(tmp, cpl_parameter_get_alias( + p, CPL_PARAMETER_MODE_CLI)); + (void)strcat(tmp, + "' was outside the permitted range "); + (void)strcat(tmp, + er_strutils_dblstr( + cpl_parameter_get_range_min_double( + p))); + (void)strcat(tmp, " to "); + (void)strcat(tmp, + er_strutils_dblstr( + cpl_parameter_get_range_max_double( + p))); + (void)strcat(tmp, ".\n"); + cpl_msg_error(er_func, "%s", tmp); + + cpl_free(tmp); + return -1; + } } + else { + cpl_error_set(er_func, CPL_ERROR_TYPE_MISMATCH); + return -1; + } + break; + case CPL_TYPE_STRING: break; + default: + break; + } + + break; + + + case CPL_PARAMETER_CLASS_ENUM: - case CPL_PARAMETER_CLASS_ENUM: - - switch (ptype) - { - - case CPL_TYPE_BOOL: - break; - - case CPL_TYPE_INT: - scanlen = sscanf (value, " %d ", &tmp_int); - if (scanlen == 1) - { - for (i=0; i +#include #endif #include @@ -59,8 +59,8 @@ #define SIZE_C 1024 #define SIZE_D 1024 -#define Xspace(x) (x == ' ') || (x == '\t') || (x == '\n') -#define Xnospace(x) (x != ' ') && (x != '\t') && (x != '\n') +#define Xspace(x) (x == ' ') || (x == '\t') || (x == '\n') +#define Xnospace(x) (x != ' ') && (x != '\t') && (x != '\n') /** @@ -73,7 +73,6 @@ /**@{*/ - /**********************************************************************/ /** * @brief Sets the message severity level for the terminal @@ -88,7 +87,8 @@ */ /**********************************************************************/ -cpl_msg_severity message_severity (cpl_parameterlist *param_list, int flag) +cpl_msg_severity +message_severity(cpl_parameterlist *param_list, int flag) { const char *msg_level_value = NULL; @@ -96,76 +96,76 @@ cpl_parameter *p; - if (param_list == NULL) return (CPL_MSG_OFF); + if (param_list == NULL) + return (CPL_MSG_OFF); if (flag == 1) - p = cpl_parameterlist_find (param_list, PACKAGE_RESOURCE ".log-level"); + p = cpl_parameterlist_find(param_list, PACKAGE_RESOURCE ".log-level"); else - p = cpl_parameterlist_find (param_list, PACKAGE_RESOURCE ".msg-level"); + p = cpl_parameterlist_find(param_list, PACKAGE_RESOURCE ".msg-level"); - msg_level_value = cpl_parameter_get_string (p); + msg_level_value = cpl_parameter_get_string(p); ForceNull(msg_level_value) - if (msg_level_value != NULL) + if (msg_level_value != NULL) { - if (strcmp (msg_level_value, "debug") == 0) + if (strcmp(msg_level_value, "debug") == 0) return CPL_MSG_DEBUG; - else if (strcmp (msg_level_value, "info") == 0) + else if (strcmp(msg_level_value, "info") == 0) return CPL_MSG_INFO; - else if (strcmp (msg_level_value, "warning") == 0) + else if (strcmp(msg_level_value, "warning") == 0) return CPL_MSG_WARNING; - else if (strcmp (msg_level_value, "error") == 0) + else if (strcmp(msg_level_value, "error") == 0) return CPL_MSG_ERROR; - else if (strcmp (msg_level_value, "off") == 0) + else if (strcmp(msg_level_value, "off") == 0) return CPL_MSG_OFF; - else - { - char tmp[16]; + else { + char tmp[16]; if (flag == 1) - (void) strcpy(tmp,"logfile"); + (void)strcpy(tmp, "logfile"); else - (void) strcpy(tmp,"terminal"); - cpl_msg_error - (er_func, "%s messaging level '%s' is not recognized", tmp,msg_level_value); + (void)strcpy(tmp, "terminal"); + cpl_msg_error(er_func, "%s messaging level '%s' is not recognized", + tmp, msg_level_value); } } return (CPL_MSG_OFF); -} /* End of message_severity() */ +} /* End of message_severity() */ - -int add_size(const char *path, double *fsz) +int +add_size(const char *path, double *fsz) { struct stat buf; - if (stat(path,&buf) == -1) /* get file structure info */ + if (stat(path, &buf) == -1) /* get file structure info */ { - return(-1); + return (-1); } - *fsz += (double) buf.st_size; /* add current files size in bytes */ + *fsz += (double)buf.st_size; /* add current files size in bytes */ - return(0); + return (0); } -int mysscanf (char *myline, char *path, char * tag,char * group) +int +mysscanf(char *myline, char *path, char *tag, char *group) { - int iout, keep; + int iout, keep; register int i; - char cc; - char *mpt[3]; - + char cc; + char *mpt[3]; mpt[0] = path; @@ -175,29 +175,31 @@ i = -1; keep = 0; - for (iout=1; iout <4; iout++) - { - while(1) /* find blank space */ + for (iout = 1; iout < 4; iout++) { + while (1) /* find blank space */ { cc = myline[++i]; - if (cc == '\0') - { - (void) strcpy(mpt[iout-1],&myline[keep]); + if (cc == '\0') { + (void)strcpy(mpt[iout - 1], &myline[keep]); return iout; } - if (Xspace(cc)) break; + if (Xspace(cc)) + break; } myline[i] = '\0'; - (void) strcpy(mpt[iout-1],&myline[keep]); + (void)strcpy(mpt[iout - 1], &myline[keep]); - if (iout == 3) return iout; /* not more than 3 items... */ + if (iout == 3) + return iout; /* not more than 3 items... */ - while(1) /* find non-space char */ + while (1) /* find non-space char */ { cc = myline[++i]; - if (cc == '\0') return iout; - if (Xnospace(cc)) break; + if (cc == '\0') + return iout; + if (Xnospace(cc)) + break; } keep = i; @@ -206,7 +208,6 @@ } - /**********************************************************************/ /** * @brief @@ -238,17 +239,17 @@ */ /**********************************************************************/ -cpl_frameset *er_frameset_load -(const char *name, cpl_frameset * set, int flag_check_sof_exist) +cpl_frameset * +er_frameset_load(const char *name, cpl_frameset *set, int flag_check_sof_exist) { FILE *fp; - char *line, *path, *group, *tag, *xpath; - char estr[240]; - register char cc; + char *line, *path, *group, *tag, *xpath; + char estr[240]; + register char cc; int line_number = 0, created = 0; - int ii, mlen, n, no_comnt; + int ii, mlen, n, no_comnt; int load_sucesfull = 1; @@ -257,205 +258,199 @@ cpl_msg_severity msg_level; - if (name == NULL) - { - cpl_msg_error (er_func, "No SOF name provided, when one was expected."); + if (name == NULL) { + cpl_msg_error(er_func, "No SOF name provided, when one was expected."); return NULL; } - if (!(fp = fopen (name, "r"))) - { - cpl_msg_error (er_func, "Unable to open SOF file '%s'", name); + if (!(fp = fopen(name, "r"))) { + cpl_msg_error(er_func, "Unable to open SOF file '%s'", name); return NULL; } /* If set was NULL, create a new frame set that we can fill. */ - if (!set) - { - set = cpl_frameset_new (); + if (!set) { + set = cpl_frameset_new(); created = 1; } - line = (char *) cpl_calloc((size_t) SIZE_C, (size_t) 1); - path = (char *) cpl_calloc((size_t) SIZE_C, (size_t) 1); - xpath = (char *) cpl_calloc((size_t) SIZE_C, (size_t) 1); - group = (char *) cpl_calloc((size_t) SIZE_C, (size_t) 1); - tag = (char *) cpl_calloc((size_t) SIZE_C, (size_t) 1); + line = (char *)cpl_calloc((size_t)SIZE_C, (size_t)1); + path = (char *)cpl_calloc((size_t)SIZE_C, (size_t)1); + xpath = (char *)cpl_calloc((size_t)SIZE_C, (size_t)1); + group = (char *)cpl_calloc((size_t)SIZE_C, (size_t)1); + tag = (char *)cpl_calloc((size_t)SIZE_C, (size_t)1); - msg_level = cpl_msg_get_level(); /* get the message level */ + msg_level = cpl_msg_get_level(); /* get the message level */ /* Loop over all the lines in the set-of-frames file */ - while( fgets (line, (SIZE_C-1), fp)) - { + while (fgets(line, (SIZE_C - 1), fp)) { line_number++; - no_comnt = 0; /* check for comments + empty records */ - line[SIZE_C-1] = '\0'; + no_comnt = 0; /* check for comments + empty records */ + line[SIZE_C - 1] = '\0'; mlen = (int)strlen(line); /* printf("line no. %d has length %d\n",line_number,mlen); */ - for (ii=0; ii= 1) - { - if (xpath[0] == '$') /* check for env. variables */ + if (n >= 1) { + if (xpath[0] == '$') /* check for env. variables */ { - int wer; - char *wp; - wordexp_t wresult; - - wer = wordexp(xpath,&wresult,0); /* expand the $VAR/file */ - if (wer == 0) - { - wp = *wresult.we_wordv; /* use 1st and only result word */ + int wer; + char *wp; + wordexp_t wresult; + + wer = + wordexp(xpath, &wresult, 0); /* expand the $VAR/file */ + if (wer == 0) { + wp = *wresult + .we_wordv; /* use 1st and only result word */ if (wp != NULL) - (void) strcpy(path,wp); + (void)strcpy(path, wp); else wer = 1; wordfree(&wresult); } - if (wer != 0) - { - (void) snprintf(estr,(size_t)238,"Expansion of %s failed...",xpath); - cpl_msg_error (er_func, "%s", estr); + if (wer != 0) { + (void)snprintf(estr, (size_t)238, + "Expansion of %s failed...", xpath); + cpl_msg_error(er_func, "%s", estr); goto dealloc; } } - else - { - (void) strcpy(path,xpath); + else { + (void)strcpy(path, xpath); } - if (!(fileutils_file_exists (path))) /* Ensure that the path exists */ - { /* Invalid file name? */ + if (!(fileutils_file_exists( + path))) /* Ensure that the path exists */ + { /* Invalid file name? */ /* allow a single FITS file instead of SOF */ - if (strncmp(path,"SIMPLE",6) == 0) - { /* it's a single FITS file */ - n = (int) strlen(name); - if (n > (SIZE_C-1)) - { + if (strncmp(path, "SIMPLE", 6) == + 0) { /* it's a single FITS file */ + n = (int)strlen(name); + if (n > (SIZE_C - 1)) { n = SIZE_C - 1; - (void) strncpy(path,name,(size_t)n); + (void)strncpy(path, name, (size_t)n); path[n] = '\0'; - cpl_msg_warning (er_func, "FITS file name truncated to %d chars", n); + cpl_msg_warning( + er_func, "FITS file name truncated to %d chars", + n); } - else - { - (void) strcpy(path,name); + else { + (void)strcpy(path, name); } - (void) strcpy(tag,"COMMAND_LINE"); - n = -1; /* to remember that later on */ + (void)strcpy(tag, "COMMAND_LINE"); + n = -1; /* to remember that later on */ } - else /* Yes, bad filename */ + else /* Yes, bad filename */ { - char * tagmsg = n >= 2 - ? cpl_sprintf("tag '%s'", tag) - : cpl_sprintf("no tag"); - char * groupmsg = n >= 3 - ? cpl_sprintf("group '%s'", group) - : cpl_sprintf("no group"); - - if (flag_check_sof_exist) - { - cpl_msg_error (er_func, - "Could not open the input file '%s' with %s and %s in " - "line %d of the SOF '%s'", path, tagmsg, groupmsg, - line_number, name); + char *tagmsg = n >= 2 ? cpl_sprintf("tag '%s'", tag) + : cpl_sprintf("no tag"); + char *groupmsg = n >= 3 + ? cpl_sprintf("group '%s'", group) + : cpl_sprintf("no group"); + + if (flag_check_sof_exist) { + cpl_msg_error(er_func, + "Could not open the input file '%s' " + "with %s and %s in " + "line %d of the SOF '%s'", + path, tagmsg, groupmsg, line_number, + name); load_sucesfull = 0; } - else - { - cpl_msg_debug (er_func, - "Could not open the input file '%s' with %s and %s in " - "line %d of the SOF '%s'", path, tagmsg, groupmsg, - line_number, name); + else { + cpl_msg_debug(er_func, + "Could not open the input file '%s' " + "with %s and %s in " + "line %d of the SOF '%s'", + path, tagmsg, groupmsg, line_number, + name); } cpl_free(tagmsg); cpl_free(groupmsg); - } } - frame = cpl_frame_new (); /* allocate a new frame */ - cpl_frame_set_filename (frame, path); /* and provide the filename */ + frame = cpl_frame_new(); /* allocate a new frame */ + cpl_frame_set_filename(frame, + path); /* and provide the filename */ - if (n == 1) /* no tag in SOF line */ - cpl_frame_set_tag (frame, ""); + if (n == 1) /* no tag in SOF line */ + cpl_frame_set_tag(frame, ""); else - cpl_frame_set_tag (frame, tag); + cpl_frame_set_tag(frame, tag); /* Set the group component of the frame (or set a default) */ - if (n > 2) /* so, omitted for single FITS file */ + if (n > 2) /* so, omitted for single FITS file */ { cpl_frame_group grp; - if (!strcmp (group, CPL_FRAME_GROUP_RAW_ID)) + if (!strcmp(group, CPL_FRAME_GROUP_RAW_ID)) grp = CPL_FRAME_GROUP_RAW; - else - { - if (!strcmp (group, CPL_FRAME_GROUP_CALIB_ID)) + else { + if (!strcmp(group, CPL_FRAME_GROUP_CALIB_ID)) grp = CPL_FRAME_GROUP_CALIB; - else - { - if (!strcmp (group, CPL_FRAME_GROUP_PRODUCT_ID)) + else { + if (!strcmp(group, CPL_FRAME_GROUP_PRODUCT_ID)) grp = CPL_FRAME_GROUP_PRODUCT; else grp = CPL_FRAME_GROUP_NONE; } } - cpl_frame_set_group (frame, grp); + cpl_frame_set_group(frame, grp); } - cpl_frameset_insert (set, frame); - if (n == -1) goto dealloc; /* was single FITS file */ + cpl_frameset_insert(set, frame); + if (n == -1) + goto dealloc; /* was single FITS file */ } - else - { /* Invalid frame description. */ - if (msg_level == CPL_MSG_DEBUG) - { - cpl_msg_debug (er_func, - "Invalid frame description '%s', specified on line %d of the SOF " - "file, '%s'.", path, line_number, name); + else { /* Invalid frame description. */ + if (msg_level == CPL_MSG_DEBUG) { + cpl_msg_debug(er_func, + "Invalid frame description '%s', specified " + "on line %d of the SOF " + "file, '%s'.", + path, line_number, name); } } } - } /* End of while() */ + } /* End of while() */ - dealloc: /* Deallocate resources */ - cpl_free (line); - cpl_free (path); - cpl_free (xpath); - cpl_free (group); - cpl_free (tag); - fclose (fp); +dealloc: /* Deallocate resources */ + cpl_free(line); + cpl_free(path); + cpl_free(xpath); + cpl_free(group); + cpl_free(tag); + fclose(fp); /* Check if the loading was successfully */ - if(!load_sucesfull) - { - if(created) + if (!load_sucesfull) { + if (created) cpl_frameset_delete(set); return NULL; } @@ -463,8 +458,7 @@ /* Return the pointer to the frameset */ return set; -} /* End of er_frameset_load() */ - +} /* End of er_frameset_load() */ /**********************************************************************/ @@ -483,7 +477,7 @@ /**********************************************************************/ inline static int -_upda_products (cpl_frameset *frameset, unsigned int flags) +_upda_products(cpl_frameset *frameset, unsigned int flags) { cpl_error_code reto; @@ -493,13 +487,11 @@ const cpl_frame *frame = NULL; while ((frame = cpl_frameset_iterator_get_const(it)) != NULL) { - if (cpl_frame_get_group(frame) == CPL_FRAME_GROUP_PRODUCT) { ++pcount; } cpl_frameset_iterator_advance(it, 1); - } cpl_frameset_iterator_delete(it); @@ -511,17 +503,14 @@ reto = cpl_dfs_sign_products(frameset, flags); - if (reto != CPL_ERROR_NONE) - { - cpl_msg_error (er_func, "could not update the product header..."); + if (reto != CPL_ERROR_NONE) { + cpl_msg_error(er_func, "could not update the product header..."); } return 0; } - - /**********************************************************************/ /** * @brief Process the Plugin @@ -549,29 +538,31 @@ /**********************************************************************/ inline static int -_move_products (cpl_frameset * frameset, - char * output_directory, - char * output_prefix, - char * link_directory, - unsigned int signature_mask, - int flag_noprefix, int flag_nolink, int flag_readonly) +_move_products(cpl_frameset *frameset, + char *output_directory, + char *output_prefix, + char *link_directory, + unsigned int signature_mask, + int flag_noprefix, + int flag_nolink, + int flag_readonly) { - cpl_frame *frame = NULL; /* The current frame being processed */ + cpl_frame *frame = NULL; /* The current frame being processed */ - int filenum = 0; /* Number of the output product */ + int filenum = 0; /* Number of the output product */ int ii, move_err; - int target_path_is_cwd = 0; /* assume that output path and CWD differ */ + int target_path_is_cwd = 0; /* assume that output path and CWD differ */ const char *fileutils_pntr; const char *cpp; - const char *input_name = NULL; /* Name of the input file */ + const char *input_name = NULL; /* Name of the input file */ - char *output_name = NULL; /* Name of the output file */ - char *suffix = NULL; /* The file suffix */ - char current_dir[FILEMAX]; /* Name of current (work) directory */ - char link_dir[PATHSET_MAX]; /* Name of the symbolic link dir. */ - char output_dir[PATHSET_MAX]; /* Name of the output dir. */ + char *output_name = NULL; /* Name of the output file */ + char *suffix = NULL; /* The file suffix */ + char current_dir[FILEMAX]; /* Name of current (work) directory */ + char link_dir[PATHSET_MAX]; /* Name of the symbolic link dir. */ + char output_dir[PATHSET_MAX]; /* Name of the output dir. */ struct stat sb_cdir; struct stat sb_tdir; @@ -579,7 +570,7 @@ /* allocate space */ - output_name = (char *) cpl_malloc((size_t) SIZE_A); + output_name = (char *)cpl_malloc((size_t)SIZE_A); current_dir[0] = '\0'; @@ -587,25 +578,23 @@ /* Start by getting the "cleaned" output directory name */ fileutils_pntr = - er_fileutils_dot_replace (er_fileutils_tilde_replace (output_directory)); - if (fileutils_pntr == NULL) - { - cpl_msg_warning (er_func, "missing output directory ..."); + er_fileutils_dot_replace(er_fileutils_tilde_replace(output_directory)); + if (fileutils_pntr == NULL) { + cpl_msg_warning(er_func, "missing output directory ..."); + } + (void)strcpy(output_dir, fileutils_pntr); + + fileutils_pntr = er_fileutils_tilde_replace(link_directory); + if (fileutils_pntr == NULL) { + cpl_msg_warning(er_func, + "missing directory for symbolic link ignored..."); } - (void) strcpy (output_dir, fileutils_pntr); - - fileutils_pntr = er_fileutils_tilde_replace (link_directory); - if (fileutils_pntr == NULL) - { - cpl_msg_warning (er_func, "missing directory for symbolic link ignored..."); - } - (void) strcpy (link_dir, fileutils_pntr); + (void)strcpy(link_dir, fileutils_pntr); /* Determine the name of the current directory */ - if (getcwd (current_dir, (size_t) FILEMAX) == NULL) - { + if (getcwd(current_dir, (size_t)FILEMAX) == NULL) { cpl_msg_error(er_func, "cannot get current working directory"); move_err = 64; goto report_products; @@ -618,15 +607,13 @@ // Finally this section should use the file utilities function, // which need to be reviewed first. - if ((stat(current_dir, &sb_cdir) != 0) || (stat(output_dir, &sb_tdir) != 0)) - { + if ((stat(current_dir, &sb_cdir) != 0) || + (stat(output_dir, &sb_tdir) != 0)) { cpl_msg_error(er_func, "cannot get directory status information"); move_err = 65; goto report_products; } - else - { - + else { /* * Check whether the current working directory and the final * location of the product files are identical, i.e. they are @@ -634,11 +621,9 @@ */ if ((sb_cdir.st_dev == sb_tdir.st_dev) && - (sb_cdir.st_ino == sb_tdir.st_ino)) - { + (sb_cdir.st_ino == sb_tdir.st_ino)) { target_path_is_cwd = 1; } - } /* MD5 errors ignored at the moment... */ @@ -648,42 +633,37 @@ /* Loop through the frameset */ - move_err = 0; /* init possible error from moving files */ + move_err = 0; /* init possible error from moving files */ cpl_frameset_iterator *it = cpl_frameset_iterator_new(frameset); - while ((frame = cpl_frameset_iterator_get(it)) != NULL) - { - if (cpl_frame_get_group (frame) == CPL_FRAME_GROUP_PRODUCT) - { - + while ((frame = cpl_frameset_iterator_get(it)) != NULL) { + if (cpl_frame_get_group(frame) == CPL_FRAME_GROUP_PRODUCT) { /* * Get the filename as specified by the frame */ - input_name = cpl_frame_get_filename (frame); + input_name = cpl_frame_get_filename(frame); /* * Temporarily remove the suffix (find the first '.' and * replace it) */ - suffix = strrchr (input_name, '.'); - if (suffix) *suffix = '\0'; + suffix = strrchr(input_name, '.'); + if (suffix) + *suffix = '\0'; /* * Generate the output filename (keep original if this * is suppressed) */ - if (flag_noprefix != 0) - { - (void) strcpy (output_name, input_name); + if (flag_noprefix != 0) { + (void)strcpy(output_name, input_name); } - else - { - (void) sprintf (output_name, "%s_%04d", output_prefix, - filenum); + else { + (void)sprintf(output_name, "%s_%04d", output_prefix, filenum); } /* @@ -691,18 +671,19 @@ * suffix and *suffix) */ - if (suffix) *suffix = '.'; - if (suffix) (void) strcat (output_name, suffix); + if (suffix) + *suffix = '.'; + if (suffix) + (void)strcat(output_name, suffix); /* * Check if any move-command is required */ - cpp = cpl_frame_get_filename (frame); - if (cpp == NULL) - { + cpp = cpl_frame_get_filename(frame); + if (cpp == NULL) { cpl_frameset_iterator_delete(it); - cpl_msg_error (er_func, "cpl_frame_get_filename failed"); + cpl_msg_error(er_func, "cpl_frame_get_filename failed"); move_err = 63; goto report_products; } @@ -714,82 +695,78 @@ * the final product name are different. */ - if (target_path_is_cwd && (strcmp(cpp, output_name) == 0)) - { - + if (target_path_is_cwd && (strcmp(cpp, output_name) == 0)) { /* * No move. Report that the product has been created */ - cpl_msg_info (er_func, "Created product %s (in place)", - output_name); - + cpl_msg_info(er_func, "Created product %s (in place)", + output_name); } - else - { - + else { /* * Create the full path */ - char tmp[SIZE_A]; + char tmp[SIZE_A]; if (output_name[0] == '\0') - (void) strcpy(tmp,"dummy_output"); + (void)strcpy(tmp, "dummy_output"); else - (void) strcpy(tmp,output_name); + (void)strcpy(tmp, output_name); - (void) strcpy (output_name, output_dir); - ii = (int) strlen(output_name) - 1; - if (output_name[ii] != '/') output_name[++ii] = '/'; - (void) strcpy (&output_name[ii+1],tmp); + (void)strcpy(output_name, output_dir); + ii = (int)strlen(output_name) - 1; + if (output_name[ii] != '/') + output_name[++ii] = '/'; + (void)strcpy(&output_name[ii + 1], tmp); int status; status = access(output_name, F_OK); - if(status == 0) - cpl_msg_warning (er_func, - "Product final output path file already exists and will be overwritten (%s)", - output_name); + if (status == 0) + cpl_msg_warning(er_func, + "Product final output path file already " + "exists and will be overwritten (%s)", + output_name); status = rename(cpp, output_name); - if(status != 0) - { - if(errno == EXDEV) - { + if (status != 0) { + if (errno == EXDEV) { status = fileutils_move(cpp, output_name); - if(status != 0) - { + if (status != 0) { cpl_frameset_iterator_delete(it); - cpl_msg_error (er_func, - "Unable to move product file to final output path in different filesystem (%s)", - output_name); + cpl_msg_error( + er_func, + "Unable to move product file to final output " + "path in different filesystem (%s)", + output_name); move_err = 66; goto report_products; } } - else if(errno == EACCES) - { + else if (errno == EACCES) { cpl_frameset_iterator_delete(it); - cpl_msg_error (er_func, - "Permission denied in product final output directory (%s)", - output_dir); + cpl_msg_error(er_func, + "Permission denied in product final " + "output directory (%s)", + output_dir); move_err = 67; goto report_products; } - else if(errno == EROFS) - { + else if (errno == EROFS) { cpl_frameset_iterator_delete(it); - cpl_msg_error (er_func, - "Read-only filesystem in product final output directory (%s)", - output_dir); + cpl_msg_error(er_func, + "Read-only filesystem in product final " + "output directory (%s)", + output_dir); move_err = 68; goto report_products; } - else - { + else { cpl_frameset_iterator_delete(it); - cpl_msg_error (er_func, - "Unable to move product file to final output path (%s)", - output_name); + cpl_msg_error(er_func, + "Unable to move product file to final " + "output path (%s)", + output_name); move_err = 61; goto report_products; } @@ -797,47 +774,47 @@ /* Update the name in the sof */ cpl_frame_set_filename(frame, output_name); - cpl_msg_info (er_func, "Created product %s", output_name); + cpl_msg_info(er_func, "Created product %s", output_name); } /* If required, generate the symbolic links for the archive system */ - if (flag_nolink == 0) - { - if (er_fileutils_link (link_dir, output_name) != EXIT_SUCCESS) - { + if (flag_nolink == 0) { + if (er_fileutils_link(link_dir, output_name) != EXIT_SUCCESS) { cpl_frameset_iterator_delete(it); - cpl_msg_error (er_func, - "Unable to create symbolic link for %s in " - "directory %s", output_name, link_dir); + cpl_msg_error(er_func, + "Unable to create symbolic link for %s in " + "directory %s", + output_name, link_dir); move_err = 62; goto report_products; } } /* If required, lock the file permissions to read-only */ - if (flag_readonly != 0) chmod (output_name, 0444); + if (flag_readonly != 0) + chmod(output_name, 0444); - filenum++; /* Increment the product number */ + filenum++; /* Increment the product number */ } /* Get the next frame in the list */ cpl_frameset_iterator_advance(it, 1); - } /* End of (while) loop through all frames in frameset */ + } /* End of (while) loop through all frames in frameset */ cpl_frameset_iterator_delete(it); /* Report how many products were created (getting the plural right!) */ - report_products: - cpl_msg_info (er_func, "%d product%s created", filenum, - (filenum == 1) ? "" : "s"); - cpl_free (output_name); /* free the allocated memory */ +report_products: + cpl_msg_info(er_func, "%d product%s created", filenum, + (filenum == 1) ? "" : "s"); + cpl_free(output_name); /* free the allocated memory */ return move_err; -} +} /**********************************************************************/ @@ -858,17 +835,16 @@ */ /**********************************************************************/ -int plugin_process_plugin (cpl_parameterlist *caller_parameters, - char *plugin_name, - er_stringarray_t * sof_filename_list, - int argc, char * argv[]) +int +plugin_process_plugin(cpl_parameterlist *caller_parameters, + char *plugin_name, + er_stringarray_t *sof_filename_list, + int argc, + char *argv[]) { - const char *val_output_mask, - *val_link_dir, - *val_log_dir, - *val_log_file, - *val_output_dir, *cpp; + const char *val_output_mask, *val_link_dir, *val_log_dir, *val_log_file, + *val_output_dir, *cpp; const char *val_string_tmp = NULL; const char *cdescr; @@ -878,14 +854,10 @@ const char *val_create = NULL; - char **val_recipe_dirs = NULL, - *log_file_name_full = NULL; + char **val_recipe_dirs = NULL, *log_file_name_full = NULL; - char *cptr, - *plugin_conf_file_global=NULL, - *plugin_conf_file_local=NULL, - library_path[MAXSTRLENCONF], - cmdline[MAXSTRLENCONF]; + char *cptr, *plugin_conf_file_global = NULL, *plugin_conf_file_local = NULL, + library_path[MAXSTRLENCONF], cmdline[MAXSTRLENCONF]; char *help_str = NULL; @@ -902,23 +874,23 @@ int flag_readonly = 0; int flag_noprefix = 0; int flag_nolink = 0; - int f_val_unload_plugin = 1; /* default is TRUE */ + int f_val_unload_plugin = 1; /* default is TRUE */ - unsigned int signature_mask = CPL_DFS_SIGNATURE_DATAMD5 | CPL_DFS_SIGNATURE_CHECKSUM; + unsigned int signature_mask = + CPL_DFS_SIGNATURE_DATAMD5 | CPL_DFS_SIGNATURE_CHECKSUM; - unsigned long uil; + unsigned long uil; - double plugin_time_start=0.0, plugin_time_end=0.0; + double plugin_time_start = 0.0, plugin_time_end = 0.0; - cpl_msg_severity msg_level = CPL_MSG_ERROR, - msg_sev_logfile, msg_sev_terminal; + cpl_msg_severity msg_level = CPL_MSG_ERROR, msg_sev_logfile, + msg_sev_terminal; cpl_parameter *p = NULL; cpl_plugin *tplugin = NULL; lt_dlhandle module = NULL; - cpl_plugin_func plugin_func_init = NULL, - plugin_func_exec = NULL, - plugin_func_deinit = NULL; + cpl_plugin_func plugin_func_init = NULL, plugin_func_exec = NULL, + plugin_func_deinit = NULL; cpl_recipe *trecipe = NULL; cpl_recipe2 *t2recipe = NULL; @@ -930,9 +902,9 @@ library_path[0] = '\0'; /* check, if we want to take times */ - p = cpl_parameterlist_find (caller_parameters, PACKAGE_RESOURCE ".time"); - flag_time_plugin = cpl_parameter_get_bool (p); - if (flag_time_plugin != 0) /* --time option */ + p = cpl_parameterlist_find(caller_parameters, PACKAGE_RESOURCE ".time"); + flag_time_plugin = cpl_parameter_get_bool(p); + if (flag_time_plugin != 0) /* --time option */ { plugin_time_start = cpl_test_get_walltime(); } @@ -942,30 +914,32 @@ * man-page output */ - p = cpl_parameterlist_find(caller_parameters, PACKAGE_RESOURCE ".show-hidden"); + p = cpl_parameterlist_find(caller_parameters, + PACKAGE_RESOURCE ".show-hidden"); flag_show_all = cpl_parameter_get_bool(p); - msg_sev_logfile = message_severity (caller_parameters,1); - msg_sev_terminal = message_severity (caller_parameters,2); + msg_sev_logfile = message_severity(caller_parameters, 1); + msg_sev_terminal = message_severity(caller_parameters, 2); - p = cpl_parameterlist_find (caller_parameters, PACKAGE_RESOURCE ".log-dir"); - val_log_dir = cpl_parameter_get_string (p); + p = cpl_parameterlist_find(caller_parameters, PACKAGE_RESOURCE ".log-dir"); + val_log_dir = cpl_parameter_get_string(p); ForceNull(val_log_dir) - p = cpl_parameterlist_find (caller_parameters, PACKAGE_RESOURCE ".log-file"); - val_log_file = cpl_parameter_get_string (p); - ForceNull(val_log_file) - log_file_name_full = - fileutils_create_fqfname ((char *) val_log_dir, (char *) val_log_file); + p = cpl_parameterlist_find(caller_parameters, + PACKAGE_RESOURCE ".log-file"); + val_log_file = cpl_parameter_get_string(p); + ForceNull(val_log_file) log_file_name_full = + fileutils_create_fqfname((char *)val_log_dir, (char *)val_log_file); - log_err = cpl_msg_set_log_level (msg_sev_logfile); - if (log_err != CPL_ERROR_NONE) - { - (void) printf ("WARNING : EsoRex is unable to establish the message log " - "(Error = %d)\n", log_err); - (void) printf (" (Check write permission for temporary files.)\n"); + log_err = cpl_msg_set_log_level(msg_sev_logfile); + if (log_err != CPL_ERROR_NONE) { + (void)printf("WARNING : EsoRex is unable to establish the message log " + "(Error = %d)\n", + log_err); + (void)printf( + " (Check write permission for temporary files.)\n"); } /* @@ -973,29 +947,29 @@ * the logfile (only) */ - cpl_msg_set_level (CPL_MSG_OFF); + cpl_msg_set_level(CPL_MSG_OFF); cdescr = cpl_get_description(CPL_DESCRIPTION_DEFAULT); - (void) cpl_msg_info(er_func,"This is EsoRex, version %s", PACKAGE_VERSION); - (void) cpl_msg_info(er_func,"using the libraries: %s",cdescr); + (void)cpl_msg_info(er_func, "This is EsoRex, version %s", PACKAGE_VERSION); + (void)cpl_msg_info(er_func, "using the libraries: %s", cdescr); sz = 0; - for (i=0; i < argc - 1; ++i) { + for (i = 0; i < argc - 1; ++i) { int nc = snprintf(&cmdline[sz], MAXSTRLENCONF, "%s ", argv[i]); sz += nc; } sz = snprintf(&cmdline[sz], MAXSTRLENCONF, "%s", argv[argc - 1]); - (void) cpl_msg_info(er_func,"Invocation command line was: %s", cmdline); - cpl_msg_set_level (msg_sev_terminal); + (void)cpl_msg_info(er_func, "Invocation command line was: %s", cmdline); + cpl_msg_set_level(msg_sev_terminal); /* look for recipe directory */ - p = cpl_parameterlist_find (caller_parameters, PACKAGE_RESOURCE ".recipe-dir"); - val_string_tmp = cpl_parameter_get_string (p); - ForceNull(val_string_tmp) - if (val_string_tmp != NULL) - val_recipe_dirs = cx_strsplit (val_string_tmp, ":", -1); + p = cpl_parameterlist_find(caller_parameters, + PACKAGE_RESOURCE ".recipe-dir"); + val_string_tmp = cpl_parameter_get_string(p); + ForceNull(val_string_tmp) if (val_string_tmp != NULL) val_recipe_dirs = + cx_strsplit(val_string_tmp, ":", -1); /* get the plugin */ @@ -1004,25 +978,26 @@ else sz = 1; - if ((val_recipe_dirs != NULL) && (sz > 0)) - { - list_of_pllib_names = er_pluginlist_create_list (val_recipe_dirs); + if ((val_recipe_dirs != NULL) && (sz > 0)) { + list_of_pllib_names = er_pluginlist_create_list(val_recipe_dirs); - sz = er_pluginlist_get_libpath (list_of_pllib_names, plugin_name, library_path); - if (sz > 0) - { - tplugin = er_pluginlist_get_plugin (library_path, plugin_name, &module); - if (tplugin != NULL) - { + sz = er_pluginlist_get_libpath(list_of_pllib_names, plugin_name, + library_path); + if (sz > 0) { + tplugin = + er_pluginlist_get_plugin(library_path, plugin_name, &module); + if (tplugin != NULL) { flag_plugin_found = 1; goto next_step; } } - cpl_msg_error (er_func, "Unable to find recipe '%s'." - " Check that the recipe is in the path specified by the" - " '--recipe-dir' option.", plugin_name); + cpl_msg_error(er_func, + "Unable to find recipe '%s'." + " Check that the recipe is in the path specified by the" + " '--recipe-dir' option.", + plugin_name); e_code = CPL_ERROR_INCOMPATIBLE_INPUT; - goto cleanup; /* we cannot do anything */ + goto cleanup; /* we cannot do anything */ } @@ -1030,149 +1005,146 @@ /* here we process the plugin (if found) */ /* ------------------------------------- */ - next_step: +next_step: uil = cpl_plugin_get_type(tplugin); /* initialize the plugin/recipe structure: trecipe->parameters is handled by plugin */ - if (uil < 2) - { - n = sizeof (cpl_recipe); - trecipe = (cpl_recipe *) cpl_calloc (1,(size_t) n); - } - else - { - n = sizeof (cpl_recipe2); - t2recipe = (cpl_recipe2 *) cpl_calloc (1,(size_t) n); + if (uil < 2) { + n = sizeof(cpl_recipe); + trecipe = (cpl_recipe *)cpl_calloc(1, (size_t)n); + } + else { + n = sizeof(cpl_recipe2); + t2recipe = (cpl_recipe2 *)cpl_calloc(1, (size_t)n); trecipe = &t2recipe->base; } - trecipe->frames = cpl_frameset_new (); + trecipe->frames = cpl_frameset_new(); - if (flag_plugin_found != 0) /* = TRUE */ + if (flag_plugin_found != 0) /* = TRUE */ { - cpl_plugin_copy ((cpl_plugin *) & trecipe->interface, tplugin); + cpl_plugin_copy((cpl_plugin *)&trecipe->interface, tplugin); /* Run Plugin Initialization... */ - plugin_func_init = cpl_plugin_get_init ((cpl_plugin *) trecipe); - if (plugin_func_init != NULL) - { - cpl_msg_set_domain (cpl_plugin_get_name ((cpl_plugin *) trecipe)); - e_code = plugin_func_init ((cpl_plugin *) trecipe); - cpl_msg_set_domain (PACKAGE); - if (e_code != 0) - { - cpl_msg_error (er_func, "Init of recipe failed..."); + plugin_func_init = cpl_plugin_get_init((cpl_plugin *)trecipe); + if (plugin_func_init != NULL) { + cpl_msg_set_domain(cpl_plugin_get_name((cpl_plugin *)trecipe)); + e_code = plugin_func_init((cpl_plugin *)trecipe); + cpl_msg_set_domain(PACKAGE); + if (e_code != 0) { + cpl_msg_error(er_func, "Init of recipe failed..."); goto plugin_deinit; } } /* loop through all parameters in the list */ - p = cpl_parameterlist_get_first (trecipe->parameters); - while (p != NULL) - { /* Set the tag */ + p = cpl_parameterlist_get_first(trecipe->parameters); + while (p != NULL) { /* Set the tag */ char recip_def[] = "recipe default"; - char *myptr; + char *myptr; myptr = recip_def; - er_manage_sources(1,cpl_parameter_get_name(p),&myptr); + er_manage_sources(1, cpl_parameter_get_name(p), &myptr); /* Get the next parameter in the list */ - p = cpl_parameterlist_get_next (trecipe->parameters); + p = cpl_parameterlist_get_next(trecipe->parameters); } - cpp = cpl_plugin_get_name ((cpl_plugin *) trecipe); + cpp = cpl_plugin_get_name((cpl_plugin *)trecipe); /* Parse any global plugin configuration file */ - cptr = getenv ("HOME"); + cptr = getenv("HOME"); if (cptr == NULL) n = 0; else - n = (int) strlen(cptr); - if (cpp != NULL) n += (int)strlen(cpp); - - n = n + ((int)strlen(cpp)) + - ((int) strlen(GLOBAL_RC_DIR)) + ((int) strlen(GLOBAL_RC_EXTENSION)); - n += 4; /* for the additionial const chars */ - - plugin_conf_file_global = (char *) cpl_malloc((size_t) n); - if ( plugin_conf_file_global == NULL) - { - cpl_msg_error (er_func, - "Could not allocate %d bytes for plugin_conf_file_global",n); + n = (int)strlen(cptr); + if (cpp != NULL) + n += (int)strlen(cpp); + + n = n + ((int)strlen(cpp)) + ((int)strlen(GLOBAL_RC_DIR)) + + ((int)strlen(GLOBAL_RC_EXTENSION)); + n += 4; /* for the additionial const chars */ + + plugin_conf_file_global = (char *)cpl_malloc((size_t)n); + if (plugin_conf_file_global == NULL) { + cpl_msg_error( + er_func, + "Could not allocate %d bytes for plugin_conf_file_global", n); e_code = CPL_ERROR_ILLEGAL_OUTPUT; goto plugin_deinit; } if (cptr == NULL) - (void) strcpy(plugin_conf_file_global, "/"); - else - { - (void) strcpy(plugin_conf_file_global,cptr); - (void) strcat(plugin_conf_file_global, "/"); - } - (void) strcat(plugin_conf_file_global, GLOBAL_RC_DIR); - (void) strcat(plugin_conf_file_global, "/"); - if (cpp != NULL) (void) strcat(plugin_conf_file_global, cpp); - (void) strcat(plugin_conf_file_global, GLOBAL_RC_EXTENSION); - - if (e_code == 0) - { - if (fileutils_file_exists(plugin_conf_file_global) != 0) - { - e_code = params_parse_config_file (trecipe->parameters, - plugin_conf_file_global); - if (e_code != 0) goto plugin_deinit; + (void)strcpy(plugin_conf_file_global, "/"); + else { + (void)strcpy(plugin_conf_file_global, cptr); + (void)strcat(plugin_conf_file_global, "/"); + } + (void)strcat(plugin_conf_file_global, GLOBAL_RC_DIR); + (void)strcat(plugin_conf_file_global, "/"); + if (cpp != NULL) + (void)strcat(plugin_conf_file_global, cpp); + (void)strcat(plugin_conf_file_global, GLOBAL_RC_EXTENSION); + + if (e_code == 0) { + if (fileutils_file_exists(plugin_conf_file_global) != 0) { + e_code = params_parse_config_file(trecipe->parameters, + plugin_conf_file_global); + if (e_code != 0) + goto plugin_deinit; } } /* Parse any specifically specified plugin configuration file */ - if (e_code == 0) - { - p = cpl_parameterlist_find (caller_parameters, - PACKAGE_RESOURCE ".recipe-config"); - val_string_tmp = cpl_parameter_get_string (p); - - if ((val_string_tmp != (char *) 0) && (strlen (val_string_tmp) > 0)) - e_code = params_parse_config_file (trecipe->parameters, val_string_tmp); + if (e_code == 0) { + p = cpl_parameterlist_find(caller_parameters, + PACKAGE_RESOURCE ".recipe-config"); + val_string_tmp = cpl_parameter_get_string(p); + if ((val_string_tmp != (char *)0) && (strlen(val_string_tmp) > 0)) + e_code = params_parse_config_file(trecipe->parameters, + val_string_tmp); } - if (e_code == 0) - { + if (e_code == 0) { char *str_tmp = NULL; - e_code = params_parse_config_commandline - (trecipe->parameters, plugin_name, - sof_filename_list, argc, argv, 0); - if (e_code != 0) goto plugin_deinit; + e_code = + params_parse_config_commandline(trecipe->parameters, + plugin_name, sof_filename_list, + argc, argv, 0); + if (e_code != 0) + goto plugin_deinit; - params_parse_config_postprocess (trecipe->parameters); + params_parse_config_postprocess(trecipe->parameters); ii = er_stringarray_size(sof_filename_list); - for (i=0; iframes, flag_check_sof_exist) == NULL) - { - cpl_msg_error (er_func, "Problem occurred loading frameset " - "from the SOF file '%s'.\n" - "If you want to ignore errors of missing files in " - "the sof, set '--check-sof-exist=false'.", str_tmp); + p = cpl_parameterlist_find(caller_parameters, + PACKAGE_RESOURCE ".check-sof-exist"); + flag_check_sof_exist = cpl_parameter_get_bool(p); + + str_tmp = er_stringarray_get(sof_filename_list, i); + if (er_frameset_load(str_tmp, trecipe->frames, + flag_check_sof_exist) == NULL) { + cpl_msg_error( + er_func, + "Problem occurred loading frameset " + "from the SOF file '%s'.\n" + "If you want to ignore errors of missing files in " + "the sof, set '--check-sof-exist=false'.", + str_tmp); e_code = CPL_ERROR_FILE_NOT_FOUND; } @@ -1181,105 +1153,99 @@ /* Check if we want to create the plugin (recipe) configuration file */ - p = cpl_parameterlist_find (caller_parameters, PACKAGE_RESOURCE ".create-config"); - if (cpl_parameter_get_default_flag (p)) - { - val_create = cpl_parameter_get_string (p); - ForceNull(val_create) - if (val_create != NULL) /* --create-config=bla.bla found */ - { /* handle FALSE and TRUE from boolean history of this param */ - if (strcmp(val_create,"TRUE") == 0) - { + p = cpl_parameterlist_find(caller_parameters, + PACKAGE_RESOURCE ".create-config"); + if (cpl_parameter_get_default_flag(p)) { + val_create = cpl_parameter_get_string(p); + ForceNull(val_create) if (val_create != + NULL) /* --create-config=bla.bla found */ + { /* handle FALSE and TRUE from boolean history of this param */ + if (strcmp(val_create, "TRUE") == 0) { flag_create_config = 1; } - else if (strcmp(val_create,"FALSE") != 0) - { - flag_create_config = 11; /* indicates filename is given */ + else if (strcmp(val_create, "FALSE") != 0) { + flag_create_config = 11; /* indicates filename is given */ } } - else /* --create-config is interpreted as ...=TRUE */ + else /* --create-config is interpreted as ...=TRUE */ { flag_create_config = 1; } } - if (flag_create_config == 11) - { - er_help_create_config (flag_create_config, plugin_name, val_create, - caller_parameters, trecipe->parameters); + if (flag_create_config == 11) { + er_help_create_config(flag_create_config, plugin_name, val_create, + caller_parameters, trecipe->parameters); e_code = -99999; } - else if (flag_create_config == 1) - { - er_help_create_config (flag_create_config, plugin_name, NULL, - caller_parameters, trecipe->parameters); + else if (flag_create_config == 1) { + er_help_create_config(flag_create_config, plugin_name, NULL, + caller_parameters, trecipe->parameters); e_code = -99999; } /* Check if we want to display the plugin help */ - p = cpl_parameterlist_find (caller_parameters, PACKAGE_RESOURCE ".man-page"); - flag_man_page = cpl_parameter_get_bool (p); - if (flag_man_page != 0) - { + p = cpl_parameterlist_find(caller_parameters, + PACKAGE_RESOURCE ".man-page"); + flag_man_page = cpl_parameter_get_bool(p); + if (flag_man_page != 0) { er_help_manpage(trecipe, flag_show_all); e_code = -99999; } /* Check if we want to display the plugin help */ - p = cpl_parameterlist_find (caller_parameters, PACKAGE_RESOURCE ".help"); - flag_help = cpl_parameter_get_bool (p); - if (flag_help != 0) - { - int h_size = 512; + p = cpl_parameterlist_find(caller_parameters, PACKAGE_RESOURCE ".help"); + flag_help = cpl_parameter_get_bool(p); + if (flag_help != 0) { + int h_size = 512; char tmp_buf[512]; - help_str = (char *) cpl_malloc((size_t) h_size); - if (help_str == NULL) - { - cpl_msg_error (er_func, "Could not allocate %d bytes for help_str",h_size); + help_str = (char *)cpl_malloc((size_t)h_size); + if (help_str == NULL) { + cpl_msg_error(er_func, + "Could not allocate %d bytes for help_str", + h_size); e_code = CPL_ERROR_ILLEGAL_OUTPUT; goto plugin_deinit; } - (void) strcpy (help_str, "Recipe: "); + (void)strcpy(help_str, "Recipe: "); countr = 9; - cpp = cpl_plugin_get_name ((cpl_plugin *) trecipe); - n = (int) strlen(cpp); + cpp = cpl_plugin_get_name((cpl_plugin *)trecipe); + n = (int)strlen(cpp); countr += (5 + n); - if (countr > h_size) - { /* allocate more space */ + if (countr > h_size) { /* allocate more space */ h_size = countr + 120; - er_enlarge(er_func,&help_str,h_size); + er_enlarge(er_func, &help_str, h_size); } - (void) strcat (help_str, cpp); - (void) strcat (help_str, " -- "); + (void)strcat(help_str, cpp); + (void)strcat(help_str, " -- "); - cpp = cpl_plugin_get_synopsis ((cpl_plugin *) trecipe); - n = (int) strlen(cpp) + countr; - if (n > h_size) - { /* allocate more space */ + cpp = cpl_plugin_get_synopsis((cpl_plugin *)trecipe); + n = (int)strlen(cpp) + countr; + if (n > h_size) { /* allocate more space */ h_size = n + 120; - er_enlarge(er_func,&help_str,h_size); + er_enlarge(er_func, &help_str, h_size); } - (void) strcat (help_str, cpp); - printf ("%s\n\n", er_strutils_split (help_str, 2, er_strutils_termwidth ())); - - msg_level = cpl_msg_get_level(); /* test, if we are in debug mode */ - if (msg_level == CPL_MSG_DEBUG) - { - (void) strcpy (help_str, "Library: "); - countr = 12; /* length of above */ - n = countr + (int) strlen(library_path); - if (n > h_size) - { /* allocate more space */ + (void)strcat(help_str, cpp); + printf("%s\n\n", + er_strutils_split(help_str, 2, er_strutils_termwidth())); + + msg_level = cpl_msg_get_level(); /* test, if we are in debug mode */ + if (msg_level == CPL_MSG_DEBUG) { + (void)strcpy(help_str, "Library: "); + countr = 12; /* length of above */ + n = countr + (int)strlen(library_path); + if (n > h_size) { /* allocate more space */ h_size = n + 120; - er_enlarge(er_func,&help_str,h_size); + er_enlarge(er_func, &help_str, h_size); } - (void) strcat (help_str, library_path); - printf ("%s\n\n", er_strutils_split (help_str, 2, er_strutils_termwidth ())); + (void)strcat(help_str, library_path); + printf("%s\n\n", + er_strutils_split(help_str, 2, er_strutils_termwidth())); } /* Display the actual help for the plugin */ @@ -1288,49 +1254,52 @@ /* Explain why the esorex help doesn't appear */ - (void) strcpy (tmp_buf,"For help on the options of " PACKAGE - " itself, please use the command '" PACKAGE " --help' " - "(that is, without specifying any recipe name). " - "For more information about the recipe, one can also use " - "the command '" PACKAGE " --man-page "); - countr = (int) strlen(tmp_buf); + (void)strcpy( + tmp_buf, + "For help on the options of " PACKAGE + " itself, please use the command '" PACKAGE " --help' " + "(that is, without specifying any recipe name). " + "For more information about the recipe, one can also use " + "the command '" PACKAGE " --man-page "); + countr = (int)strlen(tmp_buf); - cpp = cpl_plugin_get_name ((cpl_plugin *) trecipe); - n = (int) strlen(cpp) + countr + 4; + cpp = cpl_plugin_get_name((cpl_plugin *)trecipe); + n = (int)strlen(cpp) + countr + 4; - if (n > h_size) - { + if (n > h_size) { h_size = n; - er_enlarge("plugin_process_plugin",&help_str,h_size); + er_enlarge("plugin_process_plugin", &help_str, h_size); } - (void) strcpy (help_str, tmp_buf); - (void) strcat (help_str, cpp); - (void) strcat (help_str, "'."); - (void) printf - ("%s\n", er_strutils_split (help_str, 0, er_strutils_termwidth ())); + (void)strcpy(help_str, tmp_buf); + (void)strcat(help_str, cpp); + (void)strcat(help_str, "'."); + (void)printf("%s\n", er_strutils_split(help_str, 0, + er_strutils_termwidth())); - goto plugin_deinit; /* avoid plugin execution */ + goto plugin_deinit; /* avoid plugin execution */ } /* Check if we want to display the plugin parameters */ - p = cpl_parameterlist_find (caller_parameters,PACKAGE_RESOURCE ".params"); - flag_params = cpl_parameter_get_bool (p); - if (flag_params != 0) - { - if (er_paramutils_print_list(trecipe->parameters,"Recipe Parameters") != 0) - { - cpl_msg_error (er_func,"Unable to print the recipe parameter list\n"); + p = cpl_parameterlist_find(caller_parameters, + PACKAGE_RESOURCE ".params"); + flag_params = cpl_parameter_get_bool(p); + if (flag_params != 0) { + if (er_paramutils_print_list(trecipe->parameters, + "Recipe Parameters") != 0) { + cpl_msg_error(er_func, + "Unable to print the recipe parameter list\n"); e_code = CPL_ERROR_INCOMPATIBLE_INPUT; } else - goto plugin_deinit; /* avoid plugin execution */ + goto plugin_deinit; /* avoid plugin execution */ } /* Check if we don't want to cleanup after processing (for debugging) */ - p = cpl_parameterlist_find(caller_parameters, PACKAGE_RESOURCE ".unload-plugin"); + p = cpl_parameterlist_find(caller_parameters, + PACKAGE_RESOURCE ".unload-plugin"); f_val_unload_plugin = cpl_parameter_get_bool(p); @@ -1338,13 +1307,15 @@ * Set product signature bit mask */ - p = cpl_parameterlist_find(caller_parameters, PACKAGE_RESOURCE ".no-checksum"); + p = cpl_parameterlist_find(caller_parameters, + PACKAGE_RESOURCE ".no-checksum"); if (cpl_parameter_get_bool(p) == TRUE) { signature_mask &= ~CPL_DFS_SIGNATURE_CHECKSUM; } - p = cpl_parameterlist_find(caller_parameters, PACKAGE_RESOURCE ".no-datamd5"); + p = cpl_parameterlist_find(caller_parameters, + PACKAGE_RESOURCE ".no-datamd5"); if (cpl_parameter_get_bool(p) == TRUE) { signature_mask &= ~CPL_DFS_SIGNATURE_DATAMD5; @@ -1355,124 +1326,119 @@ * Run Plugin Execute - if all went well until here... */ - if (e_code == 0) - { - plugin_func_exec = cpl_plugin_get_exec ((cpl_plugin *) trecipe); + if (e_code == 0) { + plugin_func_exec = cpl_plugin_get_exec((cpl_plugin *)trecipe); - if (plugin_func_exec != NULL) - { /* We have a pointer, so run the plugin */ + if (plugin_func_exec != + NULL) { /* We have a pointer, so run the plugin */ const char *recipe_name; - recipe_name = cpl_plugin_get_name ((cpl_plugin *) trecipe); - cpl_msg_set_domain (recipe_name); - e_code = plugin_func_exec ((cpl_plugin *) trecipe); - cpl_msg_set_domain (PACKAGE); - if (e_code != 0) - { - cpl_msg_error (er_func,"Execution of recipe '%s' failed, status = %d", - recipe_name,e_code); + recipe_name = cpl_plugin_get_name((cpl_plugin *)trecipe); + cpl_msg_set_domain(recipe_name); + e_code = plugin_func_exec((cpl_plugin *)trecipe); + cpl_msg_set_domain(PACKAGE); + if (e_code != 0) { + cpl_msg_error( + er_func, "Execution of recipe '%s' failed, status = %d", + recipe_name, e_code); } } - else - { + else { /* NULL-pointer, so we simply set an error */ e_code = CPL_ERROR_INCOMPATIBLE_INPUT; } } - if (e_code == 0) /* successful execution of recipe */ + if (e_code == 0) /* successful execution of recipe */ { - p = cpl_parameterlist_find (caller_parameters, - PACKAGE_RESOURCE ".output-dir"); - val_output_dir = cpl_parameter_get_string (p); + p = cpl_parameterlist_find(caller_parameters, + PACKAGE_RESOURCE ".output-dir"); + val_output_dir = cpl_parameter_get_string(p); ForceNull(val_output_dir) - p = cpl_parameterlist_find (caller_parameters, - PACKAGE_RESOURCE ".link-dir"); - val_link_dir = cpl_parameter_get_string (p); + p = cpl_parameterlist_find(caller_parameters, + PACKAGE_RESOURCE ".link-dir"); + val_link_dir = cpl_parameter_get_string(p); ForceNull(val_link_dir) - p = cpl_parameterlist_find (caller_parameters, - PACKAGE_RESOURCE ".output-prefix"); - val_output_mask = cpl_parameter_get_string (p); + p = cpl_parameterlist_find(caller_parameters, + PACKAGE_RESOURCE ".output-prefix"); + val_output_mask = cpl_parameter_get_string(p); ForceNull(val_output_mask) - p = cpl_parameterlist_find (caller_parameters, - PACKAGE_RESOURCE ".output-readonly"); - flag_readonly = cpl_parameter_get_bool (p); - - p = cpl_parameterlist_find (caller_parameters, - PACKAGE_RESOURCE ".suppress-prefix"); - flag_noprefix = cpl_parameter_get_bool (p); - - p = cpl_parameterlist_find (caller_parameters, - PACKAGE_RESOURCE ".suppress-link"); - flag_nolink = cpl_parameter_get_bool (p); + p = cpl_parameterlist_find(caller_parameters, + PACKAGE_RESOURCE ".output-readonly"); + flag_readonly = cpl_parameter_get_bool(p); + + p = cpl_parameterlist_find(caller_parameters, + PACKAGE_RESOURCE ".suppress-prefix"); + flag_noprefix = cpl_parameter_get_bool(p); + + p = cpl_parameterlist_find(caller_parameters, + PACKAGE_RESOURCE ".suppress-link"); + flag_nolink = cpl_parameter_get_bool(p); /* Move all product files to output directory */ e_code = _move_products(trecipe->frames, (char *)val_output_dir, - (char *)val_output_mask, (char *)val_link_dir, - signature_mask, + (char *)val_output_mask, + (char *)val_link_dir, signature_mask, flag_noprefix, flag_nolink, flag_readonly); - if (e_code != 0) cpl_msg_error (er_func, - "An error occurred while trying to move the output products"); + if (e_code != 0) + cpl_msg_error(er_func, "An error occurred while trying to move " + "the output products"); } - else /* recipe failed, only get correct MD5 sum */ - { /* for all product files created anyway */ - if (e_code != -99999) - { - ii = _upda_products (trecipe->frames, signature_mask); + else /* recipe failed, only get correct MD5 sum */ + { /* for all product files created anyway */ + if (e_code != -99999) { + ii = _upda_products(trecipe->frames, signature_mask); } } /* Run PAF creation */ - p = cpl_parameterlist_find (caller_parameters, - PACKAGE_RESOURCE ".paf-config"); - val_paf_config = cpl_parameter_get_string (p); - ForceNull(val_paf_config) - if(val_paf_config != NULL) + p = cpl_parameterlist_find(caller_parameters, + PACKAGE_RESOURCE ".paf-config"); + val_paf_config = cpl_parameter_get_string(p); + ForceNull(val_paf_config) if (val_paf_config != NULL) { - if (e_code == 0) /* successful execution of recipe and product move*/ + if (e_code == + 0) /* successful execution of recipe and product move*/ { e_code = er_create_recipe_pafs(trecipe->frames, trecipe->interface.name, val_paf_config); - if (e_code != 0) - { - cpl_msg_error (er_func,"Cannot create paf files, status = %d", - e_code); + if (e_code != 0) { + cpl_msg_error(er_func, + "Cannot create paf files, status = %d", + e_code); } } - else - { - cpl_msg_warning (er_func,"Writing of paf files omitted" - " due to previous errors"); + else { + cpl_msg_warning(er_func, "Writing of paf files omitted" + " due to previous errors"); } } /* Write output sof */ - p = cpl_parameterlist_find (caller_parameters, - PACKAGE_RESOURCE ".products-sof"); - val_products_sof = cpl_parameter_get_string (p); - ForceNull(val_products_sof) - if(val_products_sof != NULL) + p = cpl_parameterlist_find(caller_parameters, + PACKAGE_RESOURCE ".products-sof"); + val_products_sof = cpl_parameter_get_string(p); + ForceNull(val_products_sof) if (val_products_sof != NULL) { - if (e_code == 0) /* successful execution of recipe and product move*/ + if (e_code == + 0) /* successful execution of recipe and product move*/ { - cpl_frameset * output_frames; - cpl_frame * frame; + cpl_frameset *output_frames; + cpl_frame *frame; cpl_frameset_iterator *it = - cpl_frameset_iterator_new(trecipe->frames); + cpl_frameset_iterator_new(trecipe->frames); output_frames = cpl_frameset_new(); - while ((frame = cpl_frameset_iterator_get(it)) != NULL) - { - if (cpl_frame_get_group (frame) == CPL_FRAME_GROUP_PRODUCT) - { + while ((frame = cpl_frameset_iterator_get(it)) != NULL) { + if (cpl_frame_get_group(frame) == CPL_FRAME_GROUP_PRODUCT) { cpl_frameset_insert(output_frames, cpl_frame_duplicate(frame)); } @@ -1481,88 +1447,85 @@ cpl_frameset_iterator_delete(it); - if(strlen(val_products_sof)>5 && - strncmp(val_products_sof + strlen(val_products_sof) - 5, - ".json", 5) == 0 ) - e_code = er_frameset_to_json(output_frames, val_products_sof); + if (strlen(val_products_sof) > 5 && + strncmp(val_products_sof + strlen(val_products_sof) - 5, + ".json", 5) == 0) + e_code = + er_frameset_to_json(output_frames, val_products_sof); else - e_code = er_frameset_to_text(output_frames, val_products_sof); + e_code = + er_frameset_to_text(output_frames, val_products_sof); cpl_frameset_delete(output_frames); - if (e_code != 0) - { - cpl_msg_error (er_func,"Cannot create output sof file, " - "status = %d", - e_code); + if (e_code != 0) { + cpl_msg_error(er_func, + "Cannot create output sof file, " + "status = %d", + e_code); } } - else - { - cpl_msg_warning (er_func,"Writing of output sof omitted" - " due to previous errors"); + else { + cpl_msg_warning(er_func, "Writing of output sof omitted" + " due to previous errors"); } } /* Run Plugin Deinitialisation... */ - plugin_deinit: + plugin_deinit: - plugin_func_deinit = cpl_plugin_get_deinit ((cpl_plugin *) trecipe); + plugin_func_deinit = cpl_plugin_get_deinit((cpl_plugin *)trecipe); - if (plugin_func_deinit != NULL) - { - cpl_msg_set_domain (cpl_plugin_get_name ((cpl_plugin *) trecipe)); - e_code2 = plugin_func_deinit ((cpl_plugin *) trecipe); - cpl_msg_set_domain (PACKAGE); + if (plugin_func_deinit != NULL) { + cpl_msg_set_domain(cpl_plugin_get_name((cpl_plugin *)trecipe)); + e_code2 = plugin_func_deinit((cpl_plugin *)trecipe); + cpl_msg_set_domain(PACKAGE); } - if (e_code2 == 0) - { + if (e_code2 == 0) { /* For now deinitialization is empty */ } /* If out main err.code is "OKAY", then use the deinit one, */ /* (otherwise, preserve the original error). */ - if (e_code == 0) e_code = e_code2; + if (e_code == 0) + e_code = e_code2; } - if ((flag_time_plugin != 0) && (flag_plugin_found != 0)) - { + if ((flag_time_plugin != 0) && (flag_plugin_found != 0)) { double fsz = 0.0; int infile_count = 0; cpl_frame *frame = NULL; const char *input_name = NULL; plugin_time_end = cpl_test_get_walltime(); - if (plugin_time_end > plugin_time_start) - { - plugin_time_end -= plugin_time_start; /* reuse for time difference */ + if (plugin_time_end > plugin_time_start) { + plugin_time_end -= + plugin_time_start; /* reuse for time difference */ } - else - { + else { plugin_time_end = -1.0; } /* loop again over frameset - now, all tags should be set by the recipe */ - if (holdme != NULL) - { + if (holdme != NULL) { cpl_frameset_iterator *it = cpl_frameset_iterator_new(holdme); - while ((frame = cpl_frameset_iterator_get(it)) != NULL) - { - if (cpl_frame_get_group (frame) == CPL_FRAME_GROUP_RAW) - { /* Get the filename as specified by the frame */ - input_name = cpl_frame_get_filename (frame); - if (add_size (input_name,&fsz) != 0) /* accumulate size (in bytes) of raw input frames */ + while ((frame = cpl_frameset_iterator_get(it)) != NULL) { + if (cpl_frame_get_group(frame) == + CPL_FRAME_GROUP_RAW) { /* Get the filename as specified by the frame */ + input_name = cpl_frame_get_filename(frame); + if (add_size(input_name, &fsz) != + 0) /* accumulate size (in bytes) of raw input frames */ { - cpl_msg_warning(er_func,"could not get size of %s\n",input_name); + cpl_msg_warning(er_func, "could not get size of %s\n", + input_name); } - else - { - infile_count ++; + else { + infile_count++; } } cpl_frameset_iterator_advance(it, 1); @@ -1571,62 +1534,62 @@ cpl_frameset_iterator_delete(it); } - if ((plugin_time_end > 0.0) && (fsz > 0.0)) - { - cpl_msg_info (er_func, "Recipe operation(s) took %14.3g seconds to complete.", - plugin_time_end); + if ((plugin_time_end > 0.0) && (fsz > 0.0)) { + cpl_msg_info(er_func, + "Recipe operation(s) took %14.3g seconds to complete.", + plugin_time_end); } - if (fsz > 0.0) - { + if (fsz > 0.0) { fsz *= 0.000001; if (infile_count > 1) - cpl_msg_info (er_func, "Total size of %d raw input frames = %8.2f MB\n",infile_count,fsz); + cpl_msg_info(er_func, + "Total size of %d raw input frames = %8.2f MB\n", + infile_count, fsz); else - cpl_msg_info (er_func, "Size of single raw input frame = %8.2f MB\n",fsz); + cpl_msg_info(er_func, + "Size of single raw input frame = %8.2f MB\n", + fsz); - if (plugin_time_end > 0.0) - { + if (plugin_time_end > 0.0) { fsz /= plugin_time_end; - cpl_msg_info (er_func, "=> processing rate of %8.2f MB/sec \n",fsz); + cpl_msg_info(er_func, "=> processing rate of %8.2f MB/sec \n", + fsz); } } - } /* Terminate CPL messaging */ - cleanup: +cleanup: /* currently cpl_msg_stop_log () always returns CPL_ERROR_NONE ... 080613 */ - if (cpl_msg_stop_log () != CPL_ERROR_NONE) - cpl_msg_error (er_func, "An error was encountered while closing the logfile"); + if (cpl_msg_stop_log() != CPL_ERROR_NONE) + cpl_msg_error(er_func, + "An error was encountered while closing the logfile"); - else - { /* Move log file... */ - char tmpbuf[FILEMAX+12]; + else { /* Move log file... */ + char tmpbuf[FILEMAX + 12]; - if (getcwd (tmpbuf, (size_t) FILEMAX) == NULL) - { + if (getcwd(tmpbuf, (size_t)FILEMAX) == NULL) { cpl_msg_error(er_func, "cannot get current working directory"); e_code = errno; } - else - { - - (void) strcat (tmpbuf, "/.logfile"); + else { + (void)strcat(tmpbuf, "/.logfile"); - if (fileutils_file_exists(tmpbuf) != 0) - { /* .logfile exists ... */ - n = fileutils_copy(tmpbuf,log_file_name_full); /* copy .logfile to "real" log file */ - if (n < 0) - { - (void) printf("we could not copy .logfile to %s (err-code = %d)\n", - log_file_name_full,n); + if (fileutils_file_exists(tmpbuf) != 0) { /* .logfile exists ... */ + n = fileutils_copy( + tmpbuf, + log_file_name_full); /* copy .logfile to "real" log file */ + if (n < 0) { + (void)printf( + "we could not copy .logfile to %s (err-code = %d)\n", + log_file_name_full, n); } - else - { /* get rid of .logfile */ - if (n == 0) (void) unlink(tmpbuf); + else { /* get rid of .logfile */ + if (n == 0) + (void)unlink(tmpbuf); } } } @@ -1635,37 +1598,41 @@ /* free memory again */ - if (help_str != NULL) cpl_free (help_str); + if (help_str != NULL) + cpl_free(help_str); - if (log_file_name_full != NULL) cpl_free (log_file_name_full); - if (plugin_conf_file_global != NULL) cpl_free (plugin_conf_file_global); - if (plugin_conf_file_local != NULL) cpl_free (plugin_conf_file_local); + if (log_file_name_full != NULL) + cpl_free(log_file_name_full); + if (plugin_conf_file_global != NULL) + cpl_free(plugin_conf_file_global); + if (plugin_conf_file_local != NULL) + cpl_free(plugin_conf_file_local); + + if (val_recipe_dirs != NULL) + cx_strfreev(val_recipe_dirs); + if (list_of_pllib_names != NULL) + er_stringarray_delete(list_of_pllib_names); - if (val_recipe_dirs != NULL) cx_strfreev (val_recipe_dirs); - if (list_of_pllib_names != NULL) er_stringarray_delete (list_of_pllib_names); - - if (tplugin != NULL) cpl_plugin_delete (tplugin); + if (tplugin != NULL) + cpl_plugin_delete(tplugin); if ((module != NULL) && (f_val_unload_plugin != 0)) { - lt_dlclose (module); + lt_dlclose(module); } - if (t2recipe != NULL) - { /* we have a version 2 recipe! */ - cpl_frameset_delete (trecipe->frames); - cpl_plugin_delete ((cpl_plugin *) t2recipe); + if (t2recipe != NULL) { /* we have a version 2 recipe! */ + cpl_frameset_delete(trecipe->frames); + cpl_plugin_delete((cpl_plugin *)t2recipe); } - else if (trecipe != NULL) - { /* trecipe->parameters handled by plugin */ - cpl_frameset_delete (trecipe->frames); - cpl_plugin_delete ((cpl_plugin *) trecipe); + else if (trecipe != NULL) { /* trecipe->parameters handled by plugin */ + cpl_frameset_delete(trecipe->frames); + cpl_plugin_delete((cpl_plugin *)trecipe); } - if (e_code == -99999) e_code = 0; + if (e_code == -99999) + e_code = 0; return e_code; -} /* End of plugin_process_plugin() */ - - +} /* End of plugin_process_plugin() */ /**********************************************************************/ @@ -1682,26 +1649,25 @@ */ /**********************************************************************/ -void er_enlarge (const char *fn, char **pptr, int msize) +void +er_enlarge(const char *fn, char **pptr, int msize) { - void *newptr, *ptr; + void *newptr, *ptr; - ptr = (void *) *pptr; /* get address to free */ + ptr = (void *)*pptr; /* get address to free */ - newptr = cpl_realloc(ptr,(size_t) msize); - if (newptr == NULL) /* couldn't get the memory... */ + newptr = cpl_realloc(ptr, (size_t)msize); + if (newptr == NULL) /* couldn't get the memory... */ { - cpl_msg_error (fn, "Could not allocate %d bytes - fatal error", msize); - exit (EXIT_FAILURE); + cpl_msg_error(fn, "Could not allocate %d bytes - fatal error", msize); + exit(EXIT_FAILURE); } - *pptr = (char *) newptr; + *pptr = (char *)newptr; } /**@}*/ /* End of file */ - - diff -Nru esorex-3.13.5+ds/src/er_plugin.h esorex-3.13.6+ds/src/er_plugin.h --- esorex-3.13.5+ds/src/er_plugin.h 2021-06-02 15:06:13.000000000 +0000 +++ esorex-3.13.6+ds/src/er_plugin.h 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 European Southern Observatory * * 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 @@ -29,19 +29,23 @@ CPL_BEGIN_DECLS -extern int plugin_process_plugin(cpl_parameterlist *, char *, - er_stringarray_t *, int, char **); +extern int plugin_process_plugin(cpl_parameterlist *, + char *, + er_stringarray_t *, + int, + char **); -extern cpl_msg_severity message_severity(cpl_parameterlist *param_list, - int flag); +extern cpl_msg_severity +message_severity(cpl_parameterlist *param_list, int flag); extern void er_enlarge(const char *fn, char **pptr, int msize); extern int mysscanf(char *myline, char *path, char *tag, char *group); -extern cpl_frameset *er_frameset_load(const char *name, cpl_frameset *set, +extern cpl_frameset *er_frameset_load(const char *name, + cpl_frameset *set, int check_input_files_flag); CPL_END_DECLS -#endif /* ER_PLUGIN_H */ +#endif /* ER_PLUGIN_H */ diff -Nru esorex-3.13.5+ds/src/er_pluginlist.c esorex-3.13.6+ds/src/er_pluginlist.c --- esorex-3.13.5+ds/src/er_pluginlist.c 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/er_pluginlist.c 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 European Southern Observatory * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif #include @@ -47,16 +47,16 @@ #include "er_python.h" #endif -extern int MyOS; /* 1 = Linux, 0 = Mac OSX */ +extern int MyOS; /* 1 = Linux, 0 = Mac OSX */ /* * Symbolic constants used in the search_directory() function */ -#define INDENT_INCR 2 /* Amount to increment per indentation */ -#define INDENT_STR "| " /* String to use for each indentation */ -#define ENTRY_STR "+-" /* String to use at the start of each entry */ -#define SEP_STR "/" /* Directory separator ("/" on UNIX) */ +#define INDENT_INCR 2 /* Amount to increment per indentation */ +#define INDENT_STR "| " /* String to use for each indentation */ +#define ENTRY_STR "+-" /* String to use at the start of each entry */ +#define SEP_STR "/" /* Directory separator ("/" on UNIX) */ #ifdef ENABLE_PYTHON_RECIPES @@ -94,37 +94,37 @@ */ /**********************************************************************/ -static int plugin_valid_filename (const char *full_filename) +static int +plugin_valid_filename(const char *full_filename) { - char *ext; /* File extension */ + char *ext; /* File extension */ /* If there was no filename, then return */ - if (full_filename == NULL) return 0; + if (full_filename == NULL) + return 0; /* Get the file extension */ - ext = strrchr (full_filename, '.'); + ext = strrchr(full_filename, '.'); /* Reject any file which doesn't have the correct file extension */ - if (ext == NULL) return 0; + if (ext == NULL) + return 0; /* Check whether the filename extension indicates a valid module */ - if (strcmp(ext, LT_MODULE_EXT) == 0) - { + if (strcmp(ext, LT_MODULE_EXT) == 0) { return 1; } #ifdef ENABLE_PYTHON_RECIPES - else if (strcmp(ext, PYTHON_MODULE_FILE_EXT) == 0) - { + else if (strcmp(ext, PYTHON_MODULE_FILE_EXT) == 0) { return 2; } #endif - else - { + else { /* Invalid file extension. */ return 0; } @@ -148,35 +148,36 @@ */ /**********************************************************************/ -static int plugin_valid_sharedlib (const char *full_filename) +static int +plugin_valid_sharedlib(const char *full_filename) { - lt_dlhandle module = NULL; /* Handle to the dynamic library */ + lt_dlhandle module = NULL; /* Handle to the dynamic library */ - int (*get_plugin_list) (cpl_pluginlist *) = NULL; + int (*get_plugin_list)(cpl_pluginlist *) = NULL; /* * Attempt to open the file as a dynamic library module */ - module = lt_dlopen (full_filename); + module = lt_dlopen(full_filename); /* If this didn't load properly, then return */ - if (!module) - { - const char *dl_errstring; + if (!module) { + const char *dl_errstring; dl_errstring = lt_dlerror(); - cpl_msg_warning (er_func, - "lt_dlopen (%s) returned NULL,\nlt_dlerror() = %s\n", - full_filename,dl_errstring); + cpl_msg_warning(er_func, + "lt_dlopen (%s) returned NULL,\nlt_dlerror() = %s\n", + full_filename, dl_errstring); return 0; } /* Check that it has the required plugin function */ - get_plugin_list = (int (*)()) lt_dlsym (module, "cpl_plugin_get_info"); - lt_dlclose (module); /* Close the module */ + get_plugin_list = (int (*)())lt_dlsym(module, "cpl_plugin_get_info"); + lt_dlclose(module); /* Close the module */ - if (get_plugin_list == NULL) return 0; + if (get_plugin_list == NULL) + return 0; /* If we get this far, then it was obviously a valid plugin file */ return 1; @@ -195,19 +196,19 @@ */ /**********************************************************************/ -static int is_python_module (const char * filename) +static int +is_python_module(const char *filename) { assert(filename != NULL); size_t len = strlen(filename); size_t extlen = strlen(PYTHON_MODULE_FILE_EXT); - if (len < extlen) return 0; - if (strcmp(filename + (len - extlen), PYTHON_MODULE_FILE_EXT) == 0) - { + if (len < extlen) + return 0; + if (strcmp(filename + (len - extlen), PYTHON_MODULE_FILE_EXT) == 0) { return 1; } - else - { + else { return 0; } } @@ -244,21 +245,22 @@ */ /**********************************************************************/ -static void search_directory (const char * dirname, - er_stringarray_t * list_of_pllibs, - er_stringarray_t * list_of_pypllibs ) +static void +search_directory(const char *dirname, + er_stringarray_t *list_of_pllibs, + er_stringarray_t *list_of_pypllibs) { - struct stat finfo; /* File information */ - struct dirent *entry; /* Entry in a given directory listing */ + struct stat finfo; /* File information */ + struct dirent *entry; /* Entry in a given directory listing */ - DIR *dp; /* Pointer to a directory */ - char *fqfn; /* Fully qualified filename (path+file+ext) */ + DIR *dp; /* Pointer to a directory */ + char *fqfn; /* Fully qualified filename (path+file+ext) */ - static int indent = 0; /* Level of indentation */ - int valid; /* Is the specified file a valid plugin file */ + static int indent = 0; /* Level of indentation */ + int valid; /* Is the specified file a valid plugin file */ - int filename_len = 4096; /* the "usual" FILENAME_MAX */ + int filename_len = 4096; /* the "usual" FILENAME_MAX */ int status; int ldir, lentry; @@ -268,81 +270,73 @@ assert(list_of_pypllibs != NULL); - dp = opendir (dirname); /* Open the directory */ - if (dp == NULL) - { - cpl_msg_warning (er_func, "Unable to open directory %s", dirname); + dp = opendir(dirname); /* Open the directory */ + if (dp == NULL) { + cpl_msg_warning(er_func, "Unable to open directory %s", dirname); return; } - ldir = (int) strlen(dirname); - fqfn = cpl_malloc ((size_t) filename_len); - if (fqfn == NULL) - { + ldir = (int)strlen(dirname); + fqfn = cpl_malloc((size_t)filename_len); + if (fqfn == NULL) { closedir(dp); return; } - while ((entry = readdir (dp)) != NULL) - { + while ((entry = readdir(dp)) != NULL) { /* Ignore hidden files, current directory and parent directory */ - if (entry->d_name[0] == '.') continue; + if (entry->d_name[0] == '.') + continue; /* We have a directory, so recursively search it with this function */ - lentry = (int) strlen(entry->d_name); - if ((lentry+ldir+4) > filename_len) /* ensure enough memory is allocated */ + lentry = (int)strlen(entry->d_name); + if ((lentry + ldir + 4) > + filename_len) /* ensure enough memory is allocated */ { - filename_len = (lentry+ldir+4) * 2; - er_enlarge("search_directory",&fqfn,filename_len); + filename_len = (lentry + ldir + 4) * 2; + er_enlarge("search_directory", &fqfn, filename_len); } - (void) sprintf (fqfn, "%s%s%s", dirname, SEP_STR, entry->d_name); + (void)sprintf(fqfn, "%s%s%s", dirname, SEP_STR, entry->d_name); /* Get information about the current entry (file) */ - status = stat (fqfn, &finfo); - if (status == 0) - { - if (S_ISREG (finfo.st_mode)) - { - valid = plugin_valid_filename (fqfn); - if (valid == 1) - { + status = stat(fqfn, &finfo); + if (status == 0) { + if (S_ISREG(finfo.st_mode)) { + valid = plugin_valid_filename(fqfn); + if (valid == 1) { /* If we get this far, then we've possibly found a shared library plugin */ /* Add it to the list of plugins that we have so far */ - er_stringarray_append (list_of_pllibs, fqfn); + er_stringarray_append(list_of_pllibs, fqfn); } #ifdef ENABLE_PYTHON_RECIPES - else if (valid == 2) - { + else if (valid == 2) { /* Found a Python module file instead. */ - er_stringarray_append (list_of_pypllibs, fqfn); + er_stringarray_append(list_of_pypllibs, fqfn); } #endif - } - else if (S_ISDIR (finfo.st_mode)) - { + else if (S_ISDIR(finfo.st_mode)) { /* Recursively search any subdirectory that we find */ - search_directory (fqfn, list_of_pllibs, list_of_pypllibs); + search_directory(fqfn, list_of_pllibs, list_of_pypllibs); } - } /* End if valid status */ - } /* End of while */ + } /* End if valid status */ + } /* End of while */ /* Release the memory allocated to the filename */ - cpl_free (fqfn); - - indent -= INDENT_INCR; /* Decrement the indentation again */ - closedir (dp); + cpl_free(fqfn); -} /* End of search_directory() */ + indent -= INDENT_INCR; /* Decrement the indentation again */ + closedir(dp); +} /* End of search_directory() */ /**********************************************************************/ @@ -360,25 +354,22 @@ */ /**********************************************************************/ -static void append_list_unique(er_stringarray_t * src, er_stringarray_t * dest) +static void +append_list_unique(er_stringarray_t *src, er_stringarray_t *dest) { int i1 = 0, i2 = 0; - for (i1=0; i1 (MAXSTRLENCONF-1)) - { - cpl_msg_error (er_func, "size of plugin lib > %d ...", MAXSTRLENCONF); + for (i = 0; i < er_stringarray_size(list_of_pllibs); i++) { + cptr = er_stringarray_get(list_of_pllibs, i); + m = (int)strlen(cptr); + if (m > (MAXSTRLENCONF - 1)) { + cpl_msg_error(er_func, "size of plugin lib > %d ...", + MAXSTRLENCONF); return 0; } - (void) strcpy(fully_qualified_library_name, cptr); + (void)strcpy(fully_qualified_library_name, cptr); #ifdef ENABLE_PYTHON_RECIPES is_shared_lib = !is_python_module(fully_qualified_library_name); - if (is_shared_lib) - { - + if (is_shared_lib) { #endif /* try to open library */ - module = lt_dlopen (fully_qualified_library_name); - if (!module) - { - cpl_msg_error (er_func, "Could not open %s: %s", - fully_qualified_library_name, lt_dlerror ()); + module = lt_dlopen(fully_qualified_library_name); + if (!module) { + cpl_msg_error(er_func, "Could not open %s: %s", + fully_qualified_library_name, lt_dlerror()); return 0; } /* get plugin list */ - get_plugin_list = (int (*)()) lt_dlsym (module, "cpl_plugin_get_info"); + get_plugin_list = + (int (*)())lt_dlsym(module, "cpl_plugin_get_info"); /* Cannot use lt_dlerror due to bug in 1.4.2 version of libtool */ - if (get_plugin_list == NULL) - { - cpl_msg_error (er_func, "Could not find cpl_plugin_get_info() " - "index function for plugin library (%s): %s", - fully_qualified_library_name, lt_dlerror ()); + if (get_plugin_list == NULL) { + cpl_msg_error(er_func, + "Could not find cpl_plugin_get_info() " + "index function for plugin library (%s): %s", + fully_qualified_library_name, lt_dlerror()); lt_dlclose(module); return 0; } #ifdef ENABLE_PYTHON_RECIPES - } - else - { + else { /* In this case we are dealing with a Python module. Need to select the Python module and assign the get_plugin_list function pointer to the special interfacing function that will communicate with the Python plugins. */ - if (er_python_select_module(fully_qualified_library_name) - != CPL_ERROR_NONE) - { + if (er_python_select_module(fully_qualified_library_name) != + CPL_ERROR_NONE) { cpl_msg_error(er_func, "%s", cpl_error_get_message()); return 0; } @@ -609,72 +594,71 @@ /* Make a pluginlist containing all the plugins in the library */ - pl_list = cpl_pluginlist_new (); - e_code = get_plugin_list (pl_list); - if (e_code != 0) - { - cpl_msg_warning (er_func, - "Unexpected error (%d) in recovering a pluginlist from " - "library '%s'", e_code, - fully_qualified_library_name); + pl_list = cpl_pluginlist_new(); + e_code = get_plugin_list(pl_list); + if (e_code != 0) { + cpl_msg_warning( + er_func, + "Unexpected error (%d) in recovering a pluginlist from " + "library '%s'", + e_code, fully_qualified_library_name); } /* Check the "one-plugin-per-library" assumption */ - m = cpl_pluginlist_get_size (pl_list); - if (m == 0) - { - cpl_msg_warning (er_func, "No plugins contained within " - "library '%s'", fully_qualified_library_name); - } - else if (m > 1) - { - cpl_msg_warning (er_func, "Multiple plugins contained within " - "library '%s'", fully_qualified_library_name); + m = cpl_pluginlist_get_size(pl_list); + if (m == 0) { + cpl_msg_warning(er_func, + "No plugins contained within " + "library '%s'", + fully_qualified_library_name); + } + else if (m > 1) { + cpl_msg_warning(er_func, + "Multiple plugins contained within " + "library '%s'", + fully_qualified_library_name); } /* Once we have a valid library, fetch the plugin out of it */ - pl = cpl_pluginlist_find (pl_list, plugin_name); + pl = cpl_pluginlist_find(pl_list, plugin_name); /* Double check again, to make sure we got it */ - if (pl != NULL) - { /* Increment a counter of all instances that we've found */ + if (pl != + NULL) { /* Increment a counter of all instances that we've found */ num_copies++; /* Get the version number of this plugin */ - this_version = cpl_plugin_get_version (pl); + this_version = cpl_plugin_get_version(pl); /* Make sure the version number is value (i.e. non-zero) */ - if (this_version == 0) - { - cpl_msg_warning (er_func, - "Recipe '%s' (in library '%s') has an invalid version number", - plugin_name, fully_qualified_library_name); + if (this_version == 0) { + cpl_msg_warning(er_func, + "Recipe '%s' (in library '%s') has an invalid " + "version number", + plugin_name, fully_qualified_library_name); } /* Now see if this version is later than the best we have so far */ - if (this_version > best_version) - { /* size check done above ... */ - (void) strcpy(libpath, fully_qualified_library_name); + if (this_version > best_version) { /* size check done above ... */ + (void)strcpy(libpath, fully_qualified_library_name); best_version = this_version; num_best = 1; } - else if (this_version == best_version) - { + else if (this_version == best_version) { num_best++; } } - cpl_pluginlist_delete (pl_list); + cpl_pluginlist_delete(pl_list); #ifdef ENABLE_PYTHON_RECIPES - if (is_shared_lib) - { + if (is_shared_lib) { lt_dlclose(module); } @@ -683,27 +667,27 @@ lt_dlclose(module); #endif - } - if (num_best > 1) - { - cpl_msg_error (er_func, - "Multiple copies (%d) of the latest version of recipe '%s' were found. " - "Using path '%s' ('%s' version %lu)", num_best, plugin_name, libpath, - plugin_name, best_version); - } - else if (num_copies > 1) - { - cpl_msg_warning (er_func, - "Older copies (%d) of recipe '%s' were also found. " - "Using latest version, path '%s' ('%s' version %lu)", - (num_copies - 1), plugin_name, libpath, plugin_name, best_version); + if (num_best > 1) { + cpl_msg_error(er_func, + "Multiple copies (%d) of the latest version of recipe " + "'%s' were found. " + "Using path '%s' ('%s' version %lu)", + num_best, plugin_name, libpath, plugin_name, + best_version); + } + else if (num_copies > 1) { + cpl_msg_warning(er_func, + "Older copies (%d) of recipe '%s' were also found. " + "Using latest version, path '%s' ('%s' version %lu)", + (num_copies - 1), plugin_name, libpath, plugin_name, + best_version); } return ((int)strlen(libpath)); -} /* End of er_pluginlist_get_libpath() */ +} /* End of er_pluginlist_get_libpath() */ /**********************************************************************/ @@ -725,9 +709,10 @@ */ /**********************************************************************/ -cpl_plugin *er_pluginlist_get_plugin (const char * library_name, - const char * plugin_name, - lt_dlhandle *module) +cpl_plugin * +er_pluginlist_get_plugin(const char *library_name, + const char *plugin_name, + lt_dlhandle *module) { const char *fn = "er_pluginlist_get_plugin"; @@ -735,68 +720,61 @@ cpl_plugin *pl = NULL, *pl_copy = NULL; int mm, e_code = 0; - int (*get_plugin_list) (cpl_pluginlist *) = NULL; + int (*get_plugin_list)(cpl_pluginlist *) = NULL; - if (library_name == NULL) - { - cpl_msg_error (fn, "NULL pointer received instead of library_name"); + if (library_name == NULL) { + cpl_msg_error(fn, "NULL pointer received instead of library_name"); return NULL; } - if (plugin_name == NULL) - { - cpl_msg_error (fn, "NULL pointer received instead of plugin_name"); + if (plugin_name == NULL) { + cpl_msg_error(fn, "NULL pointer received instead of plugin_name"); return NULL; } - pl_list = cpl_pluginlist_new (); + pl_list = cpl_pluginlist_new(); #ifdef ENABLE_PYTHON_RECIPES int is_shared_lib = !is_python_module(library_name); - if (is_shared_lib) - { - + if (is_shared_lib) { #endif /* Try to open the module */ - *module = lt_dlopen (library_name); - if (!(*module)) - { - cpl_msg_error (fn, "Could not open %s: %s", library_name, lt_dlerror ()); + *module = lt_dlopen(library_name); + if (!(*module)) { + cpl_msg_error(fn, "Could not open %s: %s", library_name, + lt_dlerror()); return NULL; } /* get plugin list */ - get_plugin_list = (int (*)()) lt_dlsym (*module, "cpl_plugin_get_info"); + get_plugin_list = (int (*)())lt_dlsym(*module, "cpl_plugin_get_info"); /* lt_dlclose (module) will be done in caller routine plugin_process_plugin() */ - if (get_plugin_list == NULL) - { - cpl_msg_error (fn, "Could not find cpl_plugin_get_info() " - "index function for plugin library (%s): %s", - library_name, lt_dlerror ()); + if (get_plugin_list == NULL) { + cpl_msg_error(fn, + "Could not find cpl_plugin_get_info() " + "index function for plugin library (%s): %s", + library_name, lt_dlerror()); return NULL; } #ifdef ENABLE_PYTHON_RECIPES - } - else - { + else { /* In this case we are dealing with a Python module. Need to select the module and assign the get_plugin_list function pointer to the special interfacing function that will communicate with the Python plugins. */ module = NULL; - if (er_python_select_module(library_name) != CPL_ERROR_NONE) - { + if (er_python_select_module(library_name) != CPL_ERROR_NONE) { cpl_msg_error(er_func, "%s", cpl_error_get_message()); return NULL; } @@ -806,64 +784,64 @@ #endif pl_copy = NULL; - e_code = get_plugin_list (pl_list); + e_code = get_plugin_list(pl_list); - if (e_code != 0) - { - cpl_msg_warning (fn, - "Unexpected error (%d) in recovering a pluginlist from " - "library '%s'", e_code, library_name); + if (e_code != 0) { + cpl_msg_warning(fn, + "Unexpected error (%d) in recovering a pluginlist from " + "library '%s'", + e_code, library_name); goto end_of_it; } /* Check the "one-plugin-per-library" assumption */ - mm = cpl_pluginlist_get_size (pl_list); - if (mm > 1) - { - cpl_msg_warning (fn, "Multiple plugins contained within " - "library '%s'", library_name); - } - else if (mm < 1) - { - cpl_msg_warning (fn, "No plugins contained within " - "library '%s'", library_name); + mm = cpl_pluginlist_get_size(pl_list); + if (mm > 1) { + cpl_msg_warning(fn, + "Multiple plugins contained within " + "library '%s'", + library_name); + } + else if (mm < 1) { + cpl_msg_warning(fn, + "No plugins contained within " + "library '%s'", + library_name); goto end_of_it; } /* Now search for the plugin in the specified library */ - pl = cpl_pluginlist_find (pl_list, plugin_name); + pl = cpl_pluginlist_find(pl_list, plugin_name); /* If found, make a copy of it (remains NULL otherwise) */ - if (pl != NULL) - { - pl_copy = cpl_plugin_new (); - e_code = cpl_plugin_copy (pl_copy, pl); - if (e_code != CPL_ERROR_NONE) - { - cpl_msg_error (fn, "Failed to make internal copy of plugin"); + if (pl != NULL) { + pl_copy = cpl_plugin_new(); + e_code = cpl_plugin_copy(pl_copy, pl); + if (e_code != CPL_ERROR_NONE) { + cpl_msg_error(fn, "Failed to make internal copy of plugin"); } } /* Delete the plugin list, and return the pointer to the copy */ - end_of_it: - cpl_pluginlist_delete (pl_list); +end_of_it: + cpl_pluginlist_delete(pl_list); return pl_copy; -} /* End of er_pluginlist_get_plugin() */ +} /* End of er_pluginlist_get_plugin() */ /**********************************************************************/ /** * @brief Creates a string array of the names of available plugins. * - * @param list_of_pllibs String array of pllibs - * @retval list_of_plugin_names String array of plugin names + * @param list_of_pllibs String array of pllibs + * @param list_of_plugin_names String array of plugin names * * This function creates a string array of all plugins contained in list * of pllibs specified in a string array. The function does not display @@ -871,8 +849,9 @@ */ /**********************************************************************/ -void er_pluginlist_create_cache (er_stringarray_t * list_of_pllibs, - er_stringarray_t * list_of_plugin_names) +void +er_pluginlist_create_cache(er_stringarray_t *list_of_pllibs, + er_stringarray_t *list_of_plugin_names) { const char *fn = "er_pluginlist_create_cache"; @@ -884,78 +863,73 @@ lt_dlhandle module = NULL; int m, e_code, i = 0; - int (*get_plugin_list) (cpl_pluginlist *) = NULL; + int (*get_plugin_list)(cpl_pluginlist *) = NULL; #ifdef ENABLE_PYTHON_RECIPES int is_shared_lib = 0; #endif - if (list_of_pllibs == NULL) return; + if (list_of_pllibs == NULL) + return; fully_qualified_library_name[0] = '\0'; - for (i = 0; i < er_stringarray_size (list_of_pllibs); i++) - { - cpl_pluginlist *pl_list = cpl_pluginlist_new (); - cptr = er_stringarray_get (list_of_pllibs, i); - - m = (int) strlen(cptr); - if (m > (MAXSTRLENCONF-1)) - { - cpl_msg_error (er_func, "size of plugin lib > %d ...", MAXSTRLENCONF); + for (i = 0; i < er_stringarray_size(list_of_pllibs); i++) { + cpl_pluginlist *pl_list = cpl_pluginlist_new(); + cptr = er_stringarray_get(list_of_pllibs, i); + + m = (int)strlen(cptr); + if (m > (MAXSTRLENCONF - 1)) { + cpl_msg_error(er_func, "size of plugin lib > %d ...", + MAXSTRLENCONF); return; } - (void) strcpy(fully_qualified_library_name,cptr); + (void)strcpy(fully_qualified_library_name, cptr); #ifdef ENABLE_PYTHON_RECIPES is_shared_lib = !is_python_module(fully_qualified_library_name); - if (is_shared_lib) - { - + if (is_shared_lib) { #endif /* Try to open the module */ - module = lt_dlopen (fully_qualified_library_name); - if (!module) - { - cpl_msg_error (fn, "Could not open %s: %s", - fully_qualified_library_name, lt_dlerror ()); - cpl_pluginlist_delete (pl_list); + module = lt_dlopen(fully_qualified_library_name); + if (!module) { + cpl_msg_error(fn, "Could not open %s: %s", + fully_qualified_library_name, lt_dlerror()); + cpl_pluginlist_delete(pl_list); return; } /* get plugin list */ - get_plugin_list = (int (*)()) lt_dlsym (module, "cpl_plugin_get_info"); + get_plugin_list = + (int (*)())lt_dlsym(module, "cpl_plugin_get_info"); - if (get_plugin_list == NULL) - { - cpl_msg_error (fn, "Could not find cpl_plugin_get_info()" - " of plugin library %s", - fully_qualified_library_name); - cpl_pluginlist_delete (pl_list); + if (get_plugin_list == NULL) { + cpl_msg_error(fn, + "Could not find cpl_plugin_get_info()" + " of plugin library %s", + fully_qualified_library_name); + cpl_pluginlist_delete(pl_list); lt_dlclose(module); return; } #ifdef ENABLE_PYTHON_RECIPES - } - else - { + else { /* In this case we are dealing with a Python module. Need to select the Python module and assign the get_plugin_list function pointer to the special interfacing function that will communicate with the Python plugins. */ - if (er_python_select_module(fully_qualified_library_name) - != CPL_ERROR_NONE) - { + if (er_python_select_module(fully_qualified_library_name) != + CPL_ERROR_NONE) { cpl_msg_error(er_func, "%s", cpl_error_get_message()); - cpl_pluginlist_delete (pl_list); + cpl_pluginlist_delete(pl_list); return; } get_plugin_list = er_python_get_plugin_list; @@ -963,22 +937,18 @@ #endif - e_code = get_plugin_list (pl_list); - if (e_code != CPL_ERROR_NONE) - { - cpl_msg_error (er_func, "Unable to read plugin list"); - cpl_pluginlist_delete (pl_list); + e_code = get_plugin_list(pl_list); + if (e_code != CPL_ERROR_NONE) { + cpl_msg_error(er_func, "Unable to read plugin list"); + cpl_pluginlist_delete(pl_list); lt_dlclose(module); return; } - tplugin = cpl_pluginlist_get_first (pl_list); - while (tplugin != NULL) - { - if (cpl_plugin_get_api(tplugin) == CPL_PLUGIN_API) - { - if (cpl_plugin_get_type(tplugin) & CPL_PLUGIN_TYPE_RECIPE) - { + tplugin = cpl_pluginlist_get_first(pl_list); + while (tplugin != NULL) { + if (cpl_plugin_get_api(tplugin) == CPL_PLUGIN_API) { + if (cpl_plugin_get_type(tplugin) & CPL_PLUGIN_TYPE_RECIPE) { er_stringarray_append(list_of_plugin_names, (char *)cpl_plugin_get_name(tplugin)); } @@ -986,14 +956,13 @@ tplugin = cpl_pluginlist_get_next(pl_list); - } /* End of while() */ + } /* End of while() */ cpl_pluginlist_delete(pl_list); #ifdef ENABLE_PYTHON_RECIPES - if (is_shared_lib) - { + if (is_shared_lib) { lt_dlclose(module); } @@ -1003,11 +972,11 @@ #endif - } /* End of for(each name in list_of_pllibs) */ + } /* End of for(each name in list_of_pllibs) */ return; -} /* End of er_pluginlist_create_cache() */ +} /* End of er_pluginlist_create_cache() */ /**********************************************************************/ @@ -1024,7 +993,8 @@ */ /**********************************************************************/ -void er_pluginlist_print_list (er_stringarray_t * list_of_pllibs) +void +er_pluginlist_print_list(er_stringarray_t *list_of_pllibs) { char *ccptr, fully_qualified_library_name[MAXSTRLENCONF]; @@ -1033,7 +1003,7 @@ lt_dlhandle module = NULL; - int (*get_plugin_list) (cpl_pluginlist *) = NULL; + int (*get_plugin_list)(cpl_pluginlist *) = NULL; int m, e_code, i = 0; int num_plugins = 0; @@ -1045,75 +1015,68 @@ fully_qualified_library_name[0] = '\0'; - if (list_of_pllibs == NULL) return; + if (list_of_pllibs == NULL) + return; - (void) printf("List of Available Recipes :\n\n"); + (void)printf("List of Available Recipes :\n\n"); /* Loop through each dynamic library file that we have */ - for (i=0; i < er_stringarray_size(list_of_pllibs); i++) - { - cpl_pluginlist *pl_list = cpl_pluginlist_new (); - - ccptr = er_stringarray_get (list_of_pllibs, i); - m = (int) strlen(ccptr); - if (m > (MAXSTRLENCONF-1)) - { - cpl_msg_error (er_func, "size of plugin lib > %d ...", MAXSTRLENCONF); + for (i = 0; i < er_stringarray_size(list_of_pllibs); i++) { + cpl_pluginlist *pl_list = cpl_pluginlist_new(); + + ccptr = er_stringarray_get(list_of_pllibs, i); + m = (int)strlen(ccptr); + if (m > (MAXSTRLENCONF - 1)) { + cpl_msg_error(er_func, "size of plugin lib > %d ...", + MAXSTRLENCONF); return; } - (void) strcpy(fully_qualified_library_name,ccptr); + (void)strcpy(fully_qualified_library_name, ccptr); #ifdef ENABLE_PYTHON_RECIPES is_shared_lib = !is_python_module(fully_qualified_library_name); - if (is_shared_lib) - { - + if (is_shared_lib) { #endif /* try to open library */ - module = lt_dlopen (fully_qualified_library_name); - if (!module) - { - cpl_msg_error (er_func, "Could not open %s: %s", - fully_qualified_library_name, lt_dlerror ()); - cpl_pluginlist_delete (pl_list); + module = lt_dlopen(fully_qualified_library_name); + if (!module) { + cpl_msg_error(er_func, "Could not open %s: %s", + fully_qualified_library_name, lt_dlerror()); + cpl_pluginlist_delete(pl_list); return; } - get_plugin_list = (int (*)()) lt_dlsym (module, - "cpl_plugin_get_info"); + get_plugin_list = + (int (*)())lt_dlsym(module, "cpl_plugin_get_info"); - if (get_plugin_list == NULL) - { - cpl_msg_error (er_func, - "Could not find the cpl_plugin_get_info()" - " function of plugin library %s", - fully_qualified_library_name); - cpl_pluginlist_delete (pl_list); + if (get_plugin_list == NULL) { + cpl_msg_error(er_func, + "Could not find the cpl_plugin_get_info()" + " function of plugin library %s", + fully_qualified_library_name); + cpl_pluginlist_delete(pl_list); lt_dlclose(module); return; } #ifdef ENABLE_PYTHON_RECIPES - } - else - { + else { /* In this case we are dealing with a Python module. Need to select the Python module and assign the get_plugin_list function pointer to the special interfacing function that will communicate with the Python plugins. */ - if (er_python_select_module(fully_qualified_library_name) - != CPL_ERROR_NONE) - { + if (er_python_select_module(fully_qualified_library_name) != + CPL_ERROR_NONE) { cpl_msg_error(er_func, "%s", cpl_error_get_message()); - cpl_pluginlist_delete (pl_list); + cpl_pluginlist_delete(pl_list); return; } get_plugin_list = er_python_get_plugin_list; @@ -1121,16 +1084,14 @@ #endif - e_code = get_plugin_list (pl_list); - if (e_code != CPL_ERROR_NONE) - { - cpl_msg_error (er_func, "Unable to read plugin list"); - cpl_pluginlist_delete (pl_list); + e_code = get_plugin_list(pl_list); + if (e_code != CPL_ERROR_NONE) { + cpl_msg_error(er_func, "Unable to read plugin list"); + cpl_pluginlist_delete(pl_list); #ifdef ENABLE_PYTHON_RECIPES - if (is_shared_lib) - { + if (is_shared_lib) { lt_dlclose(module); } @@ -1148,27 +1109,24 @@ * which uses a compatible plugin API print the plugin's summary information. */ - tplugin = cpl_pluginlist_get_first (pl_list); + tplugin = cpl_pluginlist_get_first(pl_list); - while (tplugin != NULL) - { + while (tplugin != NULL) { if ((cpl_plugin_get_api(tplugin) == CPL_PLUGIN_API) && - (cpl_plugin_get_type(tplugin) & CPL_PLUGIN_TYPE_RECIPE)) - { - er_paramutils_print_key_desc ("", cpl_plugin_get_name(tplugin), - cpl_plugin_get_synopsis(tplugin)); + (cpl_plugin_get_type(tplugin) & CPL_PLUGIN_TYPE_RECIPE)) { + er_paramutils_print_key_desc("", cpl_plugin_get_name(tplugin), + cpl_plugin_get_synopsis(tplugin)); ++num_plugins; } - tplugin = cpl_pluginlist_get_next (pl_list); + tplugin = cpl_pluginlist_get_next(pl_list); } - cpl_pluginlist_delete (pl_list); + cpl_pluginlist_delete(pl_list); #ifdef ENABLE_PYTHON_RECIPES - if (is_shared_lib) - { + if (is_shared_lib) { lt_dlclose(module); } @@ -1178,18 +1136,19 @@ #endif - } /* End of for(each name in list_of_pllibs) */ + } /* End of for(each name in list_of_pllibs) */ /* Print a warning message if no plugins were listed */ if (num_plugins == 0) - (void) printf(" No recipes were found in the specified recipe directory.\n"); + (void)printf( + " No recipes were found in the specified recipe directory.\n"); - (void) printf("\n"); + (void)printf("\n"); return; -} /* End of er_pluginlist_print_list() */ +} /* End of er_pluginlist_print_list() */ /**@}*/ diff -Nru esorex-3.13.5+ds/src/er_pluginlist.h esorex-3.13.6+ds/src/er_pluginlist.h --- esorex-3.13.5+ds/src/er_pluginlist.h 2021-06-02 15:06:13.000000000 +0000 +++ esorex-3.13.6+ds/src/er_pluginlist.h 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 European Southern Observatory * * 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 @@ -26,14 +26,15 @@ extern er_stringarray_t *er_pluginlist_create_list(char **listname); extern int er_pluginlist_get_libpath(er_stringarray_t *list_of_pllibs, - const char *plugin_name, char *libpath); + const char *plugin_name, + char *libpath); extern cpl_plugin *er_pluginlist_get_plugin(const char *library_name, const char *plugin_name, lt_dlhandle *module); -extern void er_pluginlist_create_cache(er_stringarray_t *nama, - er_stringarray_t *namb); +extern void +er_pluginlist_create_cache(er_stringarray_t *nama, er_stringarray_t *namb); extern void er_pluginlist_print_list(er_stringarray_t *list_of_pllibs); diff -Nru esorex-3.13.5+ds/src/er_python.c esorex-3.13.6+ds/src/er_python.c --- esorex-3.13.5+ds/src/er_python.c 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/er_python.c 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2017 European Southern Observatory + * Copyright (C) 2017-2022 European Southern Observatory * * 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 @@ -403,13 +403,13 @@ /* The following are file descriptor numbers for the pipes that the Python process should use to communicate with EsoRex. These will be prepared just before executing the Python interpreter binary. */ -#define PYTHON_INPUT_FD 3 -#define PYTHON_OUTPUT_FD 4 +#define PYTHON_INPUT_FD 3 +#define PYTHON_OUTPUT_FD 4 /* The following is a global map of Python module file names to cpl_pluginlist objects created by the er_python_load_modules function. */ -static cx_map * module_list = NULL; +static cx_map *module_list = NULL; /* Identifies the current module to be handled by er_python_get_plugin_list. This is set with er_python_select_module. */ @@ -418,15 +418,15 @@ /* The following is a map between cpl_plugin objects found within the plugin lists in module_list, and the corresponding python module names. In effect, this is the inverse lookup of module_list. */ -static cx_map * module_lut = NULL; +static cx_map *module_lut = NULL; /* The following command is passed to the -c option to the Python interpreter. It bootstraps the more complex script in the JSON input from standard input. This keeps the command line length reasonably short. */ -static const char * python_start_command = +static const char *python_start_command = "import sys, os, json;" - " _data = json.load(os.fdopen("CPL_STRINGIFY(PYTHON_INPUT_FD)",'r'));" - " exec(_data['script'])"; + " _data = json.load(os.fdopen(" CPL_STRINGIFY(PYTHON_INPUT_FD) ",'r'));" + " exec(_data['script'])"; /* @@ -434,14 +434,16 @@ * that is not a signal interrupt. The errno is reset to make sure we ignore * any errors from close, since there is nothing more we can do about them. */ -static void close_file(int file) +static void +close_file(int file) { - if (close(file) == 0) return; - if (errno != EINTR) - { + if (close(file) == 0) + return; + if (errno != EINTR) { cpl_msg_error(cpl_func, "Failed to close file descriptor for pipe to Python" - " interpreter: %s", strerror(errno)); + " interpreter: %s", + strerror(errno)); } errno = 0; } @@ -464,10 +466,11 @@ * process has been started. Otherwise an appropriate error code is * returned. */ -static cpl_error_code start_python_interpreter(const char * python_command, - pid_t * python_pid, - int * python_input, - int * python_output) +static cpl_error_code +start_python_interpreter(const char *python_command, + pid_t *python_pid, + int *python_input, + int *python_output) { assert(python_command != NULL); assert(python_pid != NULL); @@ -479,24 +482,23 @@ /* Prepare two streams that will be connected to the Python process for input and output. */ - if (pipe(rpipes) != 0) - { + if (pipe(rpipes) != 0) { return cpl_error_set_message(cpl_func, CPL_ERROR_FILE_IO, "Failed to create read pipe for Python" - " interpreter: %s", strerror(errno)); + " interpreter: %s", + strerror(errno)); } - if (pipe(wpipes) != 0) - { + if (pipe(wpipes) != 0) { close_file(rpipes[0]); close_file(rpipes[1]); return cpl_error_set_message(cpl_func, CPL_ERROR_FILE_IO, "Failed to create write pipe for Python" - " interpreter: %s", strerror(errno)); + " interpreter: %s", + strerror(errno)); } *python_pid = fork(); - if (*python_pid == -1) - { + if (*python_pid == -1) { close_file(rpipes[0]); close_file(rpipes[1]); close_file(wpipes[0]); @@ -505,8 +507,7 @@ "Failed to start Python process: %s", strerror(errno)); } - if (*python_pid == 0) - { + if (*python_pid == 0) { /* In child process after the fork. Here we reconnect the read/write pipes we created to use file descriptors that the Python process will expect to communicate with EsoRex on. Once the pipes are ready we @@ -523,17 +524,19 @@ allocation scheme (always use the lowest available number) mandates that this will happen. */ int rpipe = dup(rpipes[1]); - if (rpipe == -1) - { - cpl_msg_debug(cpl_func, "Failed to duplicate the output pipe for" - " the Python process: %s", strerror(errno)); + if (rpipe == -1) { + cpl_msg_debug(cpl_func, + "Failed to duplicate the output pipe for" + " the Python process: %s", + strerror(errno)); exit(EXIT_FAILURE); } int wpipe = dup(wpipes[0]); - if (wpipe == -1) - { - cpl_msg_debug(cpl_func, "Failed to duplicate the input pipe for" - " the Python process: %s", strerror(errno)); + if (wpipe == -1) { + cpl_msg_debug(cpl_func, + "Failed to duplicate the input pipe for" + " the Python process: %s", + strerror(errno)); exit(EXIT_FAILURE); } @@ -556,16 +559,18 @@ /* Redirect the saved (duplicated) ends of the pipes to the required file descriptor numbers. */ - if (dup2(rpipe, PYTHON_OUTPUT_FD) == -1) - { - cpl_msg_debug(cpl_func, "Failed to redirect output pipe for the" - " Python process: %s", strerror(errno)); + if (dup2(rpipe, PYTHON_OUTPUT_FD) == -1) { + cpl_msg_debug(cpl_func, + "Failed to redirect output pipe for the" + " Python process: %s", + strerror(errno)); exit(EXIT_FAILURE); } - if (dup2(wpipe, PYTHON_INPUT_FD) == -1) - { - cpl_msg_debug(cpl_func, "Failed to redirect input pipe for the" - " Python process: %s", strerror(errno)); + if (dup2(wpipe, PYTHON_INPUT_FD) == -1) { + cpl_msg_debug(cpl_func, + "Failed to redirect input pipe for the" + " Python process: %s", + strerror(errno)); exit(EXIT_FAILURE); } close_file(rpipe); @@ -573,13 +578,12 @@ /* execlp() will either not return, or we know we have an error so stop the process. */ - (void) execlp("python", "python", "-c", python_command, (char *)0); + (void)execlp("python", "python", "-c", python_command, (char *)0); cpl_msg_debug(cpl_func, "Failed to execute python command: %s", strerror(errno)); exit(EXIT_FAILURE); } - else - { + else { /* In parent process after the fork. Close the ends of the pipes we do not need, so that we avoid any possible deadlocks or other problems. */ @@ -603,9 +607,8 @@ * it returned a zero exit status. Otherwise an appropriate error code is * returned if the interpreter returned a non-zero value. */ -static cpl_error_code stop_python_interpreter(pid_t python_pid, - int python_input, - int python_output) +static cpl_error_code +stop_python_interpreter(pid_t python_pid, int python_input, int python_output) { int status = -1; int result = -1; @@ -614,52 +617,47 @@ python_input to let the interpreter know it needs to terminate. python_input might have been closed before, so only close it if it appears to be valid. */ - if (python_input != -1) - { + if (python_input != -1) { close_file(python_input); } close_file(python_output); time_t start_time = time(NULL); - do - { + do { result = waitpid(python_pid, &status, WNOHANG); - if (result == -1) - { - if (errno != EINTR) - { + if (result == -1) { + if (errno != EINTR) { /* waitpid() was not interrupted, thus there was an error when joining the child process. */ return cpl_error_set_message(cpl_func, CPL_ERROR_FILE_IO, "Failed to join with the Python" - " process: %s", strerror(errno)); + " process: %s", + strerror(errno)); } } - if (result == 0) - { + if (result == 0) { /* The child process did not complete yet so sleep a little. If we have been waiting too long, then also send a termination signal. */ time_t now = time(NULL); - if (now - start_time > 10) /* Waiting more than 10 seconds? */ + if (now - start_time > 10) /* Waiting more than 10 seconds? */ { - (void) kill(python_pid, SIGTERM); + (void)kill(python_pid, SIGTERM); } - struct timespec ts = {0, 10000000}; /* 10 millisecond wait. */ + struct timespec ts = { 0, 10000000 }; /* 10 millisecond wait. */ nanosleep(&ts, NULL); } } while (result != python_pid); - if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS) - { + if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS) { return CPL_ERROR_NONE; } - else - { + else { /* Python terminated with an error. */ return cpl_error_set_message(cpl_func, CPL_ERROR_FILE_IO, "Python process existed with error code" - " %d", WEXITSTATUS(status)); + " %d", + WEXITSTATUS(status)); } } @@ -674,29 +672,25 @@ * @return @c CPL_ERROR_NONE is returned on success and an appropriate error * code otherwise. */ -static cpl_error_code write_to_pipe(int python_input, - const char * data, - size_t data_size) +static cpl_error_code +write_to_pipe(int python_input, const char *data, size_t data_size) { assert(data != NULL); size_t total_written = 0; - do - { - ssize_t bytes_written = write(python_input, - data + total_written, + do { + ssize_t bytes_written = write(python_input, data + total_written, data_size - total_written); - if (bytes_written == -1) - { - if (errno == EINTR) continue; /* Got interrupted, try again. */ + if (bytes_written == -1) { + if (errno == EINTR) + continue; /* Got interrupted, try again. */ return cpl_error_set_message(cpl_func, CPL_ERROR_FILE_IO, "Failed to write commands to the" " Python interpreter: %s", strerror(errno)); } total_written += bytes_written; - } - while (total_written < data_size); + } while (total_written < data_size); return CPL_ERROR_NONE; } @@ -713,9 +707,10 @@ * @note The caller must release the returned buffer with @c free() from the * C standard library. */ -static char * read_from_pipe(int python_output) +static char * +read_from_pipe(int python_output) { - char * newptr = NULL; + char *newptr = NULL; ssize_t bytes_read = 0; size_t total_read = 0; @@ -723,28 +718,23 @@ terminate immediately if a memory allocation failed. But we do not want that, since we will still need to join with the Python interpreter child process and cleanup properly. */ - size_t data_size = 1024*4; - char * data = (char *) malloc(data_size); - if (data == NULL) - { + size_t data_size = 1024 * 4; + char *data = (char *)malloc(data_size); + if (data == NULL) { cpl_error_set_message(cpl_func, CPL_ERROR_FILE_IO, "Buffer allocation failed: %s", strerror(errno)); return NULL; } - do - { + do { /* If the buffer is 50% full then double its size before reading. */ - if (total_read > data_size / 2) - { + if (total_read > data_size / 2) { data_size *= 2; - newptr = (char *) realloc(data, data_size); - if (newptr != NULL) - { + newptr = (char *)realloc(data, data_size); + if (newptr != NULL) { data = newptr; } - else - { + else { cpl_error_set_message(cpl_func, CPL_ERROR_FILE_IO, "Buffer reallocation failed: %s", strerror(errno)); @@ -754,14 +744,15 @@ } /* Read from the Python command's output stream and check for errors. */ - bytes_read = read(python_output, data + total_read, - data_size - 1 - total_read); - if (bytes_read < 0) - { - if (errno == EINTR) continue; /* Got interrupted, try again. */ + bytes_read = + read(python_output, data + total_read, data_size - 1 - total_read); + if (bytes_read < 0) { + if (errno == EINTR) + continue; /* Got interrupted, try again. */ cpl_error_set_message(cpl_func, CPL_ERROR_FILE_IO, "Failed to read output from the Python" - " interpreter: %s", strerror(errno)); + " interpreter: %s", + strerror(errno)); free(data); return NULL; } @@ -773,13 +764,11 @@ /* Reduce the memory requirement to what we actually read out of the pipe and also make sure the result is a null terminated character string before returning it. */ - newptr = (char *) realloc(data, data_size); - if (newptr != NULL) - { + newptr = (char *)realloc(data, data_size); + if (newptr != NULL) { data = newptr; } - else - { + else { cpl_error_set_message(cpl_func, CPL_ERROR_FILE_IO, "Buffer reallocation failed: %s", strerror(errno)); @@ -802,35 +791,32 @@ * @param header An initial message to print before the line numbered text. * @param text The text which is printed with one debug message per line. */ -static void print_multiline_debug_message(const char * funcname, - const char * header, - const char * text) +static void +print_multiline_debug_message(const char *funcname, + const char *header, + const char *text) { /* Print text over multiple debug message lines to produce line numbers and thereby also try avoid the max line length limitation of the logging subsystem. */ cpl_msg_debug(funcname, "%s", header); - char * strbuf = cpl_strdup(text); - char * line = strbuf; + char *strbuf = cpl_strdup(text); + char *line = strbuf; int lineno = 1; cpl_msg_indent_more(); - char * pchar = line; - while (*pchar != '\0') - { - if (*pchar == '\n') - { + char *pchar = line; + while (*pchar != '\0') { + if (*pchar == '\n') { *(pchar++) = '\0'; cpl_msg_debug(funcname, "%.4d %s", lineno, line); line = pchar; ++lineno; } - else - { + else { ++pchar; } } - if (*line != '\0') - { + if (*line != '\0') { cpl_msg_debug(funcname, "%.4d %s", lineno, line); } cpl_msg_indent_less(); @@ -857,28 +843,25 @@ * @note The caller must release the returned buffer with @c free() from the * C standard library. */ -static char * run_python_command(const char * command, - const char * input) +static char * +run_python_command(const char *command, const char *input) { assert(command != NULL); assert(input != NULL); cpl_msg_debug(cpl_func, "Command sent to Python interpreter:\n%s", command); - print_multiline_debug_message(cpl_func, "Input to Python interpreter:", - input); + print_multiline_debug_message(cpl_func, + "Input to Python interpreter:", input); pid_t python_pid = -1; int python_input = -1, python_output = -1; - if (start_python_interpreter(command, &python_pid, - &python_input, &python_output) - != CPL_ERROR_NONE) - { + if (start_python_interpreter(command, &python_pid, &python_input, + &python_output) != CPL_ERROR_NONE) { /* Error already set in start_python_interpreter, so just return. */ return NULL; } - if (write_to_pipe(python_input, input, strlen(input)) != CPL_ERROR_NONE) - { + if (write_to_pipe(python_input, input, strlen(input)) != CPL_ERROR_NONE) { /* Cleanup, but preserve the CPL error state from write_to_pipe. */ cpl_errorstate state = cpl_errorstate_get(); stop_python_interpreter(python_pid, python_input, python_output); @@ -888,19 +871,18 @@ /* First close the input stream to the Python interpreter to let it know that no more input is coming and give it a change to run the script. */ - if (close(python_input) != 0) - { - if (errno != EINTR) - { + if (close(python_input) != 0) { + if (errno != EINTR) { cpl_error_set_message(cpl_func, CPL_ERROR_FILE_IO, "Failed to close input stream to the Python" - " interpreter: %s", strerror(errno)); + " interpreter: %s", + strerror(errno)); } /* Cleanup, but preserve the CPL error state. NOTE: since we had a problem closing the pipe this might hang the python process. Thus, send a kill signal just in case. */ cpl_errorstate state = cpl_errorstate_get(); - (void) kill(python_pid, SIGTERM); + (void)kill(python_pid, SIGTERM); stop_python_interpreter(python_pid, -1, python_output); cpl_errorstate_set(state); return NULL; @@ -910,9 +892,8 @@ input pipe, because it has now already been closed. */ python_input = -1; - char * output = read_from_pipe(python_output); - if (output == NULL) - { + char *output = read_from_pipe(python_output); + if (output == NULL) { /* Cleanup, but preserve the CPL error state from read_from_pipe. */ cpl_errorstate state = cpl_errorstate_get(); stop_python_interpreter(python_pid, python_input, python_output); @@ -920,20 +901,17 @@ return NULL; } - if (stop_python_interpreter(python_pid, python_input, python_output) - != CPL_ERROR_NONE) - { + if (stop_python_interpreter(python_pid, python_input, python_output) != + CPL_ERROR_NONE) { free(output); /* Error already set in stop_python_interpreter, so just return. */ return NULL; } - if (strlen(output) == 0) - { + if (strlen(output) == 0) { cpl_msg_debug(cpl_func, "Output from Python interpreter: (none)"); } - else - { + else { print_multiline_debug_message(cpl_func, "Output from Python interpreter:", output); @@ -945,7 +923,8 @@ /* * A comparison function to compare string keys for the cx_map class. */ -static cxint string_key_compare(cxcptr a, cxcptr b) +static cxint +string_key_compare(cxcptr a, cxcptr b) { return (strcmp(a, b) < 0) ? TRUE : FALSE; } @@ -957,46 +936,66 @@ * 0 if pa == pb * 1 if pa > pb */ -static int plugin_compare(const cpl_plugin * pa, const cpl_plugin * pb) +static int +plugin_compare(const cpl_plugin *pa, const cpl_plugin *pb) { int result = 0; /* NOTE: we order the comparison from what should typically take the least amount of time to the most. This should allow us to navigate to the matching node within cx_map more quickly. */ - if (pa->api < pb->api) return -1; - if (pa->api > pb->api) return 1; - if (pa->version < pb->version) return -1; - if (pa->version > pb->version) return 1; - if (pa->type < pb->type) return -1; - if (pa->type > pb->type) return 1; + if (pa->api < pb->api) + return -1; + if (pa->api > pb->api) + return 1; + if (pa->version < pb->version) + return -1; + if (pa->version > pb->version) + return 1; + if (pa->type < pb->type) + return -1; + if (pa->type > pb->type) + return 1; result = strcmp(pa->name, pb->name); - if (result < 0) return -1; - if (result > 0) return 1; + if (result < 0) + return -1; + if (result > 0) + return 1; result = strcmp(pa->author, pb->author); - if (result < 0) return -1; - if (result > 0) return 1; + if (result < 0) + return -1; + if (result > 0) + return 1; result = strcmp(pa->email, pb->email); - if (result < 0) return -1; - if (result > 0) return 1; + if (result < 0) + return -1; + if (result > 0) + return 1; result = strcmp(pa->synopsis, pb->synopsis); - if (result < 0) return -1; - if (result > 0) return 1; + if (result < 0) + return -1; + if (result > 0) + return 1; result = strcmp(pa->description, pb->description); - if (result < 0) return -1; - if (result > 0) return 1; + if (result < 0) + return -1; + if (result > 0) + return 1; result = strcmp(pa->copyright, pb->copyright); - if (result < 0) return -1; - if (result > 0) return 1; + if (result < 0) + return -1; + if (result > 0) + return 1; return 0; } /* * A comparison function to compare cpl_plugin like keys for the cx_map class. */ -static cxint plugin_key_compare(cxcptr a, cxcptr b) +static cxint +plugin_key_compare(cxcptr a, cxcptr b) { - const cpl_plugin * pa = (const cpl_plugin *) a; - const cpl_plugin * pb = (const cpl_plugin *) b; + const cpl_plugin *pa = (const cpl_plugin *)a; + const cpl_plugin *pb = (const cpl_plugin *)b; return (plugin_compare(pa, pb) < 0) ? TRUE : FALSE; } @@ -1025,7 +1024,8 @@ * loaded. All such modules are simply ignored. However, the user may get * error messages printed by the Python process on stderr. */ -cpl_error_code er_python_load_modules(er_stringarray_t * paths) +cpl_error_code +er_python_load_modules(er_stringarray_t *paths) { cpl_error_ensure(paths != NULL, CPL_ERROR_NULL_INPUT, return CPL_ERROR_NULL_INPUT, "paths is NULL."); @@ -1038,32 +1038,28 @@ module_lut = cx_map_new(plugin_key_compare, NULL, NULL); /* Prepare a JSON compatible string containing a list of module names. */ - char * paths_string = NULL; + char *paths_string = NULL; int i = 0; - for (i = 0; i < er_stringarray_size(paths); ++i) - { - char * path = er_json_escape_string(er_stringarray_get(paths, i)); - if (i == 0) - { + for (i = 0; i < er_stringarray_size(paths); ++i) { + char *path = er_json_escape_string(er_stringarray_get(paths, i)); + if (i == 0) { paths_string = cpl_sprintf("\"%s\"", path); } - else - { - char * tmpstr = cpl_sprintf("%s,\n \"%s\"", paths_string, path); + else { + char *tmpstr = cpl_sprintf("%s,\n \"%s\"", paths_string, path); cpl_free(paths_string); paths_string = tmpstr; } cpl_free(path); } - if (paths_string == NULL) - { + if (paths_string == NULL) { /* No paths to load. */ return CPL_ERROR_NONE; } /* The following script attempts to find Python based plugins for EsoRex in the module paths identified in _data['paths']. */ - char * script = er_json_escape_string( + char *script = er_json_escape_string( "import inspect\n" "valid_modules = {}\n" "for path in _data['paths']:\n" @@ -1076,9 +1072,9 @@ If such a class is found then add the name under the corresponding module path key in the valid modules dictionary. */ " for name, cls in inspect.getmembers(sys.modules[module]," - " predicate=inspect.isclass):\n" + " predicate=inspect.isclass):\n" " if len([base for base in cls.__mro__" - " if base.__name__ == 'CplPlugin']) > 0:\n" + " if base.__name__ == 'CplPlugin']) > 0:\n" " if path not in valid_modules:\n" " valid_modules[path] = set()\n" " valid_modules[path].add(cls)\n" @@ -1149,80 +1145,72 @@ " results[path].append(plugin)\n" /* Generate and write out the results as JSON. */ "json.dump(results," - " os.fdopen("CPL_STRINGIFY(PYTHON_OUTPUT_FD)",'w')," - " indent=2)\n" - ); + " os.fdopen(" CPL_STRINGIFY(PYTHON_OUTPUT_FD) ",'w')," + " indent=2)\n"); /* Create the input for the above script. NOTE: cpl_sprintf will create a valid buffer or terminate the process. */ - char * input = cpl_sprintf( - "{\n" - " \"script\": \"%s\",\n" - " \"paths\": [\n" - " %s\n" - " ]\n" - "}", - script, paths_string - ); + char *input = cpl_sprintf("{\n" + " \"script\": \"%s\",\n" + " \"paths\": [\n" + " %s\n" + " ]\n" + "}", + script, paths_string); cpl_free(paths_string); - char * output = run_python_command(python_start_command, input); + char *output = run_python_command(python_start_command, input); cpl_free(script); cpl_free(input); - if (output == NULL) return cpl_error_get_code(); + if (output == NULL) + return cpl_error_get_code(); /* Parse the output JSON into a parse tree of JSON nodes. These can then be converted into appropriate CPL structures. */ - er_json_node * parsetree = er_json_parse(output); - if (parsetree == NULL) - { + er_json_node *parsetree = er_json_parse(output); + if (parsetree == NULL) { free(output); return cpl_error_get_code(); } /* Make sure the top level node in the parse tree is an object. */ - if (er_json_node_type(parsetree) != JSON_OBJECT) - { + if (er_json_node_type(parsetree) != JSON_OBJECT) { int line, col; er_json_find_line_column(output, er_json_node_location(parsetree), &line, &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, - "Expected an object at line %d column %d.", - line, col); + "Expected an object at line %d column %d.", line, + col); er_json_node_delete(parsetree); free(output); return cpl_error_get_code(); } - er_stringarray_t * valid_paths = er_stringarray_new(); + er_stringarray_t *valid_paths = er_stringarray_new(); - er_json_object_iterator iter = NULL; + er_json_object_iterator iter = NULL; for (iter = er_json_node_object_begin(parsetree); iter != er_json_node_object_end(parsetree); - iter = er_json_node_object_next(parsetree, iter)) - { - const char * module = er_json_node_object_get_key(parsetree, iter); - const er_json_node * item = er_json_node_object_get_value(parsetree, - iter); - cpl_pluginlist * pluginlist = er_json_to_pluginlist(item, output); + iter = er_json_node_object_next(parsetree, iter)) { + const char *module = er_json_node_object_get_key(parsetree, iter); + const er_json_node *item = + er_json_node_object_get_value(parsetree, iter); + cpl_pluginlist *pluginlist = er_json_to_pluginlist(item, output); /* NOTE: If no plugin list could be created then skip the module, but continue processing the other possible modules. */ - if (pluginlist != NULL) - { + if (pluginlist != NULL) { er_stringarray_append(valid_paths, module); /* Need to add a copy to the map object because it will be later deleted by it in er_python_cleanup. */ - char * module_name = cpl_strdup(module); + char *module_name = cpl_strdup(module); cx_map_insert(module_list, module_name, pluginlist); /* Add all the plugin entries to the reverse lookup table. */ - cpl_plugin * plugin = NULL; - for (plugin = cpl_pluginlist_get_first(pluginlist); - plugin != NULL; - plugin = cpl_pluginlist_get_next(pluginlist)) - { + cpl_plugin *plugin = NULL; + for (plugin = cpl_pluginlist_get_first(pluginlist); plugin != NULL; + plugin = cpl_pluginlist_get_next(pluginlist)) { cx_map_insert(module_lut, plugin, module_name); } } @@ -1233,21 +1221,17 @@ /* For every path in the input paths list, we check if it was found in valid_paths. Any path not found in valid_paths is removed. */ - for (i = 0; i < er_stringarray_size(paths); ++i) - { - const char * path = er_stringarray_get(paths, i); + for (i = 0; i < er_stringarray_size(paths); ++i) { + const char *path = er_stringarray_get(paths, i); int found = 0; int j = 0; - for (j = 0; j < er_stringarray_size(valid_paths); ++j) - { - if (strcmp(path, er_stringarray_get(valid_paths, j)) == 0) - { + for (j = 0; j < er_stringarray_size(valid_paths); ++j) { + if (strcmp(path, er_stringarray_get(valid_paths, j)) == 0) { found = 1; break; } } - if (! found) - { + if (!found) { er_stringarray_remove(paths, i); } } @@ -1268,31 +1252,29 @@ * @return @c CPL_ERROR_NONE on success or an appropriate error code if a * severe error occurs. */ -cpl_error_code er_python_select_module(const char * module_name) +cpl_error_code +er_python_select_module(const char *module_name) { - if (module_name == NULL) - { + if (module_name == NULL) { current_module = NULL; return CPL_ERROR_NONE; } - if (module_list == NULL) - { + if (module_list == NULL) { return cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, "Python modules need to be loaded first" " with er_python_load_modules."); } cx_map_iterator module = cx_map_find(module_list, module_name); - if (module != cx_map_end(module_list)) - { + if (module != cx_map_end(module_list)) { current_module = module; return CPL_ERROR_NONE; } - else - { + else { return cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, "Failed to find preloaded Python module:" - " %s", module_name); + " %s", + module_name); } } @@ -1303,38 +1285,31 @@ * incorrectly copies ranges. * This function will make a duplicate copy of a CPL parameter and return it. */ -static cpl_parameter * fixed_parameter_duplicate(const cpl_parameter * par) +static cpl_parameter * +fixed_parameter_duplicate(const cpl_parameter *par) { - if (cpl_parameter_get_class(par) == CPL_PARAMETER_CLASS_RANGE) - { + if (cpl_parameter_get_class(par) == CPL_PARAMETER_CLASS_RANGE) { /* Create a new parameter range object if we were dealing with a range to begin with. */ - cpl_parameter * newpar; - switch (cpl_parameter_get_type(par)) - { + cpl_parameter *newpar; + switch (cpl_parameter_get_type(par)) { case CPL_TYPE_INT: newpar = cpl_parameter_new_range( - cpl_parameter_get_name(par), - CPL_TYPE_INT, - cpl_parameter_get_help(par), - cpl_parameter_get_context(par), - cpl_parameter_get_default_int(par), - cpl_parameter_get_range_min_int(par), - cpl_parameter_get_range_max_int(par) - ); + cpl_parameter_get_name(par), CPL_TYPE_INT, + cpl_parameter_get_help(par), cpl_parameter_get_context(par), + cpl_parameter_get_default_int(par), + cpl_parameter_get_range_min_int(par), + cpl_parameter_get_range_max_int(par)); cpl_parameter_set_int(newpar, cpl_parameter_get_int(par)); break; case CPL_TYPE_DOUBLE: newpar = cpl_parameter_new_range( - cpl_parameter_get_name(par), - CPL_TYPE_DOUBLE, - cpl_parameter_get_help(par), - cpl_parameter_get_context(par), - cpl_parameter_get_default_double(par), - cpl_parameter_get_range_min_double(par), - cpl_parameter_get_range_max_double(par) - ); + cpl_parameter_get_name(par), CPL_TYPE_DOUBLE, + cpl_parameter_get_help(par), cpl_parameter_get_context(par), + cpl_parameter_get_default_double(par), + cpl_parameter_get_range_min_double(par), + cpl_parameter_get_range_max_double(par)); cpl_parameter_set_double(newpar, cpl_parameter_get_double(par)); break; @@ -1344,38 +1319,31 @@ /* We need to copy over additional information that is not settable by the cpl_parameter_new_range function. */ - cpl_parameter_set_default_flag( - newpar, cpl_parameter_get_default_flag(par)); + cpl_parameter_set_default_flag(newpar, + cpl_parameter_get_default_flag(par)); cpl_parameter_set_id(newpar, cpl_parameter_get_id(par)); - if (cpl_parameter_get_tag(par) != NULL) - { + if (cpl_parameter_get_tag(par) != NULL) { cpl_parameter_set_tag(newpar, cpl_parameter_get_tag(par)); } - cpl_parameter_mode mode[3] = { - CPL_PARAMETER_MODE_CLI, - CPL_PARAMETER_MODE_ENV, - CPL_PARAMETER_MODE_CFG - }; + cpl_parameter_mode mode[3] = { CPL_PARAMETER_MODE_CLI, + CPL_PARAMETER_MODE_ENV, + CPL_PARAMETER_MODE_CFG }; int n = 0; - for (n = 0; n < 3; ++n) - { + for (n = 0; n < 3; ++n) { cpl_parameter_set_alias(newpar, mode[n], cpl_parameter_get_alias(par, mode[n])); - if (cpl_parameter_is_enabled(par, mode[n])) - { + if (cpl_parameter_is_enabled(par, mode[n])) { cpl_parameter_enable(newpar, mode[n]); } - else - { + else { cpl_parameter_disable(newpar, mode[n]); } } return newpar; } - else - { + else { /* If dealing with any other parameter class then just use the normal duplicate method which should work fine. */ return cpl_parameter_duplicate(par); @@ -1388,12 +1356,13 @@ * Releases a NULL terminated array of strings and all the strings that it * contains. */ -static void free_string_array(char ** array) +static void +free_string_array(char **array) { - if (array == NULL) return; - char ** str = NULL; - for (str = array; *str != NULL; ++str) - { + if (array == NULL) + return; + char **str = NULL; + for (str = array; *str != NULL; ++str) { cpl_free(*str); } cpl_free(array); @@ -1409,17 +1378,16 @@ * plugin to initialise it. Specifically things like the recipe parameters and * recipe configuration information is copied over. */ -static int plugin_initialize(cpl_plugin * plugin) +static int +plugin_initialize(cpl_plugin *plugin) { - if (plugin == NULL) - { + if (plugin == NULL) { return cpl_error_set_message(cpl_func, CPL_ERROR_NULL_INPUT, "NULL received for the plugin."); } unsigned int plugin_api = cpl_plugin_get_api(plugin); - if (plugin_api != CPL_PLUGIN_API) - { + if (plugin_api != CPL_PLUGIN_API) { return cpl_error_set_message(cpl_func, CPL_ERROR_UNSUPPORTED_MODE, "Plugin API version %u is not supported.", plugin_api); @@ -1430,52 +1398,46 @@ object to be able to correctly fill in the parameters and configuration for the plugin structure received by this function. */ cx_map_iterator plgiter = cx_map_find(module_lut, plugin); - if (plgiter == cx_map_end(module_lut)) - { + if (plgiter == cx_map_end(module_lut)) { return cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, "Failed to find preloaded Python plugin" " object for '%s'.", cpl_plugin_get_name(plugin)); } - cpl_plugin * preloaded_plugin = (cpl_plugin *) cx_map_get_key(module_lut, - plgiter); - assert(cpl_plugin_get_type(plugin) - == cpl_plugin_get_type(preloaded_plugin)); + cpl_plugin *preloaded_plugin = + (cpl_plugin *)cx_map_get_key(module_lut, plgiter); + assert(cpl_plugin_get_type(plugin) == + cpl_plugin_get_type(preloaded_plugin)); /* Allocate the necessary data structures for the recipe plugin, based on the type of plugin we are dealing with. Also find the corresponding data strutures in the preloaded plugin. */ - cpl_parameterlist * params = NULL; - cpl_recipeconfig * config = NULL; - cpl_parameterlist * preloaded_params = NULL; - cpl_recipeconfig * preloaded_config = NULL; + cpl_parameterlist *params = NULL; + cpl_recipeconfig *config = NULL; + cpl_parameterlist *preloaded_params = NULL; + cpl_recipeconfig *preloaded_config = NULL; unsigned long plugin_type = cpl_plugin_get_type(plugin); - switch (plugin_type) - { - case CPL_PLUGIN_TYPE_RECIPE: - { - cpl_recipe * recipe = (cpl_recipe *) plugin; - recipe->parameters = cpl_parameterlist_new(); - params = recipe->parameters; - - recipe = (cpl_recipe *) preloaded_plugin; - preloaded_params = recipe->parameters; - } - break; - - case CPL_PLUGIN_TYPE_RECIPE_V2: - { - cpl_recipe2 * recipe = (cpl_recipe2 *) plugin; - recipe->base.parameters = cpl_parameterlist_new(); - params = recipe->base.parameters; - recipe->config = cpl_recipeconfig_new(); - config = recipe->config; - - recipe = (cpl_recipe2 *) preloaded_plugin; - preloaded_params = recipe->base.parameters; - preloaded_config = recipe->config; - } - break; + switch (plugin_type) { + case CPL_PLUGIN_TYPE_RECIPE: { + cpl_recipe *recipe = (cpl_recipe *)plugin; + recipe->parameters = cpl_parameterlist_new(); + params = recipe->parameters; + + recipe = (cpl_recipe *)preloaded_plugin; + preloaded_params = recipe->parameters; + } break; + + case CPL_PLUGIN_TYPE_RECIPE_V2: { + cpl_recipe2 *recipe = (cpl_recipe2 *)plugin; + recipe->base.parameters = cpl_parameterlist_new(); + params = recipe->base.parameters; + recipe->config = cpl_recipeconfig_new(); + config = recipe->config; + + recipe = (cpl_recipe2 *)preloaded_plugin; + preloaded_params = recipe->base.parameters; + preloaded_config = recipe->config; + } break; default: return cpl_error_set_message(cpl_func, CPL_ERROR_UNSUPPORTED_MODE, @@ -1487,23 +1449,20 @@ to skip the __class__ parameter from the preloaded parameter list since this was added internally when parsing the JSON output from the Python interpreter. */ - if (preloaded_params != NULL) - { - const cpl_parameter * last = - cpl_parameterlist_get_last_const(preloaded_params); + if (preloaded_params != NULL) { + const cpl_parameter *last = + cpl_parameterlist_get_last_const(preloaded_params); assert(strcmp(cpl_parameter_get_name(last), "__class__") == 0); - const cpl_parameter * par = NULL; + const cpl_parameter *par = NULL; for (par = cpl_parameterlist_get_first_const(preloaded_params); par != last; - par = cpl_parameterlist_get_next_const(preloaded_params)) - { + par = cpl_parameterlist_get_next_const(preloaded_params)) { #ifdef HAVE_BROKEN_CPL_PARAMETER_DUPLICATE - cpl_parameter * newpar = fixed_parameter_duplicate(par); + cpl_parameter *newpar = fixed_parameter_duplicate(par); #else - cpl_parameter * newpar = cpl_parameter_duplicate(par); + cpl_parameter *newpar = cpl_parameter_duplicate(par); #endif - if (cpl_parameterlist_append(params, newpar) != CPL_ERROR_NONE) - { + if (cpl_parameterlist_append(params, newpar) != CPL_ERROR_NONE) { cpl_parameter_delete(newpar); return cpl_error_get_code(); } @@ -1512,48 +1471,46 @@ /* Copy the recipe configuration structure if we are dealing with a version 2 type recipe structure. */ - if (preloaded_config != NULL) - { - char ** inputs = NULL; - char ** outputs = NULL; + if (preloaded_config != NULL) { + char **inputs = NULL; + char **outputs = NULL; cpl_size min, max; - char ** tags = cpl_recipeconfig_get_tags(preloaded_config); - if (tags == NULL) return cpl_error_get_code(); + char **tags = cpl_recipeconfig_get_tags(preloaded_config); + if (tags == NULL) + return cpl_error_get_code(); - char ** tag = NULL; - for (tag = tags; *tag != NULL; ++tag) - { + char **tag = NULL; + for (tag = tags; *tag != NULL; ++tag) { inputs = cpl_recipeconfig_get_inputs(preloaded_config, *tag); - if (inputs == NULL) break; + if (inputs == NULL) + break; outputs = cpl_recipeconfig_get_outputs(preloaded_config, *tag); - if (outputs == NULL) break; + if (outputs == NULL) + break; min = cpl_recipeconfig_get_min_count(preloaded_config, *tag, *tag); max = cpl_recipeconfig_get_max_count(preloaded_config, *tag, *tag); - if (cpl_recipeconfig_set_tag(config, *tag, min, max) != 0) break; + if (cpl_recipeconfig_set_tag(config, *tag, min, max) != 0) + break; - char ** input = NULL; - for (input = inputs; *input != NULL; ++input) - { - min = cpl_recipeconfig_get_min_count(preloaded_config, - *tag, *input); - max = cpl_recipeconfig_get_max_count(preloaded_config, - *tag, *input); - - if (cpl_recipeconfig_set_input(config, *tag, *input, min, max) - != 0) - { + char **input = NULL; + for (input = inputs; *input != NULL; ++input) { + min = cpl_recipeconfig_get_min_count(preloaded_config, *tag, + *input); + max = cpl_recipeconfig_get_max_count(preloaded_config, *tag, + *input); + + if (cpl_recipeconfig_set_input(config, *tag, *input, min, + max) != 0) { goto cleanup; } } - char ** output = NULL; - for (output = outputs; *output != NULL; ++output) - { - if (cpl_recipeconfig_set_output(config, *tag, *output) != 0) - { + char **output = NULL; + for (output = outputs; *output != NULL; ++output) { + if (cpl_recipeconfig_set_output(config, *tag, *output) != 0) { goto cleanup; } } @@ -1569,7 +1526,8 @@ free_string_array(tags); /* Check if we had an error during the copy. */ - if (cpl_error_get_code() != CPL_ERROR_NONE) return cpl_error_get_code(); + if (cpl_error_get_code() != CPL_ERROR_NONE) + return cpl_error_get_code(); } return CPL_ERROR_NONE; @@ -1582,7 +1540,8 @@ * * @return @c CPL_ERROR_NONE on success and an appropriate error code otherwise. */ -static cpl_error_code update_plugin(cpl_plugin * plugin, cpl_plugin * result) +static cpl_error_code +update_plugin(cpl_plugin *plugin, cpl_plugin *result) { assert(plugin != NULL); assert(result != NULL); @@ -1590,8 +1549,7 @@ /* Perform some sanity checks to make sure that the two plugin structures, are compatible. i.e. they must have the same API number, name, version and type code. */ - if (cpl_plugin_get_api(plugin) != cpl_plugin_get_api(result)) - { + if (cpl_plugin_get_api(plugin) != cpl_plugin_get_api(result)) { return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "Plugin API number %u for the returned" " plugin does not correspond to the" @@ -1600,8 +1558,7 @@ cpl_plugin_get_api(plugin)); } - if (cpl_plugin_get_version(plugin) != cpl_plugin_get_version(result)) - { + if (cpl_plugin_get_version(plugin) != cpl_plugin_get_version(result)) { return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "Plugin version %lu for the returned" " plugin does not correspond to the" @@ -1611,8 +1568,7 @@ } unsigned long plugin_type = cpl_plugin_get_type(plugin); - if (plugin_type != cpl_plugin_get_type(result)) - { + if (plugin_type != cpl_plugin_get_type(result)) { return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "Plugin type code %lu for the returned" " plugin does not correspond to the" @@ -1620,8 +1576,7 @@ cpl_plugin_get_type(result), plugin_type); } - if (strcmp(cpl_plugin_get_name(plugin), cpl_plugin_get_name(result)) != 0) - { + if (strcmp(cpl_plugin_get_name(plugin), cpl_plugin_get_name(result)) != 0) { return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "Plugin name '%s' for the returned" " plugin does not correspond to the" @@ -1632,27 +1587,22 @@ /* Prepare the pointers to the frameset objects in each of the plugins. This will then make it easier to update the data structures. */ - cpl_frameset * plugin_frames = NULL; - cpl_frameset * result_frames = NULL; - switch (plugin_type) - { - case CPL_PLUGIN_TYPE_RECIPE: - { - cpl_recipe * recipe = (cpl_recipe *) plugin; - plugin_frames = recipe->frames; - recipe = (cpl_recipe *) result; - result_frames = recipe->frames; - } - break; - - case CPL_PLUGIN_TYPE_RECIPE_V2: - { - cpl_recipe2 * recipe = (cpl_recipe2 *) plugin; - plugin_frames = recipe->base.frames; - recipe = (cpl_recipe2 *) result; - result_frames = recipe->base.frames; - } - break; + cpl_frameset *plugin_frames = NULL; + cpl_frameset *result_frames = NULL; + switch (plugin_type) { + case CPL_PLUGIN_TYPE_RECIPE: { + cpl_recipe *recipe = (cpl_recipe *)plugin; + plugin_frames = recipe->frames; + recipe = (cpl_recipe *)result; + result_frames = recipe->frames; + } break; + + case CPL_PLUGIN_TYPE_RECIPE_V2: { + cpl_recipe2 *recipe = (cpl_recipe2 *)plugin; + plugin_frames = recipe->base.frames; + recipe = (cpl_recipe2 *)result; + result_frames = recipe->base.frames; + } break; default: return cpl_error_set_message(cpl_func, CPL_ERROR_UNSUPPORTED_MODE, @@ -1660,14 +1610,12 @@ plugin_type); } - if (result_frames == NULL) - { + if (result_frames == NULL) { return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Received and empty frameset from the" " recipe plugin as output."); } - if (plugin_frames == NULL) - { + if (plugin_frames == NULL) { return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Plugin does not have its frameset" " initialised for updating."); @@ -1677,15 +1625,13 @@ existing plugin. N is the number of frames passed to the plugin recipe as input. This is necessary since the recipe plugin is expected to update the frame information. */ - cpl_frameset_iterator * ip = cpl_frameset_iterator_new(plugin_frames); - cpl_frameset_iterator * ir = cpl_frameset_iterator_new(result_frames); - cpl_frame * fp = cpl_frameset_iterator_get(ip); - cpl_frame * fr = cpl_frameset_iterator_get(ir); - while ((fp = cpl_frameset_iterator_get(ip)) != NULL) - { + cpl_frameset_iterator *ip = cpl_frameset_iterator_new(plugin_frames); + cpl_frameset_iterator *ir = cpl_frameset_iterator_new(result_frames); + cpl_frame *fp = cpl_frameset_iterator_get(ip); + cpl_frame *fr = cpl_frameset_iterator_get(ir); + while ((fp = cpl_frameset_iterator_get(ip)) != NULL) { fr = cpl_frameset_iterator_get(ir); - if (fr == NULL) - { + if (fr == NULL) { cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "The frameset returned from the plugin recipe" " is shorter than what was given to it."); @@ -1694,12 +1640,11 @@ /* We only copy the filename and tag if these were really changed. This avoids mallocs and frees. */ - if (strcmp(cpl_frame_get_filename(fp), cpl_frame_get_filename(fr)) != 0) - { + if (strcmp(cpl_frame_get_filename(fp), cpl_frame_get_filename(fr)) != + 0) { cpl_frame_set_filename(fp, cpl_frame_get_filename(fr)); } - if (strcmp(cpl_frame_get_tag(fp), cpl_frame_get_tag(fr)) != 0) - { + if (strcmp(cpl_frame_get_tag(fp), cpl_frame_get_tag(fr)) != 0) { cpl_frame_set_tag(fp, cpl_frame_get_tag(fr)); } @@ -1713,12 +1658,9 @@ cpl_frameset_iterator_delete(ip); /* Insert copies of all the new frames to the output plugin structure. */ - while ((fr = cpl_frameset_iterator_get(ir)) != NULL) - { - cpl_frame * newframe = cpl_frame_duplicate(fr); - if (cpl_frameset_insert(plugin_frames, newframe) - != CPL_ERROR_NONE) - { + while ((fr = cpl_frameset_iterator_get(ir)) != NULL) { + cpl_frame *newframe = cpl_frame_duplicate(fr); + if (cpl_frameset_insert(plugin_frames, newframe) != CPL_ERROR_NONE) { cpl_frame_delete(newframe); break; } @@ -1795,17 +1737,16 @@ * 'outputs': [(string), (string), ...] * } */ -static int plugin_execute(cpl_plugin * plugin) +static int +plugin_execute(cpl_plugin *plugin) { - if (plugin == NULL) - { + if (plugin == NULL) { return cpl_error_set_message(cpl_func, CPL_ERROR_NULL_INPUT, "NULL received for the plugin."); } unsigned int plugin_api = cpl_plugin_get_api(plugin); - if (plugin_api != CPL_PLUGIN_API) - { + if (plugin_api != CPL_PLUGIN_API) { return cpl_error_set_message(cpl_func, CPL_ERROR_UNSUPPORTED_MODE, "Plugin API version %u is not supported.", plugin_api); @@ -1816,39 +1757,33 @@ correctly identify the Python module and class name to use when invoking the Python recipe code. */ cx_map_iterator plgiter = cx_map_find(module_lut, plugin); - if (plgiter == cx_map_end(module_lut)) - { + if (plgiter == cx_map_end(module_lut)) { return cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, "Failed to find preloaded Python plugin" " object for '%s'.", cpl_plugin_get_name(plugin)); } - cpl_plugin * preloaded_plugin = (cpl_plugin *) cx_map_get_key(module_lut, - plgiter); - const char * module_path = (const char *) cx_map_get_value(module_lut, - plgiter); - assert(cpl_plugin_get_type(plugin) - == cpl_plugin_get_type(preloaded_plugin)); + cpl_plugin *preloaded_plugin = + (cpl_plugin *)cx_map_get_key(module_lut, plgiter); + const char *module_path = + (const char *)cx_map_get_value(module_lut, plgiter); + assert(cpl_plugin_get_type(plugin) == + cpl_plugin_get_type(preloaded_plugin)); /* Identify the needed parts of the recipe data that for the preloaded plugin object. */ - cpl_parameterlist * preloaded_params = NULL; + cpl_parameterlist *preloaded_params = NULL; unsigned long plugin_type = cpl_plugin_get_type(plugin); - switch (plugin_type) - { - case CPL_PLUGIN_TYPE_RECIPE: - { - cpl_recipe * recipe = (cpl_recipe *) preloaded_plugin; - preloaded_params = recipe->parameters; - } - break; - - case CPL_PLUGIN_TYPE_RECIPE_V2: - { - cpl_recipe2 * recipe = (cpl_recipe2 *) preloaded_plugin; - preloaded_params = recipe->base.parameters; - } - break; + switch (plugin_type) { + case CPL_PLUGIN_TYPE_RECIPE: { + cpl_recipe *recipe = (cpl_recipe *)preloaded_plugin; + preloaded_params = recipe->parameters; + } break; + + case CPL_PLUGIN_TYPE_RECIPE_V2: { + cpl_recipe2 *recipe = (cpl_recipe2 *)preloaded_plugin; + preloaded_params = recipe->base.parameters; + } break; default: return cpl_error_set_message(cpl_func, CPL_ERROR_UNSUPPORTED_MODE, @@ -1857,151 +1792,144 @@ } /* Identify the Python class that we will have to instantiate. */ - if (preloaded_params == NULL) - { + if (preloaded_params == NULL) { return cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, "Missing parameter list in preloaded" " Python plugin object for '%s'.", cpl_plugin_get_name(plugin)); } - const cpl_parameter * param = + const cpl_parameter *param = cpl_parameterlist_get_last_const(preloaded_params); - if (param == NULL) - { + if (param == NULL) { return cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, "Parameter list in preloaded Python plugin" " object for '%s' is empty.", cpl_plugin_get_name(plugin)); } assert(strcmp(cpl_parameter_get_name(param), "__class__") == 0); - const char * class_name = cpl_parameter_get_string(param); - if (class_name == NULL) return cpl_error_get_code(); + const char *class_name = cpl_parameter_get_string(param); + if (class_name == NULL) + return cpl_error_get_code(); /* Need to convert the plugin object to JSON text to send to the Python interpreter. */ - char * plugin_data = er_plugin_to_json(plugin); + char *plugin_data = er_plugin_to_json(plugin); /* Extract the module name to be used in the Python import statement. We also extract the directory to the module while we are at it. NOTE: basename takes a "char *" string, not a "const char *" string. Thus, we create a modifiable string, just in case. */ - char * modpath = cpl_strdup(module_path); - char * module_name = cpl_strdup(basename(modpath)); + char *modpath = cpl_strdup(module_path); + char *module_name = cpl_strdup(basename(modpath)); cpl_free(modpath); modpath = cpl_strdup(module_path); - char * module_dir = cpl_strdup(dirname(modpath)); + char *module_dir = cpl_strdup(dirname(modpath)); cpl_free(modpath); - char * pos = strchr(module_name, '.'); - if (pos != NULL) *pos = '\0'; + char *pos = strchr(module_name, '.'); + if (pos != NULL) + *pos = '\0'; /* The following script attempts to load the Python module, instantiate the appropriate Python class and invoke it's execute method. The updated data is finally converted to JSON and written to the pipe connected to the EsoRex process. */ - char * script = cpl_sprintf( - "sys.path.append(_data['modulepath'])\n" - "import %s\n" - "plugin = %s.%s()\n" - "result = plugin.execute(_data['plugin'])\n" - "if hasattr(plugin, 'error_message'):\n" - " error_message = getattr(plugin, 'error_message')\n" - "else:" - " error_message = None\n" - "json.dump({'result': result, 'error': error_message," - " 'plugin': _data['plugin']}," - " os.fdopen("CPL_STRINGIFY(PYTHON_OUTPUT_FD)",'w')," - " indent=2)\n", - module_name, module_name, class_name - ); + char *script = + cpl_sprintf("sys.path.append(_data['modulepath'])\n" + "import %s\n" + "plugin = %s.%s()\n" + "result = plugin.execute(_data['plugin'])\n" + "if hasattr(plugin, 'error_message'):\n" + " error_message = getattr(plugin, 'error_message')\n" + "else:" + " error_message = None\n" + "json.dump({'result': result, 'error': error_message," + " 'plugin': _data['plugin']}," + " os.fdopen(" CPL_STRINGIFY(PYTHON_OUTPUT_FD) ",'w')," + " indent=2)\n", + module_name, module_name, class_name); cpl_free(module_name); - char * excaped_script = er_json_escape_string(script); + char *excaped_script = er_json_escape_string(script); cpl_free(script); /* Create the input for the above script. NOTE: cpl_sprintf will create a valid buffer or terminate the process. */ - char * input = cpl_sprintf( - "{\n" - " \"script\": \"%s\",\n" - " \"modulepath\": \"%s\",\n" - " \"plugin\": %s\n" - "}", - excaped_script, module_dir, plugin_data); + char *input = cpl_sprintf("{\n" + " \"script\": \"%s\",\n" + " \"modulepath\": \"%s\",\n" + " \"plugin\": %s\n" + "}", + excaped_script, module_dir, plugin_data); cpl_free(excaped_script); cpl_free(module_dir); cpl_free(plugin_data); - char * output = run_python_command(python_start_command, input); + char *output = run_python_command(python_start_command, input); cpl_free(input); - if (output == NULL) return cpl_error_get_code(); + if (output == NULL) + return cpl_error_get_code(); /* Parse the output JSON and convert to appropriate CPL objects. */ - er_json_node * parsetree = er_json_parse(output); - if (parsetree == NULL) - { + er_json_node *parsetree = er_json_parse(output); + if (parsetree == NULL) { free(output); return cpl_error_get_code(); } /* Make sure the top level node in the parse tree is an object. */ - if (er_json_node_type(parsetree) != JSON_OBJECT) - { + if (er_json_node_type(parsetree) != JSON_OBJECT) { int line, col; er_json_find_line_column(output, er_json_node_location(parsetree), &line, &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, - "Expected an object at line %d column %d.", - line, col); + "Expected an object at line %d column %d.", line, + col); er_json_node_delete(parsetree); free(output); return cpl_error_get_code(); } /* Get the result field from the parsed output. */ - const er_json_node * node = er_json_node_object_get(parsetree, "result"); - if (node == NULL) - { + const er_json_node *node = er_json_node_object_get(parsetree, "result"); + if (node == NULL) { int line, col; er_json_find_line_column(output, er_json_node_location(parsetree), &line, &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Missing a 'result' key in output object at line" - " %d column %d.", line, col); + " %d column %d.", + line, col); er_json_node_delete(parsetree); free(output); return cpl_error_get_code(); } - if (er_json_node_type(node) != JSON_NUMBER) - { + if (er_json_node_type(node) != JSON_NUMBER) { int line, col; - er_json_find_line_column(output, er_json_node_location(node), - &line, &col); + er_json_find_line_column(output, er_json_node_location(node), &line, + &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Expected a number for key 'result' in output" - " object at line %d column %d.", line, col); + " object at line %d column %d.", + line, col); er_json_node_delete(parsetree); free(output); return cpl_error_get_code(); } - int result = (int) er_json_node_get_number(node); - if (result != 0) - { + int result = (int)er_json_node_get_number(node); + if (result != 0) { /* An error was marked by returning non-zero from the Python plugin's execute method call. Now attempt to get the error message. If there was not error message as a atring object then just produce a defualt error message instead. */ - const char * error_msg = NULL; + const char *error_msg = NULL; node = er_json_node_object_get(parsetree, "error"); - if (node != NULL && er_json_node_type(node) == JSON_STRING) - { + if (node != NULL && er_json_node_type(node) == JSON_STRING) { error_msg = er_json_node_get_string(node); } - if (error_msg != NULL) - { + if (error_msg != NULL) { cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_OUTPUT, "%s", error_msg); } - else - { + else { cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_OUTPUT, "Plugin execution failed with error code %d", result); @@ -2015,21 +1943,20 @@ object that was passed to this function, by copying all the new frames back to the plugin object. */ node = er_json_node_object_get(parsetree, "plugin"); - if (node == NULL) - { + if (node == NULL) { int line, col; er_json_find_line_column(output, er_json_node_location(parsetree), &line, &col); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Missing a 'plugin' key in output object at line" - " %d column %d.", line, col); + " %d column %d.", + line, col); er_json_node_delete(parsetree); free(output); return cpl_error_get_code(); } - cpl_plugin * plugin_result = er_json_to_plugin(node, output); - if (plugin_result == NULL) - { + cpl_plugin *plugin_result = er_json_to_plugin(node, output); + if (plugin_result == NULL) { er_json_node_delete(parsetree); free(output); return cpl_error_get_code(); @@ -2050,39 +1977,33 @@ * for the new plugin objects that it creates. It will free memory by deleting * any objects created and added to the plugin by plugin_initialize(). */ -static int plugin_deinitialize(cpl_plugin * plugin) +static int +plugin_deinitialize(cpl_plugin *plugin) { - if (plugin == NULL) - { + if (plugin == NULL) { return cpl_error_set_message(cpl_func, CPL_ERROR_NULL_INPUT, "NULL received for the plugin."); } unsigned int plugin_api = cpl_plugin_get_api(plugin); - if (plugin_api != CPL_PLUGIN_API) - { + if (plugin_api != CPL_PLUGIN_API) { return cpl_error_set_message(cpl_func, CPL_ERROR_UNSUPPORTED_MODE, "Plugin API version %u is not supported.", plugin_api); } unsigned long plugin_type = cpl_plugin_get_type(plugin); - switch (plugin_type) - { - case CPL_PLUGIN_TYPE_RECIPE: - { - cpl_recipe * recipe = (cpl_recipe *) plugin; - cpl_parameterlist_delete(recipe->parameters); - } - break; - - case CPL_PLUGIN_TYPE_RECIPE_V2: - { - cpl_recipe2 * recipe = (cpl_recipe2 *) plugin; - cpl_recipeconfig_delete(recipe->config); - cpl_parameterlist_delete(recipe->base.parameters); - } - break; + switch (plugin_type) { + case CPL_PLUGIN_TYPE_RECIPE: { + cpl_recipe *recipe = (cpl_recipe *)plugin; + cpl_parameterlist_delete(recipe->parameters); + } break; + + case CPL_PLUGIN_TYPE_RECIPE_V2: { + cpl_recipe2 *recipe = (cpl_recipe2 *)plugin; + cpl_recipeconfig_delete(recipe->config); + cpl_parameterlist_delete(recipe->base.parameters); + } break; default: return cpl_error_set_message(cpl_func, CPL_ERROR_UNSUPPORTED_MODE, @@ -2106,33 +2027,31 @@ * @return @c 0 is returned on success and an appropriate CPL error code * otherwise. */ -int er_python_get_plugin_list(cpl_pluginlist * list) +int +er_python_get_plugin_list(cpl_pluginlist *list) { cpl_error_ensure(list != NULL, CPL_ERROR_NULL_INPUT, return CPL_ERROR_NULL_INPUT, "NULL pointer given for list."); - if (current_module == NULL) - { + if (current_module == NULL) { return cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, "Python module has not been selected yet" " with er_python_select_module."); } - cpl_pluginlist * pluginlist = - (cpl_pluginlist *) cx_map_get_value(module_list, current_module); + cpl_pluginlist *pluginlist = + (cpl_pluginlist *)cx_map_get_value(module_list, current_module); assert(pluginlist != NULL); /* Copy all the plugins we found in er_python_load_modules into the output list. But we only copy the base plugin information, not the parameters. The parameters need to be initialised in the plugin->initialize function. */ - cpl_plugin * rawplugin = NULL; - for (rawplugin = cpl_pluginlist_get_first(pluginlist); - rawplugin != NULL; - rawplugin = cpl_pluginlist_get_next(pluginlist)) - { - cpl_plugin * plugin = cpl_plugin_new(); + cpl_plugin *rawplugin = NULL; + for (rawplugin = cpl_pluginlist_get_first(pluginlist); rawplugin != NULL; + rawplugin = cpl_pluginlist_get_next(pluginlist)) { + cpl_plugin *plugin = cpl_plugin_new(); cpl_error_code result = CPL_ERROR_NONE; result |= cpl_plugin_copy(plugin, rawplugin); @@ -2143,8 +2062,7 @@ result |= cpl_plugin_set_exec(plugin, plugin_execute); result |= cpl_plugin_set_deinit(plugin, plugin_deinitialize); - if (result != CPL_ERROR_NONE) - { + if (result != CPL_ERROR_NONE) { cpl_plugin_delete(plugin); return cpl_error_set_message(cpl_func, cpl_error_get_code(), "Failed to create a copy of a plugin" @@ -2152,8 +2070,7 @@ " output list."); } - if (cpl_pluginlist_append(list, plugin) != CPL_ERROR_NONE) - { + if (cpl_pluginlist_append(list, plugin) != CPL_ERROR_NONE) { cpl_plugin_delete(plugin); return cpl_error_set_message(cpl_func, cpl_error_get_code(), "Failed to create a copy of a plugin" @@ -2171,7 +2088,8 @@ * This function should be called when one no longer needs to deal with any * Python based plugins. */ -void er_python_cleanup(void) +void +er_python_cleanup(void) { current_module = NULL; diff -Nru esorex-3.13.5+ds/src/er_python.h esorex-3.13.6+ds/src/er_python.h --- esorex-3.13.5+ds/src/er_python.h 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/er_python.h 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2017 European Southern Observatory + * Copyright (C) 2017-2022 European Southern Observatory * * 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 diff -Nru esorex-3.13.5+ds/src/er_stringarray.c esorex-3.13.6+ds/src/er_stringarray.c --- esorex-3.13.5+ds/src/er_stringarray.c 2021-06-02 15:06:13.000000000 +0000 +++ esorex-3.13.6+ds/src/er_stringarray.c 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 European Southern Observatory * * 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 @@ -46,8 +46,8 @@ */ struct er_stringarray_s { - char **strings; - int nstrings; + char **strings; + int nstrings; }; @@ -59,23 +59,23 @@ */ /**********************************************************************/ -er_stringarray_t * er_stringarray_new(void) +er_stringarray_t * +er_stringarray_new(void) { er_stringarray_t *csa; - csa = (er_stringarray_t *) cpl_malloc((size_t)sizeof(er_stringarray_t)); + csa = (er_stringarray_t *)cpl_malloc((size_t)sizeof(er_stringarray_t)); - if (csa != NULL) - { - csa->strings = NULL; + if (csa != NULL) { + csa->strings = NULL; csa->nstrings = 0; } return csa; -} /* End of er_stringarray_new() */ +} /* End of er_stringarray_new() */ /**********************************************************************/ @@ -95,53 +95,48 @@ */ /**********************************************************************/ -void er_stringarray_resize ( er_stringarray_t *csa, int size) +void +er_stringarray_resize(er_stringarray_t *csa, int size) { - int i; + int i; char **tmp; - if (csa==NULL) return; + if (csa == NULL) + return; - if (size==csa->nstrings) return; + if (size == csa->nstrings) + return; - tmp = (char **) cpl_calloc((size_t)size, (size_t)sizeof(char *)); + tmp = (char **)cpl_calloc((size_t)size, (size_t)sizeof(char *)); - if (size < csa->nstrings) - { - for (i=0; instrings) { + for (i = 0; i < size; i++) { tmp[i] = csa->strings[i]; } - for (i=size; instrings; i++) - { + for (i = size; i < csa->nstrings; i++) { cpl_free(csa->strings[i]); } - } - else - { - for (i=0; instrings; i++) - { + else { + for (i = 0; i < csa->nstrings; i++) { tmp[i] = csa->strings[i]; } - for (i=csa->nstrings; instrings; i < size; i++) { tmp[i] = NULL; } } - cpl_free(csa->strings); /* get rid of old pointer array */ + cpl_free(csa->strings); /* get rid of old pointer array */ - csa->nstrings = size; /* fill structure with new values */ - csa->strings = tmp; - -} + csa->nstrings = size; /* fill structure with new values */ + csa->strings = tmp; +} /**********************************************************************/ /** @@ -156,27 +151,27 @@ */ /**********************************************************************/ -void er_stringarray_delete ( er_stringarray_t *csa) +void +er_stringarray_delete(er_stringarray_t *csa) { int i; - if (csa==NULL) return; + if (csa == NULL) + return; - if (csa->strings!=NULL) - { - for (i=0; instrings; i++) - { - if (csa->strings[i] != NULL ) cpl_free(csa->strings[i]); + if (csa->strings != NULL) { + for (i = 0; i < csa->nstrings; i++) { + if (csa->strings[i] != NULL) + cpl_free(csa->strings[i]); } cpl_free(csa->strings); } cpl_free(csa); - -} +} /**********************************************************************/ /** @@ -190,16 +185,18 @@ */ /**********************************************************************/ -char* er_stringarray_get ( er_stringarray_t *csa, int indx) +char * +er_stringarray_get(er_stringarray_t *csa, int indx) { - - if (csa == NULL) return NULL; - if (csa->strings == NULL) return NULL; - if ( (indx < 0) || (indx > csa->nstrings) ) return NULL; + if (csa == NULL) + return NULL; + if (csa->strings == NULL) + return NULL; + if ((indx < 0) || (indx > csa->nstrings)) + return NULL; return csa->strings[indx]; - } @@ -216,27 +213,29 @@ */ /**********************************************************************/ -void er_stringarray_set (er_stringarray_t *csa, const char *instring, int indx) +void +er_stringarray_set(er_stringarray_t *csa, const char *instring, int indx) { - char *cpt; + char *cpt; - if (csa == NULL) return; - if (csa->strings == NULL) return; - if ( (indx < 0) || (indx > csa->nstrings) ) return; + if (csa == NULL) + return; + if (csa->strings == NULL) + return; + if ((indx < 0) || (indx > csa->nstrings)) + return; - if (csa->strings[indx] != NULL ) - { + if (csa->strings[indx] != NULL) { cpl_free(csa->strings[indx]); } - cpt = cpl_malloc((size_t)((int)strlen(instring)+1)); - if (cpt != NULL) csa->strings[indx] = cpt; - (void) strcpy(csa->strings[indx],instring); - -} - + cpt = cpl_malloc((size_t)((int)strlen(instring) + 1)); + if (cpt != NULL) + csa->strings[indx] = cpt; + (void)strcpy(csa->strings[indx], instring); +} /**********************************************************************/ @@ -251,20 +250,21 @@ */ /**********************************************************************/ -void er_stringarray_append ( er_stringarray_t *csa, const char *instring) +void +er_stringarray_append(er_stringarray_t *csa, const char *instring) { int new_size = 0; - if (csa==NULL) return; + if (csa == NULL) + return; new_size = csa->nstrings + 1; er_stringarray_resize(csa, new_size); - er_stringarray_set(csa, instring, new_size-1); - -} + er_stringarray_set(csa, instring, new_size - 1); +} /**********************************************************************/ @@ -280,26 +280,26 @@ */ /**********************************************************************/ -void er_stringarray_remove ( er_stringarray_t *csa, int indx) +void +er_stringarray_remove(er_stringarray_t *csa, int indx) { + if (csa == NULL) + return; + if (csa->strings == NULL) + return; + if ((indx < 0) || (indx > csa->nstrings)) + return; - if (csa == NULL) return; - if (csa->strings == NULL) return; - if ( (indx < 0) || (indx > csa->nstrings) ) return; - - if (csa->strings[indx] != NULL) - { + if (csa->strings[indx] != NULL) { cpl_free(csa->strings[indx]); csa->strings[indx] = NULL; } return; - } - /**********************************************************************/ /** * @brief @@ -313,21 +313,22 @@ */ /**********************************************************************/ -int er_stringarray_present ( er_stringarray_t *csa, int indx) +int +er_stringarray_present(er_stringarray_t *csa, int indx) { - - if (csa == NULL) return 0; - if (csa->strings == NULL) return 0; - if ((indx < 0) || (indx > csa->nstrings) ) return 0; + if (csa == NULL) + return 0; + if (csa->strings == NULL) + return 0; + if ((indx < 0) || (indx > csa->nstrings)) + return 0; if (csa->strings[indx] != NULL) return 1; return 0; - -} - +} /**********************************************************************/ @@ -341,19 +342,19 @@ */ /**********************************************************************/ -int er_stringarray_size ( er_stringarray_t *csa) +int +er_stringarray_size(er_stringarray_t *csa) { + if (csa == NULL) + return 0; + if (csa->strings == NULL) + return 0; - if (csa == NULL) return 0; - if (csa->strings == NULL) return 0; - - return(csa->nstrings); - + return (csa->nstrings); } - /**********************************************************************/ /** * @brief Prints a stringarray to standardformat @@ -365,26 +366,24 @@ */ /**********************************************************************/ -void er_stringarray_print ( er_stringarray_t *csa) +void +er_stringarray_print(er_stringarray_t *csa) { int i; - if (csa == NULL) return; + if (csa == NULL) + return; - if (csa->strings != NULL) - { - for (i = 0; i < csa->nstrings; i++) - { - if (csa->strings[i] != NULL ) - { - printf("%d : %s\n",i,csa->strings[i]); + if (csa->strings != NULL) { + for (i = 0; i < csa->nstrings; i++) { + if (csa->strings[i] != NULL) { + printf("%d : %s\n", i, csa->strings[i]); } } } - -} +} /**@}*/ diff -Nru esorex-3.13.5+ds/src/er_stringarray.h esorex-3.13.6+ds/src/er_stringarray.h --- esorex-3.13.5+ds/src/er_stringarray.h 2021-06-02 15:06:13.000000000 +0000 +++ esorex-3.13.6+ds/src/er_stringarray.h 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 European Southern Observatory * * 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 diff -Nru esorex-3.13.5+ds/src/er_stringutils.c esorex-3.13.6+ds/src/er_stringutils.c --- esorex-3.13.5+ds/src/er_stringutils.c 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/er_stringutils.c 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 European Southern Observatory * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif #include @@ -43,9 +43,8 @@ #include "er_stringutils.h" -#define MAX_DBL_STR 16 -#define COMMENT_TAB_POSITION 24 - +#define MAX_DBL_STR 16 +#define COMMENT_TAB_POSITION 24 /** @@ -72,39 +71,39 @@ */ /**********************************************************************/ -char *er_strutils_indent (const char * str, int indent) +char * +er_strutils_indent(const char *str, int indent) { static char output[MAX_MSG_LENGTH]; - const char *warning = "\n ... [ TEXT TRUNCATED - MAXIMUM STRING LENGTH EXCEEDED ]\n"; + const char *warning = + "\n ... [ TEXT TRUNCATED - MAXIMUM STRING LENGTH EXCEEDED ]\n"; int c, i, s; - memset (output, 0, MAX_MSG_LENGTH); + memset(output, 0, MAX_MSG_LENGTH); c = 0; - for (s=0; s<(int)strlen(str); s++) - { - if (c >= (MAX_MSG_LENGTH - 2 - indent)) - { - (void) strcpy (&output[MAX_MSG_LENGTH - 2 - strlen (warning)], warning); + for (s = 0; s < (int)strlen(str); s++) { + if (c >= (MAX_MSG_LENGTH - 2 - indent)) { + (void)strcpy(&output[MAX_MSG_LENGTH - 2 - strlen(warning)], + warning); /* Put a "safety-nul" on the end and return */ output[MAX_MSG_LENGTH - 1] = '\0'; return (output); } output[c++] = str[s]; - if (str[s] == '\n') - { - for (i = 0; i < indent; i++) output[c++] = ' '; + if (str[s] == '\n') { + for (i = 0; i < indent; i++) + output[c++] = ' '; } } /* Put a "safety-nul" on the end and return */ output[MAX_MSG_LENGTH - 1] = '\0'; return (output); - -} +} /**********************************************************************/ /* @@ -136,7 +135,8 @@ */ /**********************************************************************/ -char *er_strutils_split (const char *ss, int blanks, int width) +char * +er_strutils_split(const char *ss, int blanks, int width) { static char split[MAX_MSG_LENGTH]; @@ -152,94 +152,85 @@ /* if the keyword name (alias) itself is large, we split it up as well and start description on the next line (the original split function failed on that) */ - if (blanks < (width/2)) - { - s = (char *) ss; /* take full string as it is */ + if (blanks < (width / 2)) { + s = (char *)ss; /* take full string as it is */ } - else - { - char csav; - - savptr = (char *) malloc((size_t)(blanks+2)); - (void) strncpy(savptr,ss,blanks); /* isolate keyword name in savptr */ - *(savptr+blanks) = '\0'; + else { + char csav; + + savptr = (char *)malloc((size_t)(blanks + 2)); + (void)strncpy(savptr, ss, blanks); /* isolate keyword name in savptr */ + *(savptr + blanks) = '\0'; limit = width; - m = 0, nn = blanks; /* nn = length of keyword string */ - splitting: - s = savptr+m; - if (nn <= limit) - { /* end of string reached */ + m = 0, nn = blanks; /* nn = length of keyword string */ + splitting: + s = savptr + m; + if (nn <= limit) { /* end of string reached */ if (limit == width) - (void) printf("%s\n",s); + (void)printf("%s\n", s); else - (void) printf(" --%s\n",s); + (void)printf(" --%s\n", s); } - else - { - for (i=limit; i>0; i--) - { - if (s[i] == ' ' || s[i] == '\t' || s[i] == '\n') - { + else { + for (i = limit; i > 0; i--) { + if (s[i] == ' ' || s[i] == '\t' || s[i] == '\n') { s[i] = '\0'; - if (m == 0) /* 1st time */ + if (m == 0) /* 1st time */ { - (void) printf("%s\n",s); - limit = width - 4; /* because of " --" in the beginning */ + (void)printf("%s\n", s); + limit = + width - 4; /* because of " --" in the beginning */ } - else - { - (void) printf(" --%s\n",s); + else { + (void)printf(" --%s\n", s); } - m += (i+1); nn -= i; + m += (i + 1); + nn -= i; goto splitting; } } - csav = s[limit]; /* full line without spaces ... */ + csav = s[limit]; /* full line without spaces ... */ s[limit] = '\0'; - if (m == 0) /* 1st time */ + if (m == 0) /* 1st time */ { - (void) printf("%s\n",s); - limit = width - 4; /* because of " --" in the beginning */ + (void)printf("%s\n", s); + limit = width - 4; /* because of " --" in the beginning */ } - else - { - (void) printf(" --%s\n",s); + else { + (void)printf(" --%s\n", s); } s[limit] = csav; - m += limit; nn -= limit; + m += limit; + nn -= limit; goto splitting; } - m = blanks; /* offset description to default tab size */ + m = blanks; /* offset description to default tab size */ blanks = COMMENT_TAB_POSITION + 2; - nn = strlen(ss)-m; /* replace original name by new no. of blanks */ - s = (char *) malloc((size_t)(nn+blanks+2)); - for (i=0; i limit) - { + if (s[i] == ' ' || s[i] == '\t' || s[i] == '\0' || s[i] == '\n') { + if (i > limit) { /* Go back to the previous cuttable position, if possible */ - if (limit - cuti < width - blanks) - { + if (limit - cuti < width - blanks) { j = cutj; i = cuti; } - else - { + else { if (s[i] == '\0') break; } @@ -247,33 +238,29 @@ /* Split here, and insert blanks */ split[j] = '\n'; - for (k=0, j++; k= MAX_DBL_STR) - { - cpl_msg_warning ("strutils_dblstr", "Some precision may have been lost in the " - "conversion of the value '%s...'", er_buf); + if (prec >= MAX_DBL_STR) { + cpl_msg_warning("strutils_dblstr", + "Some precision may have been lost in the " + "conversion of the value '%s...'", + er_buf); } /* Now check for the case that there is no decimal point */ ptr = er_buf; - if (strstr (ptr, ".") == NULL) - { /* Now check if it is scientific notation */ - if (strstr (ptr, "e") == NULL) - { /* The representation is decimal - simply append */ - (void) strcat (er_buf, ".0"); + if (strstr(ptr, ".") == NULL) { /* Now check if it is scientific notation */ + if (strstr(ptr, "e") == + NULL) { /* The representation is decimal - simply append */ + (void)strcat(er_buf, ".0"); } } diff -Nru esorex-3.13.5+ds/src/er_stringutils.h esorex-3.13.6+ds/src/er_stringutils.h --- esorex-3.13.5+ds/src/er_stringutils.h 2021-06-02 15:06:13.000000000 +0000 +++ esorex-3.13.6+ds/src/er_stringutils.h 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 European Southern Observatory * * 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 @@ -21,16 +21,16 @@ #define ER_STRINGUTILS_H /* This constant is from cpl_msg.c */ -#define MAX_MSG_LENGTH (16384) -#define DEFAULT_TERM_WIDTH (80) +#define MAX_MSG_LENGTH (16384) +#define DEFAULT_TERM_WIDTH (80) CPL_BEGIN_DECLS -extern char * er_strutils_indent( const char *str, int ); -extern char * er_strutils_split ( const char *, int, int ); -extern int er_strutils_termwidth ( void ); -extern int er_strutils_termheight ( void ); -extern const char * er_strutils_dblstr( double ); +extern char *er_strutils_indent(const char *str, int); +extern char *er_strutils_split(const char *, int, int); +extern int er_strutils_termwidth(void); +extern int er_strutils_termheight(void); +extern const char *er_strutils_dblstr(double); extern void er_strutils_scrtest(void); CPL_END_DECLS diff -Nru esorex-3.13.5+ds/src/Makefile.am esorex-3.13.6+ds/src/Makefile.am --- esorex-3.13.5+ds/src/Makefile.am 2021-06-02 15:06:13.000000000 +0000 +++ esorex-3.13.6+ds/src/Makefile.am 2022-04-29 16:21:07.000000000 +0000 @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in ## This file is part of the ESO Recipe Execution Tool -## Copyright (C) 2002-2017 European Southern Observatory +## Copyright (C) 2002-2022 European Southern Observatory ## 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 diff -Nru esorex-3.13.5+ds/src/tests/esorex_json_internal-test.c esorex-3.13.6+ds/src/tests/esorex_json_internal-test.c --- esorex-3.13.5+ds/src/tests/esorex_json_internal-test.c 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/tests/esorex_json_internal-test.c 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 European Southern Observatory * * 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 @@ -38,79 +38,82 @@ /* Tests if two CPL recipe configuration objects are equal or not, i.e. are all their attributes the same or not. */ -#define test_equal_config(first, second) \ - { \ - char ** tag = NULL; \ - char ** ptr = NULL; \ - char ** first_tags = cpl_recipeconfig_get_tags(first); \ - cpl_test_assert(first_tags != NULL); \ - char ** second_tags = cpl_recipeconfig_get_tags(second); \ - cpl_test_assert(second_tags != NULL); \ - char ** first_tag = first_tags; \ - char ** second_tag = second_tags; \ - while (*first_tag != NULL && *second_tag != NULL) { \ - cpl_test_eq_string(*first_tag, *second_tag); \ - ++first_tag; \ - ++second_tag; \ - } \ - cpl_test_assert(*first_tag == NULL && *second_tag == NULL); \ - for (tag = first_tags; *tag != NULL; ++tag) { \ - cpl_test_eq( \ - cpl_recipeconfig_get_min_count(first, *tag, *tag), \ - cpl_recipeconfig_get_min_count(second, *tag, *tag) \ - ); \ - cpl_test_eq( \ - cpl_recipeconfig_get_max_count(first, *tag, *tag), \ - cpl_recipeconfig_get_max_count(second, *tag, *tag) \ - ); \ - char ** first_inputs = cpl_recipeconfig_get_inputs(first, *tag); \ - cpl_test_assert(first_inputs != NULL); \ - char ** second_inputs = cpl_recipeconfig_get_inputs(second, *tag); \ - cpl_test_assert(second_inputs != NULL); \ - char ** first_outputs = cpl_recipeconfig_get_outputs(first, *tag); \ - cpl_test_assert(first_outputs != NULL); \ - char ** second_outputs = cpl_recipeconfig_get_outputs(second,*tag);\ - cpl_test_assert(second_outputs != NULL); \ - char ** first_input = first_inputs; \ - char ** second_input = second_inputs; \ - while (*first_input != NULL && *second_input != NULL) { \ - cpl_test_eq_string(*first_input, *second_input); \ - ++first_input; \ - ++second_input; \ - } \ - cpl_test_assert(*first_input == NULL && *second_input == NULL); \ - char ** first_output = first_outputs; \ - char ** second_output = second_outputs; \ - while (*first_output != NULL && *second_output != NULL) { \ - cpl_test_eq_string(*first_output, *second_output); \ - ++first_output; \ - ++second_output; \ - } \ +#define test_equal_config(first, second) \ + { \ + char **tag = NULL; \ + char **ptr = NULL; \ + char **first_tags = cpl_recipeconfig_get_tags(first); \ + cpl_test_assert(first_tags != NULL); \ + char **second_tags = cpl_recipeconfig_get_tags(second); \ + cpl_test_assert(second_tags != NULL); \ + char **first_tag = first_tags; \ + char **second_tag = second_tags; \ + while (*first_tag != NULL && *second_tag != NULL) { \ + cpl_test_eq_string(*first_tag, *second_tag); \ + ++first_tag; \ + ++second_tag; \ + } \ + cpl_test_assert(*first_tag == NULL && *second_tag == NULL); \ + for (tag = first_tags; *tag != NULL; ++tag) { \ + cpl_test_eq(cpl_recipeconfig_get_min_count(first, *tag, *tag), \ + cpl_recipeconfig_get_min_count(second, *tag, *tag)); \ + cpl_test_eq(cpl_recipeconfig_get_max_count(first, *tag, *tag), \ + cpl_recipeconfig_get_max_count(second, *tag, *tag)); \ + char **first_inputs = cpl_recipeconfig_get_inputs(first, *tag); \ + cpl_test_assert(first_inputs != NULL); \ + char **second_inputs = cpl_recipeconfig_get_inputs(second, *tag); \ + cpl_test_assert(second_inputs != NULL); \ + char **first_outputs = cpl_recipeconfig_get_outputs(first, *tag); \ + cpl_test_assert(first_outputs != NULL); \ + char **second_outputs = \ + cpl_recipeconfig_get_outputs(second, *tag); \ + cpl_test_assert(second_outputs != NULL); \ + char **first_input = first_inputs; \ + char **second_input = second_inputs; \ + while (*first_input != NULL && *second_input != NULL) { \ + cpl_test_eq_string(*first_input, *second_input); \ + ++first_input; \ + ++second_input; \ + } \ + cpl_test_assert(*first_input == NULL && *second_input == NULL); \ + char **first_output = first_outputs; \ + char **second_output = second_outputs; \ + while (*first_output != NULL && *second_output != NULL) { \ + cpl_test_eq_string(*first_output, *second_output); \ + ++first_output; \ + ++second_output; \ + } \ cpl_test_assert(*first_output == NULL && *second_output == NULL); \ - char ** input = NULL; \ - for (input = first_inputs; *input != NULL; ++input) { \ - cpl_test_eq( \ - cpl_recipeconfig_get_min_count(first, *tag, *input), \ - cpl_recipeconfig_get_min_count(second, *tag, *input) \ - ); \ - cpl_test_eq( \ - cpl_recipeconfig_get_max_count(first, *tag, *input), \ - cpl_recipeconfig_get_max_count(second, *tag, *input) \ - ); \ - } \ - for (ptr = first_inputs; *ptr != NULL; ++ptr) cpl_free(*ptr); \ - cpl_free(first_inputs); \ - for (ptr = second_inputs; *ptr != NULL; ++ptr) cpl_free(*ptr); \ - cpl_free(second_inputs); \ - for (ptr = first_outputs; *ptr != NULL; ++ptr) cpl_free(*ptr); \ - cpl_free(first_outputs); \ - for (ptr = second_outputs; *ptr != NULL; ++ptr) cpl_free(*ptr); \ - cpl_free(second_outputs); \ - } \ - for (ptr = first_tags; *ptr != NULL; ++ptr) cpl_free(*ptr); \ - cpl_free(first_tags); \ - for (ptr = second_tags; *ptr != NULL; ++ptr) cpl_free(*ptr); \ - cpl_free(second_tags); \ + char **input = NULL; \ + for (input = first_inputs; *input != NULL; ++input) { \ + cpl_test_eq(cpl_recipeconfig_get_min_count(first, *tag, \ + *input), \ + cpl_recipeconfig_get_min_count(second, *tag, \ + *input)); \ + cpl_test_eq(cpl_recipeconfig_get_max_count(first, *tag, \ + *input), \ + cpl_recipeconfig_get_max_count(second, *tag, \ + *input)); \ + } \ + for (ptr = first_inputs; *ptr != NULL; ++ptr) \ + cpl_free(*ptr); \ + cpl_free(first_inputs); \ + for (ptr = second_inputs; *ptr != NULL; ++ptr) \ + cpl_free(*ptr); \ + cpl_free(second_inputs); \ + for (ptr = first_outputs; *ptr != NULL; ++ptr) \ + cpl_free(*ptr); \ + cpl_free(first_outputs); \ + for (ptr = second_outputs; *ptr != NULL; ++ptr) \ + cpl_free(*ptr); \ + cpl_free(second_outputs); \ + } \ + for (ptr = first_tags; *ptr != NULL; ++ptr) \ + cpl_free(*ptr); \ + cpl_free(first_tags); \ + for (ptr = second_tags; *ptr != NULL; ++ptr) \ + cpl_free(*ptr); \ + cpl_free(second_tags); \ } /*----------------------------------------------------------------------------- @@ -132,9 +135,9 @@ Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); /* Insert tests below */ @@ -157,10 +160,11 @@ Private functions -----------------------------------------------------------------------------*/ -static void test_get_value_from_object(void) +static void +test_get_value_from_object(void) { - const char * json = "{}"; - er_json_node * node = er_json_parse(json); + const char *json = "{}"; + er_json_node *node = er_json_parse(json); /* Check handling of error conditions. */ cpl_test_null(get_value_from_object(node, "key", json)); @@ -169,10 +173,11 @@ er_json_node_delete(node); } -static void test_get_string_from_object(void) +static void +test_get_string_from_object(void) { - const char * json = NULL; - er_json_node * node = NULL; + const char *json = NULL; + er_json_node *node = NULL; /* Check handling of error conditions. */ json = "{}"; @@ -192,10 +197,11 @@ er_json_node_delete(node); } -static void test_get_ulong_from_object(void) +static void +test_get_ulong_from_object(void) { - const char * json = NULL; - er_json_node * node = NULL; + const char *json = NULL; + er_json_node *node = NULL; /* Check handling of error conditions. */ json = "{}"; @@ -215,10 +221,11 @@ er_json_node_delete(node); } -static void test_get_choices_array(void) +static void +test_get_choices_array(void) { - const char * json = NULL; - er_json_node * node = NULL; + const char *json = NULL; + er_json_node *node = NULL; /* Check error handling when the 'choices' key is missing. */ json = "{}"; @@ -236,10 +243,11 @@ } -static void test_node_is_integer(void) +static void +test_node_is_integer(void) { - const char * json = NULL; - er_json_node * node = NULL; + const char *json = NULL; + er_json_node *node = NULL; /* Test that node_is_integer returns the correct value for various number strings. */ @@ -289,72 +297,68 @@ er_json_node_delete(node); } -static void test_json_to_frame(void) +static void +test_json_to_frame(void) { - const char * json = NULL; - er_json_node * parsetree = NULL; + const char *json = NULL; + er_json_node *parsetree = NULL; /* Test that json_to_frame produces an error if keywords are missing in the JSON input text. */ - json = - "{\n" - " \"tag\": \"RAW\",\n" - " \"type\": 1,\n" - " \"group\": 0,\n" - " \"level\": 0\n" - "}\n"; + json = "{\n" + " \"tag\": \"RAW\",\n" + " \"type\": 1,\n" + " \"group\": 0,\n" + " \"level\": 0\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_frame(parsetree, json)); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); er_json_node_delete(parsetree); - json = - "{\n" - " \"filename\": \"test.fits\",\n" - " \"type\": 1,\n" - " \"group\": 0,\n" - " \"level\": 0\n" - "}\n"; + json = "{\n" + " \"filename\": \"test.fits\",\n" + " \"type\": 1,\n" + " \"group\": 0,\n" + " \"level\": 0\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_frame(parsetree, json)); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); er_json_node_delete(parsetree); - json = - "{\n" - " \"filename\": \"test.fits\",\n" - " \"tag\": \"RAW\",\n" - " \"group\": 0,\n" - " \"level\": 0\n" - "}\n"; + json = "{\n" + " \"filename\": \"test.fits\",\n" + " \"tag\": \"RAW\",\n" + " \"group\": 0,\n" + " \"level\": 0\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_frame(parsetree, json)); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); er_json_node_delete(parsetree); - json = - "{\n" - " \"filename\": \"test.fits\",\n" - " \"tag\": \"RAW\",\n" - " \"type\": 1,\n" - " \"level\": 0\n" - "}\n"; + json = "{\n" + " \"filename\": \"test.fits\",\n" + " \"tag\": \"RAW\",\n" + " \"type\": 1,\n" + " \"level\": 0\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_frame(parsetree, json)); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); er_json_node_delete(parsetree); - json = - "{\n" - " \"filename\": \"test.fits\",\n" - " \"tag\": \"RAW\",\n" - " \"type\": 1,\n" - " \"group\": 0\n" - "}\n"; + json = "{\n" + " \"filename\": \"test.fits\",\n" + " \"tag\": \"RAW\",\n" + " \"type\": 1,\n" + " \"group\": 0\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_frame(parsetree, json)); @@ -371,12 +375,13 @@ er_json_node_delete(parsetree); } -static void test_add_recipeconfig_inputs(void) +static void +test_add_recipeconfig_inputs(void) { - const char * json = NULL; - er_json_node * parsetree = NULL; - cpl_recipeconfig * config = NULL; - cpl_recipeconfig * ref_config = NULL; + const char *json = NULL; + er_json_node *parsetree = NULL; + cpl_recipeconfig *config = NULL; + cpl_recipeconfig *ref_config = NULL; ref_config = cpl_recipeconfig_new(); cpl_test_assert(ref_config != NULL); @@ -411,14 +416,13 @@ /* Test that we get an error if trying to add an input that has the same tag value as the primary top level tag. */ - json = - "[\n" - " {\n" - " \"tag\": \"RAW\",\n" - " \"min\": 1,\n" - " \"max\": 1\n" - " }\n" - "]\n"; + json = "[\n" + " {\n" + " \"tag\": \"RAW\",\n" + " \"min\": 1,\n" + " \"max\": 1\n" + " }\n" + "]\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); config = cpl_recipeconfig_new(); @@ -431,14 +435,13 @@ er_json_node_delete(parsetree); /* Check error handling if the 'tag' field is an empty string. */ - json = - "[\n" - " {\n" - " \"tag\": \"\",\n" - " \"min\": 1,\n" - " \"max\": 1\n" - " }\n" - "]\n"; + json = "[\n" + " {\n" + " \"tag\": \"\",\n" + " \"min\": 1,\n" + " \"max\": 1\n" + " }\n" + "]\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); config = cpl_recipeconfig_new(); @@ -451,13 +454,12 @@ er_json_node_delete(parsetree); /* Check error handling if keywords are missing. */ - json = - "[\n" - " {\n" - " \"min\": 1,\n" - " \"max\": 1\n" - " }\n" - "]\n"; + json = "[\n" + " {\n" + " \"min\": 1,\n" + " \"max\": 1\n" + " }\n" + "]\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); config = cpl_recipeconfig_new(); @@ -469,13 +471,12 @@ cpl_recipeconfig_delete(config); er_json_node_delete(parsetree); - json = - "[\n" - " {\n" - " \"tag\": \"CALIB\",\n" - " \"max\": 1\n" - " }\n" - "]\n"; + json = "[\n" + " {\n" + " \"tag\": \"CALIB\",\n" + " \"max\": 1\n" + " }\n" + "]\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); config = cpl_recipeconfig_new(); @@ -487,13 +488,12 @@ cpl_recipeconfig_delete(config); er_json_node_delete(parsetree); - json = - "[\n" - " {\n" - " \"tag\": \"CALIB\",\n" - " \"min\": 1\n" - " }\n" - "]\n"; + json = "[\n" + " {\n" + " \"tag\": \"CALIB\",\n" + " \"min\": 1\n" + " }\n" + "]\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); config = cpl_recipeconfig_new(); @@ -508,12 +508,13 @@ cpl_recipeconfig_delete(ref_config); } -static void test_add_recipeconfig_outputs(void) +static void +test_add_recipeconfig_outputs(void) { - const char * json = NULL; - er_json_node * parsetree = NULL; - cpl_recipeconfig * config = NULL; - cpl_recipeconfig * ref_config = NULL; + const char *json = NULL; + er_json_node *parsetree = NULL; + cpl_recipeconfig *config = NULL; + cpl_recipeconfig *ref_config = NULL; ref_config = cpl_recipeconfig_new(); cpl_test_assert(ref_config != NULL); @@ -562,12 +563,13 @@ cpl_recipeconfig_delete(ref_config); } -static void test_add_recipeconfig_tag(void) +static void +test_add_recipeconfig_tag(void) { - const char * json = NULL; - er_json_node * parsetree = NULL; - cpl_recipeconfig * config = NULL; - cpl_recipeconfig * ref_config = NULL; + const char *json = NULL; + er_json_node *parsetree = NULL; + cpl_recipeconfig *config = NULL; + cpl_recipeconfig *ref_config = NULL; ref_config = cpl_recipeconfig_new(); cpl_test_assert(ref_config != NULL); @@ -598,11 +600,10 @@ er_json_node_delete(parsetree); /* Check error handling if required fields are missing. */ - json = - "{\n" - " \"min\": 1,\n" - " \"max\": 1\n" - "}\n"; + json = "{\n" + " \"min\": 1,\n" + " \"max\": 1\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); config = cpl_recipeconfig_new(); @@ -613,11 +614,10 @@ cpl_recipeconfig_delete(config); er_json_node_delete(parsetree); - json = - "{\n" - " \"tag\": \"RAW\",\n" - " \"max\": 1\n" - "}\n"; + json = "{\n" + " \"tag\": \"RAW\",\n" + " \"max\": 1\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); config = cpl_recipeconfig_new(); @@ -628,11 +628,10 @@ cpl_recipeconfig_delete(config); er_json_node_delete(parsetree); - json = - "{\n" - " \"tag\": \"RAW\",\n" - " \"min\": 1\n" - "}\n"; + json = "{\n" + " \"tag\": \"RAW\",\n" + " \"min\": 1\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); config = cpl_recipeconfig_new(); @@ -644,12 +643,11 @@ er_json_node_delete(parsetree); /* Test error handling if the tag has an empty string. */ - json = - "{\n" - " \"tag\": \"\",\n" - " \"min\": 1,\n" - " \"max\": 1\n" - "}\n"; + json = "{\n" + " \"tag\": \"\",\n" + " \"min\": 1,\n" + " \"max\": 1\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); config = cpl_recipeconfig_new(); @@ -664,14 +662,13 @@ Note that we do not compare to the reference structure with the test_equal_config macro, because we know that the 'config' object will be only partially constructed. */ - json = - "{\n" - " \"tag\": \"RAW\",\n" - " \"min\": 1,\n" - " \"max\": 1,\n" - " \"inputs\": [\"dummy\"],\n" - " \"outputs\": [\"PROD\"]\n" - "}\n"; + json = "{\n" + " \"tag\": \"RAW\",\n" + " \"min\": 1,\n" + " \"max\": 1,\n" + " \"inputs\": [\"dummy\"],\n" + " \"outputs\": [\"PROD\"]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); config = cpl_recipeconfig_new(); @@ -681,20 +678,19 @@ cpl_recipeconfig_delete(config); er_json_node_delete(parsetree); - json = - "{\n" - " \"tag\": \"RAW\",\n" - " \"min\": 1,\n" - " \"max\": 1,\n" - " \"inputs\": [\n" - " {\n" - " \"tag\": \"CALIB\",\n" - " \"min\": 2,\n" - " \"max\": 3\n" - " }\n" - " ],\n" - " \"outputs\": [{\"dummy\": 123}]\n" - "}\n"; + json = "{\n" + " \"tag\": \"RAW\",\n" + " \"min\": 1,\n" + " \"max\": 1,\n" + " \"inputs\": [\n" + " {\n" + " \"tag\": \"CALIB\",\n" + " \"min\": 2,\n" + " \"max\": 3\n" + " }\n" + " ],\n" + " \"outputs\": [{\"dummy\": 123}]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); config = cpl_recipeconfig_new(); @@ -706,12 +702,11 @@ /* Check for correct parsing of a valid recipe config structure. */ cpl_test_assert(cpl_recipeconfig_set_tag(ref_config, "RAW", 1, 1) == 0); - json = - "{\n" - " \"tag\": \"RAW\",\n" - " \"min\": 1,\n" - " \"max\": 1\n" - "}\n"; + json = "{\n" + " \"tag\": \"RAW\",\n" + " \"min\": 1,\n" + " \"max\": 1\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); config = cpl_recipeconfig_new(); @@ -724,24 +719,23 @@ /* Check for correct parsing of a recipe config structure with inputs and outputs. */ - cpl_test_assert(cpl_recipeconfig_set_input(ref_config, "RAW", "CALIB", 2, 3) - == 0); - cpl_test_assert(cpl_recipeconfig_set_output(ref_config, "RAW", "PROD") - == 0); - json = - "{\n" - " \"tag\": \"RAW\",\n" - " \"min\": 1,\n" - " \"max\": 1,\n" - " \"inputs\": [\n" - " {\n" - " \"tag\": \"CALIB\",\n" - " \"min\": 2,\n" - " \"max\": 3\n" - " }\n" - " ],\n" - " \"outputs\": [\"PROD\"]\n" - "}\n"; + cpl_test_assert( + cpl_recipeconfig_set_input(ref_config, "RAW", "CALIB", 2, 3) == 0); + cpl_test_assert(cpl_recipeconfig_set_output(ref_config, "RAW", "PROD") == + 0); + json = "{\n" + " \"tag\": \"RAW\",\n" + " \"min\": 1,\n" + " \"max\": 1,\n" + " \"inputs\": [\n" + " {\n" + " \"tag\": \"CALIB\",\n" + " \"min\": 2,\n" + " \"max\": 3\n" + " }\n" + " ],\n" + " \"outputs\": [\"PROD\"]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); config = cpl_recipeconfig_new(); @@ -755,16 +749,17 @@ cpl_recipeconfig_delete(ref_config); } -static void test_json_to_parameter(void) +static void +test_json_to_parameter(void) { - const char * json = NULL; - er_json_node * parsetree = NULL; - cpl_parameter * param = NULL; - cpl_parameter * ref_param = NULL; + const char *json = NULL; + er_json_node *parsetree = NULL; + cpl_parameter *param = NULL; + cpl_parameter *ref_param = NULL; /* Test that an integer value parameter is parsed correctly. */ - ref_param = cpl_parameter_new_value("testpar", CPL_TYPE_INT, - "test param", "test", 3); + ref_param = cpl_parameter_new_value("testpar", CPL_TYPE_INT, "test param", + "test", 3); cpl_test_assert(ref_param != NULL); cpl_parameter_set_id(ref_param, 2); cpl_parameter_set_int(ref_param, 5); @@ -776,24 +771,23 @@ cpl_parameter_enable(ref_param, CPL_PARAMETER_MODE_ENV); cpl_parameter_set_alias(ref_param, CPL_PARAMETER_MODE_CFG, "par_cfg"); cpl_parameter_disable(ref_param, CPL_PARAMETER_MODE_CFG); - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"id\": 2,\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"value\": 5,\n" - " \"default\": 3,\n" - " \"present\": true,\n" - " \"tag\": \"mypar\",\n" - " \"cli_enabled\": true,\n" - " \"cli_alias\": \"par_cli\",\n" - " \"env_enabled\": true,\n" - " \"env_alias\": \"par_env\",\n" - " \"cfg_enabled\": false,\n" - " \"cfg_alias\": \"par_cfg\"\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"id\": 2,\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"value\": 5,\n" + " \"default\": 3,\n" + " \"present\": true,\n" + " \"tag\": \"mypar\",\n" + " \"cli_enabled\": true,\n" + " \"cli_alias\": \"par_cli\",\n" + " \"env_enabled\": true,\n" + " \"env_alias\": \"par_env\",\n" + " \"cfg_enabled\": false,\n" + " \"cfg_alias\": \"par_cfg\"\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -817,24 +811,23 @@ cpl_parameter_disable(ref_param, CPL_PARAMETER_MODE_ENV); cpl_parameter_set_alias(ref_param, CPL_PARAMETER_MODE_CFG, "par_cfg"); cpl_parameter_enable(ref_param, CPL_PARAMETER_MODE_CFG); - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"id\": 3,\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"value\": 5.2,\n" - " \"default\": 3.5,\n" - " \"present\": false,\n" - " \"tag\": \"mypar\",\n" - " \"cli_enabled\": false,\n" - " \"cli_alias\": \"par_cli\",\n" - " \"env_enabled\": false,\n" - " \"env_alias\": \"par_env\",\n" - " \"cfg_enabled\": true,\n" - " \"cfg_alias\": \"par_cfg\"\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"id\": 3,\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"value\": 5.2,\n" + " \"default\": 3.5,\n" + " \"present\": false,\n" + " \"tag\": \"mypar\",\n" + " \"cli_enabled\": false,\n" + " \"cli_alias\": \"par_cli\",\n" + " \"env_enabled\": false,\n" + " \"env_alias\": \"par_env\",\n" + " \"cfg_enabled\": true,\n" + " \"cfg_alias\": \"par_cfg\"\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -847,13 +840,12 @@ /* Check that a missing description in the JSON does not cause errors. */ ref_param = cpl_parameter_new_value("testpar", CPL_TYPE_INT, "", "test", 3); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"context\": \"test\",\n" - " \"default\": 3\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"context\": \"test\",\n" + " \"default\": 3\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -864,16 +856,15 @@ er_json_node_delete(parsetree); /* Check that a missing context in the JSON does not cause errors. */ - ref_param = cpl_parameter_new_value("testpar", CPL_TYPE_INT, - "test param", "", 3); + ref_param = + cpl_parameter_new_value("testpar", CPL_TYPE_INT, "test param", "", 3); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"default\": 3\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"default\": 3\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -900,39 +891,36 @@ cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); er_json_node_delete(parsetree); - json = - "{\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3\n" - "}\n"; + json = "{\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"default\": 3\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); er_json_node_delete(parsetree); - json = - "{\n" - " \"class\": \"value\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"default\": 3\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); er_json_node_delete(parsetree); - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\"\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\"\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); @@ -940,14 +928,13 @@ er_json_node_delete(parsetree); /* Check for correct error handling if 'default' is invalid. */ - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"default\": {}\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"default\": {}\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); @@ -956,105 +943,98 @@ /* Check for correct error handling if there is a type mismatch between 'value' and 'default'. */ - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"value\": true,\n" - " \"default\": 3\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"value\": true,\n" + " \"default\": 3\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); er_json_node_delete(parsetree); - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"value\": 3,\n" - " \"default\": true\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"value\": 3,\n" + " \"default\": true\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); er_json_node_delete(parsetree); - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"value\": \"string\",\n" - " \"default\": 3\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"value\": \"string\",\n" + " \"default\": 3\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); er_json_node_delete(parsetree); - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"value\": 3,\n" - " \"default\": \"string\"\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"value\": 3,\n" + " \"default\": \"string\"\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); er_json_node_delete(parsetree); - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"value\": 3.12,\n" - " \"default\": 3\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"value\": 3.12,\n" + " \"default\": 3\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); er_json_node_delete(parsetree); - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"value\": \"string\",\n" - " \"default\": 3.12\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"value\": \"string\",\n" + " \"default\": 3.12\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); er_json_node_delete(parsetree); - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"value\": {},\n" - " \"default\": 123\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"value\": {},\n" + " \"default\": 123\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); @@ -1062,14 +1042,13 @@ er_json_node_delete(parsetree); /* Check for correct error handling if 'class' has an invalid value. */ - json = - "{\n" - " \"class\": \"unknown\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3\n" - "}\n"; + json = "{\n" + " \"class\": \"unknown\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"default\": 3\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); @@ -1077,15 +1056,14 @@ er_json_node_delete(parsetree); /* Test error handling if 'present' has an invalid value. */ - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3,\n" - " \"present\": 123\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"default\": 3,\n" + " \"present\": 123\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); @@ -1093,15 +1071,14 @@ er_json_node_delete(parsetree); /* Test error handling if 'id' has an invalid value. */ - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"id\": true,\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"id\": true,\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"default\": 3\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); @@ -1109,15 +1086,14 @@ er_json_node_delete(parsetree); /* Test error handling if 'tag' has an invalid value. */ - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3,\n" - " \"tag\": 1.234\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"default\": 3,\n" + " \"tag\": 1.234\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); @@ -1125,17 +1101,16 @@ er_json_node_delete(parsetree); /* Check that a null value for 'tag' does not produce an error. */ - ref_param = cpl_parameter_new_value("testpar", CPL_TYPE_INT, - "test param", "test", 3); - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3,\n" - " \"tag\": null\n" - "}\n"; + ref_param = cpl_parameter_new_value("testpar", CPL_TYPE_INT, "test param", + "test", 3); + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"default\": 3,\n" + " \"tag\": null\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -1146,15 +1121,14 @@ er_json_node_delete(parsetree); /* Test error handling if 'cli_enabled' has an invalid value. */ - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3,\n" - " \"cli_enabled\": 123\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"default\": 3,\n" + " \"cli_enabled\": 123\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); @@ -1162,15 +1136,14 @@ er_json_node_delete(parsetree); /* Test error handling if 'cli_alias' has an invalid value. */ - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3,\n" - " \"cli_alias\": 123\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"default\": 3,\n" + " \"cli_alias\": 123\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); @@ -1178,15 +1151,14 @@ er_json_node_delete(parsetree); /* Test error handling if 'env_enabled' has an invalid value. */ - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3,\n" - " \"env_enabled\": 123\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"default\": 3,\n" + " \"env_enabled\": 123\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); @@ -1194,15 +1166,14 @@ er_json_node_delete(parsetree); /* Test error handling if 'env_alias' has an invalid value. */ - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3,\n" - " \"env_alias\": 123\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"default\": 3,\n" + " \"env_alias\": 123\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); @@ -1210,15 +1181,14 @@ er_json_node_delete(parsetree); /* Test error handling if 'cfg_enabled' has an invalid value. */ - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3,\n" - " \"cfg_enabled\": 123\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"default\": 3,\n" + " \"cfg_enabled\": 123\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); @@ -1226,15 +1196,14 @@ er_json_node_delete(parsetree); /* Test error handling if 'cfg_alias' has an invalid value. */ - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3,\n" - " \"cfg_alias\": 123\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"default\": 3,\n" + " \"cfg_alias\": 123\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); @@ -1242,23 +1211,22 @@ er_json_node_delete(parsetree); /* Check that no error occurs if 'cli_alias' is null. */ - ref_param = cpl_parameter_new_value("testpar", CPL_TYPE_INT, - "test param", "test", 4); + ref_param = cpl_parameter_new_value("testpar", CPL_TYPE_INT, "test param", + "test", 4); cpl_test_assert(ref_param != NULL); cpl_parameter_set_alias(ref_param, CPL_PARAMETER_MODE_CLI, NULL); cpl_parameter_set_alias(ref_param, CPL_PARAMETER_MODE_ENV, "abc"); cpl_parameter_set_alias(ref_param, CPL_PARAMETER_MODE_CFG, "def"); - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"default\": 4,\n" - " \"cli_alias\": null,\n" - " \"env_alias\": \"abc\",\n" - " \"cfg_alias\": \"def\"\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"default\": 4,\n" + " \"cli_alias\": null,\n" + " \"env_alias\": \"abc\",\n" + " \"cfg_alias\": \"def\"\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -1269,23 +1237,22 @@ er_json_node_delete(parsetree); /* Check that no error occurs if 'env_alias' is null. */ - ref_param = cpl_parameter_new_value("testpar", CPL_TYPE_INT, - "test param", "test", 4); + ref_param = cpl_parameter_new_value("testpar", CPL_TYPE_INT, "test param", + "test", 4); cpl_test_assert(ref_param != NULL); cpl_parameter_set_alias(ref_param, CPL_PARAMETER_MODE_CLI, "abc"); cpl_parameter_set_alias(ref_param, CPL_PARAMETER_MODE_ENV, NULL); cpl_parameter_set_alias(ref_param, CPL_PARAMETER_MODE_CFG, "def"); - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"default\": 4,\n" - " \"cli_alias\": \"abc\",\n" - " \"env_alias\": null,\n" - " \"cfg_alias\": \"def\"\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"default\": 4,\n" + " \"cli_alias\": \"abc\",\n" + " \"env_alias\": null,\n" + " \"cfg_alias\": \"def\"\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -1296,23 +1263,22 @@ er_json_node_delete(parsetree); /* Check that no error occurs if 'cfg_alias' is null. */ - ref_param = cpl_parameter_new_value("testpar", CPL_TYPE_INT, - "test param", "test", 4); + ref_param = cpl_parameter_new_value("testpar", CPL_TYPE_INT, "test param", + "test", 4); cpl_test_assert(ref_param != NULL); cpl_parameter_set_alias(ref_param, CPL_PARAMETER_MODE_CLI, "abc"); cpl_parameter_set_alias(ref_param, CPL_PARAMETER_MODE_ENV, "def"); cpl_parameter_set_alias(ref_param, CPL_PARAMETER_MODE_CFG, NULL); - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"default\": 4,\n" - " \"cli_alias\": \"abc\",\n" - " \"env_alias\": \"def\",\n" - " \"cfg_alias\": null\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"default\": 4,\n" + " \"cli_alias\": \"abc\",\n" + " \"env_alias\": \"def\",\n" + " \"cfg_alias\": null\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -1323,8 +1289,8 @@ er_json_node_delete(parsetree); /* Test that an integer range parameter is parsed correctly. */ - ref_param = cpl_parameter_new_range("testpar", CPL_TYPE_INT, - "range param", "test", 3, 2, 7); + ref_param = cpl_parameter_new_range("testpar", CPL_TYPE_INT, "range param", + "test", 3, 2, 7); cpl_test_assert(ref_param != NULL); cpl_parameter_set_id(ref_param, 6); cpl_parameter_set_int(ref_param, 5); @@ -1336,26 +1302,25 @@ cpl_parameter_enable(ref_param, CPL_PARAMETER_MODE_ENV); cpl_parameter_set_alias(ref_param, CPL_PARAMETER_MODE_CFG, "par_cfg"); cpl_parameter_disable(ref_param, CPL_PARAMETER_MODE_CFG); - json = - "{\n" - " \"class\": \"range\",\n" - " \"name\": \"testpar\",\n" - " \"id\": 6,\n" - " \"description\": \"range param\",\n" - " \"context\": \"test\",\n" - " \"value\": 5,\n" - " \"default\": 3,\n" - " \"min\": 2,\n" - " \"max\": 7,\n" - " \"present\": true,\n" - " \"tag\": \"myrange\",\n" - " \"cli_enabled\": true,\n" - " \"cli_alias\": \"par_cli\",\n" - " \"env_enabled\": true,\n" - " \"env_alias\": \"par_env\",\n" - " \"cfg_enabled\": false,\n" - " \"cfg_alias\": \"par_cfg\"\n" - "}\n"; + json = "{\n" + " \"class\": \"range\",\n" + " \"name\": \"testpar\",\n" + " \"id\": 6,\n" + " \"description\": \"range param\",\n" + " \"context\": \"test\",\n" + " \"value\": 5,\n" + " \"default\": 3,\n" + " \"min\": 2,\n" + " \"max\": 7,\n" + " \"present\": true,\n" + " \"tag\": \"myrange\",\n" + " \"cli_enabled\": true,\n" + " \"cli_alias\": \"par_cli\",\n" + " \"env_enabled\": true,\n" + " \"env_alias\": \"par_env\",\n" + " \"cfg_enabled\": false,\n" + " \"cfg_alias\": \"par_cfg\"\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -1366,32 +1331,30 @@ er_json_node_delete(parsetree); /* Test error handling if the 'min' or 'max' keywords are missing. */ - json = - "{\n" - " \"class\": \"range\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"range param\",\n" - " \"context\": \"test\",\n" - " \"value\": 5,\n" - " \"default\": 3,\n" - " \"max\": 7\n" - "}\n"; + json = "{\n" + " \"class\": \"range\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"range param\",\n" + " \"context\": \"test\",\n" + " \"value\": 5,\n" + " \"default\": 3,\n" + " \"max\": 7\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); er_json_node_delete(parsetree); - json = - "{\n" - " \"class\": \"range\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"range param\",\n" - " \"context\": \"test\",\n" - " \"value\": 5,\n" - " \"default\": 3,\n" - " \"min\": 2\n" - "}\n"; + json = "{\n" + " \"class\": \"range\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"range param\",\n" + " \"context\": \"test\",\n" + " \"value\": 5,\n" + " \"default\": 3,\n" + " \"min\": 2\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); @@ -1399,34 +1362,32 @@ er_json_node_delete(parsetree); /* Test error handling if the 'min' or 'max' keywords are invalid. */ - json = - "{\n" - " \"class\": \"range\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"range param\",\n" - " \"context\": \"test\",\n" - " \"value\": 5,\n" - " \"default\": 3,\n" - " \"min\": {},\n" - " \"max\": 7\n" - "}\n"; + json = "{\n" + " \"class\": \"range\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"range param\",\n" + " \"context\": \"test\",\n" + " \"value\": 5,\n" + " \"default\": 3,\n" + " \"min\": {},\n" + " \"max\": 7\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); er_json_node_delete(parsetree); - json = - "{\n" - " \"class\": \"range\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"range param\",\n" - " \"context\": \"test\",\n" - " \"value\": 5,\n" - " \"default\": 3,\n" - " \"min\": 2,\n" - " \"max\": {}\n" - "}\n"; + json = "{\n" + " \"class\": \"range\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"range param\",\n" + " \"context\": \"test\",\n" + " \"value\": 5,\n" + " \"default\": 3,\n" + " \"min\": 2,\n" + " \"max\": {}\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); @@ -1435,34 +1396,32 @@ /* Test error handling if the 'min' or 'max' have types that do not match. */ - json = - "{\n" - " \"class\": \"range\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"range param\",\n" - " \"context\": \"test\",\n" - " \"value\": 5,\n" - " \"default\": 3,\n" - " \"min\": 2.3,\n" - " \"max\": 7\n" - "}\n"; + json = "{\n" + " \"class\": \"range\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"range param\",\n" + " \"context\": \"test\",\n" + " \"value\": 5,\n" + " \"default\": 3,\n" + " \"min\": 2.3,\n" + " \"max\": 7\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); er_json_node_delete(parsetree); - json = - "{\n" - " \"class\": \"range\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"range param\",\n" - " \"context\": \"test\",\n" - " \"value\": 5,\n" - " \"default\": 3,\n" - " \"min\": 2,\n" - " \"max\": 7.1\n" - "}\n"; + json = "{\n" + " \"class\": \"range\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"range param\",\n" + " \"context\": \"test\",\n" + " \"value\": 5,\n" + " \"default\": 3,\n" + " \"min\": 2,\n" + " \"max\": 7.1\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); @@ -1471,17 +1430,16 @@ /* Test for error if a value type is used that is not compatible with a range parameter. */ - json = - "{\n" - " \"class\": \"range\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"range param\",\n" - " \"context\": \"test\",\n" - " \"value\": true,\n" - " \"default\": true,\n" - " \"min\": true,\n" - " \"max\": false\n" - "}\n"; + json = "{\n" + " \"class\": \"range\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"range param\",\n" + " \"context\": \"test\",\n" + " \"value\": true,\n" + " \"default\": true,\n" + " \"min\": true,\n" + " \"max\": false\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); @@ -1489,8 +1447,8 @@ er_json_node_delete(parsetree); /* Test that an integer enum parameter is parsed correctly. */ - ref_param = cpl_parameter_new_enum("testpar", CPL_TYPE_INT, - "enum param", "test", 3, 3, 2, 3, 7); + ref_param = cpl_parameter_new_enum("testpar", CPL_TYPE_INT, "enum param", + "test", 3, 3, 2, 3, 7); cpl_test_assert(ref_param != NULL); cpl_parameter_set_id(ref_param, 3); cpl_parameter_set_int(ref_param, 7); @@ -1502,25 +1460,24 @@ cpl_parameter_enable(ref_param, CPL_PARAMETER_MODE_ENV); cpl_parameter_set_alias(ref_param, CPL_PARAMETER_MODE_CFG, "par_cfg"); cpl_parameter_disable(ref_param, CPL_PARAMETER_MODE_CFG); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"testpar\",\n" - " \"id\": 3,\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"value\": 7,\n" - " \"default\": 3,\n" - " \"choices\": [2, 3, 7],\n" - " \"present\": true,\n" - " \"tag\": \"myenum\",\n" - " \"cli_enabled\": true,\n" - " \"cli_alias\": \"par_cli\",\n" - " \"env_enabled\": true,\n" - " \"env_alias\": \"par_env\",\n" - " \"cfg_enabled\": false,\n" - " \"cfg_alias\": \"par_cfg\"\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"testpar\",\n" + " \"id\": 3,\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"value\": 7,\n" + " \"default\": 3,\n" + " \"choices\": [2, 3, 7],\n" + " \"present\": true,\n" + " \"tag\": \"myenum\",\n" + " \"cli_enabled\": true,\n" + " \"cli_alias\": \"par_cli\",\n" + " \"env_enabled\": true,\n" + " \"env_alias\": \"par_env\",\n" + " \"cfg_enabled\": false,\n" + " \"cfg_alias\": \"par_cfg\"\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -1532,16 +1489,15 @@ /* Test for error if a value type is used that is not compatible with an enumeration parameter. */ - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"range param\",\n" - " \"context\": \"test\",\n" - " \"value\": true,\n" - " \"default\": true,\n" - " \"choices\": [true, false]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"range param\",\n" + " \"context\": \"test\",\n" + " \"value\": true,\n" + " \"default\": true,\n" + " \"choices\": [true, false]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); @@ -1549,48 +1505,45 @@ er_json_node_delete(parsetree); /* Check error handling if 'choices' does not contain the default value. */ - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"range param\",\n" - " \"context\": \"test\",\n" - " \"value\": 4,\n" - " \"default\": 3,\n" - " \"choices\": [2, 4]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"range param\",\n" + " \"context\": \"test\",\n" + " \"value\": 4,\n" + " \"default\": 3,\n" + " \"choices\": [2, 4]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); er_json_node_delete(parsetree); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"range param\",\n" - " \"context\": \"test\",\n" - " \"value\": 4.5,\n" - " \"default\": 3.5,\n" - " \"choices\": [4.5, 5.5]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"range param\",\n" + " \"context\": \"test\",\n" + " \"value\": 4.5,\n" + " \"default\": 3.5,\n" + " \"choices\": [4.5, 5.5]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); er_json_node_delete(parsetree); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"range param\",\n" - " \"context\": \"test\",\n" - " \"value\": \"x\",\n" - " \"default\": \"y\",\n" - " \"choices\": [\"x\", \"z\"]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"range param\",\n" + " \"context\": \"test\",\n" + " \"value\": \"x\",\n" + " \"default\": \"y\",\n" + " \"choices\": [\"x\", \"z\"]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); @@ -1598,64 +1551,60 @@ er_json_node_delete(parsetree); /* Check error handling if 'choices' is invalid for different types. */ - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"range param\",\n" - " \"context\": \"test\",\n" - " \"value\": 4,\n" - " \"default\": 3,\n" - " \"choices\": [2.0, 3.0, 4.0]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"range param\",\n" + " \"context\": \"test\",\n" + " \"value\": 4,\n" + " \"default\": 3,\n" + " \"choices\": [2.0, 3.0, 4.0]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); er_json_node_delete(parsetree); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"range param\",\n" - " \"context\": \"test\",\n" - " \"value\": 4,\n" - " \"default\": 3,\n" - " \"choices\": [\"x\", \"y\", \"z\"]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"range param\",\n" + " \"context\": \"test\",\n" + " \"value\": 4,\n" + " \"default\": 3,\n" + " \"choices\": [\"x\", \"y\", \"z\"]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); er_json_node_delete(parsetree); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"range param\",\n" - " \"context\": \"test\",\n" - " \"value\": 4.0,\n" - " \"default\": 3.0,\n" - " \"choices\": [\"x\", \"y\", \"z\"]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"range param\",\n" + " \"context\": \"test\",\n" + " \"value\": 4.0,\n" + " \"default\": 3.0,\n" + " \"choices\": [\"x\", \"y\", \"z\"]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); er_json_node_delete(parsetree); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"range param\",\n" - " \"context\": \"test\",\n" - " \"value\": \"x\",\n" - " \"default\": \"y\",\n" - " \"choices\": [2, 3, 4]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"range param\",\n" + " \"context\": \"test\",\n" + " \"value\": \"x\",\n" + " \"default\": \"y\",\n" + " \"choices\": [2, 3, 4]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); @@ -1663,48 +1612,45 @@ er_json_node_delete(parsetree); /* Check error handling if 'choices' is invalid for different types. */ - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"range param\",\n" - " \"context\": \"test\",\n" - " \"value\": 4,\n" - " \"default\": 3,\n" - " \"choices\": {}\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"range param\",\n" + " \"context\": \"test\",\n" + " \"value\": 4,\n" + " \"default\": 3,\n" + " \"choices\": {}\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); er_json_node_delete(parsetree); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"range param\",\n" - " \"context\": \"test\",\n" - " \"value\": 4.1,\n" - " \"default\": 3.2,\n" - " \"choices\": {}\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"range param\",\n" + " \"context\": \"test\",\n" + " \"value\": 4.1,\n" + " \"default\": 3.2,\n" + " \"choices\": {}\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); er_json_node_delete(parsetree); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"range param\",\n" - " \"context\": \"test\",\n" - " \"value\": \"x\",\n" - " \"default\": \"y\",\n" - " \"choices\": {}\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"range param\",\n" + " \"context\": \"test\",\n" + " \"value\": \"x\",\n" + " \"default\": \"y\",\n" + " \"choices\": {}\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); @@ -1716,15 +1662,14 @@ ref_param = cpl_parameter_new_enum("par", CPL_TYPE_INT, "enum param", "test", 1, 1, 1); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": 1,\n" - " \"choices\": [1]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": 1,\n" + " \"choices\": [1]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -1737,15 +1682,14 @@ ref_param = cpl_parameter_new_enum("par", CPL_TYPE_INT, "enum param", "test", 1, 2, 1, 2); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": 1,\n" - " \"choices\": [1, 2]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": 1,\n" + " \"choices\": [1, 2]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -1758,15 +1702,14 @@ ref_param = cpl_parameter_new_enum("par", CPL_TYPE_INT, "enum param", "test", 1, 3, 1, 2, 3); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": 1,\n" - " \"choices\": [1, 2, 3]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": 1,\n" + " \"choices\": [1, 2, 3]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -1779,15 +1722,14 @@ ref_param = cpl_parameter_new_enum("par", CPL_TYPE_INT, "enum param", "test", 1, 4, 1, 2, 3, 4); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": 1,\n" - " \"choices\": [1, 2, 3, 4]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": 1,\n" + " \"choices\": [1, 2, 3, 4]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -1800,15 +1742,14 @@ ref_param = cpl_parameter_new_enum("par", CPL_TYPE_INT, "enum param", "test", 1, 5, 1, 2, 3, 4, 5); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": 1,\n" - " \"choices\": [1, 2, 3, 4, 5]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": 1,\n" + " \"choices\": [1, 2, 3, 4, 5]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -1821,15 +1762,14 @@ ref_param = cpl_parameter_new_enum("par", CPL_TYPE_INT, "enum param", "test", 1, 6, 1, 2, 3, 4, 5, 6); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": 1,\n" - " \"choices\": [1, 2, 3, 4, 5, 6]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": 1,\n" + " \"choices\": [1, 2, 3, 4, 5, 6]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -1842,15 +1782,14 @@ ref_param = cpl_parameter_new_enum("par", CPL_TYPE_INT, "enum param", "test", 1, 7, 1, 2, 3, 4, 5, 6, 7); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": 1,\n" - " \"choices\": [1, 2, 3, 4, 5, 6, 7]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": 1,\n" + " \"choices\": [1, 2, 3, 4, 5, 6, 7]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -1863,15 +1802,14 @@ ref_param = cpl_parameter_new_enum("par", CPL_TYPE_INT, "enum param", "test", 1, 8, 1, 2, 3, 4, 5, 6, 7, 8); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": 1,\n" - " \"choices\": [1, 2, 3, 4, 5, 6, 7, 8]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": 1,\n" + " \"choices\": [1, 2, 3, 4, 5, 6, 7, 8]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -1884,15 +1822,14 @@ ref_param = cpl_parameter_new_enum("par", CPL_TYPE_INT, "enum param", "test", 1, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": 1,\n" - " \"choices\": [1, 2, 3, 4, 5, 6, 7, 8, 9]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": 1,\n" + " \"choices\": [1, 2, 3, 4, 5, 6, 7, 8, 9]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -1902,19 +1839,18 @@ cpl_parameter_delete(ref_param); er_json_node_delete(parsetree); - ref_param = cpl_parameter_new_enum("par", CPL_TYPE_INT, "enum param", - "test", 1, - 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + ref_param = + cpl_parameter_new_enum("par", CPL_TYPE_INT, "enum param", "test", 1, 10, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": 1,\n" - " \"choices\": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": 1,\n" + " \"choices\": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -1927,15 +1863,14 @@ ref_param = cpl_parameter_new_enum("par", CPL_TYPE_DOUBLE, "enum param", "test", 1.1, 1, 1.1); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": 1.1,\n" - " \"choices\": [1.1]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": 1.1,\n" + " \"choices\": [1.1]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -1948,15 +1883,14 @@ ref_param = cpl_parameter_new_enum("par", CPL_TYPE_DOUBLE, "enum param", "test", 1.1, 2, 1.1, 2.2); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": 1.1,\n" - " \"choices\": [1.1, 2.2]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": 1.1,\n" + " \"choices\": [1.1, 2.2]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -1969,15 +1903,14 @@ ref_param = cpl_parameter_new_enum("par", CPL_TYPE_DOUBLE, "enum param", "test", 1.1, 3, 1.1, 2.2, 3.3); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": 1.1,\n" - " \"choices\": [1.1, 2.2, 3.3]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": 1.1,\n" + " \"choices\": [1.1, 2.2, 3.3]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -1990,15 +1923,14 @@ ref_param = cpl_parameter_new_enum("par", CPL_TYPE_DOUBLE, "enum param", "test", 1.1, 4, 1.1, 2.2, 3.3, 4.4); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": 1.1,\n" - " \"choices\": [1.1, 2.2, 3.3, 4.4]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": 1.1,\n" + " \"choices\": [1.1, 2.2, 3.3, 4.4]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -2011,15 +1943,14 @@ ref_param = cpl_parameter_new_enum("par", CPL_TYPE_DOUBLE, "enum param", "test", 1.1, 5, 1.1, 2.2, 3.3, 4.4, 5.5); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": 1.1,\n" - " \"choices\": [1.1, 2.2, 3.3, 4.4, 5.5]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": 1.1,\n" + " \"choices\": [1.1, 2.2, 3.3, 4.4, 5.5]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -2029,19 +1960,18 @@ cpl_parameter_delete(ref_param); er_json_node_delete(parsetree); - ref_param = cpl_parameter_new_enum("par", CPL_TYPE_DOUBLE, "enum param", - "test", 1.1, 6, 1.1, 2.2, 3.3, 4.4, 5.5, - 6.6); + ref_param = + cpl_parameter_new_enum("par", CPL_TYPE_DOUBLE, "enum param", "test", + 1.1, 6, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": 1.1,\n" - " \"choices\": [1.1, 2.2, 3.3, 4.4, 5.5, 6.6]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": 1.1,\n" + " \"choices\": [1.1, 2.2, 3.3, 4.4, 5.5, 6.6]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -2051,19 +1981,18 @@ cpl_parameter_delete(ref_param); er_json_node_delete(parsetree); - ref_param = cpl_parameter_new_enum("par", CPL_TYPE_DOUBLE, "enum param", - "test", 1.1, 7, 1.1, 2.2, 3.3, 4.4, 5.5, - 6.6, 7.7); + ref_param = + cpl_parameter_new_enum("par", CPL_TYPE_DOUBLE, "enum param", "test", + 1.1, 7, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": 1.1,\n" - " \"choices\": [1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": 1.1,\n" + " \"choices\": [1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -2073,19 +2002,18 @@ cpl_parameter_delete(ref_param); er_json_node_delete(parsetree); - ref_param = cpl_parameter_new_enum("par", CPL_TYPE_DOUBLE, "enum param", - "test", 1.1, 8, 1.1, 2.2, 3.3, 4.4, 5.5, - 6.6, 7.7, 8.8); + ref_param = + cpl_parameter_new_enum("par", CPL_TYPE_DOUBLE, "enum param", "test", + 1.1, 8, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": 1.1,\n" - " \"choices\": [1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": 1.1,\n" + " \"choices\": [1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -2099,15 +2027,14 @@ "test", 1.1, 9, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": 1.1,\n" - " \"choices\": [1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": 1.1,\n" + " \"choices\": [1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -2142,15 +2069,14 @@ ref_param = cpl_parameter_new_enum("par", CPL_TYPE_STRING, "enum param", "test", "a", 1, "a"); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": \"a\",\n" - " \"choices\": [\"a\"]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": \"a\",\n" + " \"choices\": [\"a\"]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -2163,15 +2089,14 @@ ref_param = cpl_parameter_new_enum("par", CPL_TYPE_STRING, "enum param", "test", "a", 2, "a", "b"); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": \"a\",\n" - " \"choices\": [\"a\", \"b\"]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": \"a\",\n" + " \"choices\": [\"a\", \"b\"]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -2184,15 +2109,14 @@ ref_param = cpl_parameter_new_enum("par", CPL_TYPE_STRING, "enum param", "test", "a", 3, "a", "b", "c"); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": \"a\",\n" - " \"choices\": [\"a\", \"b\", \"c\"]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": \"a\",\n" + " \"choices\": [\"a\", \"b\", \"c\"]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -2205,15 +2129,14 @@ ref_param = cpl_parameter_new_enum("par", CPL_TYPE_STRING, "enum param", "test", "a", 4, "a", "b", "c", "d"); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": \"a\",\n" - " \"choices\": [\"a\", \"b\", \"c\", \"d\"]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": \"a\",\n" + " \"choices\": [\"a\", \"b\", \"c\", \"d\"]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -2226,15 +2149,14 @@ ref_param = cpl_parameter_new_enum("par", CPL_TYPE_STRING, "enum param", "test", "a", 5, "a", "b", "c", "d", "e"); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": \"a\",\n" - " \"choices\": [\"a\", \"b\", \"c\", \"d\", \"e\"]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": \"a\",\n" + " \"choices\": [\"a\", \"b\", \"c\", \"d\", \"e\"]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -2244,19 +2166,18 @@ cpl_parameter_delete(ref_param); er_json_node_delete(parsetree); - ref_param = cpl_parameter_new_enum("par", CPL_TYPE_STRING, "enum param", - "test", "a", 6, "a", "b", "c", "d", "e", - "f"); + ref_param = + cpl_parameter_new_enum("par", CPL_TYPE_STRING, "enum param", "test", + "a", 6, "a", "b", "c", "d", "e", "f"); cpl_test_assert(ref_param != NULL); - json = - "{\n" - " \"class\": \"enum\",\n" - " \"name\": \"par\",\n" - " \"description\": \"enum param\",\n" - " \"context\": \"test\",\n" - " \"default\": \"a\",\n" - " \"choices\": [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\n" - "}\n"; + json = "{\n" + " \"class\": \"enum\",\n" + " \"name\": \"par\",\n" + " \"description\": \"enum param\",\n" + " \"context\": \"test\",\n" + " \"default\": \"a\",\n" + " \"choices\": [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); param = json_to_parameter(parsetree, json); @@ -2266,9 +2187,9 @@ cpl_parameter_delete(ref_param); er_json_node_delete(parsetree); - ref_param = cpl_parameter_new_enum("par", CPL_TYPE_STRING, "enum param", - "test", "a", 7, "a", "b", "c", "d", "e", - "f", "h"); + ref_param = + cpl_parameter_new_enum("par", CPL_TYPE_STRING, "enum param", "test", + "a", 7, "a", "b", "c", "d", "e", "f", "h"); cpl_test_assert(ref_param != NULL); json = "{\n" @@ -2288,9 +2209,9 @@ cpl_parameter_delete(ref_param); er_json_node_delete(parsetree); - ref_param = cpl_parameter_new_enum("par", CPL_TYPE_STRING, "enum param", - "test", "a", 8, "a", "b", "c", "d", "e", - "f", "h", "i"); + ref_param = + cpl_parameter_new_enum("par", CPL_TYPE_STRING, "enum param", "test", + "a", 8, "a", "b", "c", "d", "e", "f", "h", "i"); cpl_test_assert(ref_param != NULL); json = "{\n" @@ -2361,10 +2282,11 @@ #else /* ENABLE_PYTHON_RECIPES */ -int main(void) +int +main(void) { /* Indicate to the automake test runner that the tests are skipped. */ return 77; } -#endif /* ENABLE_PYTHON_RECIPES */ +#endif /* ENABLE_PYTHON_RECIPES */ diff -Nru esorex-3.13.5+ds/src/tests/esorex_json_parse_errors1-test.c esorex-3.13.6+ds/src/tests/esorex_json_parse_errors1-test.c --- esorex-3.13.5+ds/src/tests/esorex_json_parse_errors1-test.c 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/tests/esorex_json_parse_errors1-test.c 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2017 European Southern Observatory + * Copyright (C) 2017-2022 European Southern Observatory * * 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 @@ -56,16 +56,16 @@ static cpl_boolean strtod_produce_error = CPL_FALSE; -double strtod(const char * text, char ** endptr) +double +strtod(const char *text, char **endptr) { - if (strtod_produce_error) - { - if (endptr != NULL) *endptr = (char *) text; + if (strtod_produce_error) { + if (endptr != NULL) + *endptr = (char *)text; errno = EINVAL; return 0.0; } - else - { + else { /* Use strtof as a surrogate to reproduce the original behaviour of this function. Since we do not use very large or small numbers in these tests this approximation is good enough. */ @@ -79,53 +79,54 @@ static cpl_type cpl_parameter_get_type_return_value = CPL_TYPE_INVALID; -cpl_type cpl_parameter_get_type(const cpl_parameter *self) +cpl_type +cpl_parameter_get_type(const cpl_parameter *self) { - (void) self; + (void)self; return cpl_parameter_get_type_return_value; } -static cpl_parameter_class -cpl_parameter_get_class_return_value = CPL_PARAMETER_CLASS_INVALID; +static cpl_parameter_class cpl_parameter_get_class_return_value = + CPL_PARAMETER_CLASS_INVALID; -cpl_parameter_class cpl_parameter_get_class(const cpl_parameter *self) +cpl_parameter_class +cpl_parameter_get_class(const cpl_parameter *self) { - (void) self; + (void)self; return cpl_parameter_get_class_return_value; } static int cpl_parameter_get_enum_size_return_value = 0; -int cpl_parameter_get_enum_size(const cpl_parameter *self) +int +cpl_parameter_get_enum_size(const cpl_parameter *self) { - (void) self; + (void)self; return cpl_parameter_get_enum_size_return_value; } -static const char**cpl_recipeconfig_get_tags_return_value = NULL; +static const char **cpl_recipeconfig_get_tags_return_value = NULL; -char** cpl_recipeconfig_get_tags(const cpl_recipeconfig* self) +char ** +cpl_recipeconfig_get_tags(const cpl_recipeconfig *self) { - (void) self; + (void)self; /* If the value to return is NULL then return NULL and set and error. Otherwise depp copy the values to reproduce the behaviour of the original function. */ - if (cpl_recipeconfig_get_tags_return_value == NULL) - { + if (cpl_recipeconfig_get_tags_return_value == NULL) { cpl_error_set_message("cpl_recipeconfig_get_tags", CPL_ERROR_ILLEGAL_OUTPUT, "dummy error"); return NULL; } cpl_size count = 0; const char **str = NULL; - for (str = cpl_recipeconfig_get_tags_return_value; *str != NULL; ++str) - { + for (str = cpl_recipeconfig_get_tags_return_value; *str != NULL; ++str) { ++count; } - char ** result = cpl_calloc(count + 1, sizeof(char*)); + char **result = cpl_calloc(count + 1, sizeof(char *)); cpl_size n = 0; - for (n = 0; n < count; ++n) - { + for (n = 0; n < count; ++n) { result[n] = cpl_strdup(cpl_recipeconfig_get_tags_return_value[n]); } return result; @@ -133,19 +134,19 @@ /* Overload the following functions to return NULL. */ -char** cpl_recipeconfig_get_inputs(const cpl_recipeconfig* self, - const char* tag) +char ** +cpl_recipeconfig_get_inputs(const cpl_recipeconfig *self, const char *tag) { - (void) self; - (void) tag; + (void)self; + (void)tag; return NULL; } -char** cpl_recipeconfig_get_outputs(const cpl_recipeconfig* self, - const char* tag) +char ** +cpl_recipeconfig_get_outputs(const cpl_recipeconfig *self, const char *tag) { - (void) self; - (void) tag; + (void)self; + (void)tag; return NULL; } @@ -153,8 +154,8 @@ cpl_error_code cpl_pluginlist_append(cpl_pluginlist *self, const cpl_plugin *plugin) { - (void) self; - (void) plugin; + (void)self; + (void)plugin; return cpl_error_set_message("cpl_pluginlist_append", CPL_ERROR_ILLEGAL_OUTPUT, "dummy error"); } @@ -163,7 +164,8 @@ Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -188,7 +190,8 @@ Private functions -----------------------------------------------------------------------------*/ -static void test_parse_number(void) +static void +test_parse_number(void) { /* Test that the parse_number fuction produces an error code when parsing invalid input. We specifically check the two branches in parse_number for @@ -201,15 +204,15 @@ cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); } -static void test_parameter_to_json(void) +static void +test_parameter_to_json(void) { - cpl_parameter * param1 = cpl_parameter_new_value("par1", CPL_TYPE_INT, - "desc","ctx", 10); - cpl_parameter * param2 = cpl_parameter_new_range("par2", CPL_TYPE_INT, - "desc","ctx", 5, 1, 10); - cpl_parameter * param3 = cpl_parameter_new_enum("par3", CPL_TYPE_INT, - "desc","ctx", 2, - 3, 1, 2, 3); + cpl_parameter *param1 = + cpl_parameter_new_value("par1", CPL_TYPE_INT, "desc", "ctx", 10); + cpl_parameter *param2 = + cpl_parameter_new_range("par2", CPL_TYPE_INT, "desc", "ctx", 5, 1, 10); + cpl_parameter *param3 = cpl_parameter_new_enum("par3", CPL_TYPE_INT, "desc", + "ctx", 2, 3, 1, 2, 3); strtod_produce_error = CPL_FALSE; /* Test that the parameter_to_json fuction produces an error code when @@ -261,34 +264,34 @@ cpl_parameter_delete(param3); } -static void test_plugin_to_json(void) +static void +test_plugin_to_json(void) { - cpl_plugin * plugin = NULL; - cpl_recipe2 * recipe = NULL; - char * json = NULL; - er_json_node * parsetree = NULL; - const er_json_node * node = NULL; - const er_json_node * node2 = NULL; - const char* reference_result[2] = {"RAW", NULL}; + cpl_plugin *plugin = NULL; + cpl_recipe2 *recipe = NULL; + char *json = NULL; + er_json_node *parsetree = NULL; + const er_json_node *node = NULL; + const er_json_node *node2 = NULL; + const char *reference_result[2] = { "RAW", NULL }; /* Must restore normal behaviour of strtod function which is used in the JSON parsing. */ strtod_produce_error = CPL_FALSE; /* Prepare the plugin object to parse. */ - recipe = (cpl_recipe2 *) cpl_calloc(1, sizeof(cpl_recipe2)); + recipe = (cpl_recipe2 *)cpl_calloc(1, sizeof(cpl_recipe2)); recipe->config = cpl_recipeconfig_new(); cpl_recipeconfig_set_tag(recipe->config, "RAW", 2, 3); cpl_test_assert(recipe->config != NULL); plugin = &recipe->base.interface; - cpl_test_assert(cpl_plugin_init(plugin, CPL_PLUGIN_API, 1, - CPL_PLUGIN_TYPE_RECIPE_V2, "test", - "simple test", "description ...", - "some author", "author@eso.org", - "copyright ...", NULL, NULL, NULL) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_plugin_init(plugin, CPL_PLUGIN_API, 1, CPL_PLUGIN_TYPE_RECIPE_V2, + "test", "simple test", "description ...", "some author", + "author@eso.org", "copyright ...", NULL, NULL, + NULL) == CPL_ERROR_NONE); /* Test that NULL is returned if cpl_recipeconfig_get_tags returns a NULL value, which indicates an error. */ @@ -329,28 +332,28 @@ #ifdef ENABLE_PYTHON_RECIPES -static void test_json_to_pluginlist(void) +static void +test_json_to_pluginlist(void) { - const char * json = NULL; - er_json_node * parsetree = NULL; + const char *json = NULL; + er_json_node *parsetree = NULL; /* Test edge case where failure in cpl_pluginlist_append is handled appropriately by er_json_to_pluginlist. */ - json = - "[\n" - " {\n" - " \"class\": \"testclass\",\n" - " \"name\": \"testrecipe\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin\",\n" - " \"description\": \"description ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [],\n" - " \"frames\": []\n" - " }\n" - "]\n"; + json = "[\n" + " {\n" + " \"class\": \"testclass\",\n" + " \"name\": \"testrecipe\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test plugin\",\n" + " \"description\": \"description ...\",\n" + " \"author\": \"Some Author\",\n" + " \"email\": \"someone@eso.org\",\n" + " \"copyright\": \"copyright ...\",\n" + " \"parameters\": [],\n" + " \"frames\": []\n" + " }\n" + "]\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(er_json_to_pluginlist(parsetree, json)); diff -Nru esorex-3.13.5+ds/src/tests/esorex_json_parse_errors2-test.c esorex-3.13.6+ds/src/tests/esorex_json_parse_errors2-test.c --- esorex-3.13.5+ds/src/tests/esorex_json_parse_errors2-test.c 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/tests/esorex_json_parse_errors2-test.c 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2017 European Southern Observatory + * Copyright (C) 2017-2022 European Southern Observatory * * 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 @@ -57,18 +57,20 @@ /* Overload the following function to return a specific value that can be controlled by these tests, or to produce an error. */ -static cpl_parameter * cpl_parameter_new_value_return_value = NULL; +static cpl_parameter *cpl_parameter_new_value_return_value = NULL; cpl_parameter * -cpl_parameter_new_value(const char *name, cpl_type type, - const char *description, const char *context, ...) +cpl_parameter_new_value(const char *name, + cpl_type type, + const char *description, + const char *context, + ...) { - (void) name; - (void) type; - (void) description; - (void) context; - if (cpl_parameter_new_value_return_value == NULL) - { + (void)name; + (void)type; + (void)description; + (void)context; + if (cpl_parameter_new_value_return_value == NULL) { cpl_error_set_message("cpl_parameter_new_value", CPL_ERROR_ILLEGAL_OUTPUT, "dummy error"); } @@ -77,19 +79,20 @@ /* Overload the following functions to produce an error. */ -cpl_error_code cpl_parameterlist_append(cpl_parameterlist *self, - cpl_parameter *parameter) +cpl_error_code +cpl_parameterlist_append(cpl_parameterlist *self, cpl_parameter *parameter) { - (void) self; - (void) parameter; + (void)self; + (void)parameter; return cpl_error_set_message("cpl_parameterlist_append", CPL_ERROR_ILLEGAL_OUTPUT, "dummy error"); } -cpl_error_code cpl_frameset_insert(cpl_frameset *self, cpl_frame *frame) +cpl_error_code +cpl_frameset_insert(cpl_frameset *self, cpl_frame *frame) { - (void) self; - (void) frame; + (void)self; + (void)frame; return cpl_error_set_message("cpl_frameset_insert", CPL_ERROR_ILLEGAL_OUTPUT, "dummy error"); } @@ -98,7 +101,8 @@ Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -120,27 +124,27 @@ Private functions -----------------------------------------------------------------------------*/ -static void test_json_to_plugin(void) +static void +test_json_to_plugin(void) { - const char * json = NULL; - er_json_node * parsetree = NULL; + const char *json = NULL; + er_json_node *parsetree = NULL; /* Test edge case where failure in cpl_parameter_new_value is handled appropriately by er_json_to_plugin. */ cpl_parameter_new_value_return_value = NULL; - json = - "{\n" - " \"class\": \"testclass\",\n" - " \"name\": \"testrecipe\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin\",\n" - " \"description\": \"description ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [],\n" - " \"frames\": []\n" - "}\n"; + json = "{\n" + " \"class\": \"testclass\",\n" + " \"name\": \"testrecipe\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test plugin\",\n" + " \"description\": \"description ...\",\n" + " \"author\": \"Some Author\",\n" + " \"email\": \"someone@eso.org\",\n" + " \"copyright\": \"copyright ...\",\n" + " \"parameters\": [],\n" + " \"frames\": []\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(er_json_to_plugin(parsetree, json)); @@ -149,22 +153,22 @@ /* Test edge case where failure in cpl_parameterlist_append is handled appropriately by er_json_to_plugin. */ - cpl_parameter_new_value_return_value = cpl_parameter_new_enum("__class__", - CPL_TYPE_STRING, "Python class name", "__python__", "testclass", - 1, "testclass"); - json = - "{\n" - " \"class\": \"testclass\",\n" - " \"name\": \"testrecipe\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin\",\n" - " \"description\": \"description ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [],\n" - " \"frames\": []\n" - "}\n"; + cpl_parameter_new_value_return_value = + cpl_parameter_new_enum("__class__", CPL_TYPE_STRING, + "Python class name", "__python__", "testclass", + 1, "testclass"); + json = "{\n" + " \"class\": \"testclass\",\n" + " \"name\": \"testrecipe\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test plugin\",\n" + " \"description\": \"description ...\",\n" + " \"author\": \"Some Author\",\n" + " \"email\": \"someone@eso.org\",\n" + " \"copyright\": \"copyright ...\",\n" + " \"parameters\": [],\n" + " \"frames\": []\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(er_json_to_plugin(parsetree, json)); @@ -172,22 +176,22 @@ er_json_node_delete(parsetree); } -static void test_json_to_parameter(void) +static void +test_json_to_parameter(void) { - const char * json = NULL; - er_json_node * parsetree = NULL; + const char *json = NULL; + er_json_node *parsetree = NULL; /* Test edge case where failure in cpl_parameter_new_value is handled appropriately by json_to_parameter. */ cpl_parameter_new_value_return_value = NULL; - json = - "{\n" - " \"class\": \"value\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3\n" - "}\n"; + json = "{\n" + " \"class\": \"value\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"default\": 3\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameter(parsetree, json)); @@ -195,24 +199,24 @@ er_json_node_delete(parsetree); } -static void test_json_to_parameterlist(void) +static void +test_json_to_parameterlist(void) { - const char * json = NULL; - er_json_node * parsetree = NULL; + const char *json = NULL; + er_json_node *parsetree = NULL; /* Test edge case where failure in cpl_parameterlist_append is handled appropriately by json_to_parameterlist. */ - json = - "[\n" - " {\n" - " \"class\": \"enum\",\n" - " \"name\": \"testpar\",\n" - " \"description\": \"test param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3,\n" - " \"choices\": [3]\n" - " }\n" - "]\n"; + json = "[\n" + " {\n" + " \"class\": \"enum\",\n" + " \"name\": \"testpar\",\n" + " \"description\": \"test param\",\n" + " \"context\": \"test\",\n" + " \"default\": 3,\n" + " \"choices\": [3]\n" + " }\n" + "]\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_parameterlist(parsetree, json)); @@ -220,30 +224,30 @@ er_json_node_delete(parsetree); } -static void test_json_to_frameset(void) +static void +test_json_to_frameset(void) { - const char * json = NULL; - er_json_node * parsetree = NULL; + const char *json = NULL; + er_json_node *parsetree = NULL; /* Test edge case where failure in cpl_frameset_insert is handled appropriately by json_to_frameset. */ - json = - "[\n" - " {\n" - " \"filename\": \"test1.fits\",\n" - " \"tag\": \"RAW\",\n" - " \"type\": 1,\n" - " \"group\": 0,\n" - " \"level\": 0\n" - " },\n" - " {\n" - " \"filename\": \"test2.fits\",\n" - " \"tag\": \"CALIB\",\n" - " \"type\": 1,\n" - " \"group\": 0,\n" - " \"level\": 0\n" - " }\n" - "]\n"; + json = "[\n" + " {\n" + " \"filename\": \"test1.fits\",\n" + " \"tag\": \"RAW\",\n" + " \"type\": 1,\n" + " \"group\": 0,\n" + " \"level\": 0\n" + " },\n" + " {\n" + " \"filename\": \"test2.fits\",\n" + " \"tag\": \"CALIB\",\n" + " \"type\": 1,\n" + " \"group\": 0,\n" + " \"level\": 0\n" + " }\n" + "]\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(json_to_frameset(parsetree, json)); @@ -254,10 +258,11 @@ #else /* ENABLE_PYTHON_RECIPES */ -int main(void) +int +main(void) { /* Indicate to the automake test runner that the tests are skipped. */ return 77; } -#endif /* ENABLE_PYTHON_RECIPES */ +#endif /* ENABLE_PYTHON_RECIPES */ diff -Nru esorex-3.13.5+ds/src/tests/esorex_json_parse_errors3-test.c esorex-3.13.6+ds/src/tests/esorex_json_parse_errors3-test.c --- esorex-3.13.5+ds/src/tests/esorex_json_parse_errors3-test.c 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/tests/esorex_json_parse_errors3-test.c 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2017 European Southern Observatory + * Copyright (C) 2017-2022 European Southern Observatory * * 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 @@ -55,53 +55,62 @@ /* Overload the following functions to produce an error. */ -cpl_error_code cpl_plugin_init(cpl_plugin *self, unsigned int api, - unsigned long version, unsigned long type, - const char *name, const char *synopsis, - const char *description, const char *author, - const char *email, const char *copyright, - cpl_plugin_func initialize, - cpl_plugin_func execute, - cpl_plugin_func deinitialize) -{ - (void) self; - (void) api; - (void) version; - (void) type; - (void) name; - (void) synopsis; - (void) description; - (void) author; - (void) email; - (void) copyright; - (void) initialize; - (void) execute; - (void) deinitialize; +cpl_error_code +cpl_plugin_init(cpl_plugin *self, + unsigned int api, + unsigned long version, + unsigned long type, + const char *name, + const char *synopsis, + const char *description, + const char *author, + const char *email, + const char *copyright, + cpl_plugin_func initialize, + cpl_plugin_func execute, + cpl_plugin_func deinitialize) +{ + (void)self; + (void)api; + (void)version; + (void)type; + (void)name; + (void)synopsis; + (void)description; + (void)author; + (void)email; + (void)copyright; + (void)initialize; + (void)execute; + (void)deinitialize; return cpl_error_set_message("cpl_plugin_init", CPL_ERROR_ILLEGAL_OUTPUT, "dummy error"); } int -cpl_recipeconfig_set_input(cpl_recipeconfig* self, - const char* tag, const char* input, - cpl_size min_count, cpl_size max_count) -{ - (void) self; - (void) tag; - (void) input; - (void) min_count; - (void) max_count; +cpl_recipeconfig_set_input(cpl_recipeconfig *self, + const char *tag, + const char *input, + cpl_size min_count, + cpl_size max_count) +{ + (void)self; + (void)tag; + (void)input; + (void)min_count; + (void)max_count; return cpl_error_set_message("cpl_recipeconfig_set_input", CPL_ERROR_ILLEGAL_OUTPUT, "dummy error"); } int -cpl_recipeconfig_set_output(cpl_recipeconfig* self, - const char* tag, const char* output) -{ - (void) self; - (void) tag; - (void) output; +cpl_recipeconfig_set_output(cpl_recipeconfig *self, + const char *tag, + const char *output) +{ + (void)self; + (void)tag; + (void)output; return cpl_error_set_message("cpl_recipeconfig_set_output", CPL_ERROR_ILLEGAL_OUTPUT, "dummy error"); } @@ -110,7 +119,8 @@ Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -127,26 +137,26 @@ Private functions -----------------------------------------------------------------------------*/ -static void test_json_to_plugin(void) +static void +test_json_to_plugin(void) { - const char * json = NULL; - er_json_node * parsetree = NULL; + const char *json = NULL; + er_json_node *parsetree = NULL; /* Test edge case where failure in cpl_plugin_init is handled correctly by er_json_to_plugin. */ - json = - "{\n" - " \"class\": \"testclass\",\n" - " \"name\": \"testrecipe\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin\",\n" - " \"description\": \"description ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [],\n" - " \"frames\": []\n" - "}\n"; + json = "{\n" + " \"class\": \"testclass\",\n" + " \"name\": \"testrecipe\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test plugin\",\n" + " \"description\": \"description ...\",\n" + " \"author\": \"Some Author\",\n" + " \"email\": \"someone@eso.org\",\n" + " \"copyright\": \"copyright ...\",\n" + " \"parameters\": [],\n" + " \"frames\": []\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(er_json_to_plugin(parsetree, json)); @@ -154,22 +164,22 @@ er_json_node_delete(parsetree); } -static void test_add_recipeconfig_inputs(void) +static void +test_add_recipeconfig_inputs(void) { - const char * json = NULL; - er_json_node * parsetree = NULL; - cpl_recipeconfig * config = NULL; + const char *json = NULL; + er_json_node *parsetree = NULL; + cpl_recipeconfig *config = NULL; /* Test error handling in add_recipeconfig_inputs for an edge case where the cpl_recipeconfig_set_input function fails. */ - json = - "[\n" - " {\n" - " \"tag\": \"CALIB\",\n" - " \"max\": 1,\n" - " \"min\": 1\n" - " }\n" - "]\n"; + json = "[\n" + " {\n" + " \"tag\": \"CALIB\",\n" + " \"max\": 1,\n" + " \"min\": 1\n" + " }\n" + "]\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); config = cpl_recipeconfig_new(); @@ -181,11 +191,12 @@ er_json_node_delete(parsetree); } -static void test_add_recipeconfig_outputs(void) +static void +test_add_recipeconfig_outputs(void) { - const char * json = NULL; - er_json_node * parsetree = NULL; - cpl_recipeconfig * config = NULL; + const char *json = NULL; + er_json_node *parsetree = NULL; + cpl_recipeconfig *config = NULL; /* Test error handling in add_recipeconfig_outputs for an edge case where the cpl_recipeconfig_set_output function fails. */ @@ -204,10 +215,11 @@ #else /* ENABLE_PYTHON_RECIPES */ -int main(void) +int +main(void) { /* Indicate to the automake test runner that the tests are skipped. */ return 77; } -#endif /* ENABLE_PYTHON_RECIPES */ +#endif /* ENABLE_PYTHON_RECIPES */ diff -Nru esorex-3.13.5+ds/src/tests/esorex_json_parse_errors4-test.c esorex-3.13.6+ds/src/tests/esorex_json_parse_errors4-test.c --- esorex-3.13.5+ds/src/tests/esorex_json_parse_errors4-test.c 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/tests/esorex_json_parse_errors4-test.c 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2017 European Southern Observatory + * Copyright (C) 2017-2022 European Southern Observatory * * 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 @@ -53,13 +53,16 @@ /* Overload the following functions to produce an error. */ -int cpl_recipeconfig_set_tag(cpl_recipeconfig* self, const char* tag, - cpl_size min_count, cpl_size max_count) +int +cpl_recipeconfig_set_tag(cpl_recipeconfig *self, + const char *tag, + cpl_size min_count, + cpl_size max_count) { - (void) self; - (void) tag; - (void) min_count; - (void) max_count; + (void)self; + (void)tag; + (void)min_count; + (void)max_count; return cpl_error_set_message("cpl_recipeconfig_set_tag", CPL_ERROR_ILLEGAL_OUTPUT, "dummy error"); } @@ -68,7 +71,8 @@ Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -83,28 +87,28 @@ Private functions -----------------------------------------------------------------------------*/ -static void test_add_recipeconfig_tag(void) +static void +test_add_recipeconfig_tag(void) { - const char * json = NULL; - er_json_node * parsetree = NULL; - cpl_recipeconfig * config = NULL; + const char *json = NULL; + er_json_node *parsetree = NULL; + cpl_recipeconfig *config = NULL; /* Test error handling in add_recipeconfig_tag for an edge case where the cpl_recipeconfig_set_tag function fails. */ - json = - "{\n" - " \"tag\": \"RAW\",\n" - " \"min\": 1,\n" - " \"max\": 1,\n" - " \"inputs\": [\n" - " {\n" - " \"tag\": \"CALIB\",\n" - " \"min\": 2,\n" - " \"max\": 3\n" - " }\n" - " ],\n" - " \"outputs\": [\"PROD\"]\n" - "}\n"; + json = "{\n" + " \"tag\": \"RAW\",\n" + " \"min\": 1,\n" + " \"max\": 1,\n" + " \"inputs\": [\n" + " {\n" + " \"tag\": \"CALIB\",\n" + " \"min\": 2,\n" + " \"max\": 3\n" + " }\n" + " ],\n" + " \"outputs\": [\"PROD\"]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); config = cpl_recipeconfig_new(); @@ -118,10 +122,11 @@ #else /* ENABLE_PYTHON_RECIPES */ -int main(void) +int +main(void) { /* Indicate to the automake test runner that the tests are skipped. */ return 77; } -#endif /* ENABLE_PYTHON_RECIPES */ +#endif /* ENABLE_PYTHON_RECIPES */ diff -Nru esorex-3.13.5+ds/src/tests/esorex_json_parser-test.c esorex-3.13.6+ds/src/tests/esorex_json_parser-test.c --- esorex-3.13.5+ds/src/tests/esorex_json_parser-test.c 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/tests/esorex_json_parser-test.c 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2017 European Southern Observatory + * Copyright (C) 2017-2022 European Southern Observatory * * 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 @@ -56,7 +56,8 @@ Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -87,10 +88,11 @@ Private functions -----------------------------------------------------------------------------*/ -static void test_json_find_line_column(void) +static void +test_json_find_line_column(void) { int line, column; - const char * json = "a\nbc\nd"; + const char *json = "a\nbc\nd"; /* Test the calculation of the line and column numbers for various positions within the JSON text. */ @@ -99,32 +101,32 @@ cpl_test_eq(line, 1); cpl_test_eq(column, 1); - cpl_test_eq_error(er_json_find_line_column(json, json+1, &line, &column), + cpl_test_eq_error(er_json_find_line_column(json, json + 1, &line, &column), CPL_ERROR_NONE); cpl_test_eq(line, 1); cpl_test_eq(column, 2); - cpl_test_eq_error(er_json_find_line_column(json, json+2, &line, &column), + cpl_test_eq_error(er_json_find_line_column(json, json + 2, &line, &column), CPL_ERROR_NONE); cpl_test_eq(line, 2); cpl_test_eq(column, 1); - cpl_test_eq_error(er_json_find_line_column(json, json+3, &line, &column), + cpl_test_eq_error(er_json_find_line_column(json, json + 3, &line, &column), CPL_ERROR_NONE); cpl_test_eq(line, 2); cpl_test_eq(column, 2); - cpl_test_eq_error(er_json_find_line_column(json, json+4, &line, &column), + cpl_test_eq_error(er_json_find_line_column(json, json + 4, &line, &column), CPL_ERROR_NONE); cpl_test_eq(line, 2); cpl_test_eq(column, 3); - cpl_test_eq_error(er_json_find_line_column(json, json+5, &line, &column), + cpl_test_eq_error(er_json_find_line_column(json, json + 5, &line, &column), CPL_ERROR_NONE); cpl_test_eq(line, 3); cpl_test_eq(column, 1); - cpl_test_eq_error(er_json_find_line_column(json, json+6, &line, &column), + cpl_test_eq_error(er_json_find_line_column(json, json + 6, &line, &column), CPL_ERROR_NONE); cpl_test_eq(line, 3); cpl_test_eq(column, 2); @@ -140,11 +142,12 @@ CPL_ERROR_NULL_INPUT); } -static void test_json_node_null(void) +static void +test_json_node_null(void) { /* Test construction and destruction of null type JSON value objects. */ - const char * json = "null"; - er_json_node * obj = er_json_node_new_null(json); + const char *json = "null"; + er_json_node *obj = er_json_node_new_null(json); cpl_test_nonnull(obj); cpl_test_error(CPL_ERROR_NONE); @@ -157,11 +160,12 @@ cpl_test_error(CPL_ERROR_NONE); } -static void test_json_node_bool(void) +static void +test_json_node_bool(void) { /* Test construction and destruction of boolean type JSON value objects. */ - const char * json = "true"; - er_json_node * obj = er_json_node_new_bool(TRUE, json); + const char *json = "true"; + er_json_node *obj = er_json_node_new_bool(TRUE, json); cpl_test_nonnull(obj); cpl_test_error(CPL_ERROR_NONE); @@ -187,11 +191,12 @@ cpl_test_error(CPL_ERROR_NONE); } -static void test_json_node_number(void) +static void +test_json_node_number(void) { /* Test construction and destruction of number type JSON value objects. */ - const char * json = "123.4"; - er_json_node * obj = er_json_node_new_number(123.4, json); + const char *json = "123.4"; + er_json_node *obj = er_json_node_new_number(123.4, json); cpl_test_nonnull(obj); cpl_test_error(CPL_ERROR_NONE); @@ -204,11 +209,12 @@ cpl_test_error(CPL_ERROR_NONE); } -static void test_json_node_string(void) +static void +test_json_node_string(void) { /* Test construction and destruction of string type JSON value objects. */ - const char * json = "\"test\""; - er_json_node * obj = er_json_node_new_string("test", json); + const char *json = "\"test\""; + er_json_node *obj = er_json_node_new_string("test", json); cpl_test_nonnull(obj); cpl_test_error(CPL_ERROR_NONE); @@ -222,11 +228,12 @@ cpl_test_error(CPL_ERROR_NONE); } -static void test_json_node_array(void) +static void +test_json_node_array(void) { /* Test construction and destruction of array type JSON value objects. */ - const char * json = "[1.2, true, \"test\"]"; - er_json_node * obj = er_json_node_new_array(json); + const char *json = "[1.2, true, \"test\"]"; + er_json_node *obj = er_json_node_new_array(json); cpl_test_nonnull(obj); cpl_test_error(CPL_ERROR_NONE); @@ -241,11 +248,11 @@ cpl_test_error(CPL_ERROR_NONE); /* Add the items to the array. */ - er_json_node_array_append(obj, er_json_node_new_number(1.2, json+1)); + er_json_node_array_append(obj, er_json_node_new_number(1.2, json + 1)); cpl_test_error(CPL_ERROR_NONE); - er_json_node_array_append(obj, er_json_node_new_bool(TRUE, json+7)); + er_json_node_array_append(obj, er_json_node_new_bool(TRUE, json + 7)); cpl_test_error(CPL_ERROR_NONE); - er_json_node_array_append(obj, er_json_node_new_string("test", json+12)); + er_json_node_array_append(obj, er_json_node_new_string("test", json + 12)); cpl_test_error(CPL_ERROR_NONE); cpl_test_eq(er_json_node_array_empty(obj), FALSE); cpl_test_error(CPL_ERROR_NONE); @@ -259,7 +266,7 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_noneq_ptr(iter, er_json_node_array_end(obj)); cpl_test_error(CPL_ERROR_NONE); - const er_json_node * item = er_json_node_array_get(obj, iter); + const er_json_node *item = er_json_node_array_get(obj, iter); cpl_test_nonnull(item); cpl_test_eq(er_json_node_type(item), JSON_NUMBER); cpl_test_abs(er_json_node_get_number(item), 1.2, DBL_EPSILON); @@ -302,11 +309,12 @@ cpl_test_error(CPL_ERROR_NONE); } -static void test_json_node_object(void) +static void +test_json_node_object(void) { /* Test construction and destruction of object type JSON value objects. */ - const char * json = "{\"num\": 1.2, \"str\": \"test\"}"; - er_json_node * obj = er_json_node_new_object(json); + const char *json = "{\"num\": 1.2, \"str\": \"test\"}"; + er_json_node *obj = er_json_node_new_object(json); cpl_test_nonnull(obj); cpl_test_error(CPL_ERROR_NONE); @@ -321,9 +329,11 @@ cpl_test_error(CPL_ERROR_NONE); /* Add the key/value pairs to the object. */ - er_json_node_object_insert(obj, "num", er_json_node_new_number(1.2, json+1)); + er_json_node_object_insert(obj, "num", + er_json_node_new_number(1.2, json + 1)); cpl_test_error(CPL_ERROR_NONE); - er_json_node_object_insert(obj, "str", er_json_node_new_string("test",json+13)); + er_json_node_object_insert(obj, "str", + er_json_node_new_string("test", json + 13)); cpl_test_error(CPL_ERROR_NONE); cpl_test_eq(er_json_node_object_empty(obj), FALSE); cpl_test_error(CPL_ERROR_NONE); @@ -332,7 +342,7 @@ /* Check that the keys can be found and their values are correct. We first use the er_json_node_object_get query method. */ - const er_json_node * item = er_json_node_object_get(obj, "num"); + const er_json_node *item = er_json_node_object_get(obj, "num"); cpl_test_nonnull(item); cpl_test_error(CPL_ERROR_NONE); cpl_test_eq(er_json_node_type(item), JSON_NUMBER); @@ -382,20 +392,17 @@ dynamically as we go. */ for (iter = er_json_node_object_begin(obj); iter != er_json_node_object_end(obj); - iter = er_json_node_object_next(obj, iter)) - { + iter = er_json_node_object_next(obj, iter)) { cpl_test_nonnull(er_json_node_object_get_key(obj, iter)); cpl_test_error(CPL_ERROR_NONE); item = er_json_node_object_get_value(obj, iter); cpl_test_nonnull(item); cpl_test_error(CPL_ERROR_NONE); - if (strcmp(er_json_node_object_get_key(obj, iter), "num") == 0) - { + if (strcmp(er_json_node_object_get_key(obj, iter), "num") == 0) { cpl_test_eq(er_json_node_type(item), JSON_NUMBER); cpl_test_abs(er_json_node_get_number(item), 1.2, DBL_EPSILON); } - else - { + else { cpl_test_eq_string(er_json_node_object_get_key(obj, iter), "str"); cpl_test_eq(er_json_node_type(item), JSON_STRING); cpl_test_eq_string(er_json_node_get_string(item), "test"); @@ -406,18 +413,19 @@ cpl_test_error(CPL_ERROR_NONE); } -static void test_json_node_invalid_access(void) +static void +test_json_node_invalid_access(void) { /* Create some valid dummy objects for testing. */ - const char * nulljson = "null"; - er_json_node * nullnode = er_json_node_new_null(nulljson); + const char *nulljson = "null"; + er_json_node *nullnode = er_json_node_new_null(nulljson); cpl_test_assert(nullnode != NULL); - const char * arrayjson = "[]"; - er_json_node * arraynode = er_json_node_new_array(arrayjson); + const char *arrayjson = "[]"; + er_json_node *arraynode = er_json_node_new_array(arrayjson); er_json_array_iterator arrayiter = er_json_node_array_begin(arraynode); cpl_test_assert(arrayiter != NULL); - const char * objectjson = "{}"; - er_json_node * objectnode = er_json_node_new_object(objectjson); + const char *objectjson = "{}"; + er_json_node *objectnode = er_json_node_new_object(objectjson); er_json_object_iterator objectiter = er_json_node_object_begin(objectnode); cpl_test_assert(objectiter != NULL); @@ -546,11 +554,12 @@ er_json_node_delete(nullnode); } -static void test_simple_create_and_delete_node(void) +static void +test_simple_create_and_delete_node(void) { /* Test parsing an empty string returns a null JSON object. */ - const char * json = ""; - er_json_node * tree = er_json_parse(json); + const char *json = ""; + er_json_node *tree = er_json_parse(json); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_NULL); @@ -567,11 +576,12 @@ cpl_test_error(CPL_ERROR_NONE); } -static void test_parsing_whitespace(void) +static void +test_parsing_whitespace(void) { /* Test parsing of various white space characters. */ - const char * json = " "; - er_json_node * tree = er_json_parse(json); + const char *json = " "; + er_json_node *tree = er_json_parse(json); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_NULL); @@ -585,11 +595,12 @@ er_json_node_delete(tree); } -static void test_parsing_null(void) +static void +test_parsing_null(void) { /* Test parsing a null value. */ - const char * json = "null"; - er_json_node * tree = er_json_parse(json); + const char *json = "null"; + er_json_node *tree = er_json_parse(json); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_NULL); @@ -601,7 +612,7 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_NULL); - cpl_test_eq_ptr(er_json_node_location(tree), json+1); + cpl_test_eq_ptr(er_json_node_location(tree), json + 1); er_json_node_delete(tree); json = "null "; @@ -617,15 +628,16 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_NULL); - cpl_test_eq_ptr(er_json_node_location(tree), json+2); + cpl_test_eq_ptr(er_json_node_location(tree), json + 2); er_json_node_delete(tree); } -static void test_parsing_boolean(void) +static void +test_parsing_boolean(void) { /* Test parsing a boolean value. */ - const char * json = "true"; - er_json_node * tree = er_json_parse(json); + const char *json = "true"; + er_json_node *tree = er_json_parse(json); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_BOOL); @@ -638,7 +650,7 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_BOOL); - cpl_test_eq_ptr(er_json_node_location(tree), json+2); + cpl_test_eq_ptr(er_json_node_location(tree), json + 2); cpl_test_eq(er_json_node_get_bool(tree), TRUE); er_json_node_delete(tree); @@ -656,7 +668,7 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_BOOL); - cpl_test_eq_ptr(er_json_node_location(tree), json+1); + cpl_test_eq_ptr(er_json_node_location(tree), json + 1); cpl_test_eq(er_json_node_get_bool(tree), TRUE); er_json_node_delete(tree); @@ -665,16 +677,17 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_BOOL); - cpl_test_eq_ptr(er_json_node_location(tree), json+1); + cpl_test_eq_ptr(er_json_node_location(tree), json + 1); cpl_test_eq(er_json_node_get_bool(tree), FALSE); er_json_node_delete(tree); } -static void test_parsing_number(void) +static void +test_parsing_number(void) { /* Test parsing a number value. */ - const char * json = "123"; - er_json_node * tree = er_json_parse(json); + const char *json = "123"; + er_json_node *tree = er_json_parse(json); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_NUMBER); @@ -687,7 +700,7 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_NUMBER); - cpl_test_eq_ptr(er_json_node_location(tree), json+1); + cpl_test_eq_ptr(er_json_node_location(tree), json + 1); cpl_test_abs(er_json_node_get_number(tree), 12.3, DBL_EPSILON); er_json_node_delete(tree); @@ -705,7 +718,7 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_NUMBER); - cpl_test_eq_ptr(er_json_node_location(tree), json+2); + cpl_test_eq_ptr(er_json_node_location(tree), json + 2); cpl_test_abs(er_json_node_get_number(tree), 12.3, DBL_EPSILON); er_json_node_delete(tree); @@ -714,7 +727,7 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_NUMBER); - cpl_test_eq_ptr(er_json_node_location(tree), json+2); + cpl_test_eq_ptr(er_json_node_location(tree), json + 2); cpl_test_abs(er_json_node_get_number(tree), 12.3e4, DBL_EPSILON); er_json_node_delete(tree); @@ -723,7 +736,7 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_NUMBER); - cpl_test_eq_ptr(er_json_node_location(tree), json+2); + cpl_test_eq_ptr(er_json_node_location(tree), json + 2); cpl_test_abs(er_json_node_get_number(tree), -12.3e4, DBL_EPSILON); er_json_node_delete(tree); @@ -732,7 +745,7 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_NUMBER); - cpl_test_eq_ptr(er_json_node_location(tree), json+1); + cpl_test_eq_ptr(er_json_node_location(tree), json + 1); cpl_test(isnan(er_json_node_get_number(tree))); er_json_node_delete(tree); @@ -741,7 +754,7 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_NUMBER); - cpl_test_eq_ptr(er_json_node_location(tree), json+1); + cpl_test_eq_ptr(er_json_node_location(tree), json + 1); cpl_test(isnan(er_json_node_get_number(tree))); er_json_node_delete(tree); @@ -760,7 +773,7 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_NUMBER); - cpl_test_eq_ptr(er_json_node_location(tree), json+1); + cpl_test_eq_ptr(er_json_node_location(tree), json + 1); cpl_test(isinf(er_json_node_get_number(tree))); cpl_test(er_json_node_get_number(tree) > 0.0); er_json_node_delete(tree); @@ -770,7 +783,7 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_NUMBER); - cpl_test_eq_ptr(er_json_node_location(tree), json+1); + cpl_test_eq_ptr(er_json_node_location(tree), json + 1); cpl_test(isinf(er_json_node_get_number(tree))); cpl_test(er_json_node_get_number(tree) > 0.0); er_json_node_delete(tree); @@ -780,7 +793,7 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_NUMBER); - cpl_test_eq_ptr(er_json_node_location(tree), json+1); + cpl_test_eq_ptr(er_json_node_location(tree), json + 1); cpl_test(isinf(er_json_node_get_number(tree))); cpl_test(er_json_node_get_number(tree) > 0.0); er_json_node_delete(tree); @@ -790,7 +803,7 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_NUMBER); - cpl_test_eq_ptr(er_json_node_location(tree), json+1); + cpl_test_eq_ptr(er_json_node_location(tree), json + 1); cpl_test(isinf(er_json_node_get_number(tree))); cpl_test(er_json_node_get_number(tree) < 0.0); er_json_node_delete(tree); @@ -800,7 +813,7 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_NUMBER); - cpl_test_eq_ptr(er_json_node_location(tree), json+1); + cpl_test_eq_ptr(er_json_node_location(tree), json + 1); cpl_test(isinf(er_json_node_get_number(tree))); cpl_test(er_json_node_get_number(tree) < 0.0); er_json_node_delete(tree); @@ -810,7 +823,7 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_NUMBER); - cpl_test_eq_ptr(er_json_node_location(tree), json+1); + cpl_test_eq_ptr(er_json_node_location(tree), json + 1); cpl_test(isinf(er_json_node_get_number(tree))); cpl_test(er_json_node_get_number(tree) < 0.0); er_json_node_delete(tree); @@ -822,7 +835,7 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_NUMBER); - cpl_test_eq_ptr(er_json_node_location(tree), json+2); + cpl_test_eq_ptr(er_json_node_location(tree), json + 2); cpl_test(er_json_node_get_number(tree) > 1.234567890123e48); cpl_test(er_json_node_get_number(tree) < 1.234567890124e48); er_json_node_delete(tree); @@ -832,17 +845,18 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_NUMBER); - cpl_test_eq_ptr(er_json_node_location(tree), json+2); + cpl_test_eq_ptr(er_json_node_location(tree), json + 2); cpl_test(isinf(er_json_node_get_number(tree))); cpl_test(er_json_node_get_number(tree) > 0.0); er_json_node_delete(tree); } -static void test_parsing_string(void) +static void +test_parsing_string(void) { /* Test parsing strings. */ - const char * json = "\"test\""; - er_json_node * tree = er_json_parse(json); + const char *json = "\"test\""; + er_json_node *tree = er_json_parse(json); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_STRING); @@ -855,7 +869,7 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_STRING); - cpl_test_eq_ptr(er_json_node_location(tree), json+2); + cpl_test_eq_ptr(er_json_node_location(tree), json + 2); cpl_test_eq_string(er_json_node_get_string(tree), "test"); er_json_node_delete(tree); @@ -864,7 +878,7 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_STRING); - cpl_test_eq_ptr(er_json_node_location(tree), json+1); + cpl_test_eq_ptr(er_json_node_location(tree), json + 1); cpl_test_eq_string(er_json_node_get_string(tree), "test"); er_json_node_delete(tree); @@ -873,17 +887,18 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_STRING); - cpl_test_eq_ptr(er_json_node_location(tree), json+1); + cpl_test_eq_ptr(er_json_node_location(tree), json + 1); cpl_test_eq_string(er_json_node_get_string(tree), "test\n\t\\\"\b\f\r#/end"); er_json_node_delete(tree); } -static void test_parsing_array(void) +static void +test_parsing_array(void) { /* Test parsing an array. */ - const char * json = "[]"; - er_json_node * tree = er_json_parse(json); + const char *json = "[]"; + er_json_node *tree = er_json_parse(json); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_ARRAY); @@ -900,10 +915,10 @@ cpl_test_eq(er_json_node_array_size(tree), 1); er_json_array_iterator iter = er_json_node_array_begin(tree); /* Check the item. */ - const er_json_node * item = er_json_node_array_get(tree, iter); + const er_json_node *item = er_json_node_array_get(tree, iter); cpl_test_eq(er_json_node_type(item), JSON_NUMBER); cpl_test_abs(er_json_node_get_number(item), 1.0, DBL_EPSILON); - cpl_test_eq_ptr(er_json_node_location(item), json+1); + cpl_test_eq_ptr(er_json_node_location(item), json + 1); er_json_node_delete(tree); json = " [ 1 , \" test \" ]"; @@ -911,20 +926,20 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_ARRAY); - cpl_test_eq_ptr(er_json_node_location(tree), json+2); + cpl_test_eq_ptr(er_json_node_location(tree), json + 2); cpl_test_eq(er_json_node_array_size(tree), 2); /* Check first item. */ iter = er_json_node_array_begin(tree); item = er_json_node_array_get(tree, iter); cpl_test_eq(er_json_node_type(item), JSON_NUMBER); cpl_test_abs(er_json_node_get_number(item), 1.0, DBL_EPSILON); - cpl_test_eq_ptr(er_json_node_location(item), json+4); + cpl_test_eq_ptr(er_json_node_location(item), json + 4); /* Check second item. */ iter = er_json_node_array_next(tree, iter); item = er_json_node_array_get(tree, iter); cpl_test_eq(er_json_node_type(item), JSON_STRING); cpl_test_eq_string(er_json_node_get_string(item), " test "); - cpl_test_eq_ptr(er_json_node_location(item), json+8); + cpl_test_eq_ptr(er_json_node_location(item), json + 8); er_json_node_delete(tree); json = " [1,\" test \"] "; @@ -932,28 +947,29 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_ARRAY); - cpl_test_eq_ptr(er_json_node_location(tree), json+1); + cpl_test_eq_ptr(er_json_node_location(tree), json + 1); cpl_test_eq(er_json_node_array_size(tree), 2); /* Check first item. */ iter = er_json_node_array_begin(tree); item = er_json_node_array_get(tree, iter); cpl_test_eq(er_json_node_type(item), JSON_NUMBER); cpl_test_abs(er_json_node_get_number(item), 1.0, DBL_EPSILON); - cpl_test_eq_ptr(er_json_node_location(item), json+2); + cpl_test_eq_ptr(er_json_node_location(item), json + 2); /* Check second item. */ iter = er_json_node_array_next(tree, iter); item = er_json_node_array_get(tree, iter); cpl_test_eq(er_json_node_type(item), JSON_STRING); cpl_test_eq_string(er_json_node_get_string(item), " test "); - cpl_test_eq_ptr(er_json_node_location(item), json+4); + cpl_test_eq_ptr(er_json_node_location(item), json + 4); er_json_node_delete(tree); } -static void test_parsing_object(void) +static void +test_parsing_object(void) { /* Test parsing an object. */ - const char * json = "{}"; - er_json_node * tree = er_json_parse(json); + const char *json = "{}"; + er_json_node *tree = er_json_parse(json); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_OBJECT); @@ -966,14 +982,14 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_OBJECT); - cpl_test_eq_ptr(er_json_node_location(tree), json+1); + cpl_test_eq_ptr(er_json_node_location(tree), json + 1); cpl_test_eq(er_json_node_object_size(tree), 1); /* Check value. */ - const er_json_node * item = er_json_node_object_get(tree, "num"); + const er_json_node *item = er_json_node_object_get(tree, "num"); cpl_test_nonnull(item); cpl_test_eq(er_json_node_type(item), JSON_NUMBER); cpl_test_abs(er_json_node_get_number(item), 1.2, DBL_EPSILON); - cpl_test_eq_ptr(er_json_node_location(item), json+8); + cpl_test_eq_ptr(er_json_node_location(item), json + 8); er_json_node_delete(tree); /* Test nested structure. */ @@ -982,13 +998,13 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(tree); cpl_test_eq(er_json_node_type(tree), JSON_OBJECT); - cpl_test_eq_ptr(er_json_node_location(tree), json+1); + cpl_test_eq_ptr(er_json_node_location(tree), json + 1); cpl_test_eq(er_json_node_object_size(tree), 1); /* Check value of top level object. */ - const er_json_node * array = er_json_node_object_get(tree, "array"); + const er_json_node *array = er_json_node_object_get(tree, "array"); cpl_test_nonnull(item); cpl_test_eq(er_json_node_type(array), JSON_ARRAY); - cpl_test_eq_ptr(er_json_node_location(array), json+11); + cpl_test_eq_ptr(er_json_node_location(array), json + 11); cpl_test_eq(er_json_node_array_size(array), 2); /* Check the first array item. */ er_json_array_iterator iter = er_json_node_array_begin(array); @@ -997,25 +1013,26 @@ cpl_test_nonnull(item); cpl_test_eq(er_json_node_type(item), JSON_NUMBER); cpl_test_abs(er_json_node_get_number(item), 1.2, DBL_EPSILON); - cpl_test_eq_ptr(er_json_node_location(item), json+12); + cpl_test_eq_ptr(er_json_node_location(item), json + 12); /* Check the second array item. */ iter = er_json_node_array_next(array, iter); cpl_test_nonnull(iter); item = er_json_node_array_get(array, iter); cpl_test_nonnull(item); cpl_test_eq(er_json_node_type(item), JSON_OBJECT); - cpl_test_eq_ptr(er_json_node_location(item), json+18); + cpl_test_eq_ptr(er_json_node_location(item), json + 18); cpl_test_eq(er_json_node_object_size(item), 1); /* Check the second array item's entry. */ item = er_json_node_object_get(item, "str"); cpl_test_nonnull(item); cpl_test_eq(er_json_node_type(item), JSON_STRING); - cpl_test_eq_ptr(er_json_node_location(item), json+25); + cpl_test_eq_ptr(er_json_node_location(item), json + 25); cpl_test_eq_string(er_json_node_get_string(item), "hello\nworld"); er_json_node_delete(tree); } -static void test_parse_errors(void) +static void +test_parse_errors(void) { /* Test handling of invalid JSON input. */ cpl_test_null(er_json_parse("random")); diff -Nru esorex-3.13.5+ds/src/tests/esorex_json-test.c esorex-3.13.6+ds/src/tests/esorex_json-test.c --- esorex-3.13.5+ds/src/tests/esorex_json-test.c 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/tests/esorex_json-test.c 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 European Southern Observatory * * 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 @@ -27,7 +27,7 @@ Defines -----------------------------------------------------------------------------*/ -#ifndef STR_LENGTH +#ifndef STR_LENGTH #define STR_LENGTH 80 #endif @@ -51,9 +51,9 @@ /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); /* Insert tests below */ @@ -74,130 +74,132 @@ return cpl_test_end(0); } -static void esorex_json_parameterlist(void) +static void +esorex_json_parameterlist(void) { - cpl_parameter * par1; - cpl_parameter * par2; - cpl_parameter * par3; - cpl_parameter * par4; - cpl_parameter * par5; - cpl_parameter * par6; - cpl_parameterlist * parlist; - + cpl_parameter *par1; + cpl_parameter *par2; + cpl_parameter *par3; + cpl_parameter *par4; + cpl_parameter *par5; + cpl_parameter *par6; + cpl_parameterlist *parlist; + /* Export a parameterlist to a JSON file */ par1 = cpl_parameter_new_value("recipe.par1", CPL_TYPE_DOUBLE, - "Description 1","rec1", 10.0); - - cpl_test_nonnull( par1 ); + "Description 1", "rec1", 10.0); + + cpl_test_nonnull(par1); par2 = cpl_parameter_new_value("recipe.par2", CPL_TYPE_STRING, - "Description 2","recipe", "String"); - - cpl_test_nonnull( par2 ); - + "Description 2", "recipe", "String"); + + cpl_test_nonnull(par2); + par3 = cpl_parameter_new_value("recipe.par3", CPL_TYPE_BOOL, - "Description 3","recipe", CPL_TRUE); - - cpl_test_nonnull( par3 ); + "Description 3", "recipe", CPL_TRUE); + + cpl_test_nonnull(par3); par4 = cpl_parameter_new_value("recipe.par4", CPL_TYPE_INT, - "Escaped chars \" / \f \n \r \t \\","recipe", -10); - - par5 = cpl_parameter_new_enum("recipe.par5", CPL_TYPE_STRING, - "Description 5","recipe", "Str1", - 3,"Str1", "Str2", "Str3"); - - par6 = cpl_parameter_new_range("recipe.par6", CPL_TYPE_INT, - "Description 6","recipe", 0, -1, 1); + "Escaped chars \" / \f \n \r \t \\", + "recipe", -10); - cpl_test_nonnull( par4 ); + par5 = + cpl_parameter_new_enum("recipe.par5", CPL_TYPE_STRING, "Description 5", + "recipe", "Str1", 3, "Str1", "Str2", "Str3"); + + par6 = cpl_parameter_new_range("recipe.par6", CPL_TYPE_INT, "Description 6", + "recipe", 0, -1, 1); + + cpl_test_nonnull(par4); parlist = cpl_parameterlist_new(); - - cpl_test_nonnull( parlist ); + + cpl_test_nonnull(parlist); cpl_parameterlist_append(parlist, par1); - + /* Dumping to json */ er_recipe_parameterlist_to_json(parlist, "recipe_name", "parlist.json"); - + cpl_test_error(CPL_ERROR_NONE); /* Read the file and compare it with a static version */ { - char * whole_file = 0; + char *whole_file = 0; long length; - FILE * fjson = fopen("parlist.json", "rb"); - const char * expected_json="[\n" - " {\n" - " \"name\": \"recipe.par1\",\n" - " \"value\": 10,\n" - " \"valtype\": \"double\",\n" - " \"partype\": \"value\",\n" - " \"display_name\": \"recipe.par1\",\n" - " \"description\": \"Description 1\",\n" - " \"recipe\": \"recipe_name\"\n" - " }\n" - "]\n\0"; - + FILE *fjson = fopen("parlist.json", "rb"); + const char *expected_json = "[\n" + " {\n" + " \"name\": \"recipe.par1\",\n" + " \"value\": 10,\n" + " \"valtype\": \"double\",\n" + " \"partype\": \"value\",\n" + " \"display_name\": \"recipe.par1\",\n" + " \"description\": \"Description 1\",\n" + " \"recipe\": \"recipe_name\"\n" + " }\n" + "]\n\0"; + cpl_test_nonnull(fjson); fseek(fjson, 0, SEEK_END); length = ftell(fjson); rewind(fjson); - whole_file = cpl_malloc(length+1); - + whole_file = cpl_malloc(length + 1); + cpl_test_nonnull(whole_file); int read_length = fread(whole_file, 1, length, fjson); cpl_test_eq(read_length, length); - whole_file[length]='\0'; + whole_file[length] = '\0'; fclose(fjson); - - cpl_test_zero( strcmp(whole_file, expected_json) ); - - cpl_test_zero( remove("parlist.json") ); + + cpl_test_zero(strcmp(whole_file, expected_json)); + + cpl_test_zero(remove("parlist.json")); cpl_free(whole_file); } /* Now with no recipe name */ er_recipe_parameterlist_to_json(parlist, "", "parlist11.json"); - + cpl_test_error(CPL_ERROR_NONE); /* Read the file and compare it with a static version */ { - char * whole_file = 0; + char *whole_file = 0; long length; - FILE * fjson = fopen("parlist11.json", "rb"); - const char * expected_json="[\n" - " {\n" - " \"name\": \"recipe.par1\",\n" - " \"value\": 10,\n" - " \"valtype\": \"double\",\n" - " \"partype\": \"value\",\n" - " \"display_name\": \"recipe.par1\",\n" - " \"description\": \"Description 1\"\n" - " }\n" - "]\n\0"; - + FILE *fjson = fopen("parlist11.json", "rb"); + const char *expected_json = "[\n" + " {\n" + " \"name\": \"recipe.par1\",\n" + " \"value\": 10,\n" + " \"valtype\": \"double\",\n" + " \"partype\": \"value\",\n" + " \"display_name\": \"recipe.par1\",\n" + " \"description\": \"Description 1\"\n" + " }\n" + "]\n\0"; + cpl_test_nonnull(fjson); fseek(fjson, 0, SEEK_END); length = ftell(fjson); rewind(fjson); - whole_file = cpl_malloc(length+1); - + whole_file = cpl_malloc(length + 1); + cpl_test_nonnull(whole_file); int read_length = fread(whole_file, 1, length, fjson); cpl_test_eq(read_length, length); - whole_file[length]='\0'; + whole_file[length] = '\0'; fclose(fjson); - - cpl_test_zero( strcmp(whole_file, expected_json) ); - - cpl_test_zero( remove("parlist11.json") ); + + cpl_test_zero(strcmp(whole_file, expected_json)); + + cpl_test_zero(remove("parlist11.json")); cpl_free(whole_file); } - + /* Do the same with a list that contains more than 1 parameter, including * a parameter with control characters */ cpl_parameterlist_append(parlist, par2); @@ -205,9 +207,9 @@ cpl_parameterlist_append(parlist, par4); cpl_parameterlist_append(parlist, par5); cpl_parameterlist_append(parlist, par6); - + cpl_test_error(CPL_ERROR_NONE); - + /* Dumping to json */ er_recipe_parameterlist_to_json(parlist, "recipe_name", "parlist2.json"); @@ -215,265 +217,266 @@ /* Read the file and compare it with a static version */ { - char * whole_file = 0; + char *whole_file = 0; long length; - FILE * fjson = fopen("parlist2.json", "rb"); - const char * expected_json="[\n" - " {\n" - " \"name\": \"recipe.par1\",\n" - " \"value\": 10,\n" - " \"valtype\": \"double\",\n" - " \"partype\": \"value\",\n" - " \"display_name\": \"recipe.par1\",\n" - " \"description\": \"Description 1\",\n" - " \"recipe\": \"recipe_name\"\n" - " },\n" - " {\n" - " \"name\": \"recipe.par2\",\n" - " \"value\": \"String\",\n" - " \"valtype\": \"string\",\n" - " \"partype\": \"value\",\n" - " \"display_name\": \"recipe.par2\",\n" - " \"description\": \"Description 2\",\n" - " \"recipe\": \"recipe_name\"\n" - " },\n" - " {\n" - " \"name\": \"recipe.par3\",\n" - " \"value\": true,\n" - " \"valtype\": \"bool\",\n" - " \"partype\": \"value\",\n" - " \"display_name\": \"recipe.par3\",\n" - " \"description\": \"Description 3\",\n" - " \"recipe\": \"recipe_name\"\n" - " },\n" - " {\n" - " \"name\": \"recipe.par4\",\n" - " \"value\": -10,\n" - " \"valtype\": \"int\",\n" - " \"partype\": \"value\",\n" - " \"display_name\": \"recipe.par4\",\n" - " \"description\": \"Escaped chars \\\" \\/ \\f \\n \\r \\t \\\\\",\n" - " \"recipe\": \"recipe_name\"\n" - " },\n" - " {\n" - " \"name\": \"recipe.par5\",\n" - " \"value\": \"Str1\",\n" - " \"valtype\": \"string\",\n" - " \"partype\": \"enum\",\n" - " \"valenum\": [ \"Str1\" , \"Str2\" , \"Str3\" ],\n" - " \"display_name\": \"recipe.par5\",\n" - " \"description\": \"Description 5\",\n" - " \"recipe\": \"recipe_name\"\n" - " },\n" - " {\n" - " \"name\": \"recipe.par6\",\n" - " \"value\": 0,\n" - " \"valtype\": \"int\",\n" - " \"partype\": \"range\",\n" - " \"valmin\": -1,\n" - " \"valmax\": 1,\n" - " \"display_name\": \"recipe.par6\",\n" - " \"description\": \"Description 6\",\n" - " \"recipe\": \"recipe_name\"\n" - " }\n" - "]\n\0"; + FILE *fjson = fopen("parlist2.json", "rb"); + const char *expected_json = + "[\n" + " {\n" + " \"name\": \"recipe.par1\",\n" + " \"value\": 10,\n" + " \"valtype\": \"double\",\n" + " \"partype\": \"value\",\n" + " \"display_name\": \"recipe.par1\",\n" + " \"description\": \"Description 1\",\n" + " \"recipe\": \"recipe_name\"\n" + " },\n" + " {\n" + " \"name\": \"recipe.par2\",\n" + " \"value\": \"String\",\n" + " \"valtype\": \"string\",\n" + " \"partype\": \"value\",\n" + " \"display_name\": \"recipe.par2\",\n" + " \"description\": \"Description 2\",\n" + " \"recipe\": \"recipe_name\"\n" + " },\n" + " {\n" + " \"name\": \"recipe.par3\",\n" + " \"value\": true,\n" + " \"valtype\": \"bool\",\n" + " \"partype\": \"value\",\n" + " \"display_name\": \"recipe.par3\",\n" + " \"description\": \"Description 3\",\n" + " \"recipe\": \"recipe_name\"\n" + " },\n" + " {\n" + " \"name\": \"recipe.par4\",\n" + " \"value\": -10,\n" + " \"valtype\": \"int\",\n" + " \"partype\": \"value\",\n" + " \"display_name\": \"recipe.par4\",\n" + " \"description\": \"Escaped chars \\\" \\/ \\f \\n \\r \\t " + "\\\\\",\n" + " \"recipe\": \"recipe_name\"\n" + " },\n" + " {\n" + " \"name\": \"recipe.par5\",\n" + " \"value\": \"Str1\",\n" + " \"valtype\": \"string\",\n" + " \"partype\": \"enum\",\n" + " \"valenum\": [ \"Str1\" , \"Str2\" , \"Str3\" ],\n" + " \"display_name\": \"recipe.par5\",\n" + " \"description\": \"Description 5\",\n" + " \"recipe\": \"recipe_name\"\n" + " },\n" + " {\n" + " \"name\": \"recipe.par6\",\n" + " \"value\": 0,\n" + " \"valtype\": \"int\",\n" + " \"partype\": \"range\",\n" + " \"valmin\": -1,\n" + " \"valmax\": 1,\n" + " \"display_name\": \"recipe.par6\",\n" + " \"description\": \"Description 6\",\n" + " \"recipe\": \"recipe_name\"\n" + " }\n" + "]\n\0"; cpl_test_nonnull(fjson); fseek(fjson, 0, SEEK_END); length = ftell(fjson); rewind(fjson); - whole_file = cpl_malloc(length+1); + whole_file = cpl_malloc(length + 1); cpl_test_nonnull(whole_file); int read_length = fread(whole_file, 1, length, fjson); cpl_test_eq(read_length, length); - whole_file[length]='\0'; + whole_file[length] = '\0'; fclose(fjson); - cpl_test_zero( strcmp(whole_file, expected_json) ); + cpl_test_zero(strcmp(whole_file, expected_json)); - cpl_test_zero( remove("parlist2.json") ); + cpl_test_zero(remove("parlist2.json")); cpl_free(whole_file); } /* Try to save in a non-existent path */ { - cpl_error_code errcode = - er_recipe_parameterlist_to_json(parlist, "recipe_name", - "/non-existent/path/parlist.json"); + cpl_error_code errcode = + er_recipe_parameterlist_to_json(parlist, "recipe_name", + "/non-existent/path/parlist.json"); cpl_test_error(CPL_ERROR_FILE_NOT_CREATED); - cpl_test_eq(errcode , CPL_ERROR_FILE_NOT_CREATED); + cpl_test_eq(errcode, CPL_ERROR_FILE_NOT_CREATED); } - + /* Trying with null inputs */ { - cpl_error_code errcode = - er_recipe_parameterlist_to_json(NULL, "recipe_name", - "parlist.json"); + cpl_error_code errcode = + er_recipe_parameterlist_to_json(NULL, "recipe_name", + "parlist.json"); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); - cpl_test_eq(errcode , CPL_ERROR_ILLEGAL_INPUT); - - errcode = er_recipe_parameterlist_to_json(parlist, NULL, - "parlist.json"); + cpl_test_eq(errcode, CPL_ERROR_ILLEGAL_INPUT); + + errcode = + er_recipe_parameterlist_to_json(parlist, NULL, "parlist.json"); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); - cpl_test_eq(errcode , CPL_ERROR_ILLEGAL_INPUT); + cpl_test_eq(errcode, CPL_ERROR_ILLEGAL_INPUT); - errcode = er_recipe_parameterlist_to_json(parlist, "recipe_name", - NULL); + errcode = er_recipe_parameterlist_to_json(parlist, "recipe_name", NULL); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); - cpl_test_eq(errcode , CPL_ERROR_ILLEGAL_INPUT); + cpl_test_eq(errcode, CPL_ERROR_ILLEGAL_INPUT); } - + cpl_parameterlist_delete(parlist); } -static void esorex_json_frameset(void) +static void +esorex_json_frameset(void) { - cpl_frame * fset1; - cpl_frame * fset2; - cpl_frame * fset3; - cpl_frameset * frameset; - + cpl_frame *fset1; + cpl_frame *fset2; + cpl_frame *fset3; + cpl_frameset *frameset; + /* Export a frameset to a JSON file */ fset1 = cpl_frame_new(); cpl_frame_set_filename(fset1, "filename1.fits"); cpl_frame_set_tag(fset1, "FLAT"); - - cpl_test_nonnull( fset1 ); + + cpl_test_nonnull(fset1); fset2 = cpl_frame_new(); cpl_frame_set_filename(fset2, "filename2.fits"); cpl_frame_set_tag(fset2, "BIAS"); - - cpl_test_nonnull( fset2 ); - + + cpl_test_nonnull(fset2); + fset3 = cpl_frame_new(); cpl_frame_set_filename(fset3, "filename3.fits"); cpl_frame_set_tag(fset3, "SCIENCE"); - - cpl_test_nonnull( fset3 ); + + cpl_test_nonnull(fset3); frameset = cpl_frameset_new(); - - cpl_test_nonnull( frameset ); + + cpl_test_nonnull(frameset); cpl_frameset_insert(frameset, fset1); - + /* Dumping to json */ er_frameset_to_json(frameset, "frameset.json"); - + cpl_test_error(CPL_ERROR_NONE); /* Read the file and compare it with a static version */ { - char * whole_file = 0; + char *whole_file = 0; long length; - FILE * fjson = fopen("frameset.json", "rb"); - const char * expected_json="[\n" - " {\n" - " \"name\": \"filename1.fits\",\n" - " \"category\": \"FLAT\"\n" - " }\n" - "]\n\0"; - + FILE *fjson = fopen("frameset.json", "rb"); + const char *expected_json = "[\n" + " {\n" + " \"name\": \"filename1.fits\",\n" + " \"category\": \"FLAT\"\n" + " }\n" + "]\n\0"; + cpl_test_nonnull(fjson); fseek(fjson, 0, SEEK_END); length = ftell(fjson); rewind(fjson); - whole_file = cpl_malloc(length+1); - + whole_file = cpl_malloc(length + 1); + cpl_test_nonnull(whole_file); int read_length = fread(whole_file, 1, length, fjson); cpl_test_eq(read_length, length); - whole_file[length]='\0'; + whole_file[length] = '\0'; fclose(fjson); - - cpl_test_zero( strcmp(whole_file, expected_json) ); - - cpl_test_zero( remove("frameset.json") ); + + cpl_test_zero(strcmp(whole_file, expected_json)); + + cpl_test_zero(remove("frameset.json")); cpl_free(whole_file); } /* Do the same with a list that contains more than 1 frame */ cpl_frameset_insert(frameset, fset2); cpl_frameset_insert(frameset, fset3); - + cpl_test_error(CPL_ERROR_NONE); - + /* Dumping to json */ er_frameset_to_json(frameset, "frameset2.json"); cpl_test_error(CPL_ERROR_NONE); /* Read the file and compare it with a static version */ { - char * whole_file = 0; + char *whole_file = 0; long length; - FILE * fjson = fopen("frameset2.json", "rb"); - const char * expected_json="[\n" - " {\n" - " \"name\": \"filename1.fits\",\n" - " \"category\": \"FLAT\"\n" - " },\n" - " {\n" - " \"name\": \"filename2.fits\",\n" - " \"category\": \"BIAS\"\n" - " },\n" - " {\n" - " \"name\": \"filename3.fits\",\n" - " \"category\": \"SCIENCE\"\n" - " }\n" - "]\n\0"; + FILE *fjson = fopen("frameset2.json", "rb"); + const char *expected_json = "[\n" + " {\n" + " \"name\": \"filename1.fits\",\n" + " \"category\": \"FLAT\"\n" + " },\n" + " {\n" + " \"name\": \"filename2.fits\",\n" + " \"category\": \"BIAS\"\n" + " },\n" + " {\n" + " \"name\": \"filename3.fits\",\n" + " \"category\": \"SCIENCE\"\n" + " }\n" + "]\n\0"; cpl_test_nonnull(fjson); fseek(fjson, 0, SEEK_END); length = ftell(fjson); rewind(fjson); - whole_file = cpl_malloc(length+1); + whole_file = cpl_malloc(length + 1); cpl_test_nonnull(whole_file); int read_length = fread(whole_file, 1, length, fjson); cpl_test_eq(read_length, length); - whole_file[length]='\0'; + whole_file[length] = '\0'; fclose(fjson); - cpl_test_zero( strcmp(whole_file, expected_json) ); + cpl_test_zero(strcmp(whole_file, expected_json)); - cpl_test_zero( remove("frameset2.json") ); + cpl_test_zero(remove("frameset2.json")); cpl_free(whole_file); } /* Try to save in a non-existent path */ { cpl_error_code errcode = - er_frameset_to_json(frameset, - "/non-existent/path/frameset.json"); + er_frameset_to_json(frameset, "/non-existent/path/frameset.json"); cpl_test_error(CPL_ERROR_FILE_NOT_CREATED); - cpl_test_eq(errcode , CPL_ERROR_FILE_NOT_CREATED); + cpl_test_eq(errcode, CPL_ERROR_FILE_NOT_CREATED); } - + /* Trying with null inputs */ { - cpl_error_code errcode = - er_frameset_to_json(NULL, "frameset.json"); + cpl_error_code errcode = er_frameset_to_json(NULL, "frameset.json"); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); - cpl_test_eq(errcode , CPL_ERROR_ILLEGAL_INPUT); - + cpl_test_eq(errcode, CPL_ERROR_ILLEGAL_INPUT); + errcode = er_frameset_to_json(frameset, NULL); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); - cpl_test_eq(errcode , CPL_ERROR_ILLEGAL_INPUT); + cpl_test_eq(errcode, CPL_ERROR_ILLEGAL_INPUT); } - + cpl_frameset_delete(frameset); } -static void esorex_json_to_string_array(void) +static void +esorex_json_to_string_array(void) { /* Test conversion of a parsed JSON array of strings to er_stringarray_t. */ - const char * json = "[\"foo\",\"bar\"]"; - er_json_node * tree = er_json_parse(json); + const char *json = "[\"foo\",\"bar\"]"; + er_json_node *tree = er_json_parse(json); cpl_test_assert(tree != NULL); - er_stringarray_t * array = er_json_to_string_array(tree, json); + er_stringarray_t *array = er_json_to_string_array(tree, json); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(array); cpl_test_eq(er_stringarray_size(array), 2); @@ -505,10 +508,11 @@ er_json_node_delete(tree); } -static void esorex_json_escape_string(void) +static void +esorex_json_escape_string(void) { /* Test the er_json_escape_string function. */ - char * result = er_json_escape_string(" / \t \n \r \f \b \" \\ "); + char *result = er_json_escape_string(" / \t \n \r \f \b \" \\ "); cpl_test_nonnull(result); cpl_test_error(CPL_ERROR_NONE); cpl_test_eq_string(result, " \\/ \\t \\n \\r \\f \\b \\\" \\\\ "); @@ -521,45 +525,46 @@ #ifdef ENABLE_PYTHON_RECIPES -static void esorex_json_plugin_conversion(void) +static void +esorex_json_plugin_conversion(void) { - cpl_plugin * plugin = NULL; - cpl_plugin * parsed_plugin = NULL; - cpl_recipe * recipe = NULL; - cpl_recipe * parsed_recipe = NULL; - cpl_recipe2 * recipe2 = NULL; - cpl_recipe2 * parsed_recipe2 = NULL; - cpl_parameter * param1 = NULL; - cpl_parameter * param2 = NULL; - cpl_parameter * param3 = NULL; - cpl_parameter * param4 = NULL; - cpl_parameter * param5 = NULL; - cpl_parameter * param6 = NULL; - cpl_parameter * param7 = NULL; - cpl_parameter * param8 = NULL; - cpl_parameter * param9 = NULL; - cpl_parameter * param10 = NULL; - cpl_parameter * parsed_param0 = NULL; - cpl_parameter * parsed_param1 = NULL; - cpl_parameter * parsed_param2 = NULL; - cpl_parameter * parsed_param3 = NULL; - cpl_parameter * parsed_param4 = NULL; - cpl_parameter * parsed_param5 = NULL; - cpl_parameter * parsed_param6 = NULL; - cpl_parameter * parsed_param7 = NULL; - cpl_parameter * parsed_param8 = NULL; - cpl_parameter * parsed_param9 = NULL; - cpl_parameter * parsed_param10 = NULL; - cpl_frame * frame1 = NULL; - cpl_frame * frame2 = NULL; - cpl_frame * parsed_frame1 = NULL; - cpl_frame * parsed_frame2 = NULL; - char * json = NULL; - er_json_node * parsetree = NULL; - char** tags = NULL; - char** inputs = NULL; - char** outputs = NULL; - char** charptr = NULL; + cpl_plugin *plugin = NULL; + cpl_plugin *parsed_plugin = NULL; + cpl_recipe *recipe = NULL; + cpl_recipe *parsed_recipe = NULL; + cpl_recipe2 *recipe2 = NULL; + cpl_recipe2 *parsed_recipe2 = NULL; + cpl_parameter *param1 = NULL; + cpl_parameter *param2 = NULL; + cpl_parameter *param3 = NULL; + cpl_parameter *param4 = NULL; + cpl_parameter *param5 = NULL; + cpl_parameter *param6 = NULL; + cpl_parameter *param7 = NULL; + cpl_parameter *param8 = NULL; + cpl_parameter *param9 = NULL; + cpl_parameter *param10 = NULL; + cpl_parameter *parsed_param0 = NULL; + cpl_parameter *parsed_param1 = NULL; + cpl_parameter *parsed_param2 = NULL; + cpl_parameter *parsed_param3 = NULL; + cpl_parameter *parsed_param4 = NULL; + cpl_parameter *parsed_param5 = NULL; + cpl_parameter *parsed_param6 = NULL; + cpl_parameter *parsed_param7 = NULL; + cpl_parameter *parsed_param8 = NULL; + cpl_parameter *parsed_param9 = NULL; + cpl_parameter *parsed_param10 = NULL; + cpl_frame *frame1 = NULL; + cpl_frame *frame2 = NULL; + cpl_frame *parsed_frame1 = NULL; + cpl_frame *parsed_frame2 = NULL; + char *json = NULL; + er_json_node *parsetree = NULL; + char **tags = NULL; + char **inputs = NULL; + char **outputs = NULL; + char **charptr = NULL; /* Test some basic API error handling for the er_plugin_to_json and er_json_to_plugin functions. */ @@ -578,12 +583,11 @@ /* Test for error if an invalid plugin type is given. */ plugin = cpl_plugin_new(); - cpl_test_assert(cpl_plugin_init(plugin, CPL_PLUGIN_API, 1, - CPL_PLUGIN_TYPE_NONE, "test_recipe", - "simple test recipe", "description ...", - "some author", "author@eso.org", - "copyright ...", NULL, NULL, NULL) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_plugin_init(plugin, CPL_PLUGIN_API, 1, CPL_PLUGIN_TYPE_NONE, + "test_recipe", "simple test recipe", "description ...", + "some author", "author@eso.org", "copyright ...", NULL, + NULL, NULL) == CPL_ERROR_NONE); json = er_plugin_to_json(plugin); cpl_test_error(CPL_ERROR_UNSUPPORTED_MODE); cpl_test_null(json); @@ -591,14 +595,13 @@ /* Construct a simple recipe object, convert it to JSON text and check that the set strings are present in the output. */ - recipe = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); + recipe = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); plugin = &recipe->interface; - cpl_test_assert(cpl_plugin_init(plugin, CPL_PLUGIN_API, 1, - CPL_PLUGIN_TYPE_RECIPE, "test_recipe", - "simple test recipe", "description ...", - "some author", "author@eso.org", - "copyright ...", NULL, NULL, NULL) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_plugin_init(plugin, CPL_PLUGIN_API, 1, CPL_PLUGIN_TYPE_RECIPE, + "test_recipe", "simple test recipe", "description ...", + "some author", "author@eso.org", "copyright ...", NULL, + NULL, NULL) == CPL_ERROR_NONE); json = er_plugin_to_json(plugin); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(json); @@ -636,14 +639,13 @@ /* Construct a recipe v2 object, convert it to JSON text and check that the set strings are present in the output. */ - recipe2 = (cpl_recipe2 *) cpl_calloc(1, sizeof(cpl_recipe2)); + recipe2 = (cpl_recipe2 *)cpl_calloc(1, sizeof(cpl_recipe2)); plugin = &recipe2->base.interface; - cpl_test_assert(cpl_plugin_init(plugin, CPL_PLUGIN_API, 1, - CPL_PLUGIN_TYPE_RECIPE_V2, "test_recipe2", - "simple test recipe v2", "description ...", - "some author", "author@eso.org", - "copyright ...", NULL, NULL, NULL) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_plugin_init(plugin, CPL_PLUGIN_API, 1, CPL_PLUGIN_TYPE_RECIPE_V2, + "test_recipe2", "simple test recipe v2", + "description ...", "some author", "author@eso.org", + "copyright ...", NULL, NULL, NULL) == CPL_ERROR_NONE); json = er_plugin_to_json(plugin); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(json); @@ -658,16 +660,16 @@ /* Test a more complex example of a recipe plugin with parameters and an input frameset. */ - recipe = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); + recipe = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); recipe->parameters = cpl_parameterlist_new(); cpl_test_assert(recipe->parameters != NULL); - param1 = cpl_parameter_new_value("test.par1", CPL_TYPE_BOOL, - "bool value", "test_1", CPL_TRUE); + param1 = cpl_parameter_new_value("test.par1", CPL_TYPE_BOOL, "bool value", + "test_1", CPL_TRUE); cpl_test_assert(param1 != NULL); cpl_parameterlist_append(recipe->parameters, param1); - param2 = cpl_parameter_new_value("test.par2", CPL_TYPE_INT, - "int value", "test_2", 2); + param2 = cpl_parameter_new_value("test.par2", CPL_TYPE_INT, "int value", + "test_2", 2); cpl_test_assert(param2 != NULL); cpl_parameterlist_append(recipe->parameters, param2); param3 = cpl_parameter_new_value("test.par3", CPL_TYPE_DOUBLE, @@ -678,8 +680,8 @@ "string value", "test_4", "something"); cpl_test_assert(param4 != NULL); cpl_parameterlist_append(recipe->parameters, param4); - param5 = cpl_parameter_new_range("test.par5", CPL_TYPE_INT, - "range value1", "test_5", 3, 1, 5); + param5 = cpl_parameter_new_range("test.par5", CPL_TYPE_INT, "range value1", + "test_5", 3, 1, 5); cpl_test_assert(param5 != NULL); cpl_parameterlist_append(recipe->parameters, param5); param6 = cpl_parameter_new_range("test.par6", CPL_TYPE_DOUBLE, @@ -703,7 +705,7 @@ cpl_parameter_set_alias(param9, CPL_PARAMETER_MODE_CFG, "par9_cfg"); cpl_parameterlist_append(recipe->parameters, param9); param10 = cpl_parameter_new_value("test.par10", CPL_TYPE_BOOL, "disabled", - "test_10", CPL_FALSE); + "test_10", CPL_FALSE); cpl_test_assert(param10 != NULL); cpl_parameter_set_default_flag(param10, 0); cpl_parameter_disable(param10, CPL_PARAMETER_MODE_CLI); @@ -728,12 +730,11 @@ cpl_frameset_insert(recipe->frames, frame2); plugin = &recipe->interface; - cpl_test_assert(cpl_plugin_init(plugin, CPL_PLUGIN_API, 1, - CPL_PLUGIN_TYPE_RECIPE, "test_recipe", - "simple test recipe", "description ...", - "some author", "author@eso.org", - "copyright ...", NULL, NULL, NULL) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_plugin_init(plugin, CPL_PLUGIN_API, 1, CPL_PLUGIN_TYPE_RECIPE, + "test_recipe", "simple test recipe", "description ...", + "some author", "author@eso.org", "copyright ...", NULL, + NULL, NULL) == CPL_ERROR_NONE); json = er_plugin_to_json(plugin); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(json); @@ -751,7 +752,7 @@ cpl_test_nonnull(parsetree); cpl_test_error(CPL_ERROR_NONE); parsed_plugin = er_json_to_plugin(parsetree, json); - parsed_recipe = (cpl_recipe *) parsed_plugin; + parsed_recipe = (cpl_recipe *)parsed_plugin; cpl_test_nonnull(parsed_plugin); cpl_test_error(CPL_ERROR_NONE); @@ -772,51 +773,51 @@ same parameters as declared in the original plugin object that was serialised. */ cpl_test_eq(cpl_parameterlist_get_size(parsed_recipe->parameters), 11); - parsed_param0 = cpl_parameterlist_find(parsed_recipe->parameters, - "__class__"); + parsed_param0 = + cpl_parameterlist_find(parsed_recipe->parameters, "__class__"); cpl_test_nonnull(parsed_param0); cpl_test_eq(cpl_parameter_get_type(parsed_param0), CPL_TYPE_STRING); cpl_test_eq_string(cpl_parameter_get_string(parsed_param0), "unknown"); cpl_test_eq_string(cpl_parameter_get_default_string(parsed_param0), "unknown"); - parsed_param1 = cpl_parameterlist_find(parsed_recipe->parameters, - "test.par1"); + parsed_param1 = + cpl_parameterlist_find(parsed_recipe->parameters, "test.par1"); cpl_test_nonnull(parsed_param1); test_equal_param(param1, parsed_param1); - parsed_param2 = cpl_parameterlist_find(parsed_recipe->parameters, - "test.par2"); + parsed_param2 = + cpl_parameterlist_find(parsed_recipe->parameters, "test.par2"); cpl_test_nonnull(parsed_param2); test_equal_param(param2, parsed_param2); - parsed_param3 = cpl_parameterlist_find(parsed_recipe->parameters, - "test.par3"); + parsed_param3 = + cpl_parameterlist_find(parsed_recipe->parameters, "test.par3"); cpl_test_nonnull(parsed_param3); test_equal_param(param3, parsed_param3); - parsed_param4 = cpl_parameterlist_find(parsed_recipe->parameters, - "test.par4"); + parsed_param4 = + cpl_parameterlist_find(parsed_recipe->parameters, "test.par4"); cpl_test_nonnull(parsed_param4); test_equal_param(param4, parsed_param4); - parsed_param5 = cpl_parameterlist_find(parsed_recipe->parameters, - "test.par5"); + parsed_param5 = + cpl_parameterlist_find(parsed_recipe->parameters, "test.par5"); cpl_test_nonnull(parsed_param5); test_equal_param(param5, parsed_param5); - parsed_param6 = cpl_parameterlist_find(parsed_recipe->parameters, - "test.par6"); + parsed_param6 = + cpl_parameterlist_find(parsed_recipe->parameters, "test.par6"); cpl_test_nonnull(parsed_param6); test_equal_param(param6, parsed_param6); - parsed_param7 = cpl_parameterlist_find(parsed_recipe->parameters, - "test.par7"); + parsed_param7 = + cpl_parameterlist_find(parsed_recipe->parameters, "test.par7"); cpl_test_nonnull(parsed_param7); test_equal_param(param7, parsed_param7); - parsed_param8 = cpl_parameterlist_find(parsed_recipe->parameters, - "test.par8"); + parsed_param8 = + cpl_parameterlist_find(parsed_recipe->parameters, "test.par8"); cpl_test_nonnull(parsed_param8); test_equal_param(param8, parsed_param8); - parsed_param9 = cpl_parameterlist_find(parsed_recipe->parameters, - "test.par9"); + parsed_param9 = + cpl_parameterlist_find(parsed_recipe->parameters, "test.par9"); cpl_test_nonnull(parsed_param9); test_equal_param(param9, parsed_param9); - parsed_param10 = cpl_parameterlist_find(parsed_recipe->parameters, - "test.par10"); + parsed_param10 = + cpl_parameterlist_find(parsed_recipe->parameters, "test.par10"); cpl_test_nonnull(parsed_param10); test_equal_param(param10, parsed_param10); @@ -840,12 +841,12 @@ /* Construct a more complex example of a recipe v2 object, including its recipeconfig object. We then try produce JSON out of it and parse it back, to see that we get the same structure. */ - recipe2 = (cpl_recipe2 *) cpl_calloc(1, sizeof(cpl_recipe2)); + recipe2 = (cpl_recipe2 *)cpl_calloc(1, sizeof(cpl_recipe2)); recipe2->base.parameters = cpl_parameterlist_new(); cpl_test_assert(recipe2->base.parameters != NULL); - param1 = cpl_parameter_new_value("test.par1", CPL_TYPE_INT, - "int value", "test", 123); + param1 = cpl_parameter_new_value("test.par1", CPL_TYPE_INT, "int value", + "test", 123); cpl_test_assert(param1 != NULL); cpl_parameterlist_append(recipe2->base.parameters, param1); @@ -870,12 +871,11 @@ cpl_test_error(CPL_ERROR_NONE); plugin = &recipe2->base.interface; - cpl_test_assert(cpl_plugin_init(plugin, CPL_PLUGIN_API, 1, - CPL_PLUGIN_TYPE_RECIPE_V2, "test_recipe2", - "simple test recipe v2", "description ...", - "some author", "author@eso.org", - "copyright ...", NULL, NULL, NULL) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_plugin_init(plugin, CPL_PLUGIN_API, 1, CPL_PLUGIN_TYPE_RECIPE_V2, + "test_recipe2", "simple test recipe v2", + "description ...", "some author", "author@eso.org", + "copyright ...", NULL, NULL, NULL) == CPL_ERROR_NONE); json = er_plugin_to_json(plugin); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(json); @@ -884,7 +884,7 @@ cpl_test_nonnull(parsetree); cpl_test_error(CPL_ERROR_NONE); parsed_plugin = er_json_to_plugin(parsetree, json); - parsed_recipe2 = (cpl_recipe2 *) parsed_plugin; + parsed_recipe2 = (cpl_recipe2 *)parsed_plugin; cpl_test_nonnull(parsed_plugin); cpl_test_error(CPL_ERROR_NONE); @@ -901,15 +901,15 @@ "copyright ..."); cpl_test_eq(cpl_parameterlist_get_size(parsed_recipe2->base.parameters), 2); - parsed_param0 = cpl_parameterlist_find(parsed_recipe2->base.parameters, - "__class__"); + parsed_param0 = + cpl_parameterlist_find(parsed_recipe2->base.parameters, "__class__"); cpl_test_nonnull(parsed_param0); cpl_test_eq(cpl_parameter_get_type(parsed_param0), CPL_TYPE_STRING); cpl_test_eq_string(cpl_parameter_get_string(parsed_param0), "unknown"); cpl_test_eq_string(cpl_parameter_get_default_string(parsed_param0), "unknown"); - parsed_param1 = cpl_parameterlist_find(parsed_recipe2->base.parameters, - "test.par1"); + parsed_param1 = + cpl_parameterlist_find(parsed_recipe2->base.parameters, "test.par1"); cpl_test_nonnull(parsed_param1); test_equal_param(param1, parsed_param1); @@ -923,47 +923,51 @@ cpl_test_eq_string(tags[0], "RAW"); cpl_test_eq_string(tags[1], "RAW2"); cpl_test_null(tags[2]); - for (charptr = tags; *charptr != NULL; ++charptr) cpl_free(*charptr); + for (charptr = tags; *charptr != NULL; ++charptr) + cpl_free(*charptr); cpl_free(tags); inputs = cpl_recipeconfig_get_inputs(parsed_recipe2->config, "RAW"); cpl_test_nonnull(inputs); cpl_test_eq_string(inputs[0], "CALIB"); - cpl_test_eq(cpl_recipeconfig_get_min_count(parsed_recipe2->config, - "RAW", "CALIB"), + cpl_test_eq(cpl_recipeconfig_get_min_count(parsed_recipe2->config, "RAW", + "CALIB"), 2); - cpl_test_eq(cpl_recipeconfig_get_max_count(parsed_recipe2->config, - "RAW", "CALIB"), + cpl_test_eq(cpl_recipeconfig_get_max_count(parsed_recipe2->config, "RAW", + "CALIB"), 3); cpl_test_null(inputs[1]); - for (charptr = inputs; *charptr != NULL; ++charptr) cpl_free(*charptr); + for (charptr = inputs; *charptr != NULL; ++charptr) + cpl_free(*charptr); cpl_free(inputs); outputs = cpl_recipeconfig_get_outputs(parsed_recipe2->config, "RAW"); cpl_test_nonnull(outputs); cpl_test_eq_string(outputs[0], "PROD"); cpl_test_null(outputs[1]); - for (charptr = outputs; *charptr != NULL; ++charptr) cpl_free(*charptr); + for (charptr = outputs; *charptr != NULL; ++charptr) + cpl_free(*charptr); cpl_free(outputs); inputs = cpl_recipeconfig_get_inputs(parsed_recipe2->config, "RAW2"); cpl_test_nonnull(inputs); cpl_test_eq_string(inputs[0], "CALIB"); - cpl_test_eq(cpl_recipeconfig_get_min_count(parsed_recipe2->config, - "RAW2", "CALIB"), + cpl_test_eq(cpl_recipeconfig_get_min_count(parsed_recipe2->config, "RAW2", + "CALIB"), 2); - cpl_test_eq(cpl_recipeconfig_get_max_count(parsed_recipe2->config, - "RAW2", "CALIB"), + cpl_test_eq(cpl_recipeconfig_get_max_count(parsed_recipe2->config, "RAW2", + "CALIB"), 2); cpl_test_eq_string(inputs[1], "DARK"); - cpl_test_eq(cpl_recipeconfig_get_min_count(parsed_recipe2->config, - "RAW2", "DARK"), + cpl_test_eq(cpl_recipeconfig_get_min_count(parsed_recipe2->config, "RAW2", + "DARK"), 1); - cpl_test_eq(cpl_recipeconfig_get_max_count(parsed_recipe2->config, - "RAW2", "DARK"), + cpl_test_eq(cpl_recipeconfig_get_max_count(parsed_recipe2->config, "RAW2", + "DARK"), 1); cpl_test_null(inputs[2]); - for (charptr = inputs; *charptr != NULL; ++charptr) cpl_free(*charptr); + for (charptr = inputs; *charptr != NULL; ++charptr) + cpl_free(*charptr); cpl_free(inputs); outputs = cpl_recipeconfig_get_outputs(parsed_recipe2->config, "RAW2"); @@ -971,7 +975,8 @@ cpl_test_eq_string(inputs[0], "PROD2"); cpl_test_eq_string(inputs[1], "PROD3"); cpl_test_null(outputs[2]); - for (charptr = outputs; *charptr != NULL; ++charptr) cpl_free(*charptr); + for (charptr = outputs; *charptr != NULL; ++charptr) + cpl_free(*charptr); cpl_free(outputs); cpl_free(json); @@ -986,7 +991,7 @@ /* Test parsing of the recipeconfig object if negative values are used for the minimum and maximum. */ - recipe2 = (cpl_recipe2 *) cpl_calloc(1, sizeof(cpl_recipe2)); + recipe2 = (cpl_recipe2 *)cpl_calloc(1, sizeof(cpl_recipe2)); recipe2->base.parameters = cpl_parameterlist_new(); cpl_test_assert(recipe2->base.parameters != NULL); recipe2->base.frames = cpl_frameset_new(); @@ -1003,12 +1008,11 @@ cpl_test_error(CPL_ERROR_NONE); plugin = &recipe2->base.interface; - cpl_test_assert(cpl_plugin_init(plugin, CPL_PLUGIN_API, 1, - CPL_PLUGIN_TYPE_RECIPE_V2, "test_recipe2", - "simple test recipe v2", "description ...", - "some author", "author@eso.org", - "copyright ...", NULL, NULL, NULL) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_plugin_init(plugin, CPL_PLUGIN_API, 1, CPL_PLUGIN_TYPE_RECIPE_V2, + "test_recipe2", "simple test recipe v2", + "description ...", "some author", "author@eso.org", + "copyright ...", NULL, NULL, NULL) == CPL_ERROR_NONE); json = er_plugin_to_json(plugin); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(json); @@ -1017,7 +1021,7 @@ cpl_test_nonnull(parsetree); cpl_test_error(CPL_ERROR_NONE); parsed_plugin = er_json_to_plugin(parsetree, json); - parsed_recipe2 = (cpl_recipe2 *) parsed_plugin; + parsed_recipe2 = (cpl_recipe2 *)parsed_plugin; cpl_test_nonnull(parsed_plugin); cpl_test_error(CPL_ERROR_NONE); @@ -1027,26 +1031,27 @@ cpl_test_eq_string(tags[1], "RAW2"); cpl_test_eq_string(tags[2], "RAW3"); cpl_test_null(tags[3]); - for (charptr = tags; *charptr != NULL; ++charptr) cpl_free(*charptr); + for (charptr = tags; *charptr != NULL; ++charptr) + cpl_free(*charptr); cpl_free(tags); - cpl_test_eq(cpl_recipeconfig_get_min_count(parsed_recipe2->config, - "RAW1", "RAW1"), + cpl_test_eq(cpl_recipeconfig_get_min_count(parsed_recipe2->config, "RAW1", + "RAW1"), -1); - cpl_test_eq(cpl_recipeconfig_get_max_count(parsed_recipe2->config, - "RAW1", "RAW1"), + cpl_test_eq(cpl_recipeconfig_get_max_count(parsed_recipe2->config, "RAW1", + "RAW1"), 5); - cpl_test_eq(cpl_recipeconfig_get_min_count(parsed_recipe2->config, - "RAW2", "RAW2"), + cpl_test_eq(cpl_recipeconfig_get_min_count(parsed_recipe2->config, "RAW2", + "RAW2"), 4); - cpl_test_eq(cpl_recipeconfig_get_max_count(parsed_recipe2->config, - "RAW2", "RAW2"), + cpl_test_eq(cpl_recipeconfig_get_max_count(parsed_recipe2->config, "RAW2", + "RAW2"), -1); - cpl_test_eq(cpl_recipeconfig_get_min_count(parsed_recipe2->config, - "RAW3", "RAW3"), + cpl_test_eq(cpl_recipeconfig_get_min_count(parsed_recipe2->config, "RAW3", + "RAW3"), -1); - cpl_test_eq(cpl_recipeconfig_get_max_count(parsed_recipe2->config, - "RAW3", "RAW3"), + cpl_test_eq(cpl_recipeconfig_get_max_count(parsed_recipe2->config, "RAW3", + "RAW3"), -1); inputs = cpl_recipeconfig_get_inputs(parsed_recipe2->config, "RAW1"); @@ -1055,26 +1060,27 @@ cpl_test_eq_string(inputs[1], "CALIB2"); cpl_test_eq_string(inputs[2], "CALIB3"); cpl_test_null(inputs[3]); - for (charptr = inputs; *charptr != NULL; ++charptr) cpl_free(*charptr); + for (charptr = inputs; *charptr != NULL; ++charptr) + cpl_free(*charptr); cpl_free(inputs); - cpl_test_eq(cpl_recipeconfig_get_min_count(parsed_recipe2->config, - "RAW1", "CALIB1"), + cpl_test_eq(cpl_recipeconfig_get_min_count(parsed_recipe2->config, "RAW1", + "CALIB1"), -1); - cpl_test_eq(cpl_recipeconfig_get_max_count(parsed_recipe2->config, - "RAW1", "CALIB1"), + cpl_test_eq(cpl_recipeconfig_get_max_count(parsed_recipe2->config, "RAW1", + "CALIB1"), 3); - cpl_test_eq(cpl_recipeconfig_get_min_count(parsed_recipe2->config, - "RAW1", "CALIB2"), + cpl_test_eq(cpl_recipeconfig_get_min_count(parsed_recipe2->config, "RAW1", + "CALIB2"), 2); - cpl_test_eq(cpl_recipeconfig_get_max_count(parsed_recipe2->config, - "RAW1", "CALIB2"), + cpl_test_eq(cpl_recipeconfig_get_max_count(parsed_recipe2->config, "RAW1", + "CALIB2"), -1); - cpl_test_eq(cpl_recipeconfig_get_min_count(parsed_recipe2->config, - "RAW1", "CALIB3"), + cpl_test_eq(cpl_recipeconfig_get_min_count(parsed_recipe2->config, "RAW1", + "CALIB3"), -1); - cpl_test_eq(cpl_recipeconfig_get_max_count(parsed_recipe2->config, - "RAW1", "CALIB3"), + cpl_test_eq(cpl_recipeconfig_get_max_count(parsed_recipe2->config, "RAW1", + "CALIB3"), -1); cpl_free(json); @@ -1088,7 +1094,7 @@ /* Test parsing of the recipe configuration structure when there is only one tag and it has no inputs or outputs. */ - recipe2 = (cpl_recipe2 *) cpl_calloc(1, sizeof(cpl_recipe2)); + recipe2 = (cpl_recipe2 *)cpl_calloc(1, sizeof(cpl_recipe2)); recipe2->config = cpl_recipeconfig_new(); cpl_test_assert(recipe2->config != NULL); @@ -1096,12 +1102,11 @@ cpl_test_error(CPL_ERROR_NONE); plugin = &recipe2->base.interface; - cpl_test_assert(cpl_plugin_init(plugin, CPL_PLUGIN_API, 1, - CPL_PLUGIN_TYPE_RECIPE_V2, "test_recipe2", - "simple test recipe v2", "description ...", - "some author", "author@eso.org", - "copyright ...", NULL, NULL, NULL) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_plugin_init(plugin, CPL_PLUGIN_API, 1, CPL_PLUGIN_TYPE_RECIPE_V2, + "test_recipe2", "simple test recipe v2", + "description ...", "some author", "author@eso.org", + "copyright ...", NULL, NULL, NULL) == CPL_ERROR_NONE); json = er_plugin_to_json(plugin); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(json); @@ -1110,7 +1115,7 @@ cpl_test_nonnull(parsetree); cpl_test_error(CPL_ERROR_NONE); parsed_plugin = er_json_to_plugin(parsetree, json); - parsed_recipe2 = (cpl_recipe2 *) parsed_plugin; + parsed_recipe2 = (cpl_recipe2 *)parsed_plugin; cpl_test_nonnull(parsed_plugin); cpl_test_error(CPL_ERROR_NONE); @@ -1118,7 +1123,8 @@ cpl_test_nonnull(tags); cpl_test_eq_string(tags[0], "RAW"); cpl_test_null(tags[1]); - for (charptr = tags; *charptr != NULL; ++charptr) cpl_free(*charptr); + for (charptr = tags; *charptr != NULL; ++charptr) + cpl_free(*charptr); cpl_free(tags); inputs = cpl_recipeconfig_get_inputs(parsed_recipe2->config, "RAW"); @@ -1140,18 +1146,17 @@ /* Test parsing of the recipe configuration structure when it is empty. */ - recipe2 = (cpl_recipe2 *) cpl_calloc(1, sizeof(cpl_recipe2)); + recipe2 = (cpl_recipe2 *)cpl_calloc(1, sizeof(cpl_recipe2)); recipe2->config = cpl_recipeconfig_new(); cpl_test_assert(recipe2->config != NULL); plugin = &recipe2->base.interface; - cpl_test_assert(cpl_plugin_init(plugin, CPL_PLUGIN_API, 1, - CPL_PLUGIN_TYPE_RECIPE_V2, "test_recipe2", - "simple test recipe v2", "description ...", - "some author", "author@eso.org", - "copyright ...", NULL, NULL, NULL) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_plugin_init(plugin, CPL_PLUGIN_API, 1, CPL_PLUGIN_TYPE_RECIPE_V2, + "test_recipe2", "simple test recipe v2", + "description ...", "some author", "author@eso.org", + "copyright ...", NULL, NULL, NULL) == CPL_ERROR_NONE); json = er_plugin_to_json(plugin); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(json); @@ -1160,7 +1165,7 @@ cpl_test_nonnull(parsetree); cpl_test_error(CPL_ERROR_NONE); parsed_plugin = er_json_to_plugin(parsetree, json); - parsed_recipe2 = (cpl_recipe2 *) parsed_plugin; + parsed_recipe2 = (cpl_recipe2 *)parsed_plugin; cpl_test_nonnull(parsed_plugin); cpl_test_error(CPL_ERROR_NONE); @@ -1177,59 +1182,59 @@ er_json_node_delete(parsetree); } -static void esorex_test_plugin_parsing(void) +static void +esorex_test_plugin_parsing(void) { - const char * json = NULL; - cpl_plugin * plugin = NULL; - cpl_recipe * recipe = NULL; - cpl_parameter * ref_param1 = NULL; - cpl_parameter * parsed_param0 = NULL; - cpl_parameter * parsed_param1 = NULL; - cpl_frame * ref_frame = NULL; - cpl_frame * parsed_frame = NULL; - er_json_node * parsetree = NULL; + const char *json = NULL; + cpl_plugin *plugin = NULL; + cpl_recipe *recipe = NULL; + cpl_parameter *ref_param1 = NULL; + cpl_parameter *parsed_param0 = NULL; + cpl_parameter *parsed_param1 = NULL; + cpl_frame *ref_frame = NULL; + cpl_frame *parsed_frame = NULL; + er_json_node *parsetree = NULL; /* Test er_json_to_plugin produces a correct object for the corresponding JSON text. */ - json = - "{\n" - " \"class\": \"testclass\",\n" - " \"name\": \"testrecipe\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin\",\n" - " \"description\": \"description ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [\n" - " {\n" - " \"name\": \"test.par1\",\n" - " \"class\": \"value\",\n" - " \"id\": 0,\n" - " \"description\": \"int param\",\n" - " \"context\": \"test\",\n" - " \"value\": 12,\n" - " \"default\": 5,\n" - " \"present\": false,\n" - " \"tag\": \"myparam\",\n" - " \"cli_enabled\": true,\n" - " \"cli_alias\": \"par1_cli\",\n" - " \"env_enabled\": false,\n" - " \"env_alias\": \"par1_env\",\n" - " \"cfg_enabled\": true,\n" - " \"cfg_alias\": \"par1_cfg\"\n" - " }\n" - " ],\n" - " \"frames\": [\n" - " {\n" - " \"filename\": \"test.fits\",\n" - " \"tag\": \"RAW\",\n" - " \"type\": 2,\n" - " \"group\": 1,\n" - " \"level\": 3\n" - " }\n" - " ]\n" - "}\n"; + json = "{\n" + " \"class\": \"testclass\",\n" + " \"name\": \"testrecipe\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test plugin\",\n" + " \"description\": \"description ...\",\n" + " \"author\": \"Some Author\",\n" + " \"email\": \"someone@eso.org\",\n" + " \"copyright\": \"copyright ...\",\n" + " \"parameters\": [\n" + " {\n" + " \"name\": \"test.par1\",\n" + " \"class\": \"value\",\n" + " \"id\": 0,\n" + " \"description\": \"int param\",\n" + " \"context\": \"test\",\n" + " \"value\": 12,\n" + " \"default\": 5,\n" + " \"present\": false,\n" + " \"tag\": \"myparam\",\n" + " \"cli_enabled\": true,\n" + " \"cli_alias\": \"par1_cli\",\n" + " \"env_enabled\": false,\n" + " \"env_alias\": \"par1_env\",\n" + " \"cfg_enabled\": true,\n" + " \"cfg_alias\": \"par1_cfg\"\n" + " }\n" + " ],\n" + " \"frames\": [\n" + " {\n" + " \"filename\": \"test.fits\",\n" + " \"tag\": \"RAW\",\n" + " \"type\": 2,\n" + " \"group\": 1,\n" + " \"level\": 3\n" + " }\n" + " ]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); plugin = er_json_to_plugin(parsetree, json); @@ -1237,8 +1242,8 @@ cpl_test_error(CPL_ERROR_NONE); /* Prepare reference objects to compare to. */ - ref_param1 = cpl_parameter_new_value("test.par1", CPL_TYPE_INT, - "int param", "test", 5); + ref_param1 = cpl_parameter_new_value("test.par1", CPL_TYPE_INT, "int param", + "test", 5); cpl_test_assert(ref_param1 != NULL); cpl_parameter_set_int(ref_param1, 12); cpl_parameter_set_tag(ref_param1, "myparam"); @@ -1268,7 +1273,7 @@ cpl_test_eq_string(cpl_plugin_get_email(plugin), "someone@eso.org"); cpl_test_eq_string(cpl_plugin_get_copyright(plugin), "copyright ..."); - recipe = (cpl_recipe *) plugin; + recipe = (cpl_recipe *)plugin; cpl_test_eq(cpl_parameterlist_get_size(recipe->parameters), 2); parsed_param0 = cpl_parameterlist_find(recipe->parameters, "__class__"); cpl_test_nonnull(parsed_param0); @@ -1300,12 +1305,11 @@ er_json_node_delete(parsetree); /* Check that defaults are used if certain keywords are missing. */ - json = - "{\n" - " \"class\": \"testclass\",\n" - " \"parameters\": [],\n" - " \"frames\": []\n" - "}\n"; + json = "{\n" + " \"class\": \"testclass\",\n" + " \"parameters\": [],\n" + " \"frames\": []\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); plugin = er_json_to_plugin(parsetree, json); @@ -1341,18 +1345,17 @@ er_json_node_delete(parsetree); /* Check error handling if the 'class' keyword is missing. */ - json = - "{\n" - " \"name\": \"testrecipe\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin\",\n" - " \"description\": \"description ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [],\n" - " \"frames\": []\n" - "}\n"; + json = "{\n" + " \"name\": \"testrecipe\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test plugin\",\n" + " \"description\": \"description ...\",\n" + " \"author\": \"Some Author\",\n" + " \"email\": \"someone@eso.org\",\n" + " \"copyright\": \"copyright ...\",\n" + " \"parameters\": [],\n" + " \"frames\": []\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(er_json_to_plugin(parsetree, json)); @@ -1360,18 +1363,17 @@ er_json_node_delete(parsetree); /* Check error handling if the 'parameters' keyword is missing. */ - json = - "{\n" - " \"class\": \"testclass\",\n" - " \"name\": \"testrecipe\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin\",\n" - " \"description\": \"description ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"frames\": []\n" - "}\n"; + json = "{\n" + " \"class\": \"testclass\",\n" + " \"name\": \"testrecipe\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test plugin\",\n" + " \"description\": \"description ...\",\n" + " \"author\": \"Some Author\",\n" + " \"email\": \"someone@eso.org\",\n" + " \"copyright\": \"copyright ...\",\n" + " \"frames\": []\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(er_json_to_plugin(parsetree, json)); @@ -1379,19 +1381,18 @@ er_json_node_delete(parsetree); /* Check error handling if 'parameters' is not an array. */ - json = - "{\n" - " \"class\": \"testclass\",\n" - " \"name\": \"testrecipe\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin\",\n" - " \"description\": \"description ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": {\"dummy\": 123},\n" - " \"frames\": []\n" - "}\n"; + json = "{\n" + " \"class\": \"testclass\",\n" + " \"name\": \"testrecipe\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test plugin\",\n" + " \"description\": \"description ...\",\n" + " \"author\": \"Some Author\",\n" + " \"email\": \"someone@eso.org\",\n" + " \"copyright\": \"copyright ...\",\n" + " \"parameters\": {\"dummy\": 123},\n" + " \"frames\": []\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(er_json_to_plugin(parsetree, json)); @@ -1400,19 +1401,18 @@ /* Check error handling if the 'parameters' array contains invalid structures. */ - json = - "{\n" - " \"class\": \"testclass\",\n" - " \"name\": \"testrecipe\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin\",\n" - " \"description\": \"description ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [{\"dummy\": 123}],\n" - " \"frames\": []\n" - "}\n"; + json = "{\n" + " \"class\": \"testclass\",\n" + " \"name\": \"testrecipe\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test plugin\",\n" + " \"description\": \"description ...\",\n" + " \"author\": \"Some Author\",\n" + " \"email\": \"someone@eso.org\",\n" + " \"copyright\": \"copyright ...\",\n" + " \"parameters\": [{\"dummy\": 123}],\n" + " \"frames\": []\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(er_json_to_plugin(parsetree, json)); @@ -1420,18 +1420,17 @@ er_json_node_delete(parsetree); /* Make sure the parsing works if the 'frames' keyword is missing. */ - json = - "{\n" - " \"class\": \"testclass\",\n" - " \"name\": \"testrecipe\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin\",\n" - " \"description\": \"description ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": []\n" - "}\n"; + json = "{\n" + " \"class\": \"testclass\",\n" + " \"name\": \"testrecipe\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test plugin\",\n" + " \"description\": \"description ...\",\n" + " \"author\": \"Some Author\",\n" + " \"email\": \"someone@eso.org\",\n" + " \"copyright\": \"copyright ...\",\n" + " \"parameters\": []\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); plugin = er_json_to_plugin(parsetree, json); @@ -1442,19 +1441,18 @@ er_json_node_delete(parsetree); /* Check error handling if 'frames' is not an array. */ - json = - "{\n" - " \"class\": \"testclass\",\n" - " \"name\": \"testrecipe\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin\",\n" - " \"description\": \"description ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [],\n" - " \"frames\": {\"dummy\": 123}\n" - "}\n"; + json = "{\n" + " \"class\": \"testclass\",\n" + " \"name\": \"testrecipe\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test plugin\",\n" + " \"description\": \"description ...\",\n" + " \"author\": \"Some Author\",\n" + " \"email\": \"someone@eso.org\",\n" + " \"copyright\": \"copyright ...\",\n" + " \"parameters\": [],\n" + " \"frames\": {\"dummy\": 123}\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(er_json_to_plugin(parsetree, json)); @@ -1463,19 +1461,18 @@ /* Check error handling if the 'frames' array contains invalid structures. */ - json = - "{\n" - " \"class\": \"testclass\",\n" - " \"name\": \"testrecipe\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin\",\n" - " \"description\": \"description ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [],\n" - " \"frames\": [{\"dummy\": 123}]\n" - "}\n"; + json = "{\n" + " \"class\": \"testclass\",\n" + " \"name\": \"testrecipe\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test plugin\",\n" + " \"description\": \"description ...\",\n" + " \"author\": \"Some Author\",\n" + " \"email\": \"someone@eso.org\",\n" + " \"copyright\": \"copyright ...\",\n" + " \"parameters\": [],\n" + " \"frames\": [{\"dummy\": 123}]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(er_json_to_plugin(parsetree, json)); @@ -1483,20 +1480,19 @@ er_json_node_delete(parsetree); /* Check error handling if a 'recipeconfig' is not an array. */ - json = - "{\n" - " \"class\": \"testclass\",\n" - " \"name\": \"testrecipe\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin\",\n" - " \"description\": \"description ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [],\n" - " \"frames\": [],\n" - " \"recipeconfig\": {\"dummy\": 123}\n" - "}\n"; + json = "{\n" + " \"class\": \"testclass\",\n" + " \"name\": \"testrecipe\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test plugin\",\n" + " \"description\": \"description ...\",\n" + " \"author\": \"Some Author\",\n" + " \"email\": \"someone@eso.org\",\n" + " \"copyright\": \"copyright ...\",\n" + " \"parameters\": [],\n" + " \"frames\": [],\n" + " \"recipeconfig\": {\"dummy\": 123}\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(er_json_to_plugin(parsetree, json)); @@ -1505,20 +1501,19 @@ /* Check error handling if a 'recipeconfig' array contains invalid structures. */ - json = - "{\n" - " \"class\": \"testclass\",\n" - " \"name\": \"testrecipe\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin\",\n" - " \"description\": \"description ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [],\n" - " \"frames\": [],\n" - " \"recipeconfig\": [{\"dummy\": 123}]\n" - "}\n"; + json = "{\n" + " \"class\": \"testclass\",\n" + " \"name\": \"testrecipe\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test plugin\",\n" + " \"description\": \"description ...\",\n" + " \"author\": \"Some Author\",\n" + " \"email\": \"someone@eso.org\",\n" + " \"copyright\": \"copyright ...\",\n" + " \"parameters\": [],\n" + " \"frames\": [],\n" + " \"recipeconfig\": [{\"dummy\": 123}]\n" + "}\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); cpl_test_null(er_json_to_plugin(parsetree, json)); @@ -1526,44 +1521,44 @@ er_json_node_delete(parsetree); } -static void esorex_test_pluginlist_parsing(void) +static void +esorex_test_pluginlist_parsing(void) { - const char * json = NULL; - cpl_pluginlist * list = NULL; - cpl_plugin * plugin = NULL; - cpl_recipe * recipe = NULL; - cpl_parameter * param = NULL; - er_json_node * parsetree = NULL; + const char *json = NULL; + cpl_pluginlist *list = NULL; + cpl_plugin *plugin = NULL; + cpl_recipe *recipe = NULL; + cpl_parameter *param = NULL; + er_json_node *parsetree = NULL; /* Test er_json_to_pluginlist produces a correct plugin list for the corresponding JSON text. */ - json = - "[\n" - " {\n" - " \"class\": \"testclass1\",\n" - " \"name\": \"testrecipe1\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin\",\n" - " \"description\": \"description ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [],\n" - " \"frames\": []\n" - " },\n" - " {\n" - " \"class\": \"testclass2\",\n" - " \"name\": \"testrecipe2\",\n" - " \"version\": 345,\n" - " \"synopsis\": \"test plugin 2\",\n" - " \"description\": \"description 2 ...\",\n" - " \"author\": \"Some Author 2\",\n" - " \"email\": \"someone2@eso.org\",\n" - " \"copyright\": \"copyright 2 ...\",\n" - " \"parameters\": [],\n" - " \"frames\": []\n" - " }\n" - "]\n"; + json = "[\n" + " {\n" + " \"class\": \"testclass1\",\n" + " \"name\": \"testrecipe1\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test plugin\",\n" + " \"description\": \"description ...\",\n" + " \"author\": \"Some Author\",\n" + " \"email\": \"someone@eso.org\",\n" + " \"copyright\": \"copyright ...\",\n" + " \"parameters\": [],\n" + " \"frames\": []\n" + " },\n" + " {\n" + " \"class\": \"testclass2\",\n" + " \"name\": \"testrecipe2\",\n" + " \"version\": 345,\n" + " \"synopsis\": \"test plugin 2\",\n" + " \"description\": \"description 2 ...\",\n" + " \"author\": \"Some Author 2\",\n" + " \"email\": \"someone2@eso.org\",\n" + " \"copyright\": \"copyright 2 ...\",\n" + " \"parameters\": [],\n" + " \"frames\": []\n" + " }\n" + "]\n"; parsetree = er_json_parse(json); cpl_test_assert(parsetree != NULL); list = er_json_to_pluginlist(parsetree, json); @@ -1583,7 +1578,7 @@ cpl_test_eq_string(cpl_plugin_get_email(plugin), "someone@eso.org"); cpl_test_eq_string(cpl_plugin_get_copyright(plugin), "copyright ..."); - recipe = (cpl_recipe *) plugin; + recipe = (cpl_recipe *)plugin; cpl_test_eq(cpl_parameterlist_get_size(recipe->parameters), 1); param = cpl_parameterlist_find(recipe->parameters, "__class__"); cpl_test_nonnull(param); @@ -1602,7 +1597,7 @@ cpl_test_eq_string(cpl_plugin_get_email(plugin), "someone2@eso.org"); cpl_test_eq_string(cpl_plugin_get_copyright(plugin), "copyright 2 ..."); - recipe = (cpl_recipe *) plugin; + recipe = (cpl_recipe *)plugin; cpl_test_eq(cpl_parameterlist_get_size(recipe->parameters), 1); param = cpl_parameterlist_find(recipe->parameters, "__class__"); cpl_test_nonnull(param); diff -Nru esorex-3.13.5+ds/src/tests/esorex_python_errors1-test.c esorex-3.13.6+ds/src/tests/esorex_python_errors1-test.c --- esorex-3.13.5+ds/src/tests/esorex_python_errors1-test.c 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/tests/esorex_python_errors1-test.c 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2017 European Southern Observatory + * Copyright (C) 2017-2022 European Southern Observatory * * 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 @@ -48,9 +48,10 @@ int errno_value_to_use = EIO; -int close(int fd) +int +close(int fd) { - (void) fd; + (void)fd; errno = errno_value_to_use; return -1; } @@ -59,15 +60,14 @@ cpl_boolean cpl_plugin_set_init_must_produce_error = CPL_FALSE; -cpl_error_code _cpl_plugin_set_init(cpl_plugin * self, cpl_plugin_func func) +cpl_error_code +_cpl_plugin_set_init(cpl_plugin *self, cpl_plugin_func func) { - if (cpl_plugin_set_init_must_produce_error) - { + if (cpl_plugin_set_init_must_produce_error) { return cpl_error_set_message("cpl_plugin_set_init", CPL_ERROR_ILLEGAL_OUTPUT, "dummy error"); } - else - { + else { return cpl_plugin_set_init(self, func); } } @@ -77,39 +77,36 @@ cpl_boolean cpl_pluginlist_append_must_produce_error = CPL_FALSE; -cpl_error_code _cpl_pluginlist_append(cpl_pluginlist * self, - const cpl_plugin * plugin) +cpl_error_code +_cpl_pluginlist_append(cpl_pluginlist *self, const cpl_plugin *plugin) { - if (cpl_pluginlist_append_must_produce_error) - { + if (cpl_pluginlist_append_must_produce_error) { return cpl_error_set_message("cpl_pluginlist_append", CPL_ERROR_ILLEGAL_OUTPUT, "dummy error"); } - else - { + else { return cpl_pluginlist_append(self, plugin); } } cpl_boolean cpl_frameset_insert_must_produce_error = CPL_FALSE; -cpl_error_code _cpl_frameset_insert(cpl_frameset *self, cpl_frame *frame) +cpl_error_code +_cpl_frameset_insert(cpl_frameset *self, cpl_frame *frame) { - if (cpl_pluginlist_append_must_produce_error) - { + if (cpl_pluginlist_append_must_produce_error) { return cpl_error_set_message("cpl_frameset_insert", CPL_ERROR_ILLEGAL_OUTPUT, "dummy error"); } - else - { + else { return cpl_frameset_insert(self, frame); } } /* Replace calls in the code we want to test with our overloaded functions. */ -#define cpl_plugin_set_init _cpl_plugin_set_init +#define cpl_plugin_set_init _cpl_plugin_set_init #define cpl_pluginlist_append _cpl_pluginlist_append -#define cpl_frameset_insert _cpl_frameset_insert +#define cpl_frameset_insert _cpl_frameset_insert #include "er_python.c" #undef cpl_plugin_set_init #undef cpl_pluginlist_append @@ -127,7 +124,8 @@ Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -144,7 +142,8 @@ Private functions -----------------------------------------------------------------------------*/ -static void test_close_file(void) +static void +test_close_file(void) { /* Test edge case where close() fails with EIO. This should be ignored. */ errno_value_to_use = EIO; @@ -157,12 +156,13 @@ cpl_test_error(CPL_ERROR_NONE); } -static void test_get_plugin_list(void) +static void +test_get_plugin_list(void) { - char * module_name = NULL; - cpl_plugin * plugin = NULL; - cpl_pluginlist * pluginlist = NULL; - cpl_pluginlist * list = NULL; + char *module_name = NULL; + cpl_plugin *plugin = NULL; + cpl_pluginlist *pluginlist = NULL; + cpl_pluginlist *list = NULL; /* Test and edge case where the cpl_plugin_set_init function fails when invoking er_python_get_plugin_list. We first have to prepare the module @@ -172,17 +172,16 @@ er_python_get_plugin_list which is being tested. */ plugin = cpl_plugin_new(); - cpl_test_assert(cpl_plugin_init(plugin, CPL_PLUGIN_API, 1, - CPL_PLUGIN_TYPE_RECIPE, "test_recipe", - "simple test recipe", "description ...", - "some author", "author@eso.org", - "copyright ...", NULL, NULL, NULL) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_plugin_init(plugin, CPL_PLUGIN_API, 1, CPL_PLUGIN_TYPE_RECIPE, + "test_recipe", "simple test recipe", "description ...", + "some author", "author@eso.org", "copyright ...", NULL, + NULL, NULL) == CPL_ERROR_NONE); pluginlist = cpl_pluginlist_new(); cpl_test_assert(pluginlist != NULL); - cpl_test_assert(cpl_pluginlist_append(pluginlist, plugin) - == CPL_ERROR_NONE); + cpl_test_assert(cpl_pluginlist_append(pluginlist, plugin) == + CPL_ERROR_NONE); module_list = cx_map_new(string_key_compare, cpl_free, (cx_free_func)er_json_pluginlist_delete); @@ -209,17 +208,16 @@ the error behaviour of er_python_get_plugin_list when the function cpl_pluginlist_append fails instead. */ plugin = cpl_plugin_new(); - cpl_test_assert(cpl_plugin_init(plugin, CPL_PLUGIN_API, 1, - CPL_PLUGIN_TYPE_RECIPE, "test_recipe", - "simple test recipe", "description ...", - "some author", "author@eso.org", - "copyright ...", NULL, NULL, NULL) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_plugin_init(plugin, CPL_PLUGIN_API, 1, CPL_PLUGIN_TYPE_RECIPE, + "test_recipe", "simple test recipe", "description ...", + "some author", "author@eso.org", "copyright ...", NULL, + NULL, NULL) == CPL_ERROR_NONE); pluginlist = cpl_pluginlist_new(); cpl_test_assert(pluginlist != NULL); - cpl_test_assert(cpl_pluginlist_append(pluginlist, plugin) - == CPL_ERROR_NONE); + cpl_test_assert(cpl_pluginlist_append(pluginlist, plugin) == + CPL_ERROR_NONE); module_list = cx_map_new(string_key_compare, cpl_free, (cx_free_func)er_json_pluginlist_delete); @@ -243,22 +241,23 @@ er_python_cleanup(); } -static void test_update_plugin(void) +static void +test_update_plugin(void) { - cpl_recipe * recipe = NULL; - cpl_recipe * recipe2 = NULL; - cpl_frame * frame = NULL; + cpl_recipe *recipe = NULL; + cpl_recipe *recipe2 = NULL; + cpl_frame *frame = NULL; - recipe = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); + recipe = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); cpl_test_assert(cpl_plugin_init(&recipe->interface, CPL_PLUGIN_API, 1, CPL_PLUGIN_TYPE_RECIPE, "test_recipe", "simple test recipe", "description ...", "some author", "author@eso.org", - "copyright ...", NULL, NULL, NULL) - == CPL_ERROR_NONE); - recipe2 = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); - cpl_test_assert(cpl_plugin_copy(&recipe2->interface, &recipe->interface) - == CPL_ERROR_NONE); + "copyright ...", NULL, NULL, + NULL) == CPL_ERROR_NONE); + recipe2 = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); + cpl_test_assert(cpl_plugin_copy(&recipe2->interface, &recipe->interface) == + CPL_ERROR_NONE); recipe->frames = cpl_frameset_new(); cpl_test_assert(recipe->frames != NULL); @@ -266,17 +265,17 @@ cpl_test_assert(recipe2->frames != NULL); frame = cpl_frame_new(); cpl_test_assert(frame != NULL); - cpl_test_assert(cpl_frame_set_filename(frame, "output.fits") - == CPL_ERROR_NONE); + cpl_test_assert(cpl_frame_set_filename(frame, "output.fits") == + CPL_ERROR_NONE); cpl_test_assert(cpl_frame_set_tag(frame, "PROD") == CPL_ERROR_NONE); - cpl_test_assert(cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE) - == CPL_ERROR_NONE); - cpl_test_assert(cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT) - == CPL_ERROR_NONE); - cpl_test_assert(cpl_frame_set_level(frame, CPL_FRAME_LEVEL_FINAL) - == CPL_ERROR_NONE); - cpl_test_assert(cpl_frameset_insert(recipe2->frames, frame) - == CPL_ERROR_NONE); + cpl_test_assert(cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE) == + CPL_ERROR_NONE); + cpl_test_assert(cpl_frame_set_group(frame, CPL_FRAME_GROUP_PRODUCT) == + CPL_ERROR_NONE); + cpl_test_assert(cpl_frame_set_level(frame, CPL_FRAME_LEVEL_FINAL) == + CPL_ERROR_NONE); + cpl_test_assert(cpl_frameset_insert(recipe2->frames, frame) == + CPL_ERROR_NONE); /* Test error handling if the cpl_frameset_insert function returns an error while calling update_plugin. */ @@ -294,10 +293,11 @@ #else /* ENABLE_PYTHON_RECIPES */ -int main(void) +int +main(void) { /* Indicate to the automake test runner that the tests are skipped. */ return 77; } -#endif /* ENABLE_PYTHON_RECIPES */ +#endif /* ENABLE_PYTHON_RECIPES */ diff -Nru esorex-3.13.5+ds/src/tests/esorex_python_errors2-test.c esorex-3.13.6+ds/src/tests/esorex_python_errors2-test.c --- esorex-3.13.5+ds/src/tests/esorex_python_errors2-test.c 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/tests/esorex_python_errors2-test.c 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2017 European Southern Observatory + * Copyright (C) 2017-2022 European Southern Observatory * * 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 @@ -50,99 +50,94 @@ cpl_boolean cpl_parameterlist_append_must_produce_error = CPL_FALSE; -cpl_error_code _cpl_parameterlist_append(cpl_parameterlist *self, - cpl_parameter *parameter) +cpl_error_code +_cpl_parameterlist_append(cpl_parameterlist *self, cpl_parameter *parameter) { - if (cpl_parameterlist_append_must_produce_error) - { + if (cpl_parameterlist_append_must_produce_error) { return cpl_error_set_message("cpl_parameterlist_append", CPL_ERROR_ILLEGAL_OUTPUT, "dummy error"); } - else - { + else { return cpl_parameterlist_append(self, parameter); } } cpl_boolean cpl_recipeconfig_get_tags_must_produce_error = CPL_FALSE; -char** _cpl_recipeconfig_get_tags(const cpl_recipeconfig* self) +char ** +_cpl_recipeconfig_get_tags(const cpl_recipeconfig *self) { - if (cpl_recipeconfig_get_tags_must_produce_error) - { + if (cpl_recipeconfig_get_tags_must_produce_error) { cpl_error_set_message("cpl_recipeconfig_get_tags", CPL_ERROR_ILLEGAL_OUTPUT, "dummy error"); return NULL; } - else - { + else { return cpl_recipeconfig_get_tags(self); } } cpl_boolean cpl_recipeconfig_get_inputs_must_produce_error = CPL_FALSE; -char** _cpl_recipeconfig_get_inputs(const cpl_recipeconfig* self, - const char* tag) +char ** +_cpl_recipeconfig_get_inputs(const cpl_recipeconfig *self, const char *tag) { - if (cpl_recipeconfig_get_inputs_must_produce_error) - { + if (cpl_recipeconfig_get_inputs_must_produce_error) { cpl_error_set_message("cpl_recipeconfig_get_inputs", CPL_ERROR_ILLEGAL_OUTPUT, "dummy error"); return NULL; } - else - { + else { return cpl_recipeconfig_get_inputs(self, tag); } } cpl_boolean cpl_recipeconfig_get_outputs_must_produce_error = CPL_FALSE; -char** _cpl_recipeconfig_get_outputs(const cpl_recipeconfig* self, - const char* tag) +char ** +_cpl_recipeconfig_get_outputs(const cpl_recipeconfig *self, const char *tag) { - if (cpl_recipeconfig_get_outputs_must_produce_error) - { + if (cpl_recipeconfig_get_outputs_must_produce_error) { cpl_error_set_message("cpl_recipeconfig_get_outputs", CPL_ERROR_ILLEGAL_OUTPUT, "dummy error"); return NULL; } - else - { + else { return cpl_recipeconfig_get_outputs(self, tag); } } cpl_boolean cpl_recipeconfig_set_tag_must_produce_error = CPL_FALSE; -int _cpl_recipeconfig_set_tag(cpl_recipeconfig* self, const char* tag, - cpl_size min_count, cpl_size max_count) +int +_cpl_recipeconfig_set_tag(cpl_recipeconfig *self, + const char *tag, + cpl_size min_count, + cpl_size max_count) { - if (cpl_recipeconfig_set_tag_must_produce_error) - { + if (cpl_recipeconfig_set_tag_must_produce_error) { return cpl_error_set_message("cpl_recipeconfig_set_tag", CPL_ERROR_ILLEGAL_OUTPUT, "dummy error"); } - else - { + else { return cpl_recipeconfig_set_tag(self, tag, min_count, max_count); } } cpl_boolean cpl_recipeconfig_set_input_must_produce_error = CPL_FALSE; -int _cpl_recipeconfig_set_input(cpl_recipeconfig* self, const char* tag, - const char* input, cpl_size min_count, - cpl_size max_count) +int +_cpl_recipeconfig_set_input(cpl_recipeconfig *self, + const char *tag, + const char *input, + cpl_size min_count, + cpl_size max_count) { - if (cpl_recipeconfig_set_input_must_produce_error) - { + if (cpl_recipeconfig_set_input_must_produce_error) { return cpl_error_set_message("cpl_recipeconfig_set_input", CPL_ERROR_ILLEGAL_OUTPUT, "dummy error"); } - else - { + else { return cpl_recipeconfig_set_input(self, tag, input, min_count, max_count); } @@ -150,28 +145,28 @@ cpl_boolean cpl_recipeconfig_set_output_must_produce_error = CPL_FALSE; -int _cpl_recipeconfig_set_output(cpl_recipeconfig* self, const char* tag, - const char* output) +int +_cpl_recipeconfig_set_output(cpl_recipeconfig *self, + const char *tag, + const char *output) { - if (cpl_recipeconfig_set_output_must_produce_error) - { + if (cpl_recipeconfig_set_output_must_produce_error) { return cpl_error_set_message("cpl_recipeconfig_set_output", CPL_ERROR_ILLEGAL_OUTPUT, "dummy error"); } - else - { + else { return cpl_recipeconfig_set_output(self, tag, output); } } /* Replace calls in the code we want to test with our overloaded functions. */ -#define cpl_parameterlist_append _cpl_parameterlist_append -#define cpl_recipeconfig_get_tags _cpl_recipeconfig_get_tags -#define cpl_recipeconfig_get_inputs _cpl_recipeconfig_get_inputs +#define cpl_parameterlist_append _cpl_parameterlist_append +#define cpl_recipeconfig_get_tags _cpl_recipeconfig_get_tags +#define cpl_recipeconfig_get_inputs _cpl_recipeconfig_get_inputs #define cpl_recipeconfig_get_outputs _cpl_recipeconfig_get_outputs -#define cpl_recipeconfig_set_tag _cpl_recipeconfig_set_tag -#define cpl_recipeconfig_set_input _cpl_recipeconfig_set_input -#define cpl_recipeconfig_set_output _cpl_recipeconfig_set_output +#define cpl_recipeconfig_set_tag _cpl_recipeconfig_set_tag +#define cpl_recipeconfig_set_input _cpl_recipeconfig_set_input +#define cpl_recipeconfig_set_output _cpl_recipeconfig_set_output #include "er_python.c" #undef cpl_parameterlist_append #undef cpl_recipeconfig_get_tags @@ -191,7 +186,8 @@ Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -206,51 +202,52 @@ Private functions -----------------------------------------------------------------------------*/ -static void test_plugin_initialize(void) +static void +test_plugin_initialize(void) { - char * module_name = NULL; - cpl_recipe2 * recipe = NULL; - cpl_recipe2 * recipe2 = NULL; - cpl_pluginlist * pluginlist = NULL; - cpl_parameter * param = NULL; + char *module_name = NULL; + cpl_recipe2 *recipe = NULL; + cpl_recipe2 *recipe2 = NULL; + cpl_pluginlist *pluginlist = NULL; + cpl_parameter *param = NULL; /* Loading a simulated plugin with one parameter and a simple recipe config structure. */ - recipe = (cpl_recipe2 *) cpl_calloc(1, sizeof(cpl_recipe2)); + recipe = (cpl_recipe2 *)cpl_calloc(1, sizeof(cpl_recipe2)); cpl_test_assert(cpl_plugin_init(&recipe->base.interface, CPL_PLUGIN_API, 1, CPL_PLUGIN_TYPE_RECIPE_V2, "test_recipe", "simple test recipe", "description ...", "some author", "author@eso.org", - "copyright ...", NULL, NULL, NULL) - == CPL_ERROR_NONE); + "copyright ...", NULL, NULL, + NULL) == CPL_ERROR_NONE); recipe->base.parameters = cpl_parameterlist_new(); cpl_test_assert(recipe->base.parameters != NULL); param = cpl_parameter_new_value("test.par1", CPL_TYPE_INT, "int param", "test", 5); cpl_test_assert(param != NULL); - cpl_test_assert(cpl_parameterlist_append(recipe->base.parameters, param) - == CPL_ERROR_NONE); + cpl_test_assert(cpl_parameterlist_append(recipe->base.parameters, param) == + CPL_ERROR_NONE); param = cpl_parameter_new_value("__class__", CPL_TYPE_STRING, "Python class name", "__python__", "recipeclass"); cpl_test_assert(param != NULL); - cpl_test_assert(cpl_parameterlist_append(recipe->base.parameters, param) - == CPL_ERROR_NONE); + cpl_test_assert(cpl_parameterlist_append(recipe->base.parameters, param) == + CPL_ERROR_NONE); recipe->config = cpl_recipeconfig_new(); cpl_test_assert(recipe->config != NULL); cpl_test_assert(cpl_recipeconfig_set_tag(recipe->config, "RAW", 1, 1) == 0); - cpl_test_assert(cpl_recipeconfig_set_input(recipe->config, "RAW", - "CALIB", 1, 1) - == 0); - cpl_test_assert(cpl_recipeconfig_set_output(recipe->config, "RAW", "PROD") - == 0); + cpl_test_assert( + cpl_recipeconfig_set_input(recipe->config, "RAW", "CALIB", 1, 1) == 0); + cpl_test_assert( + cpl_recipeconfig_set_output(recipe->config, "RAW", "PROD") == 0); pluginlist = cpl_pluginlist_new(); cpl_test_assert(pluginlist != NULL); - cpl_test_assert(cpl_pluginlist_append(pluginlist, &recipe->base.interface) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_pluginlist_append(pluginlist, &recipe->base.interface) == + CPL_ERROR_NONE); module_list = cx_map_new(string_key_compare, cpl_free, (cx_free_func)er_json_pluginlist_delete); @@ -264,10 +261,9 @@ /* Test error handling of plugin_initialize if cpl_parameterlist_append produces and error. */ - recipe2 = (cpl_recipe2 *) cpl_calloc(1, sizeof(cpl_recipe2)); + recipe2 = (cpl_recipe2 *)cpl_calloc(1, sizeof(cpl_recipe2)); cpl_test_assert(cpl_plugin_copy(&recipe2->base.interface, - &recipe->base.interface) - == CPL_ERROR_NONE); + &recipe->base.interface) == CPL_ERROR_NONE); cpl_parameterlist_append_must_produce_error = CPL_TRUE; cpl_recipeconfig_get_tags_must_produce_error = CPL_FALSE; cpl_recipeconfig_get_inputs_must_produce_error = CPL_FALSE; @@ -284,10 +280,9 @@ /* Test error handling of plugin_initialize if cpl_recipeconfig_get_tags produces and error. */ - recipe2 = (cpl_recipe2 *) cpl_calloc(1, sizeof(cpl_recipe2)); + recipe2 = (cpl_recipe2 *)cpl_calloc(1, sizeof(cpl_recipe2)); cpl_test_assert(cpl_plugin_copy(&recipe2->base.interface, - &recipe->base.interface) - == CPL_ERROR_NONE); + &recipe->base.interface) == CPL_ERROR_NONE); cpl_parameterlist_append_must_produce_error = CPL_FALSE; cpl_recipeconfig_get_tags_must_produce_error = CPL_TRUE; cpl_recipeconfig_get_inputs_must_produce_error = CPL_FALSE; @@ -304,10 +299,9 @@ /* Test error handling of plugin_initialize if cpl_recipeconfig_get_inputs produces and error. */ - recipe2 = (cpl_recipe2 *) cpl_calloc(1, sizeof(cpl_recipe2)); + recipe2 = (cpl_recipe2 *)cpl_calloc(1, sizeof(cpl_recipe2)); cpl_test_assert(cpl_plugin_copy(&recipe2->base.interface, - &recipe->base.interface) - == CPL_ERROR_NONE); + &recipe->base.interface) == CPL_ERROR_NONE); cpl_parameterlist_append_must_produce_error = CPL_FALSE; cpl_recipeconfig_get_tags_must_produce_error = CPL_FALSE; cpl_recipeconfig_get_inputs_must_produce_error = CPL_TRUE; @@ -324,10 +318,9 @@ /* Test error handling of plugin_initialize if cpl_recipeconfig_get_outputs produces and error. */ - recipe2 = (cpl_recipe2 *) cpl_calloc(1, sizeof(cpl_recipe2)); + recipe2 = (cpl_recipe2 *)cpl_calloc(1, sizeof(cpl_recipe2)); cpl_test_assert(cpl_plugin_copy(&recipe2->base.interface, - &recipe->base.interface) - == CPL_ERROR_NONE); + &recipe->base.interface) == CPL_ERROR_NONE); cpl_parameterlist_append_must_produce_error = CPL_FALSE; cpl_recipeconfig_get_tags_must_produce_error = CPL_FALSE; cpl_recipeconfig_get_inputs_must_produce_error = CPL_FALSE; @@ -344,10 +337,9 @@ /* Test error handling of plugin_initialize if cpl_recipeconfig_set_tag produces and error. */ - recipe2 = (cpl_recipe2 *) cpl_calloc(1, sizeof(cpl_recipe2)); + recipe2 = (cpl_recipe2 *)cpl_calloc(1, sizeof(cpl_recipe2)); cpl_test_assert(cpl_plugin_copy(&recipe2->base.interface, - &recipe->base.interface) - == CPL_ERROR_NONE); + &recipe->base.interface) == CPL_ERROR_NONE); cpl_parameterlist_append_must_produce_error = CPL_FALSE; cpl_recipeconfig_get_tags_must_produce_error = CPL_FALSE; cpl_recipeconfig_get_inputs_must_produce_error = CPL_FALSE; @@ -364,10 +356,9 @@ /* Test error handling of plugin_initialize if cpl_recipeconfig_set_input produces and error. */ - recipe2 = (cpl_recipe2 *) cpl_calloc(1, sizeof(cpl_recipe2)); + recipe2 = (cpl_recipe2 *)cpl_calloc(1, sizeof(cpl_recipe2)); cpl_test_assert(cpl_plugin_copy(&recipe2->base.interface, - &recipe->base.interface) - == CPL_ERROR_NONE); + &recipe->base.interface) == CPL_ERROR_NONE); cpl_parameterlist_append_must_produce_error = CPL_FALSE; cpl_recipeconfig_get_tags_must_produce_error = CPL_FALSE; cpl_recipeconfig_get_inputs_must_produce_error = CPL_FALSE; @@ -384,10 +375,9 @@ /* Test error handling of plugin_initialize if cpl_recipeconfig_set_output produces and error. */ - recipe2 = (cpl_recipe2 *) cpl_calloc(1, sizeof(cpl_recipe2)); + recipe2 = (cpl_recipe2 *)cpl_calloc(1, sizeof(cpl_recipe2)); cpl_test_assert(cpl_plugin_copy(&recipe2->base.interface, - &recipe->base.interface) - == CPL_ERROR_NONE); + &recipe->base.interface) == CPL_ERROR_NONE); cpl_parameterlist_append_must_produce_error = CPL_FALSE; cpl_recipeconfig_get_tags_must_produce_error = CPL_FALSE; cpl_recipeconfig_get_inputs_must_produce_error = CPL_FALSE; @@ -412,10 +402,11 @@ #else /* ENABLE_PYTHON_RECIPES */ -int main(void) +int +main(void) { /* Indicate to the automake test runner that the tests are skipped. */ return 77; } -#endif /* ENABLE_PYTHON_RECIPES */ +#endif /* ENABLE_PYTHON_RECIPES */ diff -Nru esorex-3.13.5+ds/src/tests/esorex_python_errors3-test.c esorex-3.13.6+ds/src/tests/esorex_python_errors3-test.c --- esorex-3.13.5+ds/src/tests/esorex_python_errors3-test.c 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/tests/esorex_python_errors3-test.c 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2017 European Southern Observatory + * Copyright (C) 2017-2022 European Southern Observatory * * 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 @@ -56,31 +56,29 @@ cpl_boolean pipe_must_produce_error = CPL_FALSE; int pipe_error_countdown = 0; -int _overloaded_pipe(int fildes[2]) +int +_overloaded_pipe(int fildes[2]) { --pipe_error_countdown; - if (pipe_must_produce_error && pipe_error_countdown < 0) - { + if (pipe_must_produce_error && pipe_error_countdown < 0) { errno = EIO; return -1; } - else - { + else { return pipe(fildes); } } cpl_boolean fork_must_produce_error = CPL_FALSE; -pid_t _overloaded_fork(void) +pid_t +_overloaded_fork(void) { - if (fork_must_produce_error) - { + if (fork_must_produce_error) { errno = EIO; return -1; } - else - { + else { return fork(); } } @@ -88,16 +86,15 @@ cpl_boolean dup_must_produce_error = CPL_FALSE; int dup_error_countdown = 0; -int _overloaded_dup(int oldfd) +int +_overloaded_dup(int oldfd) { --dup_error_countdown; - if (dup_must_produce_error && dup_error_countdown < 0) - { + if (dup_must_produce_error && dup_error_countdown < 0) { errno = EIO; return -1; } - else - { + else { return dup(oldfd); } } @@ -105,16 +102,15 @@ cpl_boolean dup2_must_produce_error = CPL_FALSE; int dup2_error_countdown = 0; -int _overloaded_dup2(int oldfd, int newfd) +int +_overloaded_dup2(int oldfd, int newfd) { --dup2_error_countdown; - if (dup2_must_produce_error && dup2_error_countdown < 0) - { + if (dup2_must_produce_error && dup2_error_countdown < 0) { errno = EIO; return -1; } - else - { + else { return dup2(oldfd, newfd); } } @@ -124,20 +120,18 @@ int close_error_countdown = 0; int close_on_which_pid = -1; -int _overloaded_close(int fd) +int +_overloaded_close(int fd) { - if (getpid() != close_on_which_pid) - { + if (getpid() != close_on_which_pid) { return close(fd); } --close_error_countdown; - if (close_must_produce_error && close_error_countdown < 0) - { + if (close_must_produce_error && close_error_countdown < 0) { errno = close_failure_code; return -1; } - else - { + else { return close(fd); } } @@ -147,22 +141,19 @@ int read_call_countdown = 0; int read_nbyte_limit = -1; -ssize_t _overloaded_read(int fildes, void *buf, size_t nbyte) +ssize_t +_overloaded_read(int fildes, void *buf, size_t nbyte) { --read_call_countdown; - if (read_must_produce_error || read_call_countdown >= 0) - { + if (read_must_produce_error || read_call_countdown >= 0) { errno = read_failure_code; return -1; } - else - { - if (read_nbyte_limit > 0) - { + else { + if (read_nbyte_limit > 0) { return read(fildes, buf, read_nbyte_limit); } - else - { + else { return read(fildes, buf, nbyte); } } @@ -173,22 +164,19 @@ int write_call_countdown = 0; int write_nbyte_limit = -1; -ssize_t _overloaded_write(int fildes, const void * buf, size_t nbyte) +ssize_t +_overloaded_write(int fildes, const void *buf, size_t nbyte) { --write_call_countdown; - if (write_must_produce_error || write_call_countdown >= 0) - { + if (write_must_produce_error || write_call_countdown >= 0) { errno = write_failure_code; return -1; } - else - { - if (write_nbyte_limit > 0) - { + else { + if (write_nbyte_limit > 0) { return write(fildes, buf, write_nbyte_limit); } - else - { + else { return write(fildes, buf, nbyte); } } @@ -196,28 +184,26 @@ cpl_boolean malloc_must_produce_error = CPL_FALSE; -void * _overloaded_malloc(size_t size) +void * +_overloaded_malloc(size_t size) { - if (malloc_must_produce_error) - { + if (malloc_must_produce_error) { return NULL; } - else - { + else { return malloc(size); } } cpl_boolean realloc_must_produce_error = CPL_FALSE; -void * _overloaded_realloc(void *ptr, size_t size) +void * +_overloaded_realloc(void *ptr, size_t size) { - if (realloc_must_produce_error) - { + if (realloc_must_produce_error) { return NULL; } - else - { + else { return realloc(ptr, size); } } @@ -226,29 +212,28 @@ waitpid is called by a certain number of invocations. */ int waitpid_call_countdown = 0; -pid_t _overloaded_waitpid(pid_t pid, int * wstatus, int options) +pid_t +_overloaded_waitpid(pid_t pid, int *wstatus, int options) { --waitpid_call_countdown; - if (waitpid_call_countdown >= 0) - { + if (waitpid_call_countdown >= 0) { errno = EINTR; return -1; } - else - { + else { return waitpid(pid, wstatus, options); } } /* Replace calls in the code we want to test with our overloaded functions. */ -#define pipe _overloaded_pipe -#define fork _overloaded_fork -#define dup _overloaded_dup -#define dup2 _overloaded_dup2 -#define close _overloaded_close -#define read _overloaded_read -#define write _overloaded_write -#define malloc _overloaded_malloc +#define pipe _overloaded_pipe +#define fork _overloaded_fork +#define dup _overloaded_dup +#define dup2 _overloaded_dup2 +#define close _overloaded_close +#define read _overloaded_read +#define write _overloaded_write +#define malloc _overloaded_malloc #define realloc _overloaded_realloc #define waitpid _overloaded_waitpid #include "er_python.c" @@ -267,7 +252,7 @@ Private function prototypes -----------------------------------------------------------------------------*/ -static void mock_python(const char * script); +static void mock_python(const char *script); static void test_start_python_interpreter(void); static void test_run_python_command(void); static void test_stop_python_interpreter(void); @@ -277,13 +262,14 @@ Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); /* Update the PATH environment variable to make sure we pick up our mock python script. */ - const char * path = "./mock_python_error3_test:/usr/bin:/bin"; + const char *path = "./mock_python_error3_test:/usr/bin:/bin"; cpl_test_assert(setenv("PATH", path, 0x1) == 0); /* Need to restrict overloading close() to this process. */ @@ -308,7 +294,8 @@ * interpreter process. The input is the shell script to write to the python * script file. */ -static void mock_python(const char * script) +static void +mock_python(const char *script) { /* Do not overwrite the python script if a previous test failed. This will make it easier to debug by having the failing script available. */ @@ -316,25 +303,24 @@ /* Create the directory for the python script. We put this in its own directory so that this unit test can be made concurrency safe. */ - if (mkdir("./mock_python_error3_test", 0777) != 0) - { + if (mkdir("./mock_python_error3_test", 0777) != 0) { cpl_test_assert(errno == EEXIST); } - FILE* file = fopen("./mock_python_error3_test/python", "w"); + FILE *file = fopen("./mock_python_error3_test/python", "w"); cpl_test_assert(file != NULL); size_t bytes_to_write = strlen(script); size_t bytes_written = fwrite(script, sizeof(char), bytes_to_write, file); cpl_test_assert(bytes_written == bytes_to_write); int fclose_result = fclose(file); cpl_test_assert(fclose_result == 0); - mode_t mode = S_IRUSR | S_IWUSR | S_IXUSR | - S_IRGRP | S_IXGRP | - S_IROTH | S_IXOTH; + mode_t mode = + S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; cpl_test_assert(chmod("./mock_python_error3_test/python", mode) == 0); } -static void test_start_python_interpreter(void) +static void +test_start_python_interpreter(void) { pid_t pid = -1; int input = -1; @@ -410,7 +396,8 @@ CPL_ERROR_NONE); } -static void test_run_python_command(void) +static void +test_run_python_command(void) { close_must_produce_error = CPL_FALSE; read_must_produce_error = CPL_FALSE; @@ -469,11 +456,8 @@ dup2_must_produce_error = CPL_FALSE; /* Mockup the python command that will just echo the input to output. */ - mock_python( - "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD) - " >&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - ); + mock_python("#!/bin/sh\n" + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " >&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n"); /* Simulate a failure in the write() function and check error handling. */ write_must_produce_error = CPL_TRUE; @@ -510,7 +494,8 @@ close_must_produce_error = CPL_FALSE; } -static void test_stop_python_interpreter(void) +static void +test_stop_python_interpreter(void) { close_must_produce_error = CPL_FALSE; pipe_must_produce_error = CPL_FALSE; @@ -528,12 +513,10 @@ int input = dup(0); int output = dup(1); pid_t pid = fork(); - if (pid == 0) - { + if (pid == 0) { exit(EXIT_SUCCESS); } - else - { + else { cpl_test_eq_error(stop_python_interpreter(pid, input, output), CPL_ERROR_NONE); } @@ -545,25 +528,24 @@ input = dup(0); output = dup(1); pid = fork(); - if (pid == 0) - { + if (pid == 0) { sleep(10); exit(EXIT_FAILURE); } - else - { + else { cpl_test_assert(kill(pid, SIGTERM) == 0); cpl_test_eq_error(stop_python_interpreter(pid, input, output), CPL_ERROR_FILE_IO); } } -static void test_pipe_read_write(void) +static void +test_pipe_read_write(void) { int fildes[2]; - const char * input = "some data"; - char * output = NULL; - char * hugeinput = NULL; + const char *input = "some data"; + char *output = NULL; + char *hugeinput = NULL; int hugesize = 0; int n = 0; pid_t pid = -1; @@ -582,20 +564,19 @@ write_nbyte_limit = -1; /* Prepare a 32 MB input data buffer for some of the following tests. */ - hugesize = 32*1024*1024; + hugesize = 32 * 1024 * 1024; hugeinput = cpl_malloc(hugesize); - const char * pattern = "0123456789abcdef"; - for (n = 0; n < hugesize; ++n) - { + const char *pattern = "0123456789abcdef"; + for (n = 0; n < hugesize; ++n) { hugeinput[n] = pattern[n % 16]; } - hugeinput[hugesize-1] = '\0'; + hugeinput[hugesize - 1] = '\0'; /* Test that writing to a Unix pipe succeeds. */ cpl_test_assert(pipe(fildes) == 0); cpl_test_eq_error(write_to_pipe(fildes[1], input, strlen(input)), CPL_ERROR_NONE); - (void) close(fildes[1]); + (void)close(fildes[1]); /* Test that reading from the other end succeeds and that we get the same result as what was written to the pipe. */ @@ -604,7 +585,7 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_eq_string(input, output); free(output); - (void) close(fildes[0]); + (void)close(fildes[0]); /* Test a read write cycle if we only allow one byte to be written or read at a time. */ @@ -613,13 +594,13 @@ cpl_test_assert(pipe(fildes) == 0); cpl_test_eq_error(write_to_pipe(fildes[1], input, strlen(input)), CPL_ERROR_NONE); - (void) close(fildes[1]); + (void)close(fildes[1]); output = read_from_pipe(fildes[0]); cpl_test_nonnull(output); cpl_test_error(CPL_ERROR_NONE); cpl_test_eq_string(input, output); free(output); - (void) close(fildes[0]); + (void)close(fildes[0]); read_nbyte_limit = -1; write_nbyte_limit = -1; @@ -629,13 +610,13 @@ cpl_test_assert(pipe(fildes) == 0); cpl_test_eq_error(write_to_pipe(fildes[1], input, strlen(input)), CPL_ERROR_NONE); - (void) close(fildes[1]); + (void)close(fildes[1]); output = read_from_pipe(fildes[0]); cpl_test_nonnull(output); cpl_test_error(CPL_ERROR_NONE); cpl_test_eq_string(input, output); free(output); - (void) close(fildes[0]); + (void)close(fildes[0]); read_nbyte_limit = -1; write_nbyte_limit = -1; @@ -646,7 +627,7 @@ write_call_countdown = 0; cpl_test_eq_error(write_to_pipe(fildes[1], input, strlen(input)), CPL_ERROR_FILE_IO); - (void) close(fildes[1]); + (void)close(fildes[1]); write_must_produce_error = CPL_FALSE; /* Test error handling if read() fails. */ @@ -655,7 +636,7 @@ read_call_countdown = 0; cpl_test_null(read_from_pipe(fildes[0])); cpl_test_error(CPL_ERROR_FILE_IO); - (void) close(fildes[0]); + (void)close(fildes[0]); read_must_produce_error = CPL_FALSE; /* Simulate signal interruptions in write() calls and see that writing to @@ -666,7 +647,7 @@ write_call_countdown = 2; cpl_test_eq_error(write_to_pipe(fildes[1], input, strlen(input)), CPL_ERROR_NONE); - (void) close(fildes[1]); + (void)close(fildes[1]); write_must_produce_error = CPL_FALSE; /* Simulate interruptions for read() and see that read_from_pipe still @@ -679,18 +660,18 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_eq_string(input, output); free(output); - (void) close(fildes[0]); + (void)close(fildes[0]); read_must_produce_error = CPL_FALSE; /* Test error handling in read_from_pipe if malloc() fails. */ cpl_test_assert(pipe(fildes) == 0); - cpl_test_assert(write_to_pipe(fildes[1], input, strlen(input)) - == CPL_ERROR_NONE); - (void) close(fildes[1]); + cpl_test_assert(write_to_pipe(fildes[1], input, strlen(input)) == + CPL_ERROR_NONE); + (void)close(fildes[1]); malloc_must_produce_error = CPL_TRUE; cpl_test_null(read_from_pipe(fildes[0])); cpl_test_error(CPL_ERROR_FILE_IO); - (void) close(fildes[0]); + (void)close(fildes[0]); malloc_must_produce_error = CPL_FALSE; /* Test error handling in read_from_pipe if realloc() fails. Note that @@ -699,33 +680,31 @@ exactly the number of bytes read, and also for huge input when it is called to increase the internal buffer. */ cpl_test_assert(pipe(fildes) == 0); - cpl_test_assert(write_to_pipe(fildes[1], input, strlen(input)) - == CPL_ERROR_NONE); - (void) close(fildes[1]); + cpl_test_assert(write_to_pipe(fildes[1], input, strlen(input)) == + CPL_ERROR_NONE); + (void)close(fildes[1]); realloc_must_produce_error = CPL_TRUE; cpl_test_null(read_from_pipe(fildes[0])); cpl_test_error(CPL_ERROR_FILE_IO); - (void) close(fildes[0]); + (void)close(fildes[0]); realloc_must_produce_error = CPL_FALSE; cpl_test_assert(pipe(fildes) == 0); /* NOTE: We have to run in a separate process to avoid a deadlock, since something has to read from the pipe so that it does not go full. */ pid = fork(); - if (pid == 0) - { - (void) close(fildes[0]); + if (pid == 0) { + (void)close(fildes[0]); write_to_pipe(fildes[1], hugeinput, strlen(hugeinput)); - (void) close(fildes[1]); + (void)close(fildes[1]); exit(EXIT_SUCCESS); } - else - { - (void) close(fildes[1]); + else { + (void)close(fildes[1]); realloc_must_produce_error = CPL_TRUE; cpl_test_null(read_from_pipe(fildes[0])); cpl_test_error(CPL_ERROR_FILE_IO); - (void) close(fildes[0]); + (void)close(fildes[0]); realloc_must_produce_error = CPL_FALSE; wait(&status); } @@ -734,22 +713,20 @@ correct output. */ cpl_test_assert(pipe(fildes) == 0); pid = fork(); - if (pid == 0) - { - (void) close(fildes[0]); + if (pid == 0) { + (void)close(fildes[0]); write_to_pipe(fildes[1], hugeinput, strlen(hugeinput)); - (void) close(fildes[1]); + (void)close(fildes[1]); exit(EXIT_SUCCESS); } - else - { - (void) close(fildes[1]); + else { + (void)close(fildes[1]); output = read_from_pipe(fildes[0]); cpl_test_nonnull(output); cpl_test_error(CPL_ERROR_NONE); cpl_test_eq_string(hugeinput, output); free(output); - (void) close(fildes[0]); + (void)close(fildes[0]); wait(&status); } @@ -759,10 +736,11 @@ #else /* ENABLE_PYTHON_RECIPES */ -int main(void) +int +main(void) { /* Indicate to the automake test runner that the tests are skipped. */ return 77; } -#endif /* ENABLE_PYTHON_RECIPES */ +#endif /* ENABLE_PYTHON_RECIPES */ diff -Nru esorex-3.13.5+ds/src/tests/esorex_python_errors4-test.c esorex-3.13.6+ds/src/tests/esorex_python_errors4-test.c --- esorex-3.13.5+ds/src/tests/esorex_python_errors4-test.c 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/tests/esorex_python_errors4-test.c 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2017 European Southern Observatory + * Copyright (C) 2017-2022 European Southern Observatory * * 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 @@ -48,10 +48,11 @@ int errno_value_to_use = EIO; -int _overloaded_execlp(const char *file, const char *arg, ...) +int +_overloaded_execlp(const char *file, const char *arg, ...) { - (void) file; - (void) arg; + (void)file; + (void)arg; errno = errno_value_to_use; return -1; } @@ -72,7 +73,8 @@ Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -88,7 +90,8 @@ Private functions -----------------------------------------------------------------------------*/ -static void test_start_python_interpreter(void) +static void +test_start_python_interpreter(void) { /* Test edge case where execlp() fails. In this case the function start_python_interpreter should not be able to detect the error since @@ -100,7 +103,8 @@ CPL_ERROR_NONE); } -static void test_run_python_command(void) +static void +test_run_python_command(void) { /* Test edge case where execlp() fails. The run_python_command function should detect the error. */ @@ -111,10 +115,11 @@ #else /* ENABLE_PYTHON_RECIPES */ -int main(void) +int +main(void) { /* Indicate to the automake test runner that the tests are skipped. */ return 77; } -#endif /* ENABLE_PYTHON_RECIPES */ +#endif /* ENABLE_PYTHON_RECIPES */ diff -Nru esorex-3.13.5+ds/src/tests/esorex_python_internal-test.c esorex-3.13.6+ds/src/tests/esorex_python_internal-test.c --- esorex-3.13.5+ds/src/tests/esorex_python_internal-test.c 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/tests/esorex_python_internal-test.c 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2017 European Southern Observatory + * Copyright (C) 2017-2022 European Southern Observatory * * 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 @@ -37,7 +37,7 @@ Private function prototypes -----------------------------------------------------------------------------*/ -static void mock_python(const char * script); +static void mock_python(const char *script); static void test_plugin_initialize(void); static void test_plugin_execute(void); static void test_update_plugin(void); @@ -49,13 +49,14 @@ Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); /* Update the PATH environment variable to make sure we pick up our mock python script. */ - const char * path = "./mock_python_internal_test:/usr/bin:/bin"; + const char *path = "./mock_python_internal_test:/usr/bin:/bin"; cpl_test_assert(setenv("PATH", path, 0x1) == 0); /* Insert tests below */ @@ -79,7 +80,8 @@ * interpreter process. The input is the shell script to write to the python * script file. */ -static void mock_python(const char * script) +static void +mock_python(const char *script) { /* Do not overwrite the python script if a previous test failed. This will make it easier to debug by having the failing script available. */ @@ -87,32 +89,31 @@ /* Create the directory for the python script. We put this in its own directory so that this unit test can be made concurrency safe. */ - if (mkdir("./mock_python_internal_test", 0777) != 0) - { + if (mkdir("./mock_python_internal_test", 0777) != 0) { cpl_test_assert(errno == EEXIST); } - FILE* file = fopen("./mock_python_internal_test/python", "w"); + FILE *file = fopen("./mock_python_internal_test/python", "w"); cpl_test_assert(file != NULL); size_t bytes_to_write = strlen(script); size_t bytes_written = fwrite(script, sizeof(char), bytes_to_write, file); cpl_test_assert(bytes_written == bytes_to_write); int fclose_result = fclose(file); cpl_test_assert(fclose_result == 0); - mode_t mode = S_IRUSR | S_IWUSR | S_IXUSR | - S_IRGRP | S_IXGRP | - S_IROTH | S_IXOTH; + mode_t mode = + S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; cpl_test_assert(chmod("./mock_python_internal_test/python", mode) == 0); } -static void test_plugin_initialize(void) +static void +test_plugin_initialize(void) { - char * module_name = NULL; - cpl_recipe * recipe = NULL; - cpl_recipe * recipe2 = NULL; - cpl_recipe2 * recipe_v2 = NULL; - cpl_recipe2 * recipe2_v2 = NULL; - cpl_pluginlist * pluginlist = NULL; + char *module_name = NULL; + cpl_recipe *recipe = NULL; + cpl_recipe *recipe2 = NULL; + cpl_recipe2 *recipe_v2 = NULL; + cpl_recipe2 *recipe2_v2 = NULL; + cpl_pluginlist *pluginlist = NULL; /* Test an edge case where plugin_initialize is given a plugin type that it cannot handle. @@ -120,21 +121,21 @@ the normal case just before a call to the function under test. Only then can we make the invocation to perform the actual test. */ - recipe = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); + recipe = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); cpl_test_assert(cpl_plugin_init(&recipe->interface, CPL_PLUGIN_API, 1, CPL_PLUGIN_TYPE_NONE, "test_recipe", "simple test recipe", "description ...", "some author", "author@eso.org", - "copyright ...", NULL, NULL, NULL) - == CPL_ERROR_NONE); - recipe2 = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); - cpl_test_assert(cpl_plugin_copy(&recipe2->interface, &recipe->interface) - == CPL_ERROR_NONE); + "copyright ...", NULL, NULL, + NULL) == CPL_ERROR_NONE); + recipe2 = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); + cpl_test_assert(cpl_plugin_copy(&recipe2->interface, &recipe->interface) == + CPL_ERROR_NONE); pluginlist = cpl_pluginlist_new(); cpl_test_assert(pluginlist != NULL); - cpl_test_assert(cpl_pluginlist_append(pluginlist, &recipe->interface) - == CPL_ERROR_NONE); + cpl_test_assert(cpl_pluginlist_append(pluginlist, &recipe->interface) == + CPL_ERROR_NONE); module_list = cx_map_new(string_key_compare, cpl_free, (cx_free_func)er_json_pluginlist_delete); @@ -158,21 +159,21 @@ /* Test an edge case where plugin_initialize is given a plugin that has no parameters structure set. */ - recipe = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); + recipe = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); cpl_test_assert(cpl_plugin_init(&recipe->interface, CPL_PLUGIN_API, 1, CPL_PLUGIN_TYPE_RECIPE, "test_recipe", "simple test recipe", "description ...", "some author", "author@eso.org", - "copyright ...", NULL, NULL, NULL) - == CPL_ERROR_NONE); - recipe2 = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); - cpl_test_assert(cpl_plugin_copy(&recipe2->interface, &recipe->interface) - == CPL_ERROR_NONE); + "copyright ...", NULL, NULL, + NULL) == CPL_ERROR_NONE); + recipe2 = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); + cpl_test_assert(cpl_plugin_copy(&recipe2->interface, &recipe->interface) == + CPL_ERROR_NONE); pluginlist = cpl_pluginlist_new(); cpl_test_assert(pluginlist != NULL); - cpl_test_assert(cpl_pluginlist_append(pluginlist, &recipe->interface) - == CPL_ERROR_NONE); + cpl_test_assert(cpl_pluginlist_append(pluginlist, &recipe->interface) == + CPL_ERROR_NONE); module_list = cx_map_new(string_key_compare, cpl_free, (cx_free_func)er_json_pluginlist_delete); @@ -194,23 +195,23 @@ /* Check an edge case when a recipe v2 plugin is given a plugin with an empty recipe config. */ - recipe_v2 = (cpl_recipe2 *) cpl_calloc(1, sizeof(cpl_recipe2)); + recipe_v2 = (cpl_recipe2 *)cpl_calloc(1, sizeof(cpl_recipe2)); cpl_test_assert(cpl_plugin_init(&recipe_v2->base.interface, CPL_PLUGIN_API, 1, CPL_PLUGIN_TYPE_RECIPE_V2, "test_recipe", "simple test recipe", "description ...", "some author", "author@eso.org", - "copyright ...", NULL, NULL, NULL) - == CPL_ERROR_NONE); - recipe2_v2 = (cpl_recipe2 *) cpl_calloc(1, sizeof(cpl_recipe2)); + "copyright ...", NULL, NULL, + NULL) == CPL_ERROR_NONE); + recipe2_v2 = (cpl_recipe2 *)cpl_calloc(1, sizeof(cpl_recipe2)); cpl_test_assert(cpl_plugin_copy(&recipe2_v2->base.interface, - &recipe_v2->base.interface) - == CPL_ERROR_NONE); + &recipe_v2->base.interface) == + CPL_ERROR_NONE); pluginlist = cpl_pluginlist_new(); cpl_test_assert(pluginlist != NULL); - cpl_test_assert(cpl_pluginlist_append(pluginlist, - &recipe_v2->base.interface) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_pluginlist_append(pluginlist, &recipe_v2->base.interface) == + CPL_ERROR_NONE); module_list = cx_map_new(string_key_compare, cpl_free, (cx_free_func)er_json_pluginlist_delete); @@ -232,13 +233,14 @@ er_python_cleanup(); } -static void test_plugin_execute(void) +static void +test_plugin_execute(void) { - char * module_name = NULL; - cpl_recipe * recipe = NULL; - cpl_recipe * recipe2 = NULL; - cpl_pluginlist * pluginlist = NULL; - cpl_parameter * param = NULL; + char *module_name = NULL; + cpl_recipe *recipe = NULL; + cpl_recipe *recipe2 = NULL; + cpl_pluginlist *pluginlist = NULL; + cpl_parameter *param = NULL; /* Test an edge case where the plugin_execute function is given a plugin type that they cannot handle. @@ -246,21 +248,21 @@ the normal case just before a call to the functions under test. Only then can we make the invocations to perform the actual test. */ - recipe = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); + recipe = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); cpl_test_assert(cpl_plugin_init(&recipe->interface, CPL_PLUGIN_API, 1, CPL_PLUGIN_TYPE_NONE, "test_recipe", "simple test recipe", "description ...", "some author", "author@eso.org", - "copyright ...", NULL, NULL, NULL) - == CPL_ERROR_NONE); - recipe2 = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); - cpl_test_assert(cpl_plugin_copy(&recipe2->interface, &recipe->interface) - == CPL_ERROR_NONE); + "copyright ...", NULL, NULL, + NULL) == CPL_ERROR_NONE); + recipe2 = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); + cpl_test_assert(cpl_plugin_copy(&recipe2->interface, &recipe->interface) == + CPL_ERROR_NONE); pluginlist = cpl_pluginlist_new(); cpl_test_assert(pluginlist != NULL); - cpl_test_assert(cpl_pluginlist_append(pluginlist, &recipe->interface) - == CPL_ERROR_NONE); + cpl_test_assert(cpl_pluginlist_append(pluginlist, &recipe->interface) == + CPL_ERROR_NONE); module_list = cx_map_new(string_key_compare, cpl_free, (cx_free_func)er_json_pluginlist_delete); @@ -284,21 +286,21 @@ /* Test an edge case where the plugin_execute function is given a plugin that has no parameters structure set. */ - recipe = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); + recipe = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); cpl_test_assert(cpl_plugin_init(&recipe->interface, CPL_PLUGIN_API, 1, CPL_PLUGIN_TYPE_RECIPE, "test_recipe", "simple test recipe", "description ...", "some author", "author@eso.org", - "copyright ...", NULL, NULL, NULL) - == CPL_ERROR_NONE); - recipe2 = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); - cpl_test_assert(cpl_plugin_copy(&recipe2->interface, &recipe->interface) - == CPL_ERROR_NONE); + "copyright ...", NULL, NULL, + NULL) == CPL_ERROR_NONE); + recipe2 = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); + cpl_test_assert(cpl_plugin_copy(&recipe2->interface, &recipe->interface) == + CPL_ERROR_NONE); pluginlist = cpl_pluginlist_new(); cpl_test_assert(pluginlist != NULL); - cpl_test_assert(cpl_pluginlist_append(pluginlist, &recipe->interface) - == CPL_ERROR_NONE); + cpl_test_assert(cpl_pluginlist_append(pluginlist, &recipe->interface) == + CPL_ERROR_NONE); module_list = cx_map_new(string_key_compare, cpl_free, (cx_free_func)er_json_pluginlist_delete); @@ -320,19 +322,19 @@ /* Test error handling of plugin_execute if the __class__ parameter in the simulate plugin is missing. */ - recipe = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); + recipe = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); cpl_test_assert(cpl_plugin_init(&recipe->interface, CPL_PLUGIN_API, 1, CPL_PLUGIN_TYPE_RECIPE, "test_recipe", "simple test recipe", "description ...", "some author", "author@eso.org", - "copyright ...", NULL, NULL, NULL) - == CPL_ERROR_NONE); + "copyright ...", NULL, NULL, + NULL) == CPL_ERROR_NONE); recipe->parameters = cpl_parameterlist_new(); pluginlist = cpl_pluginlist_new(); cpl_test_assert(pluginlist != NULL); - cpl_test_assert(cpl_pluginlist_append(pluginlist, &recipe->interface) - == CPL_ERROR_NONE); + cpl_test_assert(cpl_pluginlist_append(pluginlist, &recipe->interface) == + CPL_ERROR_NONE); module_list = cx_map_new(string_key_compare, cpl_free, (cx_free_func)er_json_pluginlist_delete); @@ -344,10 +346,9 @@ cpl_test_assert(er_python_select_module("test.py") == CPL_ERROR_NONE); - recipe2 = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); - cpl_test_assert(cpl_plugin_copy(&recipe2->interface, - &recipe->interface) - == CPL_ERROR_NONE); + recipe2 = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); + cpl_test_assert(cpl_plugin_copy(&recipe2->interface, &recipe->interface) == + CPL_ERROR_NONE); cpl_test_eq_error(plugin_execute(&recipe2->interface), CPL_ERROR_DATA_NOT_FOUND); @@ -361,25 +362,25 @@ /* Test error handling of plugin_execute if the __class__ parameter in the simulate plugin is wrong. */ - recipe = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); + recipe = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); cpl_test_assert(cpl_plugin_init(&recipe->interface, CPL_PLUGIN_API, 1, CPL_PLUGIN_TYPE_RECIPE, "test_recipe", "simple test recipe", "description ...", "some author", "author@eso.org", - "copyright ...", NULL, NULL, NULL) - == CPL_ERROR_NONE); + "copyright ...", NULL, NULL, + NULL) == CPL_ERROR_NONE); recipe->parameters = cpl_parameterlist_new(); param = cpl_parameter_new_value("__class__", CPL_TYPE_INT, "Python class name", "__python__", 123); cpl_test_assert(param != NULL); - cpl_test_assert(cpl_parameterlist_append(recipe->parameters, param) - == CPL_ERROR_NONE); + cpl_test_assert(cpl_parameterlist_append(recipe->parameters, param) == + CPL_ERROR_NONE); pluginlist = cpl_pluginlist_new(); cpl_test_assert(pluginlist != NULL); - cpl_test_assert(cpl_pluginlist_append(pluginlist, &recipe->interface) - == CPL_ERROR_NONE); + cpl_test_assert(cpl_pluginlist_append(pluginlist, &recipe->interface) == + CPL_ERROR_NONE); module_list = cx_map_new(string_key_compare, cpl_free, (cx_free_func)er_json_pluginlist_delete); @@ -391,10 +392,9 @@ cpl_test_assert(er_python_select_module("test.py") == CPL_ERROR_NONE); - recipe2 = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); - cpl_test_assert(cpl_plugin_copy(&recipe2->interface, - &recipe->interface) - == CPL_ERROR_NONE); + recipe2 = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); + cpl_test_assert(cpl_plugin_copy(&recipe2->interface, &recipe->interface) == + CPL_ERROR_NONE); cpl_test_eq_error(plugin_initialize(&recipe2->interface), CPL_ERROR_NONE); cpl_test_eq_error(plugin_execute(&recipe2->interface), @@ -408,29 +408,30 @@ er_python_cleanup(); } -static void test_update_plugin(void) +static void +test_update_plugin(void) { - cpl_recipe * recipe = NULL; - cpl_recipe * recipe2 = NULL; - cpl_frame * frame = NULL; + cpl_recipe *recipe = NULL; + cpl_recipe *recipe2 = NULL; + cpl_frame *frame = NULL; - recipe = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); + recipe = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); cpl_test_assert(cpl_plugin_init(&recipe->interface, CPL_PLUGIN_API, 1, CPL_PLUGIN_TYPE_RECIPE, "test_recipe", "simple test recipe", "description ...", "some author", "author@eso.org", - "copyright ...", NULL, NULL, NULL) - == CPL_ERROR_NONE); - recipe2 = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); - cpl_test_assert(cpl_plugin_copy(&recipe2->interface, &recipe->interface) - == CPL_ERROR_NONE); + "copyright ...", NULL, NULL, + NULL) == CPL_ERROR_NONE); + recipe2 = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); + cpl_test_assert(cpl_plugin_copy(&recipe2->interface, &recipe->interface) == + CPL_ERROR_NONE); /* Test error handling if update_plugin is given a plugin with the wrong API version. */ recipe2->interface.api = 0; cpl_test_eq_error(update_plugin(&recipe->interface, &recipe2->interface), CPL_ERROR_TYPE_MISMATCH); - recipe2->interface.api = recipe->interface.api; /* restore value. */ + recipe2->interface.api = recipe->interface.api; /* restore value. */ /* Test error handling if update_plugin is given a plugin with a version number that does not match. */ @@ -444,15 +445,15 @@ recipe2->interface.type = CPL_PLUGIN_TYPE_RECIPE_V2; cpl_test_eq_error(update_plugin(&recipe->interface, &recipe2->interface), CPL_ERROR_TYPE_MISMATCH); - recipe2->interface.type = recipe->interface.type; /* restore value. */ + recipe2->interface.type = recipe->interface.type; /* restore value. */ /* Test error handling if update_plugin is given a plugin with a name that does not match. */ - const char * oldname = recipe2->interface.name; + const char *oldname = recipe2->interface.name; recipe2->interface.name = "something"; cpl_test_eq_error(update_plugin(&recipe->interface, &recipe2->interface), CPL_ERROR_TYPE_MISMATCH); - recipe2->interface.name = oldname; /* restore value. */ + recipe2->interface.name = oldname; /* restore value. */ /* Test error handling if update_plugin is given a plugins with a type that it cannot handle. */ @@ -487,33 +488,33 @@ cpl_test_assert(recipe->frames != NULL); frame = cpl_frame_new(); cpl_test_assert(frame != NULL); - cpl_test_assert(cpl_frame_set_filename(frame, "input.fits") - == CPL_ERROR_NONE); + cpl_test_assert(cpl_frame_set_filename(frame, "input.fits") == + CPL_ERROR_NONE); cpl_test_assert(cpl_frame_set_tag(frame, "RAW") == CPL_ERROR_NONE); - cpl_test_assert(cpl_frame_set_type(frame, CPL_FRAME_TYPE_NONE) - == CPL_ERROR_NONE); - cpl_test_assert(cpl_frame_set_group(frame, CPL_FRAME_GROUP_NONE) - == CPL_ERROR_NONE); - cpl_test_assert(cpl_frame_set_level(frame, CPL_FRAME_LEVEL_NONE) - == CPL_ERROR_NONE); - cpl_test_assert(cpl_frameset_insert(recipe->frames, frame) - == CPL_ERROR_NONE); + cpl_test_assert(cpl_frame_set_type(frame, CPL_FRAME_TYPE_NONE) == + CPL_ERROR_NONE); + cpl_test_assert(cpl_frame_set_group(frame, CPL_FRAME_GROUP_NONE) == + CPL_ERROR_NONE); + cpl_test_assert(cpl_frame_set_level(frame, CPL_FRAME_LEVEL_NONE) == + CPL_ERROR_NONE); + cpl_test_assert(cpl_frameset_insert(recipe->frames, frame) == + CPL_ERROR_NONE); recipe2->frames = cpl_frameset_new(); cpl_test_assert(recipe2->frames != NULL); frame = cpl_frame_new(); cpl_test_assert(frame != NULL); - cpl_test_assert(cpl_frame_set_filename(frame, "input_moved.fits") - == CPL_ERROR_NONE); + cpl_test_assert(cpl_frame_set_filename(frame, "input_moved.fits") == + CPL_ERROR_NONE); cpl_test_assert(cpl_frame_set_tag(frame, "RAW2") == CPL_ERROR_NONE); - cpl_test_assert(cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE) - == CPL_ERROR_NONE); - cpl_test_assert(cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW) - == CPL_ERROR_NONE); - cpl_test_assert(cpl_frame_set_level(frame, CPL_FRAME_LEVEL_FINAL) - == CPL_ERROR_NONE); - cpl_test_assert(cpl_frameset_insert(recipe2->frames, frame) - == CPL_ERROR_NONE); + cpl_test_assert(cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE) == + CPL_ERROR_NONE); + cpl_test_assert(cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW) == + CPL_ERROR_NONE); + cpl_test_assert(cpl_frame_set_level(frame, CPL_FRAME_LEVEL_FINAL) == + CPL_ERROR_NONE); + cpl_test_assert(cpl_frameset_insert(recipe2->frames, frame) == + CPL_ERROR_NONE); cpl_test_eq_error(update_plugin(&recipe->interface, &recipe2->interface), CPL_ERROR_NONE); @@ -524,7 +525,8 @@ cpl_plugin_delete(&recipe2->interface); } -static void test_plugin_compare(void) +static void +test_plugin_compare(void) { /* Test that the comparison function returns the correct results. */ cpl_plugin a, b; @@ -603,16 +605,14 @@ cpl_test_eq(plugin_compare(&a, &b), 0); } -static void test_run_python_command(void) +static void +test_run_python_command(void) { - char * output = NULL; + char *output = NULL; /* Mockup the python command that will just echo the input to output. */ - mock_python( - "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD) - " >&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - ); + mock_python("#!/bin/sh\n" + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " >&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n"); /* Test for success of run_python_command when given an empty input and the simple echoing python mockup script. */ @@ -628,15 +628,14 @@ free(output); /* Test error handling if the python mockup exits with an error code. */ - mock_python( - "#!/bin/sh\n" - "exit 99\n" - ); + mock_python("#!/bin/sh\n" + "exit 99\n"); cpl_test_null(run_python_command("x=1", "some data")); cpl_test_error(CPL_ERROR_FILE_IO); } -static void test_stop_python_interpreter(void) +static void +test_stop_python_interpreter(void) { /* Test error handling for edge case where we try stop the python interpreter when the child process was never started. */ @@ -647,17 +646,15 @@ the process down. i.e. avoid waiting for the process forever. An error code will be set since the process did not terminate normally. */ - mock_python( - "#!/bin/sh\n" - "sleep 601\n" - ); + mock_python("#!/bin/sh\n" + "sleep 601\n"); int start_time = time(NULL); pid_t pid; int input, output; - cpl_test_assert(start_python_interpreter("x=1", &pid, &input, &output) - == CPL_ERROR_NONE); + cpl_test_assert(start_python_interpreter("x=1", &pid, &input, &output) == + CPL_ERROR_NONE); cpl_test_eq_error(stop_python_interpreter(pid, input, output), CPL_ERROR_FILE_IO); @@ -668,10 +665,11 @@ #else /* ENABLE_PYTHON_RECIPES */ -int main(void) +int +main(void) { /* Indicate to the automake test runner that the tests are skipped. */ return 77; } -#endif /* ENABLE_PYTHON_RECIPES */ +#endif /* ENABLE_PYTHON_RECIPES */ diff -Nru esorex-3.13.5+ds/src/tests/esorex_python_recipe-test.c esorex-3.13.6+ds/src/tests/esorex_python_recipe-test.c --- esorex-3.13.5+ds/src/tests/esorex_python_recipe-test.c 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/tests/esorex_python_recipe-test.c 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2017 European Southern Observatory + * Copyright (C) 2017-2022 European Southern Observatory * * 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 @@ -37,24 +37,24 @@ #include #ifndef TEST_RECIPE_DIR -#define TEST_RECIPE_DIR "." +#define TEST_RECIPE_DIR "." #endif /*----------------------------------------------------------------------------- Private function prototypes -----------------------------------------------------------------------------*/ -static void write_file(const char * filename, const char * text); -static char * read_file(const char * filename); +static void write_file(const char *filename, const char *text); +static char *read_file(const char *filename); /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { - if (system("python --version > /dev/null") != 0) - { + if (system("python --version > /dev/null") != 0) { /* Indicate this unit test is skipped if Python is not available. */ return 77; } @@ -62,38 +62,37 @@ cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); cpl_test_assert(argc >= 1); - char * argv0 = cpl_strdup(argv[0]); - const char * dir = dirname(argv0); + char *argv0 = cpl_strdup(argv[0]); + const char *dir = dirname(argv0); /* Create a dummy input file that contains the integer 12. */ - char * filename = cpl_sprintf("%s/python_recipe_test_input.fits", dir); + char *filename = cpl_sprintf("%s/python_recipe_test_input.fits", dir); write_file(filename, "12\n"); cpl_free(filename); /* Create the Set-of-Frames file. */ filename = cpl_sprintf("%s/python_recipe_test.sof", dir); - char * value = cpl_sprintf("%s/python_recipe_test_input.fits RAW\n", dir); + char *value = cpl_sprintf("%s/python_recipe_test_input.fits RAW\n", dir); write_file(filename, value); cpl_free(value); cpl_free(filename); /* Prepare the command to execute esorex */ - char * esorex_command = cpl_sprintf( - "%s/../esorex --suppress-prefix=TRUE --recipe-dir=%s" - " testrecipe --par1=7 %s/python_recipe_test.sof" - " > %s/python_recipe_test_recipe_output.log", - dir, TEST_RECIPE_DIR, dir, dir - ); + char *esorex_command = + cpl_sprintf("%s/../esorex --suppress-prefix=TRUE --recipe-dir=%s" + " testrecipe --par1=7 %s/python_recipe_test.sof" + " > %s/python_recipe_test_recipe_output.log", + dir, TEST_RECIPE_DIR, dir, dir); cpl_test_eq(system(esorex_command), 0); /* Read the console output from EsoRex and the output file produced by the recipe. */ filename = cpl_sprintf("%s/python_recipe_test_recipe_output.log", dir); - char * console_output = read_file(filename); + char *console_output = read_file(filename); cpl_test_assert(console_output != NULL); cpl_free(filename); filename = cpl_sprintf("%s/python_recipe_test_output.fits", dir); - char * output = read_file(filename); + char *output = read_file(filename); cpl_test_assert(output != NULL); cpl_free(filename); @@ -118,9 +117,10 @@ /* * This function will write the given text to a file. */ -static void write_file(const char * filename, const char * text) +static void +write_file(const char *filename, const char *text) { - FILE* file = fopen(filename, "w"); + FILE *file = fopen(filename, "w"); cpl_test_assert(file != NULL); size_t bytes_to_write = strlen(text); size_t bytes_written = fwrite(text, sizeof(char), bytes_to_write, file); @@ -133,26 +133,28 @@ * Read a text file and return the contents as a string. * The caller must free the returned string with cpl_free(). */ -static char * read_file(const char * filename) +static char * +read_file(const char *filename) { - size_t buffersize = 1024*4; - char * buffer = cpl_malloc(buffersize); - FILE* file = fopen(filename, "r"); + size_t buffersize = 1024 * 4; + char *buffer = cpl_malloc(buffersize); + FILE *file = fopen(filename, "r"); cpl_test_assert(file != NULL); - size_t bytes_read = fread(buffer, sizeof(char), buffersize-1, file); + size_t bytes_read = fread(buffer, sizeof(char), buffersize - 1, file); int fclose_result = fclose(file); cpl_test_assert(fclose_result == 0); - buffer[bytes_read] = '\0'; /* Make sure to null terminate the string. */ + buffer[bytes_read] = '\0'; /* Make sure to null terminate the string. */ return buffer; } #else /* ENABLE_PYTHON_RECIPES */ -int main(void) +int +main(void) { /* Indicate to the automake test runner that the tests are skipped. */ return 77; } -#endif /* ENABLE_PYTHON_RECIPES */ +#endif /* ENABLE_PYTHON_RECIPES */ diff -Nru esorex-3.13.5+ds/src/tests/esorex_python-test.c esorex-3.13.6+ds/src/tests/esorex_python-test.c --- esorex-3.13.5+ds/src/tests/esorex_python-test.c 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/tests/esorex_python-test.c 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2017 European Southern Observatory + * Copyright (C) 2017-2022 European Southern Observatory * * 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 @@ -37,14 +37,14 @@ Defines -----------------------------------------------------------------------------*/ -#define PYTHON_INPUT_FD 3 -#define PYTHON_OUTPUT_FD 4 +#define PYTHON_INPUT_FD 3 +#define PYTHON_OUTPUT_FD 4 /*----------------------------------------------------------------------------- Private function prototypes -----------------------------------------------------------------------------*/ -static void mock_python(const char * script); +static void mock_python(const char *script); static void test_error_from_interpreter(void); static void test_load_modules_function(void); static void test_module_set_function(void); @@ -56,13 +56,14 @@ Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); /* Update the PATH environment variable to make sure we pick up our mock python script. */ - const char * path = "./mock_python_test:/usr/bin:/bin"; + const char *path = "./mock_python_test:/usr/bin:/bin"; cpl_test_assert(setenv("PATH", path, 0x1) == 0); /* Insert tests below */ @@ -86,7 +87,8 @@ * interpreter process. The input is the shell script to write to the python * script file. */ -static void mock_python(const char * script) +static void +mock_python(const char *script) { /* Do not overwrite the python script if a previous test failed. This will make it easier to debug by having the failing script available. */ @@ -94,28 +96,27 @@ /* Create the directory for the python script. We put this in its own directory so that this unit test can be made concurrency safe. */ - if (mkdir("./mock_python_test", 0777) != 0) - { + if (mkdir("./mock_python_test", 0777) != 0) { cpl_test_assert(errno == EEXIST); } - FILE* file = fopen("./mock_python_test/python", "w"); + FILE *file = fopen("./mock_python_test/python", "w"); cpl_test_assert(file != NULL); size_t bytes_to_write = strlen(script); size_t bytes_written = fwrite(script, sizeof(char), bytes_to_write, file); cpl_test_assert(bytes_written == bytes_to_write); int fclose_result = fclose(file); cpl_test_assert(fclose_result == 0); - mode_t mode = S_IRUSR | S_IWUSR | S_IXUSR | - S_IRGRP | S_IXGRP | - S_IROTH | S_IXOTH; + mode_t mode = + S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; cpl_test_assert(chmod("./mock_python_test/python", mode) == 0); } -static void test_error_from_interpreter(void) +static void +test_error_from_interpreter(void) { /* Test handling of errors from the external mocked up Python process. */ - er_stringarray_t * modulelist = er_stringarray_new(); + er_stringarray_t *modulelist = er_stringarray_new(); cpl_test_assert(modulelist != NULL); er_stringarray_append(modulelist, "./test.py"); @@ -128,9 +129,10 @@ er_stringarray_delete(modulelist); } -static void test_load_modules_function(void) +static void +test_load_modules_function(void) { - er_stringarray_t * modulelist = NULL; + er_stringarray_t *modulelist = NULL; /* Check for success if an empty module list is given. */ modulelist = er_stringarray_new(); @@ -138,11 +140,10 @@ mock_python( "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "{}\n" - "EOF\n" - ); + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "{}\n" + "EOF\n"); cpl_test_eq_error(er_python_load_modules(modulelist), CPL_ERROR_NONE); @@ -160,14 +161,13 @@ mock_python( "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "{}\n" - "EOF\n" - ); + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "{}\n" + "EOF\n"); cpl_test_eq_error(er_python_load_modules(modulelist), CPL_ERROR_NONE); - cpl_test(! er_stringarray_present(modulelist, 0)); + cpl_test(!er_stringarray_present(modulelist, 0)); er_python_cleanup(); er_stringarray_delete(modulelist); @@ -180,43 +180,64 @@ mock_python( "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "{\n" - " \"./test.py\": [\n" - " {\n" - " \"class\": \"testclass\",\n" - " \"name\": \"testrecipe\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin\",\n" - " \"description\": \"description ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [\n" - " {\n" - " \"name\": \"test.par1\",\n" - " \"class\": \"value\",\n" - " \"id\": 0,\n" - " \"description\": \"int param\",\n" - " \"context\": \"test\",\n" - " \"value\": 12,\n" - " \"default\": 5,\n" - " \"present\": false,\n" - " \"tag\": \"myparam\",\n" - " \"cli_enabled\": true,\n" - " \"cli_alias\": \"par1_cli\",\n" - " \"env_enabled\": false,\n" - " \"env_alias\": \"par1_env\",\n" - " \"cfg_enabled\": true,\n" - " \"cfg_alias\": \"par1_cfg\"\n" - " }\n" - " ]\n" - " }\n" - " ]\n" - "}\n" - "EOF\n" - ); + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "{\n" + " \"./test.py\": [\n" + " {\n" + " \"class\": " + "\"testclass\",\n" + " \"name\": " + "\"testrecipe\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test " + "plugin\",\n" + " \"description\": " + "\"description ...\",\n" + " \"author\": \"Some " + "Author\",\n" + " \"email\": " + "\"someone@eso.org\",\n" + " \"copyright\": " + "\"copyright ...\",\n" + " \"parameters\": [\n" + " {\n" + " \"name\": " + "\"test.par1\",\n" + " \"class\": " + "\"value\",\n" + " \"id\": 0,\n" + " " + "\"description\": \"int " + "param\",\n" + " \"context\": " + "\"test\",\n" + " \"value\": " + "12,\n" + " \"default\": " + "5,\n" + " \"present\": " + "false,\n" + " \"tag\": " + "\"myparam\",\n" + " " + "\"cli_enabled\": true,\n" + " \"cli_alias\": " + "\"par1_cli\",\n" + " " + "\"env_enabled\": false,\n" + " \"env_alias\": " + "\"par1_env\",\n" + " " + "\"cfg_enabled\": true,\n" + " \"cfg_alias\": " + "\"par1_cfg\"\n" + " }\n" + " ]\n" + " }\n" + " ]\n" + "}\n" + "EOF\n"); cpl_test_eq_error(er_python_load_modules(modulelist), CPL_ERROR_NONE); cpl_test(er_stringarray_present(modulelist, 0)); @@ -229,13 +250,11 @@ cpl_test_assert(modulelist != NULL); er_stringarray_append(modulelist, "./test.py"); - mock_python( - "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "{ ... , xyz\n" - "EOF\n" - ); + mock_python("#!/bin/sh\n" + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "{ ... , xyz\n" + "EOF\n"); cpl_test_eq_error(er_python_load_modules(modulelist), CPL_ERROR_ILLEGAL_INPUT); @@ -251,17 +270,16 @@ mock_python( "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "{\n" - " \"./test.py\": \"xyz\"\n" - "}\n" - "EOF\n" - ); + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "{\n" + " \"./test.py\": \"xyz\"\n" + "}\n" + "EOF\n"); cpl_test_eq_error(er_python_load_modules(modulelist), CPL_ERROR_ILLEGAL_INPUT); - cpl_test(! er_stringarray_present(modulelist, 0)); + cpl_test(!er_stringarray_present(modulelist, 0)); er_python_cleanup(); er_stringarray_delete(modulelist); @@ -270,13 +288,11 @@ cpl_test_assert(modulelist != NULL); er_stringarray_append(modulelist, "./test.py"); - mock_python( - "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "\"./test.py\"\n" - "EOF\n" - ); + mock_python("#!/bin/sh\n" + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "\"./test.py\"\n" + "EOF\n"); cpl_test_eq_error(er_python_load_modules(modulelist), CPL_ERROR_ILLEGAL_INPUT); @@ -292,19 +308,18 @@ mock_python( "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "{\n" - " \"./test.py\": [\n" - " {\"dummy\": 345}\n" - " ]\n" - "}\n" - "EOF\n" - ); + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "{\n" + " \"./test.py\": [\n" + " {\"dummy\": 345}\n" + " ]\n" + "}\n" + "EOF\n"); cpl_test_eq_error(er_python_load_modules(modulelist), CPL_ERROR_ILLEGAL_INPUT); - cpl_test(! er_stringarray_present(modulelist, 0)); + cpl_test(!er_stringarray_present(modulelist, 0)); er_python_cleanup(); er_stringarray_delete(modulelist); @@ -319,59 +334,81 @@ mock_python( "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "{\n" - " \"./test1.py\": [\n" - " {\n" - " \"class\": \"testclass\",\n" - " \"name\": \"testrecipe\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin\",\n" - " \"description\": \"description ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [\n" - " {\n" - " \"name\": \"test.par1\",\n" - " \"class\": \"value\",\n" - " \"id\": 0,\n" - " \"description\": \"int param\",\n" - " \"context\": \"test\",\n" - " \"value\": 12,\n" - " \"default\": 5,\n" - " \"present\": false,\n" - " \"tag\": \"myparam\",\n" - " \"cli_enabled\": true,\n" - " \"cli_alias\": \"par1_cli\",\n" - " \"env_enabled\": false,\n" - " \"env_alias\": \"par1_env\",\n" - " \"cfg_enabled\": true,\n" - " \"cfg_alias\": \"par1_cfg\"\n" - " }\n" - " ]\n" - " }\n" - " ],\n" - " \"./test2.py\": [\n" - " {\"dummy\": 345}\n" - " ]\n" - "}\n" - "EOF\n" - ); + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "{\n" + " \"./test1.py\": [\n" + " {\n" + " \"class\": " + "\"testclass\",\n" + " \"name\": " + "\"testrecipe\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test " + "plugin\",\n" + " \"description\": " + "\"description ...\",\n" + " \"author\": \"Some " + "Author\",\n" + " \"email\": " + "\"someone@eso.org\",\n" + " \"copyright\": " + "\"copyright ...\",\n" + " \"parameters\": [\n" + " {\n" + " \"name\": " + "\"test.par1\",\n" + " \"class\": " + "\"value\",\n" + " \"id\": 0,\n" + " " + "\"description\": \"int " + "param\",\n" + " \"context\": " + "\"test\",\n" + " \"value\": " + "12,\n" + " \"default\": " + "5,\n" + " \"present\": " + "false,\n" + " \"tag\": " + "\"myparam\",\n" + " " + "\"cli_enabled\": true,\n" + " \"cli_alias\": " + "\"par1_cli\",\n" + " " + "\"env_enabled\": false,\n" + " \"env_alias\": " + "\"par1_env\",\n" + " " + "\"cfg_enabled\": true,\n" + " \"cfg_alias\": " + "\"par1_cfg\"\n" + " }\n" + " ]\n" + " }\n" + " ],\n" + " \"./test2.py\": [\n" + " {\"dummy\": 345}\n" + " ]\n" + "}\n" + "EOF\n"); cpl_test_eq_error(er_python_load_modules(modulelist), CPL_ERROR_ILLEGAL_INPUT); cpl_test(er_stringarray_present(modulelist, 0)); - cpl_test(! er_stringarray_present(modulelist, 1)); + cpl_test(!er_stringarray_present(modulelist, 1)); er_python_cleanup(); er_stringarray_delete(modulelist); } -static void test_module_set_function(void) +static void +test_module_set_function(void) { - er_stringarray_t * modulelist = NULL; + er_stringarray_t *modulelist = NULL; /* Perform basic tests of the Python module selection function. */ cpl_test_eq_error(er_python_select_module(NULL), CPL_ERROR_NONE); @@ -387,25 +424,31 @@ mock_python( "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "{\n" - " \"test.py\": [\n" - " {\n" - " \"class\": \"testclass\",\n" - " \"name\": \"testrecipe\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin\",\n" - " \"description\": \"description ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": []\n" - " }\n" - " ]\n" - "}\n" - "EOF\n" - ); + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "{\n" + " \"test.py\": [\n" + " {\n" + " \"class\": " + "\"testclass\",\n" + " \"name\": " + "\"testrecipe\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test " + "plugin\",\n" + " \"description\": " + "\"description ...\",\n" + " \"author\": \"Some " + "Author\",\n" + " \"email\": " + "\"someone@eso.org\",\n" + " \"copyright\": " + "\"copyright ...\",\n" + " \"parameters\": []\n" + " }\n" + " ]\n" + "}\n" + "EOF\n"); cpl_test_assert(er_python_load_modules(modulelist) == CPL_ERROR_NONE); er_stringarray_delete(modulelist); @@ -419,10 +462,11 @@ er_python_cleanup(); } -static void test_get_plugin_list(void) +static void +test_get_plugin_list(void) { - er_stringarray_t * modulelist = NULL; - cpl_pluginlist * list = NULL; + er_stringarray_t *modulelist = NULL; + cpl_pluginlist *list = NULL; int result = -1; /* Check error handling if NULL is given. */ @@ -447,25 +491,31 @@ mock_python( "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "{\n" - " \"test.py\": [\n" - " {\n" - " \"class\": \"testclass\",\n" - " \"name\": \"testrecipe\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin\",\n" - " \"description\": \"description ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": []\n" - " }\n" - " ]\n" - "}\n" - "EOF\n" - ); + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "{\n" + " \"test.py\": [\n" + " {\n" + " \"class\": " + "\"testclass\",\n" + " \"name\": " + "\"testrecipe\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test " + "plugin\",\n" + " \"description\": " + "\"description ...\",\n" + " \"author\": \"Some " + "Author\",\n" + " \"email\": " + "\"someone@eso.org\",\n" + " \"copyright\": " + "\"copyright ...\",\n" + " \"parameters\": []\n" + " }\n" + " ]\n" + "}\n" + "EOF\n"); cpl_test_assert(er_python_load_modules(modulelist) == CPL_ERROR_NONE); cpl_test_assert(er_python_select_module("test.py") == CPL_ERROR_NONE); @@ -479,30 +529,31 @@ er_python_cleanup(); } -static void test_plugin_execution(void) +static void +test_plugin_execution(void) { - er_stringarray_t * modulelist = NULL; - cpl_pluginlist * list = NULL; + er_stringarray_t *modulelist = NULL; + cpl_pluginlist *list = NULL; int result = -1; - cpl_recipe * recipe = NULL; - cpl_recipe2 * recipe2 = NULL; + cpl_recipe *recipe = NULL; + cpl_recipe2 *recipe2 = NULL; cpl_plugin_func initfunc = NULL; cpl_plugin_func execfunc = NULL; cpl_plugin_func deinitfunc = NULL; - cpl_frame * frame = NULL; + cpl_frame *frame = NULL; /* Prepare a reference input frame. */ frame = cpl_frame_new(); cpl_test_assert(frame != NULL); - cpl_test_assert(cpl_frame_set_filename(frame, "input.fits") - == CPL_ERROR_NONE); + cpl_test_assert(cpl_frame_set_filename(frame, "input.fits") == + CPL_ERROR_NONE); cpl_test_assert(cpl_frame_set_tag(frame, "RAW") == CPL_ERROR_NONE); - cpl_test_assert(cpl_frame_set_type(frame, CPL_FRAME_TYPE_NONE) - == CPL_ERROR_NONE); - cpl_test_assert(cpl_frame_set_group(frame, CPL_FRAME_GROUP_NONE) - == CPL_ERROR_NONE); - cpl_test_assert(cpl_frame_set_level(frame, CPL_FRAME_LEVEL_NONE) - == CPL_ERROR_NONE); + cpl_test_assert(cpl_frame_set_type(frame, CPL_FRAME_TYPE_NONE) == + CPL_ERROR_NONE); + cpl_test_assert(cpl_frame_set_group(frame, CPL_FRAME_GROUP_NONE) == + CPL_ERROR_NONE); + cpl_test_assert(cpl_frame_set_level(frame, CPL_FRAME_LEVEL_NONE) == + CPL_ERROR_NONE); /* First prepare a python mockup that will load a version 1 and 2 recipe. */ modulelist = er_stringarray_new(); @@ -512,71 +563,101 @@ mock_python( "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "{\n" - " \"recipe_v1.py\": [\n" - " {\n" - " \"class\": \"testclass1\",\n" - " \"name\": \"testrecipe1\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin v1\",\n" - " \"description\": \"description v1 ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [\n" - " {\n" - " \"name\": \"par1\",\n" - " \"class\": \"value\",\n" - " \"description\": \"int param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3\n" - " }\n" - " ]\n" - " }\n" - " ],\n" - " \"recipe_v2.py\": [\n" - " {\n" - " \"class\": \"testclass2\",\n" - " \"name\": \"testrecipe2\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin v2\",\n" - " \"description\": \"description v2 ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [\n" - " {\n" - " \"name\": \"par1\",\n" - " \"class\": \"range\",\n" - " \"description\": \"range param\",\n" - " \"context\": \"test\",\n" - " \"default\": 6,\n" - " \"min\": 1,\n" - " \"max\": 9\n" - " }\n" - " ],\n" - " \"recipeconfig\": [\n" - " {\n" - " \"tag\": \"RAW\",\n" - " \"min\": 1,\n" - " \"max\": 1,\n" - " \"inputs\": [\n" - " {\n" - " \"tag\": \"CALIB\",\n" - " \"min\": 1,\n" - " \"max\": 1\n" - " }\n" - " ],\n" - " \"outputs\": [\"PROD\"]\n" - " }\n" - " ]\n" - " }\n" - " ]\n" - "}\n" - "EOF\n" - ); + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "{\n" + " \"recipe_v1.py\": [\n" + " {\n" + " \"class\": " + "\"testclass1\",\n" + " \"name\": " + "\"testrecipe1\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test " + "plugin v1\",\n" + " \"description\": " + "\"description v1 ...\",\n" + " \"author\": \"Some " + "Author\",\n" + " \"email\": " + "\"someone@eso.org\",\n" + " \"copyright\": " + "\"copyright ...\",\n" + " \"parameters\": [\n" + " {\n" + " \"name\": " + "\"par1\",\n" + " \"class\": " + "\"value\",\n" + " " + "\"description\": \"int " + "param\",\n" + " \"context\": " + "\"test\",\n" + " \"default\": " + "3\n" + " }\n" + " ]\n" + " }\n" + " ],\n" + " \"recipe_v2.py\": [\n" + " {\n" + " \"class\": " + "\"testclass2\",\n" + " \"name\": " + "\"testrecipe2\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test " + "plugin v2\",\n" + " \"description\": " + "\"description v2 ...\",\n" + " \"author\": \"Some " + "Author\",\n" + " \"email\": " + "\"someone@eso.org\",\n" + " \"copyright\": " + "\"copyright ...\",\n" + " \"parameters\": [\n" + " {\n" + " \"name\": " + "\"par1\",\n" + " \"class\": " + "\"range\",\n" + " " + "\"description\": \"range " + "param\",\n" + " \"context\": " + "\"test\",\n" + " \"default\": " + "6,\n" + " \"min\": 1,\n" + " \"max\": 9\n" + " }\n" + " ],\n" + " \"recipeconfig\": [\n" + " {\n" + " \"tag\": " + "\"RAW\",\n" + " \"min\": 1,\n" + " \"max\": 1,\n" + " \"inputs\": [\n" + " {\n" + " \"tag\": " + "\"CALIB\",\n" + " \"min\": " + "1,\n" + " \"max\": " + "1\n" + " }\n" + " ],\n" + " \"outputs\": " + "[\"PROD\"]\n" + " }\n" + " ]\n" + " }\n" + " ]\n" + "}\n" + "EOF\n"); /* Load the mocked recipe plugins and make sure this succeeds. */ cpl_test_assert(er_python_load_modules(modulelist) == CPL_ERROR_NONE); @@ -597,61 +678,77 @@ recipe execution and test the recipe invokation mechanics. */ mock_python( "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "{\n" - " \"plugin\": {\n" - " \"class\": \"testclass1\",\n" - " \"name\": \"testrecipe1\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin v1\",\n" - " \"description\": \"description v1 ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [\n" - " {\n" - " \"name\": \"par1\",\n" - " \"class\": \"value\",\n" - " \"description\": \"int param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3\n" - " }\n" - " ],\n" - " \"frames\": [\n" - " {\n" - " \"filename\": \"input.fits\",\n" - " \"tag\": \"RAW\",\n" - " \"type\": 2,\n" - " \"group\": 1,\n" - " \"level\": 3\n" - " },\n" - " {\n" - " \"filename\": \"product.fits\",\n" - " \"tag\": \"PROD\",\n" - " \"type\": 2,\n" - " \"group\": 3,\n" - " \"level\": 3\n" - " }\n" - " ]\n" - " },\n" - " \"result\": 0,\n" - " \"error\": null\n" - "}\n" - "EOF\n" - ); + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "{\n" + " \"plugin\": {\n" + " \"class\": " + "\"testclass1\",\n" + " \"name\": " + "\"testrecipe1\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test " + "plugin v1\",\n" + " \"description\": " + "\"description v1 ...\",\n" + " \"author\": \"Some " + "Author\",\n" + " \"email\": " + "\"someone@eso.org\",\n" + " \"copyright\": " + "\"copyright ...\",\n" + " \"parameters\": [\n" + " {\n" + " \"name\": " + "\"par1\",\n" + " \"class\": " + "\"value\",\n" + " " + "\"description\": \"int " + "param\",\n" + " \"context\": " + "\"test\",\n" + " \"default\": " + "3\n" + " }\n" + " ],\n" + " \"frames\": [\n" + " {\n" + " \"filename\": " + "\"input.fits\",\n" + " \"tag\": " + "\"RAW\",\n" + " \"type\": 2,\n" + " \"group\": 1,\n" + " \"level\": 3\n" + " },\n" + " {\n" + " \"filename\": " + "\"product.fits\",\n" + " \"tag\": " + "\"PROD\",\n" + " \"type\": 2,\n" + " \"group\": 3,\n" + " \"level\": 3\n" + " }\n" + " ]\n" + " },\n" + " \"result\": 0,\n" + " \"error\": null\n" + "}\n" + "EOF\n"); /* Test that invoking the recipe works successfully. We have to also mock up how EsoRex will create a new recipe object. */ - recipe = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); + recipe = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); cpl_test_eq_error(cpl_plugin_copy(&recipe->interface, cpl_pluginlist_get_first(list)), CPL_ERROR_NONE); recipe->frames = cpl_frameset_new(); cpl_test_assert(recipe->frames != NULL); - cpl_test_assert(cpl_frameset_insert(recipe->frames, - cpl_frame_duplicate(frame)) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_frameset_insert(recipe->frames, cpl_frame_duplicate(frame)) == + CPL_ERROR_NONE); initfunc = cpl_plugin_get_init(&recipe->interface); cpl_test_assert(initfunc != NULL); cpl_test_eq(initfunc(&recipe->interface), 0); @@ -666,15 +763,15 @@ /* The following tests check error handling when invoking the plugin's init, exec and deinit functions. */ - recipe = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); + recipe = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); cpl_test_eq_error(cpl_plugin_copy(&recipe->interface, cpl_pluginlist_get_first(list)), CPL_ERROR_NONE); recipe->frames = cpl_frameset_new(); cpl_test_assert(recipe->frames != NULL); - cpl_test_assert(cpl_frameset_insert(recipe->frames, - cpl_frame_duplicate(frame)) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_frameset_insert(recipe->frames, cpl_frame_duplicate(frame)) == + CPL_ERROR_NONE); initfunc = cpl_plugin_get_init(&recipe->interface); cpl_test_assert(initfunc != NULL); @@ -710,45 +807,57 @@ /* Test the error handling if the recipe produces a truncated frameset. */ mock_python( "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "{\n" - " \"plugin\": {\n" - " \"class\": \"testclass1\",\n" - " \"name\": \"testrecipe1\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin v1\",\n" - " \"description\": \"description v1 ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [\n" - " {\n" - " \"name\": \"par1\",\n" - " \"class\": \"value\",\n" - " \"description\": \"int param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3\n" - " }\n" - " ],\n" - " \"frames\": [\n" - " ]\n" - " },\n" - " \"result\": 0,\n" - " \"error\": null\n" - "}\n" - "EOF\n" - ); + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "{\n" + " \"plugin\": {\n" + " \"class\": " + "\"testclass1\",\n" + " \"name\": " + "\"testrecipe1\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test " + "plugin v1\",\n" + " \"description\": " + "\"description v1 ...\",\n" + " \"author\": \"Some " + "Author\",\n" + " \"email\": " + "\"someone@eso.org\",\n" + " \"copyright\": " + "\"copyright ...\",\n" + " \"parameters\": [\n" + " {\n" + " \"name\": " + "\"par1\",\n" + " \"class\": " + "\"value\",\n" + " " + "\"description\": \"int " + "param\",\n" + " \"context\": " + "\"test\",\n" + " \"default\": " + "3\n" + " }\n" + " ],\n" + " \"frames\": [\n" + " ]\n" + " },\n" + " \"result\": 0,\n" + " \"error\": null\n" + "}\n" + "EOF\n"); - recipe = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); + recipe = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); cpl_test_eq_error(cpl_plugin_copy(&recipe->interface, cpl_pluginlist_get_first(list)), CPL_ERROR_NONE); recipe->frames = cpl_frameset_new(); cpl_test_assert(recipe->frames != NULL); - cpl_test_assert(cpl_frameset_insert(recipe->frames, - cpl_frame_duplicate(frame)) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_frameset_insert(recipe->frames, cpl_frame_duplicate(frame)) == + CPL_ERROR_NONE); initfunc = cpl_plugin_get_init(&recipe->interface); cpl_test_assert(initfunc != NULL); cpl_test_eq(initfunc(&recipe->interface), 0); @@ -763,26 +872,24 @@ /* Test the error handling if the recipe does not produce a plugin structure in the output JSON. */ - mock_python( - "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "{\n" - " \"result\": 0,\n" - " \"error\": null\n" - "}\n" - "EOF\n" - ); + mock_python("#!/bin/sh\n" + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "{\n" + " \"result\": 0,\n" + " \"error\": null\n" + "}\n" + "EOF\n"); - recipe = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); + recipe = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); cpl_test_eq_error(cpl_plugin_copy(&recipe->interface, cpl_pluginlist_get_first(list)), CPL_ERROR_NONE); recipe->frames = cpl_frameset_new(); cpl_test_assert(recipe->frames != NULL); - cpl_test_assert(cpl_frameset_insert(recipe->frames, - cpl_frame_duplicate(frame)) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_frameset_insert(recipe->frames, cpl_frame_duplicate(frame)) == + CPL_ERROR_NONE); initfunc = cpl_plugin_get_init(&recipe->interface); cpl_test_assert(initfunc != NULL); cpl_test_eq(initfunc(&recipe->interface), 0); @@ -799,58 +906,74 @@ in the output JSON. */ mock_python( "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "{\n" - " \"plugin\": {\n" - " \"class\": \"testclass1\",\n" - " \"name\": \"testrecipe1\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin v1\",\n" - " \"description\": \"description v1 ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [\n" - " {\n" - " \"name\": \"par1\",\n" - " \"class\": \"value\",\n" - " \"description\": \"int param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3\n" - " }\n" - " ],\n" - " \"frames\": [\n" - " {\n" - " \"filename\": \"input.fits\",\n" - " \"tag\": \"RAW\",\n" - " \"type\": 2,\n" - " \"group\": 1,\n" - " \"level\": 3\n" - " },\n" - " {\n" - " \"filename\": \"product.fits\",\n" - " \"tag\": \"PROD\",\n" - " \"type\": 2,\n" - " \"group\": 3,\n" - " \"level\": 3\n" - " }\n" - " ]\n" - " },\n" - " \"error\": null\n" - "}\n" - "EOF\n" - ); + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "{\n" + " \"plugin\": {\n" + " \"class\": " + "\"testclass1\",\n" + " \"name\": " + "\"testrecipe1\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test " + "plugin v1\",\n" + " \"description\": " + "\"description v1 ...\",\n" + " \"author\": \"Some " + "Author\",\n" + " \"email\": " + "\"someone@eso.org\",\n" + " \"copyright\": " + "\"copyright ...\",\n" + " \"parameters\": [\n" + " {\n" + " \"name\": " + "\"par1\",\n" + " \"class\": " + "\"value\",\n" + " " + "\"description\": \"int " + "param\",\n" + " \"context\": " + "\"test\",\n" + " \"default\": " + "3\n" + " }\n" + " ],\n" + " \"frames\": [\n" + " {\n" + " \"filename\": " + "\"input.fits\",\n" + " \"tag\": " + "\"RAW\",\n" + " \"type\": 2,\n" + " \"group\": 1,\n" + " \"level\": 3\n" + " },\n" + " {\n" + " \"filename\": " + "\"product.fits\",\n" + " \"tag\": " + "\"PROD\",\n" + " \"type\": 2,\n" + " \"group\": 3,\n" + " \"level\": 3\n" + " }\n" + " ]\n" + " },\n" + " \"error\": null\n" + "}\n" + "EOF\n"); - recipe = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); + recipe = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); cpl_test_eq_error(cpl_plugin_copy(&recipe->interface, cpl_pluginlist_get_first(list)), CPL_ERROR_NONE); recipe->frames = cpl_frameset_new(); cpl_test_assert(recipe->frames != NULL); - cpl_test_assert(cpl_frameset_insert(recipe->frames, - cpl_frame_duplicate(frame)) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_frameset_insert(recipe->frames, cpl_frame_duplicate(frame)) == + CPL_ERROR_NONE); initfunc = cpl_plugin_get_init(&recipe->interface); cpl_test_assert(initfunc != NULL); cpl_test_eq(initfunc(&recipe->interface), 0); @@ -866,52 +989,67 @@ /* Check for correct handling when the recipe indicates an error. */ mock_python( "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "{\n" - " \"plugin\": {\n" - " \"class\": \"testclass1\",\n" - " \"name\": \"testrecipe1\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin v1\",\n" - " \"description\": \"description v1 ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [\n" - " {\n" - " \"name\": \"par1\",\n" - " \"class\": \"value\",\n" - " \"description\": \"int param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3\n" - " }\n" - " ],\n" - " \"frames\": [\n" - " {\n" - " \"filename\": \"input.fits\",\n" - " \"tag\": \"RAW\",\n" - " \"type\": 2,\n" - " \"group\": 1,\n" - " \"level\": 3\n" - " }\n" - " ]\n" - " },\n" - " \"result\": 99,\n" - " \"error\": \"FAIL FROM RECIPE\"\n" - "}\n" - "EOF\n" - ); + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "{\n" + " \"plugin\": {\n" + " \"class\": " + "\"testclass1\",\n" + " \"name\": " + "\"testrecipe1\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test " + "plugin v1\",\n" + " \"description\": " + "\"description v1 ...\",\n" + " \"author\": \"Some " + "Author\",\n" + " \"email\": " + "\"someone@eso.org\",\n" + " \"copyright\": " + "\"copyright ...\",\n" + " \"parameters\": [\n" + " {\n" + " \"name\": " + "\"par1\",\n" + " \"class\": " + "\"value\",\n" + " " + "\"description\": \"int " + "param\",\n" + " \"context\": " + "\"test\",\n" + " \"default\": " + "3\n" + " }\n" + " ],\n" + " \"frames\": [\n" + " {\n" + " \"filename\": " + "\"input.fits\",\n" + " \"tag\": " + "\"RAW\",\n" + " \"type\": 2,\n" + " \"group\": 1,\n" + " \"level\": 3\n" + " }\n" + " ]\n" + " },\n" + " \"result\": 99,\n" + " \"error\": \"FAIL FROM " + "RECIPE\"\n" + "}\n" + "EOF\n"); - recipe = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); + recipe = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); cpl_test_eq_error(cpl_plugin_copy(&recipe->interface, cpl_pluginlist_get_first(list)), CPL_ERROR_NONE); recipe->frames = cpl_frameset_new(); cpl_test_assert(recipe->frames != NULL); - cpl_test_assert(cpl_frameset_insert(recipe->frames, - cpl_frame_duplicate(frame)) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_frameset_insert(recipe->frames, cpl_frame_duplicate(frame)) == + CPL_ERROR_NONE); initfunc = cpl_plugin_get_init(&recipe->interface); cpl_test_assert(initfunc != NULL); cpl_test_eq(initfunc(&recipe->interface), 0); @@ -930,52 +1068,66 @@ message is set to null. */ mock_python( "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "{\n" - " \"plugin\": {\n" - " \"class\": \"testclass1\",\n" - " \"name\": \"testrecipe1\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin v1\",\n" - " \"description\": \"description v1 ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [\n" - " {\n" - " \"name\": \"par1\",\n" - " \"class\": \"value\",\n" - " \"description\": \"int param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3\n" - " }\n" - " ],\n" - " \"frames\": [\n" - " {\n" - " \"filename\": \"input.fits\",\n" - " \"tag\": \"RAW\",\n" - " \"type\": 2,\n" - " \"group\": 1,\n" - " \"level\": 3\n" - " }\n" - " ]\n" - " },\n" - " \"result\": 999,\n" - " \"error\": null\n" - "}\n" - "EOF\n" - ); + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "{\n" + " \"plugin\": {\n" + " \"class\": " + "\"testclass1\",\n" + " \"name\": " + "\"testrecipe1\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test " + "plugin v1\",\n" + " \"description\": " + "\"description v1 ...\",\n" + " \"author\": \"Some " + "Author\",\n" + " \"email\": " + "\"someone@eso.org\",\n" + " \"copyright\": " + "\"copyright ...\",\n" + " \"parameters\": [\n" + " {\n" + " \"name\": " + "\"par1\",\n" + " \"class\": " + "\"value\",\n" + " " + "\"description\": \"int " + "param\",\n" + " \"context\": " + "\"test\",\n" + " \"default\": " + "3\n" + " }\n" + " ],\n" + " \"frames\": [\n" + " {\n" + " \"filename\": " + "\"input.fits\",\n" + " \"tag\": " + "\"RAW\",\n" + " \"type\": 2,\n" + " \"group\": 1,\n" + " \"level\": 3\n" + " }\n" + " ]\n" + " },\n" + " \"result\": 999,\n" + " \"error\": null\n" + "}\n" + "EOF\n"); - recipe = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); + recipe = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); cpl_test_eq_error(cpl_plugin_copy(&recipe->interface, cpl_pluginlist_get_first(list)), CPL_ERROR_NONE); recipe->frames = cpl_frameset_new(); cpl_test_assert(recipe->frames != NULL); - cpl_test_assert(cpl_frameset_insert(recipe->frames, - cpl_frame_duplicate(frame)) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_frameset_insert(recipe->frames, cpl_frame_duplicate(frame)) == + CPL_ERROR_NONE); initfunc = cpl_plugin_get_init(&recipe->interface); cpl_test_assert(initfunc != NULL); cpl_test_eq(initfunc(&recipe->interface), 0); @@ -994,51 +1146,65 @@ is not set by the recipe. */ mock_python( "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "{\n" - " \"plugin\": {\n" - " \"class\": \"testclass1\",\n" - " \"name\": \"testrecipe1\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin v1\",\n" - " \"description\": \"description v1 ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [\n" - " {\n" - " \"name\": \"par1\",\n" - " \"class\": \"value\",\n" - " \"description\": \"int param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3\n" - " }\n" - " ],\n" - " \"frames\": [\n" - " {\n" - " \"filename\": \"input.fits\",\n" - " \"tag\": \"RAW\",\n" - " \"type\": 2,\n" - " \"group\": 1,\n" - " \"level\": 3\n" - " }\n" - " ]\n" - " },\n" - " \"result\": 88\n" - "}\n" - "EOF\n" - ); + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "{\n" + " \"plugin\": {\n" + " \"class\": " + "\"testclass1\",\n" + " \"name\": " + "\"testrecipe1\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test " + "plugin v1\",\n" + " \"description\": " + "\"description v1 ...\",\n" + " \"author\": \"Some " + "Author\",\n" + " \"email\": " + "\"someone@eso.org\",\n" + " \"copyright\": " + "\"copyright ...\",\n" + " \"parameters\": [\n" + " {\n" + " \"name\": " + "\"par1\",\n" + " \"class\": " + "\"value\",\n" + " " + "\"description\": \"int " + "param\",\n" + " \"context\": " + "\"test\",\n" + " \"default\": " + "3\n" + " }\n" + " ],\n" + " \"frames\": [\n" + " {\n" + " \"filename\": " + "\"input.fits\",\n" + " \"tag\": " + "\"RAW\",\n" + " \"type\": 2,\n" + " \"group\": 1,\n" + " \"level\": 3\n" + " }\n" + " ]\n" + " },\n" + " \"result\": 88\n" + "}\n" + "EOF\n"); - recipe = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); + recipe = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); cpl_test_eq_error(cpl_plugin_copy(&recipe->interface, cpl_pluginlist_get_first(list)), CPL_ERROR_NONE); recipe->frames = cpl_frameset_new(); cpl_test_assert(recipe->frames != NULL); - cpl_test_assert(cpl_frameset_insert(recipe->frames, - cpl_frame_duplicate(frame)) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_frameset_insert(recipe->frames, cpl_frame_duplicate(frame)) == + CPL_ERROR_NONE); initfunc = cpl_plugin_get_init(&recipe->interface); cpl_test_assert(initfunc != NULL); cpl_test_eq(initfunc(&recipe->interface), 0); @@ -1055,52 +1221,67 @@ /* Check error handling if the 'result' field is not a number. */ mock_python( "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "{\n" - " \"plugin\": {\n" - " \"class\": \"testclass1\",\n" - " \"name\": \"testrecipe1\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin v1\",\n" - " \"description\": \"description v1 ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [\n" - " {\n" - " \"name\": \"par1\",\n" - " \"class\": \"value\",\n" - " \"description\": \"int param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3\n" - " }\n" - " ],\n" - " \"frames\": [\n" - " {\n" - " \"filename\": \"input.fits\",\n" - " \"tag\": \"RAW\",\n" - " \"type\": 2,\n" - " \"group\": 1,\n" - " \"level\": 3\n" - " }\n" - " ]\n" - " },\n" - " \"result\": null,\n" - " \"error\": \"FAIL FROM RECIPE\"\n" - "}\n" - "EOF\n" - ); + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "{\n" + " \"plugin\": {\n" + " \"class\": " + "\"testclass1\",\n" + " \"name\": " + "\"testrecipe1\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test " + "plugin v1\",\n" + " \"description\": " + "\"description v1 ...\",\n" + " \"author\": \"Some " + "Author\",\n" + " \"email\": " + "\"someone@eso.org\",\n" + " \"copyright\": " + "\"copyright ...\",\n" + " \"parameters\": [\n" + " {\n" + " \"name\": " + "\"par1\",\n" + " \"class\": " + "\"value\",\n" + " " + "\"description\": \"int " + "param\",\n" + " \"context\": " + "\"test\",\n" + " \"default\": " + "3\n" + " }\n" + " ],\n" + " \"frames\": [\n" + " {\n" + " \"filename\": " + "\"input.fits\",\n" + " \"tag\": " + "\"RAW\",\n" + " \"type\": 2,\n" + " \"group\": 1,\n" + " \"level\": 3\n" + " }\n" + " ]\n" + " },\n" + " \"result\": null,\n" + " \"error\": \"FAIL FROM " + "RECIPE\"\n" + "}\n" + "EOF\n"); - recipe = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); + recipe = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); cpl_test_eq_error(cpl_plugin_copy(&recipe->interface, cpl_pluginlist_get_first(list)), CPL_ERROR_NONE); recipe->frames = cpl_frameset_new(); cpl_test_assert(recipe->frames != NULL); - cpl_test_assert(cpl_frameset_insert(recipe->frames, - cpl_frame_duplicate(frame)) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_frameset_insert(recipe->frames, cpl_frame_duplicate(frame)) == + CPL_ERROR_NONE); initfunc = cpl_plugin_get_init(&recipe->interface); cpl_test_assert(initfunc != NULL); cpl_test_eq(initfunc(&recipe->interface), 0); @@ -1115,27 +1296,26 @@ /* Test error handling when the recipe produces an invalid 'plugin' structure. */ - mock_python( - "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "{\n" - " \"plugin\": {\"dummy\": 123},\n" - " \"result\": 0,\n" - " \"error\": null\n" - "}\n" - "EOF\n" - ); + mock_python("#!/bin/sh\n" + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "{\n" + " \"plugin\": " + "{\"dummy\": 123},\n" + " \"result\": 0,\n" + " \"error\": null\n" + "}\n" + "EOF\n"); - recipe = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); + recipe = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); cpl_test_eq_error(cpl_plugin_copy(&recipe->interface, cpl_pluginlist_get_first(list)), CPL_ERROR_NONE); recipe->frames = cpl_frameset_new(); cpl_test_assert(recipe->frames != NULL); - cpl_test_assert(cpl_frameset_insert(recipe->frames, - cpl_frame_duplicate(frame)) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_frameset_insert(recipe->frames, cpl_frame_duplicate(frame)) == + CPL_ERROR_NONE); initfunc = cpl_plugin_get_init(&recipe->interface); cpl_test_assert(initfunc != NULL); cpl_test_eq(initfunc(&recipe->interface), 0); @@ -1151,21 +1331,20 @@ /* Test error handling when the recipe produces the wrong format. */ mock_python( "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "[]\n" - "EOF\n" - ); + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "[]\n" + "EOF\n"); - recipe = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); + recipe = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); cpl_test_eq_error(cpl_plugin_copy(&recipe->interface, cpl_pluginlist_get_first(list)), CPL_ERROR_NONE); recipe->frames = cpl_frameset_new(); cpl_test_assert(recipe->frames != NULL); - cpl_test_assert(cpl_frameset_insert(recipe->frames, - cpl_frame_duplicate(frame)) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_frameset_insert(recipe->frames, cpl_frame_duplicate(frame)) == + CPL_ERROR_NONE); initfunc = cpl_plugin_get_init(&recipe->interface); cpl_test_assert(initfunc != NULL); cpl_test_eq(initfunc(&recipe->interface), 0); @@ -1179,23 +1358,21 @@ cpl_plugin_delete(&recipe->interface); /* Test error handling when the recipe produces garbage. */ - mock_python( - "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "{ ... % \" , \n" - "EOF\n" - ); + mock_python("#!/bin/sh\n" + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "{ ... % \" , \n" + "EOF\n"); - recipe = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); + recipe = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); cpl_test_eq_error(cpl_plugin_copy(&recipe->interface, cpl_pluginlist_get_first(list)), CPL_ERROR_NONE); recipe->frames = cpl_frameset_new(); cpl_test_assert(recipe->frames != NULL); - cpl_test_assert(cpl_frameset_insert(recipe->frames, - cpl_frame_duplicate(frame)) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_frameset_insert(recipe->frames, cpl_frame_duplicate(frame)) == + CPL_ERROR_NONE); initfunc = cpl_plugin_get_init(&recipe->interface); cpl_test_assert(initfunc != NULL); cpl_test_eq(initfunc(&recipe->interface), 0); @@ -1210,20 +1387,18 @@ /* Test the error handling when we simulate a complete failure of the python process. */ - mock_python( - "#!/bin/sh\n" - "exit 7\n" - ); + mock_python("#!/bin/sh\n" + "exit 7\n"); - recipe = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); + recipe = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); cpl_test_eq_error(cpl_plugin_copy(&recipe->interface, cpl_pluginlist_get_first(list)), CPL_ERROR_NONE); recipe->frames = cpl_frameset_new(); cpl_test_assert(recipe->frames != NULL); - cpl_test_assert(cpl_frameset_insert(recipe->frames, - cpl_frame_duplicate(frame)) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_frameset_insert(recipe->frames, cpl_frame_duplicate(frame)) == + CPL_ERROR_NONE); initfunc = cpl_plugin_get_init(&recipe->interface); cpl_test_assert(initfunc != NULL); cpl_test_eq(initfunc(&recipe->interface), 0); @@ -1247,74 +1422,95 @@ mock_python( "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "{\n" - " \"plugin\": {\n" - " \"class\": \"testclass2\",\n" - " \"name\": \"testrecipe2\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin v2\",\n" - " \"description\": \"description v2 ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [\n" - " {\n" - " \"name\": \"par1\",\n" - " \"class\": \"value\",\n" - " \"description\": \"int param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3\n" - " }\n" - " ],\n" - " \"frames\": [\n" - " {\n" - " \"filename\": \"input.fits\",\n" - " \"tag\": \"RAW\",\n" - " \"type\": 2,\n" - " \"group\": 1,\n" - " \"level\": 3\n" - " },\n" - " {\n" - " \"filename\": \"product.fits\",\n" - " \"tag\": \"PROD\",\n" - " \"type\": 2,\n" - " \"group\": 3,\n" - " \"level\": 3\n" - " }\n" - " ],\n" - " \"recipeconfig\": [\n" - " {\n" - " \"tag\": \"RAW\",\n" - " \"min\": 1,\n" - " \"max\": 1,\n" - " \"inputs\": [\n" - " {\n" - " \"tag\": \"CALIB\",\n" - " \"min\": 1,\n" - " \"max\": 1\n" - " }\n" - " ],\n" - " \"outputs\": [\"PROD\"]\n" - " }\n" - " ]\n" - " },\n" - " \"result\": 0,\n" - " \"error\": null\n" - "}\n" - "EOF\n" - ); + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "{\n" + " \"plugin\": {\n" + " \"class\": " + "\"testclass2\",\n" + " \"name\": " + "\"testrecipe2\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test " + "plugin v2\",\n" + " \"description\": " + "\"description v2 ...\",\n" + " \"author\": \"Some " + "Author\",\n" + " \"email\": " + "\"someone@eso.org\",\n" + " \"copyright\": " + "\"copyright ...\",\n" + " \"parameters\": [\n" + " {\n" + " \"name\": " + "\"par1\",\n" + " \"class\": " + "\"value\",\n" + " " + "\"description\": \"int " + "param\",\n" + " \"context\": " + "\"test\",\n" + " \"default\": " + "3\n" + " }\n" + " ],\n" + " \"frames\": [\n" + " {\n" + " \"filename\": " + "\"input.fits\",\n" + " \"tag\": " + "\"RAW\",\n" + " \"type\": 2,\n" + " \"group\": 1,\n" + " \"level\": 3\n" + " },\n" + " {\n" + " \"filename\": " + "\"product.fits\",\n" + " \"tag\": " + "\"PROD\",\n" + " \"type\": 2,\n" + " \"group\": 3,\n" + " \"level\": 3\n" + " }\n" + " ],\n" + " \"recipeconfig\": [\n" + " {\n" + " \"tag\": " + "\"RAW\",\n" + " \"min\": 1,\n" + " \"max\": 1,\n" + " \"inputs\": [\n" + " {\n" + " \"tag\": " + "\"CALIB\",\n" + " \"min\": " + "1,\n" + " \"max\": " + "1\n" + " }\n" + " ],\n" + " \"outputs\": " + "[\"PROD\"]\n" + " }\n" + " ]\n" + " },\n" + " \"result\": 0,\n" + " \"error\": null\n" + "}\n" + "EOF\n"); - recipe2 = (cpl_recipe2 *) cpl_calloc(1, sizeof(cpl_recipe2)); + recipe2 = (cpl_recipe2 *)cpl_calloc(1, sizeof(cpl_recipe2)); cpl_test_eq_error(cpl_plugin_copy(&recipe2->base.interface, cpl_pluginlist_get_first(list)), CPL_ERROR_NONE); recipe2->base.frames = cpl_frameset_new(); cpl_test_assert(recipe2->base.frames != NULL); - cpl_test_assert(cpl_frameset_insert(recipe2->base.frames, - cpl_frame_duplicate(frame)) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_frameset_insert(recipe2->base.frames, cpl_frame_duplicate(frame)) == + CPL_ERROR_NONE); cpl_test_error(CPL_ERROR_NONE); initfunc = cpl_plugin_get_init(&recipe2->base.interface); cpl_test_assert(initfunc != NULL); @@ -1335,31 +1531,32 @@ cpl_frame_delete(frame); } -static void test_plugin_execution_with_simple_name(void) +static void +test_plugin_execution_with_simple_name(void) { /* This is a test for an edge case where the python module name used does not end in a .py extension. */ - er_stringarray_t * modulelist = NULL; - cpl_pluginlist * list = NULL; + er_stringarray_t *modulelist = NULL; + cpl_pluginlist *list = NULL; int result = -1; - cpl_recipe * recipe = NULL; + cpl_recipe *recipe = NULL; cpl_plugin_func initfunc = NULL; cpl_plugin_func execfunc = NULL; cpl_plugin_func deinitfunc = NULL; - cpl_frame * frame = NULL; + cpl_frame *frame = NULL; /* Prepare a reference input frame. */ frame = cpl_frame_new(); cpl_test_assert(frame != NULL); - cpl_test_assert(cpl_frame_set_filename(frame, "input.fits") - == CPL_ERROR_NONE); + cpl_test_assert(cpl_frame_set_filename(frame, "input.fits") == + CPL_ERROR_NONE); cpl_test_assert(cpl_frame_set_tag(frame, "RAW") == CPL_ERROR_NONE); - cpl_test_assert(cpl_frame_set_type(frame, CPL_FRAME_TYPE_NONE) - == CPL_ERROR_NONE); - cpl_test_assert(cpl_frame_set_group(frame, CPL_FRAME_GROUP_NONE) - == CPL_ERROR_NONE); - cpl_test_assert(cpl_frame_set_level(frame, CPL_FRAME_LEVEL_NONE) - == CPL_ERROR_NONE); + cpl_test_assert(cpl_frame_set_type(frame, CPL_FRAME_TYPE_NONE) == + CPL_ERROR_NONE); + cpl_test_assert(cpl_frame_set_group(frame, CPL_FRAME_GROUP_NONE) == + CPL_ERROR_NONE); + cpl_test_assert(cpl_frame_set_level(frame, CPL_FRAME_LEVEL_NONE) == + CPL_ERROR_NONE); /* First prepare a python mockup that will simulate loading of a recipe plugin. */ @@ -1369,33 +1566,45 @@ mock_python( "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "{\n" - " \"testrecipe\": [\n" - " {\n" - " \"class\": \"testclass1\",\n" - " \"name\": \"testrecipe1\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin v1\",\n" - " \"description\": \"description v1 ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [\n" - " {\n" - " \"name\": \"par1\",\n" - " \"class\": \"value\",\n" - " \"description\": \"int param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3\n" - " }\n" - " ]\n" - " }\n" - " ]\n" - "}\n" - "EOF\n" - ); + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "{\n" + " \"testrecipe\": [\n" + " {\n" + " \"class\": " + "\"testclass1\",\n" + " \"name\": " + "\"testrecipe1\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test " + "plugin v1\",\n" + " \"description\": " + "\"description v1 ...\",\n" + " \"author\": \"Some " + "Author\",\n" + " \"email\": " + "\"someone@eso.org\",\n" + " \"copyright\": " + "\"copyright ...\",\n" + " \"parameters\": [\n" + " {\n" + " \"name\": " + "\"par1\",\n" + " \"class\": " + "\"value\",\n" + " " + "\"description\": \"int " + "param\",\n" + " \"context\": " + "\"test\",\n" + " \"default\": " + "3\n" + " }\n" + " ]\n" + " }\n" + " ]\n" + "}\n" + "EOF\n"); /* Load the mocked recipe plugin and make sure this succeeds. */ cpl_test_assert(er_python_load_modules(modulelist) == CPL_ERROR_NONE); @@ -1410,60 +1619,76 @@ /* Prepare a python mocking script to simulate the recipe response. */ mock_python( "#!/bin/sh\n" - "cat <&"CPL_STRINGIFY(PYTHON_INPUT_FD)" > /dev/null\n" - "cat <&"CPL_STRINGIFY(PYTHON_OUTPUT_FD)"\n" - "{\n" - " \"plugin\": {\n" - " \"class\": \"testclass1\",\n" - " \"name\": \"testrecipe1\",\n" - " \"version\": 123,\n" - " \"synopsis\": \"test plugin v1\",\n" - " \"description\": \"description v1 ...\",\n" - " \"author\": \"Some Author\",\n" - " \"email\": \"someone@eso.org\",\n" - " \"copyright\": \"copyright ...\",\n" - " \"parameters\": [\n" - " {\n" - " \"name\": \"par1\",\n" - " \"class\": \"value\",\n" - " \"description\": \"int param\",\n" - " \"context\": \"test\",\n" - " \"default\": 3\n" - " }\n" - " ],\n" - " \"frames\": [\n" - " {\n" - " \"filename\": \"input.fits\",\n" - " \"tag\": \"RAW\",\n" - " \"type\": 2,\n" - " \"group\": 1,\n" - " \"level\": 3\n" - " },\n" - " {\n" - " \"filename\": \"product.fits\",\n" - " \"tag\": \"PROD\",\n" - " \"type\": 2,\n" - " \"group\": 3,\n" - " \"level\": 3\n" - " }\n" - " ]\n" - " },\n" - " \"result\": 0,\n" - " \"error\": null\n" - "}\n" - "EOF\n" - ); + "cat <&" CPL_STRINGIFY(PYTHON_INPUT_FD) " > /dev/null\n" + "cat <&" CPL_STRINGIFY(PYTHON_OUTPUT_FD) "\n" + "{\n" + " \"plugin\": {\n" + " \"class\": " + "\"testclass1\",\n" + " \"name\": " + "\"testrecipe1\",\n" + " \"version\": 123,\n" + " \"synopsis\": \"test " + "plugin v1\",\n" + " \"description\": " + "\"description v1 ...\",\n" + " \"author\": \"Some " + "Author\",\n" + " \"email\": " + "\"someone@eso.org\",\n" + " \"copyright\": " + "\"copyright ...\",\n" + " \"parameters\": [\n" + " {\n" + " \"name\": " + "\"par1\",\n" + " \"class\": " + "\"value\",\n" + " " + "\"description\": \"int " + "param\",\n" + " \"context\": " + "\"test\",\n" + " \"default\": " + "3\n" + " }\n" + " ],\n" + " \"frames\": [\n" + " {\n" + " \"filename\": " + "\"input.fits\",\n" + " \"tag\": " + "\"RAW\",\n" + " \"type\": 2,\n" + " \"group\": 1,\n" + " \"level\": 3\n" + " },\n" + " {\n" + " \"filename\": " + "\"product.fits\",\n" + " \"tag\": " + "\"PROD\",\n" + " \"type\": 2,\n" + " \"group\": 3,\n" + " \"level\": 3\n" + " }\n" + " ]\n" + " },\n" + " \"result\": 0,\n" + " \"error\": null\n" + "}\n" + "EOF\n"); /* Prepare the recipe plugin as EsoRex would and invoke the recipe. */ - recipe = (cpl_recipe *) cpl_calloc(1, sizeof(cpl_recipe)); + recipe = (cpl_recipe *)cpl_calloc(1, sizeof(cpl_recipe)); cpl_test_eq_error(cpl_plugin_copy(&recipe->interface, cpl_pluginlist_get_first(list)), CPL_ERROR_NONE); recipe->frames = cpl_frameset_new(); cpl_test_assert(recipe->frames != NULL); - cpl_test_assert(cpl_frameset_insert(recipe->frames, - cpl_frame_duplicate(frame)) - == CPL_ERROR_NONE); + cpl_test_assert( + cpl_frameset_insert(recipe->frames, cpl_frame_duplicate(frame)) == + CPL_ERROR_NONE); initfunc = cpl_plugin_get_init(&recipe->interface); cpl_test_assert(initfunc != NULL); cpl_test_eq(initfunc(&recipe->interface), 0); @@ -1486,10 +1711,11 @@ #else /* ENABLE_PYTHON_RECIPES */ -int main(void) +int +main(void) { /* Indicate to the automake test runner that the tests are skipped. */ return 77; } -#endif /* ENABLE_PYTHON_RECIPES */ +#endif /* ENABLE_PYTHON_RECIPES */ diff -Nru esorex-3.13.5+ds/src/tests/esorex_test.h esorex-3.13.6+ds/src/tests/esorex_test.h --- esorex-3.13.5+ds/src/tests/esorex_test.h 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/tests/esorex_test.h 2022-04-29 16:21:07.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Recipe Execution Tool - * Copyright (C) 2017 European Southern Observatory + * Copyright (C) 2017-2022 European Southern Observatory * * 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 @@ -25,158 +25,147 @@ /* Tests if the two string pointers are both NULL or otherwise the strings themselves are both equal. */ -#define test_equal_string(first, second) \ - if (! (first == NULL && second == NULL)) { \ - cpl_test_eq_string(first, second); \ +#define test_equal_string(first, second) \ + if (!(first == NULL && second == NULL)) { \ + cpl_test_eq_string(first, second); \ } /* Tests if two CPL parameter objects are equal or not, i.e. are all their attributes the same or not. */ -#define test_equal_param(first, second) \ - cpl_test_eq(cpl_parameter_get_class(first), \ - cpl_parameter_get_class(second)); \ - cpl_test_eq(cpl_parameter_get_type(first), \ - cpl_parameter_get_type(second)); \ - cpl_test_eq_string(cpl_parameter_get_name(first), \ - cpl_parameter_get_name(second)); \ - cpl_test_eq_string(cpl_parameter_get_help(first), \ - cpl_parameter_get_help(second)); \ - cpl_test_eq_string(cpl_parameter_get_context(first), \ - cpl_parameter_get_context(second)); \ - test_equal_string(cpl_parameter_get_tag(first), \ - cpl_parameter_get_tag(second)); \ - cpl_test_eq(cpl_parameter_get_default_flag(first), \ - cpl_parameter_get_default_flag(second)); \ - cpl_test_eq(cpl_parameter_is_enabled(first, CPL_PARAMETER_MODE_CLI), \ - cpl_parameter_is_enabled(second, CPL_PARAMETER_MODE_CLI)); \ - cpl_test_eq(cpl_parameter_is_enabled(first, CPL_PARAMETER_MODE_ENV), \ - cpl_parameter_is_enabled(second, CPL_PARAMETER_MODE_ENV)); \ - cpl_test_eq(cpl_parameter_is_enabled(first, CPL_PARAMETER_MODE_CFG), \ - cpl_parameter_is_enabled(second, CPL_PARAMETER_MODE_CFG)); \ - test_equal_string(cpl_parameter_get_alias(first, CPL_PARAMETER_MODE_CLI), \ - cpl_parameter_get_alias(second, CPL_PARAMETER_MODE_CLI));\ - test_equal_string(cpl_parameter_get_alias(first, CPL_PARAMETER_MODE_ENV), \ - cpl_parameter_get_alias(second, CPL_PARAMETER_MODE_ENV));\ - test_equal_string(cpl_parameter_get_alias(first, CPL_PARAMETER_MODE_CFG), \ - cpl_parameter_get_alias(second, CPL_PARAMETER_MODE_CFG));\ - switch (cpl_parameter_get_type(first)) { \ - case CPL_TYPE_BOOL: \ - cpl_test_eq(cpl_parameter_get_bool(first), \ - cpl_parameter_get_bool(second)); \ - cpl_test_eq(cpl_parameter_get_default_bool(first), \ - cpl_parameter_get_default_bool(second)); \ - break; \ - case CPL_TYPE_INT: \ - cpl_test_eq(cpl_parameter_get_int(first), \ - cpl_parameter_get_int(second)); \ - cpl_test_eq(cpl_parameter_get_default_int(first), \ - cpl_parameter_get_default_int(second)); \ - break; \ - case CPL_TYPE_DOUBLE: \ - cpl_test_abs(cpl_parameter_get_double(first), \ - cpl_parameter_get_double(second), DBL_EPSILON); \ - cpl_test_abs(cpl_parameter_get_default_double(first), \ - cpl_parameter_get_default_double(second), DBL_EPSILON); \ - break; \ - case CPL_TYPE_STRING: \ - cpl_test_eq_string(cpl_parameter_get_string(first), \ - cpl_parameter_get_string(second)); \ - cpl_test_eq_string(cpl_parameter_get_default_string(first), \ - cpl_parameter_get_default_string(second)); \ - break; \ - default: \ - cpl_test_assert( \ - cpl_parameter_get_type(first) == CPL_TYPE_BOOL || \ - cpl_parameter_get_type(first) == CPL_TYPE_INT || \ - cpl_parameter_get_type(first) == CPL_TYPE_DOUBLE || \ - cpl_parameter_get_type(first) == CPL_TYPE_STRING \ - ); \ - } \ - switch (cpl_parameter_get_class(first)) { \ - case CPL_PARAMETER_CLASS_RANGE: \ - switch (cpl_parameter_get_type(first)) { \ - case CPL_TYPE_INT: \ - cpl_test_eq(cpl_parameter_get_range_min_int(first), \ - cpl_parameter_get_range_min_int(second)); \ - cpl_test_eq(cpl_parameter_get_range_max_int(first), \ - cpl_parameter_get_range_max_int(second)); \ - break; \ - case CPL_TYPE_DOUBLE: \ - cpl_test_abs(cpl_parameter_get_range_min_double(first), \ - cpl_parameter_get_range_min_double(second), \ - DBL_EPSILON); \ - cpl_test_abs(cpl_parameter_get_range_max_double(first), \ - cpl_parameter_get_range_max_double(second), \ - DBL_EPSILON); \ - break; \ - default: \ - cpl_test_assert( \ - cpl_parameter_get_type(first) == CPL_TYPE_INT || \ - cpl_parameter_get_type(first) == CPL_TYPE_DOUBLE \ - ); \ - } \ - break; \ - case CPL_PARAMETER_CLASS_ENUM: \ - cpl_test_eq(cpl_parameter_get_enum_size(first), \ - cpl_parameter_get_enum_size(second)); \ - switch (cpl_parameter_get_type(first)) { \ - case CPL_TYPE_INT: \ - { \ - int n = 0; \ - for (n = 0; n < cpl_parameter_get_enum_size(first); ++n) { \ - cpl_test_eq(cpl_parameter_get_enum_int(first, n), \ - cpl_parameter_get_enum_int(second, n)); \ - } \ - } \ - break; \ - case CPL_TYPE_DOUBLE: \ - { \ - int n = 0; \ - for (n = 0; n < cpl_parameter_get_enum_size(first); ++n) { \ - cpl_test_abs(cpl_parameter_get_enum_double(first, n), \ - cpl_parameter_get_enum_double(second, n), \ - DBL_EPSILON); \ - } \ - } \ - break; \ - case CPL_TYPE_STRING: \ - { \ - int n = 0; \ - for (n = 0; n < cpl_parameter_get_enum_size(first); ++n) { \ - cpl_test_eq_string( \ - cpl_parameter_get_enum_string(first, n), \ - cpl_parameter_get_enum_string(second, n) \ - ); \ - } \ - } \ - break; \ - default: \ - cpl_test_assert( \ - cpl_parameter_get_type(first) == CPL_TYPE_INT || \ - cpl_parameter_get_type(first) == CPL_TYPE_DOUBLE || \ - cpl_parameter_get_type(first) == CPL_TYPE_STRING \ - ); \ - } \ - break; \ - default: \ - cpl_test_assert( \ - cpl_parameter_get_class(first) == CPL_PARAMETER_CLASS_VALUE || \ - cpl_parameter_get_class(first) == CPL_PARAMETER_CLASS_RANGE || \ - cpl_parameter_get_class(first) == CPL_PARAMETER_CLASS_ENUM \ - ); \ - } \ +#define test_equal_param(first, second) \ + cpl_test_eq(cpl_parameter_get_class(first), \ + cpl_parameter_get_class(second)); \ + cpl_test_eq(cpl_parameter_get_type(first), \ + cpl_parameter_get_type(second)); \ + cpl_test_eq_string(cpl_parameter_get_name(first), \ + cpl_parameter_get_name(second)); \ + cpl_test_eq_string(cpl_parameter_get_help(first), \ + cpl_parameter_get_help(second)); \ + cpl_test_eq_string(cpl_parameter_get_context(first), \ + cpl_parameter_get_context(second)); \ + test_equal_string(cpl_parameter_get_tag(first), \ + cpl_parameter_get_tag(second)); \ + cpl_test_eq(cpl_parameter_get_default_flag(first), \ + cpl_parameter_get_default_flag(second)); \ + cpl_test_eq(cpl_parameter_is_enabled(first, CPL_PARAMETER_MODE_CLI), \ + cpl_parameter_is_enabled(second, CPL_PARAMETER_MODE_CLI)); \ + cpl_test_eq(cpl_parameter_is_enabled(first, CPL_PARAMETER_MODE_ENV), \ + cpl_parameter_is_enabled(second, CPL_PARAMETER_MODE_ENV)); \ + cpl_test_eq(cpl_parameter_is_enabled(first, CPL_PARAMETER_MODE_CFG), \ + cpl_parameter_is_enabled(second, CPL_PARAMETER_MODE_CFG)); \ + test_equal_string(cpl_parameter_get_alias(first, CPL_PARAMETER_MODE_CLI), \ + cpl_parameter_get_alias(second, \ + CPL_PARAMETER_MODE_CLI)); \ + test_equal_string(cpl_parameter_get_alias(first, CPL_PARAMETER_MODE_ENV), \ + cpl_parameter_get_alias(second, \ + CPL_PARAMETER_MODE_ENV)); \ + test_equal_string(cpl_parameter_get_alias(first, CPL_PARAMETER_MODE_CFG), \ + cpl_parameter_get_alias(second, \ + CPL_PARAMETER_MODE_CFG)); \ + switch (cpl_parameter_get_type(first)) { \ + case CPL_TYPE_BOOL: \ + cpl_test_eq(cpl_parameter_get_bool(first), \ + cpl_parameter_get_bool(second)); \ + cpl_test_eq(cpl_parameter_get_default_bool(first), \ + cpl_parameter_get_default_bool(second)); \ + break; \ + case CPL_TYPE_INT: \ + cpl_test_eq(cpl_parameter_get_int(first), \ + cpl_parameter_get_int(second)); \ + cpl_test_eq(cpl_parameter_get_default_int(first), \ + cpl_parameter_get_default_int(second)); \ + break; \ + case CPL_TYPE_DOUBLE: \ + cpl_test_abs(cpl_parameter_get_double(first), \ + cpl_parameter_get_double(second), DBL_EPSILON); \ + cpl_test_abs(cpl_parameter_get_default_double(first), \ + cpl_parameter_get_default_double(second), \ + DBL_EPSILON); \ + break; \ + case CPL_TYPE_STRING: \ + cpl_test_eq_string(cpl_parameter_get_string(first), \ + cpl_parameter_get_string(second)); \ + cpl_test_eq_string(cpl_parameter_get_default_string(first), \ + cpl_parameter_get_default_string(second)); \ + break; \ + default: \ + cpl_test_assert(cpl_parameter_get_type(first) == CPL_TYPE_BOOL || \ + cpl_parameter_get_type(first) == CPL_TYPE_INT || \ + cpl_parameter_get_type(first) == \ + CPL_TYPE_DOUBLE || \ + cpl_parameter_get_type(first) == CPL_TYPE_STRING); \ + } \ + switch (cpl_parameter_get_class(first)) { \ + case CPL_PARAMETER_CLASS_RANGE: \ + switch (cpl_parameter_get_type(first)) { \ + case CPL_TYPE_INT: \ + cpl_test_eq(cpl_parameter_get_range_min_int(first), \ + cpl_parameter_get_range_min_int(second)); \ + cpl_test_eq(cpl_parameter_get_range_max_int(first), \ + cpl_parameter_get_range_max_int(second)); \ + break; \ + case CPL_TYPE_DOUBLE: \ + cpl_test_abs(cpl_parameter_get_range_min_double(first), \ + cpl_parameter_get_range_min_double(second), \ + DBL_EPSILON); \ + cpl_test_abs(cpl_parameter_get_range_max_double(first), \ + cpl_parameter_get_range_max_double(second), \ + DBL_EPSILON); \ + break; \ + default: \ + cpl_test_assert( \ + cpl_parameter_get_type(first) == CPL_TYPE_INT || \ + cpl_parameter_get_type(first) == CPL_TYPE_DOUBLE); \ + } \ + break; \ + case CPL_PARAMETER_CLASS_ENUM: \ + cpl_test_eq(cpl_parameter_get_enum_size(first), \ + cpl_parameter_get_enum_size(second)); \ + switch (cpl_parameter_get_type(first)) { \ + case CPL_TYPE_INT: { \ + int n = 0; \ + for (n = 0; n < cpl_parameter_get_enum_size(first); ++n) { \ + cpl_test_eq(cpl_parameter_get_enum_int(first, n), \ + cpl_parameter_get_enum_int(second, n)); \ + } \ + } break; \ + case CPL_TYPE_DOUBLE: { \ + int n = 0; \ + for (n = 0; n < cpl_parameter_get_enum_size(first); ++n) { \ + cpl_test_abs(cpl_parameter_get_enum_double(first, n), \ + cpl_parameter_get_enum_double(second, n), \ + DBL_EPSILON); \ + } \ + } break; \ + case CPL_TYPE_STRING: { \ + int n = 0; \ + for (n = 0; n < cpl_parameter_get_enum_size(first); ++n) { \ + cpl_test_eq_string( \ + cpl_parameter_get_enum_string(first, n), \ + cpl_parameter_get_enum_string(second, n)); \ + } \ + } break; \ + default: \ + cpl_test_assert( \ + cpl_parameter_get_type(first) == CPL_TYPE_INT || \ + cpl_parameter_get_type(first) == CPL_TYPE_DOUBLE || \ + cpl_parameter_get_type(first) == CPL_TYPE_STRING); \ + } \ + break; \ + default: \ + cpl_test_assert( \ + cpl_parameter_get_class(first) == CPL_PARAMETER_CLASS_VALUE || \ + cpl_parameter_get_class(first) == CPL_PARAMETER_CLASS_RANGE || \ + cpl_parameter_get_class(first) == CPL_PARAMETER_CLASS_ENUM); \ + } \ cpl_test_eq_error(cpl_error_get_code(), CPL_ERROR_NONE) /* Tests if two CPL frame objects are equal or not, i.e. are all their attributes the same or not. */ -#define test_equal_frame(first, second) \ - cpl_test_eq_string(cpl_frame_get_filename(first), \ - cpl_frame_get_filename(second)); \ - cpl_test_eq_string(cpl_frame_get_tag(first), \ - cpl_frame_get_tag(second)); \ - cpl_test_eq(cpl_frame_get_type(first), \ - cpl_frame_get_type(second)); \ - cpl_test_eq(cpl_frame_get_group(first), \ - cpl_frame_get_group(second)); \ - cpl_test_eq(cpl_frame_get_level(first), \ - cpl_frame_get_level(second)) +#define test_equal_frame(first, second) \ + cpl_test_eq_string(cpl_frame_get_filename(first), \ + cpl_frame_get_filename(second)); \ + cpl_test_eq_string(cpl_frame_get_tag(first), cpl_frame_get_tag(second)); \ + cpl_test_eq(cpl_frame_get_type(first), cpl_frame_get_type(second)); \ + cpl_test_eq(cpl_frame_get_group(first), cpl_frame_get_group(second)); \ + cpl_test_eq(cpl_frame_get_level(first), cpl_frame_get_level(second)) diff -Nru esorex-3.13.5+ds/src/tests/Makefile.am esorex-3.13.6+ds/src/tests/Makefile.am --- esorex-3.13.5+ds/src/tests/Makefile.am 2021-06-02 15:06:14.000000000 +0000 +++ esorex-3.13.6+ds/src/tests/Makefile.am 2022-04-29 16:21:07.000000000 +0000 @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in ## This file is part of the ESO Recipe Execution Tool -## Copyright (C) 2002-2017 European Southern Observatory +## Copyright (C) 2002-2022 European Southern Observatory ## 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