Git Product home page Git Product logo

opensourcecobol / opensource-cobol Goto Github PK

View Code? Open in Web Editor NEW
66.0 25.0 28.0 12.52 MB

"opensource COBOL" is open-source COBOL compiler, an extension of the Japan-specific features. "opensource COBOL" translates COBOL program to C code and compiles it using GCC or CL.

Home Page: https://www.osscons.jp/osscobol/

License: GNU General Public License v2.0

Shell 38.84% C 45.34% COBOL 0.38% Perl 6 0.16% Makefile 5.67% Yacc 2.71% M4 6.69% C++ 0.21%
c cobol

opensource-cobol's Introduction

			  opensource COBOL
		http://www.osscons.jp/osscobol/

"opensource COBOL" is open-source COBOL compiler, an extension of the Japan-specific features.
"opensource COBOL" translates COBOL program to C code and compiles it using GCC or CL.

It was forked from OpenCOBOL in 2012.
See also OpenCOBOL project.
    http://www.opencobol.org/
    http://sourceforge.net/projects/open-cobol/

This package contains the following subdirectories:

    cobc        COBOL compiler
    libcob      COBOL run-time library
    bin         COBOL driver program
    lib         static library and common headers
    config      configuration files
    po          international messages
    texi        Texinfo files
    tests       Test suite
    vbisam      VBISAM file I/O library
    win32       Project files for Windows

All programs except those in lib and libcob are distributed under
the GNU General Public License.  See COPYING for details.

Programs in lib and libcob are distributed under the GNU Lesser
General Public License.  See COPYING.LIB for details.

See AUTHORS for the author of each file.

Please refer to the file "win32/readme.txt" about win32 directory.

============
Requirements
============

  ***
     NOTE
	For all the following packages (required or optional),
	BOTH runtime AND development components are necessary.
  ***
  ***
     NOTE
	All the following packages are normally part of a Linux
	distribution. Cygwin also has these as installable packages
	ALWAYS install the distro packages when available !!
  ***

opensource COBOL requires the following external libraries to be installed:

  o GNU MP (libgmp) 4.1.2 or later
    http://gmplib.org

    BOTH runtime AND development components required.

    libgmp is used to implement decimal arithmetic.

    GNU MP is distributed under GNU Lesser General Public License.


  o GNU Libtool (libltdl)
    http://www.gnu.org/software/libtool/libtool.html

    ***
	NOTE - libltdl is NOT needed when installing on Linux
	or Windows (including Cygwin and MingW).
    ***

    libltdl is used to implement dynamic CALL statements.

    GNU Libtool is distributed under GNU Lesser General Public License.

  **

The following libraries ARE required WHEN :

1) Indexed-Sequential file I/O is used

  o Berkeley DB (libdb) 1.85 or later
    http://www.oracle.com/

    BOTH runtime AND development components required.

    Recommended is version 4.x as 1.85 is known to have problems.

    * NOTE *

     The following NOTE(S) ONLY apply to DB <= 4.1

	    * NOTE *
	     The BDB version 4.0 was never officially supported from
	     sleepycat but, unfortunately, found it's way into Linux
	     releases. Install a newer version.

	    * NOTE *
	     If you are generating BDB yourself and the BDB 
	     version is <= 4 (and version < 1), you need to specify
	     --enable-compat185 as a minimum to the BDB configure.
	     BDB does NOT have the usual install path of either
	     /usr or /usr/local. Therefore, it is recommended to
	     specify --prefix=/usr/local to the configure.

    libdb is used to implement indexed file I/O and SORT/MERGE.

    Berkeley DB is distributed under the original BSD License (1.85)
    or their own open-source license (2.x or later).  Note that, as
    of 2.x, if you linked your software with Berkeley DB, you must
    distribute the source code of your software along with your
    software, or you have to pay royalty to Oracle.

2) SCREEN I/O is used or extended ACCEPT/DISPLAY is used

    BOTH runtime AND development components required.

  o Ncurses (ncurses) 5.2 or later
    http://www.gnu.org/software/ncurses/ncurses.html

    libncurses is used to implement SCREEN SECTION and extended
    ACCEPT/DISPLAY.

    Ncurses is distributed under a BSD style license.

  o Unix curses

  o PDCurses (pdcurses) for MinGW ports
    http://pdcurses.sourceforge.net

