diff --git a/Makefile.in b/Makefile.in index 4e8978e9..07a10687 100644 --- a/Makefile.in +++ b/Makefile.in @@ -535,7 +535,7 @@ distdir: $(DISTFILES) $(MAKE) $(AM_MAKEFLAGS) \ top_distdir="$(top_distdir)" distdir="$(distdir)" \ dist-hook - -find $(distdir) -type d ! -perm -755 -exec chmod a+rwx,go+rx {} \; -o \ + -find $(distdir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \ ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \ ! -type d ! -perm -400 -exec chmod a+r {} \; -o \ ! -type d ! -perm -444 -exec $(SHELL) $(install_sh) -c -m a+r {} {} \; \ diff --git a/cobc/parser.y b/cobc/parser.y index a4b02008..3f6b0e30 100644 --- a/cobc/parser.y +++ b/cobc/parser.y @@ -459,6 +459,9 @@ setup_use_file (struct cb_file *fileptr) %token ENVIRONMENT %token ENVIRONMENT_NAME "ENVIRONMENT-NAME" %token ENVIRONMENT_VALUE "ENVIRONMENT-VALUE" +%token JSON_KEY "JSON-KEY" +%token JSON_NAME "JSON-NAME" +%token JSON_VALUE "JSON-VALUE" %token EOL %token EOP %token EOS @@ -737,6 +740,9 @@ setup_use_file (struct cb_file *fileptr) %token UPON_COMMAND_LINE "UPON COMMAND-LINE" %token UPON_ENVIRONMENT_NAME "UPON ENVIRONMENT-NAME" %token UPON_ENVIRONMENT_VALUE "UPON ENVIRONMENT-VALUE" +%token UPON_JSON_KEY "UPON JSON-KEY" +%token UPON_JSON_NAME "UPON JSON-NAME" +%token UPON_JSON_VALUE "UPON JSON-VALUE" %token UPPER_CASE_FUNC "FUNCTION UPPER-CASE" %token USAGE %token USE @@ -1339,6 +1345,34 @@ mnemonic_name_clause: cb_error (_("SPECIAL-NAMES with ENVIRONMENT-VALUE clause is not yet supported")); } } +| JSON_NAME _is undefined_word + { + if (cb_enable_special_names_environment_clause) { + save_tree_1 = lookup_system_name ("JSON-NAME"); + if (save_tree_1 == cb_error_node) { + cb_error_x ($1, _("Unknown system-name '%s'"), CB_NAME ($1)); + } else { + cb_define ($3, save_tree_1); + } + save_tree_2 = $3; + } else { + cb_error (_("SPECIAL-NAMES with JSON-NAME clause is not yet supported")); + } + } +| JSON_VALUE _is undefined_word + { + if (cb_enable_special_names_environment_clause) { + save_tree_1 = lookup_system_name ("JSON-VALUE"); + if (save_tree_1 == cb_error_node) { + cb_error_x ($1, _("Unknown system-name '%s'"), CB_NAME ($1)); + } else { + cb_define ($3, save_tree_1); + } + save_tree_2 = $3; + } else { + cb_error (_("SPECIAL-NAMES with JSON-VALUE clause is not yet supported")); + } + } ; special_name_mnemonic_on_off_list: @@ -4167,6 +4201,10 @@ accept_body: { cb_emit_accept_environment ($1); } +| identifier FROM JSON_VALUE on_accp_exception + { + cb_emit_accept_json ($1); + } | identifier FROM ENVIRONMENT simple_value on_accp_exception { cb_emit_get_environment ($4, $1); @@ -4185,6 +4223,7 @@ accept_body: } | identifier FROM WORD { + printf("word\n"); cb_emit_accept_name ($1, $3); } ; @@ -4614,6 +4653,18 @@ display_body: { cb_emit_env_value ($1); } +| id_or_lit UPON_JSON_KEY on_disp_exception + { + cb_emit_json_key ($1); + } +| id_or_lit UPON_JSON_NAME on_disp_exception + { + cb_emit_json_name ($1); + } +| id_or_lit UPON_JSON_VALUE on_disp_exception + { + cb_emit_json_value ($1); + } | id_or_lit UPON_ARGUMENT_NUMBER on_disp_exception { cb_emit_arg_number ($1); diff --git a/cobc/reserved.c b/cobc/reserved.c index 26de8b93..319dc080 100644 --- a/cobc/reserved.c +++ b/cobc/reserved.c @@ -75,6 +75,9 @@ static struct { {"ARGUMENT-VALUE", CB_INTERFACE_NAME, CB_ARGUMENT_VALUE, NULL}, {"ENVIRONMENT-NAME", CB_INTERFACE_NAME, CB_ENVIRONMENT_NAME, NULL}, {"ENVIRONMENT-VALUE", CB_INTERFACE_NAME, CB_ENVIRONMENT_VALUE, NULL}, + {"JSON-KEY", CB_INTERFACE_NAME, CB_JSON_NAME, NULL}, + {"JSON-NAME", CB_INTERFACE_NAME, CB_JSON_NAME, NULL}, + {"JSON-VALUE", CB_INTERFACE_NAME, CB_JSON_VALUE, NULL}, {NULL, 0, 0, NULL} }; @@ -364,6 +367,9 @@ static const struct reserved reserved_words[] = { {"INVALID", INVALID}, /* 2002 */ {"INVOKE", -1}, /* 2002 */ {"IS", IS}, /* 2002 */ + {"JSON-KEY", JSON_KEY}, /* extension */ + {"JSON-NAME", JSON_NAME}, /* extension */ + {"JSON-VALUE", JSON_VALUE}, /* extension */ {"JUST", JUSTIFIED}, /* 2002 */ {"JUSTIFIED", JUSTIFIED}, /* 2002 */ {"KEY", KEY}, /* 2002 */ diff --git a/cobc/scanner.l b/cobc/scanner.l index 0547a7e0..ac13eebc 100644 --- a/cobc/scanner.l +++ b/cobc/scanner.l @@ -485,6 +485,21 @@ H\"[^\"\n]*\" { return UPON_ENVIRONMENT_VALUE; } +"UPON"[ \t\n]+"JSON-KEY" { + count_lines (yytext); + return UPON_JSON_KEY; +} + +"UPON"[ \t\n]+"JSON-NAME" { + count_lines (yytext); + return UPON_JSON_NAME; +} + +"UPON"[ \t\n]+"JSON-VALUE" { + count_lines (yytext); + return UPON_JSON_VALUE; +} + "UPON"[ \t\n]+"ARGUMENT-NUMBER" { count_lines (yytext); return UPON_ARGUMENT_NUMBER; diff --git a/cobc/scanner.l.m4 b/cobc/scanner.l.m4 index f9fbfb37..67450e5f 100644 --- a/cobc/scanner.l.m4 +++ b/cobc/scanner.l.m4 @@ -497,6 +497,21 @@ H\"[^\"\n]*\" { return UPON_ENVIRONMENT_VALUE; } +"UPON"[ \t\n]+"JSON-KEY" { + count_lines (yytext); + return UPON_JSON_KEY; +} + +"UPON"[ \t\n]+"JSON-NAME" { + count_lines (yytext); + return UPON_JSON_NAME; +} + +"UPON"[ \t\n]+"JSON-VALUE" { + count_lines (yytext); + return UPON_JSON_VALUE; +} + "UPON"[ \t\n]+"ARGUMENT-NUMBER" { count_lines (yytext); return UPON_ARGUMENT_NUMBER; diff --git a/cobc/tree.h b/cobc/tree.h index 737d0cb4..82fb043f 100644 --- a/cobc/tree.h +++ b/cobc/tree.h @@ -142,7 +142,9 @@ enum cb_interface_name { CB_ARGUMENT_NUMBER, CB_ARGUMENT_VALUE, CB_ENVIRONMENT_NAME, - CB_ENVIRONMENT_VALUE + CB_ENVIRONMENT_VALUE, + CB_JSON_NAME, + CB_JSON_VALUE }; enum cb_class { @@ -1408,6 +1410,7 @@ extern void cb_emit_accept_time (cb_tree var); extern void cb_emit_accept_command_line (cb_tree var); extern void cb_emit_get_environment (cb_tree envvar, cb_tree envval); extern void cb_emit_accept_environment (cb_tree var); +extern void cb_emit_accept_json (cb_tree var); extern void cb_emit_accept_mnemonic (cb_tree var, cb_tree mnemonic); extern void cb_emit_accept_name (cb_tree var, cb_tree name); extern void cb_emit_accept_arg_number (cb_tree var); @@ -1446,6 +1449,9 @@ extern cb_tree cb_build_display_upon (cb_tree x); extern cb_tree cb_build_display_upon_direct (cb_tree x); extern void cb_emit_env_name (cb_tree value); extern void cb_emit_env_value (cb_tree value); +extern void cb_emit_json_key (cb_tree value); +extern void cb_emit_json_name (cb_tree value); +extern void cb_emit_json_value (cb_tree value); extern void cb_emit_arg_number (cb_tree value); extern void cb_emit_command_line (cb_tree value); diff --git a/cobc/typeck.c b/cobc/typeck.c index 9b3e5322..a6894b9e 100644 --- a/cobc/typeck.c +++ b/cobc/typeck.c @@ -3365,6 +3365,15 @@ cb_emit_accept_environment (cb_tree var) cb_emit (cb_build_funcall_1 ("cob_accept_environment", var)); } +void +cb_emit_accept_json (cb_tree var) +{ + if (cb_validate_one (var)) { + return; + } + cb_emit (cb_build_funcall_1 ("cob_accept_json", var)); +} + void cb_emit_accept_arg_number (cb_tree var) { @@ -3412,6 +3421,9 @@ cb_emit_accept_mnemonic (cb_tree var, cb_tree mnemonic) case CB_ENVIRONMENT_VALUE: cb_emit_accept_environment (var); break; + case CB_JSON_VALUE: + cb_emit_accept_json (var); + break; default: cb_error_x (mnemonic, _("Invalid interface name '%s'"), cb_name (mnemonic)); @@ -3443,7 +3455,6 @@ cb_emit_accept_name (cb_tree var, cb_tree name) } } } - cb_error_x (name, _("'%s' undefined in SPECIAL-NAMES"), CB_NAME (name)); } @@ -3699,6 +3710,33 @@ cb_emit_env_value (cb_tree value) cb_emit (cb_build_funcall_1 ("cob_display_env_value", value)); } +void +cb_emit_json_key (cb_tree value) +{ + if (cb_validate_one (value)) { + return; + } + cb_emit (cb_build_funcall_1 ("cob_display_json_key", value)); +} + +void +cb_emit_json_name (cb_tree value) +{ + if (cb_validate_one (value)) { + return; + } + cb_emit (cb_build_funcall_1 ("cob_display_json", value)); +} + +void +cb_emit_json_value (cb_tree value) +{ + if (cb_validate_one (value)) { + return; + } + cb_emit (cb_build_funcall_1 ("cob_display_json_value", value)); +} + void cb_emit_arg_number (cb_tree value) { @@ -3849,6 +3887,12 @@ cb_emit_display_mnemonic (cb_tree values, cb_tree mnemonic, cb_tree no_adv, case CB_ENVIRONMENT_VALUE: cb_emit_env_value (v); break; + case CB_JSON_NAME: + cb_emit_json_name (v); + break; + case CB_JSON_VALUE: + cb_emit_json_value (v); + break; default: cb_error_x (mnemonic, _("Invalid interface name '%s'"), cb_name (mnemonic)); break; diff --git a/config.h.in b/config.h.in index 81964d3b..3c0d4703 100644 --- a/config.h.in +++ b/config.h.in @@ -134,6 +134,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_ISAM_H +/* Define to 1 if you have the header file. */ +#undef HAVE_JANSSON_H + /* Define to 1 if you have the header file. */ #undef HAVE_KPATHSEA_GETOPT_H @@ -152,6 +155,9 @@ /* Define to 1 if you have the `ifisam' library (-lifisam). */ #undef HAVE_LIBIFISAM +/* Define to 1 if you have the `jansson' library (-ljansson). */ +#undef HAVE_LIBJANSSON + /* Define to 1 if you have the `ltdl' library (-lltdl). */ #undef HAVE_LIBLTDL @@ -328,6 +334,9 @@ /* Compile with an external ISAM handler */ #undef WITH_INDEX_EXTFH +/* use json function with jansson */ +#undef WITH_JANSSON + /* Compile with an external SEQ/RAN handler */ #undef WITH_SEQRA_EXTFH diff --git a/configure b/configure index ba320c86..cb2cfa56 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.59 for OpenCOBOL 1.1. +# Generated by GNU Autoconf 2.59 for opensource COBOL 1.5.2. # # Report bugs to . # @@ -424,7 +424,7 @@ SHELL=${CONFIG_SHELL-/bin/sh} PACKAGE_NAME='opensource COBOL' PACKAGE_TARNAME='opensource-cobol-1.5.2J' PACKAGE_VERSION='1.5.2' -PACKAGE_STRING='opensource COBOL 1.5.2J' +PACKAGE_STRING='opensource COBOL 1.5.2' PACKAGE_BUGREPORT='ws-opensource-cobol-contact@osscons.jp' ac_unique_file="libcob.h" @@ -938,7 +938,7 @@ if test "$ac_init_help" = "long"; then # 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 OpenCOBOL 1.1 to adapt to many kinds of systems. +\`configure' configures opensource COBOL 1.5.2 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1004,7 +1004,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of OpenCOBOL 1.1:";; + short | recursive ) echo "Configuration of opensource COBOL 1.5.2:";; esac cat <<\_ACEOF @@ -1043,6 +1043,7 @@ Optional Packages: --with-dl (OpenCOBOL) use system dynamic loader (default) --with-patch-level (OpenCOBOL) define a patch level (default 0) --with-varseq (OpenCOBOL) define variable sequential format (default 0) + --with-jansson (OpenCOBOL) Use jansson for JSON function --with-gnu-ld assume the C compiler uses GNU ld [default=no] --with-pic try to use only PIC/non-PIC objects [default=use both] @@ -1163,7 +1164,7 @@ fi test -n "$ac_init_help" && exit 0 if $ac_init_version; then cat <<\_ACEOF -OpenCOBOL configure 1.1 +opensource COBOL configure 1.5.2 generated by GNU Autoconf 2.59 Copyright (C) 2003 Free Software Foundation, Inc. @@ -1177,7 +1178,7 @@ cat >&5 <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by OpenCOBOL $as_me 1.1, which was +It was created by opensource COBOL $as_me 1.5.2, which was generated by GNU Autoconf 2.59. Invocation command line was $ $0 $@ @@ -2071,6 +2072,8 @@ fi + + @@ -3614,9 +3617,9 @@ echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >& echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} ( cat <<\_ASBOX -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## ## Report this to ws-opensource-cobol-contact@osscons.jp ## -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## _ASBOX ) | sed "s/^/$as_me: WARNING: /" >&2 @@ -3863,9 +3866,9 @@ echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >& echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} ( cat <<\_ASBOX -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## ## Report this to ws-opensource-cobol-contact@osscons.jp ## -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## _ASBOX ) | sed "s/^/$as_me: WARNING: /" >&2 @@ -4113,9 +4116,9 @@ echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >& echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} ( cat <<\_ASBOX -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## ## Report this to ws-opensource-cobol-contact@osscons.jp ## -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## _ASBOX ) | sed "s/^/$as_me: WARNING: /" >&2 @@ -4448,6 +4451,255 @@ cat >>confdefs.h <<_ACEOF _ACEOF +USE_JSON=none + + +# Check whether --with-jansson or --without-jansson was given. +if test "${with_jansson+set}" = set; then + withval="$with_jansson" + if test "$with_jansson" = "yes" + then + +for ac_header in jansson.h +do +as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 +else + # Is the header compilable? +echo "$as_me:$LINENO: checking $ac_header usability" >&5 +echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +#include <$ac_header> +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_header_compiler=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_header_compiler=no +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext +echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 +echo "${ECHO_T}$ac_header_compiler" >&6 + +# Is the header present? +echo "$as_me:$LINENO: checking $ac_header presence" >&5 +echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include <$ac_header> +_ACEOF +if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 + (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_c_preproc_warn_flag + ac_cpp_err=$ac_cpp_err$ac_c_werror_flag + else + ac_cpp_err= + fi +else + ac_cpp_err=yes +fi +if test -z "$ac_cpp_err"; then + ac_header_preproc=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_header_preproc=no +fi +rm -f conftest.err conftest.$ac_ext +echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 +echo "${ECHO_T}$ac_header_preproc" >&6 + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in + yes:no: ) + { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 +echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 +echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} + ac_header_preproc=yes + ;; + no:yes:* ) + { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 +echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 +echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 +echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 +echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 +echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 +echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} + ( + cat <<\_ASBOX +## ----------------------------------------------------- ## +## Report this to ws-opensource-cobol-contact@osscons.jp ## +## ----------------------------------------------------- ## +_ASBOX + ) | + sed "s/^/$as_me: WARNING: /" >&2 + ;; +esac +echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + eval "$as_ac_Header=\$ac_header_preproc" +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 + +fi +if test `eval echo '${'$as_ac_Header'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +else + { { echo "$as_me:$LINENO: error: jansson.h is required for JSON function" >&5 +echo "$as_me: error: jansson.h is required for JSON function" >&2;} + { (exit 1); exit 1; }; } +fi + +done + + +echo "$as_me:$LINENO: checking for json_loads in -ljansson" >&5 +echo $ECHO_N "checking for json_loads in -ljansson... $ECHO_C" >&6 +if test "${ac_cv_lib_jansson_json_loads+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ljansson $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char json_loads (); +int +main () +{ +json_loads (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_jansson_json_loads=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_jansson_json_loads=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_jansson_json_loads" >&5 +echo "${ECHO_T}$ac_cv_lib_jansson_json_loads" >&6 +if test $ac_cv_lib_jansson_json_loads = yes; then + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBJANSSON 1 +_ACEOF + + LIBS="-ljansson $LIBS" + +else + { { echo "$as_me:$LINENO: error: libjansson is required for JSON function" >&5 +echo "$as_me: error: libjansson is required for JSON function" >&2;} + { (exit 1); exit 1; }; } +fi + + cat >>confdefs.h <<\_ACEOF +#define WITH_JANSSON 1 +_ACEOF + + LIBCOB_LIBS="$LIBCOB_LIBS -ljansson" + USE_JSON=jansson + fi +fi; + # Checks for programs. # Stop the stupid tests for C++ and Fortran @@ -5152,7 +5404,7 @@ ia64-*-hpux*) ;; *-*-irix6*) # Find out which ABI we are using. - echo '#line 5155 "configure"' > conftest.$ac_ext + echo '#line 5407 "configure"' > conftest.$ac_ext if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 (eval $ac_compile) 2>&5 ac_status=$? @@ -5705,9 +5957,9 @@ echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >& echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} ( cat <<\_ASBOX -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## ## Report this to ws-opensource-cobol-contact@osscons.jp ## -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## _ASBOX ) | sed "s/^/$as_me: WARNING: /" >&2 @@ -6894,11 +7146,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:6897: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7149: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:6901: \$? = $ac_status" >&5 + echo "$as_me:7153: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -7184,11 +7436,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7187: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7439: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:7191: \$? = $ac_status" >&5 + echo "$as_me:7443: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -7288,11 +7540,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7291: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7543: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:7295: \$? = $ac_status" >&5 + echo "$as_me:7547: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -9674,7 +9926,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext < conftest.$ac_ext <&5) + (eval echo "\"\$as_me:12453: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:12205: \$? = $ac_status" >&5 + echo "$as_me:12457: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -12302,11 +12554,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:12305: $lt_compile\"" >&5) + (eval echo "\"\$as_me:12557: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:12309: \$? = $ac_status" >&5 + echo "$as_me:12561: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -13864,11 +14116,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:13867: $lt_compile\"" >&5) + (eval echo "\"\$as_me:14119: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:13871: \$? = $ac_status" >&5 + echo "$as_me:14123: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -13968,11 +14220,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:13971: $lt_compile\"" >&5) + (eval echo "\"\$as_me:14223: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:13975: \$? = $ac_status" >&5 + echo "$as_me:14227: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -16160,11 +16412,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:16163: $lt_compile\"" >&5) + (eval echo "\"\$as_me:16415: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:16167: \$? = $ac_status" >&5 + echo "$as_me:16419: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -16450,11 +16702,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:16453: $lt_compile\"" >&5) + (eval echo "\"\$as_me:16705: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:16457: \$? = $ac_status" >&5 + echo "$as_me:16709: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -16554,11 +16806,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:16557: $lt_compile\"" >&5) + (eval echo "\"\$as_me:16809: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:16561: \$? = $ac_status" >&5 + echo "$as_me:16813: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -19540,9 +19792,9 @@ echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >& echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} ( cat <<\_ASBOX -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## ## Report this to ws-opensource-cobol-contact@osscons.jp ## -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## _ASBOX ) | sed "s/^/$as_me: WARNING: /" >&2 @@ -21914,9 +22166,9 @@ echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >& echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} ( cat <<\_ASBOX -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## ## Report this to ws-opensource-cobol-contact@osscons.jp ## -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## _ASBOX ) | sed "s/^/$as_me: WARNING: /" >&2 @@ -22086,9 +22338,9 @@ echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >& echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} ( cat <<\_ASBOX -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## ## Report this to ws-opensource-cobol-contact@osscons.jp ## -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## _ASBOX ) | sed "s/^/$as_me: WARNING: /" >&2 @@ -23792,9 +24044,9 @@ echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >& echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} ( cat <<\_ASBOX -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## ## Report this to ws-opensource-cobol-contact@osscons.jp ## -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## _ASBOX ) | sed "s/^/$as_me: WARNING: /" >&2 @@ -23939,9 +24191,9 @@ echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >& echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} ( cat <<\_ASBOX -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## ## Report this to ws-opensource-cobol-contact@osscons.jp ## -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## _ASBOX ) | sed "s/^/$as_me: WARNING: /" >&2 @@ -24171,9 +24423,9 @@ echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >& echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} ( cat <<\_ASBOX -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## ## Report this to ws-opensource-cobol-contact@osscons.jp ## -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## _ASBOX ) | sed "s/^/$as_me: WARNING: /" >&2 @@ -24399,9 +24651,9 @@ echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >& echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} ( cat <<\_ASBOX -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## ## Report this to ws-opensource-cobol-contact@osscons.jp ## -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## _ASBOX ) | sed "s/^/$as_me: WARNING: /" >&2 @@ -24620,9 +24872,9 @@ echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >& echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} ( cat <<\_ASBOX -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## ## Report this to ws-opensource-cobol-contact@osscons.jp ## -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## _ASBOX ) | sed "s/^/$as_me: WARNING: /" >&2 @@ -24997,9 +25249,9 @@ echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >& echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} ( cat <<\_ASBOX -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## ## Report this to ws-opensource-cobol-contact@osscons.jp ## -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## _ASBOX ) | sed "s/^/$as_me: WARNING: /" >&2 @@ -26486,9 +26738,9 @@ echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >& echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} ( cat <<\_ASBOX -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## ## Report this to ws-opensource-cobol-contact@osscons.jp ## -## ---------------------------------------------------- ## +## ----------------------------------------------------- ## _ASBOX ) | sed "s/^/$as_me: WARNING: /" >&2 @@ -27421,7 +27673,7 @@ _ASBOX } >&5 cat >&5 <<_CSEOF -This file was extended by OpenCOBOL $as_me 1.1, which was +This file was extended by opensource COBOL $as_me 1.5.2, which was generated by GNU Autoconf 2.59. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -27484,7 +27736,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF ac_cs_version="\\ -OpenCOBOL config.status 1.1 +opensource COBOL config.status 1.5.2 configured by $0, generated by GNU Autoconf 2.59, with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\" @@ -28718,4 +28970,5 @@ else fi echo " Use fcntl for file locking: ${ac_cv_func_fcntl}" echo " Use ncurses/pdcurses/curses for screen I/O: ${USE_NCURSES}" +echo " Use json library: ${USE_JSON}" echo "" diff --git a/configure.ac b/configure.ac index 4bc7187c..3e1be5f0 100644 --- a/configure.ac +++ b/configure.ac @@ -84,6 +84,7 @@ AH_TEMPLATE([COB_NO_SELFOPEN], [Can not dlopen self]) AH_TEMPLATE([COB_STRFTIME], [Can use strftime for timezone]) AH_TEMPLATE([COB_LI_IS_LL], [long int is long long]) AH_TEMPLATE([HAVE_COLOR_SET], [curses has color_set function]) +AH_TEMPLATE([WITH_JANSSON], [use json function with jansson]) AC_DEFINE(__USE_STRING_INLINES) @@ -275,6 +276,19 @@ AC_ARG_WITH(varseq, [ --with-varseq (OpenCOBOL) define variable seque esac]) AC_DEFINE_UNQUOTED(WITH_VARSEQ, $WITH_VARSEQ) +USE_JSON=none + +AC_ARG_WITH(jansson, + [ --with-jansson (OpenCOBOL) Use jansson for JSON function], + [ if test "$with_jansson" = "yes" + then + AC_CHECK_HEADERS([jansson.h], , AC_MSG_ERROR(jansson.h is required for JSON function)) + AC_CHECK_LIB([jansson], [json_loads], , AC_MSG_ERROR(libjansson is required for JSON function)) + AC_DEFINE(WITH_JANSSON) + LIBCOB_LIBS="$LIBCOB_LIBS -ljansson" + USE_JSON=jansson + fi ], []) + # Checks for programs. # Stop the stupid tests for C++ and Fortran AC_PROVIDE([AC_PROG_F77]) @@ -864,4 +878,5 @@ else fi echo " Use fcntl for file locking: ${ac_cv_func_fcntl}" echo " Use ncurses/pdcurses/curses for screen I/O: ${USE_NCURSES}" +echo " Use json library: ${USE_JSON}" echo "" diff --git a/libcob.h b/libcob.h index b0fbf04b..88368a2c 100644 --- a/libcob.h +++ b/libcob.h @@ -38,6 +38,7 @@ extern "C" { #include #include #include +#include #ifdef __cplusplus } diff --git a/libcob/Makefile.am b/libcob/Makefile.am index 393a37f9..fb2a6b3a 100644 --- a/libcob/Makefile.am +++ b/libcob/Makefile.am @@ -22,7 +22,7 @@ lib_LTLIBRARIES = libcob.la libcob_la_SOURCES = common.c call.c strings.c move.c numeric.c \ - intrinsic.c fileio.c termio.c screenio.c + intrinsic.c fileio.c termio.c screenio.c json.c libcob_la_CFLAGS = $(AM_CFLAGS) $(LIBCOB_CFLAGS) -I$(top_srcdir) libcob_la_LIBADD = $(LIBCOB_LIBS) @@ -33,4 +33,4 @@ EXTRA_DIST = coblocal.h pkgincludedir = $(includedir)/libcob pkginclude_HEADERS = byteswap.h common.h move.h numeric.h exception.def \ termio.h fileio.h screenio.h strings.h call.h intrinsic.h \ - codegen.h system.def + codegen.h system.def json.h diff --git a/libcob/Makefile.in b/libcob/Makefile.in index 56a2402d..72e23c24 100644 --- a/libcob/Makefile.in +++ b/libcob/Makefile.in @@ -87,7 +87,7 @@ libcob_la_DEPENDENCIES = $(am__DEPENDENCIES_1) am_libcob_la_OBJECTS = libcob_la-common.lo libcob_la-call.lo \ libcob_la-strings.lo libcob_la-move.lo libcob_la-numeric.lo \ libcob_la-intrinsic.lo libcob_la-fileio.lo libcob_la-termio.lo \ - libcob_la-screenio.lo + libcob_la-screenio.lo libcob_la-json.lo libcob_la_OBJECTS = $(am_libcob_la_OBJECTS) DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -244,7 +244,7 @@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ lib_LTLIBRARIES = libcob.la libcob_la_SOURCES = common.c call.c strings.c move.c numeric.c \ - intrinsic.c fileio.c termio.c screenio.c + intrinsic.c fileio.c termio.c screenio.c json.c libcob_la_CFLAGS = $(AM_CFLAGS) $(LIBCOB_CFLAGS) -I$(top_srcdir) libcob_la_LIBADD = $(LIBCOB_LIBS) @@ -253,7 +253,7 @@ AM_LDFLAGS = $(COB_FIX_LIB) EXTRA_DIST = coblocal.h pkginclude_HEADERS = byteswap.h common.h move.h numeric.h exception.def \ termio.h fileio.h screenio.h strings.h call.h intrinsic.h \ - codegen.h system.def + codegen.h system.def json.h all: all-am @@ -328,6 +328,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcob_la-common.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcob_la-fileio.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcob_la-intrinsic.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcob_la-json.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcob_la-move.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcob_la-numeric.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcob_la-screenio.Plo@am__quote@ @@ -418,6 +419,13 @@ libcob_la-screenio.lo: screenio.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcob_la_CFLAGS) $(CFLAGS) -c -o libcob_la-screenio.lo `test -f 'screenio.c' || echo '$(srcdir)/'`screenio.c +libcob_la-json.lo: json.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcob_la_CFLAGS) $(CFLAGS) -MT libcob_la-json.lo -MD -MP -MF "$(DEPDIR)/libcob_la-json.Tpo" -c -o libcob_la-json.lo `test -f 'json.c' || echo '$(srcdir)/'`json.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libcob_la-json.Tpo" "$(DEPDIR)/libcob_la-json.Plo"; else rm -f "$(DEPDIR)/libcob_la-json.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='json.c' object='libcob_la-json.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcob_la_CFLAGS) $(CFLAGS) -c -o libcob_la-json.lo `test -f 'json.c' || echo '$(srcdir)/'`json.c + mostlyclean-libtool: -rm -f *.lo diff --git a/libcob/json.c b/libcob/json.c new file mode 100644 index 00000000..6f502263 --- /dev/null +++ b/libcob/json.c @@ -0,0 +1,417 @@ +/* + * Copyright (C) 2019 Tokyo System House co.,ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1, + * or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; see the file COPYING.LIB. If + * not, write to the Free Software Foundation, 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "defaults.h" + +#include +#include + +#ifdef HAVE_JANSSON_H +#include +#endif + +/* Force symbol exports */ +#define COB_LIB_EXPIMP + +#include "libcob.h" +#include "coblocal.h" +#include "lib/gettext.h" + +/* Local functions */ +static void +cob_hankaku_memcpy (cob_field *dst, unsigned char *src, const int size) +{ + cob_field temp; + cob_field_attr attr; + + COB_ATTR_INIT (COB_TYPE_ALPHANUMERIC, 0, 0, 0, NULL); + temp.size = size; + temp.data = src; + temp.attr = &attr; + cob_hankaku_move (&temp, dst); +} + +int +CBL_JSON_PARSE (unsigned char *b1, unsigned char *json_pointer_buf) +{ +#ifdef HAVE_JANSSON_H + cob_field *json_field; + char *json_str; + json_t *json; + json_error_t error; + + COB_CHK_PARMS (CBL_JSON_PARSE, 2); + + if (!cob_current_module->cob_procedure_parameters[0]) { + // TODO + return -1; + } + if (!cob_current_module->cob_procedure_parameters[1]) { + // TODO + return -1; + } + + json_field = cob_current_module->cob_procedure_parameters[0]; + + //parse json + json_str = cob_malloc (json_field->size + 1); + cob_field_to_string (json_field, json_str); + + json = json_loads (json_str, 0, &error); + if (json == NULL) { + // TODO + fputs ("COBOL JSON PARSE ERROR\n", stderr); + fputs (error.text, stderr); + free(json_str); + return -1; + } + + free(json_str); + memcpy(json_pointer_buf, &json, sizeof(void *)); +#endif + return 0; +} + +int +CBL_JSON_FREE (unsigned char *json_pointer_buf) +{ +#ifdef HAVE_JANSSON_H + json_t *json; + + COB_CHK_PARMS (CBL_JSON_GET_ARRLEN, 1); + + if (!cob_current_module->cob_procedure_parameters[0]) { + // TODO + return -1; + } + + memcpy(&json, json_pointer_buf, sizeof(void *)); + + json_decref(json); +#endif + return 0; +} + +int +CBL_JSON_GET_TYPE (unsigned char *json_pointer_buf) +{ +#ifdef HAVE_JANSSON_H + json_t *json; + + COB_CHK_PARMS (CBL_JSON_GET_TYPE, 1); + + if (!cob_current_module->cob_procedure_parameters[0]) { + // TODO + return -2; + } + + memcpy(&json, json_pointer_buf, sizeof(void *)); + return json_typeof(json); +#endif + return -1; +} + +int +CBL_JSON_GET_KEY_START (unsigned char *json_pointer_buf, + unsigned char *iter_pointer_buf) +{ +#ifdef HAVE_JANSSON_H + + json_t *json; + void *iter; + + COB_CHK_PARMS (CBL_JSON_GET_KEY_START, 2); + + if (!cob_current_module->cob_procedure_parameters[0]) { + // TODO + return -1; + } + if (!cob_current_module->cob_procedure_parameters[1]) { + // TODO + return -1; + } + + memcpy(&json, json_pointer_buf, sizeof(void *)); + + iter = json_object_iter(json); + memcpy(iter_pointer_buf, &iter, sizeof(void *)); +#endif + return 0; +} + +int +CBL_JSON_GET_KEY_NEXT (unsigned char *json_pointer_buf, + unsigned char *iter_pointer_buf, + unsigned char *key_buf) +{ + +#ifdef HAVE_JANSSON_H + json_t *json; + void *iter; + cob_field *key_field; + const char *key; + + COB_CHK_PARMS (CBL_JSON_GET_KEY_NEXT, 3); + + if (!cob_current_module->cob_procedure_parameters[0]) { + // TODO + return -1; + } + if (!cob_current_module->cob_procedure_parameters[1]) { + // TODO + return -1; + } + if (!cob_current_module->cob_procedure_parameters[2]) { + // TODO + return -1; + } + + key_field = cob_current_module->cob_procedure_parameters[2]; + + memcpy(&json, json_pointer_buf, sizeof(void *)); + memcpy(&iter, iter_pointer_buf, sizeof(void *)); + + if (iter == NULL) { + // EOF + return 10; + } + + key = json_object_iter_key (iter); + iter = json_object_iter_next (json, iter); + + cob_hankaku_memcpy (key_field, (ucharptr)key, (int) strlen (key)); + memcpy(iter_pointer_buf, &iter, sizeof(void *)); +#endif + return 0; +} + +int +CBL_JSON_GET_ARRLEN (unsigned char *json_pointer_buf) +{ +#ifdef HAVE_JANSSON_H + json_t *json; + + COB_CHK_PARMS (CBL_JSON_GET_ARRLEN, 1); + + if (!cob_current_module->cob_procedure_parameters[0]) { + // TODO + return -1; + } + + memcpy(&json, json_pointer_buf, sizeof(void *)); + + return json_array_size(json); +#endif + return 0; +} + +int +CBL_JSON_GET_VALUE (unsigned char *json_pointer_buf, + unsigned char *value_buf) +{ +#ifdef HAVE_JANSSON_H + json_t *json; + cob_field *value_filed; + char p[COB_SMALL_BUFF]; + + COB_CHK_PARMS (CBL_JSON_GET_VALUE, 2); + + if (!cob_current_module->cob_procedure_parameters[0]) { + // TODO + return -1; + } + if (!cob_current_module->cob_procedure_parameters[1]) { + // TODO + return -1; + } + + memcpy(&json, json_pointer_buf, sizeof(void *)); + value_filed = cob_current_module->cob_procedure_parameters[1]; + + memset (p, 0, COB_SMALL_BUFF); + if(json_is_string (json)) { + snprintf (p, COB_SMALL_BUFF, "%s", json_string_value (json)); + } else if (json_is_integer (json)) { + snprintf (p, COB_SMALL_BUFF, "%g", json_number_value (json)); + } + cob_hankaku_memcpy (value_filed, (unsigned char *)p, (int) strlen (p)); +#endif + return 0; +} + +int +CBL_JSON_GET_OBJECT (unsigned char *json_pointer_buf, + unsigned char *key_buf, + unsigned char *new_json_pointer_buf) +{ +#ifdef HAVE_JANSSON_H + json_t *json; + json_t *new_json; + cob_field *key_field; + char *key; + + COB_CHK_PARMS (CBL_JSON_GET_OBJECT, 3); + + if (!cob_current_module->cob_procedure_parameters[0]) { + // TODO + return -1; + } + if (!cob_current_module->cob_procedure_parameters[1]) { + // TODO + return -1; + } + if (!cob_current_module->cob_procedure_parameters[2]) { + // TODO + return -1; + } + + key_field = cob_current_module->cob_procedure_parameters[1]; + key = cob_malloc (key_field->size + 1); + cob_field_to_string (key_field, key); + + memcpy(&json, json_pointer_buf, sizeof(void *)); + + new_json = json_object_get (json, (const char *)key); + memcpy(new_json_pointer_buf, &new_json, sizeof(void *)); +#endif + return 0; +} + +int +CBL_JSON_GET_OBJECT_L (unsigned char *json_pointer_buf, + unsigned char *key_buf, + unsigned char *new_json_pointer_buf) +{ +#ifdef HAVE_JANSSON_H + json_t *json; + json_t *new_json; + cob_field *key_field; + char *key; + char *tok; + char *start_adr; + char *end_adr; + char buf[COB_SMALL_BUFF]; + int array_index; + + COB_CHK_PARMS (CBL_JSON_GET_OBJECT, 3); + + if (!cob_current_module->cob_procedure_parameters[0]) { + // TODO + return -1; + } + if (!cob_current_module->cob_procedure_parameters[1]) { + // TODO + return -1; + } + if (!cob_current_module->cob_procedure_parameters[2]) { + // TODO + return -1; + } + + key_field = cob_current_module->cob_procedure_parameters[1]; + key = cob_malloc (key_field->size + 1); + cob_field_to_string (key_field, key); + + memcpy(&json, json_pointer_buf, sizeof(void *)); + new_json = json; + + tok = strtok (key, "."); + + while (tok != NULL) { + start_adr = strchr (tok, (int)'['); + end_adr = strchr (tok, (int)']'); + if (start_adr && end_adr && (start_adr < end_adr)) { + memset (buf, 0, COB_SMALL_BUFF); + strncpy (buf, tok, start_adr - tok); + new_json = json_object_get (new_json, buf); + + if (!json_is_array (new_json)) { + // TODO + free (key); + return -3; + } + + memset (buf, 0, COB_SMALL_BUFF); + strncpy (buf, start_adr + 1, end_adr - start_adr - 1); + array_index = atoi (buf); + new_json = json_array_get (new_json, array_index); + } else { + new_json = json_object_get (new_json, tok); + } + + tok = strtok(NULL, "."); + } + + if (!new_json) { + // TODO + free (key); + return -4; + } + + memcpy(new_json_pointer_buf, &new_json, sizeof(void *)); + free (key); +#endif + return 0; +} + +int +CBL_JSON_GET_OBJECT_A (unsigned char *json_pointer_buf, + unsigned char *index_buf, + unsigned char *new_json_pointer_buf) +{ +#ifdef HAVE_JANSSON_H + json_t *json; + json_t *new_json; + cob_field *index_field; + int index; + cob_field_attr attr; + cob_field temp; + + COB_CHK_PARMS (CBL_JSON_GET_OBJECT, 3); + + if (!cob_current_module->cob_procedure_parameters[0]) { + // TODO + return -1; + } + if (!cob_current_module->cob_procedure_parameters[1]) { + // TODO + return -1; + } + if (!cob_current_module->cob_procedure_parameters[2]) { + // TODO + return -1; + } + + index_field = cob_current_module->cob_procedure_parameters[1]; + + COB_ATTR_INIT (COB_TYPE_NUMERIC_BINARY, sizeof(int), 0, 0, NULL); + + temp.size = sizeof(int); + temp.data = (unsigned char *)&index; + temp.attr = &attr; + cob_move (index_field, &temp); + + memcpy(&json, json_pointer_buf, sizeof(void *)); + + new_json = json_array_get (json, index); + memcpy(new_json_pointer_buf, &new_json, sizeof(void *)); +#endif + return 0; +} diff --git a/libcob/json.h b/libcob/json.h new file mode 100644 index 00000000..288e3d3c --- /dev/null +++ b/libcob/json.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2019 Tokyo System House co.,ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1, + * or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; see the file COPYING.LIB. If + * not, write to the Free Software Foundation, 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ + +#ifndef COB_JSON_H +#define COB_JSON_H + +/* JSON functions */ +COB_EXPIMP int CBL_JSON_PARSE (unsigned char *, unsigned char *); +COB_EXPIMP int CBL_JSON_FREE (unsigned char *); +COB_EXPIMP int CBL_JSON_GET_TYPE (unsigned char *); +COB_EXPIMP int CBL_JSON_GET_KEY_START (unsigned char *, unsigned char *); +COB_EXPIMP int CBL_JSON_GET_KEY_NEXT (unsigned char *, unsigned char *, unsigned char *); +COB_EXPIMP int CBL_JSON_GET_ARRLEN (unsigned char *); +COB_EXPIMP int CBL_JSON_GET_VALUE (unsigned char *, unsigned char *); +COB_EXPIMP int CBL_JSON_GET_OBJECT (unsigned char *, unsigned char *, unsigned char *); +COB_EXPIMP int CBL_JSON_GET_OBJECT_L (unsigned char *, unsigned char *, unsigned char *); +COB_EXPIMP int CBL_JSON_GET_OBJECT_A (unsigned char *, unsigned char *, unsigned char *); + +#endif /* COB_JSON_H */ diff --git a/libcob/system.def b/libcob/system.def index 6c6810ac..abcfc86b 100644 --- a/libcob/system.def +++ b/libcob/system.def @@ -66,6 +66,17 @@ COB_SYSTEM_GEN ("C$PARAMSIZE", 1, cob_parameter_size) COB_SYSTEM_GEN ("C$TOUPPER", 2, CBL_TOUPPER) COB_SYSTEM_GEN ("C$TOLOWER", 2, CBL_TOLOWER) +COB_SYSTEM_GEN ("CBL_JSON_PARSE", 2, CBL_JSON_PARSE) +COB_SYSTEM_GEN ("CBL_JSON_FREE", 1, CBL_JSON_FREE) +COB_SYSTEM_GEN ("CBL_JSON_GET_TYPE", 1, CBL_JSON_GET_TYPE) +COB_SYSTEM_GEN ("CBL_JSON_GET_KEY_START", 2, CBL_JSON_GET_KEY_START) +COB_SYSTEM_GEN ("CBL_JSON_GET_KEY_NEXT", 3, CBL_JSON_GET_KEY_NEXT) +COB_SYSTEM_GEN ("CBL_JSON_GET_ARRLEN", 1, CBL_JSON_GET_ARRLEN) +COB_SYSTEM_GEN ("CBL_JSON_GET_VALUE", 2, CBL_JSON_GET_VALUE) +COB_SYSTEM_GEN ("CBL_JSON_GET_OBJECT", 1, CBL_JSON_GET_OBJECT) +COB_SYSTEM_GEN ("CBL_JSON_GET_OBJECT_L", 3, CBL_JSON_GET_OBJECT_L) +COB_SYSTEM_GEN ("CBL_JSON_GET_OBJECT_A", 3, CBL_JSON_GET_OBJECT_A) + COB_SYSTEM_GEN ("\221", 2, CBL_X91) COB_SYSTEM_GEN ("\364", 2, CBL_XF4) COB_SYSTEM_GEN ("\365", 2, CBL_XF5) diff --git a/tests/Makefile.am b/tests/Makefile.am index 50c35472..4f15cf4b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -134,7 +134,8 @@ jp_compat_DEPENDENCIES = \ jp-compat.src/greater-less-than-equal.at \ jp-compat.src/file-desc.at \ jp-compat.src/abort-on-file-error.at \ - jp-compat.src/system-routine.at + jp-compat.src/system-routine.at \ + jp-compat.src/catch-exception.at EXTRA_DIST = $(srcdir)/package.m4 $(TESTS) \ $(syntax_DEPENDENCIES) \