============

============
Installation
============

  **
	NOTE
	Due to deficiencies in the tools used to prepare
	opensource COBOL (autoconf/automake/libtool), it is
	NOT generally possible to use path names with
	spaces embedded within them (Mainly Cygwin/MingW/Windows ports).
  **
 
To generate/install opensource COBOL on Linux:

**************************************

    ./configure
    make

 Here you may run
    make check
 to run a series of opensource COBOL test programs (must do!)
 This MUST succeed - If not, please report.

    make install

** NOTE **
   On Linux systems, if you are installing for the
   -first- time, you may need to run "ldconfig" (as root).
   In fact, it does not hurt if you always do this.

** NOTE **
   On some Red Hat (Fedora) installations and
   possibly other Linux distros, /usr/local/lib
   is NOT automatically searched at runtime. 
   Edit /etc/ld.so.conf and add /usr/local/lib to the file.
   Rerun "ldconfig".

You may optionally perform a series of COBOL85 tests.
See tests/cobol85/README
It is recommended that you perform this test.

**************************************

If you think you have a problem or just want to
record the make output, just redirect the output thus :
    make 1>mymake.log 2>&1
    make install 1>myinstall.log 2>&1

**************************************

You can get back to a clean installation status by running :
    make distclean

**************************************

The "make install" will default to "/usr/local" as
the install path. You may override this by specifying
"--prefix=<your install path>" to the "./configure"
command.

***********************************************************

============

The following is only interesting for advanced use.
A normal user should not have recourse to use these
options.

There are the following configure options:

  --with-cc=<cc>		Specify C compiler command used by cobc
				Do not specify this unless you know what
				you are doing!

  --with-db1			Use Berkeley DB 1.85 (libdb1/libdb-1.85)
				This overrides --with-db/--without-db

  --with-db			Use Berkeley DB 3.0 or later (libdb)
				This is the default

  --without-db			Do not use Berkeley DB
				You will not be able to use SORT/indexed I/O

  --with-dl			Use the system dynamic linker instead of ltdl
				This is the default
				(Note on Windows, native loading is used)

  --without-dl			Use ltdl for dynamic program loading

  --with-patch-level=<n>	Set internal patch level to n (default 0)

  --with-varseq=<n>		Define the format for variable length sequential
				files. For values of 0, 1 and 2, four bytes are
				written preceeding each record. The format of
				these four bytes for values of 0, 1, 2 is
				as follows :
				n = 0 (default)
					The first 2 bytes are the record length
					in big-endian order. This is compatible
					with mainframe. Bytes 3 and 4 are set
					to binary 0.
				n = 1
					The 4 bytes are the record length in
					big-endian order.
				n = 2
					The 4 bytes are the record length in
					native machine order (int).
					(This was previously the default)

				For the value of 3, two bytes are written
				preceeding each record :
				n = 3
					The first 2 bytes are the record length
					in big-endian order. The record follows
					immediately after beginning at byte 3.

  --enable-debug		Add '-g' debug option to make

============

============
Development
============

If you wish to hack the opensource COBOL source code, proceed
as follows.

You need to install the following extra packages with specified
minimum version before changing/building opensource COBOL:

For compiling :
  o Bison 1.875
  o Flex 2.5.4

If you reconfigure and/or prepare a distribution
  o Autoconf 2.59
  o Automake 1.9.6
  o Libtool 1.5.24
  o m4 1.4.2
  o Gettext 0.14.1
  o Texinfo 4.6 (For makeinfo)

If you modify top-level configure.ac, Makefile.am in any directory,
or any of the standard OC tests then you will need to
run "autoreconf -I m4" to regenerate the necessary files.

opensource-cobol's People

Contributors

juflux avatar kztanaka avatar n-isaka avatar nor51010 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

opensource-cobol's Issues

コーディングスタイルについて

以前に部会にて「オリジナルのOpenCOBOLとコーディングスタイルを合わせる」方針について検討した際に作成しました指針について挙げます。
ご意見、ご指摘、間違い等ありましたら返信願います。

1.関数呼び出しを行う際に関数名と"("の間に半角スペースを入れる。

2.","の後ろには半角スペースを入れる。

3.文字列の際に、型と変数名の間にタブを2つ入れる。INT型の宣言は半角スペースを入れる。

4.memcpyを呼び出す場合、引数として渡す式の演算子の前後にはスペースを入れない。

5.FOR文の各演算子の前後、";"の後ろには半角スペースを入れる。

6.通常の式では演算子の前後に半角スペースを入れる。

7."sizeof"と"("の間には半角スペースを入れる。(4の場合であってもsizeofは例外)

8.IF文の条件句の")"と"{"の間には半角スペースを入れる。改行は入れない。

9.各行の後ろや空白行などで、無駄なスペースを入れない。

10.SWITCH文の内部のCASEについては、インデントを下げない。

11.CASE文の中の演算(1行にまとまるもの)については演算子、";"などの前後にスペースを入れない。

12.IF文の条件式等、複数行にわたって記述する際には、各行の条件文の先頭の"文字"をそろえる。

13.コメントの後に空白行をいれない。

14.#defineによる宣言では区切りにタブを使う

15.グローバル宣言の文字列(char *)の宣言では、"char * 変数名"と半角スペースで区切る。(3の例外)

16.関数の宣言では、返り値と関数名の間は改行を行う。

17.変数宣言後、処理記述の間には空白行を入れる。

18.ELSE IFで対応できるものはつなげていく

19.typedef struct後の構造体名宣言では"}"と名前の間に半角スペースを入れる。

20.EXTERNの関数宣言では以下の形式
 →extern[_]void[_]関数名[タブ*1またはタブ*2](引数)
 →extern[_]int[_][_]関数名[タブ*1またはタブ*2](引数)

English commit-messages / missing Changelog entries

For understanding what is going on here it would be very helpful to have the commit messages in English.
They actually could contain both Japanese and English messages if this would be helpful for the Japanese users.

The old messages can be changed, too - see https://help.github.com/articles/changing-a-commit-message/

In general there is are two things missing:

a) "user viewable changes" - NEWS file - you actually did a quite good job to provide the messages in https://github.com/opensourcecobol/opensource-cobol/releases - they only are missing from the NEWS file - please copy them over and commit the file.
Afterwards it is fine to change the NEWS file when preparing a new release.

b) Changelog entries - not every minor change needs them but it is good to have entries for most changes. I assume the commit messages can be used as a first "source" for them, you may see missing stuff when copying them (translated to English) into the Changelogs.
Afterwards Changelog entries are ideally always done during a change and committed along the actual change.

Thank you for responding.

make error while trying to generate/install opensource COBOL on Linux

I installed GNU MP (libgmp) successfully in Ubuntu 18. To generate/install opensource COBOL on Linux, I then ran ./configure and ran successfully. Then I ran make. I got some errors. I wanted to restart make, so I ran make clean and afterwards ran make.

The make command did not run successfully. I got errors and the first error was the following error. Attached is the full log of the last time I ran make.

rm -f ja.gmo && : -c --statistics -o ja.gmo ja.po
Makefile:123: recipe for target 'ja.gmo' failed

make.log

Could anybody help?

Duplicate definitions of the same variable

An error occurs where the same variable is defined multiple times.
This error has been occurring since v1.0.19.

COBOL code:

      ****************************************************************
      *                                                              *
      *         ローン返済額計算(元利均等返済)                        *
      *                                                              *
      ****************************************************************
       IDENTIFICATION          DIVISION.
      ****************************************************************
       PROGRAM-ID.             LOANSAMPLE.
       AUTHOR.                 TOKYO-SYSTEM-HOUSE.
       DATE-WRITTEN.           2016/01/14.
       ENVIRONMENT             DIVISION.
       CONFIGURATION           SECTION.
       SOURCE-COMPUTER.        OPEN-COBOL.
       OBJECT-COMPUTER.        OPEN-COBOL.
      ****************************************************************
       DATA                    DIVISION.
      ****************************************************************
       WORKING-STORAGE         SECTION.
      * 01  WK-AREA.
       01  WK-INTEREST-RATE  PIC 9(02)V9(03).
       01  WK-INTEREST-YEAR  PIC 9(02)V9(09).
       01  WK-INTEREST-MONTH PIC 9(02)V9(09).
       01  WK-PERIODS        PIC 999.
       01 WK-PAYMENT        PIC 9(09).*>V9(09).
       01  WK-LOAN           PIC 9(09)V9(09).
       01  WK-LOAN-LEFT      PIC 9(09)V9(09).
       01  WK-PRINCIPAL      PIC 9(09).*>V9(09).
       01  WK-INTEREST       PIC 9(09).*>V9(09).
       01  WK-PERIODS-CNT    PIC 999.
       01  WK-DATE.
           05  WK-YEAR         PIC 9999.
           05  WK-MONTH        PIC 99.
           05  WK-DAY          PIC 99.
       01  WK-KAKUNIN          PIC X.
       *01  DSP-AREA.
       01  DSP-PAYMENT       PIC ZZZ,ZZZ,ZZ9.*>.99.
       01  DSP-PRINCIPAL     PIC ZZZ,ZZZ,ZZ9.*>.99.
       01  DSP-INTEREST      PIC ZZZ,ZZZ,ZZ9.*>.99.
       01  DSP-LOAN-LEFT     PIC ZZZ,ZZZ,ZZ9.*>.99.
       01  DSP-PERIODS-CNT   PIC ZZ9.  
       01  DSP-YEAR          PIC 9999.
       01  DSP-MONTH         PIC 99.      
       COPY "NUM-IO".
      ****************************************************************
       PROCEDURE               DIVISION.
      ****************************************************************
       HAJIME.
       MAIN-000.
           DISPLAY "***  ローン返済額計算  ***" .
           DISPLAY "借入金額: " NO ADVANCING.
           COPY "NUM-ACP" REPLACING =='#1'==  BY ==WK-LOAN==..
           DISPLAY "年利 (%): " NO ADVANCING.        
           COPY "NUM-ACP" REPLACING =='#1'==  BY ==WK-INTEREST-RATE==..
           DISPLAY "ローン期間(月): " NO ADVANCING.
           COPY "NUM-ACP" REPLACING =='#1'==  BY ==WK-PERIODS==..
       MAIN-100.
           COMPUTE WK-INTEREST-YEAR  = WK-INTEREST-RATE / 100.
           COMPUTE WK-INTEREST-MONTH = WK-INTEREST-YEAR / 12.
           COMPUTE WK-PAYMENT ROUNDED
                 = (WK-LOAN * WK-INTEREST-MONTH *
                    ((1 + WK-INTEREST-MONTH) ** (WK-PERIODS)))
                 / ((1 + WK-INTEREST-MONTH) ** (WK-PERIODS) - 1).            
       MAIN-100.
           DISPLAY "返済額(月) = " NO ADVANCING.
           MOVE WK-PAYMENT TO DSP-PAYMENT.
           DISPLAY DSP-PAYMENT.
           DISPLAY "印刷しますか?(Y/N)".
           ACCEPT WK-KAKUNIN.
           IF WK-KAKUNIN NOT = "Y"
               GO TO OWARI.
       MAIN-200.
           MOVE  WK-LOAN TO WK-LOAN-LEFT.
           MOVE  1       TO WK-PERIODS-CNT.
           ACCEPT WK-DATE FROM DATE YYYYMMDD.
      *            "ZZ9 9999/99  ZZZ,ZZZ,ZZ9 ZZZ,ZZZ,ZZ9 ZZZ,ZZZ,ZZ9 ZZZ,ZZZ,ZZ9"     
           DISPLAY "NO  年月     支払        原本        利息   "        
      -            "     残元金".
           DISPLAY "--- ------- ----------- ----------- ----------- ----
      -            "-------".
       MAIN-210.
           COMPUTE WK-INTEREST  ROUNDED
                   = WK-LOAN-LEFT * WK-INTEREST-MONTH.
           COMPUTE WK-PRINCIPAL = WK-PAYMENT - WK-INTEREST.
           COMPUTE WK-LOAN-LEFT = WK-LOAN-LEFT - WK-PRINCIPAL.
           IF WK-PERIODS-CNT = WK-PERIODS
              ADD  WK-LOAN-LEFT  TO WK-PRINCIPAL
                                    WK-PAYMENT
              MOVE ZERO          TO WK-LOAN-LEFT.
           MOVE    WK-PERIODS-CNT TO DSP-PERIODS-CNT.
           MOVE    WK-PAYMENT    TO DSP-PAYMENT.
           MOVE    WK-INTEREST   TO DSP-INTEREST.
           MOVE    WK-PRINCIPAL  TO DSP-PRINCIPAL.
           MOVE    WK-LOAN-LEFT  TO DSP-LOAN-LEFT.
           DISPLAY WK-PERIODS-CNT " " WK-YEAR "/" WK-MONTH " "
                   DSP-PAYMENT " "
                   DSP-PRINCIPAL " " DSP-INTEREST " "
                   DSP-LOAN-LEFT.
           COMPUTE WK-PERIODS-CNT = WK-PERIODS-CNT + 1.
           IF WK-MONTH = 12
              MOVE 1 TO WK-MONTH
              ADD  1 TO WK-YEAR
           ELSE
              ADD  1 TO WK-MONTH.     
           IF WK-PERIODS-CNT > WK-PERIODS
              GO TO OWARI.
           GO TO MAIN-210.
       OWARI.
           STOP RUN.
      *--------------------<< END OF PROGRAM >>-----------------------*

java code:

/* Sections and Labels */
  private final static int l_LOANSAMPLE = 1;
  private final static int l_MAIN_SECTION = 2;
  private final static int l_MAIN_SECTION__HAJIME = 3;
  private final static int l_MAIN_SECTION__MAIN_000 = 4;
  private final static int l_MAIN_SECTION__MAIN_100 = 5;
  private final static int l_MAIN_SECTION__MAIN_100 = 6;
  private final static int l_MAIN_SECTION__MAIN_200 = 7;
  private final static int l_MAIN_SECTION__MAIN_210 = 8;
  private final static int l_MAIN_SECTION__OWARI = 9;
  private final static int l_Default_Error_Handler = 10;

error message:
./LOANSAMPLE.java:718: error: variable l_MAIN_SECTION__MAIN_100 is already defined in class LOANSAMPLE private final static int l_MAIN_SECTION__MAIN_100 = 6; ^ 1 error

Java変換プロジェクト

opensource COBOL開発者各位

お疲れ様です。
現在、我々のチームでopenosurce COBOLでのCOBOLのコンバート先として、C言語だけでなく、Javaコードを出力できるようにすることを考えています。

目的として、以下2点があります。

  • 昨今増えてきているJavaのシステムとの親和性を向上し、クラウド、マイクロサービスへの適用を考える
  • 日本国内ではCOBOLからJavaへの移行の需要が増えており、その中で利用できるようにしたい

開発内容について、opensourcecobol内に別途リポジトリを作成して共有したいと考えています。
ご意見有りましたら、コメントお願いいたします。

--
We would like to update opensource COBOL to generate Java code not only C code

because,

  • I want to improve the affinity with the Java system
  • I want to help migration, migrate from COBOL to Java

I'm thinking of create new repositoy and publish development.

what's your opinion.

Update automake files

While developing #41 , While developing # 41, I got many errors when trying to add an option to configure.

Opensource COBOL's Automake related files are created for older versions, and running new Automake and Autoconf will result in an error.
 
I'm thinking of updating these files, but what about that?
Or, please let me know if you already have the updated file.

Currently I am installing and fixing an older version of Automake.

test

テストです。

機能開発時のブランチ名について

お世話になります。井坂です。

v1.4.0J作成時は、別サイトで管理していましたチケットIDをブランチ名として利用していました。
(チケット100ならブランチ名[iss100])

今後の開発はgithub上ですべて行えるように、ブランチ名については簡単な機能名などを付けていったほうがいいかと考えています。
※あまり名前付けは得意ではないので、何か規則があるとうれしいです

皆様のご意見はありますでしょうか。

#INCLUDE problem in libcob/call.c

This is not a particularly important issue.
When building opensource-cobol, make command displays the following warning message.

 gcc -DHAVE_CONFIG_H -I. -I. -I.. -I.. -O2 -finline-functions -fsigned-char -Wall -Wwrite-strings -Wmissing-prototypes -Wno-format-y2k -MT libcob_la-call.lo -MD -MP -MF .deps/libcob_la-call.Tpo -c call.c  -fPIC -DPIC -o .libs/libcob_la-call.o
call.c: In function 'cob_init_call':
call.c:595:7: warning: implicit declaration of function 'strcasecmp' [-Wimplicit-function-declaration]
  595 |   if (strcasecmp (s, "LOWER") == 0) {
      | 

The function strcasecmp is defined in strings.h of C standard libraries.
Even if #include<strings.h> is added to libcob/call.c, the warning will not be resolved.
The cause of the above warning message is that #include <strings.h> refers to libcob/strings.h instead of strings.h of C standard libraries. (gcc finds libcob/strings.h first because of -I. option)
I think it is necessary to update Makefile.am in order to fix the problem.
Once I learn more about Automake and Autoconf, I will fix the warning message.

Memory leaks in `Hello World` program

I used valgrind memory check against 'Hello World' program and found memory leaks.

       IDENTIFICATION              DIVISION.
       PROGRAM-ID.                 hello.
       DATA                        DIVISION.
       WORKING-STORAGE             SECTION.
       PROCEDURE                   DIVISION.
           DISPLAY "Hello".
           STOP RUN.
$ cobc -g -x hello.cbl
$ valgrind --leak-check=full --show-leak-kinds=all --tool=memcheck ./hello
==3009== Memcheck, a memory error detector
==3009== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==3009== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==3009== Command: ./hello
==3009==
Hello
==3009==
==3009== HEAP SUMMARY:
==3009==     in use at exit: 35,883 bytes in 171 blocks
==3009==   total heap usage: 211 allocs, 40 frees, 45,470 bytes allocated
==3009==
==3009== 2 bytes in 1 blocks are definitely lost in loss record 1 of 38
==3009==    at 0x4C360A5: malloc (vg_replace_malloc.c:380)
==3009==    by 0x5D1480D: strdup (in /usr/lib64/libc-2.28.so)
==3009==    by 0x4E5253C: cob_init (in /usr/lib/libcob.so.1.0.0)
==3009==    by 0x400B55: main (hello.c:31)
==3009==
==3009== LEAK SUMMARY:
==3009==    definitely lost: 2 bytes in 1 blocks
==3009==    indirectly lost: 0 bytes in 0 blocks
==3009==      possibly lost: 0 bytes in 0 blocks
==3009==    still reachable: 35,881 bytes in 170 blocks
==3009==         suppressed: 0 bytes in 0 blocks
==3009== Reachable blocks (those to which a pointer was found) are not shown.
==3009== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==3009==
==3009== For lists of detected and suppressed errors, rerun with: -s
==3009== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

プレリリース用のブランチ作成について

お世話になります。井坂です。

こちら側の都合となってしまい恐縮ですが、各機能を開発するにあたって、未リリースの状態でも機能をマージした環境が欲しいなと考えています。

いきなりマスターに入れてしまうのも運用上、あまりよくないと思いますので、開発中リポジトリを用意するのはどうでしょうか。

※ついでに開発時の運用ルールとかもある程度相談できればと思います。

JSON support

I tried to implement the JSON function.
This function like a environment function with jansson.

DISPLAY JSON-NAME : Specify the name of JSON structure.
DISPLAY JSON-KEY : Register period separated key names.
ACCEPT JSON-VALUE: Gets the value specified by JSON-KEY from JSON-NAME data.

Look at this branch: feature/JSON_support

COBOL sample:

      ******************************************************************
      *  opensource COBOL JSON support
      ******************************************************************
       IDENTIFICATION              DIVISION.
      ******************************************************************
       PROGRAM-ID.                 JSON.
       AUTHOR.                     n-isaka.
       DATE-WRITTEN.               2019-06-13.
      ******************************************************************
       ENVIRONMENT                 DIVISION.
      ******************************************************************
       CONFIGURATION               SECTION.
       SPECIAL-NAMES.
      ******************************************************************
       INPUT-OUTPUT                SECTION.
       FILE-CONTROL.
      ******************************************************************
       DATA                        DIVISION.
      ******************************************************************
       FILE                        SECTION.
      ******************************************************************
       WORKING-STORAGE             SECTION.
       01  JSON-STR                PIC  X(255).
       01  J-KEY                   PIC  X(255).
       01  J-VALUE                 PIC  X(255).
      ******************************************************************
       PROCEDURE                   DIVISION.
      ******************************************************************
       MAIN-RTN.

      *    *** 1つ目のJSONを登録
           STRING '{'                             DELIMITED BY SIZE
                     '"key1" : "value1",'         DELIMITED BY SIZE
                     '"key2" : 2,'                DELIMITED BY SIZE
                     '"key3" : {'                 DELIMITED BY SIZE
                        '"key3-1" : "value3-1",'  DELIMITED BY SIZE
                        '"key3-2" : "value3-2"'   DELIMITED BY SIZE
                     '},'                         DELIMITED BY SIZE
                     '"key4" : ['                 DELIMITED BY SIZE
                        '"value4-1",'             DELIMITED BY SIZE
                        '"value4-2",'             DELIMITED BY SIZE
                        '"value4-3"'              DELIMITED BY SIZE
                     ']'                          DELIMITED BY SIZE
                  '}'                             DELIMITED BY SIZE
                  INTO JSON-STR.

           DISPLAY "JSON"          UPON JSON-NAME.
           DISPLAY JSON-STR        UPON JSON-VALUE.

      *    *** 2つ目のJSONを登録
           MOVE SPACE              TO JSON-STR.
           STRING '{'                             DELIMITED BY SIZE
                     '"key10" : "value10"'        DELIMITED BY SIZE
                  '}'                             DELIMITED BY SIZE
                  INTO JSON-STR.

           DISPLAY "JSON2"         UPON JSON-NAME.
           DISPLAY JSON-STR        UPON JSON-VALUE.

      *    *** 1つ目のJSONを選択
           DISPLAY "JSON"          UPON JSON-NAME.

      *    *** 1つ目のJSONからKEYでデータを取得
      *    *** 配列は対応
           MOVE "key4[1]"          TO J-KEY.
           MOVE SPACE              TO J-VALUE.
           DISPLAY J-KEY           UPON JSON-KEY.
           ACCEPT  J-VALUE         FROM JSON-VALUE.
           DISPLAY J-KEY ":" J-VALUE.
      *    key4[1] : value4-2

      *    *** 数値型も対応
           MOVE "key2"             TO J-KEY.
           MOVE SPACE              TO J-VALUE.
           DISPLAY J-KEY           UPON JSON-KEY.
           ACCEPT  J-VALUE         FROM JSON-VALUE.
           DISPLAY J-KEY ":" J-VALUE.
      *    key2 : 2

      *    *** 入れ子も対応
           MOVE "key3.key3-2"      TO J-KEY.
           MOVE SPACE              TO J-VALUE.
           DISPLAY J-KEY           UPON JSON-KEY.
           ACCEPT  J-VALUE         FROM JSON-VALUE.
           DISPLAY J-KEY ":" J-VALUE.
      *    key3.key3-2 : value3-2

      *    *** 2つ目のJSONを選択
           DISPLAY "JSON2"         UPON JSON-NAME.

      *    *** 2つ目のJSONから値を取得
           MOVE "key10"            TO J-KEY.
           MOVE SPACE              TO J-VALUE.
           DISPLAY J-KEY           UPON JSON-KEY.
           ACCEPT  J-VALUE         FROM JSON-VALUE.
           DISPLAY J-KEY ":" J-VALUE.
      *    key10 : value10

      *    *** この時1個目のJSONからは値がとれない
           MOVE "key3.key3-2"      TO J-KEY.
           MOVE SPACE              TO J-VALUE.
           DISPLAY J-KEY           UPON JSON-KEY.
           ACCEPT  J-VALUE         FROM JSON-VALUE.
           DISPLAY J-KEY ":" J-VALUE.
      *    key3.key3-2 : 

       MAIN-EXT.
           STOP RUN.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.