diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..c9adb5ce --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,12 @@ +FROM almalinux:9 + +SHELL ["/bin/bash", "-c"] + +# classpath settings +ENV CLASSPATH :/usr/lib/opensourcecobol4j/libcobj.jar +RUN echo 'export CLASSPATH=:/usr/lib/opensourcecobol4j/libcobj.jar' >> ~/.bashrc + +# install dependencies +RUN dnf update -y +RUN dnf install -y epel-release +RUN dnf install -y gcc make bison flex automake autoconf diffutils gettext java-21-openjdk-devel git-clang-format cppcheck libtool gettext-devel unzip diff --git a/.devcontainer/boot.sh b/.devcontainer/boot.sh new file mode 100755 index 00000000..2e20ebd8 --- /dev/null +++ b/.devcontainer/boot.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# Build and Install +./configure --prefix=/usr/ +make +make install + +# Set up ~/.bashrc +cat .devcontainer/term_settings/extra_bashrc.sh >> ~/.bashrc diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..eeaa6983 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,7 @@ +{ + "name": "opensource COBOL 4J development", + "build": { + "dockerfile": "Dockerfile" + }, + "postCreateCommand": ".devcontainer/boot.sh && source ~/.bashrc" +} \ No newline at end of file diff --git a/.devcontainer/term_settings/extra_bashrc.sh b/.devcontainer/term_settings/extra_bashrc.sh new file mode 100644 index 00000000..f1d4274b --- /dev/null +++ b/.devcontainer/term_settings/extra_bashrc.sh @@ -0,0 +1,11 @@ +alias ls='ls --color=auto' +alias ll='ls -l' +alias la='ls -a' + +alias g='git' + +parse_git_branch() { + git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' +} + +export PS1="\e[0;32m[\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\]\e[0;32m]\033[00m " diff --git a/.github/workflows/build-gcc9.yml b/.github/workflows/build-gcc9.yml index dfd332dc..e5b00791 100644 --- a/.github/workflows/build-gcc9.yml +++ b/.github/workflows/build-gcc9.yml @@ -10,7 +10,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/setup-java@v4 + - uses: actions/setup-java@v5 with: distribution: 'temurin' java-version: '21' @@ -21,7 +21,7 @@ jobs: sudo apt-get install -y gcc-9 build-essential gettext autoconf - name: Checkout opensource COBOL 4J - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Install opensource COBOL 4J run: | diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2212a8fa..a39026b8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,6 +6,10 @@ on: os: required: true type: string + configure-args: + required: false + type: string + default: "" permissions: contents: read @@ -16,13 +20,13 @@ jobs: container: image: ${{ inputs.os }} steps: - - uses: actions/setup-java@v4 + - uses: actions/setup-java@v5 if: inputs.os == 'ubuntu:24.04' with: distribution: 'temurin' java-version: '21' - - uses: actions/setup-java@v4 + - uses: actions/setup-java@v5 if: inputs.os == 'almalinux:9' with: distribution: 'temurin' @@ -32,29 +36,43 @@ jobs: if: inputs.os == 'ubuntu:24.04' run: | apt-get update -y - apt-get install -y build-essential gettext autoconf + apt-get install -y build-essential gettext autoconf bison flex - name: Install dependencies on AlmaLinux 9 if: inputs.os == 'almalinux:9' run: | dnf -y update - dnf install -y gcc make autoconf diffutils gettext + dnf install -y gcc make autoconf diffutils gettext bison flex - name: Install dependencies on Amazon Linux 2023 if: inputs.os == 'amazonlinux:2023' run: | dnf -y update - dnf install -y java-21-amazon-corretto-devel gcc make autoconf diffutils gettext tar gzip + dnf install -y java-21-amazon-corretto-devel gcc make autoconf diffutils gettext tar gzip bison flex - name: Checkout opensource COBOL 4J - uses: actions/checkout@v4 + uses: actions/checkout@v6 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v5 + with: + gradle-version: wrapper - name: Install opensource COBOL 4J + if: inputs.configure-args == '' run: | ./configure --prefix=/usr/ CFLAGS=-Werror make echo "ARTIFACT_NAME=${{ inputs.os }}" | sed 's/:/-/g' >> "$GITHUB_ENV" + - name: Install opensource COBOL 4J + if: inputs.configure-args != '' + run: | + ./configure --prefix=/usr/ CFLAGS=-Werror ${{ inputs.configure-args }} + touch cobj/*.m4 + make + echo "ARTIFACT_NAME=${{ inputs.os }}" | sed 's/:/-/g' >> "$GITHUB_ENV" + - name: Create an artifact file run: | cd ../ @@ -62,7 +80,7 @@ jobs: mv opensourcecobol4j.tar.gz opensourcecobol4j - name: Upload an artifact - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v5 with: - name: opensourcecobol4j-${{ env.ARTIFACT_NAME }} + name: opensourcecobol4j-${{ env.ARTIFACT_NAME }}-opt_${{ inputs.configure-args }} path: opensourcecobol4j.tar.gz \ No newline at end of file diff --git a/.github/workflows/check-missing-javadoc.yml b/.github/workflows/check-missing-javadoc.yml index abd25362..db1d33a5 100644 --- a/.github/workflows/check-missing-javadoc.yml +++ b/.github/workflows/check-missing-javadoc.yml @@ -15,7 +15,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/setup-java@v4 + - uses: actions/setup-java@v5 with: distribution: 'temurin' java-version: '21' @@ -26,7 +26,7 @@ jobs: sudo apt-get install -y gcc-9 build-essential gettext autoconf - name: Checkout opensource COBOL 4J - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Install opensource COBOL 4J run: | diff --git a/.github/workflows/check-workflows.yml b/.github/workflows/check-workflows.yml index ed960900..bcf40c1b 100644 --- a/.github/workflows/check-workflows.yml +++ b/.github/workflows/check-workflows.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Install actionlint run: | diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 00000000..762ab48a --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,65 @@ +name: Coverage + +on: + workflow_dispatch: + workflow_call: + +permissions: + contents: read + +env: + CLASSPATH: ":/usr/lib/opensourcecobol4j/libcobj.jar" + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/setup-java@v5 + with: + distribution: 'temurin' + java-version: '21' + + - name: Install dependencies on Ubuntu + run: | + sudo apt-get update -y + sudo apt-get install -y build-essential gettext autoconf bison flex gcovr + + - name: Checkout opensource COBOL 4J + uses: actions/checkout@v6 + + - name: Install opensource COBOL 4J + run: | + ./configure --prefix=/usr/ CFLAGS='-fprofile-arcs -ftest-coverage' + make + sudo make install + + - name: Run NIST test + working-directory: tests/cobol85 + run: make test || true + + - name: Run other tests + working-directory: tests + run: | + tests=("command-line-options" "data-rep" "i18n_sjis" "jp-compat" "run" "syntax" "cobj-idx" "file-lock" "misc") + for test in "${tests[@]}"; do + ./"$test" || true + done + + - name: Generate a coverage report + working-directory: cobj + run: | + gcov -l ./*.gcda + gcovr -r . \ + -e cobj-parser -e cobj-scanner -e cobj-pplex -e cobj-ppparse \ + -e parser.c -e parser.y -e scanner.l -e scanner.c -e pplex.l -e pplex.c -e ppparse.y -e ppparse.c \ + -e flag-help.def -e warning-help.def -e warning.def \ + --html-details --html-self-contained --html -o report.html --txt-metric=branch + mkdir -p coverage-report + cp ./*.html coverage-report + + - name: Archive a coverage report + uses: actions/upload-artifact@v5 + with: + name: code-coverage-report + path: cobj/coverage-report/ \ No newline at end of file diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index 49d8a2b8..86ac6147 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -6,13 +6,67 @@ on: - v*.*.* jobs: + check-workflows: + uses: ./.github/workflows/check-workflows.yml + + build-artifacts: + needs: check-workflows + uses: ./.github/workflows/windows-build.yml + with: + upload-artifacts: true + create-release: - runs-on: windows-latest + needs: build-artifacts + runs-on: ubuntu-latest + permissions: + contents: write env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Create a Release - run: gh release create ${{ github.ref }} -F ReleaseNote.md \ No newline at end of file + run: gh release create ${{ github.ref }} -F ReleaseNote.md + + - name: Download cobj.exe + uses: actions/download-artifact@v6 + with: + name: cobj.exe + + - name: Download libcobj.jar + uses: actions/download-artifact@v6 + with: + name: libcobj.jar + + - name: Publish artifacts + run: | + gh release upload ${{ github.ref_name }} cobj.exe --clobber + gh release upload ${{ github.ref_name }} libcobj.jar --clobber + gh release upload ${{ github.ref_name }} config/default.conf --clobber + + # publish libcobj.jar to GitHub Packages + publish: + needs: check-workflows + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v6 + - run: | + cd ../ + mv opensourcecobol4j/* . + mv libcobj/* opensourcecobol4j + - uses: actions/setup-java@v5 + with: + java-version: '11' + distribution: 'temurin' + - name: Validate Gradle wrapper + uses: gradle/wrapper-validation-action@v3 + - name: Publish package + uses: gradle/gradle-build-action@v3 + with: + arguments: publish + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/javadoc.yml b/.github/workflows/javadoc.yml index dbb20482..69c800f5 100644 --- a/.github/workflows/javadoc.yml +++ b/.github/workflows/javadoc.yml @@ -10,16 +10,17 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/setup-java@v4 + - uses: actions/setup-java@v5 with: distribution: 'temurin' java-version: '21' - name: Checkout opensource COBOL 4J - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Run javadoc - working-directory: libcobj + working-directory: libcobj run: | + ./gradlew javadoc ./gradlew javadoc | tee javadoc.log test "$(grep '[1-9][0-9]* warning' javadoc.log)" = "" \ No newline at end of file diff --git a/.github/workflows/publish-libcobj.yml b/.github/workflows/publish-libcobj.yml deleted file mode 100644 index 4e7d018f..00000000 --- a/.github/workflows/publish-libcobj.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Publish package to GitHub Packages - -on: - workflow_dispatch: - release: - types: [published] - -jobs: - check-workflows: - uses: ./.github/workflows/check-workflows.yml - - publish: - needs: check-workflows - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - steps: - - uses: actions/checkout@v4 - - run: | - cd ../ - mv opensourcecobol4j/* . - mv libcobj/* opensourcecobol4j - - uses: actions/setup-java@v4 - with: - java-version: '11' - distribution: 'temurin' - - name: Validate Gradle wrapper - uses: gradle/wrapper-validation-action@v3 - - name: Publish package - uses: gradle/gradle-build-action@v3 - with: - arguments: publish - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index c59a163b..b50a9379 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -2,13 +2,14 @@ name: test on pull request on: pull_request: - types: [opened, reopened, review_requested, synchronize] + types: [opened, reopened, synchronize] paths-ignore: - '*.md' - 'ChangeLog' - 'NEWS' - 'README' - 'COPYING' + workflow_dispatch: concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -17,9 +18,6 @@ concurrency: permissions: contents: read -env: - CLASSPATH: ":/usr/lib/opensourcecobol4j/libcobj.jar" - jobs: check-workflows: uses: ./.github/workflows/check-workflows.yml @@ -33,6 +31,16 @@ jobs: with: os: ${{ matrix.os }} + build-utf8: + needs: check-workflows + strategy: + matrix: + os: ["ubuntu:24.04", "almalinux:9", "amazonlinux:2023"] + uses: ./.github/workflows/build.yml + with: + os: ${{ matrix.os }} + configure-args: --enable-utf8 + run-test-other: needs: build strategy: @@ -46,12 +54,36 @@ jobs: - "syntax" - "cobj-idx" - "misc" + - "file-lock" os: ["ubuntu:24.04", "almalinux:9", "amazonlinux:2023"] uses: ./.github/workflows/test-other.yml with: test-name: ${{ matrix.test_name }} os: ${{ matrix.os }} + run-test-other-utf8: + needs: build-utf8 + strategy: + fail-fast: false + matrix: + test_name: + - "command-line-options" + - "data-rep" + - "cobol_utf8" + #- "i18n_utf8" + - "jp-compat" + - "run" + - "syntax" + - "cobj-idx" + - "file-lock" + #- "misc" + os: ["ubuntu:24.04", "almalinux:9", "amazonlinux:2023"] + uses: ./.github/workflows/test-other.yml + with: + test-name: ${{ matrix.test_name }} + os: ${{ matrix.os }} + configure-args: --enable-utf8 + run-test-cobj-api: needs: build strategy: @@ -73,6 +105,20 @@ jobs: check-result: true os: ${{ matrix.os }} + run-test-nist-utf8: + needs: build-utf8 + strategy: + fail-fast: false + matrix: + test_name: ["IC", "IF", "IX", "NC", "OB", "RL", "SG", "SM", "SQ", "ST"] + os: ["ubuntu:24.04", "almalinux:9", "amazonlinux:2023"] + uses: ./.github/workflows/test-nist.yml + with: + test-name: ${{ matrix.test_name }} + check-result: true + os: ${{ matrix.os }} + configure-args: --enable-utf8 + run-test-nist-extra: needs: build strategy: @@ -100,9 +146,9 @@ jobs: windows-build: needs: check-workflows - strategy: - fail-fast: false uses: ./.github/workflows/windows-build.yml + with: + upload-artifacts: true windows-test: needs: windows-build diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index ae1b0de1..18d39930 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -8,6 +8,7 @@ on: - 'NEWS' - 'README' - 'COPYING' + workflow_dispatch: concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -16,9 +17,6 @@ concurrency: permissions: contents: read -env: - CLASSPATH: ":/usr/lib/opensourcecobol4j/libcobj.jar" - jobs: check-workflows: uses: ./.github/workflows/check-workflows.yml @@ -32,9 +30,25 @@ jobs: with: os: ${{ matrix.os }} + build-utf8: + needs: check-workflows + strategy: + matrix: + os: ["ubuntu:24.04"] + uses: ./.github/workflows/build.yml + with: + os: ${{ matrix.os }} + configure-args: --enable-utf8 + + coverage: + needs: check-workflows + if: github.ref == 'refs/heads/develop' + uses: ./.github/workflows/coverage.yml + run-test-other: needs: build strategy: + fail-fast: false matrix: test_name: - "command-line-options" @@ -44,12 +58,36 @@ jobs: - "run" - "syntax" - "cobj-idx" + - "file-lock" - "misc" os: ["ubuntu:24.04"] uses: ./.github/workflows/test-other.yml with: test-name: ${{ matrix.test_name }} os: ${{ matrix.os }} + + run-test-other-utf8: + needs: build-utf8 + strategy: + fail-fast: false + matrix: + test_name: + - "command-line-options" + - "data-rep" + - "cobol_utf8" + #- "i18n_utf8" + - "jp-compat" + - "run" + - "syntax" + - "cobj-idx" + - "file-lock" + #- "misc" + os: ["ubuntu:24.04"] + uses: ./.github/workflows/test-other.yml + with: + test-name: ${{ matrix.test_name }} + os: ${{ matrix.os }} + configure-args: --enable-utf8 run-test-cobj-api: needs: build @@ -63,6 +101,20 @@ jobs: run-test-nist: needs: build strategy: + fail-fast: false + matrix: + test_name: ["IC", "IF", "IX", "NC", "OB", "RL", "SG", "SM", "SQ", "ST"] + os: ["ubuntu:24.04"] + uses: ./.github/workflows/test-nist.yml + with: + test-name: ${{ matrix.test_name }} + check-result: true + os: ${{ matrix.os }} + + run-test-nist-utf8: + needs: build-utf8 + strategy: + fail-fast: false matrix: test_name: ["IC", "IF", "IX", "NC", "OB", "RL", "SG", "SM", "SQ", "ST"] os: ["ubuntu:24.04"] @@ -71,6 +123,7 @@ jobs: test-name: ${{ matrix.test_name }} check-result: true os: ${{ matrix.os }} + configure-args: --enable-utf8 run-test-nist-extra: needs: build @@ -98,9 +151,9 @@ jobs: windows-build: needs: check-workflows - strategy: - fail-fast: false uses: ./.github/workflows/windows-build.yml + with: + upload-artifacts: true windows-test: needs: windows-build diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 23b6c0f9..e93fe0c9 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -8,28 +8,29 @@ permissions: jobs: static_analysis: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 + container: + image: almalinux:9 steps: - # Checkout opensource COBOL - name: Checkout opensource COBOL 4J - uses: actions/checkout@v4 + uses: actions/checkout@v6 - - uses: actions/setup-java@v4 + - uses: actions/setup-java@v5 with: distribution: 'temurin' - java-version: '11' + java-version: '21' - name: Install static analysis tools run: | - sudo apt-get update -y - sudo apt-get install -y clang-format cppcheck + dnf update -y + dnf install -y epel-release + dnf install -y gcc make bison flex automake autoconf diffutils gettext java-21-openjdk-devel git-clang-format cppcheck - name: Install opensource COBOL 4J run: | - sudo apt-get install -y build-essential bison flex gettext texinfo autoconf ./configure --prefix=/usr/ make - sudo make install + make install - name: Check format with google-java-format and clang-format run: | diff --git a/.github/workflows/test-cobj-api.yml b/.github/workflows/test-cobj-api.yml index 4f95c137..a5a62cc7 100644 --- a/.github/workflows/test-cobj-api.yml +++ b/.github/workflows/test-cobj-api.yml @@ -6,6 +6,10 @@ on: os: required: true type: string + configure-args: + required: false + type: string + default: "" permissions: contents: read @@ -22,11 +26,11 @@ jobs: - name: Get the artifact name run: echo "ARTIFACT_NAME=${{ inputs.os }}" | sed 's/:/-/g' >> "$GITHUB_ENV" - - uses: actions/download-artifact@v4 + - uses: actions/download-artifact@v6 with: - name: opensourcecobol4j-${{ env.ARTIFACT_NAME }} + name: opensourcecobol4j-${{ env.ARTIFACT_NAME }}-opt_${{ inputs.configure-args }} - - uses: actions/setup-java@v4 + - uses: actions/setup-java@v5 if: inputs.os != 'amazonlinux:2023' with: distribution: 'temurin' diff --git a/.github/workflows/test-nist.yml b/.github/workflows/test-nist.yml index 3fbd8cd5..87322f9e 100644 --- a/.github/workflows/test-nist.yml +++ b/.github/workflows/test-nist.yml @@ -12,6 +12,10 @@ on: os: required: true type: string + configure-args: + required: false + type: string + default: "" permissions: contents: read @@ -21,9 +25,6 @@ env: jobs: test-other: - strategy: - matrix: - os: ["ubuntu:24.04", "almalinux:9"] runs-on: ubuntu-latest container: image: ${{ inputs.os }} @@ -31,12 +32,12 @@ jobs: - name: Get the artifact name run: echo "ARTIFACT_NAME=${{ inputs.os }}" | sed 's/:/-/g' >> "$GITHUB_ENV" - - uses: actions/download-artifact@v4 + - uses: actions/download-artifact@v6 with: - name: opensourcecobol4j-${{ env.ARTIFACT_NAME }} + name: opensourcecobol4j-${{ env.ARTIFACT_NAME }}-opt_${{ inputs.configure-args }} - name: Install Java - uses: actions/setup-java@v4 + uses: actions/setup-java@v5 if: inputs.os != 'amazonlinux:2023' with: distribution: 'temurin' diff --git a/.github/workflows/test-other.yml b/.github/workflows/test-other.yml index b7703654..646d2eaa 100644 --- a/.github/workflows/test-other.yml +++ b/.github/workflows/test-other.yml @@ -9,6 +9,10 @@ on: os: required: true type: string + configure-args: + required: false + type: string + default: "" permissions: contents: read @@ -25,11 +29,11 @@ jobs: - name: Get the artifact name run: echo "ARTIFACT_NAME=${{ inputs.os }}" | sed 's/:/-/g' >> "$GITHUB_ENV" - - uses: actions/download-artifact@v4 + - uses: actions/download-artifact@v6 with: - name: opensourcecobol4j-${{ env.ARTIFACT_NAME }} + name: opensourcecobol4j-${{ env.ARTIFACT_NAME }}-opt_${{ inputs.configure-args }} - - uses: actions/setup-java@v4 + - uses: actions/setup-java@v5 if: inputs.os != 'amazonlinux:2023' with: distribution: 'temurin' @@ -39,19 +43,24 @@ jobs: if: inputs.os == 'ubuntu:24.04' run: | apt-get update -y - apt-get install -y build-essential unzip + apt-get install -y build-essential unzip nkf - name: Install dependencies on AlmaLinux 9 if: inputs.os == 'almalinux:9' run: | dnf -y update - dnf install -y gcc make diffutils glibc-gconv-extra unzip + dnf install -y gcc make diffutils glibc-gconv-extra unzip wget + wget "https://github.com/nurse/nkf/archive/refs/tags/v2_1_3.tar.gz" -O nkf-2.1.3.tar.gz + tar zxf nkf-2.1.3.tar.gz + cd nkf-2_1_3 + make + make install - name: Install dependencies on Amazon Linux 2023 if: inputs.os == 'amazonlinux:2023' run: | dnf -y update - dnf install -y gcc make diffutils tar gzip unzip + dnf install -y gcc make diffutils tar gzip unzip wget nkf - name: Install Java if: inputs.os == 'amazonlinux:2023' @@ -71,7 +80,7 @@ jobs: - name: Upload log files if tests fail if: failure() - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v5 with: name: ${{ inputs.test-name }}-${{ env.ARTIFACT_NAME }}-log path: tests/${{ inputs.test-name }}.dir/ diff --git a/.github/workflows/update-github-pages.yml b/.github/workflows/update-github-pages.yml index 1e55431f..2bbbb9ed 100644 --- a/.github/workflows/update-github-pages.yml +++ b/.github/workflows/update-github-pages.yml @@ -26,6 +26,7 @@ jobs: # Single deploy job since we're just deploying deploy: + if: github.repository == 'opensourcecobol/opensourcecobol4j' needs: check-workflows environment: name: github-pages @@ -33,13 +34,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 - - uses: actions/setup-java@v4 + - uses: actions/setup-java@v5 with: distribution: 'temurin' java-version: '21' - + - name: Build Javadoc working-directory: libcobj run: | @@ -51,7 +52,7 @@ jobs: uses: actions/configure-pages@v5 - name: Upload artifact - uses: actions/upload-pages-artifact@v3 + uses: actions/upload-pages-artifact@v4 with: # Upload entire repository path: 'github-pages' diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index a0ecad63..a2042e91 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -2,6 +2,11 @@ name: build opensource COBOL 4J on Windows on: workflow_call: + inputs: + upload-artifacts: + description: 'Upload artifacts' + required: true + type: boolean permissions: contents: read @@ -10,7 +15,7 @@ jobs: build: runs-on: windows-latest steps: - - uses: actions/setup-java@v4 + - uses: actions/setup-java@v5 with: distribution: 'temurin' java-version: '21' @@ -19,11 +24,16 @@ jobs: uses: microsoft/setup-msbuild@v2.0.0 - name: Checkout opensource COBOL 4J - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Restore NuGet packages run: nuget restore ./win/ + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v5 + with: + gradle-version: wrapper + - name: Install opensource COBOL 4J working-directory: libcobj run: ./gradlew shadowJar @@ -32,13 +42,15 @@ jobs: run: msbuild /p:Configuration=Release /p:AdditionalIncludePaths=./:./cobj/:./win:./lib win/opensourcecobol4j.sln - name: Upload libcobj.jar - uses: actions/upload-artifact@v4 + if: ${{inputs.upload-artifacts}} + uses: actions/upload-artifact@v5 with: name: libcobj.jar path: libcobj/app/build/libs/libcobj.jar - name: Upload cobj.exe - uses: actions/upload-artifact@v4 + if: ${{inputs.upload-artifacts}} + uses: actions/upload-artifact@v5 with: name: cobj.exe path: win/x64/Release/cobj.exe \ No newline at end of file diff --git a/.github/workflows/windows-test.yml b/.github/workflows/windows-test.yml index e1801a10..bdc31601 100644 --- a/.github/workflows/windows-test.yml +++ b/.github/workflows/windows-test.yml @@ -12,22 +12,22 @@ jobs: runs-on: windows-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Download libcobj.jar - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v6 with: name: libcobj.jar path: libcobj/app/build/libs/ - name: Download cobj.exe - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v6 with: name: cobj.exe - path: win/cobj.exe + path: win/x64/Release/ - name: Install Java - uses: actions/setup-java@v4 + uses: actions/setup-java@v5 with: distribution: 'temurin' java-version: '11' diff --git a/.gitignore b/.gitignore index 8aeec330..cef26e9c 100644 --- a/.gitignore +++ b/.gitignore @@ -49,10 +49,12 @@ tests/command-line-options tests/data-rep tests/i18n_sjis tests/i18n_utf8 +tests/cobol_utf8 tests/jp-compat tests/cobj-idx tests/misc tests/run +tests/file-lock tests/*.log tests/syntax tests/cobol85/*/*.class diff --git a/CHANGELOG.md b/CHANGELOG.md index ad2a502c..e0e6b048 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,161 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). + +## [1.1.14] - 2025-10-31 +### Improved +* `cobj` now preserves string concatenation structure in the generated Java code. (#731) + +### Fixed +* Fix the implementation of `PROGRAM STATUS`. (#735) + +### Miscellaneous +* For Windows support, tests are now run on Windows Server 2025. (#732) + +## [1.1.13] - 2025-09-29 + +### Fixed + +* Fix file locking of SEQUENTIAL, LINE SEQUENTIAL and RELATIVE file types. (#714) +* Fix reading process for variable length SEQUENTIAL files. (#722) + +## Miscellaneous + +* `cobj-idx unlock` and `cobj-idx migrate` can handle multiple files at once. (#708) + +## [1.1.12] - 2025-08-28 + +### Add + +* Implemented new file locking and record locking for INDEXED files. +* Add a new sub command `migrate` for `cobj-idx`. + * With this command, you can convert an old version of an INDEXED file to a new version compatible with the latest opensource COBOL 4J. +* Add a new sub command `unlock` for `cobj-idx`. + * With this command, you can unlock all record locks and file locks on an INDEXED file. +* Add documentation of locking for INDEXED files. + +## [1.1.11] - 2025-07-25 + +### Fix + +* Fix OPEN operation for indexed files. (#676) + * The runtime library now correctly sets the file status to 30 when attempting to open indexed files with invalid or corrupted file formats. + +## [1.1.10] - 2025-06-30 + +### Add + +* Add a manual for the compiler configuration file (#665) +* Add a built-in subroutine + * C$SLEEP (#669) + +### Miscellaneous + +* Improve the test coverage slightly (#667, #664) + +## [1.1.9] - 2025-05-30 + +### Add + +* Add a sub command create for cobj-idx. + * `cobj-idx create` creates a new indexed file. + +### Fix + +* Handle non-ASCII characters in EXTERNAL items and EXTERNAL file names correctly. +* Show error messages if unimplemented subroutines are used. +* Fix non-ASCII characters in external items and external file descriptors + * The older version does not convert `-` in EXTERNAL items and EXTERNAL file names into another valid character in Java. + * The older version converts `BC` in EXTERNAL file names into invalid characters. + +## [1.1.8-hotfix1] - 2025-04-18 + +### Fix + +* Fix code generations for some WRITE statements. + * Older versions of the compiler converts some WRITE statements into invalid Java code. +* Fix the compiler to handle source code with UTF-8 encoded half-width Katakana characters correctly. + +## [1.1.8] - 2025-03-31 + +### Fix + +* Fix a bug of duplicate record keys of indexed files. + +## [1.1.7-hotfix1] - 2025-02-28 + +### Fix + +* Fix bugs related to UTF-8 (#590) + * With older versions, DISPLAY statements output invalid UTF-8 data when the arguments are sub items of group fields. + * With older versions, initilizing data with VALUE clauses fails in some cases. + +## [1.1.7] - 2025-02-28 + +### Add + +* Implement the environment variable `COB_TERMINAL_ENCODING`. (#590) + * If the value of `COB_TERMINAL_ENCODING` is `UTF-8`, the DISPLAY statement outputs data after converting it to UTF-8. Otherwise, it outputs raw data (typically encoded in Shift JIS). + * If the value of `COB_TERMINAL_ENCODING` is `UTF-8`, the ACCEPT statement processes input data as UTF-8 encoded. Otherwise, it processes input data as Shift JIS encoded. +* Fix the UTF-8 compatible compiler to recognize that the size of multibyte characters in COBOL source code as 2 bytes instead of 3 bytes. (#592) + * This change allows users to write more multibyte characters on each line of the COBOL source code. + +## [1.1.6] - 2025-01-31 + +### Add + +* Compile UTF-8 Source Code + * The latest version of cobj is now able to accept UTF-8 encoded COBOL and generate UTF-8 encoded Java. + +## [1.1.5] - 2024-12-27 + +### Add + +* Convert string literals containing SJIS characters to Java string literals. (#561) + * The older versions convert string literals containing SJIS characters into byte arrays with hexdecimal integers. + * Older versions convert `"日本語"` into `CobolUtil.toBytes((byte)0x93, (byte)0xfa, (byte)0x96, (byte)0x7b, (byte)0x8c, (byte)0xea)`. + * Latest version converts `"日本語"` to `CobolUtil.stringToBytes("日本語")`. + +### Fix + +* Fix comparisons of COMP data. (#559) + * With older versions, comparisons of COMP data are invalid in some cases. + +## [1.1.4] - 2024-11-29 + +### Fix +* Process Japanese identifiers in COBOL correctly (#540) + * The older versions convert some Japanese characters in COBOL identifiers to another characters in Java. +* Fix the conditions `PERFORM UNTIL` (#544) + * If COBOL source code contains divisions in conditions of `PERFORM UNTIL`, the older versions emit compile errors. +* Fix `SEARCH` statements with data specified `OCCURS` and `DEPENDING`(#545) + * The older versions emit compile errors when `SEARCH` statements with data specified `OCCURS` and `DEPENDING` +* Fix `ADD` statements and `SUBTRACT` statements (#546) + * In some case, the result of `SUBTRACT` was previously incorrect when the operands contais PIC S9(n) negative values. + * In some case, the result of `ADD` was -0 instead of +0 previously. +* Fix the process of checking signs of PIC 9(n) containing spaces (#549) +* Fix `INSPECT` statements (#550) + * The older versions change signs of some values accidentally because of the bug of `INSPECT` statements. + +## [1.1.3] - 2024-10-31 +### Add +* Add a new option `-variable` (#513) + * With `-variable`, cobj allows 73 or more characters for each lines +* Add documentations that describe the structure of libcobj and generated Java files (#492) +* Add Visual Studio Code Dev Container of opensource COBOL 4J (#529, #530) + +### Fix +* Fix a build error of opensource COBOL 4J on Windows 10 (489) +* Fix a build error of opensource COBOL 4J on Docker (#511) +* Fix `cobj-api` (#528) + * `cobj-api` previously generated invalid constructors in record classses +* Fix typos of `cobj-idx` command (#503) +* Fix a command line option `-fserial-variable` (#534) + +### Miscellaneous +* Improve the readability of variable names containing multi-byte characters (#502) +* Convert some EVALUATE statements to switch statements (#504) + ## [1.1.2] - 2024-07-31 ### Added * Add a new command line option `-Wtruncate` (#459) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bf552d4a..3d14bac2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,14 +10,29 @@ Although any topics related to opensource COBOL 4J can be posted in [Issues](htt We will check pull requests that passed all CI checks running both tests and static code analysis. The static analysis checks whether C and Java source files are formatted using [clang-format](https://clang.llvm.org/docs/ClangFormat.html) and [google-java-format](https://github.com/google/google-java-format) respectively, and whether [PMD](https://pmd.github.io/) finds no error and warning in Java source files. +Before you submit pull requests, you should run `./format` in order to format files in this repository. + The below sections describe how to setup and run static code analysis. -## Setup static analysis tools +## Setup Development Environment + +We strongly recommend using [Visual Studio Code with Dev Containers](https://code.visualstudio.com/docs/devcontainers/containers) for a consistent development environment. Follow the steps below to set up your development environment. -Run `sudo apt install clang-format` in Ubuntu to install `clang-format`. +1. Install [Docker](https://www.docker.com/get-started) on your machine. +1. Install [Visual Studio Code](https://code.visualstudio.com/). +1. Install the [Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension in Visual Studio Code. +1. Clone the repository. +1. Open the repository in Visual Studio Code. +1. Press `Ctrl+Shift+P` and Select `Dev Containers: Reopen in Container`. +1. Wait for the DevContainer to start up and the build to complete. It may take several minutes to complete this process. +1. (Optional) Press `Ctrl+Shift+@` to open a new terminal of Visual Studio code. +1. (Optional) [Setup credentials for git](https://code.visualstudio.com/remote/advancedcontainers/sharing-git-credentials). ## Run static analysis +> [!CAUTION] +> Since the behavior of these tools may differ from the one in other operatins systems, we recommend that you run `./format` in Visual Studio Code with Dev Containers described in the previous section. + ### check with clang-format and google-java-format Run `./format` in the top directory of opensource COBOL 4J. diff --git a/CONTRIBUTING_JP.md b/CONTRIBUTING_JP.md index a191d350..8bebc24c 100644 --- a/CONTRIBUTING_JP.md +++ b/CONTRIBUTING_JP.md @@ -10,14 +10,30 @@ CIはテストとコードの静的解析を実行します。 CIの静的解析はCとJavaのソースコードがそれぞれ[clang-format](https://clang.llvm.org/docs/ClangFormat.html) and [google-java-format](https://github.com/google/google-java-format)で整形されているか、 [PMD](https://pmd.github.io/)によるJavaソースコードの静的解析でエラーや警告が表示されないかをチェックします。 +Pull Request提出時には、./formatを実行してリポジトリ内のコードをフォーマットしてください。 + 下記にそれぞれのツールのセットアップと使用方法を説明します。 -## セットアップ +## 開発環境のセットアップ + +一貫した開発環境を確保するために、[Visual Studio Code with Dev Containers](https://code.visualstudio.com/docs/devcontainers/containers)の使用を強く推奨します。以下の手順に従って開発環境をセットアップしてください。 + +1. [Docker](https://www.docker.com/get-started)をインストールします。 +1. [Visual Studio Code](https://code.visualstudio.com/)をインストールします。 +1. Visual Studio Codeに[Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)拡張機能をインストールします。 +1. リポジトリをクローンします。 +1. Visual Studio Codeでリポジトリを開きます。 +1. `Ctrl+Shift+P`を押して、`Dev Containers: Reopen in Container`を選択します。 +1. DevContainerの起動とビルドが完了するまで待ちます。このプロセスは数分かかることがあります。 +1. (オプション)`Ctrl+Shift+@`を押して、Visual Studio Codeの新しいターミナルを開きます。 +1. (オプション)[gitの認証情報を設定](https://code.visualstudio.com/remote/advancedcontainers/sharing-git-credentials)します。 -Ubuntuでは`sudo apt install clang-format`コマンドを実行すれば`clang-format`をインストールできます。 ## 静的解析の実行 +> [!CAUTION] +> これらのツールの動作は他のオペレーティングシステムとは異なる場合があります。上記のVisual Studio Code with Dev Containersの環境でフォーマッタを実行することを推奨します。 + ### clang-formatとgoogle-java-format opensource COBOL 4Jのトップディレクトリで`./format`を実行してください。 diff --git a/ChangeLog b/ChangeLog index 7d3632c1..5878a795 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,59 @@ +2025-10-31 OSS Consortium + + * opensource COBOL 4J v1.1.14 released. + +2025-09-29 OSS Consortium + + * opensource COBOL 4J v1.1.13 released. + +2025-08-28 OSS Consortium + + * opensource COBOL 4J v1.1.12 released. + +2025-07-25 OSS Consortium + + * opensource COBOL 4J v1.1.11 released. + +2025-06-30 OSS Consortium + + * opensource COBOL 4J v1.1.10 released. + +2025-05-30 OSS Consortium + + * opensource COBOL 4J v1.1.9 released. + +2025-04-18 OSS Consortium + + * opensource COBOL 4J v1.1.8-hotfix1 released. + +2025-03-31 OSS Consortium + + * opensource COBOL 4J v1.1.8 released. + +2025-03-07 OSS Consortium + + * opensource COBOL 4J v1.1.7-hotfix1 released. + +2025-02-28 OSS Consortium + + * opensource COBOL 4J v1.1.7 released. + +2025-01-31 OSS Consortium + + * opensource COBOL 4J v1.1.6 released. + +2024-12-27 OSS Consortium + + * opensource COBOL 4J v1.1.5 released. + +2024-11-29 OSS Consortium + + * opensource COBOL 4J v1.1.4 released. + +2024-10-31 OSS Consortium + + * opensource COBOL 4J v1.1.3 released. + 2024-07-31 OSS Consortium * opensource COBOL 4J v1.1.2 released. diff --git a/Makefile.in b/Makefile.in index fbe138e1..2f44ed02 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.16.5 from Makefile.am. +# Makefile.in generated by automake 1.16.2 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2021 Free Software Foundation, Inc. +# Copyright (C) 1994-2020 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -208,6 +208,9 @@ am__define_uniq_tagged_files = \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +CSCOPE = cscope DIST_SUBDIRS = $(SUBDIRS) am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/config.h.in \ ABOUT-NLS AUTHORS COPYING COPYING.LIB ChangeLog INSTALL NEWS \ @@ -250,8 +253,6 @@ am__relativize = \ DIST_ARCHIVES = $(distdir).tar.gz GZIP_ENV = --best DIST_TARGETS = dist-gzip -# Exists only to be overridden by the user if desired. -AM_DISTCHECK_DVI_TARGET = dvi distuninstallcheck_listfiles = find . -type f -print am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \ | sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$' @@ -289,8 +290,6 @@ COB_SHARED_OPT = @COB_SHARED_OPT@ COB_SPLITKEY_FLAGS = @COB_SPLITKEY_FLAGS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ -CSCOPE = @CSCOPE@ -CTAGS = @CTAGS@ CXXCPP = @CXXCPP@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ @@ -302,7 +301,6 @@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ -ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ @@ -647,6 +645,7 @@ cscopelist-am: $(am__tagged_files) distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags -rm -f cscope.out cscope.in.out cscope.po.out cscope.files + distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am @@ -796,7 +795,7 @@ distcheck: dist $(DISTCHECK_CONFIGURE_FLAGS) \ --srcdir=../.. --prefix="$$dc_install_base" \ && $(MAKE) $(AM_MAKEFLAGS) \ - && $(MAKE) $(AM_MAKEFLAGS) $(AM_DISTCHECK_DVI_TARGET) \ + && $(MAKE) $(AM_MAKEFLAGS) dvi \ && $(MAKE) $(AM_MAKEFLAGS) check \ && $(MAKE) $(AM_MAKEFLAGS) install \ && $(MAKE) $(AM_MAKEFLAGS) installcheck \ @@ -858,8 +857,7 @@ installdirs-am: done install: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) install-recursive -install-exec: $(BUILT_SOURCES) - $(MAKE) $(AM_MAKEFLAGS) install-exec-recursive +install-exec: install-exec-recursive install-data: install-data-recursive uninstall: uninstall-recursive @@ -961,7 +959,7 @@ ps-am: uninstall-am: uninstall-binSCRIPTS uninstall-includeHEADERS .MAKE: $(am__recursive_targets) all check install install-am \ - install-exec install-strip + install-strip .PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am \ am--refresh check check-am clean clean-cscope clean-generic \ diff --git a/NEWS b/NEWS index 10265a63..b2891f43 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,192 @@ NEWS - user visible changes -*- outline -*- +* opensource COBOL 4J 1.1.14 + +** Improvement +(1) `cobj` now preserves string concatenation structure in the generated Java code. + +** Bug Fixes + +(1) Fix the implementation of `PROGRAM STATUS`. + +** Miscellaneous + +(1) For Windows support, tests are now run on Windows Server 2025. + +----------------------------------------------------------------------- + +----------------------------------------------------------------------- + +* opensource COBOL 4J 1.1.13 + +** Bug Fixes + +(1) Fix file locking of SEQUENTIAL, LINE SEQUENTIAL and RELATIVE file types. +(2) Fix reading process for variable length SEQUENTIAL files. + +** Miscellaneous + +(1) `cobj-idx unlock` and `cobj-idx migrate` can handle multiple files at once. + +----------------------------------------------------------------------- + +* opensource COBOL 4J 1.1.12 + +** New Features + +(1) Implemented new file locking and record locking for INDEXED files. +(2) Add a new sub command `migrate` for `cobj-idx`. + * With this command, you can convert an old version of an INDEXED file to a new version compatible with the latest opensource COBOL 4J. +(3) Add a new sub command `unlock` for `cobj-idx`. + * With this command, you can unlock all record locks and file locks on an INDEXED file. +(4) Add documentation of locking for INDEXED files. + + +----------------------------------------------------------------------- + +* opensource COBOL 4J 1.1.11 + +** Bug Fixes + +(1) Fix OPEN operation for indexed files. (#676) + * The runtime library now correctly sets the file status to 30 when attempting to open indexed files with invalid or corrupted file formats. + +----------------------------------------------------------------------- + +* opensource COBOL 4J 1.1.10 + +** New Features + +(1) Add a manual for the compiler configuration file (#665) +(2) Add a built-in subroutine + * C$SLEEP (#669) + +** Miscellaneous + +(1) Improve the test coverage slightly (#667, #664) + +----------------------------------------------------------------------- + +* opensource COBOL 4J 1.1.9 + +** New Features + +(1) Add a sub command create for cobj-idx. + * `cobj-idx create` creates a new indexed file. + +** Fix + +(1) Handle non-ASCII characters in EXTERNAL items and EXTERNAL file names correctly. +(2) Show error messages if unimplemented subroutines are used. +(3) Fix non-ASCII characters in external items and external file descriptors + * The older version does not convert `-` in EXTERNAL items and EXTERNAL file names into another valid character in Java. + * The older version converts `BC` in EXTERNAL file names into invalid characters. + +----------------------------------------------------------------------- + +* opensource COBOL 4J 1.1.8-hotfix1 + +** Bug Fixes + + (1) Fix code generations for some WRITE statements. + * Older versions of the compiler converts some WRITE statements into invalid Java code. + (2) Fix the compiler to handle source code with UTF-8 encoded half-width Katakana characters correctly. + +----------------------------------------------------------------------- + +* opensource COBOL 4J 1.1.8 + +** Bug Fixes + + (1) Fix a bug of duplicate record keys of indexed files. + +----------------------------------------------------------------------- + +* opensource COBOL 4J 1.1.7-hotfix1 + +** New Features + + (1) Fix bugs related to UTF-8 + * With older versions, DISPLAY statements output invalid UTF-8 data when the arguments are sub items of group fields. + * With older versions, initilizing data with VALUE clauses fails in some cases. + +----------------------------------------------------------------------- + +* opensource COBOL 4J 1.1.7 + +** New Features + + (1) Implement the environment variable `COB_TERMINAL_ENCODING`. + * If the value of `COB_TERMINAL_ENCODING` is `UTF-8`, the DISPLAY statement outputs data after converting it to UTF-8. Otherwise, it outputs raw data (typically encoded in Shift JIS). + * If the value of `COB_TERMINAL_ENCODING` is `UTF-8`, the ACCEPT statement processes input data as UTF-8 encoded. Otherwise, it processes input data as Shift JIS encoded. + (2) Fix the UTF-8 compatible compiler to recognize that the size of multibyte characters in COBOL source code as 2 bytes instead of 3 bytes. + * This change allows users to write more multibyte characters on each line of the COBOL source code. + +----------------------------------------------------------------------- + +* opensource COBOL 4J 1.1.6 + +** New Features + + (1) Compile UTF-8 Source Code + * The latest version of cobj is now able to accept UTF-8 encoded COBOL and generate UTF-8 encoded Java. + +----------------------------------------------------------------------- + +* opensource COBOL 4J 1.1.5 + +** New Features + + (1) Convert string literals containing SJIS characters to Java string literals. (#561) + * The older versions convert string literals containing SJIS characters into byte arrays with hexdecimal integers. + * Older versions convert `"日本語"` into `CobolUtil.toBytes((byte)0x93, (byte)0xfa, (byte)0x96, (byte)0x7b, (byte)0x8c, (byte)0xea)`. + * Latest version converts `"日本語"` to `CobolUtil.stringToBytes("日本語")`. + +** Bug Fixes + + (1) Fix comparisons of COMP data. + * With older versions, comparisons of COMP data are invalid in some cases. + +----------------------------------------------------------------------- + +* opensource COBOL 4J 1.1.4 + +*** Bug Fixes + (1) Process Japanese identifiers in COBOL correctly (#540) + * The older versions convert some Japanese characters in COBOL identifiers to another characters in Java. + (2) Fix the conditions `PERFORM UNTIL` (#544) + * If COBOL source code contains divisions in conditions of `PERFORM UNTIL`, the older versions emit compile errors. + (3) Fix `SEARCH` statements with data specified `OCCURS` and `DEPENDING`(#545) + * The older versions emit compile errors when `SEARCH` statements with data specified `OCCURS` and `DEPENDING` + (4) Fix `ADD` statements and `SUBTRACT` statements (#546) + * In some case, the result of `SUBTRACT` was previously incorrect when the operands contais PIC S9(n) negative values. + * In some case, the result of `ADD` was -0 instead of +0 previously. + (5) Fix the process of checking signs of PIC 9(n) containing spaces (#549) + (6) Fix `INSPECT` statements (#550) + * The older versions change signs of some values accidentally because of the bug of `INSPECT` statements. + +----------------------------------------------------------------------- + +* opensource COBOL 4J 1.1.3 + +** New Features + (1) Add a new option `-variable` + * With `-variable`, cobj allows 73 or more characters for each lines + (2) Add documentations that describe the structure of libcobj and generated Java files + (3) Add Visual Studio Code Dev Container of opensource COBOL 4J + +** Bug Fixes + (1) Fix a build error of opensource COBOL 4J on Windows 10 + (2) Fix a build error of opensource COBOL 4J on Docker + (3) Fix `cobj-api` + * `cobj-api` previously generated invalid constructors in record classses + (4) Fix typos of `cobj-idx` command + (5) Fix a command line option `-fserial-variable` + +** Miscellaneous + (1) Improve the readability of variable names containing multi-byte characters + (2) Convert some EVALUATE statements to switch statements + ----------------------------------------------------------------------- * opensource COBOL 4J 1.1.2 diff --git a/README.md b/README.md index 3dc8b582..35cd8499 100644 --- a/README.md +++ b/README.md @@ -52,16 +52,33 @@ dnf install -y java-21-amazon-corretto-devel gcc make bison flex automake autoco ### Install opensource COBOL 4J ``` -curl -L -o opensourcecobol4j-v1.1.2.tar.gz https://github.com/opensourcecobol/opensourcecobol4j/archive/refs/tags/v1.1.2.tar.gz -tar zxvf opensourcecobol4j-v1.1.2.tar.gz -cd opensourcecobol4j-1.1.2 +curl -L -o opensourcecobol4j-v1.1.14.tar.gz https://github.com/opensourcecobol/opensourcecobol4j/archive/refs/tags/v1.1.14.tar.gz +tar zxvf opensourcecobol4j-v1.1.14.tar.gz +cd opensourcecobol4j-1.1.14 ./configure --prefix=/usr/ make sudo make install ``` +In order to install a compiler for UTF-8 encoded COBOL source code, run the following commands. + +``` +curl -L -o opensourcecobol4j-v1.1.14.tar.gz https://github.com/opensourcecobol/opensourcecobol4j/archive/refs/tags/v1.1.14.tar.gz +tar zxvf opensourcecobol4j-v1.1.14.tar.gz +cd opensourcecobol4j-1.1.14 +./configure --prefix=/usr/ --enable-utf8 +touch cobj/*.m4 +make +sudo make install +``` + ### Set $CLASSPATH Add /usr/lib/opensourcecobol4j/libcobj.jar to the environment variable $CLASSPATH. +For instance, run the following code in Unix-like systems. + +```bash +export CLASSPATH="$CLASSPATH:/usr/lib/opensourcecobol4j/libcobj.jar" +``` If you want to check installations of older versions, see [doc/installation/](./doc/installation) directory respectively. @@ -81,25 +98,32 @@ The Windows version of opensource COBOL 4J uses the CL compiler included in Visu After the build is completed, "cobj.exe" will be created in `win/x64/Debug` or `win/x64/Release`. ### Build Java Files -1. Install JDK. +1. Install JDK. https://www.oracle.com/java/technologies/downloads/?er=221886#java8-windows 2. Open PowerShell. -3. Move to "libcobj" directory and execute `./gradlew shadowJar` -![alt text](image/readme3.png) -Then, libcobj.jar will be created in `libcobj/app/build/libs/`. +3. Move to "libcobj" directory and execute `.\gradlew shadowJar` + ``` + cd libcobj + .\gradlew shadowJar + ``` + + Then, libcobj.jar will be created in `libcobj\app\build\libs\`. ### Place files in the appropriate location 1. If you build in Debug mode, change the 5th line of win/make-install.ps1 from `\x64\Release\cobj.exe` to `\x64\Debug\cobj.exe`. 2. Open PowerShell -3. Move to "win" directory and execute make-install.ps1. -![alt text](image/readme4.png) -* Each file is placed in the following location. - -| File name | Location | -|---|---| -| cobj.exe | C:\opensourcecobol4j\bin | -| libcobj.jar | C:\opensourcecobol4j\lib | -| config files | C:\opensourcecobol4j\config | +3. Move to "win" directory and execute make-install.ps1. + ``` + cd win + .\make-install.ps1 + ``` +* Each file is placed in the following location. + + | File name | Location | + |---|---| + | cobj.exe | C:\opensourcecobol4j\bin | + | libcobj.jar | C:\opensourcecobol4j\lib | + | config files | C:\opensourcecobol4j\config | * If you want to change the location of the files, modify make-install.ps1. @@ -113,7 +137,7 @@ Then, libcobj.jar will be created in `libcobj/app/build/libs/`. The docker container for opensource COBOL 4J is available. ```bash -docker pull opensourcecobol/opensourcecobol4j:1.1.2 +docker pull opensourcecobol/opensourcecobol4j:20251031 ``` Execute the following commands in order to run the "Hello World" COBOL program. @@ -142,9 +166,12 @@ Run. java [PROGRAM-ID] ``` -## API reference of the runtime library +## Documentation -The API reference of the runtime library `libcobj.jar` is available [here](https://opensourcecobol.github.io/opensourcecobol4j/javadoc/libcobj/index.html) +* [The API reference of the runtime library `libcobj.jar`](https://opensourcecobol.github.io/opensourcecobol4j/javadoc/libcobj/index.html) +* [opensource COBOL 4J: Java変換解説](./doc/converted_Java_file_JP.md) +* [configuration-params-JP](./doc/configuration-params-JP.md) +* [The specification of locking for INDEXED files in opensource COBOL 4J](./doc/specification-locking-indexed-file.md) ## Development Progress @@ -206,18 +233,29 @@ cobj-idx - A utility tool to handle an indexed file of opensource COBOL 4J Usage: cobj-idx [options] -Sub commands: cobj-idx info Show information of the indexed file. +cobj-idx create --size= --key= + Create a new indexed file. + The record size and key information are specified by the options. + By default, this command does not overwrite the indexed file. + To overwrite the indexed file, use the --new option. + Example) cobj-idx create test.idx --size=100 --key=2,2:5,4:d15,5 + File name: test.idx + Record size: 100 + Primary key: 2-3 + Alternate key (No Duplicates):5-8 + Alternate key (Duplicates): 15-19 + cobj-idx load Load the data from stdin into the indexed file. - The default format of the input data is SQUENTIAL of COBOL. + The default format of the input data is SEQUENTIAL of COBOL. cobj-idx load - Load data from the input fiile into the indexed file. - The default format of the input data is SQUENTIAL of COBOL. + Load data from the input file into the indexed file. + The default format of the input data is SEQUENTIAL of COBOL. cobj-idx unload Write the records stored in the indexed file into stdout. @@ -244,6 +282,7 @@ Options: -v, --version Print the version of cobj-idx. + ``` ## cobj-api @@ -262,6 +301,8 @@ Options: -v, --version Prints the version of the cobj-api ``` +For information on how to create a Spring Boot application using cobj-api, see [here](./doc/cobj-api_SpringBoot.md). + ## Contributing Guidelines for contributing to opensource COBOL 4J can be found in [CONTRIBUTING.md](./CONTRIBUTING.md). diff --git a/README_JP.md b/README_JP.md index 5adc8cbb..4cea69bd 100644 --- a/README_JP.md +++ b/README_JP.md @@ -2,175 +2,182 @@ [English version README](./README.md) -opensource COBOL 4JはCOBOLソースコードをJavaソースコードに変換するCOBOLコンパイラです. -opensource COBOL 4JはCOBOLからCに変換するCOBOLコンパイラ["opensource COBOL"](https://github.com/opensourcecobol/opensource-cobol)をもとに開発されています. +"opensource COBOL 4J"は、COBOLソースコードをJavaソースコードに変換するCOBOLコンパイラです。 +"opensource COBOL 4J"は、COBOLからCソースコードに変換するCOBOLコンパイラ["opensource COBOL"](https://github.com/opensourcecobol/opensource-cobol)をもとに開発されています。 +(実際、このリポジトリには多くの["opensource COBOL"](https://github.com/opensourcecobol/opensource-cobol)のソースファイルが含まれています。) -変更履歴は[CHANGELOG.md](./CHANGELOG.md)を参照してください. +変更履歴は[CHANGELOG.md](./CHANGELOG.md)をご覧ください。 ## ライセンス -ランタイムライブラリであるlibcobjはLGPL 3,それ以外のソフトウェアやライブラリはGPL 3の下で配布されています. +ランタイムライブラリであるlibcobjはLGPL 3、それ以外のソフトウェアやライブラリはGPL 3の下で配布されています。 ## 動作環境 - -opensource COBOL 4J は下記の環境でテストされています. +opensource COBOL 4Jは、下記の環境でテストされています: * Ubuntu 24.04 と OpenJDK 21 * AlmaLinux 9 と OpenJDK 11 * Amazon Linux 2023 と OpenJDK 21 -古いバージョンの動作環境については、[doc/requirements-all.md](./doc/requirements-all.md)をご覧ください. - +古いバージョンの動作環境については、[doc/requirements-all.md](./doc/requirements-all.md)をご覧ください。 -## インストール -opensource COBOL 4J v1.1.2はUbuntuとAlmaLinuxで動作を確認しています. - -## 手動インストール +## インストール(Linux) ### 依存ライブラリのインストール - -下記のコマンドを実行する. +下記のコマンドを実行します。 #### Ubuntu 24.04 - ``` sudo apt-get update sudo apt-get install -y default-jdk build-essential bison flex gettext texinfo libgmp-dev autoconf ``` #### AlmaLinux 9 - ``` dnf -y update dnf install -y java-11-openjdk-devel gcc make bison flex automake autoconf diffutils gettext ``` #### Amazon Linux 2023 - ``` dnf -y update dnf install -y java-21-amazon-corretto-devel gcc make bison flex automake autoconf diffutils gettext tar gzip ``` -### opensource COBOL 4Jのインストール (Linux) +### opensource COBOL 4Jのインストール +``` +curl -L -o opensourcecobol4j-v1.1.14.tar.gz https://github.com/opensourcecobol/opensourcecobol4j/archive/refs/tags/v1.1.14.tar.gz +tar zxvf opensourcecobol4j-v1.1.14.tar.gz +cd opensourcecobol4j-1.1.14 +./configure --prefix=/usr/ +make +sudo make install +``` -下記のコマンドを実行する +UTF-8のCOBOLソースコード対応版コンパイラをインストールする場合は、下記のコマンドを実行する。 ``` -curl -L -o opensourcecobol4j-v1.1.2.tar.gz https://github.com/opensourcecobol/opensourcecobol4j/archive/refs/tags/v1.1.2.tar.gz -tar zxvf opensourcecobol4j-v1.1.2.tar.gz -cd opensourcecobol4j-1.1.2 -./configure --prefix=/usr/ +curl -L -o opensourcecobol4j-v1.1.14.tar.gz https://github.com/opensourcecobol/opensourcecobol4j/archive/refs/tags/v1.1.14.tar.gz +tar zxvf opensourcecobol4j-v1.1.14.tar.gz +cd opensourcecobol4j-1.1.14 +./configure --prefix=/usr/ --enable-utf8 +touch cobj/*.m4 make sudo make install ``` ### $CLASSPATHの設定 +/usr/lib/opensourcecobol4j/libcobj.jarを環境変数$CLASSPATHに追加します。 +例えば、Unix系システムで次のコードを実行します。 -/usr/lib/opensourcecobol4j/libcobj.jar を 環境変数$CLASSPATH に追加する. +```bash +export CLASSPATH="$CLASSPATH:/usr/lib/opensourcecobol4j/libcobj.jar" +``` -古いバージョンのインストール方法は、[doc/installation_jp](./doc/installation_jp)をご覧ください. +古いバージョンのインストール方法は、[doc/installation_jp](./doc/installation_jp)をご覧ください。 -## opensource COBOL 4Jのインストール (Windows) +## インストール (Windows) ### Visual Studioのインストール -Windows版のopensource COBOL 4JはVisual Studioに含まれるCLコンパイラを使用します. -そのため、まずは[Visual Studio](https://visualstudio.microsoft.com/)をインストールしてください. - -### Javaファイルのビルド -1. JDKをインストールする. -https://www.oracle.com/java/technologies/downloads/?er=221886#java8-windows -2. PowerShellを開く. -3. libcobjディレクトリに移動し、`./gradlew shadowJar`を実行する. -![alt text](image/readme3.png) -これにより、"libcobj.jar"が`libcobj/app/build/libs/`に作成される. +Windows版のopensource COBOL 4JはVisual Studioに含まれるCLコンパイラを使用します。 +そのため、まずは[Visual Studio](https://visualstudio.microsoft.com/)をインストールする必要があります。 ### ソリューションファイルのビルド -1. opensource COBOL 4Jのファイル一式をダウンロードする. -2. win/opensourcecobol4j.slnをVisual Studioで開く. -3. ”Debug”または”Release”モードを選択する. -![alt text](image/readme1.png) -4. ”ビルド” -> ”ソリューションのビルド” を選択する. -![alt text](image/readme2.png) -ビルドが完了したら、`win/x64/Debug`または`win/x64/Release`に"cobj.exe"が生成される. - -### ファイルの配置 -1. Debugモードでビルドした場合、win/make-install.ps1の5行目を`\x64\Release\cobj.exe`から`\x64\Debug\cobj.exe`に変更する. -2. PowerShellを開く. -3. ”win”ディレクトリに移動し、make-install.ps1を実行する. -![alt text](image/readme4.png) -* ファイルは下記の場所にそれぞれ配置される. -* ファイルの配置場所を変更したい場合は、make-install.ps1に記載してあるパスを編集する. - -| ファイル名 | 配置場所 | -|---|---| -| cobj.exe | C:\opensourcecobol4j\bin | -| libcobj.jar | C:\opensourcecobol4j\lib | -| configファイル | C:\opensourcecobol4j\config | +1. opensource COBOL 4Jのファイル一式をダウンロードする。 +2. Visual Studioでwin/opensourcecobol4j.slnを開く。 +3. ”Debug”または”Release”モードを選択する。 + ![alt text](image/readme1.png) +4. ”ビルド” -> ”ソリューションのビルド” を選択する。 + ![alt text](image/readme2.png) + ビルドが完了すると、`win/x64/Debug`または`win/x64/Release`に"cobj.exe"が作成される。 -### 環境変数の設定 -1. 環境変数PATHに`C:\opensourcecobol4j\bin`を追加する. -2. 環境変数CLASSPATHに`C:\opensourcecobol4j\lib\libcobj.jar`を追加する. +### Javaファイルのビルド +1. JDKをインストールする。 + https://www.oracle.com/java/technologies/downloads/?er=221886#java8-windows +2. PowerShellを開く。 +3. "libcobj"ディレクトリに移動し、`.\gradlew shadowJar`を実行する。 + ``` + cd libcobj + .\gradlew shadowJar + ``` + これにより、`libcobj\app\build\libs\`に"libcobj.jar"が作成される。 + +### ファイルを適切な位置に配置 +1. Debugモードでビルドした場合、`win/make-install.ps1`の5行目を`\x64\Release\cobj.exe`から`\x64\Debug\cobj.exe`に変更する。 +2. PowerShellを開く。 +3. ”win”ディレクトリに移動し、`make-install.ps1`を実行する。 + ``` + cd win + .\make-install.ps1 + ``` +* 各ファイルは以下の場所に配置されます。 + | ファイル名 | 配置場所 | + |---|---| + | cobj.exe | C:\opensourcecobol4j\bin | + | libcobj.jar | C:\opensourcecobol4j\lib | + | configファイル | C:\opensourcecobol4j\config | + +* ファイルの配置場所を変更したい場合は、`make-install.ps1`に記載してあるパスを編集してください。 -## Dockerによるインストール +### 環境変数の設定 +1. `C:\opensourcecobol4j\bin`を環境変数PATHに追加する。 +2. `C:\opensourcecobol4j\lib\libcobj.jar`を環境変数CLASSPATHに追加する。 -opensource COBOL 4J v1.1.2をインストールしたDockerイメージを利用できます. +## Dockerを使ったインストール +opensource COBOL 4JのDockerコンテナを利用できます。 ```bash -docker pull opensourcecobol/opensourcecobol4j:1.1.2 +docker pull opensourcecobol/opensourcecobol4j:20251031 ``` -コンテナ内で下記のコマンドを実行すると、Hello Worldプログラムをコンパイル&実行できる. +以下のコマンドを実行して、"Hello World"のCOBOLプログラムを実行します。 ``` bash -# Move to the sample directory +# サンプルディレクトリに移動 $ cd /root/cobol_sample -# Translate COBOL to Java and compile the Java source file. +# COBOLをJavaに変換し、Javaソースファイルをコンパイル $ cobj HELLO.cbl -# Run "Hello World" +# "Hello World"を実行 $ java HELLO HELLO WORLD! ``` ## 使い方 - -コンパイル. +コンパイルします。 ```bash cobj [COBOL source file] ``` -(cobjコマンドにより,カレントディレクトリに[PROGRAM-ID].javaと[PROGRAM-ID].classが生成されます.) +(cobjコマンドにより、カレントディレクトリに[PROGRAM-ID].javaと[PROGRAM-ID].classが生成されます。) -実行. +実行します。 ```bash java [PROGRAM-ID] ``` -## ランタイムライブラリのAPIリファレンス - -ランタイムライブラリである`libcobj.jar`のAPIリファレンスは[こちら](https://opensourcecobol.github.io/opensourcecobol4j/javadoc/libcobj/index.html)から確認できます。 -## 実装状況 +## ドキュメント -実装済み +* [ランタイムライブラリ`libcobj.jar`のAPIリファレンス](https://opensourcecobol.github.io/opensourcecobol4j/javadoc/libcobj/index.html) +* [opensource COBOL 4J: Java変換解説](./doc/converted_Java_file_JP.md) +* [configuration-params-JP](./doc/configuration-params-JP.md) +* [INDEXEDファイルのロックの仕様](./doc/specification-locking-indexed-file_JP.md) -* 基本的なデータ操作 (MOVE, COMPUTE, ... ) -* 制御文 (IF, PERFORM, GO TO, ...) -* DISPLAY文, ACCEPT文 +## 実装状況 +実装済み機能: +* 基本的なデータ操作 (MOVE, COMPUTEなど) +* 制御文 (IF, PERFORM, GO TOなど) +* 一部のI/O機能 (DISPLAY, ACCEPTなど) * CALLによる呼び出し * SEQUENTIALファイルの入出力機能 * RELATIVEファイルの入出力機能 * INDEXEDファイルの入出力機能 * SORT文 -* 組み込み関数 (ACOS, LENGTH, MAX, ...) - -## テストのステータス - -### NIST COBOL85 test suite +* 組み込み関数 (ACOS, LENGTH, MAXなど) -opensource COBOL 4Jは[NIST COBOL85 test suite](https://www.itl.nist.gov/div897/ctg/cobol_fo -rm.htm)によりテストされています. +## NIST85テストの状況 +opensource COBOL 4Jは[NIST COBOL85 test suite](https://www.itl.nist.gov/div897/ctg/cobol_form.htm)によりテストされています。 -主要テスト結果 +主要テスト結果: ``` ------ Directory Information ------- --- Total Tests Information --- @@ -190,7 +197,7 @@ RL 32 32 0 0 1827 0 5 0 1832 Relativ Total 361 361 0 0 8804 0 21 93 8918 ``` -その他のテストの結果 +追加テストの結果: ``` ------ directory information ------- --- total tests information --- @@ -203,7 +210,7 @@ rw 4 0 4 0 0 0 0 0 0 REPORT total 21 0 21 0 0 0 0 0 0 ``` ## cobj-idx -`cobj-idx` コマンドはINDEXEDファイルを扱うためのユーティリティで、opensource COBOL 4Jの一部としてインストールされます. +`cobj-idx`コマンドはINDEXEDファイルを扱うためのユーティリティで、opensource COBOL 4Jをインストールする際に、一緒にインストールされます。 ``` cobj-idx - A utility tool to handle an indexed file of opensource COBOL 4J @@ -211,18 +218,29 @@ cobj-idx - A utility tool to handle an indexed file of opensource COBOL 4J Usage: cobj-idx [options] -Sub commands: cobj-idx info Show information of the indexed file. +cobj-idx create --size= --key= + Create a new indexed file. + The record size and key information are specified by the options. + By default, this command does not overwrite the indexed file. + To overwrite the indexed file, use the --new option. + Example) cobj-idx create test.idx --size=100 --key=2,2:5,4:d15,5 + File name: test.idx + Record size: 100 + Primary key: 2-3 + Alternate key (No Duplicates):5-8 + Alternate key (Duplicates): 15-19 + cobj-idx load Load the data from stdin into the indexed file. - The default format of the input data is SQUENTIAL of COBOL. + The default format of the input data is SEQUENTIAL of COBOL. cobj-idx load - Load data from the input fiile into the indexed file. - The default format of the input data is SQUENTIAL of COBOL. + Load data from the input file into the indexed file. + The default format of the input data is SEQUENTIAL of COBOL. cobj-idx unload Write the records stored in the indexed file into stdout. @@ -249,10 +267,11 @@ Options: -v, --version Print the version of cobj-idx. + ``` ## cobj-api -cobj-apiコマンドを使用することで、`cobj`で生成されたプログラムを呼び出すSpring boot向けのJavaファイルを簡単に生成できます. +`cobj-api`コマンドを使用することで、`cobj`で生成されたプログラムを呼び出すSpring boot向けのJavaファイルを簡単に生成できます。 ``` Usage: cobj-api [options] @@ -266,8 +285,8 @@ Options: -o=, --output-dir= Set the output destination of the java file to an arbitrary destination -v, --version Prints the version of the cobj-api ``` +cobj-apiを用いたSpring Bootアプリケーションの作成方法については、[こちら](./doc/cobj-api_SpringBoot_JP.md)をご覧ください。 ## コントリビューㇳ - -コントリビュータの一覧は https://github.com/opensourcecobol/opensourcecobol4j/graphs/contributors に掲載されています. -コントリビュータ向けのガイドラインは[CONTRIBUTING_JP.md](./CONTRIBUTING_JP.md)を参照してください. +コントリビュータ向けのガイドラインは[CONTRIBUTING_JP.md](./CONTRIBUTING_JP.md)を参照してください。 +コントリビュータの一覧は https://github.com/opensourcecobol/opensourcecobol4j/graphs/contributors に掲載されています。 diff --git a/ReleaseNote.md b/ReleaseNote.md index c48dd1a6..ac034cb0 100644 --- a/ReleaseNote.md +++ b/ReleaseNote.md @@ -1,9 +1,8 @@ -# Added -* Add a new command line option `-Wtruncate`. - * When `-Wtruncate` is enabled, cobj warns data truncations of MOVE statements. -# Fix -* Fix `CALL (an integer) BY CONTENT`. -* Change `-m` option so that generated jar files contains only class files. Now `-m` becomes an alias of `-jar`. -* Show an error message when SCREEN SECTION is found. -# Miscellaneous -* Improve code generated by cobj-api. \ No newline at end of file +### Improved +* `cobj` now preserves string concatenation structure in the generated Java code. (#731) + +### Fixed +* Fix the implementation of `PROGRAM STATUS`. (#735) + +### Miscellaneous +* For Windows support, tests are now run on Windows Server 2025. (#732) diff --git a/aclocal.m4 b/aclocal.m4 index e795c66f..63cb62ce 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -1,6 +1,6 @@ -# generated automatically by aclocal 1.16.5 -*- Autoconf -*- +# generated automatically by aclocal 1.16.2 -*- Autoconf -*- -# Copyright (C) 1996-2021 Free Software Foundation, Inc. +# Copyright (C) 1996-2020 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -14,8 +14,8 @@ m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])]) m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl -m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.71],, -[m4_warning([this file was generated for autoconf 2.71. +m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.69],, +[m4_warning([this file was generated for autoconf 2.69. You have another version of autoconf. It may work, but is not guaranteed to. If you have problems, you may need to regenerate the build system entirely. To do so, use the procedure documented by the package, typically 'autoreconf'.])]) @@ -3453,6 +3453,7 @@ _LT_CONFIG_SAVE_COMMANDS([ cat <<_LT_EOF >> "$cfgfile" #! $SHELL # Generated automatically by $as_me ($PACKAGE) $VERSION +# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: # NOTE: Changes made to this file will be lost: look at ltmain.sh. # Provide generalized library-building support services. @@ -3764,8 +3765,8 @@ int forced_loaded() { return 2;} _LT_EOF echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&AS_MESSAGE_LOG_FD $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&AS_MESSAGE_LOG_FD - echo "$AR cr libconftest.a conftest.o" >&AS_MESSAGE_LOG_FD - $AR cr libconftest.a conftest.o 2>&AS_MESSAGE_LOG_FD + echo "$AR cru libconftest.a conftest.o" >&AS_MESSAGE_LOG_FD + $AR cru libconftest.a conftest.o 2>&AS_MESSAGE_LOG_FD echo "$RANLIB libconftest.a" >&AS_MESSAGE_LOG_FD $RANLIB libconftest.a 2>&AS_MESSAGE_LOG_FD cat > conftest.c << _LT_EOF @@ -3794,11 +3795,11 @@ _LT_EOF # to the OS version, if on x86, and 10.4, the deployment # target defaults to 10.4. Don't you love it? case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in - 10.0,*86*-darwin8*|10.0,*-darwin[[912]]*) + 10.0,*86*-darwin8*|10.0,*-darwin[[91]]*) _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; 10.[[012]][[,.]]*) _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; - 10.*|11.*) + 10.*) _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; esac ;; @@ -4215,7 +4216,7 @@ need_locks=$enable_libtool_lock m4_defun([_LT_PROG_AR], [AC_CHECK_TOOLS(AR, [ar], false) : ${AR=ar} -: ${AR_FLAGS=cr} +: ${AR_FLAGS=cru} _LT_DECL([], [AR], [1], [The archiver]) _LT_DECL([], [AR_FLAGS], [1], [Flags to create an archive]) @@ -5589,6 +5590,9 @@ linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) # before this can be enabled. hardcode_into_libs=yes + # Add ABI-specific directories to the system library path. + sys_lib_dlsearch_path_spec="/lib64 /usr/lib64 /lib /usr/lib" + # Ideally, we could use ldconfig to report *all* directores which are # searched for libraries, however this is still not possible. Aside from not # being certain /sbin/ldconfig is available, command @@ -5597,7 +5601,7 @@ linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) # appending ld.so.conf contents (and includes) to the search path. if test -f /etc/ld.so.conf; then lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` - sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" + sys_lib_dlsearch_path_spec="$sys_lib_dlsearch_path_spec $lt_ld_extra" fi # We used to test for /lib/ld.so.1 and disable shared libraries on @@ -5609,18 +5613,6 @@ linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) dynamic_linker='GNU/Linux ld.so' ;; -netbsdelf*-gnu) - version_type=linux - need_lib_prefix=no - need_version=no - library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' - soname_spec='${libname}${release}${shared_ext}$major' - shlibpath_var=LD_LIBRARY_PATH - shlibpath_overrides_runpath=no - hardcode_into_libs=yes - dynamic_linker='NetBSD ld.elf_so' - ;; - netbsd*) version_type=sunos need_lib_prefix=no @@ -6280,7 +6272,7 @@ linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) lt_cv_deplibs_check_method=pass_all ;; -netbsd* | netbsdelf*-gnu) +netbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' else @@ -6786,8 +6778,7 @@ _LT_EOF if AC_TRY_EVAL(ac_compile); then # Now try to grab the symbols. nlist=conftest.nm - $ECHO "$as_me:$LINENO: $NM conftest.$ac_objext | $lt_cv_sys_global_symbol_pipe > $nlist" >&AS_MESSAGE_LOG_FD - if eval "$NM" conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist 2>&AS_MESSAGE_LOG_FD && test -s "$nlist"; then + if AC_TRY_EVAL(NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist) && test -s "$nlist"; then # Try sorting and uniquifying the output. if sort "$nlist" | uniq > "$nlist"T; then mv -f "$nlist"T "$nlist" @@ -7159,7 +7150,7 @@ m4_if([$1], [CXX], [ ;; esac ;; - netbsd* | netbsdelf*-gnu) + netbsd*) ;; *qnx* | *nto*) # QNX uses GNU C++, but need to define -shared option too, otherwise @@ -7427,12 +7418,6 @@ m4_if([$1], [CXX], [ _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' ;; - # flang / f18. f95 an alias for gfortran or flang on Debian - flang* | f18* | f95*) - _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' - _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' - _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' - ;; # icc used to be incompatible with GCC. # ICC 10 doesn't accept -KPIC any more. icc* | ifort*) @@ -7677,9 +7662,6 @@ m4_if([$1], [CXX], [ ;; esac ;; - linux* | k*bsd*-gnu | gnu*) - _LT_TAGVAR(link_all_deplibs, $1)=no - ;; *) _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' ;; @@ -7742,9 +7724,6 @@ dnl Note also adjust exclude_expsyms for C++ above. openbsd* | bitrig*) with_gnu_ld=no ;; - linux* | k*bsd*-gnu | gnu*) - _LT_TAGVAR(link_all_deplibs, $1)=no - ;; esac _LT_TAGVAR(ld_shlibs, $1)=yes @@ -7999,7 +7978,7 @@ _LT_EOF fi ;; - netbsd* | netbsdelf*-gnu) + netbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' wlarc= @@ -8520,7 +8499,6 @@ _LT_EOF if test yes = "$lt_cv_irix_exported_symbol"; then _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations $wl-exports_file $wl$export_symbols -o $lib' fi - _LT_TAGVAR(link_all_deplibs, $1)=no else _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -exports_file $export_symbols -o $lib' @@ -8542,7 +8520,7 @@ _LT_EOF esac ;; - netbsd* | netbsdelf*-gnu) + netbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out else @@ -9164,7 +9142,7 @@ if test yes != "$_lt_caught_CXX_error"; then # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' else GXX=no @@ -9539,7 +9517,7 @@ if test yes != "$_lt_caught_CXX_error"; then # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. - output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP " \-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' ;; *) if test yes = "$GXX"; then @@ -9604,7 +9582,7 @@ if test yes != "$_lt_caught_CXX_error"; then # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. - output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP " \-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' ;; *) if test yes = "$GXX"; then @@ -9943,7 +9921,7 @@ if test yes != "$_lt_caught_CXX_error"; then # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' else # FIXME: insert proper C++ library support @@ -10027,7 +10005,7 @@ if test yes != "$_lt_caught_CXX_error"; then # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' else # g++ 2.7 appears to require '-G' NOT '-shared' on this # platform. @@ -10038,7 +10016,7 @@ if test yes != "$_lt_caught_CXX_error"; then # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' + output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' fi _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R $wl$libdir' @@ -12359,7 +12337,7 @@ fi AC_SUBST([$1])dnl ]) -# Copyright (C) 2002-2021 Free Software Foundation, Inc. +# Copyright (C) 2002-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -12374,7 +12352,7 @@ AC_DEFUN([AM_AUTOMAKE_VERSION], [am__api_version='1.16' dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to dnl require some minimum version. Point them to the right macro. -m4_if([$1], [1.16.5], [], +m4_if([$1], [1.16.2], [], [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl ]) @@ -12390,14 +12368,14 @@ m4_define([_AM_AUTOCONF_VERSION], []) # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced. # This function is AC_REQUIREd by AM_INIT_AUTOMAKE. AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], -[AM_AUTOMAKE_VERSION([1.16.5])dnl +[AM_AUTOMAKE_VERSION([1.16.2])dnl m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) # AM_AUX_DIR_EXPAND -*- Autoconf -*- -# Copyright (C) 2001-2021 Free Software Foundation, Inc. +# Copyright (C) 2001-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -12449,7 +12427,7 @@ am_aux_dir=`cd "$ac_aux_dir" && pwd` # AM_CONDITIONAL -*- Autoconf -*- -# Copyright (C) 1997-2021 Free Software Foundation, Inc. +# Copyright (C) 1997-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -12480,7 +12458,7 @@ AC_CONFIG_COMMANDS_PRE( Usually this means the macro was only invoked conditionally.]]) fi])]) -# Copyright (C) 1999-2021 Free Software Foundation, Inc. +# Copyright (C) 1999-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -12671,7 +12649,7 @@ _AM_SUBST_NOTMAKE([am__nodep])dnl # Generate code to set up dependency tracking. -*- Autoconf -*- -# Copyright (C) 1999-2021 Free Software Foundation, Inc. +# Copyright (C) 1999-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -12739,7 +12717,7 @@ AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], # Do all the work for Automake. -*- Autoconf -*- -# Copyright (C) 1996-2021 Free Software Foundation, Inc. +# Copyright (C) 1996-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -12767,10 +12745,6 @@ m4_defn([AC_PROG_CC]) # release and drop the old call support. AC_DEFUN([AM_INIT_AUTOMAKE], [AC_PREREQ([2.65])dnl -m4_ifdef([_$0_ALREADY_INIT], - [m4_fatal([$0 expanded multiple times -]m4_defn([_$0_ALREADY_INIT]))], - [m4_define([_$0_ALREADY_INIT], m4_expansion_stack)])dnl dnl Autoconf wants to disallow AM_ names. We explicitly allow dnl the ones we care about. m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl @@ -12807,7 +12781,7 @@ m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl [_AM_SET_OPTIONS([$1])dnl dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT. m4_if( - m4_ifset([AC_PACKAGE_NAME], [ok]):m4_ifset([AC_PACKAGE_VERSION], [ok]), + m4_ifdef([AC_PACKAGE_NAME], [ok]):m4_ifdef([AC_PACKAGE_VERSION], [ok]), [ok:ok],, [m4_fatal([AC_INIT should be called with package and version arguments])])dnl AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl @@ -12859,20 +12833,6 @@ AC_PROVIDE_IFELSE([AC_PROG_OBJCXX], [m4_define([AC_PROG_OBJCXX], m4_defn([AC_PROG_OBJCXX])[_AM_DEPENDENCIES([OBJCXX])])])dnl ]) -# Variables for tags utilities; see am/tags.am -if test -z "$CTAGS"; then - CTAGS=ctags -fi -AC_SUBST([CTAGS]) -if test -z "$ETAGS"; then - ETAGS=etags -fi -AC_SUBST([ETAGS]) -if test -z "$CSCOPE"; then - CSCOPE=cscope -fi -AC_SUBST([CSCOPE]) - AC_REQUIRE([AM_SILENT_RULES])dnl dnl The testsuite driver may need to know about EXEEXT, so add the dnl 'am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen. This @@ -12954,7 +12914,7 @@ for _am_header in $config_headers :; do done echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count]) -# Copyright (C) 2001-2021 Free Software Foundation, Inc. +# Copyright (C) 2001-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -12975,7 +12935,7 @@ if test x"${install_sh+set}" != xset; then fi AC_SUBST([install_sh])]) -# Copyright (C) 2003-2021 Free Software Foundation, Inc. +# Copyright (C) 2003-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -12997,7 +12957,7 @@ AC_SUBST([am__leading_dot])]) # Add --enable-maintainer-mode option to configure. -*- Autoconf -*- # From Jim Meyering -# Copyright (C) 1996-2021 Free Software Foundation, Inc. +# Copyright (C) 1996-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -13032,7 +12992,7 @@ AC_MSG_CHECKING([whether to enable maintainer-specific portions of Makefiles]) # Check to see how 'make' treats includes. -*- Autoconf -*- -# Copyright (C) 2001-2021 Free Software Foundation, Inc. +# Copyright (C) 2001-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -13075,7 +13035,7 @@ AC_SUBST([am__quote])]) # Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- -# Copyright (C) 1997-2021 Free Software Foundation, Inc. +# Copyright (C) 1997-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -13096,7 +13056,12 @@ AC_DEFUN([AM_MISSING_HAS_RUN], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl AC_REQUIRE_AUX_FILE([missing])dnl if test x"${MISSING+set}" != xset; then - MISSING="\${SHELL} '$am_aux_dir/missing'" + case $am_aux_dir in + *\ * | *\ *) + MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; + *) + MISSING="\${SHELL} $am_aux_dir/missing" ;; + esac fi # Use eval to expand $SHELL if eval "$MISSING --is-lightweight"; then @@ -13109,7 +13074,7 @@ fi # Helper functions for option handling. -*- Autoconf -*- -# Copyright (C) 2001-2021 Free Software Foundation, Inc. +# Copyright (C) 2001-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -13138,7 +13103,7 @@ AC_DEFUN([_AM_SET_OPTIONS], AC_DEFUN([_AM_IF_OPTION], [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) -# Copyright (C) 1999-2021 Free Software Foundation, Inc. +# Copyright (C) 1999-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -13185,7 +13150,7 @@ AC_LANG_POP([C])]) # For backward compatibility. AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])]) -# Copyright (C) 2001-2021 Free Software Foundation, Inc. +# Copyright (C) 2001-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -13204,7 +13169,7 @@ AC_DEFUN([AM_RUN_LOG], # Check to make sure that the build environment is sane. -*- Autoconf -*- -# Copyright (C) 1996-2021 Free Software Foundation, Inc. +# Copyright (C) 1996-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -13285,7 +13250,7 @@ AC_CONFIG_COMMANDS_PRE( rm -f conftest.file ]) -# Copyright (C) 2009-2021 Free Software Foundation, Inc. +# Copyright (C) 2009-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -13345,7 +13310,7 @@ AC_SUBST([AM_BACKSLASH])dnl _AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl ]) -# Copyright (C) 2001-2021 Free Software Foundation, Inc. +# Copyright (C) 2001-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -13373,7 +13338,7 @@ fi INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" AC_SUBST([INSTALL_STRIP_PROGRAM])]) -# Copyright (C) 2006-2021 Free Software Foundation, Inc. +# Copyright (C) 2006-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -13392,7 +13357,7 @@ AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)]) # Check how to create a tarball. -*- Autoconf -*- -# Copyright (C) 2004-2021 Free Software Foundation, Inc. +# Copyright (C) 2004-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, diff --git a/bin/Makefile.in b/bin/Makefile.in index 94357239..b0af4b8b 100644 --- a/bin/Makefile.in +++ b/bin/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.16.5 from Makefile.am. +# Makefile.in generated by automake 1.16.2 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2021 Free Software Foundation, Inc. +# Copyright (C) 1994-2020 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -217,6 +217,8 @@ am__define_uniq_tagged_files = \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/cob-config.in \ $(top_srcdir)/depcomp $(top_srcdir)/mkinstalldirs ChangeLog DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -253,8 +255,6 @@ COB_SHARED_OPT = @COB_SHARED_OPT@ COB_SPLITKEY_FLAGS = @COB_SPLITKEY_FLAGS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ -CSCOPE = @CSCOPE@ -CTAGS = @CTAGS@ CXXCPP = @CXXCPP@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ @@ -266,7 +266,6 @@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ -ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ @@ -600,6 +599,7 @@ cscopelist-am: $(am__tagged_files) distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am diff --git a/check-format b/check-format index 8a2c7174..505b1662 100755 --- a/check-format +++ b/check-format @@ -1,3 +1,3 @@ #!/bin/bash -cd libcobj && ./gradlew verGJF +cd libcobj && ./gradlew spotlessCheck cd ../cobj && ./check-format diff --git a/cobj/Makefile.in b/cobj/Makefile.in index 1e0fd25f..e7926526 100644 --- a/cobj/Makefile.in +++ b/cobj/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.16.5 from Makefile.am. +# Makefile.in generated by automake 1.16.2 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2021 Free Software Foundation, Inc. +# Copyright (C) 1994-2020 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -200,6 +200,8 @@ am__define_uniq_tagged_files = \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp \ $(top_srcdir)/mkinstalldirs ChangeLog DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -236,8 +238,6 @@ COB_SHARED_OPT = @COB_SHARED_OPT@ COB_SPLITKEY_FLAGS = @COB_SPLITKEY_FLAGS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ -CSCOPE = @CSCOPE@ -CTAGS = @CTAGS@ CXXCPP = @CXXCPP@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ @@ -249,7 +249,6 @@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ -ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ @@ -732,6 +731,7 @@ cscopelist-am: $(am__tagged_files) distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am @@ -775,8 +775,7 @@ installdirs: done install: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) install-am -install-exec: $(BUILT_SOURCES) - $(MAKE) $(AM_MAKEFLAGS) install-exec-am +install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am @@ -899,7 +898,7 @@ ps-am: uninstall-am: uninstall-binPROGRAMS -.MAKE: all check install install-am install-exec install-strip +.MAKE: all check install install-am install-strip .PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \ clean-binPROGRAMS clean-generic clean-libtool cscopelist-am \ diff --git a/cobj/cobj.c b/cobj/cobj.c index 366196f0..48cafbad 100644 --- a/cobj/cobj.c +++ b/cobj/cobj.c @@ -145,10 +145,14 @@ int cb_flag_main = 0; int cb_default_byte_specified = 0; unsigned char cb_default_byte = 0; + +int cb_default_select_lock_mode = COB_LOCK_MANUAL; + #define OPTION_ID_DEFAULT_BYTE (1024) #define OPTION_ID_SINGLE_JAR (1025) #define OPTION_ID_JAR (1026) #define OPTION_ID_INFO_JSON (1027) +#define OPTION_ID_LOCK_MODE_AUTOMATIC (1028) int external_flg = 0; int errorcount = 0; @@ -194,9 +198,6 @@ char *cb_single_jar_name = NULL; int cb_flag_info_json = 0; char *cb_info_json_dir = NULL; -char edit_code_command[512]; -char edit_code_command_is_set = 0; - #define PROGRAM_ID_LIST_MAX_LEN 1024 char *program_id_list[PROGRAM_ID_LIST_MAX_LEN]; @@ -303,6 +304,7 @@ static const struct option long_options[] = { {"free", no_argument, &cb_source_format, CB_FORMAT_FREE}, {"free_1col_aster", no_argument, &cb_source_format, CB_FORMAT_FREE_1COL_ASTER}, + {"variable", no_argument, &cb_source_format, CB_FORMAT_VARIABLE}, {"fixed", no_argument, &cb_source_format, CB_FORMAT_FIXED}, {"static", no_argument, &cb_flag_static_call, 1}, {"dynamic", no_argument, &cb_flag_static_call, 0}, @@ -313,7 +315,7 @@ static const struct option long_options[] = { {"reference_check", no_argument, NULL, 'K'}, {"constant", optional_argument, NULL, '3'}, {"fdefaultbyte", required_argument, NULL, OPTION_ID_DEFAULT_BYTE}, - {"edit-code-command", optional_argument, NULL, '['}, + {"lock-mode-automatic", no_argument, NULL, OPTION_ID_LOCK_MODE_AUTOMATIC}, #undef CB_FLAG #define CB_FLAG(var, name, doc) \ {"f" name, no_argument, &var, 1}, {"fno-" name, no_argument, &var, 0}, @@ -328,6 +330,12 @@ static const struct option long_options[] = { #undef CB_WARNDEF {NULL, 0, NULL, 0}}; +#ifdef I18N_UTF8 +static const char *JAVAC_ENCODING = "UTF-8"; +#else +static const char *JAVAC_ENCODING = "SJIS"; +#endif + static const char *cob_cc; /* gcc */ static char cob_java_flags[COB_SMALL_BUFF]; /* -I... */ static char cob_libs[COB_MEDIUM_BUFF]; /* -L... -lcob */ @@ -663,6 +671,64 @@ void sjis_spc_to_ascii(char *str) { } #endif /*I18N_UTF8*/ +#ifdef I18N_UTF8 +size_t utf8_calc_sjis_size(const unsigned char *p, int len) { + const unsigned char *ub = p + len; + int char_size = 0; + size_t name_size = 0; + while (p < ub) { + char_size = COB_U8BYTE_1(*p); + if (char_size == 1) { + name_size += 1; + p++; + } else if (char_size == 3 && utf8_hankaku_kana(p)) { + name_size += 1; + p += char_size; + } else { + name_size += 2; + p += char_size; + } + } + return name_size; +} + +int utf8_hankaku_kana(const unsigned char *p) { + if (p[0] == 0xef) { + if (p[1] == 0xbd) { + if (p[2] >= 0xa1 && p[2] <= 0xbf) { + return 1; + } + } else if (p[1] == 0xbe) { + if (p[2] >= 0x80 && p[2] <= 0x9f) { + return 1; + } + } + } + return 0; +} + +int utf8_calc_sjis_column(const unsigned char *p, int column) { + const unsigned char *start = p; + int char_size = 0; + int i = 0; + + while (i < column && *p != '\0') { + char_size = COB_U8BYTE_1(*p); + if (char_size == 1) { + i++; + p++; + } else if (char_size == 3 && utf8_hankaku_kana(p)) { + i++; + p += char_size; + } else { + i += 2; + p += char_size; + } + } + return p - start; +} +#endif /*I18N_UTF8*/ + /* * Local functions */ @@ -783,8 +849,13 @@ static void cobc_print_version(void) { #endif /*I18N_UTF8*/ puts("----"); printf("cobj (%s) %s\n", PACKAGE_NAME, PACKAGE_VERSION); - puts("Copyright (C) 2021-2023 TOKYO SYSTEM HOUSE CO.,LTD."); + puts("Copyright (C) 2021-2025 TOKYO SYSTEM HOUSE CO.,LTD."); printf("Built %s\n", cb_oc_build_stamp); + puts("----"); + puts("cobc (opensource COBOL) 1.5.2.0"); + puts("----"); + puts("cobc (OpenCOBOL) 1.1"); + puts("Copyright (C) 2001-2009 Keisuke Nishida / Roger While"); } static void cobc_print_usage(void) { @@ -802,6 +873,8 @@ static void cobc_print_usage(void) { puts(_(" -free Use free source format")); puts(_(" -free_1col_aster Use free(1col_aster) source " "format")); + puts(_(" -variable Allow codes after 72 digits not " + "to be ignored")); puts(_(" -g Enable Java compiler debug")); puts(_(" -debug Enable all run-time error " "checking")); @@ -833,13 +906,15 @@ static void cobc_print_usage(void) { "representing a character")); puts(_(" * octodecimal 00..0377 " "representing a character")); + puts(_(" -lock-mode-automatic Set the default lock mode of " + "select clauses to AUTOMATIC")); puts(_(" -info-json-dir= Specify the directory path of " "JSON files that hold information of COBOL programs")); puts(_(" -java-package(=) Specify the package name of the " "generated source code")); puts(_(" -m, -jar Create .jar and " "remove class files")); - puts(_(" -single-jar= Create .jar and " + puts(_(" -single-jar= Create and " "remove class files")); puts(_(" The JAR file contains all class " "files of all specified COBOL programs")); @@ -1088,6 +1163,10 @@ static int process_command_line(const int argc, char *argv[]) { fflush(stderr); break; + case OPTION_ID_LOCK_MODE_AUTOMATIC: + cb_default_select_lock_mode = COB_LOCK_AUTOMATIC; + break; + case '3': /* --constant */ if (optarg) { cb_constant_list_add(optarg); @@ -1134,10 +1213,6 @@ static int process_command_line(const int argc, char *argv[]) { perror(optarg); } break; - case '[': - strcpy(edit_code_command, optarg); - edit_code_command_is_set = 1; - break; case 'I': #ifdef _MSC_VER @@ -1359,7 +1434,7 @@ static char *cobc_temp_name(const char *ext) { #ifdef _WIN32 char temp[MAX_PATH]; - GetTempPath2A(MAX_PATH, temp); + GetTempPathA(MAX_PATH, temp); GetTempFileNameA(temp, "cob", 0, buff); DeleteFile(buff); strcpy(buff + strlen(buff) - 4, ext); /* replace ".tmp" by EXT */ @@ -1769,8 +1844,9 @@ static int process_compile(struct filename *fn) { char **program_id; for (program_id = program_id_list; *program_id; ++program_id) { - snprintf(buff, COB_MEDIUM_BUFF, "javac %s -encoding SJIS -d %s %s/%s.java", - cob_java_flags, output_name_a, java_source_dir_a, *program_id); + snprintf(buff, COB_MEDIUM_BUFF, "javac %s -encoding %s -d %s %s/%s.java", + cob_java_flags, JAVAC_ENCODING, output_name_a, java_source_dir_a, + *program_id); ret = process(buff); if (ret) { @@ -2041,8 +2117,8 @@ static int process_build_single_jar() { #else char remove_cmd[] = "rm -f"; #endif - sprintf(buff, "javac %s -encoding SJIS -d %s %s/*.java", cob_java_flags, - output_name_a, java_source_dir_a); + sprintf(buff, "javac %s -encoding %s -d %s %s/*.java", cob_java_flags, + JAVAC_ENCODING, output_name_a, java_source_dir_a); ret = process(buff); if (ret) { diff --git a/cobj/cobj.h b/cobj/cobj.h index 76be035e..ea1af270 100644 --- a/cobj/cobj.h +++ b/cobj/cobj.h @@ -36,20 +36,12 @@ #include "lib/gettext.h" #endif -#if !defined(__i386__) && !defined(__x86_64__) && !defined(__powerpc__) && \ - !defined(__powerpc64__) && !defined(__ppc__) && !defined(__amd64__) -#define COB_NON_ALIGNED -/* Some DEC Alphas can only directly load shorts at 4-byte aligned addresses */ -#ifdef __alpha -#define COB_SHORT_BORK -#endif -#endif - #define ABORT() cobc_abort(__FILE__, __LINE__) #define CB_FORMAT_FIXED 0 #define CB_FORMAT_FREE 1 #define CB_FORMAT_FREE_1COL_ASTER 2 +#define CB_FORMAT_VARIABLE 3 extern int cb_source_format; extern int cb_source_format1; @@ -183,9 +175,6 @@ DECLNORET extern void cobc_abort(const char *filename, extern size_t cobc_check_valid_name(char *name); -extern char edit_code_command[512]; -extern char edit_code_command_is_set; - #ifdef I18N_UTF8 #define COB_U8CSIZ 3 @@ -206,6 +195,9 @@ extern size_t utf8_strlen(const unsigned char *p); extern int utf8_casecmp(const char *s1, const char *s2); extern void utf8_spc_to_ascii(char *); extern int utf8_national_length(const unsigned char *str, int len); +extern size_t utf8_calc_sjis_size(const unsigned char *data, int len); +extern int utf8_hankaku_kana(const unsigned char *data); +extern int utf8_calc_sjis_column(const unsigned char *p, int column); #else /*!I18N_UTF8*/ extern const unsigned char *sjis_pick(const unsigned char *); extern size_t sjis_strlen(const unsigned char *); @@ -244,7 +236,10 @@ enum cb_assign_clause { CB_ASSIGN_JPH1 /* JP compatibility */ }; -enum cb_binary_byteorder { CB_BYTEORDER_NATIVE, CB_BYTEORDER_BIG_ENDIAN }; +enum cb_binary_byteorder { + CB_BYTEORDER_LITTLE_ENDIAN, + CB_BYTEORDER_BIG_ENDIAN +}; enum cb_binary_size { CB_BINARY_SIZE_2_4_8, /* 2,4,8 bytes */ @@ -388,4 +383,5 @@ extern int cb_verify(const enum cb_support tag, const char *feature); extern int cb_flag_info_json; extern char *cb_info_json_dir; +extern int cb_default_select_lock_mode; #endif /* CB_COBC_H */ diff --git a/cobj/codegen.c b/cobj/codegen.c index d6dcebd9..ece49c9f 100644 --- a/cobj/codegen.c +++ b/cobj/codegen.c @@ -79,6 +79,8 @@ static const char *excp_current_program_id = NULL; static const char *excp_current_section = NULL; static const char *excp_current_paragraph = NULL; static struct cb_program *current_prog; +static size_t *sgmt_sizes = NULL; +static size_t sgmt_count = 0; extern int cb_default_byte_specified; extern unsigned char cb_default_byte; @@ -87,7 +89,7 @@ extern unsigned char cb_default_byte; static int index_read_flag = 0; static struct label_list { - struct label_list *next; + // struct label_list *next; int id; int call_num; } *label_cache = NULL; @@ -187,7 +189,6 @@ static char *convert_byte_value_format(char value); static void append_label_id_map(struct cb_label *label); static void create_label_id_map(struct cb_program *prog); static void destroy_label_id_map(void); -static void joutput_edit_code_command(const char *target); static void joutput_label_variable(struct cb_label *label); static void joutput_label_variable_name(char *s, int key, @@ -234,31 +235,29 @@ static void get_java_identifier_helper(struct cb_field *f, char *buf) { } static void strcpy_identifier_cobol_to_java(char *buf, const char *identifier) { - int all_ascii = 1; - unsigned char *p = (unsigned char *)identifier; - for (; *p; ++p) { - unsigned char c = *p; - if (c < 0x0A || 0x80 <= c) { - all_ascii = 0; - break; - } - } - - if (all_ascii) { - for (; *identifier; ++identifier, ++buf) { - if (*identifier == '-') { - *buf = '_'; + unsigned char *src = (unsigned char *)identifier; + unsigned char *dst = (unsigned char *)buf; + while (*src) { + // ASCII characters + if (*src < 0x80) { + *dst = (*src == '-') ? '_' : *src; + ++dst; + ++src; + // Shift_JIS characters + } else { + // convert zenkaku hyphen to zenkaku underscore + if (src[0] == 0x81 && src[1] == 0x7C) { + dst[0] = 0x81; + dst[1] = 0x51; } else { - *buf = *identifier; + dst[0] = src[0]; + dst[1] = src[1]; } - } - } else { - for (; *identifier; ++identifier) { - sprintf(buf, "%02x", (unsigned char)*identifier); - buf += 2; + dst += 2; + src += 2; } } - *buf = '\0'; + *dst = '\0'; } struct cb_label_id_map { @@ -451,9 +450,12 @@ static void joutput_indent(const char *str) { } enum cb_string_category { + // all chracters are ASCII CB_STRING_CATEGORY_ALL_ASCII, - CB_STRING_CATEGORY_ALL_SJIS, - CB_STRING_CATEGORY_CONTAINS_NON_SJIS, + // string contains non-ASCII characters but no uncommon characters + CB_STRING_CATEGORY_CONTAINS_NON_ASCII, + // string contains uncommon characters + CB_STRING_CATEGORY_CONTAINS_UNCOMMON, }; struct string_literal_cache { @@ -463,6 +465,7 @@ struct string_literal_cache { enum cb_string_category category; char *var_name; struct string_literal_cache *next; + size_t *segment_sizes; /* segment sizes for strings concatenated with '&' */ }; int string_literal_id = 0; @@ -493,30 +496,88 @@ static enum cb_string_category get_string_category(const unsigned char *s, int c = s[i]; if (0x20 <= c && c <= 0x7e) { i += 1; +#ifdef I18N_UTF8 + } else if (0xc2 <= c && c <= 0xdf) { + if (i + 1 < size && 0x80 <= s[i + 1] && s[i + 1] <= 0xbf) { + i += 2; + category = CB_STRING_CATEGORY_CONTAINS_NON_ASCII; + } else { + return CB_STRING_CATEGORY_CONTAINS_UNCOMMON; + } + } else if (0xe0 <= c && c <= 0xef) { + if (i + 2 < size && 0x80 <= s[i + 1] && s[i + 1] <= 0xbf && + 0x80 <= s[i + 2] && s[i + 2] <= 0xbf) { + i += 3; + category = CB_STRING_CATEGORY_CONTAINS_NON_ASCII; + } else { + return CB_STRING_CATEGORY_CONTAINS_UNCOMMON; + } + } else if (0xf0 <= c && c <= 0xf4) { + if (i + 3 < size && 0x80 <= s[i + 1] && s[i + 1] <= 0xbf && + 0x80 <= s[i + 2] && s[i + 2] <= 0xbf && 0x80 <= s[i + 3] && + s[i + 3] <= 0xbf) { + i += 4; + category = CB_STRING_CATEGORY_CONTAINS_NON_ASCII; + } else { + return CB_STRING_CATEGORY_CONTAINS_UNCOMMON; + } +#else } else if ((0x81 <= c && c <= 0x9f) || (0xe0 <= c && c <= 0xef)) { i += 2; - category = CB_STRING_CATEGORY_ALL_SJIS; + category = CB_STRING_CATEGORY_CONTAINS_NON_ASCII; +#endif } else { - return CB_STRING_CATEGORY_CONTAINS_NON_SJIS; + return CB_STRING_CATEGORY_CONTAINS_UNCOMMON; } } return category; } static void joutput_string_write(const unsigned char *s, int size, - enum cb_string_category category) { + enum cb_string_category category, + const size_t *tmp_sgmt_sizes) { int i; - if (category == CB_STRING_CATEGORY_ALL_ASCII) { +#ifdef I18N_UTF8 + int multi_byte = 0; + if (utf8_ext_pick(s)) { + multi_byte = 1; + } +#endif /* I18N_UTF8 */ + + if (category == CB_STRING_CATEGORY_ALL_ASCII || + category == CB_STRING_CATEGORY_CONTAINS_NON_ASCII +#ifdef I18N_UTF8 + || multi_byte +#endif /* I18N_UTF8 */ + ) { if (param_wrap_string_flag) { joutput("new CobolDataStorage("); } else { joutput("CobolUtil.stringToBytes("); } - + if (tmp_sgmt_sizes) { + joutput_indent_level += 2; + joutput_newline(); + joutput_prefix(); + } joutput("\""); +#ifdef I18N_UTF8 + for (i = 0; i < size; i++) { + int c = s[i]; + if (c == '\"' || c == '\\') { + joutput("\\%c", c); + } else if (c == '\n') { + joutput("\\n"); + } else { + joutput("%c", c); + } + } +#else int output_multibyte = 0; + int sum_sgmt_size = 0; + int sgmt_index = 0; for (i = 0; i < size; i++) { int c = s[i]; if (!output_multibyte && (c == '\"' || c == '\\')) { @@ -526,11 +587,33 @@ static void joutput_string_write(const unsigned char *s, int size, } else { joutput("%c", c); } + + // insert line breaks between segments concatenated with '&' + if (tmp_sgmt_sizes && i < size - 1) { + size_t segment_end_position = + sum_sgmt_size + tmp_sgmt_sizes[sgmt_index] - 1; + if (i == segment_end_position) { + joutput("\" + "); + joutput_newline(); + joutput_prefix(); + joutput("\""); + sum_sgmt_size += tmp_sgmt_sizes[sgmt_index]; + sgmt_index++; + } + } output_multibyte = !output_multibyte && ((0x81 <= c && c <= 0x9f) || (0xe0 <= c && c <= 0xef)); } - - joutput("\")"); +#endif + if (tmp_sgmt_sizes) { + joutput("\""); + joutput_newline(); + joutput_indent_level -= 2; + joutput_prefix(); + joutput(")"); + } else { + joutput("\")"); + } } else { if (param_wrap_string_flag) { joutput("CobolDataStorage.makeCobolDataStorage("); @@ -580,6 +663,16 @@ static void joutput_string(const unsigned char *s, int size) { new_literal_cache->var_name[var_name_length + 1 + i] = '\0'; } + // set segment sizes to new cache + if (sgmt_sizes) { + new_literal_cache->segment_sizes = cobc_malloc(sizeof(size_t) * sgmt_count); + memcpy(new_literal_cache->segment_sizes, sgmt_sizes, + sizeof(size_t) * sgmt_count); + sgmt_sizes = NULL; + } else { + new_literal_cache->segment_sizes = NULL; + } + // add the new cache to string_literal_list new_literal_cache->next = string_literal_list; string_literal_list = new_literal_cache; @@ -607,7 +700,8 @@ static void joutput_all_string_literals() { joutput_prefix(); joutput("public static final %s %s = ", data_type, l->var_name); param_wrap_string_flag = l->param_wrap_string_flag; - joutput_string_write(l->string_value, l->size, l->category); + joutput_string_write(l->string_value, l->size, l->category, + l->segment_sizes); joutput(";\n"); l = l->next; } @@ -623,35 +717,6 @@ static void joutput_local(const char *fmt, ...) { } } -static void joutput_edit_code_command(const char *target) { - if (!edit_code_command_is_set) { - return; - } - - char command[BUF_SIZE]; - char buf[BUF_SIZE]; - sprintf(command, "%s --target=%s", edit_code_command, target); - -#ifdef _WIN32 - FILE *fp = _popen(command, "r"); -#else - FILE *fp = popen(command, "r"); -#endif - if (fp == NULL) { - return; - } - memset(buf, 0, BUF_SIZE); - - while (fgets(buf, BUF_SIZE, fp) != NULL) { - joutput("%s", buf); - } -#ifdef _WIN32 - _pclose(fp); -#else - pclose(fp); -#endif -} - /* * Field */ @@ -755,7 +820,6 @@ static int is_call_parameter(const struct cb_field *f) { } static int joutput_field_storage(struct cb_field *f, struct cb_field *top) { - const char *p; int flag_call_parameter = is_call_parameter(top); if (flag_call_parameter || (f->offset == 0 && strcmp(f->name, top->name) == 0)) { @@ -763,34 +827,9 @@ static int joutput_field_storage(struct cb_field *f, struct cb_field *top) { joutput(base_name); free(base_name); return flag_call_parameter; - } else if (cb_flag_short_variable) { - joutput("b_"); - for (p = f->name; *p != '\0'; ++p) { - if (*p == '-') { - joutput("_"); - } else { - joutput("%c", *p); - } - } } else { - joutput("b_"); - struct cb_field *field = f; - int flag_first_iteration = 1; - while (field) { - if (flag_first_iteration) { - flag_first_iteration = 0; - } else { - joutput("__"); - } - for (p = field->name; *p != '\0'; ++p) { - if (*p == '-') { - joutput("_"); - } else { - joutput("%c", *p); - } - } - field = field->parent; - } + char *base_name = get_java_identifier_base(f); + joutput(base_name); } return 0; } @@ -813,48 +852,33 @@ static void joutput_base(struct cb_field *f) { // EDIT /* Base name */ - if (top->flag_external) { - strcpy(name, top->name); - char *nmp; - for (nmp = name; *nmp; nmp++) { - if (*nmp == '-') { - *nmp = '_'; - } - } - } else { - register_data_storage_list(f, top); - } + strcpy_identifier_cobol_to_java(name, top->name); + + register_data_storage_list(f, top); if (!top->flag_base) { - if (!top->flag_external) { - if (!top->flag_local || top->flag_is_global) { - bl = cobc_malloc(sizeof(struct base_list)); - bl->f = top; - bl->curr_prog = excp_current_program_id; - bl->next = base_cache; - base_cache = bl; + if (!top->flag_local || top->flag_is_global) { + bl = cobc_malloc(sizeof(struct base_list)); + bl->f = top; + bl->curr_prog = excp_current_program_id; + bl->next = base_cache; + base_cache = bl; + } else { + if (current_prog->flag_global_use) { + joutput_local("unsigned char\t\t*%s%s = NULL;", CB_PREFIX_BASE, name); + joutput_local("\t/* %s */\n", top->name); + joutput_local("static unsigned char\t*save_%s%s;\n", CB_PREFIX_BASE, + name); } else { - if (current_prog->flag_global_use) { - joutput_local("unsigned char\t\t*%s%s = NULL;", CB_PREFIX_BASE, name); - joutput_local("unsigned char\t\t*%s%s = NULL;", CB_PREFIX_BASE, name); - joutput_local("\t/* %s */\n", top->name); - joutput_local("static unsigned char\t*save_%s%s;\n", CB_PREFIX_BASE, - name); - } else { - joutput_local("unsigned char\t*%s%s = NULL;", CB_PREFIX_BASE, name); - joutput_local("\t/* %s */\n", top->name); - } + joutput_local("unsigned char\t*%s%s = NULL;", CB_PREFIX_BASE, name); + joutput_local("\t/* %s */\n", top->name); } } top->flag_base = 1; } - if (top->flag_external) { - joutput("%s%s", CB_PREFIX_BASE, name); - } else { - if (joutput_field_storage(f, top) && f->offset != 0) { - joutput(".getSubDataStorage(%d)", f->offset); - } + if (joutput_field_storage(f, top) && f->offset != 0) { + joutput(".getSubDataStorage(%d)", f->offset); } if (cb_field_variable_address(f)) { @@ -1142,9 +1166,14 @@ static void joutput_attr(cb_tree x) { * AbstractCobolField型の変数をインスタンス化するコードを出力する */ static void joutput_field(cb_tree x) { + joutput("CobolFieldFactory.makeCobolField("); - joutput_size(x); - joutput(", "); + if (!(CB_LITERAL_P(x) && + (CB_TREE_CATEGORY(x) == CB_CATEGORY_ALPHANUMERIC || + CB_LITERAL_P(x) && CB_TREE_CATEGORY(x) == CB_CATEGORY_NATIONAL))) { + joutput_size(x); + joutput(", "); + } joutput_data(x); joutput(", "); joutput_attr(x); @@ -1290,25 +1319,13 @@ static void joutput_integer(cb_tree x) { return; case CB_USAGE_POINTER: -#ifdef COB_NON_ALIGNED - joutput("(cob_get_pointer ("); - joutput_data(x); - joutput("))"); -#else joutput("(*(unsigned char **) ("); joutput_data(x); joutput("))"); -#endif return; case CB_USAGE_PROGRAM_POINTER: -#ifdef COB_NON_ALIGNED - joutput("(cob_get_prog_pointer ("); - joutput_data(x); - joutput("))"); -#else joutput_data(x); -#endif return; case CB_USAGE_DISPLAY: @@ -1339,28 +1356,26 @@ static void joutput_integer(cb_tree x) { } return; } -#ifdef COB_NON_ALIGNED - if (f->storage != CB_STORAGE_LINKAGE && f->indexes == 0 && - ( -#ifdef COB_SHORT_BORK - (f->size == 2 && (f->offset % 4 == 0)) || -#else - (f->size == 2 && (f->offset % 2 == 0)) || -#endif - (f->size == 4 && (f->offset % 4 == 0)) || - (f->size == 8 && (f->offset % 8 == 0)))) { -#else if (f->size == 2 || f->size == 4 || f->size == 8) { -#endif if (f->flag_binary_swap) { + if (!integer_reference_flag) { + switch (f->size) { + case 2: + joutput("(short)("); + break; + case 4: + joutput("(int)("); + break; + } + } joutput_data(x); if (!integer_reference_flag) { switch (f->size) { case 2: - joutput(".bswap_16()"); + joutput(".bswap_16())"); break; case 4: - joutput(".bswap_32()"); + joutput(".bswap_32())"); break; case 8: joutput(".bswap_64()"); @@ -1442,10 +1457,8 @@ static void joutput_param(cb_tree x, int id) { cb_tree l; struct literal_list *ll; int n; - int extrefs; int sav_stack_id; char fname[12]; - COB_UNUSED(extrefs); param_id = id; @@ -1532,7 +1545,6 @@ static void joutput_param(cb_tree x, int id) { break; case CB_TAG_REFERENCE: r = CB_REFERENCE(x); - extrefs = 0; if (r->check) { joutput("(new GetAbstractCobolField() {"); joutput_newline(); @@ -1604,7 +1616,6 @@ static void joutput_param(cb_tree x, int id) { } f = CB_FIELD(r->value); if (f->redefines && f->redefines->flag_external) { - extrefs = 1; f->flag_item_external = 1; f->flag_external = 1; } @@ -1613,12 +1624,10 @@ static void joutput_param(cb_tree x, int id) { } for (pechk = f->parent; pechk; pechk = pechk->parent) { if (pechk->flag_external) { - extrefs = 1; f->flag_item_external = 1; break; } if (pechk->redefines && pechk->redefines->flag_external) { - extrefs = 1; f->flag_item_external = 1; f->flag_external = 1; break; @@ -1702,8 +1711,12 @@ static void joutput_param(cb_tree x, int id) { } #endif joutput("CobolFieldFactory.makeCobolField("); - joutput_size(x); - joutput(", "); + if (!(CB_LITERAL_P(x) && + (CB_TREE_CATEGORY(x) == CB_CATEGORY_ALPHANUMERIC || + CB_LITERAL_P(x) && CB_TREE_CATEGORY(x) == CB_CATEGORY_NATIONAL))) { + joutput_size(x); + joutput(", "); + } joutput_data(x); joutput(", "); joutput_attr(x); @@ -2000,30 +2013,17 @@ static void joutput_cond(cb_tree x, int save_flag) { if (save_flag) { joutput("(ret = "); } - //#ifdef __GNUC__ - // joutput_indent ("({"); - //#else - // inside_stack[inside_check] = 0; - // ++inside_check; - // joutput ("(\n"); - //#endif joutput_indent("(new GetInt() {"); joutput_indent_level += 2; - joutput_indent("public int run(){"); + joutput_indent("public int run() throws CobolStopRunException {"); joutput_indent_level += 2; for (; x; x = CB_CHAIN(x)) { - //最後の文ならreturn文を書く + // 最後の文ならreturn文を書く if (!CB_CHAIN(x)) { joutput_indent("return "); } joutput_stmt(CB_VALUE(x), JOUTPUT_STMT_DEFAULT); } - //#ifdef __GNUC__ - // joutput_indent ("})"); - //#else - // --inside_check; - // joutput (")"); - //#endif joutput_indent_level -= 2; joutput_indent("}"); joutput_indent_level -= 2; @@ -2216,13 +2216,13 @@ static void joutput_initialize_literal(cb_tree x, struct cb_field *f, i_counters[0] = 1; joutput_line("for (int i0 = 0; i0 < %u; i0++)", (unsigned int)i); - joutput_indent(" {"); + joutput_indent("{"); joutput_prefix(); joutput_data(x); joutput(".memcpy(i0 * %u, ", (unsigned int)l->size); joutput_string(l->data, l->size); joutput(", %u);\n", (unsigned int)l->size); - joutput_indent(" }"); + joutput_indent("}"); n = f->size % l->size; if (n) { @@ -2247,33 +2247,19 @@ static void joutput_initialize_fp(cb_tree x, struct cb_field *f) { } static void joutput_initialize_external(cb_tree x, struct cb_field *f) { - unsigned char *p; cb_tree file; - char name[COB_MINI_BUFF]; joutput_prefix(); joutput_data(x); if (f->ename) { - joutput(" = CobolExternal.getStorageAddress (\"%s\", %d);\n", f->ename, + joutput(" = CobolExternal.getStorageAddress (\"%s\", %d);", f->ename, f->size); } else if (f->storage == CB_STORAGE_FILE) { file = CB_TREE(f->file); - strcpy(name, CB_FILE(file)->record->name); - for (p = (unsigned char *)name; *p; p++) { - if (*p == '-') { - *p = '_'; - } - } - joutput(" = CobolExternal.getStorageAddress (\"%s\", %d);\n", name, - f->size); + joutput(" = CobolExternal.getStorageAddress (\"%s\", %d);", + CB_FILE(file)->record->name, f->size); } else { - strcpy(name, f->name); - for (p = (unsigned char *)name; *p; p++) { - if (islower(*p)) { - *p = (unsigned char)toupper(*p); - } - } - joutput(" = CobolExternal.getStorageAddress (\"%s\", %d);\n", name, + joutput(" = CobolExternal.getStorageAddress (\"%s\", %d);", f->name, f->size); } } @@ -2329,6 +2315,13 @@ static void joutput_initialize_one(struct cb_initialize *p, cb_tree x) { /* Initialize by value */ if (p->val && f->values) { cb_tree value = CB_VALUE(f->values); + struct cb_literal *l = CB_LITERAL_P(value) ? CB_LITERAL(value) : NULL; + // save the size information of '&' concatenated segments + if (l && l->segment_count > 0) { + sgmt_sizes = cobc_malloc(sizeof(size_t) * l->segment_count); + memcpy(sgmt_sizes, l->segment_sizes, sizeof(size_t) * l->segment_count); + sgmt_count = l->segment_count; + } /* NATIONAL also needs no editing but mbchar conversion. */ if (CB_TREE_CATEGORY(x) == CB_CATEGORY_NATIONAL) { @@ -2389,7 +2382,6 @@ static void joutput_initialize_one(struct cb_initialize *p, cb_tree x) { /* We do not use joutput_move here because we do not want to have the value be edited. */ - struct cb_literal *l = CB_LITERAL(value); static char *buff = NULL; static int lastsize = 0; if (!buff) { @@ -2431,6 +2423,7 @@ static void joutput_initialize_one(struct cb_initialize *p, cb_tree x) { joutput_data(x); joutput(".fillBytes(%d, %d);\n", buffchar, f->size); } else { +#if !I18N_UTF8 if (f->size >= 8) { buffchar = *(buff + f->size - 1); int n = 0; @@ -2450,10 +2443,17 @@ static void joutput_initialize_one(struct cb_initialize *p, cb_tree x) { return; } } +#endif joutput_data(x); +#if I18N_UTF8 + joutput(".setByByteArrayAndPaddingSpaces ("); + joutput_string(l->data, l->size); + joutput(", %d);\n", f->size); +#else joutput(".setBytes ("); joutput_string((ucharptr)buff, f->size); joutput(", %d);\n", f->size); +#endif } } } @@ -2560,7 +2560,7 @@ static void joutput_initialize_compound(struct cb_initialize *p, cb_tree x) { i_counters[i] = 1; joutput_line("for (int i%d = 1; i%d <= %d; i%d++)", i, i, f->occurs_max, i); - joutput_indent(" {"); + joutput_indent("{"); CB_REFERENCE(c)->subs = cb_cons(cb_i[i], CB_REFERENCE(c)->subs); } @@ -2574,7 +2574,7 @@ static void joutput_initialize_compound(struct cb_initialize *p, cb_tree x) { if (f->flag_occurs) { /* Close loop */ CB_REFERENCE(c)->subs = CB_CHAIN(CB_REFERENCE(c)->subs); - joutput_indent(" }"); + joutput_indent("}"); } } if (f == ff) @@ -2589,12 +2589,6 @@ static void joutput_initialize(struct cb_initialize *p) { int c; f = cb_field(p->var); - if (f->flag_external) { - joutput_initialize_external(p->var, f); - if (!p->flag_statement) { - return; - } - } switch (initialize_type(p, f, 1)) { case INITIALIZE_NONE: break; @@ -2614,6 +2608,7 @@ static void joutput_initialize(struct cb_initialize *p) { break; } } + /* * SEARCH */ @@ -2647,7 +2642,7 @@ static void joutput_search_whens(cb_tree table, cb_tree var, cb_tree stmt, /* Start loop */ joutput_line("for (;;)"); - joutput_indent(" {"); + joutput_indent("{"); /* End test */ joutput_prefix(); @@ -2663,17 +2658,17 @@ static void joutput_search_whens(cb_tree table, cb_tree var, cb_tree stmt, joutput(" > "); joutput_occurs(p); joutput(")\n"); - joutput_indent(" {"); + joutput_indent("{"); if (stmt) { joutput_stmt(stmt, JOUTPUT_STMT_DEFAULT); } joutput_line("break;"); - joutput_indent(" }"); + joutput_indent("}"); /* WHEN test */ joutput_stmt(whens, JOUTPUT_STMT_DEFAULT); joutput_line("else"); - joutput_indent(" {"); + joutput_indent("{"); joutput_prefix(); int tmp_flag = integer_reference_flag; @@ -2689,9 +2684,9 @@ static void joutput_search_whens(cb_tree table, cb_tree var, cb_tree stmt, joutput_move(idx, var); } joutput_line("continue;"); - joutput_indent(" }"); + joutput_indent("}"); joutput_line("break;"); - joutput_indent(" }"); + joutput_indent("}"); } static void joutput_search_all(cb_tree table, cb_tree stmt, cb_tree cond, @@ -2709,6 +2704,7 @@ static void joutput_search_all(cb_tree table, cb_tree stmt, cb_tree cond, joutput_prefix(); joutput("int tail = "); if (p->occurs_depending) { + joutput("(int)"); joutput_integer(p->occurs_depending); joutput(" + 1;\n"); } else { @@ -2717,16 +2713,16 @@ static void joutput_search_all(cb_tree table, cb_tree stmt, cb_tree cond, /* Start loop */ joutput_line("for (;;)"); - joutput_indent(" {"); + joutput_indent("{"); /* End test */ joutput_line("if (head >= tail - 1)"); - joutput_indent(" {"); + joutput_indent("{"); if (stmt) { joutput_stmt(stmt, JOUTPUT_STMT_DEFAULT); } joutput_line("break;"); - joutput_indent(" }"); + joutput_indent("}"); /* Next index */ joutput_prefix(); @@ -2745,7 +2741,7 @@ static void joutput_search_all(cb_tree table, cb_tree stmt, cb_tree cond, joutput_stmt(when, JOUTPUT_STMT_DEFAULT); joutput_indent_level -= 2; joutput_line("else"); - joutput_indent(" {"); + joutput_indent("{"); joutput_line("if (ret < 0)"); joutput_prefix(); joutput(" head = "); @@ -2757,9 +2753,9 @@ static void joutput_search_all(cb_tree table, cb_tree stmt, cb_tree cond, joutput_integer(idx); joutput(";\n"); joutput_line("continue;"); - joutput_indent(" }"); + joutput_indent("}"); joutput_line("break;"); - joutput_indent(" }"); + joutput_indent("}"); joutput_indent("}"); } @@ -2779,11 +2775,8 @@ static void joutput_search(struct cb_search *p) { static void joutput_call(struct cb_call *p) { cb_tree x; cb_tree l; - struct cb_literal *lp; - char *callp; struct cb_field *f; char *system_call = NULL; - struct system_table *psyst; size_t n; size_t retptr; int dynamic_link = 1; @@ -2795,8 +2788,9 @@ static void joutput_call(struct cb_call *p) { } /* System routine entry points */ if (p->is_system) { - lp = CB_LITERAL(p->name); - psyst = (struct system_table *)&system_tab[0]; + struct cb_literal *lp = CB_LITERAL(p->name); + + struct system_table *psyst = (struct system_table *)&system_tab[0]; for (; psyst->syst_name; psyst++) { if (!strcmp((const char *)lp->data, (const char *)psyst->syst_name)) { system_call = (char *)psyst->syst_call; @@ -2811,12 +2805,6 @@ static void joutput_call(struct cb_call *p) { } /* Local variables */ -#ifdef COB_NON_ALIGNED - if (dynamic_link && retptr) { - // output_line ("void *temptr;"); - } -#endif - if (CB_REFERENCE_P(p->name) && CB_FIELD_P(CB_REFERENCE(p->name)->value) && CB_FIELD(CB_REFERENCE(p->name)->value)->usage == CB_USAGE_PROGRAM_POINTER) { @@ -2986,6 +2974,7 @@ static void joutput_call(struct cb_call *p) { } } } else { + char *callp; /* Dynamic link */ if (CB_LITERAL_P(p->name)) { callp = cb_encode_program_id((char *)(CB_LITERAL(p->name)->data)); @@ -3207,13 +3196,6 @@ static void joutput_call(struct cb_call *p) { joutput_stmt(cb_build_move(current_prog->cb_return_code, p->returning), JOUTPUT_STMT_DEFAULT); suppress_warn = 0; -#ifdef COB_NON_ALIGNED - } else { - // output_prefix (); - // output ("memcpy ("); - // output_data (p->returning); - // output (", &temptr, %d);\n", sizeof (void *)); -#endif } } if (p->stmt2) { @@ -3240,7 +3222,7 @@ static void joutput_goto(struct cb_goto *p) { joutput("switch ((int)"); joutput_param(cb_build_cast_integer(p->depending), 0); joutput(")\n"); - joutput_indent(" {"); + joutput_indent("{"); cb_tree l; for (l = p->target; l; l = CB_CHAIN(l)) { joutput_indent_level -= 2; @@ -3248,7 +3230,7 @@ static void joutput_goto(struct cb_goto *p) { joutput_indent_level += 2; joutput_goto_1(CB_VALUE(l)); } - joutput_indent(" }"); + joutput_indent("}"); } else if (p->target == NULL) { needs_exit_prog = 1; if (cb_flag_implicit_init) { @@ -3323,7 +3305,7 @@ static void joutput_perform_until(struct cb_perform *p, cb_tree l) { } else { joutput_line("for (;;)"); } - joutput_indent(" {"); + joutput_indent("{"); if (next && CB_PERFORM_VARYING(CB_VALUE(next))->name) { joutput_move(CB_PERFORM_VARYING(CB_VALUE(next))->from, @@ -3348,7 +3330,7 @@ static void joutput_perform_until(struct cb_perform *p, cb_tree l) { joutput_perform_until(p, next); } - joutput_indent(" }"); + joutput_indent("}"); } static void joutput_perform(struct cb_perform *p) { @@ -3369,9 +3351,9 @@ static void joutput_perform(struct cb_perform *p) { joutput_param(cb_build_cast_integer(p->data), 0); joutput("; n%d > 0; n%d--)\n", loop_counter, loop_counter); loop_counter++; - joutput_indent(" {"); + joutput_indent("{"); joutput_perform_once(p); - joutput_indent(" }"); + joutput_indent("}"); break; case CB_PERFORM_UNTIL: v = CB_PERFORM_VARYING(CB_VALUE(p->varying)); @@ -3383,9 +3365,9 @@ static void joutput_perform(struct cb_perform *p) { case CB_PERFORM_FOREVER: joutput_prefix(); joutput("for (;;)\n"); - joutput_indent(" {"); + joutput_indent("{"); joutput_perform_once(p); - joutput_indent(" }"); + joutput_indent("}"); break; } if (p->exit_label) { @@ -3509,7 +3491,7 @@ static void joutput_file_error(struct cb_file *pfile) { static void joutput_ferror_stmt(struct cb_statement *p, int code) { joutput_line("if (CobolRuntimeException.code != 0)"); - joutput_indent(" {"); + joutput_indent("{"); if (p->handler1) { if ((code & 0x00ff) == 0) { joutput_line("if ((CobolRuntimeException.code & 0xff00) == 0x%04x)", @@ -3517,27 +3499,27 @@ static void joutput_ferror_stmt(struct cb_statement *p, int code) { } else { joutput_line("if (CobolRuntimeException.code == 0x%04x)", code); } - joutput_indent(" {"); + joutput_indent("{"); joutput_stmt(p->handler1, JOUTPUT_STMT_DEFAULT); - joutput_indent(" }"); + joutput_indent("}"); joutput_line("else"); - joutput_indent(" {"); + joutput_indent("{"); } joutput_file_error(CB_FILE(p->file)); - joutput_indent(" }"); + joutput_indent("}"); if (p->handler1) { - joutput_indent(" }"); + joutput_indent("}"); } if (p->handler2 || p->handler3) { joutput_line("else"); - joutput_indent(" {"); + joutput_indent("{"); if (p->handler3) { joutput_stmt(p->handler3, JOUTPUT_STMT_DEFAULT); } if (p->handler2) { joutput_stmt(p->handler2, JOUTPUT_STMT_DEFAULT); } - joutput_indent(" }"); + joutput_indent("}"); } } @@ -3551,14 +3533,52 @@ static void joutput_ferror_stmt(struct cb_statement *p, int code) { // joutput_line("// %s:%d: %s", p->file, p->line, p->comment); // } +static void joutput_switch(struct cb_switch *sw, + enum joutput_stmt_type output_type) { + joutput_prefix(); + joutput("switch("); + joutput_param(sw->test, -1); + joutput(".getInt()) {"); + joutput_newline(); + joutput_indent_level += 2; + cb_tree case_tree; + for (case_tree = sw->case_list; case_tree; case_tree = CB_CHAIN(case_tree)) { + cb_tree whens = CB_VALUE(case_tree); + cb_tree stmt = CB_VALUE(whens); + int flag_other_exists = 1; + for (; whens; whens = CB_CHAIN(whens)) { + cb_tree objs = CB_VALUE(whens); + for (; objs; objs = CB_CHAIN(objs)) { + cb_tree obj = CB_VALUE(objs); + if (obj && CB_LIST_P(obj)) { + flag_other_exists = 0; + } + if (obj && CB_PAIR_P(obj)) { + cb_tree when_target = CB_PAIR_Y(obj); + struct cb_literal *primary_target = + CB_LITERAL(CB_PAIR_X(when_target)); + int dummy; + int label = + cb_literal_to_int_for_switch_label(primary_target, &dummy); + joutput_line("case %d:", label); + } + } + } + if (flag_other_exists) { + joutput_line("default:"); + } + joutput_stmt(stmt, output_type); + joutput_line("break;"); + } + joutput_indent_level -= 2; + joutput_line("}"); +} + static void joutput_stmt(cb_tree x, enum joutput_stmt_type output_type) { struct cb_statement *p; struct cb_label *lp; struct cb_assign *ap; struct cb_if *ip; -#ifdef COB_NON_ALIGNED - struct cb_cast *cp; -#endif int code; int putParen = 0; @@ -3670,9 +3690,9 @@ static void joutput_stmt(cb_tree x, enum joutput_stmt_type output_type) { } else { joutput_line("if (CobolRuntimeException.code == 0x%04x)", code); } - joutput_indent(" {"); + joutput_indent("{"); joutput_stmt(p->handler1, output_type); - joutput_indent(" }"); + joutput_indent("}"); if (p->handler2) { joutput_line("else"); } @@ -3681,9 +3701,9 @@ static void joutput_stmt(cb_tree x, enum joutput_stmt_type output_type) { if (p->handler1 == NULL) { joutput_line("if (CobolRuntimeException.code == 0)"); } - joutput_indent(" {"); + joutput_indent("{"); joutput_stmt(p->handler2, output_type); - joutput_indent(" }"); + joutput_indent("}"); } } } @@ -3779,80 +3799,7 @@ static void joutput_stmt(cb_tree x, enum joutput_stmt_type output_type) { break; case CB_TAG_ASSIGN: ap = CB_ASSIGN(x); -#ifdef COB_NON_ALIGNED - /* Nonaligned */ - if (CB_TREE_CLASS(ap->var) == CB_CLASS_POINTER || - CB_TREE_CLASS(ap->val) == CB_CLASS_POINTER) { - /* Pointer assignment */ - joutput_indent("{"); - joutput_line("void *temp_ptr;"); - - /* temp_ptr = source address; */ - joutput_prefix(); - if (ap->val == cb_null || ap->val == cb_zero) { - /* MOVE NULL ... */ - joutput("temp_ptr = 0;\n"); - } else if (CB_TREE_TAG(ap->val) == CB_TAG_CAST) { - /* MOVE ADDRESS OF val ... */ - cp = CB_CAST(ap->val); - joutput("temp_ptr = "); - switch (cp->type) { - case CB_CAST_ADDRESS: - joutput_data(cp->val); - break; - case CB_CAST_PROGRAM_POINTER: - joutput_func_1("CobolResolve.resolveToPointer", ap->val); - break; - default: - fprintf(stderr, "Unexpected cast type %d\n", cp->type); - ABORT(); - } - joutput(";\n"); - } else { - /* MOVE val ... */ - joutput("LIBCOB.memcpy(&temp_ptr, "); - joutput_data(ap->val); - joutput(", sizeof(temp_ptr));\n"); - } - - /* destination address = temp_ptr; */ - joutput_prefix(); - if (CB_TREE_TAG(ap->var) == CB_TAG_CAST) { - /* SET ADDRESS OF var ... */ - cp = CB_CAST(ap->var); - if (cp->type != CB_CAST_ADDRESS) { - fprintf(stderr, "Unexpected tree type %d\n", cp->type); - ABORT(); - } - joutput_data(cp->val); - joutput(" = temp_ptr;\n"); - } else { - /* MOVE ... TO var */ - joutput("LIBCOB.memcpy("); - joutput_data(ap->var); - joutput(", &temp_ptr, sizeof(temp_ptr));\n"); - } - - joutput_indent("}"); - } else { - /* Numeric assignment */ - joutput_prefix(); - int tmp_flag = integer_reference_flag; - integer_reference_flag = 1; - joutput_integer(ap->var); - integer_reference_flag = tmp_flag; - joutput(".set("); - ++index_read_flag; - joutput_integer(ap->val); - --index_read_flag; - if (output_type == JOUTPUT_STMT_TRIM) { - joutput(")\n"); - } else { - joutput(");\n"); - } - } -#else /* Nonaligned */ joutput_prefix(); int tmp_flag = integer_reference_flag; @@ -3884,7 +3831,6 @@ static void joutput_stmt(cb_tree x, enum joutput_stmt_type output_type) { } else { joutput(");\n"); } -#endif /* Nonaligned */ break; case CB_TAG_INITIALIZE: joutput_initialize(CB_INITIALIZE(x)); @@ -3950,6 +3896,9 @@ static void joutput_stmt(cb_tree x, enum joutput_stmt_type output_type) { joutput_prefix(); joutput(";\n"); break; + case CB_TAG_SWITCH: + joutput_switch(CB_SWITCH(x), output_type); + break; case CB_TAG_LIST: if (x && CB_TREE_TAG(CB_VALUE(x)) == CB_TAG_PERFORM) { putParen = 0; @@ -4278,6 +4227,10 @@ static void joutput_initial_values(struct cb_field *p) { if (p->flag_no_init && !p->count) { continue; } + /* EXTERNAL items */ + if (p->flag_external) { + continue; + } int tmp_flag = integer_reference_flag; integer_reference_flag = 1; joutput_stmt(cb_build_initialize(x, cb_true, NULL, def, 0), @@ -4437,13 +4390,11 @@ static void joutput_internal_function(struct cb_program *prog, cb_tree l; struct cb_field *f; struct cb_file *fl; - char *p; int i; // int n; int parmnum = 0; // int seen = 0; // int anyseen; - char name[COB_MINI_BUFF]; /* Program function */ // output ("static int\n%s_ (const int entry", prog->program_id); @@ -4690,15 +4641,11 @@ static void joutput_internal_function(struct cb_program *prog, for (l = prog->file_list; l; l = CB_CHAIN(l)) { f = CB_FILE(CB_VALUE(l))->record; if (f->flag_external) { - strcpy(name, f->name); - for (p = name; *p; p++) { - if (*p == '-') { - *p = '_'; - } - } - joutput_line("%s%s = CobolExternal.getStorageAddress (\"%s\", %d);", - CB_PREFIX_BASE, name, name, - CB_FILE(CB_VALUE(l))->record_max); + joutput_prefix(); + joutput_base(f); + joutput(" = CobolExternal.getStorageAddress (\"%s\", %d);", f->name, + CB_FILE(CB_VALUE(l))->record_max); + joutput_newline(); } } joutput_initial_values(prog->working_storage); @@ -4788,15 +4735,10 @@ static void joutput_internal_function(struct cb_program *prog, for (l = prog->file_list; l; l = CB_CHAIN(l)) { f = CB_FILE(CB_VALUE(l))->record; if (f->flag_external) { - strcpy(name, f->name); - for (p = name; *p; p++) { - if (*p == '-') { - *p = '_'; - } - } - joutput_line("%s%s = CobolExternal.getStorageAddress (\"%s\", %d);", - CB_PREFIX_BASE, name, name, - CB_FILE(CB_VALUE(l))->record_max); + joutput_prefix(); + joutput_base(f); + joutput_line(" = CobolExternal.getStorageAddress (\"%s\", %d);", + f->name, CB_FILE(CB_VALUE(l))->record_max); } } joutput_initial_values(prog->working_storage); @@ -4898,7 +4840,7 @@ static void joutput_internal_function(struct cb_program *prog, joutput_line("//multiple entry dispatch is not implemented"); joutput_newline(); joutput_line("switch (entry)"); - joutput_line(" {"); + joutput_line("{"); for (i = 0, l = prog->entry_list; l; l = CB_CHAIN(l)) { joutput_line(" case %d:", i++); joutput_prefix(); @@ -4906,7 +4848,7 @@ static void joutput_internal_function(struct cb_program *prog, joutput_label_variable(CB_LABEL(CB_PURPOSE(l))); joutput(");\n"); } - joutput_line(" }"); + joutput_line("}"); joutput_line("/* This should never be reached */"); joutput_line("CobolUtil.fatalError (CobolUtil.FERROR_CHAINING);"); joutput_newline(); @@ -5128,6 +5070,11 @@ static void joutput_init_method(struct cb_program *prog) { joutput_prefix(); joutput("%s = new CobolDataStorage(%d);", base_name, blp->f->memory_size); + } + + if (blp->f->flag_external) { + joutput_initialize_external(cb_build_field_reference(blp->f, NULL), + blp->f); } else { joutput_prefix(); joutput("%s = new CobolDataStorage(%d);", base_name, @@ -5528,8 +5475,6 @@ static void joutput_declare_member_variables(struct cb_program *prog, struct base_list *blp; const char *prevprog; struct cb_field *f; - char *p; - char name[COB_MINI_BUFF]; /* CobolDecimal型変数の宣言 */ if (prog->decimal_index_max) { @@ -5595,11 +5540,12 @@ static void joutput_declare_member_variables(struct cb_program *prog, prevprog = blp->curr_prog; joutput_prefix(); joutput("/* PROGRAM-ID : %s */\n", prevprog); - joutput_prefix(); - joutput("private CobolDataStorage %s;", base_name, blp->f->memory_size); + } + joutput_prefix(); + if (strcmp(blp->f->name, "RETURN-CODE") == 0) { + joutput("public CobolDataStorage %s;", base_name); } else { - joutput_prefix(); - joutput("private CobolDataStorage %s;", base_name, blp->f->memory_size); + joutput("private CobolDataStorage %s;", base_name); } free(base_name); joutput("\t/* %s */\n", blp->f->name); @@ -5644,33 +5590,6 @@ static void joutput_declare_member_variables(struct cb_program *prog, joutput("\n"); } - /* External items */ - for (f = prog->working_storage; f; f = f->sister) { - if (f->flag_external) { - strcpy(name, f->name); - for (p = name; *p; p++) { - if (*p == '-') { - *p = '_'; - } - } - joutput("private CobolDataStorage\t%s%s = null;", CB_PREFIX_BASE, name); - joutput(" /* %s */\n", f->name); - } - } - for (l = prog->file_list; l; l = CB_CHAIN(l)) { - f = CB_FILE(CB_VALUE(l))->record; - if (f->flag_external) { - strcpy(name, f->name); - for (p = name; *p; p++) { - if (*p == '-') { - *p = '_'; - } - } - joutput("private CobolDataStorage\t%s%s = null;", CB_PREFIX_BASE, name); - joutput(" /* %s */\n", f->name); - } - } - /* AbstractCobolField型変数の宣言(非定数) */ if (field_cache) { joutput_line("/* Fields */\n"); @@ -6158,9 +6077,6 @@ void codegen(struct cb_program *prog, const int nested, char **program_id_list, if (cb_java_package_name) { joutput_line("package %s;\n", cb_java_package_name); } - if (edit_code_command_is_set) { - joutput_edit_code_command("file-header"); - } joutput_line("import java.io.UnsupportedEncodingException;"); joutput_line("import jp.osscons.opensourcecobol.libcobj.*;"); @@ -6189,17 +6105,7 @@ void codegen(struct cb_program *prog, const int nested, char **program_id_list, } }*/ - if (edit_code_command_is_set) { - joutput_edit_code_command("main-class-annotation"); - } - if (edit_code_command_is_set) { - joutput("public class %s implements CobolRunnable, ", prog->program_id); - joutput_edit_code_command("main-class-implements"); - joutput(" {\n"); - } else { - joutput_line("public class %s implements CobolRunnable {", - prog->program_id); - } + joutput_line("public class %s implements CobolRunnable {", prog->program_id); joutput_indent_level += 2; joutput("\n"); @@ -6211,9 +6117,6 @@ void codegen(struct cb_program *prog, const int nested, char **program_id_list, // output_storage ("union cob_call_union\tcob_unifunc;\n\n"); joutput_line("private CobolRunnable cob_unifunc;\n"); - if (edit_code_command_is_set) { - joutput_edit_code_command("main-class-contents"); - } joutput("\n"); joutput_line("@Override"); @@ -6310,8 +6213,18 @@ void codegen(struct cb_program *prog, const int nested, char **program_id_list, //} joutput_line("CobolDecimal.cobInitNumeric();"); - joutput_line("new %s().%s_(0);", prog->program_id, prog->program_id); + if (cb_enable_program_status_register) { + joutput_line("%s $module$ = new %s();", prog->program_id, prog->program_id); + joutput_line("$module$.%s_(0);", prog->program_id); + } else { + joutput_line("new %s().%s_(0);", prog->program_id, prog->program_id); + } joutput_line("CobolStopRunException.stopRun();"); + + if (cb_enable_program_status_register) { + joutput_line("System.exit($module$.b_RETURN_CODE.intValue());"); + } + joutput_indent_level -= 2; joutput_line("}\n"); @@ -6322,20 +6235,20 @@ void codegen(struct cb_program *prog, const int nested, char **program_id_list, /* Program local stuff */ - //コンストラクタの実装コードを出力 - //メンバ変数の初期化を行う + // コンストラクタの実装コードを出力 + // メンバ変数の初期化を行う joutput_line("public %s()", prog->program_id); joutput_line("{"); joutput_line(" init();"); joutput_line("}"); joutput_newline(); - //メンバ変数の初期化メソッドを出力 + // メンバ変数の初期化メソッドを出力 create_sorted_data_storage_cache(); joutput_init_method(prog); joutput_newline(); - //メンバ変数の出力 + // メンバ変数の出力 joutput_declare_member_variables(prog, prog->parameter_list); joutput("\n"); diff --git a/cobj/config.c b/cobj/config.c index 4f0bf3b6..a30025d8 100644 --- a/cobj/config.c +++ b/cobj/config.c @@ -229,8 +229,8 @@ int cb_load_conf(const char *fname, const int check_nodef, ret = -1; } } else if (strcmp(name, "binary-byteorder") == 0) { - if (strcmp(val, "native") == 0) { - cb_binary_byteorder = CB_BYTEORDER_NATIVE; + if (strcmp(val, "little-endian") == 0) { + cb_binary_byteorder = CB_BYTEORDER_LITTLE_ENDIAN; } else if (strcmp(val, "big-endian") == 0) { cb_binary_byteorder = CB_BYTEORDER_BIG_ENDIAN; } else { diff --git a/cobj/cpp-check b/cobj/cpp-check index 9fa70161..23e31699 100755 --- a/cobj/cpp-check +++ b/cobj/cpp-check @@ -5,4 +5,7 @@ cppcheck --error-exitcode=1 \ --enable=performance \ --enable=portability \ --suppress=unusedFunctions \ - --suppress=toomanyconfigs + --suppress=toomanyconfigs \ + --suppress=unusedStructMember \ + --suppress=leakNoVarFunctionCall \ + --suppress=unreadVariable diff --git a/cobj/format b/cobj/format index 7205d31b..3b835409 100755 --- a/cobj/format +++ b/cobj/format @@ -7,7 +7,6 @@ codegen.c \ config.c \ error.c \ field.c \ -pplex.c \ ppparse.c \ ppparse.h \ reserved.c \ diff --git a/cobj/parser.c b/cobj/parser.c index a6d09491..e80ebf1d 100644 --- a/cobj/parser.c +++ b/cobj/parser.c @@ -1,8 +1,8 @@ -/* A Bison parser, made by GNU Bison 3.8.2. */ +/* A Bison parser, made by GNU Bison 3.7.4. */ /* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ /* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work @@ -46,10 +46,10 @@ USER NAME SPACE" below. */ /* Identify Bison output, and Bison version. */ -#define YYBISON 30802 +#define YYBISON 30704 /* Bison version string. */ -#define YYBISON_VERSION "3.8.2" +#define YYBISON_VERSION "3.7.4" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -1587,18 +1587,6 @@ typedef int_least16_t yytype_int16; typedef short yytype_int16; #endif -/* Work around bug in HP-UX 11.23, which defines these macros - incorrectly for preprocessor constants. This workaround can likely - be removed in 2023, as HPE has promised support for HP-UX 11.23 - (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of - . */ -#ifdef __hpux -# undef UINT_LEAST8_MAX -# undef UINT_LEAST16_MAX -# define UINT_LEAST8_MAX 255 -# define UINT_LEAST16_MAX 65535 -#endif - #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ typedef __UINT_LEAST8_TYPE__ yytype_uint8; #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ @@ -1696,23 +1684,17 @@ typedef int yy_state_fast_t; /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ -# define YY_USE(E) ((void) (E)) +# define YYUSE(E) ((void) (E)) #else -# define YY_USE(E) /* empty */ +# define YYUSE(E) /* empty */ #endif +#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ /* Suppress an incorrect diagnostic about yylval being uninitialized. */ -#if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__ -# if __GNUC__ * 100 + __GNUC_MINOR__ < 407 -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") -# else -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ _Pragma ("GCC diagnostic push") \ _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") -# endif # define YY_IGNORE_MAYBE_UNINITIALIZED_END \ _Pragma ("GCC diagnostic pop") #else @@ -1971,7 +1953,7 @@ static const yytype_int16 yytranslate[] = }; #if YYDEBUG -/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ + /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_int16 yyrline[] = { 0, 772, 772, 772, 816, 817, 821, 822, 827, 828, @@ -2013,122 +1995,122 @@ static const yytype_int16 yyrline[] = 2709, 2715, 2724, 2732, 2733, 2741, 2742, 2743, 2747, 2767, 2771, 2780, 2781, 2782, 2783, 2784, 2785, 2786, 2787, 2788, 2789, 2790, 2791, 2792, 2793, 2794, 2801, 2823, 2845, 2846, - 2858, 2878, 2885, 2886, 2890, 2891, 2892, 2893, 2894, 2895, - 2896, 2897, 2898, 2899, 2900, 2901, 2906, 2911, 2912, 2913, - 2914, 2915, 2916, 2917, 2918, 2919, 2920, 2921, 2922, 2923, - 2924, 2925, 2926, 2927, 2928, 2929, 2937, 2945, 2953, 2960, - 2965, 2975, 2976, 2977, 2981, 2998, 2999, 3002, 3003, 3009, - 3009, 3012, 3036, 3052, 3053, 3057, 3058, 3061, 3061, 3064, - 3071, 3072, 3077, 3087, 3094, 3097, 3098, 3099, 3106, 3113, - 3138, 3142, 3142, 3147, 3148, 3152, 3153, 3156, 3157, 3170, - 3182, 3202, 3216, 3218, 3217, 3237, 3238, 3238, 3251, 3253, - 3252, 3264, 3265, 3269, 3270, 3279, 3286, 3289, 3293, 3297, - 3298, 3299, 3306, 3307, 3311, 3314, 3314, 3317, 3318, 3324, - 3329, 3330, 3333, 3334, 3337, 3338, 3341, 3342, 3345, 3346, - 3350, 3351, 3352, 3356, 3357, 3360, 3361, 3365, 3369, 3370, - 3374, 3375, 3376, 3377, 3378, 3379, 3380, 3381, 3382, 3383, - 3384, 3385, 3386, 3387, 3388, 3389, 3393, 3397, 3398, 3399, - 3400, 3401, 3402, 3403, 3407, 3411, 3412, 3413, 3417, 3418, - 3422, 3426, 3431, 3435, 3439, 3443, 3444, 3448, 3449, 3453, - 3454, 3455, 3458, 3458, 3458, 3461, 3465, 3468, 3468, 3471, - 3478, 3479, 3479, 3489, 3491, 3501, 3490, 3528, 3530, 3529, - 3536, 3535, 3544, 3545, 3550, 3557, 3559, 3563, 3573, 3575, - 3583, 3591, 3620, 3651, 3653, 3663, 3668, 3679, 3680, 3680, - 3707, 3708, 3712, 3713, 3714, 3715, 3731, 3743, 3774, 3811, - 3823, 3826, 3827, 3836, 3840, 3836, 3853, 3874, 3878, 3879, - 3880, 3881, 3882, 3883, 3884, 3885, 3886, 3887, 3888, 3889, - 3890, 3891, 3892, 3893, 3894, 3895, 3896, 3897, 3898, 3899, - 3900, 3901, 3902, 3903, 3904, 3905, 3906, 3907, 3908, 3909, - 3910, 3911, 3912, 3913, 3914, 3915, 3916, 3917, 3918, 3919, - 3920, 3921, 3922, 3923, 3924, 3925, 3926, 3927, 3950, 3949, - 3962, 3966, 3970, 3974, 3978, 3982, 3986, 3990, 3994, 3998, - 4002, 4006, 4010, 4014, 4018, 4022, 4026, 4033, 4034, 4035, - 4036, 4037, 4038, 4042, 4046, 4047, 4050, 4051, 4055, 4056, - 4060, 4061, 4062, 4063, 4064, 4065, 4066, 4067, 4071, 4075, - 4079, 4084, 4085, 4086, 4087, 4088, 4089, 4093, 4094, 4103, - 4103, 4109, 4113, 4117, 4123, 4124, 4128, 4129, 4138, 4138, - 4143, 4147, 4154, 4155, 4164, 4170, 4171, 4175, 4175, 4183, - 4183, 4193, 4195, 4194, 4203, 4204, 4209, 4216, 4223, 4225, - 4229, 4237, 4248, 4249, 4250, 4255, 4259, 4258, 4270, 4274, - 4273, 4284, 4285, 4294, 4294, 4298, 4299, 4303, 4315, 4315, - 4319, 4320, 4331, 4332, 4333, 4334, 4335, 4338, 4338, 4346, - 4346, 4352, 4359, 4360, 4363, 4363, 4370, 4383, 4396, 4396, - 4407, 4408, 4417, 4417, 4437, 4436, 4449, 4453, 4457, 4461, - 4465, 4469, 4473, 4478, 4482, 4489, 4490, 4491, 4495, 4496, - 4501, 4502, 4503, 4504, 4505, 4506, 4507, 4508, 4509, 4510, - 4514, 4518, 4522, 4527, 4528, 4532, 4533, 4542, 4542, 4548, - 4552, 4556, 4560, 4564, 4571, 4572, 4581, 4581, 4603, 4602, - 4621, 4622, 4633, 4642, 4647, 4655, 4684, 4685, 4691, 4690, - 4706, 4710, 4709, 4724, 4725, 4730, 4731, 4742, 4771, 4772, - 4773, 4776, 4777, 4781, 4782, 4791, 4791, 4796, 4797, 4805, - 4813, 4821, 4839, 4864, 4864, 4877, 4877, 4890, 4890, 4899, - 4903, 4916, 4916, 4929, 4931, 4929, 4942, 4947, 4951, 4950, - 4964, 4965, 4974, 4974, 4982, 4983, 4987, 4988, 4989, 4993, - 4994, 4999, 5000, 5005, 5009, 5010, 5011, 5012, 5013, 5014, - 5015, 5019, 5020, 5029, 5029, 5042, 5041, 5051, 5052, 5053, - 5057, 5058, 5062, 5063, 5064, 5070, 5070, 5075, 5076, 5080, - 5081, 5082, 5083, 5084, 5085, 5091, 5095, 5096, 5100, 5105, - 5109, 5110, 5111, 5112, 5113, 5117, 5143, 5156, 5157, 5161, - 5161, 5169, 5169, 5179, 5179, 5184, 5188, 5200, 5200, 5206, - 5210, 5217, 5218, 5227, 5227, 5231, 5232, 5246, 5247, 5248, - 5249, 5253, 5254, 5258, 5259, 5260, 5272, 5272, 5277, 5282, - 5281, 5291, 5298, 5299, 5303, 5308, 5317, 5320, 5324, 5329, - 5336, 5343, 5344, 5348, 5349, 5354, 5366, 5366, 5395, 5396, - 5400, 5401, 5405, 5409, 5413, 5417, 5424, 5425, 5431, 5432, - 5433, 5437, 5438, 5447, 5447, 5462, 5462, 5473, 5474, 5483, - 5483, 5500, 5501, 5505, 5512, 5513, 5522, 5535, 5535, 5541, - 5546, 5545, 5556, 5557, 5561, 5563, 5562, 5573, 5574, 5579, - 5578, 5589, 5590, 5599, 5599, 5604, 5605, 5606, 5607, 5608, - 5614, 5623, 5627, 5636, 5643, 5644, 5650, 5651, 5655, 5664, - 5665, 5669, 5673, 5685, 5685, 5691, 5690, 5707, 5710, 5731, - 5732, 5735, 5736, 5740, 5741, 5746, 5751, 5759, 5771, 5776, - 5784, 5800, 5801, 5800, 5821, 5822, 5830, 5831, 5832, 5833, - 5834, 5838, 5839, 5848, 5848, 5853, 5853, 5860, 5861, 5862, - 5871, 5871, 5880, 5881, 5885, 5886, 5887, 5891, 5892, 5896, - 5897, 5906, 5906, 5912, 5916, 5920, 5927, 5928, 5937, 5944, - 5945, 5953, 5953, 5966, 5966, 5982, 5982, 5991, 5993, 5994, - 6003, 6003, 6013, 6014, 6019, 6020, 6025, 6032, 6033, 6038, - 6045, 6046, 6050, 6051, 6055, 6056, 6060, 6061, 6070, 6071, - 6072, 6076, 6100, 6103, 6111, 6121, 6126, 6131, 6136, 6143, - 6144, 6147, 6148, 6152, 6152, 6156, 6156, 6160, 6160, 6163, - 6164, 6168, 6175, 6176, 6180, 6192, 6192, 6209, 6210, 6215, - 6218, 6222, 6226, 6233, 6234, 6237, 6238, 6239, 6243, 6244, - 6257, 6265, 6272, 6274, 6273, 6283, 6285, 6284, 6299, 6303, - 6305, 6304, 6315, 6317, 6316, 6333, 6339, 6341, 6340, 6350, - 6352, 6351, 6367, 6372, 6377, 6387, 6386, 6398, 6397, 6413, - 6418, 6423, 6433, 6432, 6444, 6443, 6458, 6459, 6463, 6468, - 6473, 6483, 6482, 6494, 6493, 6510, 6513, 6525, 6532, 6539, - 6539, 6549, 6550, 6552, 6553, 6554, 6555, 6556, 6557, 6559, - 6560, 6561, 6562, 6563, 6564, 6566, 6567, 6569, 6570, 6571, - 6574, 6576, 6577, 6578, 6580, 6581, 6582, 6584, 6585, 6587, - 6588, 6589, 6590, 6591, 6593, 6594, 6595, 6596, 6597, 6598, - 6600, 6601, 6602, 6603, 6604, 6605, 6607, 6608, 6611, 6611, - 6611, 6612, 6612, 6613, 6613, 6614, 6614, 6614, 6615, 6615, - 6615, 6620, 6621, 6624, 6625, 6626, 6630, 6631, 6632, 6633, - 6634, 6635, 6636, 6637, 6638, 6649, 6661, 6676, 6677, 6682, - 6688, 6710, 6730, 6734, 6750, 6764, 6765, 6770, 6776, 6777, - 6782, 6791, 6792, 6793, 6797, 6808, 6809, 6813, 6823, 6824, - 6828, 6829, 6833, 6834, 6840, 6860, 6861, 6865, 6866, 6870, - 6871, 6875, 6876, 6877, 6878, 6879, 6880, 6881, 6882, 6883, - 6887, 6888, 6889, 6890, 6891, 6892, 6893, 6897, 6898, 6902, - 6903, 6907, 6908, 6912, 6913, 6924, 6925, 6929, 6930, 6931, - 6935, 6936, 6937, 6945, 6949, 6950, 6951, 6952, 6956, 6957, - 6961, 6971, 6989, 7016, 7028, 7029, 7039, 7040, 7044, 7045, - 7046, 7047, 7048, 7049, 7050, 7058, 7062, 7066, 7070, 7074, - 7078, 7082, 7086, 7090, 7094, 7098, 7102, 7109, 7110, 7111, - 7115, 7116, 7120, 7121, 7126, 7133, 7140, 7150, 7157, 7167, - 7174, 7188, 7198, 7199, 7203, 7204, 7208, 7209, 7213, 7214, - 7215, 7219, 7220, 7224, 7225, 7229, 7230, 7234, 7235, 7242, - 7242, 7243, 7243, 7244, 7244, 7245, 7245, 7247, 7247, 7248, - 7248, 7249, 7249, 7250, 7250, 7251, 7251, 7252, 7252, 7253, - 7253, 7254, 7254, 7255, 7255, 7256, 7256, 7257, 7257, 7258, - 7258, 7259, 7259, 7260, 7260, 7261, 7261, 7262, 7262, 7263, - 7263, 7264, 7264, 7264, 7265, 7265, 7266, 7266, 7266, 7267, - 7267, 7268, 7268, 7269, 7269, 7270, 7270, 7271, 7271, 7272, - 7272, 7273, 7273, 7273, 7274, 7274, 7275, 7275, 7276, 7276, - 7277, 7277, 7278, 7278, 7279, 7279, 7280, 7280, 7280, 7281, - 7281, 7282, 7282, 7283, 7283, 7284, 7284, 7285, 7285, 7286, - 7286, 7287, 7287, 7289, 7289, 7290, 7290 + 2858, 2878, 2885, 2886, 2890, 2891, 2892, 2897, 2902, 2903, + 2904, 2905, 2906, 2907, 2908, 2909, 2914, 2919, 2920, 2921, + 2922, 2923, 2924, 2925, 2926, 2927, 2928, 2929, 2930, 2931, + 2932, 2933, 2934, 2935, 2936, 2937, 2945, 2953, 2961, 2968, + 2973, 2983, 2984, 2985, 2989, 3006, 3007, 3010, 3011, 3017, + 3017, 3020, 3044, 3060, 3061, 3065, 3066, 3069, 3069, 3072, + 3079, 3080, 3085, 3095, 3102, 3105, 3106, 3107, 3114, 3121, + 3146, 3150, 3150, 3155, 3156, 3160, 3161, 3164, 3165, 3178, + 3190, 3210, 3224, 3226, 3225, 3245, 3246, 3246, 3259, 3261, + 3260, 3272, 3273, 3277, 3278, 3287, 3294, 3297, 3301, 3305, + 3306, 3307, 3314, 3315, 3319, 3322, 3322, 3325, 3326, 3332, + 3337, 3338, 3341, 3342, 3345, 3346, 3349, 3350, 3353, 3354, + 3358, 3359, 3360, 3364, 3365, 3368, 3369, 3373, 3377, 3378, + 3382, 3383, 3384, 3385, 3386, 3387, 3388, 3389, 3390, 3391, + 3392, 3393, 3394, 3395, 3396, 3397, 3401, 3405, 3406, 3407, + 3408, 3409, 3410, 3411, 3415, 3419, 3420, 3421, 3425, 3426, + 3430, 3434, 3439, 3443, 3447, 3451, 3452, 3456, 3457, 3461, + 3462, 3463, 3466, 3466, 3466, 3469, 3473, 3476, 3476, 3479, + 3486, 3487, 3487, 3497, 3499, 3509, 3498, 3536, 3538, 3537, + 3544, 3543, 3552, 3553, 3558, 3565, 3567, 3571, 3581, 3583, + 3591, 3599, 3628, 3659, 3661, 3671, 3676, 3687, 3688, 3688, + 3715, 3716, 3720, 3721, 3722, 3723, 3739, 3751, 3782, 3819, + 3831, 3834, 3835, 3844, 3848, 3844, 3861, 3882, 3886, 3887, + 3888, 3889, 3890, 3891, 3892, 3893, 3894, 3895, 3896, 3897, + 3898, 3899, 3900, 3901, 3902, 3903, 3904, 3905, 3906, 3907, + 3908, 3909, 3910, 3911, 3912, 3913, 3914, 3915, 3916, 3917, + 3918, 3919, 3920, 3921, 3922, 3923, 3924, 3925, 3926, 3927, + 3928, 3929, 3930, 3931, 3932, 3933, 3934, 3935, 3958, 3957, + 3970, 3974, 3978, 3982, 3986, 3990, 3994, 3998, 4002, 4006, + 4010, 4014, 4018, 4022, 4026, 4030, 4034, 4041, 4042, 4043, + 4044, 4045, 4046, 4050, 4054, 4055, 4058, 4059, 4063, 4064, + 4068, 4069, 4070, 4071, 4072, 4073, 4074, 4075, 4079, 4083, + 4087, 4092, 4093, 4094, 4095, 4096, 4097, 4101, 4102, 4111, + 4111, 4117, 4121, 4125, 4131, 4132, 4136, 4137, 4146, 4146, + 4151, 4155, 4162, 4163, 4172, 4178, 4179, 4183, 4183, 4191, + 4191, 4201, 4203, 4202, 4211, 4212, 4217, 4224, 4231, 4233, + 4237, 4245, 4256, 4257, 4258, 4263, 4267, 4266, 4278, 4282, + 4281, 4292, 4293, 4302, 4302, 4306, 4307, 4311, 4323, 4323, + 4327, 4328, 4339, 4340, 4341, 4342, 4343, 4346, 4346, 4354, + 4354, 4360, 4367, 4368, 4371, 4371, 4378, 4391, 4404, 4404, + 4415, 4416, 4425, 4425, 4445, 4444, 4457, 4461, 4465, 4469, + 4473, 4477, 4481, 4486, 4490, 4497, 4498, 4499, 4503, 4504, + 4509, 4510, 4511, 4512, 4513, 4514, 4515, 4516, 4517, 4518, + 4522, 4526, 4530, 4535, 4536, 4540, 4541, 4550, 4550, 4556, + 4560, 4564, 4568, 4572, 4579, 4580, 4589, 4589, 4611, 4610, + 4629, 4630, 4641, 4650, 4655, 4663, 4692, 4693, 4699, 4698, + 4714, 4718, 4717, 4732, 4733, 4738, 4739, 4750, 4779, 4780, + 4781, 4784, 4785, 4789, 4790, 4799, 4799, 4804, 4805, 4813, + 4821, 4829, 4847, 4872, 4872, 4885, 4885, 4898, 4898, 4907, + 4911, 4924, 4924, 4937, 4939, 4937, 4950, 4955, 4959, 4958, + 4972, 4973, 4982, 4982, 4990, 4991, 4995, 4996, 4997, 5001, + 5002, 5007, 5008, 5013, 5017, 5018, 5019, 5020, 5021, 5022, + 5023, 5027, 5028, 5037, 5037, 5050, 5049, 5059, 5060, 5061, + 5065, 5066, 5070, 5071, 5072, 5078, 5078, 5083, 5084, 5088, + 5089, 5090, 5091, 5092, 5093, 5099, 5103, 5104, 5108, 5113, + 5117, 5118, 5119, 5120, 5121, 5125, 5151, 5164, 5165, 5169, + 5169, 5177, 5177, 5187, 5187, 5192, 5196, 5208, 5208, 5214, + 5218, 5225, 5226, 5235, 5235, 5239, 5240, 5254, 5255, 5256, + 5257, 5261, 5262, 5266, 5267, 5268, 5280, 5280, 5285, 5290, + 5289, 5299, 5306, 5307, 5311, 5316, 5325, 5328, 5332, 5337, + 5344, 5351, 5352, 5356, 5357, 5362, 5374, 5374, 5401, 5402, + 5406, 5407, 5411, 5415, 5419, 5423, 5430, 5431, 5437, 5438, + 5439, 5443, 5444, 5453, 5453, 5468, 5468, 5479, 5480, 5489, + 5489, 5506, 5507, 5511, 5518, 5519, 5528, 5541, 5541, 5547, + 5552, 5551, 5562, 5563, 5567, 5569, 5568, 5579, 5580, 5585, + 5584, 5595, 5596, 5605, 5605, 5610, 5611, 5612, 5613, 5614, + 5620, 5629, 5633, 5642, 5649, 5650, 5656, 5657, 5661, 5670, + 5671, 5675, 5679, 5691, 5691, 5697, 5696, 5713, 5716, 5737, + 5738, 5741, 5742, 5746, 5747, 5752, 5757, 5765, 5777, 5782, + 5790, 5806, 5807, 5806, 5827, 5828, 5836, 5837, 5838, 5839, + 5840, 5844, 5845, 5854, 5854, 5859, 5859, 5866, 5867, 5868, + 5877, 5877, 5886, 5887, 5891, 5892, 5893, 5897, 5898, 5902, + 5903, 5912, 5912, 5918, 5922, 5926, 5933, 5934, 5943, 5950, + 5951, 5959, 5959, 5972, 5972, 5988, 5988, 5997, 5999, 6000, + 6009, 6009, 6019, 6020, 6025, 6026, 6031, 6038, 6039, 6044, + 6051, 6052, 6056, 6057, 6061, 6062, 6066, 6067, 6076, 6077, + 6078, 6082, 6106, 6109, 6117, 6127, 6132, 6137, 6142, 6149, + 6150, 6153, 6154, 6158, 6158, 6162, 6162, 6166, 6166, 6169, + 6170, 6174, 6181, 6182, 6186, 6198, 6198, 6215, 6216, 6221, + 6224, 6228, 6232, 6239, 6240, 6243, 6244, 6245, 6249, 6250, + 6263, 6271, 6278, 6280, 6279, 6289, 6291, 6290, 6305, 6309, + 6311, 6310, 6321, 6323, 6322, 6339, 6345, 6347, 6346, 6356, + 6358, 6357, 6373, 6378, 6383, 6393, 6392, 6404, 6403, 6419, + 6424, 6429, 6439, 6438, 6450, 6449, 6464, 6465, 6469, 6474, + 6479, 6489, 6488, 6500, 6499, 6516, 6519, 6531, 6538, 6545, + 6545, 6555, 6556, 6558, 6559, 6560, 6561, 6562, 6563, 6565, + 6566, 6567, 6568, 6569, 6570, 6572, 6573, 6575, 6576, 6577, + 6580, 6582, 6583, 6584, 6586, 6587, 6588, 6590, 6591, 6593, + 6594, 6595, 6596, 6597, 6599, 6600, 6601, 6602, 6603, 6604, + 6606, 6607, 6608, 6609, 6610, 6611, 6613, 6614, 6617, 6617, + 6617, 6618, 6618, 6619, 6619, 6620, 6620, 6620, 6621, 6621, + 6621, 6626, 6627, 6630, 6631, 6632, 6636, 6637, 6638, 6639, + 6640, 6641, 6642, 6643, 6644, 6655, 6667, 6682, 6683, 6688, + 6694, 6716, 6736, 6740, 6756, 6770, 6771, 6776, 6782, 6783, + 6788, 6797, 6798, 6799, 6803, 6814, 6815, 6819, 6829, 6830, + 6834, 6835, 6839, 6840, 6846, 6866, 6867, 6871, 6872, 6876, + 6877, 6881, 6882, 6883, 6884, 6885, 6886, 6887, 6888, 6889, + 6893, 6894, 6895, 6896, 6897, 6898, 6899, 6903, 6904, 6908, + 6909, 6913, 6914, 6918, 6919, 6930, 6931, 6935, 6936, 6937, + 6941, 6942, 6943, 6951, 6955, 6956, 6957, 6958, 6962, 6963, + 6967, 6977, 6991, 7014, 7026, 7027, 7037, 7038, 7042, 7043, + 7044, 7045, 7046, 7047, 7048, 7056, 7060, 7064, 7068, 7072, + 7076, 7080, 7084, 7088, 7092, 7096, 7100, 7107, 7108, 7109, + 7113, 7114, 7118, 7119, 7124, 7131, 7138, 7148, 7155, 7165, + 7172, 7186, 7196, 7197, 7201, 7202, 7206, 7207, 7211, 7212, + 7213, 7217, 7218, 7222, 7223, 7227, 7228, 7232, 7233, 7240, + 7240, 7241, 7241, 7242, 7242, 7243, 7243, 7245, 7245, 7246, + 7246, 7247, 7247, 7248, 7248, 7249, 7249, 7250, 7250, 7251, + 7251, 7252, 7252, 7253, 7253, 7254, 7254, 7255, 7255, 7256, + 7256, 7257, 7257, 7258, 7258, 7259, 7259, 7260, 7260, 7261, + 7261, 7262, 7262, 7262, 7263, 7263, 7264, 7264, 7264, 7265, + 7265, 7266, 7266, 7267, 7267, 7268, 7268, 7269, 7269, 7270, + 7270, 7271, 7271, 7271, 7272, 7272, 7273, 7273, 7274, 7274, + 7275, 7275, 7276, 7276, 7277, 7277, 7278, 7278, 7278, 7279, + 7279, 7280, 7280, 7281, 7281, 7282, 7282, 7283, 7283, 7284, + 7284, 7285, 7285, 7287, 7287, 7288, 7288 }; #endif @@ -2420,6 +2402,61 @@ yysymbol_name (yysymbol_kind_t yysymbol) } #endif +#ifdef YYPRINT +/* YYTOKNUM[NUM] -- (External) token number corresponding to the + (internal) symbol number NUM (which must be that of a token). */ +static const yytype_int16 yytoknum[] = +{ + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, + 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, + 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, + 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, + 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, + 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, + 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, + 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, + 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, + 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, + 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, + 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, + 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, + 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, + 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, + 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, + 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, + 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, + 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, + 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, + 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, + 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, + 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, + 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, + 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, + 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, + 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, + 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, + 575, 576, 577, 578, 579, 580, 581, 582, 583, 584, + 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, + 595, 596, 597, 598, 599, 600, 601, 602, 603, 604, + 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, + 615, 616, 617, 618, 619, 620, 621, 622, 623, 624, + 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, + 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, + 645, 646, 647, 648, 649, 650, 651, 652, 653, 654, + 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, + 665, 666, 667, 668, 669, 670, 671, 672, 673, 674, + 675, 676, 677, 678, 679, 680, 681, 682, 683, 684, + 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, + 695, 696, 697, 698, 699, 700, 701, 702, 703, 43, + 45, 42, 47, 704, 94, 46, 61, 41, 40, 62, + 60, 58, 38 +}; +#endif + #define YYPACT_NINF (-2010) #define yypact_value_is_default(Yyn) \ @@ -2430,8 +2467,8 @@ yysymbol_name (yysymbol_kind_t yysymbol) #define yytable_value_is_error(Yyn) \ 0 -/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - STATE-NUM. */ + /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ static const yytype_int16 yypact[] = { -2010, 206, 536, -2010, 153, 306, 195, -2010, -2010, -2010, @@ -2665,9 +2702,9 @@ static const yytype_int16 yypact[] = -2010, 4721, -2010, -2010 }; -/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. - Performed when YYTABLE does not specify something else to do. Zero - means the default is an error. */ + /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE does not specify something else to do. Zero + means the default is an error. */ static const yytype_int16 yydefact[] = { 2, 0, 0, 1, 0, 0, 0, 4, 6, 7, @@ -2901,7 +2938,7 @@ static const yytype_int16 yydefact[] = 509, 0, 1080, 553 }; -/* YYPGOTO[NTERM-NUM]. */ + /* YYPGOTO[NTERM-NUM]. */ static const yytype_int16 yypgoto[] = { -2010, -2010, -2010, -2010, 1892, -2010, -2010, -2010, 44, -2010, @@ -2977,10 +3014,10 @@ static const yytype_int16 yypgoto[] = 1076, -129 }; -/* YYDEFGOTO[NTERM-NUM]. */ + /* YYDEFGOTO[NTERM-NUM]. */ static const yytype_int16 yydefgoto[] = { - 0, 1, 2, 6, 7, 8, 24, 39, 69, 128, + -1, 1, 2, 6, 7, 8, 24, 39, 69, 128, 256, 9, 25, 40, 70, 90, 499, 73, 71, 35, 11, 21, 27, 42, 57, 58, 17, 37, 77, 97, 98, 191, 192, 178, 99, 179, 180, 181, 182, 502, @@ -3053,9 +3090,9 @@ static const yytype_int16 yydefgoto[] = 844, 1524 }; -/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If - positive, shift that token. If negative, reduce the rule whose - number is the opposite. If YYTABLE_NINF, syntax error. */ + /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule whose + number is the opposite. If YYTABLE_NINF, syntax error. */ static const yytype_int16 yytable[] = { 122, 258, 301, 194, 478, 686, 902, 1137, 560, 865, @@ -4174,8 +4211,8 @@ static const yytype_int16 yycheck[] = 450, -1, -1, -1, -1, -1, -1, -1, 458 }; -/* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of - state STATE-NUM. */ + /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ static const yytype_int16 yystos[] = { 0, 464, 465, 0, 183, 311, 466, 467, 468, 474, @@ -4409,7 +4446,7 @@ static const yytype_int16 yystos[] = 1098, 49, 901, 1084 }; -/* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */ + /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ static const yytype_int16 yyr1[] = { 0, 463, 465, 464, 466, 466, 467, 467, 469, 470, @@ -4569,7 +4606,7 @@ static const yytype_int16 yyr1[] = 1161, 1162, 1162, 1163, 1163, 1164, 1164 }; -/* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */ + /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ static const yytype_int8 yyr2[] = { 0, 2, 0, 3, 1, 2, 1, 1, 0, 0, @@ -4738,7 +4775,6 @@ enum { YYENOMEM = -2 }; #define YYACCEPT goto yyacceptlab #define YYABORT goto yyabortlab #define YYERROR goto yyerrorlab -#define YYNOMEM goto yyexhaustedlab #define YYRECOVERING() (!!yyerrstatus) @@ -4779,7 +4815,10 @@ do { \ YYFPRINTF Args; \ } while (0) - +/* This macro is provided for backward compatibility. */ +# ifndef YY_LOCATION_PRINT +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# endif # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ @@ -4803,11 +4842,15 @@ yy_symbol_value_print (FILE *yyo, yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) { FILE *yyoutput = yyo; - YY_USE (yyoutput); + YYUSE (yyoutput); if (!yyvaluep) return; +# ifdef YYPRINT + if (yykind < YYNTOKENS) + YYPRINT (yyo, yytoknum[yykind], *yyvaluep); +# endif YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - YY_USE (yykind); + YYUSE (yykind); YY_IGNORE_MAYBE_UNINITIALIZED_END } @@ -4921,13 +4964,13 @@ static void yydestruct (const char *yymsg, yysymbol_kind_t yykind, YYSTYPE *yyvaluep) { - YY_USE (yyvaluep); + YYUSE (yyvaluep); if (!yymsg) yymsg = "Deleting"; YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - YY_USE (yykind); + YYUSE (yykind); YY_IGNORE_MAYBE_UNINITIALIZED_END } @@ -4990,7 +5033,6 @@ yyparse (void) YYDPRINTF ((stderr, "Starting parse\n")); yychar = YYEMPTY; /* Cause a token to be read. */ - goto yysetstate; @@ -5016,7 +5058,7 @@ yyparse (void) if (yyss + yystacksize - 1 <= yyssp) #if !defined yyoverflow && !defined YYSTACK_RELOCATE - YYNOMEM; + goto yyexhaustedlab; #else { /* Get the current used size of the three stacks, in elements. */ @@ -5044,7 +5086,7 @@ yyparse (void) # else /* defined YYSTACK_RELOCATE */ /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) - YYNOMEM; + goto yyexhaustedlab; yystacksize *= 2; if (YYMAXDEPTH < yystacksize) yystacksize = YYMAXDEPTH; @@ -5055,7 +5097,7 @@ yyparse (void) YY_CAST (union yyalloc *, YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); if (! yyptr) - YYNOMEM; + goto yyexhaustedlab; YYSTACK_RELOCATE (yyss_alloc, yyss); YYSTACK_RELOCATE (yyvs_alloc, yyvs); # undef YYSTACK_RELOCATE @@ -5077,7 +5119,6 @@ yyparse (void) } #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ - if (yystate == YYFINAL) YYACCEPT; @@ -5213,7 +5254,7 @@ yyparse (void) cb_build_registers (); current_program->flag_main = cb_flag_main; } -#line 5217 "parser.c" +#line 5258 "parser.c" break; case 3: /* start: $@1 nested_list "end of file" */ @@ -5235,19 +5276,19 @@ yyparse (void) emit_entry (current_program->program_id, 0, NULL); } } -#line 5239 "parser.c" +#line 5280 "parser.c" break; case 8: /* $@2: %empty */ #line 827 "parser.y" { cb_validate_program_environment (current_program); } -#line 5245 "parser.c" +#line 5286 "parser.c" break; case 9: /* $@3: %empty */ #line 828 "parser.y" { cb_validate_program_data (current_program); } -#line 5251 "parser.c" +#line 5292 "parser.c" break; case 10: /* program_definition: identification_division environment_division $@2 data_division $@3 procedure_division nested_prog end_program */ @@ -5258,19 +5299,19 @@ yyparse (void) cb_validate_indexed_file_key(CB_FILE(CB_VALUE(file))); } } -#line 5262 "parser.c" +#line 5303 "parser.c" break; case 11: /* $@4: %empty */ #line 841 "parser.y" { cb_validate_program_environment (current_program); } -#line 5268 "parser.c" +#line 5309 "parser.c" break; case 12: /* $@5: %empty */ #line 842 "parser.y" { cb_validate_program_data (current_program); } -#line 5274 "parser.c" +#line 5315 "parser.c" break; case 13: /* program_mandatory: identification_division environment_division $@4 data_division $@5 procedure_division nested_prog end_mandatory */ @@ -5281,19 +5322,19 @@ yyparse (void) cb_validate_indexed_file_key(CB_FILE(CB_VALUE(file))); } } -#line 5285 "parser.c" +#line 5326 "parser.c" break; case 14: /* $@6: %empty */ #line 855 "parser.y" { cb_validate_program_environment (current_program); } -#line 5291 "parser.c" +#line 5332 "parser.c" break; case 15: /* $@7: %empty */ #line 856 "parser.y" { cb_validate_program_data (current_program); } -#line 5297 "parser.c" +#line 5338 "parser.c" break; case 21: /* end_program: "END PROGRAM" program_name '.' */ @@ -5322,7 +5363,7 @@ yyparse (void) cb_validate_program_body (current_program); } } -#line 5326 "parser.c" +#line 5367 "parser.c" break; case 22: /* end_mandatory: "END PROGRAM" program_name '.' */ @@ -5349,7 +5390,7 @@ yyparse (void) cb_validate_program_body (current_program); } } -#line 5353 "parser.c" +#line 5394 "parser.c" break; case 23: /* end_function: "END FUNCTION" program_name '.' */ @@ -5376,7 +5417,7 @@ yyparse (void) cb_validate_program_body (current_program); } } -#line 5380 "parser.c" +#line 5421 "parser.c" break; case 24: /* $@8: %empty */ @@ -5420,7 +5461,7 @@ yyparse (void) depth++; current_program->program_id = cb_build_program_id (yyvsp[-1], yyvsp[0]); } -#line 5424 "parser.c" +#line 5465 "parser.c" break; case 26: /* function_division: "FUNCTION-ID" '.' program_name as_literal '.' */ @@ -5465,19 +5506,19 @@ yyparse (void) current_program->flag_recursive = 1; current_program->flag_initial = 1; } -#line 5469 "parser.c" +#line 5510 "parser.c" break; case 29: /* as_literal: %empty */ #line 1045 "parser.y" { yyval = NULL; } -#line 5475 "parser.c" +#line 5516 "parser.c" break; case 30: /* as_literal: AS "Literal" */ #line 1046 "parser.y" { yyval = yyvsp[0]; } -#line 5481 "parser.c" +#line 5522 "parser.c" break; case 33: /* program_type_clause: COMMON */ @@ -5488,7 +5529,7 @@ yyparse (void) } current_program->flag_common = 1; } -#line 5492 "parser.c" +#line 5533 "parser.c" break; case 34: /* program_type_clause: COMMON _init_or_recurs */ @@ -5499,7 +5540,7 @@ yyparse (void) } current_program->flag_common = 1; } -#line 5503 "parser.c" +#line 5544 "parser.c" break; case 36: /* _init_or_recurs: "INITIAL" */ @@ -5507,7 +5548,7 @@ yyparse (void) { current_program->flag_initial = 1; } -#line 5511 "parser.c" +#line 5552 "parser.c" break; case 37: /* _init_or_recurs: RECURSIVE */ @@ -5516,7 +5557,7 @@ yyparse (void) current_program->flag_recursive = 1; current_program->flag_initial = 1; } -#line 5520 "parser.c" +#line 5561 "parser.c" break; case 41: /* configuration_section: CONFIGURATION SECTION '.' configuration_list */ @@ -5526,7 +5567,7 @@ yyparse (void) cb_error (_("CONFIGURATION SECTION not allowed in nested programs")); } } -#line 5530 "parser.c" +#line 5571 "parser.c" break; case 53: /* with_debugging_mode: _with DEBUGGING MODE */ @@ -5534,13 +5575,13 @@ yyparse (void) { cb_verify (cb_debugging_line, "DEBUGGING MODE"); } -#line 5538 "parser.c" +#line 5579 "parser.c" break; case 54: /* computer_name: "Identifier" */ #line 1143 "parser.y" { } -#line 5544 "parser.c" +#line 5585 "parser.c" break; case 65: /* object_computer_memory: MEMORY SIZE _is integer object_char_or_word */ @@ -5548,7 +5589,7 @@ yyparse (void) { cb_verify (cb_memory_size_clause, "MEMORY SIZE"); } -#line 5552 "parser.c" +#line 5593 "parser.c" break; case 68: /* object_computer_sequence: _program coll_sequence _is reference */ @@ -5556,7 +5597,7 @@ yyparse (void) { current_program->collating_sequence = yyvsp[0]; } -#line 5560 "parser.c" +#line 5601 "parser.c" break; case 69: /* object_computer_segment: "SEGMENT-LIMIT" _is integer */ @@ -5564,7 +5605,7 @@ yyparse (void) { /* Ignore */ } -#line 5568 "parser.c" +#line 5609 "parser.c" break; case 75: /* repository_name: FUNCTION repository_literal_list INTRINSIC */ @@ -5572,7 +5613,7 @@ yyparse (void) { current_program->function_spec_list = yyvsp[-1]; } -#line 5576 "parser.c" +#line 5617 "parser.c" break; case 76: /* repository_name: FUNCTION ALL INTRINSIC */ @@ -5580,19 +5621,19 @@ yyparse (void) { functions_are_all = 1; } -#line 5584 "parser.c" +#line 5625 "parser.c" break; case 77: /* repository_literal_list: "Literal" */ #line 1228 "parser.y" { yyval = cb_list_init (yyvsp[0]); } -#line 5590 "parser.c" +#line 5631 "parser.c" break; case 78: /* repository_literal_list: repository_literal_list "Literal" */ #line 1230 "parser.y" { yyval = cb_list_add (yyvsp[-1], yyvsp[0]); } -#line 5596 "parser.c" +#line 5637 "parser.c" break; case 96: /* mnemonic_name_clause: "Identifier" _is CRT */ @@ -5606,7 +5647,7 @@ yyparse (void) } /* current_program->flag_screen = 1; */ } -#line 5610 "parser.c" +#line 5651 "parser.c" break; case 97: /* $@9: %empty */ @@ -5620,7 +5661,7 @@ yyparse (void) } save_tree_2 = yyvsp[0]; } -#line 5624 "parser.c" +#line 5665 "parser.c" break; case 99: /* $@10: %empty */ @@ -5632,7 +5673,7 @@ yyparse (void) } save_tree_2 = NULL; } -#line 5636 "parser.c" +#line 5677 "parser.c" break; case 101: /* mnemonic_name_clause: "ARGUMENT-NUMBER" _is undefined_word */ @@ -5650,7 +5691,7 @@ yyparse (void) cb_error (_("SPECIAL-NAMES with ARGUMENT-NUMBER clause is not yet supported")); } } -#line 5654 "parser.c" +#line 5695 "parser.c" break; case 102: /* mnemonic_name_clause: "ARGUMENT-VALUE" _is undefined_word */ @@ -5668,7 +5709,7 @@ yyparse (void) cb_error (_("SPECIAL-NAMES with ARGUMENT-VALUE clause is not yet supported")); } } -#line 5672 "parser.c" +#line 5713 "parser.c" break; case 103: /* mnemonic_name_clause: "ENVIRONMENT-NAME" _is undefined_word */ @@ -5686,7 +5727,7 @@ yyparse (void) cb_error (_("SPECIAL-NAMES with ENVIRONMENT-NAME clause is not yet supported")); } } -#line 5690 "parser.c" +#line 5731 "parser.c" break; case 104: /* mnemonic_name_clause: "ENVIRONMENT-VALUE" _is undefined_word */ @@ -5704,7 +5745,7 @@ yyparse (void) cb_error (_("SPECIAL-NAMES with ENVIRONMENT-VALUE clause is not yet supported")); } } -#line 5708 "parser.c" +#line 5749 "parser.c" break; case 109: /* special_name_mnemonic_on_off: on_or_off _status _is undefined_word */ @@ -5716,19 +5757,19 @@ yyparse (void) cb_define_switch_name (yyvsp[0], save_tree_1, yyvsp[-3], save_tree_2); } } -#line 5720 "parser.c" +#line 5761 "parser.c" break; case 110: /* on_or_off: ON */ #line 1379 "parser.y" { yyval = cb_int1; } -#line 5726 "parser.c" +#line 5767 "parser.c" break; case 111: /* on_or_off: OFF */ #line 1380 "parser.y" { yyval = cb_int0; } -#line 5732 "parser.c" +#line 5773 "parser.c" break; case 112: /* $@11: %empty */ @@ -5736,7 +5777,7 @@ yyparse (void) { save_tree_1 = yyvsp[0]; } -#line 5740 "parser.c" +#line 5781 "parser.c" break; case 113: /* alphabet_name_clause: ALPHABET undefined_word $@11 _is alphabet_definition */ @@ -5745,31 +5786,31 @@ yyparse (void) current_program->alphabet_name_list = cb_list_add (current_program->alphabet_name_list, yyvsp[0]); } -#line 5749 "parser.c" +#line 5790 "parser.c" break; case 114: /* alphabet_definition: NATIVE */ #line 1399 "parser.y" { yyval = cb_build_alphabet_name (save_tree_1, CB_ALPHABET_NATIVE); } -#line 5755 "parser.c" +#line 5796 "parser.c" break; case 115: /* alphabet_definition: "STANDARD-1" */ #line 1400 "parser.y" { yyval = cb_build_alphabet_name (save_tree_1, CB_ALPHABET_STANDARD_1); } -#line 5761 "parser.c" +#line 5802 "parser.c" break; case 116: /* alphabet_definition: "STANDARD-2" */ #line 1401 "parser.y" { yyval = cb_build_alphabet_name (save_tree_1, CB_ALPHABET_STANDARD_2); } -#line 5767 "parser.c" +#line 5808 "parser.c" break; case 117: /* alphabet_definition: EBCDIC */ #line 1402 "parser.y" { yyval = cb_build_alphabet_name (save_tree_1, CB_ALPHABET_EBCDIC); } -#line 5773 "parser.c" +#line 5814 "parser.c" break; case 118: /* alphabet_definition: alphabet_literal_list */ @@ -5778,31 +5819,31 @@ yyparse (void) yyval = cb_build_alphabet_name (save_tree_1, CB_ALPHABET_CUSTOM); CB_ALPHABET_NAME (yyval)->custom_list = yyvsp[0]; } -#line 5782 "parser.c" +#line 5823 "parser.c" break; case 119: /* alphabet_literal_list: alphabet_literal */ #line 1411 "parser.y" { yyval = cb_list_init (yyvsp[0]); } -#line 5788 "parser.c" +#line 5829 "parser.c" break; case 120: /* alphabet_literal_list: alphabet_literal_list alphabet_literal */ #line 1413 "parser.y" { yyval = cb_list_add (yyvsp[-1], yyvsp[0]); } -#line 5794 "parser.c" +#line 5835 "parser.c" break; case 121: /* alphabet_literal: alphabet_lits */ #line 1417 "parser.y" { yyval = yyvsp[0]; } -#line 5800 "parser.c" +#line 5841 "parser.c" break; case 122: /* alphabet_literal: alphabet_lits THRU alphabet_lits */ #line 1418 "parser.y" { yyval = cb_build_pair (yyvsp[-2], yyvsp[0]); } -#line 5806 "parser.c" +#line 5847 "parser.c" break; case 123: /* @12: %empty */ @@ -5811,7 +5852,7 @@ yyparse (void) yyval = cb_list_init (yyvsp[-1]); save_tree_2 = yyval; } -#line 5815 "parser.c" +#line 5856 "parser.c" break; case 124: /* alphabet_literal: alphabet_lits ALSO @12 alphabet_also_sequence */ @@ -5819,79 +5860,79 @@ yyparse (void) { yyval = yyvsp[-1]; } -#line 5823 "parser.c" +#line 5864 "parser.c" break; case 127: /* alphabet_lits: "Literal" */ #line 1436 "parser.y" { yyval = yyvsp[0]; } -#line 5829 "parser.c" +#line 5870 "parser.c" break; case 128: /* alphabet_lits: SPACE */ #line 1437 "parser.y" { yyval = cb_space; } -#line 5835 "parser.c" +#line 5876 "parser.c" break; case 129: /* alphabet_lits: ZERO */ #line 1438 "parser.y" { yyval = cb_zero; } -#line 5841 "parser.c" +#line 5882 "parser.c" break; case 130: /* alphabet_lits: QUOTE */ #line 1439 "parser.y" { yyval = cb_quote; } -#line 5847 "parser.c" +#line 5888 "parser.c" break; case 131: /* alphabet_lits: "HIGH-VALUE" */ #line 1440 "parser.y" { yyval = cb_norm_high; } -#line 5853 "parser.c" +#line 5894 "parser.c" break; case 132: /* alphabet_lits: "LOW-VALUE" */ #line 1441 "parser.y" { yyval = cb_norm_low; } -#line 5859 "parser.c" +#line 5900 "parser.c" break; case 133: /* alphabet_also_literal: "Literal" */ #line 1445 "parser.y" { cb_list_add (save_tree_2, yyvsp[0]); } -#line 5865 "parser.c" +#line 5906 "parser.c" break; case 134: /* alphabet_also_literal: SPACE */ #line 1446 "parser.y" { cb_list_add (save_tree_2, cb_space); } -#line 5871 "parser.c" +#line 5912 "parser.c" break; case 135: /* alphabet_also_literal: ZERO */ #line 1447 "parser.y" { cb_list_add (save_tree_2, cb_zero); } -#line 5877 "parser.c" +#line 5918 "parser.c" break; case 136: /* alphabet_also_literal: QUOTE */ #line 1448 "parser.y" { cb_list_add (save_tree_2, cb_quote); } -#line 5883 "parser.c" +#line 5924 "parser.c" break; case 137: /* alphabet_also_literal: "HIGH-VALUE" */ #line 1449 "parser.y" { cb_list_add (save_tree_2, cb_norm_high); } -#line 5889 "parser.c" +#line 5930 "parser.c" break; case 138: /* alphabet_also_literal: "LOW-VALUE" */ #line 1450 "parser.y" { cb_list_add (save_tree_2, cb_norm_low); } -#line 5895 "parser.c" +#line 5936 "parser.c" break; case 139: /* symbolic_characters_clause: SYMBOLIC _characters symbolic_characters_list */ @@ -5903,7 +5944,7 @@ yyparse (void) } PENDING ("SYMBOLIC CHARACTERS"); } -#line 5907 "parser.c" +#line 5948 "parser.c" break; case 140: /* symbolic_characters_list: char_list _is_are integer_list */ @@ -5916,31 +5957,31 @@ yyparse (void) yyval = NULL; } } -#line 5920 "parser.c" +#line 5961 "parser.c" break; case 141: /* char_list: undefined_word */ #line 1480 "parser.y" { yyval = cb_list_init (yyvsp[0]); } -#line 5926 "parser.c" +#line 5967 "parser.c" break; case 142: /* char_list: char_list undefined_word */ #line 1481 "parser.y" { yyval = cb_list_add (yyvsp[-1], yyvsp[0]); } -#line 5932 "parser.c" +#line 5973 "parser.c" break; case 143: /* integer_list: integer */ #line 1485 "parser.y" { yyval = cb_list_init (yyvsp[0]); } -#line 5938 "parser.c" +#line 5979 "parser.c" break; case 144: /* integer_list: integer_list integer */ #line 1486 "parser.y" { yyval = cb_list_add (yyvsp[-1], yyvsp[0]); } -#line 5944 "parser.c" +#line 5985 "parser.c" break; case 145: /* class_name_clause: CLASS undefined_word _is class_item_list */ @@ -5950,25 +5991,25 @@ yyparse (void) cb_list_add (current_program->class_name_list, cb_build_class_name (yyvsp[-2], yyvsp[0])); } -#line 5954 "parser.c" +#line 5995 "parser.c" break; case 146: /* class_item_list: class_item */ #line 1502 "parser.y" { yyval = cb_list_init (yyvsp[0]); } -#line 5960 "parser.c" +#line 6001 "parser.c" break; case 147: /* class_item_list: class_item_list class_item */ #line 1503 "parser.y" { yyval = cb_list_add (yyvsp[-1], yyvsp[0]); } -#line 5966 "parser.c" +#line 6007 "parser.c" break; case 148: /* class_item: basic_value */ #line 1507 "parser.y" { yyval = yyvsp[0]; } -#line 5972 "parser.c" +#line 6013 "parser.c" break; case 149: /* class_item: basic_value THRU basic_value */ @@ -5981,7 +6022,7 @@ yyparse (void) yyval = cb_build_pair (yyvsp[0], yyvsp[-2]); } } -#line 5985 "parser.c" +#line 6026 "parser.c" break; case 150: /* locale_clause: LOCALE undefined_word _is reference */ @@ -5995,7 +6036,7 @@ yyparse (void) cb_list_add (current_program->locale_list, l); } } -#line 5999 "parser.c" +#line 6040 "parser.c" break; case 151: /* currency_sign_clause: CURRENCY _sign _is "Literal" */ @@ -6060,7 +6101,7 @@ yyparse (void) } current_program->currency_symbol = s[0]; } -#line 6064 "parser.c" +#line 6105 "parser.c" break; case 152: /* decimal_point_clause: "DECIMAL-POINT" _is COMMA */ @@ -6069,31 +6110,31 @@ yyparse (void) current_program->decimal_point = ','; current_program->numeric_separator = '.'; } -#line 6073 "parser.c" +#line 6114 "parser.c" break; case 153: /* cursor_clause: CURSOR _is reference */ #line 1615 "parser.y" { current_program->cursor_pos = yyvsp[0]; } -#line 6079 "parser.c" +#line 6120 "parser.c" break; case 154: /* crt_status_clause: CRT STATUS _is reference */ #line 1622 "parser.y" { current_program->crt_status = yyvsp[0]; } -#line 6085 "parser.c" +#line 6126 "parser.c" break; case 155: /* screen_control: "SCREEN-CONTROL" _is reference */ #line 1629 "parser.y" { PENDING ("SCREEN CONTROL"); } -#line 6091 "parser.c" +#line 6132 "parser.c" break; case 156: /* event_status: "EVENT-STATUS" _is reference */ #line 1635 "parser.y" { PENDING ("EVENT STATUS"); } -#line 6097 "parser.c" +#line 6138 "parser.c" break; case 159: /* $@13: %empty */ @@ -6106,7 +6147,7 @@ yyparse (void) cb_error (_("INPUT-OUTPUT SECTION header missing")); } } -#line 6110 "parser.c" +#line 6151 "parser.c" break; case 161: /* $@14: %empty */ @@ -6119,7 +6160,7 @@ yyparse (void) cb_error (_("INPUT-OUTPUT SECTION header missing")); } } -#line 6123 "parser.c" +#line 6164 "parser.c" break; case 167: /* $@15: %empty */ @@ -6138,7 +6179,7 @@ yyparse (void) current_program->file_list = cb_cons (CB_TREE (current_file), current_program->file_list); } -#line 6142 "parser.c" +#line 6183 "parser.c" break; case 168: /* file_control_entry: SELECT flag_optional undefined_word $@15 select_clause_sequence '.' */ @@ -6146,7 +6187,7 @@ yyparse (void) { validate_file (current_file, yyvsp[-3]); } -#line 6150 "parser.c" +#line 6191 "parser.c" break; case 186: /* assign_clause: ASSIGN _to _ext_clause _device assignment_name */ @@ -6154,7 +6195,7 @@ yyparse (void) { current_file->assign = cb_build_assignment_name (current_file, yyvsp[0]); } -#line 6158 "parser.c" +#line 6199 "parser.c" break; case 187: /* assign_clause: ASSIGN _to _ext_clause DISK */ @@ -6163,7 +6204,7 @@ yyparse (void) current_file->fileid_assign = 1; current_file->assign = cb_build_assignment_name (current_file, cb_build_reference ("DISK")); } -#line 6167 "parser.c" +#line 6208 "parser.c" break; case 188: /* assign_clause: ASSIGN _to _ext_clause PRINTER */ @@ -6172,13 +6213,13 @@ yyparse (void) current_file->fileid_assign = 1; current_file->assign = cb_build_assignment_name (current_file, cb_build_reference ("PRINTER")); } -#line 6176 "parser.c" +#line 6217 "parser.c" break; case 191: /* _device: PRINTER */ #line 1745 "parser.y" { current_file->organization = COB_ORG_LINE_SEQUENTIAL; } -#line 6182 "parser.c" +#line 6223 "parser.c" break; case 193: /* _ext_clause: EXTERNAL */ @@ -6186,7 +6227,7 @@ yyparse (void) { current_file->external_assign = 1; } -#line 6190 "parser.c" +#line 6231 "parser.c" break; case 194: /* _ext_clause: DYNAMIC */ @@ -6194,7 +6235,7 @@ yyparse (void) { current_file->external_assign = 0; } -#line 6198 "parser.c" +#line 6239 "parser.c" break; case 196: /* assignment_name: DISPLAY */ @@ -6205,7 +6246,7 @@ yyparse (void) s = "$#@DUMMY@#$"; yyval = cb_build_alphanumeric_literal ((unsigned char *)s, strlen (s)); } -#line 6209 "parser.c" +#line 6250 "parser.c" break; case 197: /* assignment_name: _literal assignment_device_name_list */ @@ -6226,37 +6267,37 @@ yyparse (void) yyval = yyvsp[-1]; } } -#line 6230 "parser.c" +#line 6271 "parser.c" break; case 198: /* assignment_device_name_list: qualified_word */ #line 1788 "parser.y" { yyval = cb_list_init (yyvsp[0]); } -#line 6236 "parser.c" +#line 6277 "parser.c" break; case 199: /* assignment_device_name_list: assignment_device_name_list qualified_word */ #line 1789 "parser.y" { yyval = cb_list_add (yyvsp[-1], yyvsp[0]); } -#line 6242 "parser.c" +#line 6283 "parser.c" break; case 201: /* access_mode: SEQUENTIAL */ #line 1799 "parser.y" { current_file->access_mode = COB_ACCESS_SEQUENTIAL; } -#line 6248 "parser.c" +#line 6289 "parser.c" break; case 202: /* access_mode: DYNAMIC */ #line 1800 "parser.y" { current_file->access_mode = COB_ACCESS_DYNAMIC; } -#line 6254 "parser.c" +#line 6295 "parser.c" break; case 203: /* access_mode: RANDOM */ #line 1801 "parser.y" { current_file->access_mode = COB_ACCESS_RANDOM; } -#line 6260 "parser.c" +#line 6301 "parser.c" break; case 204: /* alternative_record_key_clause: ALTERNATE RECORD _key _is reference flag_duplicates */ @@ -6280,7 +6321,7 @@ yyparse (void) l->next = p; } } -#line 6284 "parser.c" +#line 6325 "parser.c" break; case 205: /* alternative_record_key_clause: ALTERNATE RECORD _key _is reference key_is_eq split_key_list flag_duplicates */ @@ -6324,7 +6365,7 @@ yyparse (void) } } } -#line 6328 "parser.c" +#line 6369 "parser.c" break; case 206: /* $@16: %empty */ @@ -6332,7 +6373,7 @@ yyparse (void) { key_component_list = NULL; } -#line 6336 "parser.c" +#line 6377 "parser.c" break; case 209: /* split_key: reference */ @@ -6349,25 +6390,25 @@ yyparse (void) c->next = comp; } } -#line 6353 "parser.c" +#line 6394 "parser.c" break; case 210: /* key_is_eq: %empty */ #line 1895 "parser.y" { yyval = NULL; } -#line 6359 "parser.c" +#line 6400 "parser.c" break; case 211: /* key_is_eq: SOURCE _is */ #line 1896 "parser.y" { yyval = cb_int1; } -#line 6365 "parser.c" +#line 6406 "parser.c" break; case 212: /* key_is_eq: '=' */ #line 1897 "parser.y" { yyval = cb_int('='); } -#line 6371 "parser.c" +#line 6412 "parser.c" break; case 213: /* collating_sequence_clause: coll_sequence _is "Identifier" */ @@ -6375,7 +6416,7 @@ yyparse (void) { PENDING ("COLLATING SEQUENCE"); } -#line 6379 "parser.c" +#line 6420 "parser.c" break; case 214: /* file_status_clause: file_or_sort STATUS _is reference opt_reference */ @@ -6386,25 +6427,25 @@ yyparse (void) PENDING ("2nd FILE STATUS"); } } -#line 6390 "parser.c" +#line 6431 "parser.c" break; case 219: /* lock_mode: MANUAL lock_with */ #line 1935 "parser.y" { current_file->lock_mode = COB_LOCK_MANUAL; } -#line 6396 "parser.c" +#line 6437 "parser.c" break; case 220: /* lock_mode: AUTOMATIC lock_with */ #line 1936 "parser.y" { current_file->lock_mode = COB_LOCK_AUTOMATIC; } -#line 6402 "parser.c" +#line 6443 "parser.c" break; case 221: /* lock_mode: EXCLUSIVE */ #line 1937 "parser.y" { current_file->lock_mode = COB_LOCK_EXCLUSIVE; } -#line 6408 "parser.c" +#line 6449 "parser.c" break; case 224: /* lock_with: WITH LOCK ON MULTIPLE lock_records */ @@ -6412,13 +6453,13 @@ yyparse (void) { current_file->lock_mode |= COB_LOCK_MULTIPLE; } -#line 6416 "parser.c" +#line 6457 "parser.c" break; case 225: /* lock_with: WITH ROLLBACK */ #line 1946 "parser.y" { PENDING ("WITH ROLLBACK"); } -#line 6422 "parser.c" +#line 6463 "parser.c" break; case 230: /* organization: INDEXED */ @@ -6431,7 +6472,7 @@ yyparse (void) organized_seen = 1; } } -#line 6435 "parser.c" +#line 6476 "parser.c" break; case 231: /* organization: RECORD _binary SEQUENTIAL */ @@ -6444,7 +6485,7 @@ yyparse (void) organized_seen = 1; } } -#line 6448 "parser.c" +#line 6489 "parser.c" break; case 232: /* organization: SEQUENTIAL */ @@ -6457,7 +6498,7 @@ yyparse (void) organized_seen = 1; } } -#line 6461 "parser.c" +#line 6502 "parser.c" break; case 233: /* organization: RELATIVE */ @@ -6470,7 +6511,7 @@ yyparse (void) organized_seen = 1; } } -#line 6474 "parser.c" +#line 6515 "parser.c" break; case 234: /* organization: LINE SEQUENTIAL */ @@ -6483,7 +6524,7 @@ yyparse (void) organized_seen = 1; } } -#line 6487 "parser.c" +#line 6528 "parser.c" break; case 235: /* padding_character_clause: PADDING _character _is reference_or_literal */ @@ -6491,13 +6532,13 @@ yyparse (void) { cb_verify (cb_padding_character_clause, "PADDING CHARACTER"); } -#line 6495 "parser.c" +#line 6536 "parser.c" break; case 236: /* record_delimiter_clause: RECORD DELIMITER _is "STANDARD-1" */ #line 2023 "parser.y" { /* ignored */ } -#line 6501 "parser.c" +#line 6542 "parser.c" break; case 237: /* record_key_clause: RECORD _key _is reference flag_duplicates */ @@ -6510,7 +6551,7 @@ yyparse (void) current_file->key = yyvsp[-1]; } -#line 6514 "parser.c" +#line 6555 "parser.c" break; case 238: /* record_key_clause: RECORD _key _is reference key_is_eq split_key_list flag_duplicates */ @@ -6546,55 +6587,55 @@ yyparse (void) current_file->component_list = key_component_list; } } -#line 6550 "parser.c" +#line 6591 "parser.c" break; case 239: /* relative_key_clause: RELATIVE _key _is reference */ #line 2077 "parser.y" { current_file->key = yyvsp[0]; } -#line 6556 "parser.c" +#line 6597 "parser.c" break; case 240: /* reserve_clause: RESERVE integer _area */ #line 2084 "parser.y" { /* ignored */ } -#line 6562 "parser.c" +#line 6603 "parser.c" break; case 241: /* reserve_clause: RESERVE NO */ #line 2085 "parser.y" { /* ignored */ } -#line 6568 "parser.c" +#line 6609 "parser.c" break; case 242: /* sharing_clause: SHARING _with sharing_option */ #line 2092 "parser.y" { current_file->sharing = yyvsp[0]; } -#line 6574 "parser.c" +#line 6615 "parser.c" break; case 243: /* sharing_option: ALL _other */ #line 2096 "parser.y" { yyval = NULL; PENDING ("SHARING ALL OTHER"); } -#line 6580 "parser.c" +#line 6621 "parser.c" break; case 244: /* sharing_option: NO _other */ #line 2097 "parser.y" { yyval = cb_int1; } -#line 6586 "parser.c" +#line 6627 "parser.c" break; case 245: /* sharing_option: READ ONLY */ #line 2098 "parser.y" { yyval = cb_int0; } -#line 6592 "parser.c" +#line 6633 "parser.c" break; case 246: /* nominal_key_clause: NOMINAL _key _is reference */ #line 2104 "parser.y" { PENDING ("NOMINAL KEY"); } -#line 6598 "parser.c" +#line 6639 "parser.c" break; case 257: /* same_clause: SAME same_option _area _for file_name_list */ @@ -6620,31 +6661,31 @@ yyparse (void) break; } } -#line 6624 "parser.c" +#line 6665 "parser.c" break; case 258: /* same_option: %empty */ #line 2159 "parser.y" { yyval = cb_int0; } -#line 6630 "parser.c" +#line 6671 "parser.c" break; case 259: /* same_option: RECORD */ #line 2160 "parser.y" { yyval = cb_int1; } -#line 6636 "parser.c" +#line 6677 "parser.c" break; case 260: /* same_option: SORT */ #line 2161 "parser.y" { yyval = cb_int2; } -#line 6642 "parser.c" +#line 6683 "parser.c" break; case 261: /* same_option: "SORT-MERGE" */ #line 2162 "parser.y" { yyval = cb_int2; } -#line 6648 "parser.c" +#line 6689 "parser.c" break; case 262: /* multiple_file_tape_clause: MULTIPLE _file _tape _contains multiple_file_list */ @@ -6652,13 +6693,13 @@ yyparse (void) { cb_verify (cb_multiple_file_tape_clause, "MULTIPLE FILE TAPE"); } -#line 6656 "parser.c" +#line 6697 "parser.c" break; case 265: /* multiple_file: file_name multiple_file_position */ #line 2180 "parser.y" { } -#line 6662 "parser.c" +#line 6703 "parser.c" break; case 271: /* apply_clause: APPLY "COMMITMENT-CONTROL" _on reference_list */ @@ -6666,7 +6707,7 @@ yyparse (void) { PENDING ("APPLY COMMITMENT-CONTROL"); } -#line 6670 "parser.c" +#line 6711 "parser.c" break; case 272: /* apply_clause: APPLY "CYL-OVERFLOW" _of "Literal" TRACKS ON reference_list */ @@ -6674,7 +6715,7 @@ yyparse (void) { PENDING ("APPLY CYL-OVERFLOW"); } -#line 6678 "parser.c" +#line 6719 "parser.c" break; case 273: /* apply_clause: APPLY "CORE-INDEX" TO reference ON reference_list */ @@ -6682,7 +6723,7 @@ yyparse (void) { PENDING ("APPLY CORE-INDEX"); } -#line 6686 "parser.c" +#line 6727 "parser.c" break; case 274: /* apply_clause: APPLY "FORMS-OVERLAY" TO reference ON reference_list */ @@ -6690,7 +6731,7 @@ yyparse (void) { PENDING ("APPLY FORMS-OVERLAY"); } -#line 6694 "parser.c" +#line 6735 "parser.c" break; case 275: /* apply_clause: APPLY "CLOSE-NOFEED" ON reference_list */ @@ -6698,13 +6739,13 @@ yyparse (void) { PENDING ("APPLY CLOSE-NOFEED"); } -#line 6702 "parser.c" +#line 6743 "parser.c" break; case 279: /* $@17: %empty */ #line 2238 "parser.y" { current_storage = CB_STORAGE_FILE; } -#line 6708 "parser.c" +#line 6749 "parser.c" break; case 281: /* $@18: %empty */ @@ -6718,7 +6759,7 @@ yyparse (void) } current_storage = CB_STORAGE_FILE; } -#line 6722 "parser.c" +#line 6763 "parser.c" break; case 285: /* file_description: file_type file_description_entry record_description_list */ @@ -6730,7 +6771,7 @@ yyparse (void) cb_error (_("RECORD description missing or invalid")); } } -#line 6734 "parser.c" +#line 6775 "parser.c" break; case 286: /* file_description_sequence_without_type: file_description_entry record_description_list */ @@ -6742,19 +6783,19 @@ yyparse (void) cb_error (_("RECORD description missing or invalid")); } } -#line 6746 "parser.c" +#line 6787 "parser.c" break; case 288: /* file_type: FD */ #line 2283 "parser.y" { yyval = cb_int0; } -#line 6752 "parser.c" +#line 6793 "parser.c" break; case 289: /* file_type: SD */ #line 2284 "parser.y" { yyval = cb_int1; } -#line 6758 "parser.c" +#line 6799 "parser.c" break; case 290: /* @19: %empty */ @@ -6769,7 +6810,7 @@ yyparse (void) current_file->organization = COB_ORG_SORT; } } -#line 6773 "parser.c" +#line 6814 "parser.c" break; case 291: /* file_description_entry: file_name @19 file_description_clause_sequence '.' */ @@ -6778,7 +6819,7 @@ yyparse (void) /* Shut up bison */ dummy_tree = yyvsp[-2]; } -#line 6782 "parser.c" +#line 6823 "parser.c" break; case 294: /* file_description_clause: _is EXTERNAL */ @@ -6789,7 +6830,7 @@ yyparse (void) } current_file->external = 1; } -#line 6793 "parser.c" +#line 6834 "parser.c" break; case 295: /* file_description_clause: _is GLOBAL */ @@ -6800,13 +6841,13 @@ yyparse (void) } current_file->global = 1; } -#line 6804 "parser.c" +#line 6845 "parser.c" break; case 306: /* block_contains_clause: BLOCK _contains integer opt_to_integer _records_or_characters */ #line 2347 "parser.y" { /* ignored */ } -#line 6810 "parser.c" +#line 6851 "parser.c" break; case 310: /* record_clause: RECORD _contains integer _characters */ @@ -6822,7 +6863,7 @@ yyparse (void) } } } -#line 6826 "parser.c" +#line 6867 "parser.c" break; case 311: /* record_clause: RECORD _contains integer TO integer _characters */ @@ -6851,7 +6892,7 @@ yyparse (void) } } } -#line 6855 "parser.c" +#line 6896 "parser.c" break; case 312: /* record_clause: RECORD _is VARYING _in _size opt_from_integer opt_to_integer _characters record_depending */ @@ -6876,7 +6917,7 @@ yyparse (void) cb_error (_("RECORD clause invalid")); } } -#line 6880 "parser.c" +#line 6921 "parser.c" break; case 314: /* record_depending: DEPENDING _on reference */ @@ -6884,31 +6925,31 @@ yyparse (void) { current_file->record_depending = yyvsp[0]; } -#line 6888 "parser.c" +#line 6929 "parser.c" break; case 315: /* opt_from_integer: %empty */ #line 2425 "parser.y" { yyval = NULL; } -#line 6894 "parser.c" +#line 6935 "parser.c" break; case 316: /* opt_from_integer: _from integer */ #line 2426 "parser.y" { yyval = yyvsp[0]; } -#line 6900 "parser.c" +#line 6941 "parser.c" break; case 317: /* opt_to_integer: %empty */ #line 2430 "parser.y" { yyval = NULL; } -#line 6906 "parser.c" +#line 6947 "parser.c" break; case 318: /* opt_to_integer: TO integer */ #line 2431 "parser.y" { yyval = yyvsp[0]; } -#line 6912 "parser.c" +#line 6953 "parser.c" break; case 319: /* label_records_clause: LABEL records label_option */ @@ -6916,7 +6957,7 @@ yyparse (void) { cb_verify (cb_label_records_clause, "LABEL RECORDS"); } -#line 6920 "parser.c" +#line 6961 "parser.c" break; case 322: /* value_of_clause: VALUE OF "Identifier" _is valueof_name */ @@ -6924,7 +6965,7 @@ yyparse (void) { cb_verify (cb_value_of_clause, "VALUE OF"); } -#line 6928 "parser.c" +#line 6969 "parser.c" break; case 323: /* value_of_clause: VALUE OF "FILE-ID" _is valueof_name */ @@ -6934,7 +6975,7 @@ yyparse (void) current_file->assign = cb_build_assignment_name (current_file, yyvsp[0]); } } -#line 6938 "parser.c" +#line 6979 "parser.c" break; case 326: /* data_records_clause: DATA records no_reference_list */ @@ -6942,7 +6983,7 @@ yyparse (void) { cb_verify (cb_data_records_clause, "DATA RECORDS"); } -#line 6946 "parser.c" +#line 6987 "parser.c" break; case 327: /* linage_clause: LINAGE _is reference_or_literal _lines linage_sequence */ @@ -6961,7 +7002,7 @@ yyparse (void) current_linage++; } } -#line 6965 "parser.c" +#line 7006 "parser.c" break; case 333: /* linage_footing: _with FOOTING _at reference_or_literal _lines */ @@ -6969,7 +7010,7 @@ yyparse (void) { current_file->latfoot = yyvsp[-1]; } -#line 6973 "parser.c" +#line 7014 "parser.c" break; case 334: /* linage_top: _at TOP reference_or_literal _lines */ @@ -6977,7 +7018,7 @@ yyparse (void) { current_file->lattop = yyvsp[-1]; } -#line 6981 "parser.c" +#line 7022 "parser.c" break; case 335: /* linage_bottom: _at BOTTOM reference_or_literal */ @@ -6985,13 +7026,13 @@ yyparse (void) { current_file->latbot = yyvsp[0]; } -#line 6989 "parser.c" +#line 7030 "parser.c" break; case 336: /* recording_mode_clause: RECORDING _mode _is "Identifier" */ #line 2536 "parser.y" { /* ignore */ } -#line 6995 "parser.c" +#line 7036 "parser.c" break; case 337: /* code_set_clause: "CODE-SET" _is "Identifier" */ @@ -7008,7 +7049,7 @@ yyparse (void) } } } -#line 7012 "parser.c" +#line 7053 "parser.c" break; case 338: /* report_clause: REPORT _is report_name */ @@ -7016,7 +7057,7 @@ yyparse (void) { cb_warning (_("file descriptor REPORT IS")); } -#line 7020 "parser.c" +#line 7061 "parser.c" break; case 339: /* report_clause: REPORTS _are report_name */ @@ -7024,13 +7065,13 @@ yyparse (void) { cb_warning (_("file descriptor REPORTS ARE")); } -#line 7028 "parser.c" +#line 7069 "parser.c" break; case 341: /* $@20: %empty */ #line 2577 "parser.y" { current_storage = CB_STORAGE_WORKING; } -#line 7034 "parser.c" +#line 7075 "parser.c" break; case 342: /* working_storage_section: "WORKING-STORAGE" SECTION '.' $@20 record_description_list */ @@ -7041,19 +7082,19 @@ yyparse (void) cb_field_add (current_program->working_storage, CB_FIELD (yyvsp[0])); } } -#line 7045 "parser.c" +#line 7086 "parser.c" break; case 343: /* record_description_list: %empty */ #line 2588 "parser.y" { yyval = NULL; } -#line 7051 "parser.c" +#line 7092 "parser.c" break; case 344: /* record_description_list: record_description_list_1 */ #line 2589 "parser.y" { yyval = yyvsp[0]; } -#line 7057 "parser.c" +#line 7098 "parser.c" break; case 345: /* $@21: %empty */ @@ -7063,7 +7104,7 @@ yyparse (void) description_field = NULL; cb_clear_real_field (); } -#line 7067 "parser.c" +#line 7108 "parser.c" break; case 346: /* record_description_list_1: $@21 record_description_list_2 */ @@ -7076,7 +7117,7 @@ yyparse (void) } yyval = CB_TREE (description_field); } -#line 7080 "parser.c" +#line 7121 "parser.c" break; case 351: /* $@22: %empty */ @@ -7092,7 +7133,7 @@ yyparse (void) current_field = CB_FIELD (x); } } -#line 7096 "parser.c" +#line 7137 "parser.c" break; case 352: /* data_description: level_number entry_name $@22 data_description_clause_sequence _maybe_next_level_number */ @@ -7109,7 +7150,7 @@ yyparse (void) description_field = current_field; } } -#line 7113 "parser.c" +#line 7154 "parser.c" break; case 353: /* $@23: %empty */ @@ -7125,7 +7166,7 @@ yyparse (void) current_field = CB_FIELD (x); } } -#line 7129 "parser.c" +#line 7170 "parser.c" break; case 354: /* data_description: level_number_88 entry_name $@23 value_cond_clause */ @@ -7140,7 +7181,7 @@ yyparse (void) } } -#line 7144 "parser.c" +#line 7185 "parser.c" break; case 358: /* _maybe_next_level_number: "Literal" */ @@ -7162,7 +7203,7 @@ yyparse (void) cb_unget_token (LITERAL, yyvsp[0]); } } -#line 7166 "parser.c" +#line 7207 "parser.c" break; case 359: /* entry_name: %empty */ @@ -7172,7 +7213,7 @@ yyparse (void) qualifier = NULL; non_const_word = 0; } -#line 7176 "parser.c" +#line 7217 "parser.c" break; case 360: /* entry_name: FILLER */ @@ -7182,7 +7223,7 @@ yyparse (void) qualifier = NULL; non_const_word = 0; } -#line 7186 "parser.c" +#line 7227 "parser.c" break; case 361: /* entry_name: "Identifier" */ @@ -7192,7 +7233,7 @@ yyparse (void) qualifier = yyvsp[0]; non_const_word = 0; } -#line 7196 "parser.c" +#line 7237 "parser.c" break; case 362: /* const_name: "Identifier" */ @@ -7202,7 +7243,7 @@ yyparse (void) qualifier = yyvsp[0]; non_const_word = 0; } -#line 7206 "parser.c" +#line 7247 "parser.c" break; case 364: /* const_global: _is GLOBAL */ @@ -7211,25 +7252,25 @@ yyparse (void) current_field->flag_is_global = 1; cb_error (_("CONSTANT with GLOBAL clause is not yet supported")); } -#line 7215 "parser.c" +#line 7256 "parser.c" break; case 365: /* lit_or_length: literal */ #line 2741 "parser.y" { yyval = yyvsp[0]; } -#line 7221 "parser.c" +#line 7262 "parser.c" break; case 366: /* lit_or_length: LENGTH _of identifier_1 */ #line 2742 "parser.y" { yyval = cb_build_const_length (yyvsp[0]); } -#line 7227 "parser.c" +#line 7268 "parser.c" break; case 367: /* lit_or_length: "BYTE-LENGTH" _of identifier_1 */ #line 2743 "parser.y" { yyval = cb_build_const_length (yyvsp[0]); } -#line 7233 "parser.c" +#line 7274 "parser.c" break; case 368: /* constant_entry: level_number const_name CONSTANT const_global _as lit_or_length */ @@ -7249,7 +7290,7 @@ yyparse (void) /* Ignore return value */ cb_validate_78_item (CB_FIELD (x)); } -#line 7253 "parser.c" +#line 7294 "parser.c" break; case 369: /* data_description_clause_sequence: %empty */ @@ -7258,7 +7299,7 @@ yyparse (void) /* required to check redefines */ yyval = NULL; } -#line 7262 "parser.c" +#line 7303 "parser.c" break; case 370: /* data_description_clause_sequence: data_description_clause_sequence data_description_clause */ @@ -7267,7 +7308,7 @@ yyparse (void) /* required to check redefines */ yyval = cb_true; } -#line 7271 "parser.c" +#line 7312 "parser.c" break; case 386: /* redefines_clause: REDEFINES identifier_1 */ @@ -7287,7 +7328,7 @@ yyparse (void) YYERROR; } } -#line 7291 "parser.c" +#line 7332 "parser.c" break; case 387: /* external_clause: _is EXTERNAL as_extname */ @@ -7310,13 +7351,13 @@ yyparse (void) has_external = 1; } } -#line 7314 "parser.c" +#line 7355 "parser.c" break; case 388: /* as_extname: %empty */ #line 2845 "parser.y" { current_field->ename = NULL; } -#line 7320 "parser.c" +#line 7361 "parser.c" break; case 389: /* as_extname: AS "Literal" */ @@ -7327,7 +7368,7 @@ yyparse (void) x = CB_FIELD(cb_build_field (cb_build_reference ((char *)(CB_LITERAL (yyvsp[0])->data)))); current_field->ename = x->name; } -#line 7331 "parser.c" +#line 7372 "parser.c" break; case 390: /* global_clause: _is GLOBAL */ @@ -7345,209 +7386,215 @@ yyparse (void) current_field->flag_is_global = 1; } } -#line 7349 "parser.c" +#line 7390 "parser.c" break; case 391: /* picture_clause: PICTURE */ #line 2878 "parser.y" { current_field->pic = CB_PICTURE (yyvsp[0]); } -#line 7355 "parser.c" +#line 7396 "parser.c" break; case 394: /* usage: BINARY */ #line 2890 "parser.y" { current_field->usage = CB_USAGE_BINARY; } -#line 7361 "parser.c" +#line 7402 "parser.c" break; case 395: /* usage: COMP */ #line 2891 "parser.y" { current_field->usage = CB_USAGE_BINARY; } -#line 7367 "parser.c" +#line 7408 "parser.c" break; case 396: /* usage: "COMP-1" */ -#line 2892 "parser.y" - { current_field->usage = CB_USAGE_FLOAT; } -#line 7373 "parser.c" +#line 2893 "parser.y" +{ + current_field->usage = CB_USAGE_FLOAT; + cb_error (_("COMP-1 not implemented")); +} +#line 7417 "parser.c" break; case 397: /* usage: "COMP-2" */ -#line 2893 "parser.y" - { current_field->usage = CB_USAGE_DOUBLE; } -#line 7379 "parser.c" +#line 2898 "parser.y" +{ + current_field->usage = CB_USAGE_DOUBLE; + cb_error (_("COMP-2 not implemented")); +} +#line 7426 "parser.c" break; case 398: /* usage: "COMP-3" */ -#line 2894 "parser.y" +#line 2902 "parser.y" { current_field->usage = CB_USAGE_PACKED; } -#line 7385 "parser.c" +#line 7432 "parser.c" break; case 399: /* usage: "COMP-4" */ -#line 2895 "parser.y" +#line 2903 "parser.y" { current_field->usage = CB_USAGE_BINARY; } -#line 7391 "parser.c" +#line 7438 "parser.c" break; case 400: /* usage: "COMP-5" */ -#line 2896 "parser.y" +#line 2904 "parser.y" { current_field->usage = CB_USAGE_COMP_5; } -#line 7397 "parser.c" +#line 7444 "parser.c" break; case 401: /* usage: "COMP-X" */ -#line 2897 "parser.y" +#line 2905 "parser.y" { current_field->usage = CB_USAGE_COMP_X; } -#line 7403 "parser.c" +#line 7450 "parser.c" break; case 402: /* usage: DISPLAY */ -#line 2898 "parser.y" +#line 2906 "parser.y" { current_field->usage = CB_USAGE_DISPLAY; } -#line 7409 "parser.c" +#line 7456 "parser.c" break; case 403: /* usage: INDEX */ -#line 2899 "parser.y" +#line 2907 "parser.y" { current_field->usage = CB_USAGE_INDEX; } -#line 7415 "parser.c" +#line 7462 "parser.c" break; case 404: /* usage: "PACKED-DECIMAL" */ -#line 2900 "parser.y" +#line 2908 "parser.y" { current_field->usage = CB_USAGE_PACKED; } -#line 7421 "parser.c" +#line 7468 "parser.c" break; case 405: /* usage: POINTER */ -#line 2902 "parser.y" +#line 2910 "parser.y" { current_field->usage = CB_USAGE_POINTER; current_field->flag_is_pointer = 1; } -#line 7430 "parser.c" +#line 7477 "parser.c" break; case 406: /* usage: "PROGRAM-POINTER" */ -#line 2907 "parser.y" +#line 2915 "parser.y" { current_field->usage = CB_USAGE_PROGRAM_POINTER; current_field->flag_is_pointer = 1; } -#line 7439 "parser.c" +#line 7486 "parser.c" break; case 407: /* usage: "SIGNED-SHORT" */ -#line 2911 "parser.y" +#line 2919 "parser.y" { current_field->usage = CB_USAGE_SIGNED_SHORT; } -#line 7445 "parser.c" +#line 7492 "parser.c" break; case 408: /* usage: "SIGNED-INT" */ -#line 2912 "parser.y" +#line 2920 "parser.y" { current_field->usage = CB_USAGE_SIGNED_INT; } -#line 7451 "parser.c" +#line 7498 "parser.c" break; case 409: /* usage: "SIGNED-LONG" */ -#line 2913 "parser.y" +#line 2921 "parser.y" { current_field->usage = CB_USAGE_SIGNED_LONG; } -#line 7457 "parser.c" +#line 7504 "parser.c" break; case 410: /* usage: "UNSIGNED-SHORT" */ -#line 2914 "parser.y" +#line 2922 "parser.y" { current_field->usage = CB_USAGE_UNSIGNED_SHORT; } -#line 7463 "parser.c" +#line 7510 "parser.c" break; case 411: /* usage: "UNSIGNED-INT" */ -#line 2915 "parser.y" +#line 2923 "parser.y" { current_field->usage = CB_USAGE_UNSIGNED_INT; } -#line 7469 "parser.c" +#line 7516 "parser.c" break; case 412: /* usage: "UNSIGNED-LONG" */ -#line 2916 "parser.y" +#line 2924 "parser.y" { current_field->usage = CB_USAGE_UNSIGNED_LONG; } -#line 7475 "parser.c" +#line 7522 "parser.c" break; case 413: /* usage: "BINARY-CHAR" SIGNED */ -#line 2917 "parser.y" +#line 2925 "parser.y" { current_field->usage = CB_USAGE_SIGNED_CHAR; } -#line 7481 "parser.c" +#line 7528 "parser.c" break; case 414: /* usage: "BINARY-CHAR" UNSIGNED */ -#line 2918 "parser.y" +#line 2926 "parser.y" { current_field->usage = CB_USAGE_UNSIGNED_CHAR; } -#line 7487 "parser.c" +#line 7534 "parser.c" break; case 415: /* usage: "BINARY-CHAR" */ -#line 2919 "parser.y" +#line 2927 "parser.y" { current_field->usage = CB_USAGE_SIGNED_CHAR; } -#line 7493 "parser.c" +#line 7540 "parser.c" break; case 416: /* usage: "BINARY-SHORT" SIGNED */ -#line 2920 "parser.y" +#line 2928 "parser.y" { current_field->usage = CB_USAGE_SIGNED_SHORT; } -#line 7499 "parser.c" +#line 7546 "parser.c" break; case 417: /* usage: "BINARY-SHORT" UNSIGNED */ -#line 2921 "parser.y" +#line 2929 "parser.y" { current_field->usage = CB_USAGE_UNSIGNED_SHORT; } -#line 7505 "parser.c" +#line 7552 "parser.c" break; case 418: /* usage: "BINARY-SHORT" */ -#line 2922 "parser.y" +#line 2930 "parser.y" { current_field->usage = CB_USAGE_SIGNED_SHORT; } -#line 7511 "parser.c" +#line 7558 "parser.c" break; case 419: /* usage: "BINARY-LONG" SIGNED */ -#line 2923 "parser.y" +#line 2931 "parser.y" { current_field->usage = CB_USAGE_SIGNED_INT; } -#line 7517 "parser.c" +#line 7564 "parser.c" break; case 420: /* usage: "BINARY-LONG" UNSIGNED */ -#line 2924 "parser.y" +#line 2932 "parser.y" { current_field->usage = CB_USAGE_UNSIGNED_INT; } -#line 7523 "parser.c" +#line 7570 "parser.c" break; case 421: /* usage: "BINARY-LONG" */ -#line 2925 "parser.y" +#line 2933 "parser.y" { current_field->usage = CB_USAGE_SIGNED_INT; } -#line 7529 "parser.c" +#line 7576 "parser.c" break; case 422: /* usage: "BINARY-DOUBLE" SIGNED */ -#line 2926 "parser.y" +#line 2934 "parser.y" { current_field->usage = CB_USAGE_SIGNED_LONG; } -#line 7535 "parser.c" +#line 7582 "parser.c" break; case 423: /* usage: "BINARY-DOUBLE" UNSIGNED */ -#line 2927 "parser.y" +#line 2935 "parser.y" { current_field->usage = CB_USAGE_UNSIGNED_LONG; } -#line 7541 "parser.c" +#line 7588 "parser.c" break; case 424: /* usage: "BINARY-DOUBLE" */ -#line 2928 "parser.y" +#line 2936 "parser.y" { current_field->usage = CB_USAGE_SIGNED_LONG; } -#line 7547 "parser.c" +#line 7594 "parser.c" break; case 425: /* usage: "BINARY-C-LONG" SIGNED */ -#line 2930 "parser.y" +#line 2938 "parser.y" { if (sizeof(long) == 4) { current_field->usage = CB_USAGE_SIGNED_INT; @@ -7555,11 +7602,11 @@ yyparse (void) current_field->usage = CB_USAGE_SIGNED_LONG; } } -#line 7559 "parser.c" +#line 7606 "parser.c" break; case 426: /* usage: "BINARY-C-LONG" UNSIGNED */ -#line 2938 "parser.y" +#line 2946 "parser.y" { if (sizeof(long) == 4) { current_field->usage = CB_USAGE_UNSIGNED_INT; @@ -7567,11 +7614,11 @@ yyparse (void) current_field->usage = CB_USAGE_UNSIGNED_LONG; } } -#line 7571 "parser.c" +#line 7618 "parser.c" break; case 427: /* usage: "BINARY-C-LONG" */ -#line 2946 "parser.y" +#line 2954 "parser.y" { if (sizeof(long) == 4) { current_field->usage = CB_USAGE_SIGNED_INT; @@ -7579,35 +7626,35 @@ yyparse (void) current_field->usage = CB_USAGE_SIGNED_LONG; } } -#line 7583 "parser.c" +#line 7630 "parser.c" break; case 428: /* usage: NATIONAL */ -#line 2953 "parser.y" +#line 2961 "parser.y" { PENDING ("USAGE NATIONAL");} -#line 7589 "parser.c" +#line 7636 "parser.c" break; case 429: /* sign_clause: _sign_is LEADING flag_separate */ -#line 2961 "parser.y" +#line 2969 "parser.y" { current_field->flag_sign_separate = CB_INTEGER (yyvsp[0])->val; current_field->flag_sign_leading = 1; } -#line 7598 "parser.c" +#line 7645 "parser.c" break; case 430: /* sign_clause: _sign_is TRAILING flag_separate */ -#line 2966 "parser.y" +#line 2974 "parser.y" { current_field->flag_sign_separate = CB_INTEGER (yyvsp[0])->val; current_field->flag_sign_leading = 0; } -#line 7607 "parser.c" +#line 7654 "parser.c" break; case 434: /* occurs_clause: OCCURS integer occurs_to_integer _times occurs_depending occurs_key_spec */ -#line 2983 "parser.y" +#line 2991 "parser.y" { if (current_field->occurs_depending && !(yyvsp[-3])) { cb_verify (cb_odo_without_to, "ODO without TO clause"); @@ -7620,31 +7667,31 @@ yyparse (void) } current_field->flag_occurs = 1; } -#line 7624 "parser.c" +#line 7671 "parser.c" break; case 435: /* occurs_to_integer: %empty */ -#line 2998 "parser.y" +#line 3006 "parser.y" { yyval = NULL; } -#line 7630 "parser.c" +#line 7677 "parser.c" break; case 436: /* occurs_to_integer: TO integer */ -#line 2999 "parser.y" +#line 3007 "parser.y" { yyval = yyvsp[0]; } -#line 7636 "parser.c" +#line 7683 "parser.c" break; case 438: /* occurs_depending: DEPENDING _on reference */ -#line 3004 "parser.y" +#line 3012 "parser.y" { current_field->occurs_depending = yyvsp[0]; } -#line 7644 "parser.c" +#line 7691 "parser.c" break; case 441: /* occurs_keys: occurs_key_list */ -#line 3013 "parser.y" +#line 3021 "parser.y" { if (yyvsp[0]) { cb_tree l; @@ -7665,11 +7712,11 @@ yyparse (void) current_field->nkeys = nkeys; } } -#line 7669 "parser.c" +#line 7716 "parser.c" break; case 442: /* occurs_key: ascending_or_descending _key _is reference_list */ -#line 3037 "parser.y" +#line 3045 "parser.y" { cb_tree l; @@ -7682,81 +7729,81 @@ yyparse (void) } yyval = yyvsp[0]; } -#line 7686 "parser.c" +#line 7733 "parser.c" break; case 443: /* occurs_key_list: occurs_key */ -#line 3052 "parser.y" +#line 3060 "parser.y" { yyval = yyvsp[0]; } -#line 7692 "parser.c" +#line 7739 "parser.c" break; case 444: /* occurs_key_list: occurs_key_list occurs_key */ -#line 3053 "parser.y" +#line 3061 "parser.y" { yyval = cb_list_append (yyvsp[-1], yyvsp[0]); } -#line 7698 "parser.c" +#line 7745 "parser.c" break; case 445: /* ascending_or_descending: ASCENDING */ -#line 3057 "parser.y" +#line 3065 "parser.y" { yyval = cb_int (COB_ASCENDING); } -#line 7704 "parser.c" +#line 7751 "parser.c" break; case 446: /* ascending_or_descending: DESCENDING */ -#line 3058 "parser.y" +#line 3066 "parser.y" { yyval = cb_int (COB_DESCENDING); } -#line 7710 "parser.c" +#line 7757 "parser.c" break; case 449: /* occurs_indexed: INDEXED _by occurs_index_list */ -#line 3065 "parser.y" +#line 3073 "parser.y" { current_field->index_list = yyvsp[0]; } -#line 7718 "parser.c" +#line 7765 "parser.c" break; case 450: /* occurs_index_list: occurs_index */ -#line 3071 "parser.y" +#line 3079 "parser.y" { yyval = cb_list_init (yyvsp[0]); } -#line 7724 "parser.c" +#line 7771 "parser.c" break; case 451: /* occurs_index_list: occurs_index_list occurs_index */ -#line 3073 "parser.y" +#line 3081 "parser.y" { yyval = cb_list_add (yyvsp[-1], yyvsp[0]); } -#line 7730 "parser.c" +#line 7777 "parser.c" break; case 452: /* occurs_index: "Identifier" */ -#line 3078 "parser.y" +#line 3086 "parser.y" { yyval = cb_build_index (yyvsp[0], cb_int1, 1, current_field); } -#line 7738 "parser.c" +#line 7785 "parser.c" break; case 453: /* justified_clause: JUSTIFIED _right */ -#line 3087 "parser.y" +#line 3095 "parser.y" { current_field->flag_justified = 1; } -#line 7744 "parser.c" +#line 7791 "parser.c" break; case 454: /* synchronized_clause: SYNCHRONIZED left_or_right */ -#line 3094 "parser.y" +#line 3102 "parser.y" { current_field->flag_synchronized = 1; } -#line 7750 "parser.c" +#line 7797 "parser.c" break; case 458: /* blank_clause: BLANK _when ZERO */ -#line 3106 "parser.y" +#line 3114 "parser.y" { current_field->flag_blank_zero = 1; } -#line 7756 "parser.c" +#line 7803 "parser.c" break; case 459: /* based_clause: BASED */ -#line 3114 "parser.y" +#line 3122 "parser.y" { if (current_storage != CB_STORAGE_WORKING && current_storage != CB_STORAGE_LINKAGE && @@ -7776,58 +7823,58 @@ yyparse (void) current_field->flag_item_based = 1; } } -#line 7780 "parser.c" +#line 7827 "parser.c" break; case 460: /* value_clause: VALUE _is literal */ -#line 3138 "parser.y" +#line 3146 "parser.y" { current_field->values = cb_list_init (yyvsp[0]); } -#line 7786 "parser.c" +#line 7833 "parser.c" break; case 461: /* $@24: %empty */ -#line 3142 "parser.y" +#line 3150 "parser.y" { current_field->values = yyvsp[0]; } -#line 7792 "parser.c" +#line 7839 "parser.c" break; case 463: /* value_item_list: value_item */ -#line 3147 "parser.y" +#line 3155 "parser.y" { yyval = cb_list_init (yyvsp[0]); } -#line 7798 "parser.c" +#line 7845 "parser.c" break; case 464: /* value_item_list: value_item_list value_item */ -#line 3148 "parser.y" +#line 3156 "parser.y" { yyval = cb_list_add (yyvsp[-1], yyvsp[0]); } -#line 7804 "parser.c" +#line 7851 "parser.c" break; case 465: /* value_item: literal */ -#line 3152 "parser.y" +#line 3160 "parser.y" { yyval = yyvsp[0]; } -#line 7810 "parser.c" +#line 7857 "parser.c" break; case 466: /* value_item: literal THRU literal */ -#line 3153 "parser.y" +#line 3161 "parser.y" { yyval = cb_build_pair (yyvsp[-2], yyvsp[0]); } -#line 7816 "parser.c" +#line 7863 "parser.c" break; case 468: /* false_is: "FALSE" _is literal */ -#line 3158 "parser.y" +#line 3166 "parser.y" { if (current_field->level != 88) { cb_error (_("FALSE clause only allowed for 88 level")); } current_field->false_88 = cb_list_init (yyvsp[0]); } -#line 7827 "parser.c" +#line 7874 "parser.c" break; case 469: /* renames_clause: RENAMES qualified_word */ -#line 3171 "parser.y" +#line 3179 "parser.y" { if (cb_ref (yyvsp[0]) != cb_error_node) { if (CB_FIELD (cb_ref (yyvsp[0]))->level == 01 || @@ -7839,11 +7886,11 @@ yyparse (void) } } } -#line 7843 "parser.c" +#line 7890 "parser.c" break; case 470: /* renames_clause: RENAMES qualified_word THRU qualified_word */ -#line 3183 "parser.y" +#line 3191 "parser.y" { if (cb_ref (yyvsp[-2]) != cb_error_node && cb_ref (yyvsp[0]) != cb_error_node) { if (CB_FIELD (cb_ref (yyvsp[-2]))->level == 01 || @@ -7858,11 +7905,11 @@ yyparse (void) } } } -#line 7862 "parser.c" +#line 7909 "parser.c" break; case 471: /* any_length_clause: ANY LENGTH */ -#line 3203 "parser.y" +#line 3211 "parser.y" { if (current_field->flag_item_based) { cb_error (_("BASED and ANY LENGTH are mutually exclusive")); @@ -7870,105 +7917,105 @@ yyparse (void) current_field->flag_any_length = 1; } } -#line 7874 "parser.c" +#line 7921 "parser.c" break; case 473: /* $@25: %empty */ -#line 3218 "parser.y" +#line 3226 "parser.y" { current_storage = CB_STORAGE_LOCAL; if (current_program->nested_level) { cb_error (_("LOCAL-STORAGE not allowed in nested programs")); } } -#line 7885 "parser.c" +#line 7932 "parser.c" break; case 474: /* local_storage_section: "LOCAL-STORAGE" SECTION '.' $@25 record_description_list */ -#line 3225 "parser.y" +#line 3233 "parser.y" { if (yyvsp[0]) { current_program->local_storage = CB_FIELD (yyvsp[0]); } } -#line 7895 "parser.c" +#line 7942 "parser.c" break; case 476: /* $@26: %empty */ -#line 3238 "parser.y" +#line 3246 "parser.y" { current_storage = CB_STORAGE_LINKAGE; } -#line 7901 "parser.c" +#line 7948 "parser.c" break; case 477: /* linkage_section: LINKAGE SECTION '.' $@26 record_description_list */ -#line 3240 "parser.y" +#line 3248 "parser.y" { if (yyvsp[0]) { current_program->linkage_storage = CB_FIELD (yyvsp[0]); } } -#line 7911 "parser.c" +#line 7958 "parser.c" break; case 479: /* $@27: %empty */ -#line 3253 "parser.y" +#line 3261 "parser.y" { cb_error (_("REPORT SECTION not supported")); current_storage = CB_STORAGE_REPORT; } -#line 7920 "parser.c" +#line 7967 "parser.c" break; case 486: /* report_description_options: %empty */ -#line 3286 "parser.y" +#line 3294 "parser.y" { cb_warning (_("Report description using defaults")); } -#line 7928 "parser.c" +#line 7975 "parser.c" break; case 488: /* report_description_option: _is GLOBAL */ -#line 3294 "parser.y" +#line 3302 "parser.y" { cb_error (_("GLOBAL is not allowed with RD")); } -#line 7936 "parser.c" +#line 7983 "parser.c" break; case 497: /* identifier_list: identifier */ -#line 3317 "parser.y" +#line 3325 "parser.y" { yyval = cb_list_init (yyvsp[0]); } -#line 7942 "parser.c" +#line 7989 "parser.c" break; case 498: /* identifier_list: identifier_list identifier */ -#line 3318 "parser.y" +#line 3326 "parser.y" { yyval = cb_list_add (yyvsp[-1], yyvsp[0]); } -#line 7948 "parser.c" +#line 7995 "parser.c" break; case 520: /* report_group_option: type_clause */ -#line 3374 "parser.y" +#line 3382 "parser.y" { cb_warning (_("looking for Report line TYPE")); } -#line 7954 "parser.c" +#line 8001 "parser.c" break; case 571: /* $@28: %empty */ -#line 3479 "parser.y" +#line 3487 "parser.y" { current_storage = CB_STORAGE_SCREEN; } -#line 7960 "parser.c" +#line 8007 "parser.c" break; case 572: /* screen_section: SCREEN SECTION '.' $@28 */ -#line 3480 "parser.y" +#line 3488 "parser.y" { cb_error (_("SCREEN SECTION is not supported")); } -#line 7968 "parser.c" +#line 8015 "parser.c" break; case 574: /* $@29: %empty */ -#line 3491 "parser.y" +#line 3499 "parser.y" { current_section = NULL; current_paragraph = NULL; @@ -7978,11 +8025,11 @@ yyparse (void) cb_define_system_name ("SYSERR"); cb_set_in_procedure (); } -#line 7982 "parser.c" +#line 8029 "parser.c" break; case 575: /* $@30: %empty */ -#line 3501 "parser.y" +#line 3509 "parser.y" { if (current_program->flag_main && !current_program->flag_chained && yyvsp[-4]) { cb_error (_("Executable program requested but PROCEDURE/ENTRY has USING clause")); @@ -7992,11 +8039,11 @@ yyparse (void) emit_entry (current_program->source_name, 1, yyvsp[-4]); } } -#line 7996 "parser.c" +#line 8043 "parser.c" break; case 576: /* procedure_division: PROCEDURE DIVISION procedure_using_chaining procedure_returning '.' $@29 procedure_declaratives $@30 procedure_list */ -#line 3511 "parser.y" +#line 3519 "parser.y" { if (current_paragraph) { if (current_paragraph->exit_label) { @@ -8011,76 +8058,76 @@ yyparse (void) emit_statement (cb_build_perform_exit (current_section)); } } -#line 8015 "parser.c" +#line 8062 "parser.c" break; case 577: /* procedure_using_chaining: %empty */ -#line 3528 "parser.y" +#line 3536 "parser.y" { yyval = NULL; } -#line 8021 "parser.c" +#line 8068 "parser.c" break; case 578: /* $@31: %empty */ -#line 3530 "parser.y" +#line 3538 "parser.y" { call_mode = CB_CALL_BY_REFERENCE; size_mode = CB_SIZE_4; } -#line 8030 "parser.c" +#line 8077 "parser.c" break; case 579: /* procedure_using_chaining: USING $@31 procedure_param_list */ -#line 3534 "parser.y" +#line 3542 "parser.y" { yyval = yyvsp[0]; } -#line 8036 "parser.c" +#line 8083 "parser.c" break; case 580: /* $@32: %empty */ -#line 3536 "parser.y" +#line 3544 "parser.y" { call_mode = CB_CALL_BY_REFERENCE; current_program->flag_chained = 1; } -#line 8045 "parser.c" +#line 8092 "parser.c" break; case 581: /* procedure_using_chaining: CHAINING $@32 procedure_param_list */ -#line 3540 "parser.y" +#line 3548 "parser.y" { yyval = yyvsp[0]; } -#line 8051 "parser.c" +#line 8098 "parser.c" break; case 582: /* procedure_param_list: procedure_param */ -#line 3544 "parser.y" +#line 3552 "parser.y" { yyval = yyvsp[0]; } -#line 8057 "parser.c" +#line 8104 "parser.c" break; case 583: /* procedure_param_list: procedure_param_list procedure_param */ -#line 3546 "parser.y" +#line 3554 "parser.y" { yyval = cb_list_append (yyvsp[-1], yyvsp[0]); } -#line 8063 "parser.c" +#line 8110 "parser.c" break; case 584: /* procedure_param: procedure_type size_optional procedure_optional "Identifier" */ -#line 3551 "parser.y" +#line 3559 "parser.y" { yyval = cb_build_pair (cb_int (call_mode), cb_build_identifier (yyvsp[0])); CB_SIZES (yyval) = size_mode; } -#line 8072 "parser.c" +#line 8119 "parser.c" break; case 586: /* procedure_type: _by REFERENCE */ -#line 3560 "parser.y" +#line 3568 "parser.y" { call_mode = CB_CALL_BY_REFERENCE; } -#line 8080 "parser.c" +#line 8127 "parser.c" break; case 587: /* procedure_type: _by VALUE */ -#line 3564 "parser.y" +#line 3572 "parser.y" { if (current_program->flag_chained) { cb_error (_("BY VALUE not allowed in CHAINED program")); @@ -8088,11 +8135,11 @@ yyparse (void) call_mode = CB_CALL_BY_VALUE; } } -#line 8092 "parser.c" +#line 8139 "parser.c" break; case 589: /* size_optional: SIZE _is AUTO */ -#line 3576 "parser.y" +#line 3584 "parser.y" { if (call_mode != CB_CALL_BY_VALUE) { cb_error (_("SIZE only allowed for BY VALUE items")); @@ -8100,11 +8147,11 @@ yyparse (void) size_mode = CB_SIZE_AUTO; } } -#line 8104 "parser.c" +#line 8151 "parser.c" break; case 590: /* size_optional: SIZE _is DEFAULT */ -#line 3584 "parser.y" +#line 3592 "parser.y" { if (call_mode != CB_CALL_BY_VALUE) { cb_error (_("SIZE only allowed for BY VALUE items")); @@ -8112,11 +8159,11 @@ yyparse (void) size_mode = CB_SIZE_4; } } -#line 8116 "parser.c" +#line 8163 "parser.c" break; case 591: /* size_optional: UNSIGNED SIZE _is integer */ -#line 3592 "parser.y" +#line 3600 "parser.y" { unsigned char *s = CB_LITERAL (yyvsp[0])->data; @@ -8145,11 +8192,11 @@ yyparse (void) } } } -#line 8149 "parser.c" +#line 8196 "parser.c" break; case 592: /* size_optional: SIZE _is integer */ -#line 3621 "parser.y" +#line 3629 "parser.y" { unsigned char *s = CB_LITERAL (yyvsp[0])->data; @@ -8178,31 +8225,31 @@ yyparse (void) } } } -#line 8182 "parser.c" +#line 8229 "parser.c" break; case 594: /* procedure_optional: OPTIONAL */ -#line 3654 "parser.y" +#line 3662 "parser.y" { if (call_mode != CB_CALL_BY_REFERENCE) { cb_error (_("OPTIONAL only allowed for BY REFERENCE items")); } } -#line 8192 "parser.c" +#line 8239 "parser.c" break; case 595: /* procedure_returning: %empty */ -#line 3663 "parser.y" +#line 3671 "parser.y" { if (current_program->prog_type == CB_FUNCTION_TYPE) { cb_error (_("RETURNING clause is required for a FUNCTION")); } } -#line 8202 "parser.c" +#line 8249 "parser.c" break; case 596: /* procedure_returning: RETURNING "Identifier" */ -#line 3669 "parser.y" +#line 3677 "parser.y" { if (cb_ref (yyvsp[0]) != cb_error_node) { current_program->returning = yyvsp[0]; @@ -8211,17 +8258,17 @@ yyparse (void) } } } -#line 8215 "parser.c" +#line 8262 "parser.c" break; case 598: /* $@33: %empty */ -#line 3680 "parser.y" +#line 3688 "parser.y" { in_declaratives = 1; } -#line 8221 "parser.c" +#line 8268 "parser.c" break; case 599: /* procedure_declaratives: DECLARATIVES '.' $@33 procedure_list END DECLARATIVES '.' */ -#line 3683 "parser.y" +#line 3691 "parser.y" { in_declaratives = 0; if (current_paragraph) { @@ -8239,11 +8286,11 @@ yyparse (void) current_section = NULL; } } -#line 8243 "parser.c" +#line 8290 "parser.c" break; case 605: /* procedure: statements '.' */ -#line 3716 "parser.y" +#line 3724 "parser.y" { if (next_label_list) { cb_tree label; @@ -8259,19 +8306,19 @@ yyparse (void) } /* check_unreached = 0; */ } -#line 8263 "parser.c" +#line 8310 "parser.c" break; case 606: /* procedure: error */ -#line 3732 "parser.y" +#line 3740 "parser.y" { check_unreached = 0; } -#line 8271 "parser.c" +#line 8318 "parser.c" break; case 607: /* section_header: section_name SECTION opt_segment '.' */ -#line 3744 "parser.y" +#line 3752 "parser.y" { non_const_word = 0; check_unreached = 0; @@ -8299,11 +8346,11 @@ yyparse (void) current_paragraph = NULL; emit_statement (CB_TREE (current_section)); } -#line 8303 "parser.c" +#line 8350 "parser.c" break; case 608: /* paragraph_header: "Identifier" '.' */ -#line 3775 "parser.y" +#line 3783 "parser.y" { cb_tree label; @@ -8337,11 +8384,11 @@ yyparse (void) } emit_statement (CB_TREE (current_paragraph)); } -#line 8341 "parser.c" +#line 8388 "parser.c" break; case 609: /* invalid_statement: section_name */ -#line 3812 "parser.y" +#line 3820 "parser.y" { non_const_word = 0; check_unreached = 0; @@ -8350,51 +8397,51 @@ yyparse (void) } YYERROR; } -#line 8354 "parser.c" +#line 8401 "parser.c" break; case 610: /* section_name: "Identifier" */ -#line 3823 "parser.y" +#line 3831 "parser.y" { yyval = cb_build_section_name (yyvsp[0], 0); } -#line 8360 "parser.c" +#line 8407 "parser.c" break; case 612: /* opt_segment: "Literal" */ -#line 3827 "parser.y" +#line 3835 "parser.y" { /* ignore */ } -#line 8366 "parser.c" +#line 8413 "parser.c" break; case 613: /* @34: %empty */ -#line 3836 "parser.y" +#line 3844 "parser.y" { yyval = current_program->exec_list; current_program->exec_list = NULL; } -#line 8375 "parser.c" +#line 8422 "parser.c" break; case 614: /* @35: %empty */ -#line 3840 "parser.y" +#line 3848 "parser.y" { yyval = CB_TREE (current_statement); current_statement = NULL; } -#line 8384 "parser.c" +#line 8431 "parser.c" break; case 615: /* statement_list: @34 @35 statements */ -#line 3845 "parser.y" +#line 3853 "parser.y" { yyval = cb_list_reverse (current_program->exec_list); current_program->exec_list = yyvsp[-2]; current_statement = CB_STATEMENT (yyvsp[-1]); } -#line 8394 "parser.c" +#line 8441 "parser.c" break; case 616: /* statements: %empty */ -#line 3853 "parser.y" +#line 3861 "parser.y" { cb_tree label; @@ -8415,11 +8462,11 @@ yyparse (void) cb_cons (CB_TREE (current_paragraph), current_section->children); } } -#line 8419 "parser.c" +#line 8466 "parser.c" break; case 667: /* statement: "NEXT SENTENCE" */ -#line 3928 "parser.y" +#line 3936 "parser.y" { if (cb_verify (cb_next_sentence_phrase, "NEXT SENTENCE")) { cb_tree label; @@ -8433,11 +8480,11 @@ yyparse (void) } check_unreached = 0; } -#line 8437 "parser.c" +#line 8484 "parser.c" break; case 668: /* $@36: %empty */ -#line 3950 "parser.y" +#line 3958 "parser.y" { BEGIN_STATEMENT ("ACCEPT", TERM_ACCEPT); dispattrs = 0; @@ -8445,489 +8492,489 @@ yyparse (void) bgc = NULL; scroll = NULL; } -#line 8449 "parser.c" +#line 8496 "parser.c" break; case 670: /* accept_body: identifier opt_at_line_column opt_accp_attr on_accp_exception */ -#line 3963 "parser.y" +#line 3971 "parser.y" { cb_emit_accept (yyvsp[-3], yyvsp[-2], fgc, bgc, scroll, dispattrs); } -#line 8457 "parser.c" +#line 8504 "parser.c" break; case 671: /* accept_body: identifier FROM ESCAPE KEY */ -#line 3967 "parser.y" +#line 3975 "parser.y" { PENDING ("ACCEPT .. FROM ESCAPE KEY"); } -#line 8465 "parser.c" +#line 8512 "parser.c" break; case 672: /* accept_body: identifier FROM LINES */ -#line 3971 "parser.y" +#line 3979 "parser.y" { cb_emit_accept_line_or_col (yyvsp[-2], 0); } -#line 8473 "parser.c" +#line 8520 "parser.c" break; case 673: /* accept_body: identifier FROM COLUMNS */ -#line 3975 "parser.y" +#line 3983 "parser.y" { cb_emit_accept_line_or_col (yyvsp[-2], 1); } -#line 8481 "parser.c" +#line 8528 "parser.c" break; case 674: /* accept_body: identifier FROM DATE */ -#line 3979 "parser.y" +#line 3987 "parser.y" { cb_emit_accept_date (yyvsp[-2]); } -#line 8489 "parser.c" +#line 8536 "parser.c" break; case 675: /* accept_body: identifier FROM DATE YYYYMMDD */ -#line 3983 "parser.y" +#line 3991 "parser.y" { cb_emit_accept_date_yyyymmdd (yyvsp[-3]); } -#line 8497 "parser.c" +#line 8544 "parser.c" break; case 676: /* accept_body: identifier FROM DAY */ -#line 3987 "parser.y" +#line 3995 "parser.y" { cb_emit_accept_day (yyvsp[-2]); } -#line 8505 "parser.c" +#line 8552 "parser.c" break; case 677: /* accept_body: identifier FROM DAY YYYYDDD */ -#line 3991 "parser.y" +#line 3999 "parser.y" { cb_emit_accept_day_yyyyddd (yyvsp[-3]); } -#line 8513 "parser.c" +#line 8560 "parser.c" break; case 678: /* accept_body: identifier FROM "DAY-OF-WEEK" */ -#line 3995 "parser.y" +#line 4003 "parser.y" { cb_emit_accept_day_of_week (yyvsp[-2]); } -#line 8521 "parser.c" +#line 8568 "parser.c" break; case 679: /* accept_body: identifier FROM TIME */ -#line 3999 "parser.y" +#line 4007 "parser.y" { cb_emit_accept_time (yyvsp[-2]); } -#line 8529 "parser.c" +#line 8576 "parser.c" break; case 680: /* accept_body: identifier FROM "COMMAND-LINE" */ -#line 4003 "parser.y" +#line 4011 "parser.y" { cb_emit_accept_command_line (yyvsp[-2]); } -#line 8537 "parser.c" +#line 8584 "parser.c" break; case 681: /* accept_body: identifier FROM "ENVIRONMENT-VALUE" on_accp_exception */ -#line 4007 "parser.y" +#line 4015 "parser.y" { cb_emit_accept_environment (yyvsp[-3]); } -#line 8545 "parser.c" +#line 8592 "parser.c" break; case 682: /* accept_body: identifier FROM ENVIRONMENT simple_value on_accp_exception */ -#line 4011 "parser.y" +#line 4019 "parser.y" { cb_emit_get_environment (yyvsp[-1], yyvsp[-4]); } -#line 8553 "parser.c" +#line 8600 "parser.c" break; case 683: /* accept_body: identifier FROM "ARGUMENT-NUMBER" */ -#line 4015 "parser.y" +#line 4023 "parser.y" { cb_emit_accept_arg_number (yyvsp[-2]); } -#line 8561 "parser.c" +#line 8608 "parser.c" break; case 684: /* accept_body: identifier FROM "ARGUMENT-VALUE" on_accp_exception */ -#line 4019 "parser.y" +#line 4027 "parser.y" { cb_emit_accept_arg_value (yyvsp[-3]); } -#line 8569 "parser.c" +#line 8616 "parser.c" break; case 685: /* accept_body: identifier FROM mnemonic_name */ -#line 4023 "parser.y" +#line 4031 "parser.y" { cb_emit_accept_mnemonic (yyvsp[-2], yyvsp[0]); } -#line 8577 "parser.c" +#line 8624 "parser.c" break; case 686: /* accept_body: identifier FROM "Identifier" */ -#line 4027 "parser.y" +#line 4035 "parser.y" { cb_emit_accept_name (yyvsp[-2], yyvsp[0]); } -#line 8585 "parser.c" +#line 8632 "parser.c" break; case 687: /* opt_at_line_column: %empty */ -#line 4033 "parser.y" +#line 4041 "parser.y" { yyval = NULL; } -#line 8591 "parser.c" +#line 8638 "parser.c" break; case 688: /* opt_at_line_column: _at line_number column_number */ -#line 4034 "parser.y" +#line 4042 "parser.y" { yyval = cb_build_pair (yyvsp[-1], yyvsp[0]); } -#line 8597 "parser.c" +#line 8644 "parser.c" break; case 689: /* opt_at_line_column: _at column_number line_number */ -#line 4035 "parser.y" +#line 4043 "parser.y" { yyval = cb_build_pair (yyvsp[0], yyvsp[-1]); } -#line 8603 "parser.c" +#line 8650 "parser.c" break; case 690: /* opt_at_line_column: _at line_number */ -#line 4036 "parser.y" +#line 4044 "parser.y" { yyval = cb_build_pair (yyvsp[0], NULL); } -#line 8609 "parser.c" +#line 8656 "parser.c" break; case 691: /* opt_at_line_column: _at column_number */ -#line 4037 "parser.y" +#line 4045 "parser.y" { yyval = cb_build_pair (NULL, yyvsp[0]); } -#line 8615 "parser.c" +#line 8662 "parser.c" break; case 692: /* opt_at_line_column: AT simple_value */ -#line 4038 "parser.y" +#line 4046 "parser.y" { yyval = yyvsp[0]; } -#line 8621 "parser.c" +#line 8668 "parser.c" break; case 693: /* line_number: LINE _number id_or_lit */ -#line 4042 "parser.y" +#line 4050 "parser.y" { yyval = yyvsp[0]; } -#line 8627 "parser.c" +#line 8674 "parser.c" break; case 694: /* column_number: COLUMN _number id_or_lit */ -#line 4046 "parser.y" +#line 4054 "parser.y" { yyval = yyvsp[0]; } -#line 8633 "parser.c" +#line 8680 "parser.c" break; case 695: /* column_number: POSITION _number id_or_lit */ -#line 4047 "parser.y" +#line 4055 "parser.y" { yyval = yyvsp[0]; } -#line 8639 "parser.c" +#line 8686 "parser.c" break; case 700: /* accp_attr: BELL */ -#line 4060 "parser.y" +#line 4068 "parser.y" { dispattrs |= COB_SCREEN_BELL; } -#line 8645 "parser.c" +#line 8692 "parser.c" break; case 701: /* accp_attr: BLINK */ -#line 4061 "parser.y" +#line 4069 "parser.y" { dispattrs |= COB_SCREEN_BLINK; } -#line 8651 "parser.c" +#line 8698 "parser.c" break; case 702: /* accp_attr: HIGHLIGHT */ -#line 4062 "parser.y" +#line 4070 "parser.y" { dispattrs |= COB_SCREEN_HIGHLIGHT; } -#line 8657 "parser.c" +#line 8704 "parser.c" break; case 703: /* accp_attr: LOWLIGHT */ -#line 4063 "parser.y" +#line 4071 "parser.y" { dispattrs |= COB_SCREEN_LOWLIGHT; } -#line 8663 "parser.c" +#line 8710 "parser.c" break; case 704: /* accp_attr: "REVERSE-VIDEO" */ -#line 4064 "parser.y" +#line 4072 "parser.y" { dispattrs |= COB_SCREEN_REVERSE; } -#line 8669 "parser.c" +#line 8716 "parser.c" break; case 705: /* accp_attr: UNDERLINE */ -#line 4065 "parser.y" +#line 4073 "parser.y" { dispattrs |= COB_SCREEN_UNDERLINE; } -#line 8675 "parser.c" +#line 8722 "parser.c" break; case 706: /* accp_attr: OVERLINE */ -#line 4066 "parser.y" +#line 4074 "parser.y" { dispattrs |= COB_SCREEN_OVERLINE; } -#line 8681 "parser.c" +#line 8728 "parser.c" break; case 707: /* accp_attr: "FOREGROUND-COLOR" _is num_id_or_lit */ -#line 4068 "parser.y" +#line 4076 "parser.y" { fgc = yyvsp[0]; } -#line 8689 "parser.c" +#line 8736 "parser.c" break; case 708: /* accp_attr: "BACKGROUND-COLOR" _is num_id_or_lit */ -#line 4072 "parser.y" +#line 4080 "parser.y" { bgc = yyvsp[0]; } -#line 8697 "parser.c" +#line 8744 "parser.c" break; case 709: /* accp_attr: SCROLL UP _opt_scroll_lines */ -#line 4076 "parser.y" +#line 4084 "parser.y" { scroll = yyvsp[0]; } -#line 8705 "parser.c" +#line 8752 "parser.c" break; case 710: /* accp_attr: SCROLL DOWN _opt_scroll_lines */ -#line 4080 "parser.y" +#line 4088 "parser.y" { dispattrs |= COB_SCREEN_SCROLL_DOWN; scroll = yyvsp[0]; } -#line 8714 "parser.c" +#line 8761 "parser.c" break; case 711: /* accp_attr: AUTO */ -#line 4084 "parser.y" +#line 4092 "parser.y" { dispattrs |= COB_SCREEN_AUTO; } -#line 8720 "parser.c" +#line 8767 "parser.c" break; case 712: /* accp_attr: FULL */ -#line 4085 "parser.y" +#line 4093 "parser.y" { dispattrs |= COB_SCREEN_FULL; } -#line 8726 "parser.c" +#line 8773 "parser.c" break; case 713: /* accp_attr: REQUIRED */ -#line 4086 "parser.y" +#line 4094 "parser.y" { dispattrs |= COB_SCREEN_REQUIRED; } -#line 8732 "parser.c" +#line 8779 "parser.c" break; case 714: /* accp_attr: SECURE */ -#line 4087 "parser.y" +#line 4095 "parser.y" { dispattrs |= COB_SCREEN_SECURE; } -#line 8738 "parser.c" +#line 8785 "parser.c" break; case 715: /* accp_attr: UPDATE */ -#line 4088 "parser.y" +#line 4096 "parser.y" { dispattrs |= COB_SCREEN_UPDATE; } -#line 8744 "parser.c" +#line 8791 "parser.c" break; case 716: /* accp_attr: PROMPT */ -#line 4089 "parser.y" +#line 4097 "parser.y" { dispattrs |= COB_SCREEN_PROMPT; } -#line 8750 "parser.c" +#line 8797 "parser.c" break; case 717: /* end_accept: %empty */ -#line 4093 "parser.y" +#line 4101 "parser.y" { terminator_warning (TERM_ACCEPT); } -#line 8756 "parser.c" +#line 8803 "parser.c" break; case 718: /* end_accept: "END-ACCEPT" */ -#line 4094 "parser.y" +#line 4102 "parser.y" { terminator_clear (TERM_ACCEPT); } -#line 8762 "parser.c" +#line 8809 "parser.c" break; case 719: /* $@37: %empty */ -#line 4103 "parser.y" +#line 4111 "parser.y" { BEGIN_STATEMENT ("ADD", TERM_ADD); } -#line 8768 "parser.c" +#line 8815 "parser.c" break; case 721: /* add_body: x_list TO arithmetic_x_list on_size_error */ -#line 4110 "parser.y" +#line 4118 "parser.y" { cb_emit_arithmetic (yyvsp[-1], '+', cb_build_binary_list (yyvsp[-3], '+')); } -#line 8776 "parser.c" +#line 8823 "parser.c" break; case 722: /* add_body: x_list add_to GIVING arithmetic_x_list on_size_error */ -#line 4114 "parser.y" +#line 4122 "parser.y" { cb_emit_arithmetic (yyvsp[-1], 0, cb_build_binary_list (yyvsp[-4], '+')); } -#line 8784 "parser.c" +#line 8831 "parser.c" break; case 723: /* add_body: CORRESPONDING identifier TO identifier flag_rounded on_size_error */ -#line 4118 "parser.y" +#line 4126 "parser.y" { cb_emit_corresponding (cb_build_add, yyvsp[-2], yyvsp[-4], yyvsp[-1]); } -#line 8792 "parser.c" +#line 8839 "parser.c" break; case 725: /* add_to: TO x */ -#line 4124 "parser.y" +#line 4132 "parser.y" { cb_list_add (yyvsp[-2], yyvsp[0]); } -#line 8798 "parser.c" +#line 8845 "parser.c" break; case 726: /* end_add: %empty */ -#line 4128 "parser.y" +#line 4136 "parser.y" { terminator_warning (TERM_ADD); } -#line 8804 "parser.c" +#line 8851 "parser.c" break; case 727: /* end_add: "END-ADD" */ -#line 4129 "parser.y" +#line 4137 "parser.y" { terminator_clear (TERM_ADD); } -#line 8810 "parser.c" +#line 8857 "parser.c" break; case 728: /* $@38: %empty */ -#line 4138 "parser.y" +#line 4146 "parser.y" { BEGIN_STATEMENT ("ALLOCATE", 0); } -#line 8816 "parser.c" +#line 8863 "parser.c" break; case 730: /* allocate_body: "Identifier" flag_initialized allocate_returning */ -#line 4144 "parser.y" +#line 4152 "parser.y" { cb_emit_allocate (yyvsp[-2], yyvsp[0], NULL, yyvsp[-1]); } -#line 8824 "parser.c" +#line 8871 "parser.c" break; case 731: /* allocate_body: expr CHARACTERS flag_initialized RETURNING target_x */ -#line 4148 "parser.y" +#line 4156 "parser.y" { cb_emit_allocate (NULL, yyvsp[0], yyvsp[-4], yyvsp[-2]); } -#line 8832 "parser.c" +#line 8879 "parser.c" break; case 732: /* allocate_returning: %empty */ -#line 4154 "parser.y" +#line 4162 "parser.y" { yyval = NULL; } -#line 8838 "parser.c" +#line 8885 "parser.c" break; case 733: /* allocate_returning: RETURNING target_x */ -#line 4155 "parser.y" +#line 4163 "parser.y" { yyval = yyvsp[0]; } -#line 8844 "parser.c" +#line 8891 "parser.c" break; case 734: /* alter_statement: ALTER alter_options */ -#line 4165 "parser.y" +#line 4173 "parser.y" { cb_error (_("ALTER statement is obsolete and unsupported")); } -#line 8852 "parser.c" +#line 8899 "parser.c" break; case 739: /* $@39: %empty */ -#line 4183 "parser.y" +#line 4191 "parser.y" { BEGIN_STATEMENT ("CALL", TERM_CALL); } -#line 8858 "parser.c" +#line 8905 "parser.c" break; case 740: /* call_statement: CALL $@39 id_or_lit_or_func call_using call_returning call_on_exception call_not_on_exception end_call */ -#line 4187 "parser.y" +#line 4195 "parser.y" { cb_emit_call (yyvsp[-5], yyvsp[-4], yyvsp[-3], yyvsp[-2], yyvsp[-1]); } -#line 8866 "parser.c" +#line 8913 "parser.c" break; case 741: /* call_using: %empty */ -#line 4193 "parser.y" +#line 4201 "parser.y" { yyval = NULL; } -#line 8872 "parser.c" +#line 8919 "parser.c" break; case 742: /* $@40: %empty */ -#line 4195 "parser.y" +#line 4203 "parser.y" { call_mode = CB_CALL_BY_REFERENCE; size_mode = CB_SIZE_4; } -#line 8881 "parser.c" +#line 8928 "parser.c" break; case 743: /* call_using: USING $@40 call_param_list */ -#line 4199 "parser.y" +#line 4207 "parser.y" { yyval = yyvsp[0]; } -#line 8887 "parser.c" +#line 8934 "parser.c" break; case 744: /* call_param_list: call_param */ -#line 4203 "parser.y" +#line 4211 "parser.y" { yyval = yyvsp[0]; } -#line 8893 "parser.c" +#line 8940 "parser.c" break; case 745: /* call_param_list: call_param_list call_param */ -#line 4205 "parser.y" +#line 4213 "parser.y" { yyval = cb_list_append (yyvsp[-1], yyvsp[0]); } -#line 8899 "parser.c" +#line 8946 "parser.c" break; case 746: /* call_param: call_type OMITTED */ -#line 4210 "parser.y" +#line 4218 "parser.y" { if (call_mode != CB_CALL_BY_REFERENCE) { cb_error (_("OMITTED only allowed with BY REFERENCE")); } yyval = cb_build_pair (cb_int (call_mode), cb_null); } -#line 8910 "parser.c" +#line 8957 "parser.c" break; case 747: /* call_param: call_type size_optional x */ -#line 4217 "parser.y" +#line 4225 "parser.y" { yyval = cb_build_pair (cb_int (call_mode), yyvsp[0]); CB_SIZES (yyval) = size_mode; } -#line 8919 "parser.c" +#line 8966 "parser.c" break; case 749: /* call_type: _by REFERENCE */ -#line 4226 "parser.y" +#line 4234 "parser.y" { call_mode = CB_CALL_BY_REFERENCE; } -#line 8927 "parser.c" +#line 8974 "parser.c" break; case 750: /* call_type: _by CONTENT */ -#line 4230 "parser.y" +#line 4238 "parser.y" { if (current_program->flag_chained) { cb_error (_("BY CONTENT not allowed in CHAINED program")); @@ -8935,11 +8982,11 @@ yyparse (void) call_mode = CB_CALL_BY_CONTENT; } } -#line 8939 "parser.c" +#line 8986 "parser.c" break; case 751: /* call_type: _by VALUE */ -#line 4238 "parser.y" +#line 4246 "parser.y" { if (current_program->flag_chained) { cb_error (_("BY VALUE not allowed in CHAINED program")); @@ -8947,236 +8994,236 @@ yyparse (void) call_mode = CB_CALL_BY_VALUE; } } -#line 8951 "parser.c" +#line 8998 "parser.c" break; case 752: /* call_returning: %empty */ -#line 4248 "parser.y" +#line 4256 "parser.y" { yyval = NULL; } -#line 8957 "parser.c" +#line 9004 "parser.c" break; case 753: /* call_returning: RETURNING identifier */ -#line 4249 "parser.y" +#line 4257 "parser.y" { yyval = yyvsp[0]; } -#line 8963 "parser.c" +#line 9010 "parser.c" break; case 754: /* call_returning: GIVING identifier */ -#line 4250 "parser.y" +#line 4258 "parser.y" { yyval = yyvsp[0]; } -#line 8969 "parser.c" +#line 9016 "parser.c" break; case 755: /* call_on_exception: %empty */ -#line 4255 "parser.y" +#line 4263 "parser.y" { yyval = NULL; } -#line 8977 "parser.c" +#line 9024 "parser.c" break; case 756: /* $@41: %empty */ -#line 4259 "parser.y" +#line 4267 "parser.y" { check_unreached = 0; } -#line 8985 "parser.c" +#line 9032 "parser.c" break; case 757: /* call_on_exception: exception_or_overflow $@41 statement_list */ -#line 4263 "parser.y" +#line 4271 "parser.y" { yyval = yyvsp[0]; } -#line 8993 "parser.c" +#line 9040 "parser.c" break; case 758: /* call_not_on_exception: %empty */ -#line 4270 "parser.y" +#line 4278 "parser.y" { yyval = NULL; } -#line 9001 "parser.c" +#line 9048 "parser.c" break; case 759: /* $@42: %empty */ -#line 4274 "parser.y" +#line 4282 "parser.y" { check_unreached = 0; } -#line 9009 "parser.c" +#line 9056 "parser.c" break; case 760: /* call_not_on_exception: not_exception_or_overflow $@42 statement_list */ -#line 4278 "parser.y" +#line 4286 "parser.y" { yyval = yyvsp[0]; } -#line 9017 "parser.c" +#line 9064 "parser.c" break; case 761: /* end_call: %empty */ -#line 4284 "parser.y" +#line 4292 "parser.y" { terminator_warning (TERM_CALL); } -#line 9023 "parser.c" +#line 9070 "parser.c" break; case 762: /* end_call: "END-CALL" */ -#line 4285 "parser.y" +#line 4293 "parser.y" { terminator_clear (TERM_CALL); } -#line 9029 "parser.c" +#line 9076 "parser.c" break; case 763: /* $@43: %empty */ -#line 4294 "parser.y" +#line 4302 "parser.y" { BEGIN_STATEMENT ("CANCEL", 0); } -#line 9035 "parser.c" +#line 9082 "parser.c" break; case 766: /* cancel_list: cancel_list id_or_lit */ -#line 4300 "parser.y" +#line 4308 "parser.y" { cb_emit_cancel (yyvsp[0]); } -#line 9043 "parser.c" +#line 9090 "parser.c" break; case 767: /* cancel_list: ALL */ -#line 4304 "parser.y" +#line 4312 "parser.y" { cb_emit_cancel_all (); } -#line 9051 "parser.c" +#line 9098 "parser.c" break; case 768: /* $@44: %empty */ -#line 4315 "parser.y" +#line 4323 "parser.y" { BEGIN_STATEMENT ("CLOSE", 0); } -#line 9057 "parser.c" +#line 9104 "parser.c" break; case 771: /* close_list: close_list file_name close_option */ -#line 4322 "parser.y" +#line 4330 "parser.y" { BEGIN_IMPLICIT_STATEMENT (yyvsp[-1]); if (yyvsp[-1] != cb_error_node) { cb_emit_close (yyvsp[-1], yyvsp[0]); } } -#line 9068 "parser.c" +#line 9115 "parser.c" break; case 772: /* close_option: %empty */ -#line 4331 "parser.y" +#line 4339 "parser.y" { yyval = cb_int (COB_CLOSE_NORMAL); } -#line 9074 "parser.c" +#line 9121 "parser.c" break; case 773: /* close_option: reel_or_unit */ -#line 4332 "parser.y" +#line 4340 "parser.y" { yyval = cb_int (COB_CLOSE_UNIT); } -#line 9080 "parser.c" +#line 9127 "parser.c" break; case 774: /* close_option: reel_or_unit _for REMOVAL */ -#line 4333 "parser.y" +#line 4341 "parser.y" { yyval = cb_int (COB_CLOSE_UNIT_REMOVAL); } -#line 9086 "parser.c" +#line 9133 "parser.c" break; case 775: /* close_option: _with NO REWIND */ -#line 4334 "parser.y" +#line 4342 "parser.y" { yyval = cb_int (COB_CLOSE_NO_REWIND); } -#line 9092 "parser.c" +#line 9139 "parser.c" break; case 776: /* close_option: _with LOCK */ -#line 4335 "parser.y" +#line 4343 "parser.y" { yyval = cb_int (COB_CLOSE_LOCK); } -#line 9098 "parser.c" +#line 9145 "parser.c" break; case 779: /* $@45: %empty */ -#line 4346 "parser.y" +#line 4354 "parser.y" { BEGIN_STATEMENT ("COMPUTE", TERM_COMPUTE); } -#line 9104 "parser.c" +#line 9151 "parser.c" break; case 781: /* compute_body: arithmetic_x_list comp_equal expr on_size_error */ -#line 4353 "parser.y" +#line 4361 "parser.y" { cb_emit_arithmetic (yyvsp[-3], 0, yyvsp[-1]); } -#line 9112 "parser.c" +#line 9159 "parser.c" break; case 782: /* end_compute: %empty */ -#line 4359 "parser.y" +#line 4367 "parser.y" { terminator_warning (TERM_COMPUTE); } -#line 9118 "parser.c" +#line 9165 "parser.c" break; case 783: /* end_compute: "END-COMPUTE" */ -#line 4360 "parser.y" +#line 4368 "parser.y" { terminator_clear (TERM_COMPUTE); } -#line 9124 "parser.c" +#line 9171 "parser.c" break; case 786: /* commit_statement: COMMIT */ -#line 4371 "parser.y" +#line 4379 "parser.y" { BEGIN_STATEMENT ("COMMIT", 0); cb_emit_commit (); } -#line 9133 "parser.c" +#line 9180 "parser.c" break; case 787: /* continue_statement: CONTINUE */ -#line 4384 "parser.y" +#line 4392 "parser.y" { BEGIN_STATEMENT ("CONTINUE", 0); cb_emit_continue (); } -#line 9142 "parser.c" +#line 9189 "parser.c" break; case 788: /* $@46: %empty */ -#line 4396 "parser.y" +#line 4404 "parser.y" { BEGIN_STATEMENT ("DELETE", TERM_DELETE); } -#line 9148 "parser.c" +#line 9195 "parser.c" break; case 789: /* delete_statement: DELETE $@46 file_name _record opt_invalid_key end_delete */ -#line 4399 "parser.y" +#line 4407 "parser.y" { if (yyvsp[-3] != cb_error_node) { cb_emit_delete (yyvsp[-3]); } } -#line 9158 "parser.c" +#line 9205 "parser.c" break; case 790: /* end_delete: %empty */ -#line 4407 "parser.y" +#line 4415 "parser.y" { terminator_warning (TERM_DELETE); } -#line 9164 "parser.c" +#line 9211 "parser.c" break; case 791: /* end_delete: "END-DELETE" */ -#line 4408 "parser.y" +#line 4416 "parser.y" { terminator_clear (TERM_DELETE); } -#line 9170 "parser.c" +#line 9217 "parser.c" break; case 792: /* $@47: %empty */ -#line 4417 "parser.y" +#line 4425 "parser.y" { BEGIN_STATEMENT ("DELETE-FILE", 0); } -#line 9176 "parser.c" +#line 9223 "parser.c" break; case 793: /* delete_file_statement: DELETE $@47 "FILE" file_name_list */ -#line 4419 "parser.y" +#line 4427 "parser.y" { cb_tree l; for (l = yyvsp[0]; l; l = CB_CHAIN (l)) { @@ -9186,11 +9233,11 @@ yyparse (void) } } } -#line 9190 "parser.c" +#line 9237 "parser.c" break; case 794: /* $@48: %empty */ -#line 4437 "parser.y" +#line 4445 "parser.y" { BEGIN_STATEMENT ("DISPLAY", TERM_DISPLAY); dispattrs = 0; @@ -9198,277 +9245,277 @@ yyparse (void) bgc = NULL; scroll = NULL; } -#line 9202 "parser.c" +#line 9249 "parser.c" break; case 796: /* display_body: id_or_lit "UPON ENVIRONMENT-NAME" on_disp_exception */ -#line 4450 "parser.y" +#line 4458 "parser.y" { cb_emit_env_name (yyvsp[-2]); } -#line 9210 "parser.c" +#line 9257 "parser.c" break; case 797: /* display_body: id_or_lit "UPON ENVIRONMENT-VALUE" on_disp_exception */ -#line 4454 "parser.y" +#line 4462 "parser.y" { cb_emit_env_value (yyvsp[-2]); } -#line 9218 "parser.c" +#line 9265 "parser.c" break; case 798: /* display_body: id_or_lit "UPON ARGUMENT-NUMBER" on_disp_exception */ -#line 4458 "parser.y" +#line 4466 "parser.y" { cb_emit_arg_number (yyvsp[-2]); } -#line 9226 "parser.c" +#line 9273 "parser.c" break; case 799: /* display_body: id_or_lit "UPON COMMAND-LINE" on_disp_exception */ -#line 4462 "parser.y" +#line 4470 "parser.y" { cb_emit_command_line (yyvsp[-2]); } -#line 9234 "parser.c" +#line 9281 "parser.c" break; case 800: /* display_body: x_list opt_at_line_column with_clause on_disp_exception */ -#line 4466 "parser.y" +#line 4474 "parser.y" { cb_emit_display (yyvsp[-3], cb_int0, yyvsp[-1], yyvsp[-2], fgc, bgc, scroll, dispattrs); } -#line 9242 "parser.c" +#line 9289 "parser.c" break; case 801: /* display_body: x_list opt_at_line_column UPON mnemonic_name with_clause on_disp_exception */ -#line 4470 "parser.y" +#line 4478 "parser.y" { cb_emit_display_mnemonic (yyvsp[-5], yyvsp[-2], yyvsp[-1], yyvsp[-4], fgc, bgc, scroll, dispattrs); } -#line 9250 "parser.c" +#line 9297 "parser.c" break; case 802: /* display_body: x_list opt_at_line_column UPON "Identifier" with_clause on_disp_exception */ -#line 4474 "parser.y" +#line 4482 "parser.y" { cb_tree word = cb_build_display_upon_direct (yyvsp[-2]); cb_emit_display (yyvsp[-5], word, yyvsp[-1], yyvsp[-4], fgc, bgc, scroll, dispattrs); } -#line 9259 "parser.c" +#line 9306 "parser.c" break; case 803: /* display_body: x_list opt_at_line_column UPON PRINTER with_clause on_disp_exception */ -#line 4479 "parser.y" +#line 4487 "parser.y" { cb_emit_display (yyvsp[-5], cb_int0, yyvsp[-1], yyvsp[-4], fgc, bgc, scroll, dispattrs); } -#line 9267 "parser.c" +#line 9314 "parser.c" break; case 804: /* display_body: x_list opt_at_line_column UPON CRT with_clause on_disp_exception */ -#line 4483 "parser.y" +#line 4491 "parser.y" { cb_emit_display (yyvsp[-5], cb_int0, yyvsp[-1], yyvsp[-4], fgc, bgc, scroll, dispattrs); } -#line 9275 "parser.c" +#line 9322 "parser.c" break; case 805: /* with_clause: %empty */ -#line 4489 "parser.y" +#line 4497 "parser.y" { yyval = cb_int1; } -#line 9281 "parser.c" +#line 9328 "parser.c" break; case 806: /* with_clause: _with "NO ADVANCING" */ -#line 4490 "parser.y" +#line 4498 "parser.y" { yyval = cb_int0; } -#line 9287 "parser.c" +#line 9334 "parser.c" break; case 807: /* with_clause: WITH disp_attrs */ -#line 4491 "parser.y" +#line 4499 "parser.y" { yyval = cb_int1; } -#line 9293 "parser.c" +#line 9340 "parser.c" break; case 810: /* disp_attr: BELL */ -#line 4501 "parser.y" +#line 4509 "parser.y" { dispattrs |= COB_SCREEN_BELL; } -#line 9299 "parser.c" +#line 9346 "parser.c" break; case 811: /* disp_attr: BLINK */ -#line 4502 "parser.y" +#line 4510 "parser.y" { dispattrs |= COB_SCREEN_BLINK; } -#line 9305 "parser.c" +#line 9352 "parser.c" break; case 812: /* disp_attr: ERASE EOL */ -#line 4503 "parser.y" +#line 4511 "parser.y" { dispattrs |= COB_SCREEN_ERASE_EOL; } -#line 9311 "parser.c" +#line 9358 "parser.c" break; case 813: /* disp_attr: ERASE EOS */ -#line 4504 "parser.y" +#line 4512 "parser.y" { dispattrs |= COB_SCREEN_ERASE_EOS; } -#line 9317 "parser.c" +#line 9364 "parser.c" break; case 814: /* disp_attr: HIGHLIGHT */ -#line 4505 "parser.y" +#line 4513 "parser.y" { dispattrs |= COB_SCREEN_HIGHLIGHT; } -#line 9323 "parser.c" +#line 9370 "parser.c" break; case 815: /* disp_attr: LOWLIGHT */ -#line 4506 "parser.y" +#line 4514 "parser.y" { dispattrs |= COB_SCREEN_LOWLIGHT; } -#line 9329 "parser.c" +#line 9376 "parser.c" break; case 816: /* disp_attr: "REVERSE-VIDEO" */ -#line 4507 "parser.y" +#line 4515 "parser.y" { dispattrs |= COB_SCREEN_REVERSE; } -#line 9335 "parser.c" +#line 9382 "parser.c" break; case 817: /* disp_attr: UNDERLINE */ -#line 4508 "parser.y" +#line 4516 "parser.y" { dispattrs |= COB_SCREEN_UNDERLINE; } -#line 9341 "parser.c" +#line 9388 "parser.c" break; case 818: /* disp_attr: OVERLINE */ -#line 4509 "parser.y" +#line 4517 "parser.y" { dispattrs |= COB_SCREEN_OVERLINE; } -#line 9347 "parser.c" +#line 9394 "parser.c" break; case 819: /* disp_attr: "FOREGROUND-COLOR" _is num_id_or_lit */ -#line 4511 "parser.y" +#line 4519 "parser.y" { fgc = yyvsp[0]; } -#line 9355 "parser.c" +#line 9402 "parser.c" break; case 820: /* disp_attr: "BACKGROUND-COLOR" _is num_id_or_lit */ -#line 4515 "parser.y" +#line 4523 "parser.y" { bgc = yyvsp[0]; } -#line 9363 "parser.c" +#line 9410 "parser.c" break; case 821: /* disp_attr: SCROLL UP _opt_scroll_lines */ -#line 4519 "parser.y" +#line 4527 "parser.y" { scroll = yyvsp[0]; } -#line 9371 "parser.c" +#line 9418 "parser.c" break; case 822: /* disp_attr: SCROLL DOWN _opt_scroll_lines */ -#line 4523 "parser.y" +#line 4531 "parser.y" { dispattrs |= COB_SCREEN_SCROLL_DOWN; scroll = yyvsp[0]; } -#line 9380 "parser.c" +#line 9427 "parser.c" break; case 823: /* disp_attr: "BLANK-LINE" */ -#line 4527 "parser.y" +#line 4535 "parser.y" { dispattrs |= COB_SCREEN_BLANK_LINE; } -#line 9386 "parser.c" +#line 9433 "parser.c" break; case 824: /* disp_attr: "BLANK-SCREEN" */ -#line 4528 "parser.y" +#line 4536 "parser.y" { dispattrs |= COB_SCREEN_BLANK_SCREEN; } -#line 9392 "parser.c" +#line 9439 "parser.c" break; case 825: /* end_display: %empty */ -#line 4532 "parser.y" +#line 4540 "parser.y" { terminator_warning (TERM_DISPLAY); } -#line 9398 "parser.c" +#line 9445 "parser.c" break; case 826: /* end_display: "END-DISPLAY" */ -#line 4533 "parser.y" +#line 4541 "parser.y" { terminator_clear (TERM_DISPLAY); } -#line 9404 "parser.c" +#line 9451 "parser.c" break; case 827: /* $@49: %empty */ -#line 4542 "parser.y" +#line 4550 "parser.y" { BEGIN_STATEMENT ("DIVIDE", TERM_DIVIDE); } -#line 9410 "parser.c" +#line 9457 "parser.c" break; case 829: /* divide_body: x INTO arithmetic_x_list on_size_error */ -#line 4549 "parser.y" +#line 4557 "parser.y" { cb_emit_arithmetic (yyvsp[-1], '/', yyvsp[-3]); } -#line 9418 "parser.c" +#line 9465 "parser.c" break; case 830: /* divide_body: x INTO x GIVING arithmetic_x_list on_size_error */ -#line 4553 "parser.y" +#line 4561 "parser.y" { cb_emit_arithmetic (yyvsp[-1], 0, cb_build_binary_op (yyvsp[-3], '/', yyvsp[-5])); } -#line 9426 "parser.c" +#line 9473 "parser.c" break; case 831: /* divide_body: x BY x GIVING arithmetic_x_list on_size_error */ -#line 4557 "parser.y" +#line 4565 "parser.y" { cb_emit_arithmetic (yyvsp[-1], 0, cb_build_binary_op (yyvsp[-5], '/', yyvsp[-3])); } -#line 9434 "parser.c" +#line 9481 "parser.c" break; case 832: /* divide_body: x INTO x GIVING arithmetic_x REMAINDER arithmetic_x on_size_error */ -#line 4561 "parser.y" +#line 4569 "parser.y" { cb_emit_divide (yyvsp[-5], yyvsp[-7], yyvsp[-3], yyvsp[-1]); } -#line 9442 "parser.c" +#line 9489 "parser.c" break; case 833: /* divide_body: x BY x GIVING arithmetic_x REMAINDER arithmetic_x on_size_error */ -#line 4565 "parser.y" +#line 4573 "parser.y" { cb_emit_divide (yyvsp[-7], yyvsp[-5], yyvsp[-3], yyvsp[-1]); } -#line 9450 "parser.c" +#line 9497 "parser.c" break; case 834: /* end_divide: %empty */ -#line 4571 "parser.y" +#line 4579 "parser.y" { terminator_warning (TERM_DIVIDE); } -#line 9456 "parser.c" +#line 9503 "parser.c" break; case 835: /* end_divide: "END-DIVIDE" */ -#line 4572 "parser.y" +#line 4580 "parser.y" { terminator_clear (TERM_DIVIDE); } -#line 9462 "parser.c" +#line 9509 "parser.c" break; case 836: /* $@50: %empty */ -#line 4581 "parser.y" +#line 4589 "parser.y" { BEGIN_STATEMENT ("ENTRY", 0); } -#line 9468 "parser.c" +#line 9515 "parser.c" break; case 837: /* entry_statement: ENTRY $@50 "Literal" call_using */ -#line 4583 "parser.y" +#line 4591 "parser.y" { if (current_program->nested_level) { cb_error (_("ENTRY is invalid in nested program")); @@ -9480,11 +9527,11 @@ yyparse (void) } check_unreached = 0; } -#line 9484 "parser.c" +#line 9531 "parser.c" break; case 838: /* $@51: %empty */ -#line 4603 "parser.y" +#line 4611 "parser.y" { BEGIN_STATEMENT ("EVALUATE", TERM_EVALUATE); eval_level++; @@ -9494,37 +9541,37 @@ yyparse (void) eval_inc = 0; eval_inc2 = 0; } -#line 9498 "parser.c" +#line 9545 "parser.c" break; case 839: /* evaluate_statement: EVALUATE $@51 evaluate_subject_list evaluate_condition_list end_evaluate */ -#line 4614 "parser.y" +#line 4622 "parser.y" { cb_emit_evaluate (yyvsp[-2], yyvsp[-1]); eval_level--; } -#line 9507 "parser.c" +#line 9554 "parser.c" break; case 840: /* evaluate_subject_list: evaluate_subject */ -#line 4621 "parser.y" +#line 4629 "parser.y" { yyval = cb_list_init (yyvsp[0]); } -#line 9513 "parser.c" +#line 9560 "parser.c" break; case 841: /* evaluate_subject_list: evaluate_subject_list _also evaluate_subject */ -#line 4624 "parser.y" +#line 4632 "parser.y" { if (!cb_allow_missing_also_clause_in_evaluate && yyvsp[-1] != cb_int1) { cb_error (_("Invalid expression")); } yyval = cb_list_add (yyvsp[-2], yyvsp[0]); } -#line 9524 "parser.c" +#line 9571 "parser.c" break; case 842: /* evaluate_subject: expr */ -#line 4634 "parser.y" +#line 4642 "parser.y" { yyval = yyvsp[0]; if (CB_REFERENCE_P (yyvsp[0])) { @@ -9533,29 +9580,29 @@ yyparse (void) eval_check[eval_level][eval_inc++] = 1; } } -#line 9537 "parser.c" +#line 9584 "parser.c" break; case 843: /* evaluate_subject: "TRUE" */ -#line 4643 "parser.y" +#line 4651 "parser.y" { yyval = cb_true; eval_check[eval_level][eval_inc++] = 2; } -#line 9546 "parser.c" +#line 9593 "parser.c" break; case 844: /* evaluate_subject: "FALSE" */ -#line 4648 "parser.y" +#line 4656 "parser.y" { yyval = cb_false; eval_check[eval_level][eval_inc++] = 3; } -#line 9555 "parser.c" +#line 9602 "parser.c" break; case 845: /* evaluate_condition_list: evaluate_case_list evaluate_other */ -#line 4656 "parser.y" +#line 4664 "parser.y" { yyval = yyvsp[-1]; if (yyvsp[0]) { @@ -9581,31 +9628,31 @@ yyparse (void) yyval = cb_list_add (yyval, yyvsp[0]); } } -#line 9585 "parser.c" +#line 9632 "parser.c" break; case 846: /* evaluate_case_list: evaluate_case */ -#line 4684 "parser.y" +#line 4692 "parser.y" { yyval = cb_list_init (yyvsp[0]); } -#line 9591 "parser.c" +#line 9638 "parser.c" break; case 847: /* evaluate_case_list: evaluate_case_list evaluate_case */ -#line 4686 "parser.y" +#line 4694 "parser.y" { yyval = cb_list_add (yyvsp[-1], yyvsp[0]); } -#line 9597 "parser.c" +#line 9644 "parser.c" break; case 848: /* $@52: %empty */ -#line 4691 "parser.y" +#line 4699 "parser.y" { check_unreached = 0; } -#line 9605 "parser.c" +#line 9652 "parser.c" break; case 849: /* evaluate_case: evaluate_when_list $@52 statement_list */ -#line 4695 "parser.y" +#line 4703 "parser.y" { if (!cb_allow_empty_imperative_statement && yyvsp[0] == NULL) { cb_error (_("syntax error")); @@ -9613,27 +9660,27 @@ yyparse (void) yyval = cb_cons (yyvsp[0], yyvsp[-2]); eval_inc2 = 0; } -#line 9617 "parser.c" +#line 9664 "parser.c" break; case 850: /* evaluate_other: %empty */ -#line 4706 "parser.y" +#line 4714 "parser.y" { yyval = NULL; } -#line 9625 "parser.c" +#line 9672 "parser.c" break; case 851: /* $@53: %empty */ -#line 4710 "parser.y" +#line 4718 "parser.y" { check_unreached = 0; } -#line 9633 "parser.c" +#line 9680 "parser.c" break; case 852: /* evaluate_other: "WHEN OTHER" $@53 statement_list */ -#line 4714 "parser.y" +#line 4722 "parser.y" { if (!cb_allow_empty_imperative_statement && yyvsp[0] == NULL) { cb_error (_("syntax error")); @@ -9641,40 +9688,40 @@ yyparse (void) yyval = cb_cons (yyvsp[0], NULL); eval_inc2 = 0; } -#line 9645 "parser.c" +#line 9692 "parser.c" break; case 853: /* evaluate_when_list: WHEN evaluate_object_list */ -#line 4724 "parser.y" +#line 4732 "parser.y" { yyval = cb_list_init (yyvsp[0]); } -#line 9651 "parser.c" +#line 9698 "parser.c" break; case 854: /* evaluate_when_list: evaluate_when_list WHEN evaluate_object_list */ -#line 4726 "parser.y" +#line 4734 "parser.y" { yyval = cb_list_add (yyvsp[-2], yyvsp[0]); } -#line 9657 "parser.c" +#line 9704 "parser.c" break; case 855: /* evaluate_object_list: evaluate_object */ -#line 4730 "parser.y" +#line 4738 "parser.y" { yyval = cb_list_init (yyvsp[0]); } -#line 9663 "parser.c" +#line 9710 "parser.c" break; case 856: /* evaluate_object_list: evaluate_object_list _also evaluate_object */ -#line 4733 "parser.y" +#line 4741 "parser.y" { if (!cb_allow_missing_also_clause_in_evaluate && yyvsp[-1] != cb_int1) { cb_error (_("Invalid expression")); } yyval = cb_list_add (yyvsp[-2], yyvsp[0]); } -#line 9674 "parser.c" +#line 9721 "parser.c" break; case 857: /* evaluate_object: partial_expr opt_evaluate_thru_expr */ -#line 4743 "parser.y" +#line 4751 "parser.y" { cb_tree not; cb_tree e1; @@ -9703,65 +9750,65 @@ yyparse (void) eval_inc2++; } } -#line 9707 "parser.c" +#line 9754 "parser.c" break; case 858: /* evaluate_object: ANY */ -#line 4771 "parser.y" +#line 4779 "parser.y" { yyval = cb_any; eval_inc2++; } -#line 9713 "parser.c" +#line 9760 "parser.c" break; case 859: /* evaluate_object: "TRUE" */ -#line 4772 "parser.y" +#line 4780 "parser.y" { yyval = cb_true; eval_inc2++; } -#line 9719 "parser.c" +#line 9766 "parser.c" break; case 860: /* evaluate_object: "FALSE" */ -#line 4773 "parser.y" +#line 4781 "parser.y" { yyval = cb_false; eval_inc2++; } -#line 9725 "parser.c" +#line 9772 "parser.c" break; case 861: /* opt_evaluate_thru_expr: %empty */ -#line 4776 "parser.y" +#line 4784 "parser.y" { yyval = NULL; } -#line 9731 "parser.c" +#line 9778 "parser.c" break; case 862: /* opt_evaluate_thru_expr: THRU expr */ -#line 4777 "parser.y" +#line 4785 "parser.y" { yyval = yyvsp[0]; } -#line 9737 "parser.c" +#line 9784 "parser.c" break; case 863: /* end_evaluate: %empty */ -#line 4781 "parser.y" +#line 4789 "parser.y" { terminator_warning (TERM_EVALUATE); } -#line 9743 "parser.c" +#line 9790 "parser.c" break; case 864: /* end_evaluate: "END-EVALUATE" */ -#line 4782 "parser.y" +#line 4790 "parser.y" { terminator_clear (TERM_EVALUATE); } -#line 9749 "parser.c" +#line 9796 "parser.c" break; case 865: /* $@54: %empty */ -#line 4791 "parser.y" +#line 4799 "parser.y" { BEGIN_STATEMENT ("EXIT", 0); } -#line 9755 "parser.c" +#line 9802 "parser.c" break; case 867: /* exit_body: %empty */ -#line 4796 "parser.y" +#line 4804 "parser.y" { /* nothing */ } -#line 9761 "parser.c" +#line 9808 "parser.c" break; case 868: /* exit_body: PROGRAM */ -#line 4798 "parser.y" +#line 4806 "parser.y" { if (in_declaratives && use_global_ind) { cb_error (_("EXIT PROGRAM is not allowed within a USE GLOBAL procedure")); @@ -9769,11 +9816,11 @@ yyparse (void) check_unreached = 1; cb_emit_exit (0); } -#line 9773 "parser.c" +#line 9820 "parser.c" break; case 869: /* exit_body: PERFORM */ -#line 4806 "parser.y" +#line 4814 "parser.y" { if (!perform_stack) { cb_error (_("EXIT PERFORM is only valid with inline PERFORM")); @@ -9781,11 +9828,11 @@ yyparse (void) cb_emit_java_break (); } } -#line 9785 "parser.c" +#line 9832 "parser.c" break; case 870: /* exit_body: PERFORM CYCLE */ -#line 4814 "parser.y" +#line 4822 "parser.y" { if (!perform_stack) { cb_error (_("EXIT PERFORM is only valid with inline PERFORM")); @@ -9793,11 +9840,11 @@ yyparse (void) cb_emit_java_continue (); } } -#line 9797 "parser.c" +#line 9844 "parser.c" break; case 871: /* exit_body: SECTION */ -#line 4822 "parser.y" +#line 4830 "parser.y" { cb_tree plabel; char name[64]; @@ -9815,11 +9862,11 @@ yyparse (void) cb_emit_goto (cb_list_init (current_section->exit_label_ref), NULL); } } -#line 9819 "parser.c" +#line 9866 "parser.c" break; case 872: /* exit_body: PARAGRAPH */ -#line 4840 "parser.y" +#line 4848 "parser.y" { cb_tree plabel; char name[64]; @@ -9837,461 +9884,461 @@ yyparse (void) cb_emit_goto (cb_list_init (current_paragraph->exit_label_ref), NULL); } } -#line 9841 "parser.c" +#line 9888 "parser.c" break; case 873: /* $@55: %empty */ -#line 4864 "parser.y" +#line 4872 "parser.y" { BEGIN_STATEMENT ("FREE", 0); } -#line 9847 "parser.c" +#line 9894 "parser.c" break; case 874: /* free_statement: FREE $@55 target_x_list */ -#line 4866 "parser.y" +#line 4874 "parser.y" { cb_emit_free (yyvsp[0]); } -#line 9855 "parser.c" +#line 9902 "parser.c" break; case 875: /* $@56: %empty */ -#line 4877 "parser.y" +#line 4885 "parser.y" { BEGIN_STATEMENT ("GENERATE", 0); } -#line 9861 "parser.c" +#line 9908 "parser.c" break; case 876: /* generate_statement: GENERATE $@56 identifier */ -#line 4879 "parser.y" +#line 4887 "parser.y" { PENDING("GENERATE"); } -#line 9869 "parser.c" +#line 9916 "parser.c" break; case 877: /* $@57: %empty */ -#line 4890 "parser.y" +#line 4898 "parser.y" { BEGIN_STATEMENT ("GO TO", 0); } -#line 9875 "parser.c" +#line 9922 "parser.c" break; case 878: /* goto_statement: GO _to $@57 procedure_name_list goto_depending */ -#line 4892 "parser.y" +#line 4900 "parser.y" { cb_emit_goto (yyvsp[-1], yyvsp[0]); } -#line 9883 "parser.c" +#line 9930 "parser.c" break; case 879: /* goto_depending: %empty */ -#line 4899 "parser.y" +#line 4907 "parser.y" { check_unreached = 1; yyval = NULL; } -#line 9892 "parser.c" +#line 9939 "parser.c" break; case 880: /* goto_depending: DEPENDING _on identifier */ -#line 4904 "parser.y" +#line 4912 "parser.y" { check_unreached = 0; yyval = yyvsp[0]; } -#line 9901 "parser.c" +#line 9948 "parser.c" break; case 881: /* $@58: %empty */ -#line 4916 "parser.y" +#line 4924 "parser.y" { BEGIN_STATEMENT ("GOBACK", 0); } -#line 9907 "parser.c" +#line 9954 "parser.c" break; case 882: /* goback_statement: GOBACK $@58 */ -#line 4917 "parser.y" +#line 4925 "parser.y" { check_unreached = 1; cb_emit_exit (1); } -#line 9916 "parser.c" +#line 9963 "parser.c" break; case 883: /* $@59: %empty */ -#line 4929 "parser.y" +#line 4937 "parser.y" { BEGIN_STATEMENT ("IF", TERM_IF); } -#line 9922 "parser.c" +#line 9969 "parser.c" break; case 884: /* $@60: %empty */ -#line 4931 "parser.y" +#line 4939 "parser.y" { check_unreached = 0; } -#line 9930 "parser.c" +#line 9977 "parser.c" break; case 885: /* if_statement: IF $@59 condition _then $@60 statement_list if_else_sentence end_if */ -#line 4936 "parser.y" +#line 4944 "parser.y" { if (!cb_allow_empty_imperative_statement && yyvsp[-2] == NULL) { cb_error (_("syntax error")); } cb_emit_if (yyvsp[-5], yyvsp[-2], yyvsp[-1]); } -#line 9941 "parser.c" +#line 9988 "parser.c" break; case 887: /* if_else_sentence: %empty */ -#line 4947 "parser.y" +#line 4955 "parser.y" { yyval = NULL; } -#line 9949 "parser.c" +#line 9996 "parser.c" break; case 888: /* $@61: %empty */ -#line 4951 "parser.y" +#line 4959 "parser.y" { check_unreached = 0; } -#line 9957 "parser.c" +#line 10004 "parser.c" break; case 889: /* if_else_sentence: ELSE $@61 statement_list */ -#line 4955 "parser.y" +#line 4963 "parser.y" { if (!cb_allow_empty_imperative_statement && yyvsp[0] == NULL) { cb_error (_("syntax error")); } yyval = yyvsp[0]; } -#line 9968 "parser.c" +#line 10015 "parser.c" break; case 890: /* end_if: %empty */ -#line 4964 "parser.y" +#line 4972 "parser.y" { terminator_warning (TERM_IF); } -#line 9974 "parser.c" +#line 10021 "parser.c" break; case 891: /* end_if: "END-IF" */ -#line 4965 "parser.y" +#line 4973 "parser.y" { terminator_clear (TERM_IF); } -#line 9980 "parser.c" +#line 10027 "parser.c" break; case 892: /* $@62: %empty */ -#line 4974 "parser.y" +#line 4982 "parser.y" { BEGIN_STATEMENT ("INITIALIZE", 0); } -#line 9986 "parser.c" +#line 10033 "parser.c" break; case 893: /* initialize_statement: INITIALIZE $@62 target_x_list initialize_filler initialize_value initialize_replacing initialize_default */ -#line 4976 "parser.y" +#line 4984 "parser.y" { cb_emit_initialize (yyvsp[-4], yyvsp[-3], yyvsp[-2], yyvsp[-1], yyvsp[0]); } -#line 9994 "parser.c" +#line 10041 "parser.c" break; case 894: /* initialize_filler: %empty */ -#line 4982 "parser.y" +#line 4990 "parser.y" { yyval = NULL; } -#line 10000 "parser.c" +#line 10047 "parser.c" break; case 895: /* initialize_filler: _with FILLER */ -#line 4983 "parser.y" +#line 4991 "parser.y" { yyval = cb_true; } -#line 10006 "parser.c" +#line 10053 "parser.c" break; case 896: /* initialize_value: %empty */ -#line 4987 "parser.y" +#line 4995 "parser.y" { yyval = NULL; } -#line 10012 "parser.c" +#line 10059 "parser.c" break; case 897: /* initialize_value: ALL _to VALUE */ -#line 4988 "parser.y" +#line 4996 "parser.y" { yyval = cb_true; } -#line 10018 "parser.c" +#line 10065 "parser.c" break; case 898: /* initialize_value: initialize_category _to VALUE */ -#line 4989 "parser.y" +#line 4997 "parser.y" { yyval = yyvsp[-2]; } -#line 10024 "parser.c" +#line 10071 "parser.c" break; case 899: /* initialize_replacing: %empty */ -#line 4993 "parser.y" +#line 5001 "parser.y" { yyval = NULL; } -#line 10030 "parser.c" +#line 10077 "parser.c" break; case 900: /* initialize_replacing: REPLACING initialize_replacing_list */ -#line 4995 "parser.y" +#line 5003 "parser.y" { yyval = yyvsp[0]; } -#line 10036 "parser.c" +#line 10083 "parser.c" break; case 901: /* initialize_replacing_list: initialize_replacing_item */ -#line 4999 "parser.y" +#line 5007 "parser.y" { yyval = yyvsp[0]; } -#line 10042 "parser.c" +#line 10089 "parser.c" break; case 902: /* initialize_replacing_list: initialize_replacing_list initialize_replacing_item */ -#line 5001 "parser.y" +#line 5009 "parser.y" { yyval = cb_list_append (yyvsp[-1], yyvsp[0]); } -#line 10048 "parser.c" +#line 10095 "parser.c" break; case 903: /* initialize_replacing_item: initialize_category _data BY x */ -#line 5005 "parser.y" +#line 5013 "parser.y" { yyval = cb_build_pair (yyvsp[-3], yyvsp[0]); } -#line 10054 "parser.c" +#line 10101 "parser.c" break; case 904: /* initialize_category: ALPHABETIC */ -#line 5009 "parser.y" +#line 5017 "parser.y" { yyval = cb_int (CB_CATEGORY_ALPHABETIC); } -#line 10060 "parser.c" +#line 10107 "parser.c" break; case 905: /* initialize_category: ALPHANUMERIC */ -#line 5010 "parser.y" +#line 5018 "parser.y" { yyval = cb_int (CB_CATEGORY_ALPHANUMERIC); } -#line 10066 "parser.c" +#line 10113 "parser.c" break; case 906: /* initialize_category: NUMERIC */ -#line 5011 "parser.y" +#line 5019 "parser.y" { yyval = cb_int (CB_CATEGORY_NUMERIC); } -#line 10072 "parser.c" +#line 10119 "parser.c" break; case 907: /* initialize_category: "ALPHANUMERIC-EDITED" */ -#line 5012 "parser.y" +#line 5020 "parser.y" { yyval = cb_int (CB_CATEGORY_ALPHANUMERIC_EDITED); } -#line 10078 "parser.c" +#line 10125 "parser.c" break; case 908: /* initialize_category: "NUMERIC-EDITED" */ -#line 5013 "parser.y" +#line 5021 "parser.y" { yyval = cb_int (CB_CATEGORY_NUMERIC_EDITED); } -#line 10084 "parser.c" +#line 10131 "parser.c" break; case 909: /* initialize_category: NATIONAL */ -#line 5014 "parser.y" +#line 5022 "parser.y" { yyval = cb_int (CB_CATEGORY_NATIONAL); } -#line 10090 "parser.c" +#line 10137 "parser.c" break; case 910: /* initialize_category: "NATIONAL-EDITED" */ -#line 5015 "parser.y" +#line 5023 "parser.y" { yyval = cb_int (CB_CATEGORY_NATIONAL_EDITED); } -#line 10096 "parser.c" +#line 10143 "parser.c" break; case 911: /* initialize_default: %empty */ -#line 5019 "parser.y" +#line 5027 "parser.y" { yyval = NULL; } -#line 10102 "parser.c" +#line 10149 "parser.c" break; case 912: /* initialize_default: DEFAULT */ -#line 5020 "parser.y" +#line 5028 "parser.y" { yyval = cb_true; } -#line 10108 "parser.c" +#line 10155 "parser.c" break; case 913: /* $@63: %empty */ -#line 5029 "parser.y" +#line 5037 "parser.y" { BEGIN_STATEMENT ("INITIATE", 0); } -#line 10114 "parser.c" +#line 10161 "parser.c" break; case 914: /* initiate_statement: INITIATE $@63 identifier_list */ -#line 5031 "parser.y" +#line 5039 "parser.y" { PENDING("INITIATE"); } -#line 10122 "parser.c" +#line 10169 "parser.c" break; case 915: /* $@64: %empty */ -#line 5042 "parser.y" +#line 5050 "parser.y" { BEGIN_STATEMENT ("INSPECT", 0); sending_id = 0; inspect_keyword = 0; } -#line 10132 "parser.c" +#line 10179 "parser.c" break; case 917: /* send_identifier: identifier */ -#line 5051 "parser.y" +#line 5059 "parser.y" { save_tree_1 = yyvsp[0]; sending_id = 0; } -#line 10138 "parser.c" +#line 10185 "parser.c" break; case 918: /* send_identifier: literal */ -#line 5052 "parser.y" +#line 5060 "parser.y" { save_tree_1 = yyvsp[0]; sending_id = 1; } -#line 10144 "parser.c" +#line 10191 "parser.c" break; case 919: /* send_identifier: function */ -#line 5053 "parser.y" +#line 5061 "parser.y" { save_tree_1 = yyvsp[0]; sending_id = 1; } -#line 10150 "parser.c" +#line 10197 "parser.c" break; case 922: /* inspect_item: inspect_tallying */ -#line 5062 "parser.y" +#line 5070 "parser.y" { cb_emit_inspect (save_tree_1, yyvsp[0], cb_int0, 0); } -#line 10156 "parser.c" +#line 10203 "parser.c" break; case 923: /* inspect_item: inspect_replacing */ -#line 5063 "parser.y" +#line 5071 "parser.y" { cb_emit_inspect (save_tree_1, yyvsp[0], cb_int1, 1); } -#line 10162 "parser.c" +#line 10209 "parser.c" break; case 924: /* inspect_item: inspect_converting */ -#line 5064 "parser.y" +#line 5072 "parser.y" { cb_emit_inspect (save_tree_1, yyvsp[0], cb_int0, 2); } -#line 10168 "parser.c" +#line 10215 "parser.c" break; case 925: /* $@65: %empty */ -#line 5070 "parser.y" +#line 5078 "parser.y" { cb_init_tarrying (); } -#line 10174 "parser.c" +#line 10221 "parser.c" break; case 926: /* inspect_tallying: TALLYING $@65 tallying_list */ -#line 5071 "parser.y" +#line 5079 "parser.y" { yyval = yyvsp[0]; } -#line 10180 "parser.c" +#line 10227 "parser.c" break; case 927: /* tallying_list: tallying_item */ -#line 5075 "parser.y" +#line 5083 "parser.y" { yyval = yyvsp[0]; } -#line 10186 "parser.c" +#line 10233 "parser.c" break; case 928: /* tallying_list: tallying_list tallying_item */ -#line 5076 "parser.y" +#line 5084 "parser.y" { yyval = cb_list_append (yyvsp[-1], yyvsp[0]); } -#line 10192 "parser.c" +#line 10239 "parser.c" break; case 929: /* tallying_item: simple_value FOR */ -#line 5080 "parser.y" +#line 5088 "parser.y" { yyval = cb_build_tarrying_data (yyvsp[-1]); } -#line 10198 "parser.c" +#line 10245 "parser.c" break; case 930: /* tallying_item: CHARACTERS inspect_region */ -#line 5081 "parser.y" +#line 5089 "parser.y" { yyval = cb_build_tarrying_characters (yyvsp[0]); } -#line 10204 "parser.c" +#line 10251 "parser.c" break; case 931: /* tallying_item: ALL */ -#line 5082 "parser.y" +#line 5090 "parser.y" { yyval = cb_build_tarrying_all (); } -#line 10210 "parser.c" +#line 10257 "parser.c" break; case 932: /* tallying_item: LEADING */ -#line 5083 "parser.y" +#line 5091 "parser.y" { yyval = cb_build_tarrying_leading (); } -#line 10216 "parser.c" +#line 10263 "parser.c" break; case 933: /* tallying_item: TRAILING */ -#line 5084 "parser.y" +#line 5092 "parser.y" { yyval = cb_build_tarrying_trailing (); } -#line 10222 "parser.c" +#line 10269 "parser.c" break; case 934: /* tallying_item: simple_value inspect_region */ -#line 5085 "parser.y" +#line 5093 "parser.y" { yyval = cb_build_tarrying_value (yyvsp[-1], yyvsp[0]); } -#line 10228 "parser.c" +#line 10275 "parser.c" break; case 935: /* inspect_replacing: REPLACING replacing_list */ -#line 5091 "parser.y" +#line 5099 "parser.y" { yyval = yyvsp[0]; inspect_keyword = 0; } -#line 10234 "parser.c" +#line 10281 "parser.c" break; case 936: /* replacing_list: replacing_item */ -#line 5095 "parser.y" +#line 5103 "parser.y" { yyval = yyvsp[0]; } -#line 10240 "parser.c" +#line 10287 "parser.c" break; case 937: /* replacing_list: replacing_list replacing_item */ -#line 5096 "parser.y" +#line 5104 "parser.y" { yyval = cb_list_append (yyvsp[-1], yyvsp[0]); } -#line 10246 "parser.c" +#line 10293 "parser.c" break; case 938: /* replacing_item: CHARACTERS BY simple_value inspect_region */ -#line 5101 "parser.y" +#line 5109 "parser.y" { yyval = cb_build_replacing_characters (yyvsp[-1], yyvsp[0], save_tree_1); inspect_keyword = 0; } -#line 10255 "parser.c" +#line 10302 "parser.c" break; case 939: /* replacing_item: rep_keyword replacing_region */ -#line 5105 "parser.y" +#line 5113 "parser.y" { yyval = yyvsp[0]; } -#line 10261 "parser.c" +#line 10308 "parser.c" break; case 940: /* rep_keyword: %empty */ -#line 5109 "parser.y" +#line 5117 "parser.y" { /* Nothing */ } -#line 10267 "parser.c" +#line 10314 "parser.c" break; case 941: /* rep_keyword: ALL */ -#line 5110 "parser.y" +#line 5118 "parser.y" { inspect_keyword = 1; } -#line 10273 "parser.c" +#line 10320 "parser.c" break; case 942: /* rep_keyword: LEADING */ -#line 5111 "parser.y" +#line 5119 "parser.y" { inspect_keyword = 2; } -#line 10279 "parser.c" +#line 10326 "parser.c" break; case 943: /* rep_keyword: FIRST */ -#line 5112 "parser.y" +#line 5120 "parser.y" { inspect_keyword = 3; } -#line 10285 "parser.c" +#line 10332 "parser.c" break; case 944: /* rep_keyword: TRAILING */ -#line 5113 "parser.y" +#line 5121 "parser.y" { inspect_keyword = 4; } -#line 10291 "parser.c" +#line 10338 "parser.c" break; case 945: /* replacing_region: simple_value BY simple_all_value inspect_region */ -#line 5118 "parser.y" +#line 5126 "parser.y" { switch (inspect_keyword) { case 1: @@ -10312,11 +10359,11 @@ yyparse (void) break; } } -#line 10316 "parser.c" +#line 10363 "parser.c" break; case 946: /* inspect_converting: CONVERTING simple_value TO simple_all_value inspect_region */ -#line 5144 "parser.y" +#line 5152 "parser.y" { if (cb_validate_inspect (save_tree_1, yyvsp[-3], yyvsp[-1]) < 0 ) { yyval = cb_error_node; @@ -10324,91 +10371,91 @@ yyparse (void) yyval = cb_build_converting (yyvsp[-3], yyvsp[-1], yyvsp[0]); } } -#line 10328 "parser.c" +#line 10375 "parser.c" break; case 947: /* inspect_region: %empty */ -#line 5156 "parser.y" +#line 5164 "parser.y" { yyval = cb_build_inspect_region_start (); } -#line 10334 "parser.c" +#line 10381 "parser.c" break; case 948: /* inspect_region: inspect_region before_or_after _initial x */ -#line 5158 "parser.y" +#line 5166 "parser.y" { yyval = cb_build_inspect_region (yyvsp[-3], yyvsp[-2], yyvsp[0]); } -#line 10340 "parser.c" +#line 10387 "parser.c" break; case 951: /* $@66: %empty */ -#line 5169 "parser.y" +#line 5177 "parser.y" { BEGIN_STATEMENT ("MERGE", 0); } -#line 10346 "parser.c" +#line 10393 "parser.c" break; case 953: /* $@67: %empty */ -#line 5179 "parser.y" +#line 5187 "parser.y" { BEGIN_STATEMENT ("MOVE", 0); } -#line 10352 "parser.c" +#line 10399 "parser.c" break; case 955: /* move_body: x TO target_x_list */ -#line 5185 "parser.y" +#line 5193 "parser.y" { cb_emit_move (yyvsp[-2], yyvsp[0]); } -#line 10360 "parser.c" +#line 10407 "parser.c" break; case 956: /* move_body: CORRESPONDING x TO target_x_list */ -#line 5189 "parser.y" +#line 5197 "parser.y" { cb_emit_move_corresponding (yyvsp[-2], yyvsp[0]); } -#line 10368 "parser.c" +#line 10415 "parser.c" break; case 957: /* $@68: %empty */ -#line 5200 "parser.y" +#line 5208 "parser.y" { BEGIN_STATEMENT ("MULTIPLY", TERM_MULTIPLY); } -#line 10374 "parser.c" +#line 10421 "parser.c" break; case 959: /* multiply_body: x BY arithmetic_x_list on_size_error */ -#line 5207 "parser.y" +#line 5215 "parser.y" { cb_emit_arithmetic (yyvsp[-1], '*', yyvsp[-3]); } -#line 10382 "parser.c" +#line 10429 "parser.c" break; case 960: /* multiply_body: x BY x GIVING arithmetic_x_list on_size_error */ -#line 5211 "parser.y" +#line 5219 "parser.y" { cb_emit_arithmetic (yyvsp[-1], 0, cb_build_binary_op (yyvsp[-5], '*', yyvsp[-3])); } -#line 10390 "parser.c" +#line 10437 "parser.c" break; case 961: /* end_multiply: %empty */ -#line 5217 "parser.y" +#line 5225 "parser.y" { terminator_warning (TERM_MULTIPLY); } -#line 10396 "parser.c" +#line 10443 "parser.c" break; case 962: /* end_multiply: "END-MULTIPLY" */ -#line 5218 "parser.y" +#line 5226 "parser.y" { terminator_clear (TERM_MULTIPLY); } -#line 10402 "parser.c" +#line 10449 "parser.c" break; case 963: /* $@69: %empty */ -#line 5227 "parser.y" +#line 5235 "parser.y" { BEGIN_STATEMENT ("OPEN", 0); } -#line 10408 "parser.c" +#line 10455 "parser.c" break; case 966: /* open_list: open_list open_mode open_sharing file_name_list open_option */ -#line 5234 "parser.y" +#line 5242 "parser.y" { cb_tree l; for (l = yyvsp[-1]; l; l = CB_CHAIN (l)) { @@ -10418,217 +10465,217 @@ yyparse (void) } } } -#line 10422 "parser.c" +#line 10469 "parser.c" break; case 967: /* open_mode: INPUT */ -#line 5246 "parser.y" +#line 5254 "parser.y" { yyval = cb_int (COB_OPEN_INPUT); } -#line 10428 "parser.c" +#line 10475 "parser.c" break; case 968: /* open_mode: OUTPUT */ -#line 5247 "parser.y" +#line 5255 "parser.y" { yyval = cb_int (COB_OPEN_OUTPUT); } -#line 10434 "parser.c" +#line 10481 "parser.c" break; case 969: /* open_mode: "I-O" */ -#line 5248 "parser.y" +#line 5256 "parser.y" { yyval = cb_int (COB_OPEN_I_O); } -#line 10440 "parser.c" +#line 10487 "parser.c" break; case 970: /* open_mode: EXTEND */ -#line 5249 "parser.y" +#line 5257 "parser.y" { yyval = cb_int (COB_OPEN_EXTEND); } -#line 10446 "parser.c" +#line 10493 "parser.c" break; case 971: /* open_sharing: %empty */ -#line 5253 "parser.y" +#line 5261 "parser.y" { yyval = NULL; } -#line 10452 "parser.c" +#line 10499 "parser.c" break; case 972: /* open_sharing: SHARING _with sharing_option */ -#line 5254 "parser.y" +#line 5262 "parser.y" { yyval = yyvsp[0]; } -#line 10458 "parser.c" +#line 10505 "parser.c" break; case 973: /* open_option: %empty */ -#line 5258 "parser.y" +#line 5266 "parser.y" { yyval = NULL; } -#line 10464 "parser.c" +#line 10511 "parser.c" break; case 974: /* open_option: _with NO REWIND */ -#line 5259 "parser.y" +#line 5267 "parser.y" { yyval = NULL; } -#line 10470 "parser.c" +#line 10517 "parser.c" break; case 975: /* open_option: _with LOCK */ -#line 5260 "parser.y" +#line 5268 "parser.y" { PENDING ("OPEN ... WITH LOCK"); } -#line 10476 "parser.c" +#line 10523 "parser.c" break; case 976: /* $@70: %empty */ -#line 5272 "parser.y" +#line 5280 "parser.y" { BEGIN_STATEMENT ("PERFORM", TERM_PERFORM); } -#line 10482 "parser.c" +#line 10529 "parser.c" break; case 978: /* perform_body: perform_procedure perform_option */ -#line 5278 "parser.y" +#line 5286 "parser.y" { cb_emit_perform (yyvsp[0], yyvsp[-1]); } -#line 10490 "parser.c" +#line 10537 "parser.c" break; case 979: /* $@71: %empty */ -#line 5282 "parser.y" +#line 5290 "parser.y" { perform_stack = cb_cons (yyvsp[0], perform_stack); check_unreached = 0; } -#line 10499 "parser.c" +#line 10546 "parser.c" break; case 980: /* perform_body: perform_option $@71 statement_list end_perform */ -#line 5287 "parser.y" +#line 5295 "parser.y" { perform_stack = CB_CHAIN (perform_stack); cb_emit_perform (yyvsp[-3], yyvsp[-1]); } -#line 10508 "parser.c" +#line 10555 "parser.c" break; case 981: /* perform_body: perform_option "END-PERFORM" */ -#line 5292 "parser.y" +#line 5300 "parser.y" { cb_emit_perform (yyvsp[-1], NULL); } -#line 10516 "parser.c" +#line 10563 "parser.c" break; case 982: /* end_perform: %empty */ -#line 5298 "parser.y" +#line 5306 "parser.y" { terminator_error (); } -#line 10522 "parser.c" +#line 10569 "parser.c" break; case 983: /* end_perform: "END-PERFORM" */ -#line 5299 "parser.y" +#line 5307 "parser.y" { terminator_clear (TERM_PERFORM); } -#line 10528 "parser.c" +#line 10575 "parser.c" break; case 984: /* perform_procedure: procedure_name */ -#line 5304 "parser.y" +#line 5312 "parser.y" { CB_REFERENCE (yyvsp[0])->length = cb_true; /* return from $1 */ yyval = cb_build_pair (yyvsp[0], yyvsp[0]); } -#line 10537 "parser.c" +#line 10584 "parser.c" break; case 985: /* perform_procedure: procedure_name THRU procedure_name */ -#line 5309 "parser.y" +#line 5317 "parser.y" { CB_REFERENCE (yyvsp[0])->length = cb_true; /* return from $3 */ yyval = cb_build_pair (yyvsp[-2], yyvsp[0]); } -#line 10546 "parser.c" +#line 10593 "parser.c" break; case 986: /* perform_option: %empty */ -#line 5317 "parser.y" +#line 5325 "parser.y" { yyval = cb_build_perform_once (NULL); } -#line 10554 "parser.c" +#line 10601 "parser.c" break; case 987: /* perform_option: FOREVER */ -#line 5321 "parser.y" +#line 5329 "parser.y" { yyval = cb_build_perform_forever (NULL); } -#line 10562 "parser.c" +#line 10609 "parser.c" break; case 988: /* perform_option: id_or_lit_or_func TIMES */ -#line 5325 "parser.y" +#line 5333 "parser.y" { yyval = cb_build_perform_times (yyvsp[-1]); current_program->loop_counter++; } -#line 10571 "parser.c" +#line 10618 "parser.c" break; case 989: /* perform_option: perform_test UNTIL condition */ -#line 5330 "parser.y" +#line 5338 "parser.y" { cb_tree varying; varying = cb_list_init (cb_build_perform_varying (NULL, NULL, NULL, yyvsp[0])); yyval = cb_build_perform_until (yyvsp[-2], varying); } -#line 10582 "parser.c" +#line 10629 "parser.c" break; case 990: /* perform_option: perform_test VARYING perform_varying_list */ -#line 5337 "parser.y" +#line 5345 "parser.y" { yyval = cb_build_perform_until (yyvsp[-2], yyvsp[0]); } -#line 10590 "parser.c" +#line 10637 "parser.c" break; case 991: /* perform_test: %empty */ -#line 5343 "parser.y" +#line 5351 "parser.y" { yyval = CB_BEFORE; } -#line 10596 "parser.c" +#line 10643 "parser.c" break; case 992: /* perform_test: _with TEST before_or_after */ -#line 5344 "parser.y" +#line 5352 "parser.y" { yyval = yyvsp[0]; } -#line 10602 "parser.c" +#line 10649 "parser.c" break; case 993: /* perform_varying_list: perform_varying */ -#line 5348 "parser.y" +#line 5356 "parser.y" { yyval = cb_list_init (yyvsp[0]); } -#line 10608 "parser.c" +#line 10655 "parser.c" break; case 994: /* perform_varying_list: perform_varying_list AFTER perform_varying */ -#line 5350 "parser.y" +#line 5358 "parser.y" { yyval = cb_list_add (yyvsp[-2], yyvsp[0]); } -#line 10614 "parser.c" +#line 10661 "parser.c" break; case 995: /* perform_varying: identifier FROM x BY x UNTIL condition */ -#line 5355 "parser.y" +#line 5363 "parser.y" { yyval = cb_build_perform_varying (yyvsp[-6], yyvsp[-4], yyvsp[-2], yyvsp[0]); } -#line 10622 "parser.c" +#line 10669 "parser.c" break; case 996: /* $@72: %empty */ -#line 5366 "parser.y" +#line 5374 "parser.y" { BEGIN_STATEMENT ("READ", TERM_READ); } -#line 10628 "parser.c" +#line 10675 "parser.c" break; case 997: /* read_statement: READ $@72 file_name flag_next _record read_into with_lock read_key read_handler end_read */ -#line 5369 "parser.y" +#line 5377 "parser.y" { if (yyvsp[-7] != cb_error_node) { if (cb_use_invalidkey_handler_on_status34 && @@ -10637,9 +10684,7 @@ yyparse (void) CB_FILE(cb_ref (yyvsp[-7]))->organization != COB_ORG_INDEXED)) { current_statement->handler_id = COB_EC_I_O_PERMANENT_ERROR; } - if (yyvsp[-3] && (CB_FILE(cb_ref (yyvsp[-7]))->lock_mode & COB_LOCK_AUTOMATIC)) { - cb_error (_("LOCK clause invalid with file LOCK AUTOMATIC")); - } else if (yyvsp[-2] && + if (yyvsp[-2] && (CB_FILE(cb_ref (yyvsp[-7]))->organization != COB_ORG_RELATIVE && CB_FILE(cb_ref (yyvsp[-7]))->organization != COB_ORG_INDEXED)) { cb_error (_("KEY clause invalid with this file type")); @@ -10652,145 +10697,145 @@ yyparse (void) } } } -#line 10656 "parser.c" +#line 10701 "parser.c" break; case 998: /* read_into: %empty */ -#line 5395 "parser.y" +#line 5401 "parser.y" { yyval = NULL; } -#line 10662 "parser.c" +#line 10707 "parser.c" break; case 999: /* read_into: INTO identifier */ -#line 5396 "parser.y" +#line 5402 "parser.y" { yyval = yyvsp[0]; } -#line 10668 "parser.c" +#line 10713 "parser.c" break; case 1000: /* with_lock: %empty */ -#line 5400 "parser.y" +#line 5406 "parser.y" { yyval = NULL; } -#line 10674 "parser.c" +#line 10719 "parser.c" break; case 1001: /* with_lock: IGNORING LOCK */ -#line 5402 "parser.y" +#line 5408 "parser.y" { yyval = cb_int3; } -#line 10682 "parser.c" +#line 10727 "parser.c" break; case 1002: /* with_lock: _with LOCK */ -#line 5406 "parser.y" +#line 5412 "parser.y" { yyval = cb_int1; } -#line 10690 "parser.c" +#line 10735 "parser.c" break; case 1003: /* with_lock: _with NO LOCK */ -#line 5410 "parser.y" +#line 5416 "parser.y" { yyval = cb_int2; } -#line 10698 "parser.c" +#line 10743 "parser.c" break; case 1004: /* with_lock: _with IGNORE LOCK */ -#line 5414 "parser.y" +#line 5420 "parser.y" { yyval = cb_int3; } -#line 10706 "parser.c" +#line 10751 "parser.c" break; case 1005: /* with_lock: _with WAIT */ -#line 5418 "parser.y" +#line 5424 "parser.y" { yyval = cb_int4; } -#line 10714 "parser.c" +#line 10759 "parser.c" break; case 1006: /* read_key: %empty */ -#line 5424 "parser.y" +#line 5430 "parser.y" { yyval = NULL; } -#line 10720 "parser.c" +#line 10765 "parser.c" break; case 1007: /* read_key: KEY _is identifier_list */ -#line 5426 "parser.y" +#line 5432 "parser.y" { yyval = yyvsp[0]; } -#line 10728 "parser.c" +#line 10773 "parser.c" break; case 1011: /* end_read: %empty */ -#line 5437 "parser.y" +#line 5443 "parser.y" { terminator_warning (TERM_READ); } -#line 10734 "parser.c" +#line 10779 "parser.c" break; case 1012: /* end_read: "END-READ" */ -#line 5438 "parser.y" +#line 5444 "parser.y" { terminator_clear (TERM_READ); } -#line 10740 "parser.c" +#line 10785 "parser.c" break; case 1013: /* $@73: %empty */ -#line 5447 "parser.y" +#line 5453 "parser.y" { BEGIN_STATEMENT ("RELEASE", 0); } -#line 10746 "parser.c" +#line 10791 "parser.c" break; case 1014: /* release_statement: RELEASE $@73 record_name write_from */ -#line 5449 "parser.y" +#line 5455 "parser.y" { if (yyvsp[-1] != cb_error_node) { cb_emit_release (yyvsp[-1], yyvsp[0]); } } -#line 10756 "parser.c" +#line 10801 "parser.c" break; case 1015: /* $@74: %empty */ -#line 5462 "parser.y" +#line 5468 "parser.y" { BEGIN_STATEMENT ("RETURN", TERM_RETURN); } -#line 10762 "parser.c" +#line 10807 "parser.c" break; case 1016: /* return_statement: RETURN $@74 file_name _record read_into at_end end_return */ -#line 5465 "parser.y" +#line 5471 "parser.y" { if (yyvsp[-4] != cb_error_node) { cb_emit_return (yyvsp[-4], yyvsp[-2]); } } -#line 10772 "parser.c" +#line 10817 "parser.c" break; case 1017: /* end_return: %empty */ -#line 5473 "parser.y" +#line 5479 "parser.y" { terminator_warning (TERM_RETURN); } -#line 10778 "parser.c" +#line 10823 "parser.c" break; case 1018: /* end_return: "END-RETURN" */ -#line 5474 "parser.y" +#line 5480 "parser.y" { terminator_clear (TERM_RETURN); } -#line 10784 "parser.c" +#line 10829 "parser.c" break; case 1019: /* $@75: %empty */ -#line 5483 "parser.y" +#line 5489 "parser.y" { BEGIN_STATEMENT ("REWRITE", TERM_REWRITE); } -#line 10790 "parser.c" +#line 10835 "parser.c" break; case 1020: /* rewrite_statement: REWRITE $@75 record_name write_from write_lock opt_invalid_key end_rewrite */ -#line 5486 "parser.y" +#line 5492 "parser.y" { if (yyvsp[-4] != cb_error_node) { if (cb_use_invalidkey_handler_on_status34 && @@ -10802,238 +10847,238 @@ yyparse (void) cb_emit_rewrite (yyvsp[-4], yyvsp[-3], yyvsp[-2]); } } -#line 10806 "parser.c" +#line 10851 "parser.c" break; case 1021: /* write_lock: %empty */ -#line 5500 "parser.y" +#line 5506 "parser.y" { yyval = NULL; } -#line 10812 "parser.c" +#line 10857 "parser.c" break; case 1022: /* write_lock: _with LOCK */ -#line 5502 "parser.y" +#line 5508 "parser.y" { yyval = cb_int1; } -#line 10820 "parser.c" +#line 10865 "parser.c" break; case 1023: /* write_lock: _with NO LOCK */ -#line 5506 "parser.y" +#line 5512 "parser.y" { yyval = cb_int2; } -#line 10828 "parser.c" +#line 10873 "parser.c" break; case 1024: /* end_rewrite: %empty */ -#line 5512 "parser.y" +#line 5518 "parser.y" { terminator_warning (TERM_REWRITE); } -#line 10834 "parser.c" +#line 10879 "parser.c" break; case 1025: /* end_rewrite: "END-REWRITE" */ -#line 5513 "parser.y" +#line 5519 "parser.y" { terminator_clear (TERM_REWRITE); } -#line 10840 "parser.c" +#line 10885 "parser.c" break; case 1026: /* rollback_statement: ROLLBACK */ -#line 5523 "parser.y" +#line 5529 "parser.y" { BEGIN_STATEMENT ("ROLLBACK", 0); cb_emit_rollback (); } -#line 10849 "parser.c" +#line 10894 "parser.c" break; case 1027: /* $@76: %empty */ -#line 5535 "parser.y" +#line 5541 "parser.y" { BEGIN_STATEMENT ("SEARCH", TERM_SEARCH); } -#line 10855 "parser.c" +#line 10900 "parser.c" break; case 1029: /* search_body: table_name search_varying search_at_end search_whens */ -#line 5542 "parser.y" +#line 5548 "parser.y" { cb_emit_search (yyvsp[-3], yyvsp[-2], yyvsp[-1], yyvsp[0]); } -#line 10863 "parser.c" +#line 10908 "parser.c" break; case 1030: /* $@77: %empty */ -#line 5546 "parser.y" +#line 5552 "parser.y" { check_unreached = 0; } -#line 10871 "parser.c" +#line 10916 "parser.c" break; case 1031: /* search_body: ALL table_name search_at_end WHEN expr $@77 statement_list */ -#line 5550 "parser.y" +#line 5556 "parser.y" { cb_emit_search_all (yyvsp[-5], yyvsp[-4], yyvsp[-2], yyvsp[0]); } -#line 10879 "parser.c" +#line 10924 "parser.c" break; case 1032: /* search_varying: %empty */ -#line 5556 "parser.y" +#line 5562 "parser.y" { yyval = NULL; } -#line 10885 "parser.c" +#line 10930 "parser.c" break; case 1033: /* search_varying: VARYING identifier */ -#line 5557 "parser.y" +#line 5563 "parser.y" { yyval = yyvsp[0]; } -#line 10891 "parser.c" +#line 10936 "parser.c" break; case 1034: /* search_at_end: %empty */ -#line 5561 "parser.y" +#line 5567 "parser.y" { yyval = NULL; } -#line 10897 "parser.c" +#line 10942 "parser.c" break; case 1035: /* $@78: %empty */ -#line 5563 "parser.y" +#line 5569 "parser.y" { check_unreached = 0; } -#line 10905 "parser.c" +#line 10950 "parser.c" break; case 1036: /* search_at_end: _at END $@78 statement_list */ -#line 5567 "parser.y" +#line 5573 "parser.y" { yyval = yyvsp[0]; } -#line 10913 "parser.c" +#line 10958 "parser.c" break; case 1037: /* search_whens: search_when */ -#line 5573 "parser.y" +#line 5579 "parser.y" { yyval = yyvsp[0]; } -#line 10919 "parser.c" +#line 10964 "parser.c" break; case 1038: /* search_whens: search_when search_whens */ -#line 5574 "parser.y" +#line 5580 "parser.y" { yyval = yyvsp[-1]; CB_IF (yyvsp[-1])->stmt2 = yyvsp[0]; } -#line 10925 "parser.c" +#line 10970 "parser.c" break; case 1039: /* $@79: %empty */ -#line 5579 "parser.y" +#line 5585 "parser.y" { check_unreached = 0; } -#line 10933 "parser.c" +#line 10978 "parser.c" break; case 1040: /* search_when: WHEN condition $@79 statement_list */ -#line 5583 "parser.y" +#line 5589 "parser.y" { yyval = cb_build_if (yyvsp[-2], yyvsp[0], NULL); } -#line 10941 "parser.c" +#line 10986 "parser.c" break; case 1041: /* end_search: %empty */ -#line 5589 "parser.y" +#line 5595 "parser.y" { terminator_warning (TERM_SEARCH); } -#line 10947 "parser.c" +#line 10992 "parser.c" break; case 1042: /* end_search: "END-SEARCH" */ -#line 5590 "parser.y" +#line 5596 "parser.y" { terminator_clear (TERM_SEARCH); } -#line 10953 "parser.c" +#line 10998 "parser.c" break; case 1043: /* $@80: %empty */ -#line 5599 "parser.y" +#line 5605 "parser.y" { BEGIN_STATEMENT ("SET", 0); } -#line 10959 "parser.c" +#line 11004 "parser.c" break; case 1050: /* set_environment: ENVIRONMENT simple_value TO simple_value */ -#line 5615 "parser.y" +#line 5621 "parser.y" { cb_emit_setenv (yyvsp[-2], yyvsp[0]); } -#line 10967 "parser.c" +#line 11012 "parser.c" break; case 1051: /* set_to: target_x_list TO ENTRY alnum_or_id */ -#line 5624 "parser.y" +#line 5630 "parser.y" { cb_emit_set_to (yyvsp[-3], cb_build_ppointer (yyvsp[0])); } -#line 10975 "parser.c" +#line 11020 "parser.c" break; case 1052: /* set_to: target_x_list TO x */ -#line 5628 "parser.y" +#line 5634 "parser.y" { cb_emit_set_to (yyvsp[-2], yyvsp[0]); } -#line 10983 "parser.c" +#line 11028 "parser.c" break; case 1053: /* set_up_down: target_x_list up_or_down BY x */ -#line 5637 "parser.y" +#line 5643 "parser.y" { cb_emit_set_up_down (yyvsp[-3], yyvsp[-2], yyvsp[0]); } -#line 10991 "parser.c" +#line 11036 "parser.c" break; case 1054: /* up_or_down: UP */ -#line 5643 "parser.y" +#line 5649 "parser.y" { yyval = cb_int0; } -#line 10997 "parser.c" +#line 11042 "parser.c" break; case 1055: /* up_or_down: DOWN */ -#line 5644 "parser.y" +#line 5650 "parser.y" { yyval = cb_int1; } -#line 11003 "parser.c" +#line 11048 "parser.c" break; case 1058: /* set_to_on_off: mnemonic_name_list TO on_or_off */ -#line 5656 "parser.y" +#line 5662 "parser.y" { cb_emit_set_on_off (yyvsp[-2], yyvsp[0]); } -#line 11011 "parser.c" +#line 11056 "parser.c" break; case 1061: /* set_to_true_false: target_x_list TO "TRUE" */ -#line 5670 "parser.y" +#line 5676 "parser.y" { cb_emit_set_true (yyvsp[-2]); } -#line 11019 "parser.c" +#line 11064 "parser.c" break; case 1062: /* set_to_true_false: target_x_list TO "FALSE" */ -#line 5674 "parser.y" +#line 5680 "parser.y" { cb_emit_set_false (yyvsp[-2]); } -#line 11027 "parser.c" +#line 11072 "parser.c" break; case 1063: /* $@81: %empty */ -#line 5685 "parser.y" +#line 5691 "parser.y" { BEGIN_STATEMENT ("SORT", 0); } -#line 11033 "parser.c" +#line 11078 "parser.c" break; case 1065: /* $@82: %empty */ -#line 5691 "parser.y" +#line 5697 "parser.y" { cb_emit_sort_init (yyvsp[-3], yyvsp[-2], yyvsp[0]); if (CB_FILE_P (cb_ref (yyvsp[-3])) && yyvsp[-2] == NULL) { @@ -11042,27 +11087,27 @@ yyparse (void) /* used in sort_input/sort_output */ save_tree_1 = yyvsp[-3]; } -#line 11046 "parser.c" +#line 11091 "parser.c" break; case 1066: /* sort_body: qualified_word sort_key_list sort_duplicates sort_collating $@82 sort_input sort_output */ -#line 5700 "parser.y" +#line 5706 "parser.y" { cb_emit_sort_finish (yyvsp[-6]); } -#line 11054 "parser.c" +#line 11099 "parser.c" break; case 1067: /* sort_key_list: %empty */ -#line 5707 "parser.y" +#line 5713 "parser.y" { yyval = NULL; } -#line 11062 "parser.c" +#line 11107 "parser.c" break; case 1068: /* sort_key_list: sort_key_list _on ascending_or_descending _key _is opt_key_list */ -#line 5712 "parser.y" +#line 5718 "parser.y" { cb_tree l; @@ -11079,51 +11124,51 @@ yyparse (void) yyval = cb_list_append (yyvsp[-5], yyvsp[0]); } } -#line 11083 "parser.c" +#line 11128 "parser.c" break; case 1069: /* opt_key_list: %empty */ -#line 5731 "parser.y" +#line 5737 "parser.y" { yyval = NULL; } -#line 11089 "parser.c" +#line 11134 "parser.c" break; case 1070: /* opt_key_list: opt_key_list qualified_word */ -#line 5732 "parser.y" +#line 5738 "parser.y" { yyval = cb_list_add (yyvsp[-1], yyvsp[0]); } -#line 11095 "parser.c" +#line 11140 "parser.c" break; case 1072: /* sort_duplicates: with_dups _in_order */ -#line 5736 "parser.y" +#line 5742 "parser.y" { /* nothing */ } -#line 11101 "parser.c" +#line 11146 "parser.c" break; case 1073: /* sort_collating: %empty */ -#line 5740 "parser.y" +#line 5746 "parser.y" { yyval = cb_null; } -#line 11107 "parser.c" +#line 11152 "parser.c" break; case 1074: /* sort_collating: coll_sequence _is reference */ -#line 5741 "parser.y" +#line 5747 "parser.y" { yyval = cb_ref (yyvsp[0]); } -#line 11113 "parser.c" +#line 11158 "parser.c" break; case 1075: /* sort_input: %empty */ -#line 5746 "parser.y" +#line 5752 "parser.y" { if (CB_FILE_P (cb_ref (save_tree_1))) { cb_error (_("File sort requires USING or INPUT PROCEDURE")); } } -#line 11123 "parser.c" +#line 11168 "parser.c" break; case 1076: /* sort_input: USING file_name_list */ -#line 5752 "parser.y" +#line 5758 "parser.y" { if (!CB_FILE_P (cb_ref (save_tree_1))) { cb_error (_("USING invalid with table SORT")); @@ -11131,11 +11176,11 @@ yyparse (void) cb_emit_sort_using (save_tree_1, yyvsp[0]); } } -#line 11135 "parser.c" +#line 11180 "parser.c" break; case 1077: /* sort_input: INPUT PROCEDURE _is perform_procedure */ -#line 5760 "parser.y" +#line 5766 "parser.y" { if (!CB_FILE_P (cb_ref (save_tree_1))) { cb_error (_("INPUT PROCEDURE invalid with table SORT")); @@ -11143,21 +11188,21 @@ yyparse (void) cb_emit_sort_input (yyvsp[0], save_tree_1); } } -#line 11147 "parser.c" +#line 11192 "parser.c" break; case 1078: /* sort_output: %empty */ -#line 5771 "parser.y" +#line 5777 "parser.y" { if (CB_FILE_P (cb_ref (save_tree_1))) { cb_error (_("File sort requires GIVING or OUTPUT PROCEDURE")); } } -#line 11157 "parser.c" +#line 11202 "parser.c" break; case 1079: /* sort_output: GIVING file_name_list */ -#line 5777 "parser.y" +#line 5783 "parser.y" { if (!CB_FILE_P (cb_ref (save_tree_1))) { cb_error (_("GIVING invalid with table SORT")); @@ -11165,11 +11210,11 @@ yyparse (void) cb_emit_sort_giving (save_tree_1, yyvsp[0]); } } -#line 11169 "parser.c" +#line 11214 "parser.c" break; case 1080: /* sort_output: OUTPUT PROCEDURE _is perform_procedure */ -#line 5785 "parser.y" +#line 5791 "parser.y" { if (!CB_FILE_P (cb_ref (save_tree_1))) { cb_error (_("OUTPUT PROCEDURE invalid with table SORT")); @@ -11177,23 +11222,23 @@ yyparse (void) cb_emit_sort_output (yyvsp[0], save_tree_1); } } -#line 11181 "parser.c" +#line 11226 "parser.c" break; case 1081: /* $@83: %empty */ -#line 5800 "parser.y" +#line 5806 "parser.y" { BEGIN_STATEMENT ("START", TERM_START); } -#line 11187 "parser.c" +#line 11232 "parser.c" break; case 1082: /* @84: %empty */ -#line 5801 "parser.y" +#line 5807 "parser.y" { yyval = cb_int (COB_EQ); } -#line 11193 "parser.c" +#line 11238 "parser.c" break; case 1083: /* start_statement: START $@83 file_name @84 start_key opt_invalid_key end_start */ -#line 5804 "parser.y" +#line 5810 "parser.y" { if (CB_FILE_P (cb_ref (yyvsp[-4]))) { if (CB_FILE (cb_ref (yyvsp[-4]))->organization != COB_ORG_INDEXED && @@ -11208,394 +11253,394 @@ yyparse (void) yyval = cb_error_node; } } -#line 11212 "parser.c" +#line 11257 "parser.c" break; case 1084: /* start_key: %empty */ -#line 5821 "parser.y" +#line 5827 "parser.y" { yyval = NULL; } -#line 11218 "parser.c" +#line 11263 "parser.c" break; case 1085: /* start_key: KEY _is start_op identifier_list */ -#line 5823 "parser.y" +#line 5829 "parser.y" { yyvsp[-4] = yyvsp[-1]; yyval = yyvsp[0]; } -#line 11227 "parser.c" +#line 11272 "parser.c" break; case 1086: /* start_op: flag_not eq */ -#line 5830 "parser.y" +#line 5836 "parser.y" { yyval = cb_int ((yyvsp[-1] == cb_int1) ? COB_NE : COB_EQ); } -#line 11233 "parser.c" +#line 11278 "parser.c" break; case 1087: /* start_op: flag_not gt */ -#line 5831 "parser.y" +#line 5837 "parser.y" { yyval = cb_int ((yyvsp[-1] == cb_int1) ? COB_LE : COB_GT); } -#line 11239 "parser.c" +#line 11284 "parser.c" break; case 1088: /* start_op: flag_not lt */ -#line 5832 "parser.y" +#line 5838 "parser.y" { yyval = cb_int ((yyvsp[-1] == cb_int1) ? COB_GE : COB_LT); } -#line 11245 "parser.c" +#line 11290 "parser.c" break; case 1089: /* start_op: flag_not ge */ -#line 5833 "parser.y" +#line 5839 "parser.y" { yyval = cb_int ((yyvsp[-1] == cb_int1) ? COB_LT : COB_GE); } -#line 11251 "parser.c" +#line 11296 "parser.c" break; case 1090: /* start_op: flag_not le */ -#line 5834 "parser.y" +#line 5840 "parser.y" { yyval = cb_int ((yyvsp[-1] == cb_int1) ? COB_GT : COB_LE); } -#line 11257 "parser.c" +#line 11302 "parser.c" break; case 1091: /* end_start: %empty */ -#line 5838 "parser.y" +#line 5844 "parser.y" { terminator_warning (TERM_START); } -#line 11263 "parser.c" +#line 11308 "parser.c" break; case 1092: /* end_start: "END-START" */ -#line 5839 "parser.y" +#line 5845 "parser.y" { terminator_clear (TERM_START); } -#line 11269 "parser.c" +#line 11314 "parser.c" break; case 1093: /* $@85: %empty */ -#line 5848 "parser.y" +#line 5854 "parser.y" { BEGIN_STATEMENT ("STOP", 0); } -#line 11275 "parser.c" +#line 11320 "parser.c" break; case 1094: /* stop_statement: STOP RUN $@85 stop_returning */ -#line 5850 "parser.y" +#line 5856 "parser.y" { cb_emit_stop_run (yyvsp[0]); } -#line 11283 "parser.c" +#line 11328 "parser.c" break; case 1095: /* $@86: %empty */ -#line 5853 "parser.y" +#line 5859 "parser.y" { BEGIN_STATEMENT ("STOP", 0); } -#line 11289 "parser.c" +#line 11334 "parser.c" break; case 1096: /* stop_statement: STOP "Literal" $@86 */ -#line 5854 "parser.y" +#line 5860 "parser.y" { cb_verify (cb_stop_literal_statement, "STOP literal"); } -#line 11297 "parser.c" +#line 11342 "parser.c" break; case 1097: /* stop_returning: %empty */ -#line 5860 "parser.y" +#line 5866 "parser.y" { yyval = current_program->cb_return_code; } -#line 11303 "parser.c" +#line 11348 "parser.c" break; case 1098: /* stop_returning: RETURNING x */ -#line 5861 "parser.y" +#line 5867 "parser.y" { yyval = yyvsp[0]; } -#line 11309 "parser.c" +#line 11354 "parser.c" break; case 1099: /* stop_returning: GIVING x */ -#line 5862 "parser.y" +#line 5868 "parser.y" { yyval = yyvsp[0]; } -#line 11315 "parser.c" +#line 11360 "parser.c" break; case 1100: /* $@87: %empty */ -#line 5871 "parser.y" +#line 5877 "parser.y" { BEGIN_STATEMENT ("STRING", TERM_STRING); } -#line 11321 "parser.c" +#line 11366 "parser.c" break; case 1101: /* string_statement: STRING $@87 string_item_list INTO identifier opt_with_pointer on_overflow end_string */ -#line 5874 "parser.y" +#line 5880 "parser.y" { cb_emit_string (yyvsp[-5], yyvsp[-3], yyvsp[-2]); } -#line 11329 "parser.c" +#line 11374 "parser.c" break; case 1102: /* string_item_list: string_item */ -#line 5880 "parser.y" +#line 5886 "parser.y" { yyval = cb_list_init (yyvsp[0]); } -#line 11335 "parser.c" +#line 11380 "parser.c" break; case 1103: /* string_item_list: string_item_list string_item */ -#line 5881 "parser.y" +#line 5887 "parser.y" { yyval = cb_list_add (yyvsp[-1], yyvsp[0]); } -#line 11341 "parser.c" +#line 11386 "parser.c" break; case 1104: /* string_item: x */ -#line 5885 "parser.y" +#line 5891 "parser.y" { yyval = yyvsp[0]; } -#line 11347 "parser.c" +#line 11392 "parser.c" break; case 1105: /* string_item: DELIMITED _by SIZE */ -#line 5886 "parser.y" +#line 5892 "parser.y" { yyval = cb_build_pair (cb_int0, NULL); } -#line 11353 "parser.c" +#line 11398 "parser.c" break; case 1106: /* string_item: DELIMITED _by x */ -#line 5887 "parser.y" +#line 5893 "parser.y" { yyval = cb_build_pair (yyvsp[0], NULL); } -#line 11359 "parser.c" +#line 11404 "parser.c" break; case 1107: /* opt_with_pointer: %empty */ -#line 5891 "parser.y" +#line 5897 "parser.y" { yyval = cb_int0; } -#line 11365 "parser.c" +#line 11410 "parser.c" break; case 1108: /* opt_with_pointer: _with POINTER identifier */ -#line 5892 "parser.y" +#line 5898 "parser.y" { yyval = yyvsp[0]; } -#line 11371 "parser.c" +#line 11416 "parser.c" break; case 1109: /* end_string: %empty */ -#line 5896 "parser.y" +#line 5902 "parser.y" { terminator_warning (TERM_STRING); } -#line 11377 "parser.c" +#line 11422 "parser.c" break; case 1110: /* end_string: "END-STRING" */ -#line 5897 "parser.y" +#line 5903 "parser.y" { terminator_clear (TERM_STRING); } -#line 11383 "parser.c" +#line 11428 "parser.c" break; case 1111: /* $@88: %empty */ -#line 5906 "parser.y" +#line 5912 "parser.y" { BEGIN_STATEMENT ("SUBTRACT", TERM_SUBTRACT); } -#line 11389 "parser.c" +#line 11434 "parser.c" break; case 1113: /* subtract_body: x_list FROM arithmetic_x_list on_size_error */ -#line 5913 "parser.y" +#line 5919 "parser.y" { cb_emit_arithmetic (yyvsp[-1], '-', cb_build_binary_list (yyvsp[-3], '+')); } -#line 11397 "parser.c" +#line 11442 "parser.c" break; case 1114: /* subtract_body: x_list FROM x GIVING arithmetic_x_list on_size_error */ -#line 5917 "parser.y" +#line 5923 "parser.y" { cb_emit_arithmetic (yyvsp[-1], 0, cb_build_binary_list (cb_cons (yyvsp[-3], yyvsp[-5]), '-')); } -#line 11405 "parser.c" +#line 11450 "parser.c" break; case 1115: /* subtract_body: CORRESPONDING identifier FROM identifier flag_rounded on_size_error */ -#line 5921 "parser.y" +#line 5927 "parser.y" { cb_emit_corresponding (cb_build_sub, yyvsp[-2], yyvsp[-4], yyvsp[-1]); } -#line 11413 "parser.c" +#line 11458 "parser.c" break; case 1116: /* end_subtract: %empty */ -#line 5927 "parser.y" +#line 5933 "parser.y" { terminator_warning (TERM_SUBTRACT); } -#line 11419 "parser.c" +#line 11464 "parser.c" break; case 1117: /* end_subtract: "END-SUBTRACT" */ -#line 5928 "parser.y" +#line 5934 "parser.y" { terminator_clear (TERM_SUBTRACT); } -#line 11425 "parser.c" +#line 11470 "parser.c" break; case 1118: /* suppress_statement: SUPPRESS _printing */ -#line 5938 "parser.y" +#line 5944 "parser.y" { BEGIN_STATEMENT ("SUPPRESS", 0); PENDING("SUPPRESS"); } -#line 11434 "parser.c" +#line 11479 "parser.c" break; case 1121: /* $@89: %empty */ -#line 5953 "parser.y" +#line 5959 "parser.y" { BEGIN_STATEMENT ("TERMINATE", 0); } -#line 11440 "parser.c" +#line 11485 "parser.c" break; case 1122: /* terminate_statement: TERMINATE $@89 identifier_list */ -#line 5955 "parser.y" +#line 5961 "parser.y" { PENDING("TERMINATE"); } -#line 11448 "parser.c" +#line 11493 "parser.c" break; case 1123: /* $@90: %empty */ -#line 5966 "parser.y" +#line 5972 "parser.y" { BEGIN_STATEMENT ("TRANSFORM", 0); } -#line 11454 "parser.c" +#line 11499 "parser.c" break; case 1124: /* transform_statement: TRANSFORM $@90 identifier FROM simple_value TO simple_all_value */ -#line 5968 "parser.y" +#line 5974 "parser.y" { cb_tree x; x = cb_build_converting (yyvsp[-2], yyvsp[0], cb_build_inspect_region_start ()); cb_emit_inspect (yyvsp[-4], x, cb_int0, 2); } -#line 11465 "parser.c" +#line 11510 "parser.c" break; case 1125: /* $@91: %empty */ -#line 5982 "parser.y" +#line 5988 "parser.y" { BEGIN_STATEMENT ("UNLOCK", 0); } -#line 11471 "parser.c" +#line 11516 "parser.c" break; case 1126: /* unlock_statement: UNLOCK $@91 file_name opt_record */ -#line 5984 "parser.y" +#line 5990 "parser.y" { if (yyvsp[-1] != cb_error_node) { cb_emit_unlock (yyvsp[-1]); } } -#line 11481 "parser.c" +#line 11526 "parser.c" break; case 1130: /* $@92: %empty */ -#line 6003 "parser.y" +#line 6009 "parser.y" { BEGIN_STATEMENT ("UNSTRING", TERM_UNSTRING); } -#line 11487 "parser.c" +#line 11532 "parser.c" break; case 1131: /* unstring_statement: UNSTRING $@92 identifier unstring_delimited unstring_into opt_with_pointer unstring_tallying on_overflow end_unstring */ -#line 6007 "parser.y" +#line 6013 "parser.y" { cb_emit_unstring (yyvsp[-6], yyvsp[-5], yyvsp[-4], yyvsp[-3], yyvsp[-2]); } -#line 11495 "parser.c" +#line 11540 "parser.c" break; case 1132: /* unstring_delimited: %empty */ -#line 6013 "parser.y" +#line 6019 "parser.y" { yyval = NULL; } -#line 11501 "parser.c" +#line 11546 "parser.c" break; case 1133: /* unstring_delimited: DELIMITED _by unstring_delimited_list */ -#line 6015 "parser.y" +#line 6021 "parser.y" { yyval = yyvsp[0]; } -#line 11507 "parser.c" +#line 11552 "parser.c" break; case 1134: /* unstring_delimited_list: unstring_delimited_item */ -#line 6019 "parser.y" +#line 6025 "parser.y" { yyval = cb_list_init (yyvsp[0]); } -#line 11513 "parser.c" +#line 11558 "parser.c" break; case 1135: /* unstring_delimited_list: unstring_delimited_list OR unstring_delimited_item */ -#line 6021 "parser.y" +#line 6027 "parser.y" { yyval = cb_list_add (yyvsp[-2], yyvsp[0]); } -#line 11519 "parser.c" +#line 11564 "parser.c" break; case 1136: /* unstring_delimited_item: flag_all simple_value */ -#line 6026 "parser.y" +#line 6032 "parser.y" { yyval = cb_build_unstring_delimited (yyvsp[-1], yyvsp[0]); } -#line 11527 "parser.c" +#line 11572 "parser.c" break; case 1137: /* unstring_into: INTO unstring_into_item */ -#line 6032 "parser.y" +#line 6038 "parser.y" { yyval = cb_list_init (yyvsp[0]); } -#line 11533 "parser.c" +#line 11578 "parser.c" break; case 1138: /* unstring_into: unstring_into unstring_into_item */ -#line 6034 "parser.y" +#line 6040 "parser.y" { yyval = cb_list_add (yyvsp[-1], yyvsp[0]); } -#line 11539 "parser.c" +#line 11584 "parser.c" break; case 1139: /* unstring_into_item: identifier unstring_into_delimiter unstring_into_count */ -#line 6039 "parser.y" +#line 6045 "parser.y" { yyval = cb_build_unstring_into (yyvsp[-2], yyvsp[-1], yyvsp[0]); } -#line 11547 "parser.c" +#line 11592 "parser.c" break; case 1140: /* unstring_into_delimiter: %empty */ -#line 6045 "parser.y" +#line 6051 "parser.y" { yyval = NULL; } -#line 11553 "parser.c" +#line 11598 "parser.c" break; case 1141: /* unstring_into_delimiter: DELIMITER _in identifier */ -#line 6046 "parser.y" +#line 6052 "parser.y" { yyval = yyvsp[0]; } -#line 11559 "parser.c" +#line 11604 "parser.c" break; case 1142: /* unstring_into_count: %empty */ -#line 6050 "parser.y" +#line 6056 "parser.y" { yyval = NULL; } -#line 11565 "parser.c" +#line 11610 "parser.c" break; case 1143: /* unstring_into_count: COUNT _in identifier */ -#line 6051 "parser.y" +#line 6057 "parser.y" { yyval = yyvsp[0]; } -#line 11571 "parser.c" +#line 11616 "parser.c" break; case 1144: /* unstring_tallying: %empty */ -#line 6055 "parser.y" +#line 6061 "parser.y" { yyval = NULL; } -#line 11577 "parser.c" +#line 11622 "parser.c" break; case 1145: /* unstring_tallying: TALLYING _in identifier */ -#line 6056 "parser.y" +#line 6062 "parser.y" { yyval = yyvsp[0]; } -#line 11583 "parser.c" +#line 11628 "parser.c" break; case 1146: /* end_unstring: %empty */ -#line 6060 "parser.y" +#line 6066 "parser.y" { terminator_warning (TERM_UNSTRING); } -#line 11589 "parser.c" +#line 11634 "parser.c" break; case 1147: /* end_unstring: "END-UNSTRING" */ -#line 6061 "parser.y" +#line 6067 "parser.y" { terminator_clear (TERM_UNSTRING); } -#line 11595 "parser.c" +#line 11640 "parser.c" break; case 1151: /* use_exception: USE use_global _after _standard exception_or_error _procedure _on use_exception_target */ -#line 6079 "parser.y" +#line 6085 "parser.y" { if (!in_declaratives) { cb_error (_("USE statement must be within DECLARATIVES")); @@ -11613,28 +11658,28 @@ yyparse (void) } } } -#line 11617 "parser.c" +#line 11662 "parser.c" break; case 1152: /* use_global: %empty */ -#line 6100 "parser.y" +#line 6106 "parser.y" { use_global_ind = 0; } -#line 11625 "parser.c" +#line 11670 "parser.c" break; case 1153: /* use_global: GLOBAL */ -#line 6104 "parser.y" +#line 6110 "parser.y" { use_global_ind = 1; current_program->flag_global_use = 1; } -#line 11634 "parser.c" +#line 11679 "parser.c" break; case 1154: /* use_exception_target: file_name_list */ -#line 6112 "parser.y" +#line 6118 "parser.y" { cb_tree l; @@ -11644,69 +11689,69 @@ yyparse (void) } } } -#line 11648 "parser.c" +#line 11693 "parser.c" break; case 1155: /* use_exception_target: INPUT */ -#line 6122 "parser.y" +#line 6128 "parser.y" { current_program->global_handler[COB_OPEN_INPUT].handler_label = current_section; current_program->global_handler[COB_OPEN_INPUT].handler_prog = current_program; } -#line 11657 "parser.c" +#line 11702 "parser.c" break; case 1156: /* use_exception_target: OUTPUT */ -#line 6127 "parser.y" +#line 6133 "parser.y" { current_program->global_handler[COB_OPEN_OUTPUT].handler_label = current_section; current_program->global_handler[COB_OPEN_OUTPUT].handler_prog = current_program; } -#line 11666 "parser.c" +#line 11711 "parser.c" break; case 1157: /* use_exception_target: "I-O" */ -#line 6132 "parser.y" +#line 6138 "parser.y" { current_program->global_handler[COB_OPEN_I_O].handler_label = current_section; current_program->global_handler[COB_OPEN_I_O].handler_prog = current_program; } -#line 11675 "parser.c" +#line 11720 "parser.c" break; case 1158: /* use_exception_target: EXTEND */ -#line 6137 "parser.y" +#line 6143 "parser.y" { current_program->global_handler[COB_OPEN_EXTEND].handler_label = current_section; current_program->global_handler[COB_OPEN_EXTEND].handler_prog = current_program; } -#line 11684 "parser.c" +#line 11729 "parser.c" break; case 1171: /* use_debugging: USE _for DEBUGGING _on use_debugging_target */ -#line 6169 "parser.y" +#line 6175 "parser.y" { PENDING ("USE FOR DEBUGGING"); } -#line 11692 "parser.c" +#line 11737 "parser.c" break; case 1174: /* use_reporting: USE use_global BEFORE REPORTING identifier */ -#line 6181 "parser.y" +#line 6187 "parser.y" { PENDING ("USE BEFORE REPORTING"); } -#line 11700 "parser.c" +#line 11745 "parser.c" break; case 1175: /* $@93: %empty */ -#line 6192 "parser.y" +#line 6198 "parser.y" { BEGIN_STATEMENT ("WRITE", TERM_WRITE); } -#line 11706 "parser.c" +#line 11751 "parser.c" break; case 1176: /* write_statement: WRITE $@93 record_name write_from write_lock write_option write_handler end_write */ -#line 6195 "parser.y" +#line 6201 "parser.y" { if (yyvsp[-5] != cb_error_node) { if (cb_use_invalidkey_handler_on_status34 && @@ -11718,759 +11763,759 @@ yyparse (void) cb_emit_write (yyvsp[-5], yyvsp[-4], yyvsp[-2], yyvsp[-3]); } } -#line 11722 "parser.c" +#line 11767 "parser.c" break; case 1177: /* write_from: %empty */ -#line 6209 "parser.y" +#line 6215 "parser.y" { yyval = NULL; } -#line 11728 "parser.c" +#line 11773 "parser.c" break; case 1178: /* write_from: FROM id_or_lit */ -#line 6210 "parser.y" +#line 6216 "parser.y" { yyval = yyvsp[0]; } -#line 11734 "parser.c" +#line 11779 "parser.c" break; case 1179: /* write_option: %empty */ -#line 6215 "parser.y" +#line 6221 "parser.y" { yyval = cb_int0; } -#line 11742 "parser.c" +#line 11787 "parser.c" break; case 1180: /* write_option: before_or_after _advancing num_id_or_lit _line_or_lines */ -#line 6219 "parser.y" +#line 6225 "parser.y" { yyval = cb_build_write_advancing_lines (yyvsp[-3], yyvsp[-1]); } -#line 11750 "parser.c" +#line 11795 "parser.c" break; case 1181: /* write_option: before_or_after _advancing mnemonic_name */ -#line 6223 "parser.y" +#line 6229 "parser.y" { yyval = cb_build_write_advancing_mnemonic (yyvsp[-2], yyvsp[0]); } -#line 11758 "parser.c" +#line 11803 "parser.c" break; case 1182: /* write_option: before_or_after _advancing PAGE */ -#line 6227 "parser.y" +#line 6233 "parser.y" { yyval = cb_build_write_advancing_page (yyvsp[-2]); } -#line 11766 "parser.c" +#line 11811 "parser.c" break; case 1183: /* before_or_after: BEFORE */ -#line 6233 "parser.y" +#line 6239 "parser.y" { yyval = CB_BEFORE; } -#line 11772 "parser.c" +#line 11817 "parser.c" break; case 1184: /* before_or_after: AFTER */ -#line 6234 "parser.y" +#line 6240 "parser.y" { yyval = CB_AFTER; } -#line 11778 "parser.c" +#line 11823 "parser.c" break; case 1188: /* end_write: %empty */ -#line 6243 "parser.y" +#line 6249 "parser.y" { terminator_warning (TERM_WRITE); } -#line 11784 "parser.c" +#line 11829 "parser.c" break; case 1189: /* end_write: "END-WRITE" */ -#line 6244 "parser.y" +#line 6250 "parser.y" { terminator_clear (TERM_WRITE); } -#line 11790 "parser.c" +#line 11835 "parser.c" break; case 1190: /* on_accp_exception: opt_on_exception opt_not_on_exception */ -#line 6259 "parser.y" +#line 6265 "parser.y" { current_statement->handler_id = COB_EC_IMP_ACCEPT; } -#line 11798 "parser.c" +#line 11843 "parser.c" break; case 1191: /* on_disp_exception: opt_on_exception opt_not_on_exception */ -#line 6267 "parser.y" +#line 6273 "parser.y" { current_statement->handler_id = COB_EC_IMP_DISPLAY; } -#line 11806 "parser.c" +#line 11851 "parser.c" break; case 1193: /* $@94: %empty */ -#line 6274 "parser.y" +#line 6280 "parser.y" { check_unreached = 0; } -#line 11814 "parser.c" +#line 11859 "parser.c" break; case 1194: /* opt_on_exception: EXCEPTION $@94 statement_list */ -#line 6278 "parser.y" +#line 6284 "parser.y" { current_statement->handler1 = yyvsp[0]; } -#line 11822 "parser.c" +#line 11867 "parser.c" break; case 1196: /* $@95: %empty */ -#line 6285 "parser.y" +#line 6291 "parser.y" { check_unreached = 0; } -#line 11830 "parser.c" +#line 11875 "parser.c" break; case 1197: /* opt_not_on_exception: "NOT EXCEPTION" $@95 statement_list */ -#line 6289 "parser.y" +#line 6295 "parser.y" { current_statement->handler2 = yyvsp[0]; } -#line 11838 "parser.c" +#line 11883 "parser.c" break; case 1200: /* $@96: %empty */ -#line 6305 "parser.y" +#line 6311 "parser.y" { check_unreached = 0; current_statement->handler_id = COB_EC_SIZE; } -#line 11847 "parser.c" +#line 11892 "parser.c" break; case 1201: /* opt_on_size_error: "SIZE ERROR" $@96 statement_list */ -#line 6310 "parser.y" +#line 6316 "parser.y" { current_statement->handler1 = yyvsp[0]; } -#line 11855 "parser.c" +#line 11900 "parser.c" break; case 1203: /* $@97: %empty */ -#line 6317 "parser.y" +#line 6323 "parser.y" { check_unreached = 0; current_statement->handler_id = COB_EC_SIZE; } -#line 11864 "parser.c" +#line 11909 "parser.c" break; case 1204: /* opt_not_on_size_error: "NOT SIZE ERROR" $@97 statement_list */ -#line 6322 "parser.y" +#line 6328 "parser.y" { current_statement->handler2 = yyvsp[0]; } -#line 11872 "parser.c" +#line 11917 "parser.c" break; case 1205: /* on_overflow: opt_on_overflow opt_not_on_overflow */ -#line 6334 "parser.y" +#line 6340 "parser.y" { current_statement->handler_id = COB_EC_OVERFLOW; } -#line 11880 "parser.c" +#line 11925 "parser.c" break; case 1207: /* $@98: %empty */ -#line 6341 "parser.y" +#line 6347 "parser.y" { check_unreached = 0; } -#line 11888 "parser.c" +#line 11933 "parser.c" break; case 1208: /* opt_on_overflow: OVERFLOW $@98 statement_list */ -#line 6345 "parser.y" +#line 6351 "parser.y" { current_statement->handler1 = yyvsp[0]; } -#line 11896 "parser.c" +#line 11941 "parser.c" break; case 1210: /* $@99: %empty */ -#line 6352 "parser.y" +#line 6358 "parser.y" { check_unreached = 0; } -#line 11904 "parser.c" +#line 11949 "parser.c" break; case 1211: /* opt_not_on_overflow: "NOT OVERFLOW" $@99 statement_list */ -#line 6356 "parser.y" +#line 6362 "parser.y" { current_statement->handler2 = yyvsp[0]; } -#line 11912 "parser.c" +#line 11957 "parser.c" break; case 1212: /* at_end: at_end_sentence */ -#line 6368 "parser.y" +#line 6374 "parser.y" { current_statement->handler_id = COB_EC_I_O_AT_END; current_statement->handler1 = yyvsp[0]; } -#line 11921 "parser.c" +#line 11966 "parser.c" break; case 1213: /* at_end: not_at_end_sentence */ -#line 6373 "parser.y" +#line 6379 "parser.y" { current_statement->handler_id = COB_EC_I_O_AT_END; current_statement->handler2 = yyvsp[0]; } -#line 11930 "parser.c" +#line 11975 "parser.c" break; case 1214: /* at_end: at_end_sentence not_at_end_sentence */ -#line 6378 "parser.y" +#line 6384 "parser.y" { current_statement->handler_id = COB_EC_I_O_AT_END; current_statement->handler1 = yyvsp[-1]; current_statement->handler2 = yyvsp[0]; } -#line 11940 "parser.c" +#line 11985 "parser.c" break; case 1215: /* $@100: %empty */ -#line 6387 "parser.y" +#line 6393 "parser.y" { check_unreached = 0; } -#line 11948 "parser.c" +#line 11993 "parser.c" break; case 1216: /* at_end_sentence: END $@100 statement_list */ -#line 6391 "parser.y" +#line 6397 "parser.y" { yyval = yyvsp[0]; } -#line 11956 "parser.c" +#line 12001 "parser.c" break; case 1217: /* $@101: %empty */ -#line 6398 "parser.y" +#line 6404 "parser.y" { check_unreached = 0; } -#line 11964 "parser.c" +#line 12009 "parser.c" break; case 1218: /* not_at_end_sentence: "NOT END" $@101 statement_list */ -#line 6402 "parser.y" +#line 6408 "parser.y" { yyval = yyvsp[0]; } -#line 11972 "parser.c" +#line 12017 "parser.c" break; case 1219: /* at_eop: at_eop_sentence */ -#line 6414 "parser.y" +#line 6420 "parser.y" { current_statement->handler_id = COB_EC_I_O_EOP; current_statement->handler1 = yyvsp[0]; } -#line 11981 "parser.c" +#line 12026 "parser.c" break; case 1220: /* at_eop: not_at_eop_sentence */ -#line 6419 "parser.y" +#line 6425 "parser.y" { current_statement->handler_id = COB_EC_I_O_EOP; current_statement->handler2 = yyvsp[0]; } -#line 11990 "parser.c" +#line 12035 "parser.c" break; case 1221: /* at_eop: at_eop_sentence not_at_eop_sentence */ -#line 6424 "parser.y" +#line 6430 "parser.y" { current_statement->handler_id = COB_EC_I_O_EOP; current_statement->handler1 = yyvsp[-1]; current_statement->handler2 = yyvsp[0]; } -#line 12000 "parser.c" +#line 12045 "parser.c" break; case 1222: /* $@102: %empty */ -#line 6433 "parser.y" +#line 6439 "parser.y" { check_unreached = 0; } -#line 12008 "parser.c" +#line 12053 "parser.c" break; case 1223: /* at_eop_sentence: EOP $@102 statement_list */ -#line 6437 "parser.y" +#line 6443 "parser.y" { yyval = yyvsp[0]; } -#line 12016 "parser.c" +#line 12061 "parser.c" break; case 1224: /* $@103: %empty */ -#line 6444 "parser.y" +#line 6450 "parser.y" { check_unreached = 0; } -#line 12024 "parser.c" +#line 12069 "parser.c" break; case 1225: /* not_at_eop_sentence: "NOT EOP" $@103 statement_list */ -#line 6448 "parser.y" +#line 6454 "parser.y" { yyval = yyvsp[0]; } -#line 12032 "parser.c" +#line 12077 "parser.c" break; case 1228: /* invalid_key: invalid_key_sentence */ -#line 6464 "parser.y" +#line 6470 "parser.y" { current_statement->handler_id = COB_EC_I_O_INVALID_KEY; current_statement->handler1 = yyvsp[0]; } -#line 12041 "parser.c" +#line 12086 "parser.c" break; case 1229: /* invalid_key: not_invalid_key_sentence */ -#line 6469 "parser.y" +#line 6475 "parser.y" { current_statement->handler_id = COB_EC_I_O_INVALID_KEY; current_statement->handler2 = yyvsp[0]; } -#line 12050 "parser.c" +#line 12095 "parser.c" break; case 1230: /* invalid_key: invalid_key_sentence not_invalid_key_sentence */ -#line 6474 "parser.y" +#line 6480 "parser.y" { current_statement->handler_id = COB_EC_I_O_INVALID_KEY; current_statement->handler1 = yyvsp[-1]; current_statement->handler2 = yyvsp[0]; } -#line 12060 "parser.c" +#line 12105 "parser.c" break; case 1231: /* $@104: %empty */ -#line 6483 "parser.y" +#line 6489 "parser.y" { check_unreached = 0; } -#line 12068 "parser.c" +#line 12113 "parser.c" break; case 1232: /* invalid_key_sentence: "INVALID KEY" $@104 statement_list */ -#line 6487 "parser.y" +#line 6493 "parser.y" { yyval = yyvsp[0]; } -#line 12076 "parser.c" +#line 12121 "parser.c" break; case 1233: /* $@105: %empty */ -#line 6494 "parser.y" +#line 6500 "parser.y" { check_unreached = 0; } -#line 12084 "parser.c" +#line 12129 "parser.c" break; case 1234: /* not_invalid_key_sentence: "NOT INVALID KEY" $@105 statement_list */ -#line 6498 "parser.y" +#line 6504 "parser.y" { yyval = yyvsp[0]; } -#line 12092 "parser.c" +#line 12137 "parser.c" break; case 1235: /* _opt_scroll_lines: %empty */ -#line 6510 "parser.y" +#line 6516 "parser.y" { yyval = cb_one; } -#line 12100 "parser.c" +#line 12145 "parser.c" break; case 1236: /* _opt_scroll_lines: _by num_id_or_lit _line_or_lines */ -#line 6514 "parser.y" +#line 6520 "parser.y" { yyval = yyvsp[-1]; } -#line 12108 "parser.c" +#line 12153 "parser.c" break; case 1237: /* condition: expr */ -#line 6526 "parser.y" +#line 6532 "parser.y" { yyval = cb_build_cond (yyvsp[0]); } -#line 12116 "parser.c" +#line 12161 "parser.c" break; case 1238: /* expr: partial_expr */ -#line 6533 "parser.y" +#line 6539 "parser.y" { yyval = cb_build_expr (yyvsp[0]); } -#line 12124 "parser.c" +#line 12169 "parser.c" break; case 1239: /* $@106: %empty */ -#line 6539 "parser.y" +#line 6545 "parser.y" { current_expr = NULL; } -#line 12132 "parser.c" +#line 12177 "parser.c" break; case 1240: /* partial_expr: $@106 expr_tokens */ -#line 6543 "parser.y" +#line 6549 "parser.y" { yyval = cb_list_reverse (current_expr); } -#line 12140 "parser.c" +#line 12185 "parser.c" break; case 1241: /* expr_tokens: expr_token x */ -#line 6549 "parser.y" +#line 6555 "parser.y" { push_expr ('x', yyvsp[0]); } -#line 12146 "parser.c" +#line 12191 "parser.c" break; case 1242: /* expr_tokens: expr_tokens ')' */ -#line 6550 "parser.y" +#line 6556 "parser.y" { push_expr (')', NULL); } -#line 12152 "parser.c" +#line 12197 "parser.c" break; case 1243: /* expr_tokens: expr_token OMITTED */ -#line 6552 "parser.y" +#line 6558 "parser.y" { push_expr ('O', NULL); } -#line 12158 "parser.c" +#line 12203 "parser.c" break; case 1244: /* expr_tokens: expr_token NUMERIC */ -#line 6553 "parser.y" +#line 6559 "parser.y" { push_expr ('9', NULL); } -#line 12164 "parser.c" +#line 12209 "parser.c" break; case 1245: /* expr_tokens: expr_token ALPHABETIC */ -#line 6554 "parser.y" +#line 6560 "parser.y" { push_expr ('A', NULL); } -#line 12170 "parser.c" +#line 12215 "parser.c" break; case 1246: /* expr_tokens: expr_token "ALPHABETIC-LOWER" */ -#line 6555 "parser.y" +#line 6561 "parser.y" { push_expr ('L', NULL); } -#line 12176 "parser.c" +#line 12221 "parser.c" break; case 1247: /* expr_tokens: expr_token "ALPHABETIC-UPPER" */ -#line 6556 "parser.y" +#line 6562 "parser.y" { push_expr ('U', NULL); } -#line 12182 "parser.c" +#line 12227 "parser.c" break; case 1248: /* expr_tokens: expr_token CLASS_NAME */ -#line 6557 "parser.y" +#line 6563 "parser.y" { push_expr ('x', yyvsp[0]); } -#line 12188 "parser.c" +#line 12233 "parser.c" break; case 1249: /* expr_tokens: expr_tokens OMITTED */ -#line 6559 "parser.y" +#line 6565 "parser.y" { push_expr ('O', NULL); } -#line 12194 "parser.c" +#line 12239 "parser.c" break; case 1250: /* expr_tokens: expr_tokens NUMERIC */ -#line 6560 "parser.y" +#line 6566 "parser.y" { push_expr ('9', NULL); } -#line 12200 "parser.c" +#line 12245 "parser.c" break; case 1251: /* expr_tokens: expr_tokens ALPHABETIC */ -#line 6561 "parser.y" +#line 6567 "parser.y" { push_expr ('A', NULL); } -#line 12206 "parser.c" +#line 12251 "parser.c" break; case 1252: /* expr_tokens: expr_tokens "ALPHABETIC-LOWER" */ -#line 6562 "parser.y" +#line 6568 "parser.y" { push_expr ('L', NULL); } -#line 12212 "parser.c" +#line 12257 "parser.c" break; case 1253: /* expr_tokens: expr_tokens "ALPHABETIC-UPPER" */ -#line 6563 "parser.y" +#line 6569 "parser.y" { push_expr ('U', NULL); } -#line 12218 "parser.c" +#line 12263 "parser.c" break; case 1254: /* expr_tokens: expr_tokens CLASS_NAME */ -#line 6564 "parser.y" +#line 6570 "parser.y" { push_expr ('x', yyvsp[0]); } -#line 12224 "parser.c" +#line 12269 "parser.c" break; case 1255: /* expr_tokens: expr_token POSITIVE */ -#line 6566 "parser.y" +#line 6572 "parser.y" { push_expr ('P', NULL); } -#line 12230 "parser.c" +#line 12275 "parser.c" break; case 1256: /* expr_tokens: expr_token NEGATIVE */ -#line 6567 "parser.y" +#line 6573 "parser.y" { push_expr ('N', NULL); } -#line 12236 "parser.c" +#line 12281 "parser.c" break; case 1257: /* expr_tokens: expr_tokens POSITIVE */ -#line 6569 "parser.y" +#line 6575 "parser.y" { push_expr ('P', NULL); } -#line 12242 "parser.c" +#line 12287 "parser.c" break; case 1258: /* expr_tokens: expr_tokens NEGATIVE */ -#line 6570 "parser.y" +#line 6576 "parser.y" { push_expr ('N', NULL); } -#line 12248 "parser.c" +#line 12293 "parser.c" break; case 1259: /* expr_tokens: expr_tokens ZERO */ -#line 6571 "parser.y" +#line 6577 "parser.y" { push_expr ('x', cb_zero); } -#line 12254 "parser.c" +#line 12299 "parser.c" break; case 1263: /* expr_token: expr_token '(' */ -#line 6578 "parser.y" +#line 6584 "parser.y" { push_expr ('(', NULL); } -#line 12260 "parser.c" +#line 12305 "parser.c" break; case 1264: /* expr_token: expr_token '+' */ -#line 6580 "parser.y" +#line 6586 "parser.y" { push_expr ('+', NULL); } -#line 12266 "parser.c" +#line 12311 "parser.c" break; case 1265: /* expr_token: expr_token '-' */ -#line 6581 "parser.y" +#line 6587 "parser.y" { push_expr ('-', NULL); } -#line 12272 "parser.c" +#line 12317 "parser.c" break; case 1266: /* expr_token: expr_token '^' */ -#line 6582 "parser.y" +#line 6588 "parser.y" { push_expr ('^', NULL); } -#line 12278 "parser.c" +#line 12323 "parser.c" break; case 1267: /* expr_token: expr_token NOT */ -#line 6584 "parser.y" +#line 6590 "parser.y" { push_expr ('!', NULL); } -#line 12284 "parser.c" +#line 12329 "parser.c" break; case 1268: /* expr_token: expr_tokens NOT */ -#line 6585 "parser.y" +#line 6591 "parser.y" { push_expr ('!', NULL); } -#line 12290 "parser.c" +#line 12335 "parser.c" break; case 1269: /* expr_token: expr_tokens '+' */ -#line 6587 "parser.y" +#line 6593 "parser.y" { push_expr ('+', NULL); } -#line 12296 "parser.c" +#line 12341 "parser.c" break; case 1270: /* expr_token: expr_tokens '-' */ -#line 6588 "parser.y" +#line 6594 "parser.y" { push_expr ('-', NULL); } -#line 12302 "parser.c" +#line 12347 "parser.c" break; case 1271: /* expr_token: expr_tokens '*' */ -#line 6589 "parser.y" +#line 6595 "parser.y" { push_expr ('*', NULL); } -#line 12308 "parser.c" +#line 12353 "parser.c" break; case 1272: /* expr_token: expr_tokens '/' */ -#line 6590 "parser.y" +#line 6596 "parser.y" { push_expr ('/', NULL); } -#line 12314 "parser.c" +#line 12359 "parser.c" break; case 1273: /* expr_token: expr_tokens '^' */ -#line 6591 "parser.y" +#line 6597 "parser.y" { push_expr ('^', NULL); } -#line 12320 "parser.c" +#line 12365 "parser.c" break; case 1274: /* expr_token: expr_tokens eq */ -#line 6593 "parser.y" +#line 6599 "parser.y" { push_expr ('=', NULL); } -#line 12326 "parser.c" +#line 12371 "parser.c" break; case 1275: /* expr_token: expr_tokens gt */ -#line 6594 "parser.y" +#line 6600 "parser.y" { push_expr ('>', NULL); } -#line 12332 "parser.c" +#line 12377 "parser.c" break; case 1276: /* expr_token: expr_tokens lt */ -#line 6595 "parser.y" +#line 6601 "parser.y" { push_expr ('<', NULL); } -#line 12338 "parser.c" +#line 12383 "parser.c" break; case 1277: /* expr_token: expr_tokens ge */ -#line 6596 "parser.y" +#line 6602 "parser.y" { push_expr (']', NULL); } -#line 12344 "parser.c" +#line 12389 "parser.c" break; case 1278: /* expr_token: expr_tokens le */ -#line 6597 "parser.y" +#line 6603 "parser.y" { push_expr ('[', NULL); } -#line 12350 "parser.c" +#line 12395 "parser.c" break; case 1279: /* expr_token: expr_tokens NE */ -#line 6598 "parser.y" +#line 6604 "parser.y" { push_expr ('~', NULL); } -#line 12356 "parser.c" +#line 12401 "parser.c" break; case 1280: /* expr_token: expr_token eq */ -#line 6600 "parser.y" +#line 6606 "parser.y" { push_expr ('=', NULL); } -#line 12362 "parser.c" +#line 12407 "parser.c" break; case 1281: /* expr_token: expr_token gt */ -#line 6601 "parser.y" +#line 6607 "parser.y" { push_expr ('>', NULL); } -#line 12368 "parser.c" +#line 12413 "parser.c" break; case 1282: /* expr_token: expr_token lt */ -#line 6602 "parser.y" +#line 6608 "parser.y" { push_expr ('<', NULL); } -#line 12374 "parser.c" +#line 12419 "parser.c" break; case 1283: /* expr_token: expr_token ge */ -#line 6603 "parser.y" +#line 6609 "parser.y" { push_expr (']', NULL); } -#line 12380 "parser.c" +#line 12425 "parser.c" break; case 1284: /* expr_token: expr_token le */ -#line 6604 "parser.y" +#line 6610 "parser.y" { push_expr ('[', NULL); } -#line 12386 "parser.c" +#line 12431 "parser.c" break; case 1285: /* expr_token: expr_token NE */ -#line 6605 "parser.y" +#line 6611 "parser.y" { push_expr ('~', NULL); } -#line 12392 "parser.c" +#line 12437 "parser.c" break; case 1286: /* expr_token: expr_tokens AND */ -#line 6607 "parser.y" +#line 6613 "parser.y" { push_expr ('&', NULL); } -#line 12398 "parser.c" +#line 12443 "parser.c" break; case 1287: /* expr_token: expr_tokens OR */ -#line 6608 "parser.y" +#line 6614 "parser.y" { push_expr ('|', NULL); } -#line 12404 "parser.c" +#line 12449 "parser.c" break; case 1301: /* exp_list: exp */ -#line 6620 "parser.y" +#line 6626 "parser.y" { yyval = cb_list_init (yyvsp[0]); } -#line 12410 "parser.c" +#line 12455 "parser.c" break; case 1302: /* exp_list: exp_list e_sep exp */ -#line 6621 "parser.y" +#line 6627 "parser.y" { yyval = cb_list_add (yyvsp[-2], yyvsp[0]); } -#line 12416 "parser.c" +#line 12461 "parser.c" break; case 1306: /* exp: arith_x */ -#line 6630 "parser.y" +#line 6636 "parser.y" { yyval = yyvsp[0]; } -#line 12422 "parser.c" +#line 12467 "parser.c" break; case 1307: /* exp: exp '+' exp */ -#line 6631 "parser.y" +#line 6637 "parser.y" { yyval = cb_build_binary_op (yyvsp[-2], '+', yyvsp[0]); } -#line 12428 "parser.c" +#line 12473 "parser.c" break; case 1308: /* exp: exp '-' exp */ -#line 6632 "parser.y" +#line 6638 "parser.y" { yyval = cb_build_binary_op (yyvsp[-2], '-', yyvsp[0]); } -#line 12434 "parser.c" +#line 12479 "parser.c" break; case 1309: /* exp: exp '*' exp */ -#line 6633 "parser.y" +#line 6639 "parser.y" { yyval = cb_build_binary_op (yyvsp[-2], '*', yyvsp[0]); } -#line 12440 "parser.c" +#line 12485 "parser.c" break; case 1310: /* exp: exp '/' exp */ -#line 6634 "parser.y" +#line 6640 "parser.y" { yyval = cb_build_binary_op (yyvsp[-2], '/', yyvsp[0]); } -#line 12446 "parser.c" +#line 12491 "parser.c" break; case 1311: /* exp: '+' exp */ -#line 6635 "parser.y" +#line 6641 "parser.y" { yyval = yyvsp[0]; } -#line 12452 "parser.c" +#line 12497 "parser.c" break; case 1312: /* exp: '-' exp */ -#line 6636 "parser.y" +#line 6642 "parser.y" { yyval = cb_build_binary_op (cb_zero, '-', yyvsp[0]); } -#line 12458 "parser.c" +#line 12503 "parser.c" break; case 1313: /* exp: exp '^' exp */ -#line 6637 "parser.y" +#line 6643 "parser.y" { yyval = cb_build_binary_op (yyvsp[-2], '^', yyvsp[0]); } -#line 12464 "parser.c" +#line 12509 "parser.c" break; case 1314: /* exp: '(' exp ')' */ -#line 6638 "parser.y" +#line 6644 "parser.y" { yyval = yyvsp[-1]; } -#line 12470 "parser.c" +#line 12515 "parser.c" break; case 1315: /* linage_counter: "LINAGE-COUNTER" */ -#line 6650 "parser.y" +#line 6656 "parser.y" { if (current_linage > 1) { cb_error (_("LINAGE-COUNTER must be qualified here")); @@ -12482,11 +12527,11 @@ yyparse (void) yyval = linage_file->linage_ctr; } } -#line 12486 "parser.c" +#line 12531 "parser.c" break; case 1316: /* linage_counter: "LINAGE-COUNTER" in_of "Identifier" */ -#line 6662 "parser.y" +#line 6668 "parser.y" { if (CB_FILE_P (cb_ref (yyvsp[0]))) { yyval = CB_FILE (cb_ref (yyvsp[0]))->linage_ctr; @@ -12495,29 +12540,29 @@ yyparse (void) yyval = cb_error_node; } } -#line 12499 "parser.c" +#line 12544 "parser.c" break; case 1317: /* arithmetic_x_list: arithmetic_x */ -#line 6676 "parser.y" +#line 6682 "parser.y" { yyval = yyvsp[0]; } -#line 12505 "parser.c" +#line 12550 "parser.c" break; case 1318: /* arithmetic_x_list: arithmetic_x_list arithmetic_x */ -#line 6678 "parser.y" +#line 6684 "parser.y" { yyval = cb_list_append (yyvsp[-1], yyvsp[0]); } -#line 12511 "parser.c" +#line 12556 "parser.c" break; case 1319: /* arithmetic_x: x flag_rounded */ -#line 6682 "parser.y" +#line 6688 "parser.y" { yyval = cb_build_pair (yyvsp[0], yyvsp[-1]); } -#line 12517 "parser.c" +#line 12562 "parser.c" break; case 1320: /* record_name: qualified_word */ -#line 6689 "parser.y" +#line 6695 "parser.y" { cb_tree x; cb_tree r; @@ -12534,11 +12579,11 @@ yyparse (void) } yyval = x; } -#line 12538 "parser.c" +#line 12583 "parser.c" break; case 1321: /* table_name: qualified_word */ -#line 6711 "parser.y" +#line 6717 "parser.y" { cb_tree x; @@ -12553,19 +12598,19 @@ yyparse (void) yyval = yyvsp[0]; } } -#line 12557 "parser.c" +#line 12602 "parser.c" break; case 1322: /* file_name_list: file_name */ -#line 6731 "parser.y" +#line 6737 "parser.y" { yyval = cb_list_init (yyvsp[0]); } -#line 12565 "parser.c" +#line 12610 "parser.c" break; case 1323: /* file_name_list: file_name_list file_name */ -#line 6735 "parser.y" +#line 6741 "parser.y" { cb_tree l; @@ -12578,11 +12623,11 @@ yyparse (void) yyval = cb_list_add (yyvsp[-1], yyvsp[0]); } } -#line 12582 "parser.c" +#line 12627 "parser.c" break; case 1324: /* file_name: "Identifier" */ -#line 6751 "parser.y" +#line 6757 "parser.y" { if (CB_FILE_P (cb_ref (yyvsp[0]))) { yyval = yyvsp[0]; @@ -12591,106 +12636,106 @@ yyparse (void) yyval = cb_error_node; } } -#line 12595 "parser.c" +#line 12640 "parser.c" break; case 1325: /* mnemonic_name_list: mnemonic_name */ -#line 6764 "parser.y" +#line 6770 "parser.y" { yyval = cb_list_init (yyvsp[0]); } -#line 12601 "parser.c" +#line 12646 "parser.c" break; case 1326: /* mnemonic_name_list: mnemonic_name_list mnemonic_name */ -#line 6766 "parser.y" +#line 6772 "parser.y" { yyval = cb_list_add (yyvsp[-1], yyvsp[0]); } -#line 12607 "parser.c" +#line 12652 "parser.c" break; case 1327: /* mnemonic_name: "MNEMONIC NAME" */ -#line 6770 "parser.y" +#line 6776 "parser.y" { yyval = yyvsp[0]; } -#line 12613 "parser.c" +#line 12658 "parser.c" break; case 1328: /* procedure_name_list: %empty */ -#line 6776 "parser.y" +#line 6782 "parser.y" { yyval = NULL; } -#line 12619 "parser.c" +#line 12664 "parser.c" break; case 1329: /* procedure_name_list: procedure_name_list procedure_name */ -#line 6778 "parser.y" +#line 6784 "parser.y" { yyval = cb_list_add (yyvsp[-1], yyvsp[0]); } -#line 12625 "parser.c" +#line 12670 "parser.c" break; case 1330: /* procedure_name: label */ -#line 6783 "parser.y" +#line 6789 "parser.y" { yyval = yyvsp[0]; CB_REFERENCE (yyval)->offset = CB_TREE (current_section); current_program->label_list = cb_cons (yyval, current_program->label_list); } -#line 12635 "parser.c" +#line 12680 "parser.c" break; case 1334: /* integer_label: "Literal" */ -#line 6798 "parser.y" +#line 6804 "parser.y" { yyval = cb_build_reference ((char *)(CB_LITERAL (yyvsp[0])->data)); yyval->source_file = yyvsp[0]->source_file; yyval->source_line = yyvsp[0]->source_line; } -#line 12645 "parser.c" +#line 12690 "parser.c" break; case 1335: /* reference_list: reference */ -#line 6808 "parser.y" +#line 6814 "parser.y" { yyval = cb_list_init (yyvsp[0]); } -#line 12651 "parser.c" +#line 12696 "parser.c" break; case 1336: /* reference_list: reference_list reference */ -#line 6809 "parser.y" +#line 6815 "parser.y" { yyval = cb_list_add (yyvsp[-1], yyvsp[0]); } -#line 12657 "parser.c" +#line 12702 "parser.c" break; case 1337: /* reference: qualified_word */ -#line 6814 "parser.y" +#line 6820 "parser.y" { yyval = yyvsp[0]; current_program->reference_list = cb_cons (yyval, current_program->reference_list); } -#line 12666 "parser.c" +#line 12711 "parser.c" break; case 1338: /* no_reference_list: qualified_word */ -#line 6823 "parser.y" +#line 6829 "parser.y" { yyval = cb_list_init (yyvsp[0]); } -#line 12672 "parser.c" +#line 12717 "parser.c" break; case 1339: /* no_reference_list: no_reference_list qualified_word */ -#line 6824 "parser.y" +#line 6830 "parser.y" { yyval = cb_list_add (yyvsp[-1], yyvsp[0]); } -#line 12678 "parser.c" +#line 12723 "parser.c" break; case 1340: /* opt_reference: %empty */ -#line 6828 "parser.y" +#line 6834 "parser.y" { yyval = NULL; } -#line 12684 "parser.c" +#line 12729 "parser.c" break; case 1341: /* opt_reference: reference */ -#line 6829 "parser.y" +#line 6835 "parser.y" { yyval = yyvsp[0]; } -#line 12690 "parser.c" +#line 12735 "parser.c" break; case 1344: /* undefined_word: "Identifier" */ -#line 6841 "parser.y" +#line 6847 "parser.y" { yyval = yyvsp[0]; if (CB_REFERENCE (yyval)->word->count > 0) { @@ -12698,194 +12743,186 @@ yyparse (void) yyval = cb_error_node; } } -#line 12702 "parser.c" +#line 12747 "parser.c" break; case 1345: /* target_x_list: target_x */ -#line 6860 "parser.y" +#line 6866 "parser.y" { yyval = cb_list_init (yyvsp[0]); } -#line 12708 "parser.c" +#line 12753 "parser.c" break; case 1346: /* target_x_list: target_x_list target_x */ -#line 6861 "parser.y" +#line 6867 "parser.y" { yyval = cb_list_add (yyvsp[-1], yyvsp[0]); } -#line 12714 "parser.c" +#line 12759 "parser.c" break; case 1348: /* target_x: ADDRESS _of identifier_1 */ -#line 6866 "parser.y" +#line 6872 "parser.y" { yyval = cb_build_address (yyvsp[0]); } -#line 12720 "parser.c" +#line 12765 "parser.c" break; case 1349: /* x_list: x */ -#line 6870 "parser.y" +#line 6876 "parser.y" { yyval = cb_list_init (yyvsp[0]); } -#line 12726 "parser.c" +#line 12771 "parser.c" break; case 1350: /* x_list: x_list x */ -#line 6871 "parser.y" +#line 6877 "parser.y" { yyval = cb_list_add (yyvsp[-1], yyvsp[0]); } -#line 12732 "parser.c" +#line 12777 "parser.c" break; case 1352: /* x: LENGTH _of identifier_1 */ -#line 6876 "parser.y" +#line 6882 "parser.y" { yyval = cb_build_length (yyvsp[0]); } -#line 12738 "parser.c" +#line 12783 "parser.c" break; case 1353: /* x: LENGTH _of basic_literal */ -#line 6877 "parser.y" +#line 6883 "parser.y" { yyval = cb_build_length (yyvsp[0]); } -#line 12744 "parser.c" +#line 12789 "parser.c" break; case 1354: /* x: LENGTH _of function */ -#line 6878 "parser.y" +#line 6884 "parser.y" { yyval = cb_build_length (yyvsp[0]); } -#line 12750 "parser.c" +#line 12795 "parser.c" break; case 1355: /* x: ADDRESS _of prog_or_entry alnum_or_id */ -#line 6879 "parser.y" +#line 6885 "parser.y" { yyval = cb_build_ppointer (yyvsp[0]); } -#line 12756 "parser.c" +#line 12801 "parser.c" break; case 1356: /* x: ADDRESS _of identifier_1 */ -#line 6880 "parser.y" +#line 6886 "parser.y" { yyval = cb_build_address (yyvsp[0]); } -#line 12762 "parser.c" +#line 12807 "parser.c" break; case 1361: /* arith_x: LENGTH _of identifier_1 */ -#line 6888 "parser.y" +#line 6894 "parser.y" { yyval = cb_build_length (yyvsp[0]); } -#line 12768 "parser.c" +#line 12813 "parser.c" break; case 1362: /* arith_x: LENGTH _of basic_literal */ -#line 6889 "parser.y" +#line 6895 "parser.y" { yyval = cb_build_length (yyvsp[0]); } -#line 12774 "parser.c" +#line 12819 "parser.c" break; case 1363: /* arith_x: LENGTH _of function */ -#line 6890 "parser.y" +#line 6896 "parser.y" { yyval = cb_build_length (yyvsp[0]); } -#line 12780 "parser.c" +#line 12825 "parser.c" break; case 1369: /* alnum_or_id: identifier_1 */ -#line 6902 "parser.y" +#line 6908 "parser.y" { yyval = yyvsp[0]; } -#line 12786 "parser.c" +#line 12831 "parser.c" break; case 1370: /* alnum_or_id: "Literal" */ -#line 6903 "parser.y" +#line 6909 "parser.y" { yyval = yyvsp[0]; } -#line 12792 "parser.c" +#line 12837 "parser.c" break; case 1382: /* num_id_or_lit: ZERO */ -#line 6937 "parser.y" +#line 6943 "parser.y" { yyval = cb_zero; } -#line 12798 "parser.c" +#line 12843 "parser.c" break; case 1383: /* identifier: identifier_1 */ -#line 6945 "parser.y" +#line 6951 "parser.y" { yyval = cb_build_identifier (yyvsp[0]); } -#line 12804 "parser.c" +#line 12849 "parser.c" break; case 1384: /* identifier_1: qualified_word */ -#line 6949 "parser.y" +#line 6955 "parser.y" { yyval = yyvsp[0]; } -#line 12810 "parser.c" +#line 12855 "parser.c" break; case 1385: /* identifier_1: qualified_word subref */ -#line 6950 "parser.y" +#line 6956 "parser.y" { yyval = yyvsp[-1]; } -#line 12816 "parser.c" +#line 12861 "parser.c" break; case 1386: /* identifier_1: qualified_word refmod */ -#line 6951 "parser.y" +#line 6957 "parser.y" { yyval = yyvsp[-1]; } -#line 12822 "parser.c" +#line 12867 "parser.c" break; case 1387: /* identifier_1: qualified_word subref refmod */ -#line 6952 "parser.y" +#line 6958 "parser.y" { yyval = yyvsp[-2]; } -#line 12828 "parser.c" +#line 12873 "parser.c" break; case 1388: /* qualified_word: "Identifier" */ -#line 6956 "parser.y" +#line 6962 "parser.y" { yyval = yyvsp[0]; } -#line 12834 "parser.c" +#line 12879 "parser.c" break; case 1389: /* qualified_word: "Identifier" in_of qualified_word */ -#line 6957 "parser.y" +#line 6963 "parser.y" { yyval = yyvsp[-2]; CB_REFERENCE (yyvsp[-2])->chain = yyvsp[0]; } -#line 12840 "parser.c" +#line 12885 "parser.c" break; case 1390: /* subref: '(' exp_list ')' */ -#line 6962 "parser.y" +#line 6968 "parser.y" { if (cb_ref (yyvsp[-3]) != cb_error_node) { yyval = yyvsp[-3]; CB_REFERENCE (yyvsp[-3])->subs = cb_list_reverse (yyvsp[-1]); } } -#line 12851 "parser.c" +#line 12896 "parser.c" break; case 1391: /* refmod: '(' exp ':' ')' */ -#line 6972 "parser.y" +#line 6978 "parser.y" { if (cb_ref (yyvsp[-4]) != cb_error_node) { CB_REFERENCE (yyvsp[-4])->value = CB_TREE (cb_field (yyvsp[-4])); if (cb_tree_category (yyvsp[-4]) == CB_CATEGORY_NATIONAL || cb_tree_category (yyvsp[-4]) == CB_CATEGORY_NATIONAL_EDITED) { -#ifdef I18N_UTF8 - /* I18N_UTF8: No wide char support. */ -#else /*!I18N_UTF8*/ yyvsp[-2] = cb_build_binary_op (yyvsp[-2], '*', cb_int2); yyvsp[-2] = cb_build_binary_op (yyvsp[-2], '-', cb_int1); -#endif /*I18N_UTF8*/ } else { CB_TREE (yyvsp[-4])->category = CB_CATEGORY_ALPHANUMERIC; } CB_REFERENCE (yyvsp[-4])->offset = yyvsp[-2]; } } -#line 12873 "parser.c" +#line 12914 "parser.c" break; case 1392: /* refmod: '(' exp ':' exp ')' */ -#line 6990 "parser.y" +#line 6992 "parser.y" { if (cb_ref (yyvsp[-5]) != cb_error_node) { CB_REFERENCE (yyvsp[-5])->value = CB_TREE (cb_field (yyvsp[-5])); if (cb_tree_category (yyvsp[-5]) == CB_CATEGORY_NATIONAL || cb_tree_category (yyvsp[-5]) == CB_CATEGORY_NATIONAL_EDITED) { -#ifdef I18N_UTF8 - /* I18N_UTF8: No wide char support. */ -#else /*!I18N_UTF8*/ yyvsp[-3] = cb_build_binary_op (yyvsp[-3], '*', cb_int2); yyvsp[-3] = cb_build_binary_op (yyvsp[-3], '-', cb_int1); yyvsp[-1] = cb_build_binary_op (yyvsp[-1], '*', cb_int2); -#endif /*I18N_UTF8*/ } else { CB_TREE (yyvsp[-5])->category = CB_CATEGORY_ALPHANUMERIC; } @@ -12893,11 +12930,11 @@ yyparse (void) CB_REFERENCE (yyvsp[-5])->length = yyvsp[-1]; } } -#line 12897 "parser.c" +#line 12934 "parser.c" break; case 1393: /* integer: "Literal" */ -#line 7017 "parser.y" +#line 7015 "parser.y" { if (cb_tree_category (yyvsp[0]) != CB_CATEGORY_NUMERIC) { cb_error (_("Integer value expected")); @@ -12906,437 +12943,437 @@ yyparse (void) } yyval = yyvsp[0]; } -#line 12910 "parser.c" +#line 12947 "parser.c" break; case 1394: /* literal: basic_literal */ -#line 7028 "parser.y" +#line 7026 "parser.y" { yyval = yyvsp[0]; } -#line 12916 "parser.c" +#line 12953 "parser.c" break; case 1395: /* literal: ALL basic_value */ -#line 7030 "parser.y" +#line 7028 "parser.y" { yyval = yyvsp[0]; if (CB_LITERAL_P (yyvsp[0])) { CB_LITERAL (yyvsp[0])->all = 1; } } -#line 12927 "parser.c" +#line 12964 "parser.c" break; case 1396: /* basic_literal: basic_value */ -#line 7039 "parser.y" +#line 7037 "parser.y" { yyval = yyvsp[0]; } -#line 12933 "parser.c" +#line 12970 "parser.c" break; case 1397: /* basic_literal: basic_literal '&' basic_value */ -#line 7040 "parser.y" +#line 7038 "parser.y" { yyval = cb_concat_literals (yyvsp[-2], yyvsp[0]); } -#line 12939 "parser.c" +#line 12976 "parser.c" break; case 1398: /* basic_value: "Literal" */ -#line 7044 "parser.y" +#line 7042 "parser.y" { yyval = yyvsp[0]; } -#line 12945 "parser.c" +#line 12982 "parser.c" break; case 1399: /* basic_value: SPACE */ -#line 7045 "parser.y" +#line 7043 "parser.y" { yyval = cb_space; } -#line 12951 "parser.c" +#line 12988 "parser.c" break; case 1400: /* basic_value: ZERO */ -#line 7046 "parser.y" +#line 7044 "parser.y" { yyval = cb_zero; } -#line 12957 "parser.c" +#line 12994 "parser.c" break; case 1401: /* basic_value: QUOTE */ -#line 7047 "parser.y" +#line 7045 "parser.y" { yyval = cb_quote; } -#line 12963 "parser.c" +#line 13000 "parser.c" break; case 1402: /* basic_value: "HIGH-VALUE" */ -#line 7048 "parser.y" +#line 7046 "parser.y" { yyval = cb_high; } -#line 12969 "parser.c" +#line 13006 "parser.c" break; case 1403: /* basic_value: "LOW-VALUE" */ -#line 7049 "parser.y" +#line 7047 "parser.y" { yyval = cb_low; } -#line 12975 "parser.c" +#line 13012 "parser.c" break; case 1404: /* basic_value: "NULL" */ -#line 7050 "parser.y" +#line 7048 "parser.y" { yyval = cb_null; } -#line 12981 "parser.c" +#line 13018 "parser.c" break; case 1405: /* function: "FUNCTION CURRENT-DATE" func_refmod */ -#line 7059 "parser.y" +#line 7057 "parser.y" { yyval = cb_build_intrinsic (yyvsp[-1], NULL, yyvsp[0]); } -#line 12989 "parser.c" +#line 13026 "parser.c" break; case 1406: /* function: "FUNCTION WHEN-COMPILED" func_refmod */ -#line 7063 "parser.y" +#line 7061 "parser.y" { yyval = cb_build_intrinsic (yyvsp[-1], NULL, yyvsp[0]); } -#line 12997 "parser.c" +#line 13034 "parser.c" break; case 1407: /* function: "FUNCTION UPPER-CASE" '(' exp ')' func_refmod */ -#line 7067 "parser.y" +#line 7065 "parser.y" { yyval = cb_build_intrinsic (yyvsp[-4], cb_list_init (yyvsp[-2]), yyvsp[0]); } -#line 13005 "parser.c" +#line 13042 "parser.c" break; case 1408: /* function: "FUNCTION LOWER-CASE" '(' exp ')' func_refmod */ -#line 7071 "parser.y" +#line 7069 "parser.y" { yyval = cb_build_intrinsic (yyvsp[-4], cb_list_init (yyvsp[-2]), yyvsp[0]); } -#line 13013 "parser.c" +#line 13050 "parser.c" break; case 1409: /* function: "FUNCTION REVERSE" '(' exp ')' func_refmod */ -#line 7075 "parser.y" +#line 7073 "parser.y" { yyval = cb_build_intrinsic (yyvsp[-4], cb_list_init (yyvsp[-2]), yyvsp[0]); } -#line 13021 "parser.c" +#line 13058 "parser.c" break; case 1410: /* function: "FUNCTION CONCATENATE" '(' exp_list ')' func_refmod */ -#line 7079 "parser.y" +#line 7077 "parser.y" { yyval = cb_build_intrinsic (yyvsp[-4], yyvsp[-2], yyvsp[0]); } -#line 13029 "parser.c" +#line 13066 "parser.c" break; case 1411: /* function: "FUNCTION SUBSTITUTE" '(' exp_list ')' func_refmod */ -#line 7083 "parser.y" +#line 7081 "parser.y" { yyval = cb_build_intrinsic (yyvsp[-4], yyvsp[-2], yyvsp[0]); } -#line 13037 "parser.c" +#line 13074 "parser.c" break; case 1412: /* function: "FUNCTION SUBSTITUTE-CASE" '(' exp_list ')' func_refmod */ -#line 7087 "parser.y" +#line 7085 "parser.y" { yyval = cb_build_intrinsic (yyvsp[-4], yyvsp[-2], yyvsp[0]); } -#line 13045 "parser.c" +#line 13082 "parser.c" break; case 1413: /* function: "FUNCTION TRIM" '(' trim_args ')' func_refmod */ -#line 7091 "parser.y" +#line 7089 "parser.y" { yyval = cb_build_intrinsic (yyvsp[-4], yyvsp[-2], yyvsp[0]); } -#line 13053 "parser.c" +#line 13090 "parser.c" break; case 1414: /* function: "FUNCTION NUMVALC" '(' numvalc_args ')' */ -#line 7095 "parser.y" +#line 7093 "parser.y" { yyval = cb_build_intrinsic (yyvsp[-3], yyvsp[-1], NULL); } -#line 13061 "parser.c" +#line 13098 "parser.c" break; case 1415: /* function: "FUNCTION LOCALE" '(' locale_dt_args ')' func_refmod */ -#line 7099 "parser.y" +#line 7097 "parser.y" { yyval = cb_build_intrinsic (yyvsp[-4], yyvsp[-2], yyvsp[0]); } -#line 13069 "parser.c" +#line 13106 "parser.c" break; case 1416: /* function: "FUNCTION" func_args */ -#line 7103 "parser.y" +#line 7101 "parser.y" { yyval = cb_build_intrinsic (yyvsp[-1], yyvsp[0], NULL); } -#line 13077 "parser.c" +#line 13114 "parser.c" break; case 1417: /* func_refmod: %empty */ -#line 7109 "parser.y" +#line 7107 "parser.y" { yyval = NULL; } -#line 13083 "parser.c" +#line 13120 "parser.c" break; case 1418: /* func_refmod: '(' exp ':' ')' */ -#line 7110 "parser.y" +#line 7108 "parser.y" { yyval = cb_build_pair (yyvsp[-2], NULL); } -#line 13089 "parser.c" +#line 13126 "parser.c" break; case 1419: /* func_refmod: '(' exp ':' exp ')' */ -#line 7111 "parser.y" +#line 7109 "parser.y" { yyval = cb_build_pair (yyvsp[-3], yyvsp[-1]); } -#line 13095 "parser.c" +#line 13132 "parser.c" break; case 1420: /* func_args: %empty */ -#line 7115 "parser.y" +#line 7113 "parser.y" { yyval = NULL; } -#line 13101 "parser.c" +#line 13138 "parser.c" break; case 1421: /* func_args: '(' list_func_args ')' */ -#line 7116 "parser.y" +#line 7114 "parser.y" { yyval = yyvsp[-1]; } -#line 13107 "parser.c" +#line 13144 "parser.c" break; case 1422: /* list_func_args: %empty */ -#line 7120 "parser.y" +#line 7118 "parser.y" { yyval = NULL; } -#line 13113 "parser.c" +#line 13150 "parser.c" break; case 1423: /* list_func_args: exp_list */ -#line 7121 "parser.y" +#line 7119 "parser.y" { yyval = yyvsp[0]; } -#line 13119 "parser.c" +#line 13156 "parser.c" break; case 1424: /* trim_args: exp */ -#line 7127 "parser.y" +#line 7125 "parser.y" { cb_tree x; x = cb_list_init (yyvsp[0]); yyval = cb_list_add (x, cb_int0); } -#line 13130 "parser.c" +#line 13167 "parser.c" break; case 1425: /* trim_args: exp e_sep LEADING */ -#line 7134 "parser.y" +#line 7132 "parser.y" { cb_tree x; x = cb_list_init (yyvsp[-2]); yyval = cb_list_add (x, cb_int1); } -#line 13141 "parser.c" +#line 13178 "parser.c" break; case 1426: /* trim_args: exp e_sep TRAILING */ -#line 7141 "parser.y" +#line 7139 "parser.y" { cb_tree x; x = cb_list_init (yyvsp[-2]); yyval = cb_list_add (x, cb_int2); } -#line 13152 "parser.c" +#line 13189 "parser.c" break; case 1427: /* numvalc_args: exp */ -#line 7151 "parser.y" +#line 7149 "parser.y" { cb_tree x; x = cb_list_init (yyvsp[0]); yyval = cb_list_add (x, cb_null); } -#line 13163 "parser.c" +#line 13200 "parser.c" break; case 1428: /* numvalc_args: exp e_sep exp */ -#line 7158 "parser.y" +#line 7156 "parser.y" { cb_tree x; x = cb_list_init (yyvsp[-2]); yyval = cb_list_add (x, yyvsp[0]); } -#line 13174 "parser.c" +#line 13211 "parser.c" break; case 1429: /* locale_dt_args: exp */ -#line 7168 "parser.y" +#line 7166 "parser.y" { cb_tree x; x = cb_list_init (yyvsp[0]); yyval = cb_list_add (x, cb_null); } -#line 13185 "parser.c" +#line 13222 "parser.c" break; case 1430: /* locale_dt_args: exp e_sep reference */ -#line 7175 "parser.y" +#line 7173 "parser.y" { cb_tree x; x = cb_list_init (yyvsp[-2]); yyval = cb_list_add (x, cb_ref (yyvsp[0])); } -#line 13196 "parser.c" +#line 13233 "parser.c" break; case 1431: /* not_const_word: %empty */ -#line 7188 "parser.y" +#line 7186 "parser.y" { non_const_word = 1; } -#line 13204 "parser.c" +#line 13241 "parser.c" break; case 1432: /* flag_all: %empty */ -#line 7198 "parser.y" +#line 7196 "parser.y" { yyval = cb_int0; } -#line 13210 "parser.c" +#line 13247 "parser.c" break; case 1433: /* flag_all: ALL */ -#line 7199 "parser.y" +#line 7197 "parser.y" { yyval = cb_int1; } -#line 13216 "parser.c" +#line 13253 "parser.c" break; case 1434: /* flag_duplicates: %empty */ -#line 7203 "parser.y" +#line 7201 "parser.y" { yyval = cb_int0; } -#line 13222 "parser.c" +#line 13259 "parser.c" break; case 1435: /* flag_duplicates: with_dups */ -#line 7204 "parser.y" +#line 7202 "parser.y" { yyval = cb_int1; } -#line 13228 "parser.c" +#line 13265 "parser.c" break; case 1436: /* flag_initialized: %empty */ -#line 7208 "parser.y" +#line 7206 "parser.y" { yyval = NULL; } -#line 13234 "parser.c" +#line 13271 "parser.c" break; case 1437: /* flag_initialized: INITIALIZED */ -#line 7209 "parser.y" +#line 7207 "parser.y" { yyval = cb_int1; } -#line 13240 "parser.c" +#line 13277 "parser.c" break; case 1438: /* flag_next: %empty */ -#line 7213 "parser.y" +#line 7211 "parser.y" { yyval = cb_int0; } -#line 13246 "parser.c" +#line 13283 "parser.c" break; case 1439: /* flag_next: NEXT */ -#line 7214 "parser.y" +#line 7212 "parser.y" { yyval = cb_int1; } -#line 13252 "parser.c" +#line 13289 "parser.c" break; case 1440: /* flag_next: PREVIOUS */ -#line 7215 "parser.y" +#line 7213 "parser.y" { yyval = cb_int2; } -#line 13258 "parser.c" +#line 13295 "parser.c" break; case 1441: /* flag_not: %empty */ -#line 7219 "parser.y" +#line 7217 "parser.y" { yyval = cb_int0; } -#line 13264 "parser.c" +#line 13301 "parser.c" break; case 1442: /* flag_not: NOT */ -#line 7220 "parser.y" +#line 7218 "parser.y" { yyval = cb_int1; } -#line 13270 "parser.c" +#line 13307 "parser.c" break; case 1443: /* flag_optional: %empty */ -#line 7224 "parser.y" +#line 7222 "parser.y" { yyval = cb_int0; } -#line 13276 "parser.c" +#line 13313 "parser.c" break; case 1444: /* flag_optional: OPTIONAL */ -#line 7225 "parser.y" +#line 7223 "parser.y" { yyval = cb_int1; } -#line 13282 "parser.c" +#line 13319 "parser.c" break; case 1445: /* flag_rounded: %empty */ -#line 7229 "parser.y" +#line 7227 "parser.y" { yyval = cb_int0; } -#line 13288 "parser.c" +#line 13325 "parser.c" break; case 1446: /* flag_rounded: ROUNDED */ -#line 7230 "parser.y" +#line 7228 "parser.y" { yyval = cb_int1; } -#line 13294 "parser.c" +#line 13331 "parser.c" break; case 1447: /* flag_separate: %empty */ -#line 7234 "parser.y" +#line 7232 "parser.y" { yyval = cb_int0; } -#line 13300 "parser.c" +#line 13337 "parser.c" break; case 1448: /* flag_separate: SEPARATE _character */ -#line 7235 "parser.y" +#line 7233 "parser.y" { yyval = cb_int1; } -#line 13306 "parser.c" +#line 13343 "parser.c" break; case 1460: /* _also: ALSO */ -#line 7248 "parser.y" +#line 7246 "parser.y" { yyval = cb_int1; } -#line 13312 "parser.c" +#line 13349 "parser.c" break; case 1489: /* _is: %empty */ -#line 7263 "parser.y" +#line 7261 "parser.y" { yyval = NULL; } -#line 13318 "parser.c" +#line 13355 "parser.c" break; case 1490: /* _is: IS */ -#line 7263 "parser.y" +#line 7261 "parser.y" { yyval = cb_int1; } -#line 13324 "parser.c" +#line 13361 "parser.c" break; case 1501: /* _literal: %empty */ -#line 7268 "parser.y" +#line 7266 "parser.y" { yyval = NULL; } -#line 13330 "parser.c" +#line 13367 "parser.c" break; case 1502: /* _literal: "Literal" */ -#line 7268 "parser.y" +#line 7266 "parser.y" { yyval = yyvsp[0]; } -#line 13336 "parser.c" +#line 13373 "parser.c" break; -#line 13340 "parser.c" +#line 13377 "parser.c" default: break; } @@ -13418,7 +13455,6 @@ yyparse (void) label yyerrorlab therefore never appears in user code. */ if (0) YYERROR; - ++yynerrs; /* Do not reclaim the symbols of the rule whose action triggered this YYERROR. */ @@ -13479,7 +13515,7 @@ yyparse (void) `-------------------------------------*/ yyacceptlab: yyresult = 0; - goto yyreturnlab; + goto yyreturn; /*-----------------------------------. @@ -13487,22 +13523,24 @@ yyparse (void) `-----------------------------------*/ yyabortlab: yyresult = 1; - goto yyreturnlab; + goto yyreturn; -/*-----------------------------------------------------------. -| yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. | -`-----------------------------------------------------------*/ +#if !defined yyoverflow +/*-------------------------------------------------. +| yyexhaustedlab -- memory exhaustion comes here. | +`-------------------------------------------------*/ yyexhaustedlab: yyerror (YY_("memory exhausted")); yyresult = 2; - goto yyreturnlab; + goto yyreturn; +#endif -/*----------------------------------------------------------. -| yyreturnlab -- parsing is finished, clean up and return. | -`----------------------------------------------------------*/ -yyreturnlab: +/*-------------------------------------------------------. +| yyreturn -- parsing is finished, clean up and return. | +`-------------------------------------------------------*/ +yyreturn: if (yychar != YYEMPTY) { /* Make sure we have latest lookahead translation. See comments at @@ -13529,5 +13567,5 @@ yyparse (void) return yyresult; } -#line 7293 "parser.y" +#line 7291 "parser.y" diff --git a/cobj/parser.h b/cobj/parser.h index e3f2fe0c..e5bb7c26 100644 --- a/cobj/parser.h +++ b/cobj/parser.h @@ -1,8 +1,8 @@ -/* A Bison parser, made by GNU Bison 3.8.2. */ +/* A Bison parser, made by GNU Bison 3.7.4. */ /* Bison interface for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ /* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work @@ -515,8 +515,6 @@ typedef int YYSTYPE; extern YYSTYPE yylval; - int yyparse (void); - #endif /* !YY_YY_PARSER_H_INCLUDED */ diff --git a/cobj/parser.y b/cobj/parser.y index 524bc1f8..00b85122 100644 --- a/cobj/parser.y +++ b/cobj/parser.y @@ -2889,8 +2889,16 @@ usage_clause: usage: BINARY { current_field->usage = CB_USAGE_BINARY; } | COMP { current_field->usage = CB_USAGE_BINARY; } -| COMP_1 { current_field->usage = CB_USAGE_FLOAT; } -| COMP_2 { current_field->usage = CB_USAGE_DOUBLE; } +| COMP_1 +{ + current_field->usage = CB_USAGE_FLOAT; + cb_error (_("COMP-1 not implemented")); +} +| COMP_2 +{ + current_field->usage = CB_USAGE_DOUBLE; + cb_error (_("COMP-2 not implemented")); +} | COMP_3 { current_field->usage = CB_USAGE_PACKED; } | COMP_4 { current_field->usage = CB_USAGE_BINARY; } | COMP_5 { current_field->usage = CB_USAGE_COMP_5; } @@ -5374,9 +5382,7 @@ read_statement: CB_FILE(cb_ref ($3))->organization != COB_ORG_INDEXED)) { current_statement->handler_id = COB_EC_I_O_PERMANENT_ERROR; } - if ($7 && (CB_FILE(cb_ref ($3))->lock_mode & COB_LOCK_AUTOMATIC)) { - cb_error (_("LOCK clause invalid with file LOCK AUTOMATIC")); - } else if ($8 && + if ($8 && (CB_FILE(cb_ref ($3))->organization != COB_ORG_RELATIVE && CB_FILE(cb_ref ($3))->organization != COB_ORG_INDEXED)) { cb_error (_("KEY clause invalid with this file type")); @@ -6974,12 +6980,8 @@ refmod: CB_REFERENCE ($0)->value = CB_TREE (cb_field ($0)); if (cb_tree_category ($0) == CB_CATEGORY_NATIONAL || cb_tree_category ($0) == CB_CATEGORY_NATIONAL_EDITED) { -#ifdef I18N_UTF8 - /* I18N_UTF8: No wide char support. */ -#else /*!I18N_UTF8*/ $2 = cb_build_binary_op ($2, '*', cb_int2); $2 = cb_build_binary_op ($2, '-', cb_int1); -#endif /*I18N_UTF8*/ } else { CB_TREE ($0)->category = CB_CATEGORY_ALPHANUMERIC; } @@ -6992,13 +6994,9 @@ refmod: CB_REFERENCE ($0)->value = CB_TREE (cb_field ($0)); if (cb_tree_category ($0) == CB_CATEGORY_NATIONAL || cb_tree_category ($0) == CB_CATEGORY_NATIONAL_EDITED) { -#ifdef I18N_UTF8 - /* I18N_UTF8: No wide char support. */ -#else /*!I18N_UTF8*/ $2 = cb_build_binary_op ($2, '*', cb_int2); $2 = cb_build_binary_op ($2, '-', cb_int1); $4 = cb_build_binary_op ($4, '*', cb_int2); -#endif /*I18N_UTF8*/ } else { CB_TREE ($0)->category = CB_CATEGORY_ALPHANUMERIC; } diff --git a/cobj/pplex.c b/cobj/pplex.c index 56d6be46..0f3b1b43 100644 --- a/cobj/pplex.c +++ b/cobj/pplex.c @@ -1,8 +1,8 @@ -#line 2 "pplex.c" +#line 1 "pplex.c" -#line 4 "pplex.c" +#line 3 "pplex.c" -#define YY_INT_ALIGNED short int +#define YY_INT_ALIGNED short int /* A lexical scanner generated by flex */ @@ -276,10 +276,10 @@ /* First, we deal with platform-specific or compiler-specific issues. */ /* begin standard C headers. */ -#include #include -#include #include +#include +#include /* end standard C headers. */ @@ -290,10 +290,10 @@ /* C99 systems have . Non-C99 systems may or may not. */ -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. + * if you want the limit (max/min) macros for int types. */ #ifndef __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS 1 @@ -310,41 +310,41 @@ typedef uint32_t flex_uint32_t; typedef signed char flex_int8_t; typedef short int flex_int16_t; typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; +typedef unsigned char flex_uint8_t; typedef unsigned short int flex_uint16_t; typedef unsigned int flex_uint32_t; /* Limits of integral types. */ #ifndef INT8_MIN -#define INT8_MIN (-128) +#define INT8_MIN (-128) #endif #ifndef INT16_MIN -#define INT16_MIN (-32767 - 1) +#define INT16_MIN (-32767-1) #endif #ifndef INT32_MIN -#define INT32_MIN (-2147483647 - 1) +#define INT32_MIN (-2147483647-1) #endif #ifndef INT8_MAX -#define INT8_MAX (127) +#define INT8_MAX (127) #endif #ifndef INT16_MAX -#define INT16_MAX (32767) +#define INT16_MAX (32767) #endif #ifndef INT32_MAX -#define INT32_MAX (2147483647) +#define INT32_MAX (2147483647) #endif #ifndef UINT8_MAX -#define UINT8_MAX (255U) +#define UINT8_MAX (255U) #endif #ifndef UINT16_MAX -#define UINT16_MAX (65535U) +#define UINT16_MAX (65535U) #endif #ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) +#define UINT32_MAX (4294967295U) #endif #ifndef SIZE_MAX -#define SIZE_MAX (~(size_t)0) +#define SIZE_MAX (~(size_t)0) #endif #endif /* ! C99 */ @@ -368,7 +368,7 @@ typedef unsigned int flex_uint32_t; /* Promotes a possibly negative, possibly signed char to an * integer in range [0..255] for use as an array index. */ -#define YY_SC_TO_UI(c) ((YY_CHAR)(c)) +#define YY_SC_TO_UI(c) ((YY_CHAR) (c)) /* Enter a start condition. This macro really ought to take a parameter, * but we do it the disgusting crufty way forced on us by the ()-less @@ -379,12 +379,12 @@ typedef unsigned int flex_uint32_t; * to BEGIN to return to the state. The YYSTATE alias is for lex * compatibility. */ -#define YY_START (((yy_start)-1) / 2) +#define YY_START (((yy_start) - 1) / 2) #define YYSTATE YY_START /* Action number for EOF rule of a given start state. */ #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) /* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart(yyin) +#define YY_NEW_FILE yyrestart( yyin ) #define YY_END_OF_BUFFER_CHAR 0 /* Size of default input buffer. */ @@ -400,10 +400,9 @@ typedef unsigned int flex_uint32_t; #endif /* __ia64__ */ #endif -/* The state buf must be large enough to hold one state per character in the - * main buffer. +/* The state buf must be large enough to hold one state per character in the main buffer. */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) #ifndef YY_TYPEDEF_YY_BUFFER_STATE #define YY_TYPEDEF_YY_BUFFER_STATE @@ -422,90 +421,94 @@ extern FILE *yyin, *yyout; #define EOB_ACT_CONTINUE_SCAN 0 #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 - -#define YY_LESS_LINENO(n) -#define YY_LINENO_REWIND_TO(ptr) - + + #define YY_LESS_LINENO(n) + #define YY_LINENO_REWIND_TO(ptr) + /* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg); \ - *yy_cp = (yy_hold_char); \ - YY_RESTORE_YY_MORE_OFFSET(yy_c_buf_p) = yy_cp = \ - yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } while (0) -#define unput(c) yyunput(c, (yytext_ptr)) +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = (yy_hold_char); \ + YY_RESTORE_YY_MORE_OFFSET \ + (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) +#define unput(c) yyunput( c, (yytext_ptr) ) #ifndef YY_STRUCT_YY_BUFFER_STATE #define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - int yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + int yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; #define YY_BUFFER_NEW 0 #define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ #define YY_BUFFER_EOF_PENDING 2 -}; + + }; #endif /* !YY_STRUCT_YY_BUFFER_STATE */ /* Stack of input buffers. */ -static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ -static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ -static YY_BUFFER_STATE *yy_buffer_stack = NULL; /**< Stack as an array. */ +static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ +static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ +static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */ /* We provide macros for accessing buffer states in case in the * future we want to put the buffer states in a more general @@ -513,8 +516,9 @@ static YY_BUFFER_STATE *yy_buffer_stack = NULL; /**< Stack as an array. */ * * Returns the top of the stack, or NULL. */ -#define YY_CURRENT_BUFFER \ - ((yy_buffer_stack) ? (yy_buffer_stack)[(yy_buffer_stack_top)] : NULL) +#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ + ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ + : NULL) /* Same as previous macro, but useful when we know that the buffer stack is not * NULL or when we need an lvalue. For internal use only. */ @@ -522,62 +526,64 @@ static YY_BUFFER_STATE *yy_buffer_stack = NULL; /**< Stack as an array. */ /* yy_hold_char holds the character lost when yytext is formed. */ static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ +static int yy_n_chars; /* number of characters read into yy_ch_buf */ int yyleng; /* Points to current character in buffer. */ static char *yy_c_buf_p = NULL; -static int yy_init = 0; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ +static int yy_init = 0; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ /* Flag which is used to allow yywrap()'s to do buffer switches * instead of setting up a fresh yyin. A bit of a hack ... */ static int yy_did_buffer_switch_on_eof; -void yyrestart(FILE *input_file); -void yy_switch_to_buffer(YY_BUFFER_STATE new_buffer); -YY_BUFFER_STATE yy_create_buffer(FILE *file, int size); -void yy_delete_buffer(YY_BUFFER_STATE b); -void yy_flush_buffer(YY_BUFFER_STATE b); -void yypush_buffer_state(YY_BUFFER_STATE new_buffer); -void yypop_buffer_state(void); +void yyrestart ( FILE *input_file ); +void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer ); +YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size ); +void yy_delete_buffer ( YY_BUFFER_STATE b ); +void yy_flush_buffer ( YY_BUFFER_STATE b ); +void yypush_buffer_state ( YY_BUFFER_STATE new_buffer ); +void yypop_buffer_state ( void ); -static void yyensure_buffer_stack(void); -static void yy_load_buffer_state(void); -static void yy_init_buffer(YY_BUFFER_STATE b, FILE *file); -#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER) +static void yyensure_buffer_stack ( void ); +static void yy_load_buffer_state ( void ); +static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file ); +#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER ) -YY_BUFFER_STATE yy_scan_buffer(char *base, yy_size_t size); -YY_BUFFER_STATE yy_scan_string(const char *yy_str); -YY_BUFFER_STATE yy_scan_bytes(const char *bytes, int len); +YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size ); +YY_BUFFER_STATE yy_scan_string ( const char *yy_str ); +YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len ); -void *yyalloc(yy_size_t); -void *yyrealloc(void *, yy_size_t); -void yyfree(void *); +void *yyalloc ( yy_size_t ); +void *yyrealloc ( void *, yy_size_t ); +void yyfree ( void * ); #define yy_new_buffer yy_create_buffer -#define yy_set_interactive(is_interactive) \ - { \ - if (!YY_CURRENT_BUFFER) { \ - yyensure_buffer_stack(); \ - YY_CURRENT_BUFFER_LVALUE = yy_create_buffer(yyin, YY_BUF_SIZE); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } -#define yy_set_bol(at_bol) \ - { \ - if (!YY_CURRENT_BUFFER) { \ - yyensure_buffer_stack(); \ - YY_CURRENT_BUFFER_LVALUE = yy_create_buffer(yyin, YY_BUF_SIZE); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer( yyin, YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer( yyin, YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } #define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) /* Begin user sect3 */ -#define ppwrap() (/*CONSTCOND*/ 1) +#define ppwrap() (/*CONSTCOND*/1) #define YY_SKIP_YYWRAP typedef flex_uint8_t YY_CHAR; @@ -594,820 +600,1129 @@ extern char *yytext; #endif #define yytext_ptr yytext -static yy_state_type yy_get_previous_state(void); -static yy_state_type yy_try_NUL_trans(yy_state_type current_state); -static int yy_get_next_buffer(void); -static void yynoreturn yy_fatal_error(const char *msg); +static yy_state_type yy_get_previous_state ( void ); +static yy_state_type yy_try_NUL_trans ( yy_state_type current_state ); +static int yy_get_next_buffer ( void ); +static void yynoreturn yy_fatal_error ( const char* msg ); /* Done after the current pattern has been matched and before the * corresponding action - sets up yytext. */ -#define YY_DO_BEFORE_ACTION \ - (yytext_ptr) = yy_bp; \ - yyleng = (int)(yy_cp - yy_bp); \ - (yy_hold_char) = *yy_cp; \ - *yy_cp = '\0'; \ - (yy_c_buf_p) = yy_cp; +#define YY_DO_BEFORE_ACTION \ + (yytext_ptr) = yy_bp; \ + yyleng = (int) (yy_cp - yy_bp); \ + (yy_hold_char) = *yy_cp; \ + *yy_cp = '\0'; \ + (yy_c_buf_p) = yy_cp; #define YY_NUM_RULES 99 #define YY_END_OF_BUFFER 100 /* This struct is not used in this scanner, but its presence is necessary. */ -struct yy_trans_info { - flex_int32_t yy_verify; - flex_int32_t yy_nxt; -}; -static const flex_int16_t yy_accept[609] = { - 0, 0, 0, 16, 16, 0, 0, 0, 0, 0, 0, 100, 98, 73, 74, 98, 98, - 76, 77, 98, 98, 98, 95, 94, 95, 98, 95, 95, 95, 95, 95, 95, 95, 95, - 95, 95, 95, 95, 98, 98, 74, 12, 13, 93, 98, 16, 15, 16, 12, 13, 44, - 20, 21, 44, 44, 24, 25, 44, 44, 44, 41, 22, 41, 44, 44, 41, 41, 41, - 41, 41, 41, 41, 41, 41, 41, 41, 44, 44, 12, 13, 51, 45, 46, 51, 51, - 51, 51, 51, 48, 51, 48, 51, 51, 48, 51, 51, 12, 13, 60, 55, 56, - - 60, 60, 60, 60, 60, 57, 60, 57, 60, 57, 57, 57, 57, 60, 60, 12, 13, - 74, 0, 0, 97, 0, 1, 0, 96, 73, 75, 0, 95, 95, 0, 0, 74, 0, - 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, - 95, 95, 95, 95, 95, 74, 93, 0, 12, 1, 13, 93, 16, 1, 12, 1, 13, - 21, 0, 0, 43, 0, 0, 42, 20, 41, 41, 0, 0, 23, 36, 26, 27, 41, - 41, 28, 41, 41, 41, 41, 46, 0, 0, 50, 0, 0, 49, 45, 48, - - 48, 0, 0, 47, 56, 0, 0, 59, 0, 0, 58, 55, 57, 57, 0, 0, 57, - 57, 57, 1, 95, 95, 0, 0, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, - 0, 95, 0, 95, 95, 0, 0, 95, 95, 95, 95, 95, 95, 95, 95, 0, 0, - 95, 1, 1, 1, 41, 41, 29, 41, 41, 41, 41, 41, 41, 57, 57, 57, 0, - 0, 0, 0, 89, 0, 95, 95, 17, 95, 95, 95, 0, 0, 95, 95, 95, 95, - 0, 0, 95, 95, 95, 80, 0, 95, 95, 95, 95, 95, 95, 95, 95, - - 95, 95, 92, 0, 95, 41, 41, 41, 41, 41, 41, 41, 41, 52, 57, 57, 82, - 0, 81, 0, 95, 95, 0, 0, 95, 69, 0, 0, 0, 95, 95, 0, 0, 95, - 0, 95, 95, 95, 0, 0, 95, 95, 95, 95, 95, 95, 70, 71, 72, 95, 0, - 0, 95, 41, 41, 41, 41, 41, 41, 41, 41, 57, 57, 62, 95, 0, 0, 95, - 95, 95, 69, 0, 0, 95, 0, 0, 91, 0, 95, 0, 95, 95, 95, 90, 0, - 95, 95, 95, 95, 95, 95, 95, 70, 71, 72, 95, 84, 0, 0, 95, - - 0, 41, 41, 37, 41, 41, 38, 41, 41, 57, 57, 95, 0, 95, 95, 95, 0, - 0, 95, 85, 0, 95, 0, 95, 18, 95, 95, 14, 95, 95, 67, 19, 95, 95, - 78, 0, 0, 0, 35, 33, 41, 41, 41, 41, 41, 41, 53, 54, 95, 0, 95, - 95, 95, 0, 0, 95, 95, 0, 95, 95, 95, 95, 95, 68, 0, 0, 79, 0, - 41, 31, 41, 41, 30, 34, 0, 0, 0, 95, 95, 95, 0, 0, 95, 0, 95, - 0, 0, 95, 95, 95, 95, 61, 83, 0, 39, 32, 40, 86, 0, 0, - - 0, 0, 95, 95, 95, 0, 0, 95, 0, 0, 95, 0, 95, 95, 0, 0, 5, - 0, 0, 0, 95, 95, 95, 0, 10, 95, 0, 6, 0, 95, 95, 0, 0, 0, - 0, 0, 0, 95, 95, 63, 11, 0, 0, 0, 0, 3, 0, 95, 66, 0, 0, - 0, 8, 65, 64, 0, 0, 0, 95, 0, 0, 0, 0, 0, 95, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 87, 0, 0, 0, - 0, 0, 0, 0, 0, 4, 0, 0, 9, 0, 0, 0, 0, 88, 7, - - 0, 0, 0, 0, 0, 2, 0, 0}; - -static const YY_CHAR yy_ec[256] = { - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 4, 1, 1, 1, - 1, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 14, 14, 14, 14, 14, - 14, 1, 18, 1, 19, 20, 1, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, - 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 38, 47, 47, 47, 47, - 38, 47, 48, 49, 50, 51, - - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 38, 64, 65, 66, 67, 68, 69, - 70, 71, 38, 47, 47, 47, 47, 1, 47, 72, 73, 73, 73, 73, 73, 73, 73, 73, 73, - 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, - 73, 73, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, - 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, - 74, 74, 74, 74, 74, - - 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, - 74, 74, 74, 74, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, - 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 1, 1, 1}; - -static const YY_CHAR yy_meta[75] = { - 0, 1, 2, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 1, 3, 3, 3, 3, 1, 1, 1, 1, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}; - -static const flex_int16_t yy_base[632] = { - 0, 0, 72, 74, 82, 144, 70, 218, 291, 364, 83, 871, - 3699, 3699, 241, 866, 858, 3699, 3699, 839, 87, 243, 252, 95, - 260, 245, 429, 67, 436, 432, 446, 473, 501, 517, 512, 539, - 532, 545, 609, 617, 268, 831, 0, 586, 625, 0, 3699, 829, - 808, 0, 3699, 3699, 246, 808, 787, 3699, 3699, 771, 103, 651, - 633, 111, 659, 248, 755, 276, 487, 645, 667, 671, 674, 677, - 681, 684, 699, 703, 748, 767, 753, 0, 3699, 3699, 249, 764, - 747, 717, 119, 784, 792, 340, 801, 448, 715, 717, 810, 822, - 699, 0, 3699, 3699, 251, - - 710, 698, 679, 449, 838, 865, 873, 881, 471, 832, 850, 889, - 899, 918, 931, 677, 0, 258, 671, 676, 3699, 646, 0, 903, - 965, 3699, 270, 601, 835, 973, 981, 989, 275, 589, 997, 1001, - 1012, 1006, 1025, 1009, 1028, 1051, 1031, 1055, 1077, 1096, 1101, 1127, - 1104, 1108, 1150, 1083, 1122, 1133, 1155, 1130, 475, 226, 571, 0, - 0, 0, 1176, 0, 0, 0, 0, 0, 286, 565, 579, 3699, - 577, 1202, 1219, 3699, 1173, 1227, 1240, 1248, 3699, 1199, 1220, 1256, - 1264, 1267, 1270, 1278, 1295, 1334, 1300, 442, 554, 568, 3699, 565, - 1364, 1374, 3699, 1291, - - 1384, 1398, 1406, 3699, 444, 513, 527, 3699, 512, 1414, 1422, 3699, - 1392, 1432, 1456, 1464, 1423, 1477, 1451, 0, 1480, 1496, 953, 1518, - 1490, 1506, 1510, 1532, 1549, 1440, 1545, 1554, 1564, 1578, 481, 1581, - 1645, 1575, 1597, 1629, 1661, 1655, 1669, 1673, 1676, 1679, 1690, 1693, - 1697, 1758, 1766, 1725, 0, 0, 0, 1774, 1743, 1778, 1781, 1791, - 1800, 1795, 1807, 1813, 1819, 1828, 1845, 1879, 1895, 1911, 1919, 312, - 466, 1887, 1909, 1865, 1912, 1933, 1929, 698, 1957, 1951, 1936, 1977, - 1945, 68, 455, 1981, 1984, 1988, 320, 449, 2017, 2020, 2002, 2025, - 2030, 2033, 2052, 2067, - - 2075, 2097, 329, 446, 2100, 2058, 2103, 2108, 2055, 2131, 2144, 2122, - 2125, 2134, 2173, 2177, 345, 434, 563, 431, 2180, 2199, 961, 2212, - 2224, 2208, 39, 77, 422, 2227, 2252, 2288, 2296, 2265, 213, 2306, - 2276, 2282, 2317, 2353, 2332, 2318, 2346, 2341, 2335, 2365, 2370, 2374, - 2382, 2399, 2414, 2446, 2438, 2424, 2454, 2463, 2458, 2467, 2471, 2480, - 2489, 2495, 2513, 2492, 2537, 419, 419, 2544, 2559, 2563, 3699, 418, - 424, 2547, 2574, 2627, 592, 332, 2587, 498, 2603, 2614, 2595, 599, - 330, 2591, 2640, 2635, 2643, 2660, 2667, 2679, 3699, 3699, 3699, 2682, - 943, 310, 2707, 2724, - - 2746, 2718, 2731, 2738, 2754, 2765, 2768, 2774, 2771, 2761, 2790, 2795, - 271, 2818, 2841, 2844, 545, 616, 2838, 1269, 301, 2810, 417, 2847, - 2807, 2874, 2863, 2877, 2883, 2889, 2894, 2897, 2911, 2922, 1302, 298, - 2928, 2964, 2916, 2941, 2961, 2981, 2989, 2994, 2998, 3011, 2953, 3005, - 3034, 622, 3031, 3018, 3039, 459, 471, 3046, 3076, 632, 3085, 3089, - 3098, 3103, 3113, 3110, 3124, 3177, 3129, 266, 3153, 3142, 3156, 3162, - 3167, 3185, 3216, 3238, 483, 3211, 3190, 3235, 652, 668, 3226, 1459, - 3256, 3279, 659, 3270, 3267, 3201, 3294, 3259, 1310, 259, 3299, 3303, - 3310, 1338, 665, 523, - - 258, 682, 3315, 3323, 3326, 686, 759, 3339, 767, 242, 3334, 768, - 3348, 3374, 1466, 3412, 3344, 799, 864, 810, 3382, 3392, 3358, 823, - 3699, 3429, 617, 3403, 527, 3433, 3425, 838, 122, 853, 1107, 121, - 865, 3441, 3457, 3438, 3699, 1671, 3505, 884, 1005, 3699, 117, 3471, - 3462, 712, 954, 961, 3699, 3467, 3475, 993, 116, 745, 3515, 996, - 996, 995, 762, 1002, 3481, 838, 1311, 1019, 1036, 1069, 1786, 3545, - 1091, 3565, 111, 1160, 866, 1163, 1191, 109, 1234, 1596, 1276, 1291, - 1353, 906, 1296, 1523, 1297, 1548, 3699, 101, 1319, 3699, 3569, 93, - 1331, 994, 1699, 3699, - - 1339, 1341, 1350, 1646, 1728, 3699, 87, 3699, 3641, 3644, 3647, 3650, - 97, 3653, 3656, 3659, 3662, 3665, 3668, 3671, 91, 3674, 3677, 90, - 3680, 3683, 89, 3686, 3689, 3692, 3695}; - -static const flex_int16_t yy_def[632] = { - 0, 608, 1, 609, 609, 608, 5, 610, 610, 608, 9, 608, 608, 608, 608, - 611, 612, 608, 608, 608, 608, 608, 613, 608, 613, 608, 613, 613, 613, 613, - 613, 613, 613, 613, 613, 613, 613, 613, 613, 613, 608, 614, 615, 613, 613, - 616, 608, 616, 617, 618, 608, 608, 608, 619, 620, 608, 608, 608, 608, 608, - 621, 608, 621, 608, 608, 621, 621, 621, 621, 621, 621, 621, 621, 621, 621, - 621, 621, 621, 614, 615, 608, 608, 608, 622, 623, 608, 608, 608, 624, 608, - 624, 608, 608, 624, 624, 624, 614, 615, 608, 608, 608, - - 625, 626, 608, 608, 608, 627, 608, 627, 608, 627, 627, 627, 627, 627, 627, - 614, 615, 608, 608, 611, 608, 612, 628, 608, 608, 608, 608, 608, 613, 613, - 613, 613, 608, 608, 613, 613, 613, 613, 613, 613, 613, 613, 613, 613, 613, - 613, 613, 613, 613, 613, 613, 613, 613, 613, 613, 613, 608, 608, 608, 614, - 629, 615, 613, 616, 630, 617, 631, 618, 608, 608, 619, 608, 620, 608, 608, - 608, 621, 621, 621, 621, 608, 621, 621, 621, 621, 621, 621, 621, 621, 621, - 621, 608, 608, 622, 608, 623, 608, 608, 608, 624, - - 624, 624, 624, 608, 608, 608, 625, 608, 626, 608, 608, 608, 627, 627, 627, - 627, 627, 627, 627, 628, 613, 613, 608, 613, 613, 613, 613, 613, 613, 613, - 613, 613, 613, 613, 608, 613, 613, 613, 613, 608, 613, 613, 613, 613, 613, - 613, 613, 613, 613, 608, 613, 613, 629, 630, 631, 621, 621, 621, 621, 621, - 621, 621, 621, 621, 627, 627, 627, 608, 613, 608, 613, 608, 608, 613, 613, - 613, 613, 613, 613, 608, 613, 613, 613, 613, 613, 608, 608, 613, 613, 613, - 608, 608, 613, 613, 613, 613, 613, 613, 613, 613, - - 613, 613, 608, 608, 613, 621, 621, 621, 621, 621, 621, 621, 621, 627, 627, - 627, 608, 608, 608, 608, 613, 613, 608, 613, 613, 613, 608, 608, 608, 613, - 613, 608, 613, 613, 608, 613, 613, 613, 608, 613, 613, 613, 613, 613, 613, - 613, 613, 613, 613, 613, 608, 613, 613, 621, 621, 621, 621, 621, 621, 621, - 621, 627, 627, 613, 613, 608, 608, 613, 613, 613, 608, 608, 608, 613, 608, - 613, 608, 608, 613, 608, 613, 613, 613, 608, 608, 613, 613, 613, 613, 613, - 613, 613, 608, 608, 608, 613, 608, 608, 608, 613, - - 613, 621, 621, 621, 621, 621, 621, 621, 621, 627, 627, 613, 608, 613, 613, - 613, 608, 608, 613, 608, 608, 613, 608, 613, 613, 613, 613, 613, 613, 613, - 613, 613, 613, 613, 608, 608, 608, 613, 621, 621, 621, 621, 621, 621, 621, - 621, 627, 627, 613, 608, 613, 613, 613, 608, 608, 613, 613, 608, 613, 613, - 613, 613, 613, 613, 608, 613, 608, 608, 621, 621, 621, 621, 621, 621, 608, - 613, 608, 613, 613, 613, 608, 608, 613, 608, 613, 613, 608, 613, 613, 613, - 613, 613, 608, 608, 621, 621, 621, 608, 608, 608, - - 608, 608, 613, 613, 613, 608, 608, 613, 608, 608, 613, 608, 613, 613, 608, - 613, 613, 608, 608, 608, 613, 613, 613, 608, 608, 613, 608, 613, 608, 613, - 613, 608, 608, 608, 608, 608, 608, 613, 613, 613, 608, 608, 613, 608, 608, - 608, 608, 613, 613, 608, 608, 608, 608, 613, 613, 608, 608, 608, 613, 608, - 608, 608, 608, 608, 613, 608, 608, 608, 608, 608, 608, 613, 608, 608, 608, - 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, - 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, - - 608, 608, 608, 608, 608, 608, 608, 0, 608, 608, 608, 608, 608, 608, 608, - 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, - 608}; - -static const flex_int16_t yy_nxt[3774] = { - 0, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 24, - 24, 24, 24, 25, 12, 12, 12, 26, 27, 28, 29, 30, 31, 27, 27, - 32, 27, 27, 27, 27, 27, 27, 33, 27, 34, 35, 36, 27, 37, 27, - 27, 27, 12, 26, 27, 28, 29, 30, 31, 27, 27, 32, 27, 27, 27, - 27, 27, 27, 33, 34, 35, 36, 27, 37, 27, 27, 27, 38, 39, 27, - 40, 46, 608, 78, 608, 41, 372, 47, 79, 46, 42, 43, 43, 43, 43, - 48, 116, 213, 200, 177, 49, 117, 124, 335, 124, 129, - - 125, 125, 125, 125, 124, 372, 124, 605, 125, 125, 125, 125, 174, 595, 174, - 373, 175, 175, 175, 175, 174, 590, 174, 335, 175, 175, 175, 175, 197, 571, - 197, 574, 198, 198, 198, 198, 542, 545, 131, 132, 373, 535, 515, 44, 50, - 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 50, 62, 62, 62, - 62, 63, 64, 50, 50, 65, 66, 67, 67, 67, 67, 67, 67, 68, 69, - 67, 70, 67, 67, 71, 72, 67, 73, 74, 75, 67, 67, 67, 67, 67, - 50, 65, 66, 67, 67, 67, 67, 67, 67, 68, - - 69, 67, 70, 67, 67, 71, 72, 73, 74, 75, 67, 67, 67, 67, 67, - 76, 77, 67, 80, 81, 82, 83, 84, 80, 80, 85, 86, 87, 88, 89, - 80, 90, 90, 90, 90, 91, 92, 80, 80, 158, 158, 158, 158, 118, 126, - 127, 126, 133, 169, 176, 169, 192, 124, 205, 124, 380, 125, 125, 125, 125, - 118, 124, 484, 124, 80, 130, 130, 130, 130, 124, 157, 124, 127, 130, 130, - 130, 130, 133, 475, 465, 380, 158, 158, 158, 158, 608, 437, 608, 169, 94, - 95, 80, 81, 82, 83, 84, 80, 80, 96, 86, - - 87, 88, 89, 97, 90, 90, 90, 90, 91, 92, 80, 80, 119, 450, 128, - 182, 134, 170, 399, 170, 193, 375, 206, 131, 132, 272, 272, 272, 272, 119, - 351, 131, 132, 291, 291, 291, 291, 80, 450, 159, 182, 128, 303, 303, 303, - 303, 134, 179, 180, 197, 339, 197, 332, 198, 198, 198, 198, 170, 317, 317, - 317, 317, 94, 95, 98, 99, 100, 101, 102, 98, 98, 103, 104, 105, 106, - 107, 98, 108, 108, 108, 108, 109, 98, 98, 98, 110, 110, 111, 110, 110, - 110, 110, 110, 112, 110, 110, 110, 110, 110, 110, - - 110, 110, 113, 110, 110, 110, 110, 110, 110, 110, 98, 110, 110, 111, 110, - 110, 110, 110, 110, 112, 110, 110, 110, 110, 110, 110, 110, 113, 110, 110, - 110, 110, 110, 110, 110, 114, 115, 110, 608, 323, 608, 608, 280, 608, 192, - 608, 205, 608, 413, 199, 192, 270, 417, 140, 268, 608, 458, 608, 210, 418, - 210, 135, 211, 211, 211, 211, 250, 136, 137, 240, 138, 139, 212, 205, 413, - 235, 141, 157, 417, 140, 142, 458, 608, 235, 608, 418, 223, 135, 158, 158, - 158, 158, 136, 137, 143, 138, 608, 139, 608, 481, - - 131, 132, 141, 131, 132, 286, 142, 131, 132, 482, 608, 144, 608, 193, 145, - 206, 208, 131, 132, 193, 143, 608, 502, 608, 481, 146, 608, 423, 608, 545, - 208, 286, 183, 205, 482, 147, 144, 151, 546, 145, 148, 608, 206, 608, 131, - 132, 159, 502, 608, 149, 608, 146, 287, 423, 608, 150, 608, 183, 179, 180, - 154, 147, 519, 151, 152, 148, 156, 155, 454, 195, 153, 195, 131, 132, 192, - 149, 319, 319, 319, 319, 150, 172, 172, 131, 132, 169, 154, 519, 131, 132, - 152, 157, 156, 155, 454, 124, 153, 124, 547, 163, - - 163, 163, 163, 131, 132, 377, 377, 377, 377, 133, 131, 132, 384, 384, 384, - 384, 131, 132, 608, 608, 608, 127, 608, 608, 608, 608, 608, 608, 608, 118, - 608, 608, 608, 608, 608, 608, 608, 129, 608, 608, 608, 608, 174, 455, 174, - 157, 178, 178, 178, 178, 121, 477, 176, 169, 608, 129, 608, 131, 132, 544, - 174, 487, 174, 129, 175, 175, 175, 175, 174, 455, 174, 129, 178, 178, 178, - 178, 608, 477, 608, 121, 608, 506, 608, 608, 544, 608, 608, 487, 608, 507, - 608, 118, 608, 608, 512, 608, 161, 518, 123, 186, - - 280, 184, 208, 187, 179, 180, 185, 506, 608, 189, 608, 520, 608, 208, 608, - 507, 179, 180, 161, 188, 512, 524, 170, 518, 327, 186, 608, 184, 608, 187, - 179, 180, 185, 204, 328, 189, 123, 520, 179, 180, 190, 191, 179, 180, 188, - 179, 180, 524, 179, 180, 327, 195, 179, 180, 560, 179, 180, 608, 608, 608, - 328, 608, 608, 608, 608, 190, 191, 195, 169, 329, 179, 180, 161, 181, 179, - 180, 608, 608, 608, 560, 608, 608, 608, 608, 564, 199, 192, 177, 202, 203, - 123, 172, 525, 197, 177, 197, 527, 198, 198, 198, - - 198, 197, 529, 197, 569, 201, 201, 201, 201, 564, 197, 172, 197, 177, 201, - 201, 201, 201, 525, 608, 608, 608, 527, 608, 608, 608, 608, 167, 529, 569, - 192, 608, 608, 608, 534, 608, 608, 608, 608, 212, 205, 608, 200, 608, 608, - 537, 608, 210, 165, 210, 161, 211, 211, 211, 211, 193, 200, 541, 123, 608, - 534, 608, 121, 202, 203, 535, 535, 550, 200, 121, 608, 537, 202, 203, 210, - 551, 210, 573, 214, 214, 214, 214, 210, 541, 210, 217, 211, 211, 211, 211, - 210, 608, 210, 550, 214, 214, 214, 214, 608, 553, - - 608, 551, 573, 215, 216, 584, 131, 132, 608, 206, 608, 217, 124, 558, 124, - 608, 125, 125, 125, 125, 608, 215, 216, 218, 219, 553, 608, 608, 608, 608, - 584, 608, 608, 608, 608, 536, 215, 216, 205, 558, 608, 608, 608, 608, 608, - 608, 608, 608, 593, 218, 219, 213, 215, 216, 223, 223, 397, 397, 397, 397, - 215, 216, 608, 323, 213, 608, 272, 272, 272, 272, 215, 216, 608, 593, 124, - 561, 124, 213, 125, 125, 125, 125, 124, 608, 124, 366, 130, 130, 130, 130, - 608, 608, 608, 562, 608, 608, 608, 608, 608, 608, - - 608, 561, 608, 608, 608, 608, 608, 545, 608, 129, 608, 366, 608, 223, 223, - 608, 546, 608, 608, 562, 608, 608, 563, 608, 273, 566, 222, 129, 567, 221, - 568, 570, 367, 601, 608, 129, 608, 608, 608, 608, 608, 576, 608, 608, 131, - 132, 225, 608, 563, 228, 608, 566, 222, 229, 567, 221, 568, 570, 601, 226, - 608, 227, 608, 232, 608, 577, 608, 576, 131, 132, 608, 225, 131, 132, 228, - 230, 547, 131, 132, 229, 131, 132, 608, 224, 132, 226, 608, 227, 608, 232, - 233, 577, 608, 231, 608, 608, 131, 132, 235, 131, - - 132, 230, 131, 132, 578, 608, 247, 608, 535, 535, 608, 234, 608, 608, 608, - 608, 233, 608, 231, 608, 581, 236, 131, 132, 238, 608, 131, 132, 240, 240, - 578, 608, 247, 608, 552, 608, 608, 234, 608, 608, 239, 608, 608, 243, 608, - 242, 581, 236, 131, 132, 238, 248, 608, 608, 131, 132, 250, 250, 608, 608, - 552, 608, 252, 608, 608, 239, 608, 237, 132, 243, 242, 249, 131, 132, 244, - 131, 132, 248, 536, 131, 132, 583, 608, 245, 608, 124, 246, 124, 252, 163, - 163, 163, 163, 131, 132, 608, 249, 585, 241, 132, - - 244, 131, 132, 608, 131, 132, 608, 583, 608, 245, 608, 174, 246, 174, 608, - 175, 175, 175, 175, 608, 586, 131, 132, 585, 608, 608, 251, 132, 174, 608, - 174, 608, 175, 175, 175, 175, 174, 608, 174, 608, 178, 178, 178, 178, 179, - 180, 586, 131, 132, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, - 608, 608, 608, 608, 608, 608, 608, 608, 177, 587, 179, 180, 608, 608, 608, - 608, 608, 608, 608, 608, 608, 608, 420, 420, 420, 420, 177, 608, 257, 608, - 608, 179, 180, 256, 177, 587, 258, 608, 179, 180, - - 608, 608, 608, 259, 608, 608, 608, 260, 588, 608, 608, 608, 574, 574, 257, - 435, 435, 435, 435, 256, 589, 264, 258, 493, 493, 493, 493, 179, 180, 259, - 594, 261, 597, 260, 588, 179, 180, 608, 179, 180, 608, 179, 180, 608, 608, - 608, 589, 264, 598, 179, 180, 498, 498, 498, 498, 590, 594, 261, 597, 608, - 262, 608, 202, 203, 591, 600, 179, 180, 602, 608, 263, 179, 180, 197, 598, - 197, 603, 198, 198, 198, 198, 608, 575, 197, 604, 197, 262, 198, 198, 198, - 198, 600, 608, 197, 602, 197, 263, 201, 201, 201, - - 201, 608, 603, 608, 608, 179, 180, 608, 608, 608, 604, 608, 608, 608, 608, - 608, 608, 608, 608, 608, 608, 608, 608, 210, 592, 210, 200, 211, 211, 211, - 211, 210, 608, 210, 608, 211, 211, 211, 211, 608, 608, 210, 280, 210, 200, - 214, 214, 214, 214, 608, 608, 608, 200, 608, 608, 202, 203, 608, 608, 265, - 608, 484, 608, 215, 216, 608, 608, 608, 515, 608, 608, 608, 608, 608, 608, - 608, 608, 608, 608, 608, 608, 268, 268, 509, 213, 265, 608, 267, 608, 608, - 532, 608, 608, 608, 215, 216, 608, 270, 270, 608, - - 266, 608, 213, 215, 216, 608, 608, 608, 608, 509, 213, 281, 132, 267, 608, - 608, 532, 608, 274, 608, 608, 608, 215, 216, 595, 595, 266, 608, 608, 608, - 510, 608, 608, 608, 608, 608, 608, 533, 223, 608, 608, 608, 608, 608, 274, - 275, 608, 608, 215, 216, 590, 269, 132, 277, 608, 276, 608, 278, 608, 591, - 608, 131, 132, 608, 129, 608, 608, 271, 132, 608, 275, 608, 279, 608, 282, - 608, 608, 131, 132, 277, 276, 131, 132, 278, 608, 608, 608, 608, 608, 608, - 608, 608, 608, 283, 596, 608, 608, 284, 279, 608, - - 282, 285, 608, 131, 132, 608, 608, 289, 608, 582, 582, 582, 582, 608, 608, - 288, 131, 132, 283, 592, 131, 132, 608, 284, 608, 131, 132, 285, 608, 608, - 240, 240, 608, 289, 608, 131, 132, 290, 608, 608, 608, 288, 291, 291, 291, - 291, 131, 132, 605, 131, 132, 608, 131, 132, 608, 608, 608, 606, 608, 608, - 608, 608, 290, 608, 608, 235, 608, 608, 131, 132, 608, 608, 608, 542, 608, - 608, 608, 608, 608, 608, 608, 240, 608, 608, 608, 608, 608, 608, 608, 608, - 608, 129, 294, 608, 293, 556, 295, 297, 296, 608, - - 292, 608, 608, 608, 608, 608, 608, 129, 608, 608, 608, 298, 599, 599, 599, - 599, 608, 607, 294, 293, 608, 556, 295, 297, 296, 608, 131, 132, 608, 300, - 605, 299, 301, 608, 608, 608, 608, 298, 302, 606, 131, 132, 557, 608, 131, - 132, 608, 131, 132, 608, 131, 132, 608, 608, 608, 300, 299, 608, 301, 250, - 250, 131, 132, 302, 131, 132, 305, 307, 131, 132, 608, 303, 303, 303, 303, - 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 250, 608, 571, 608, - 608, 305, 608, 307, 608, 608, 131, 132, 608, 607, - - 608, 608, 608, 608, 608, 608, 608, 308, 306, 608, 579, 608, 129, 608, 179, - 180, 608, 608, 608, 608, 608, 311, 608, 608, 608, 309, 608, 608, 608, 304, - 608, 608, 310, 308, 306, 608, 579, 608, 608, 608, 608, 608, 313, 312, 608, - 179, 180, 311, 608, 179, 180, 309, 179, 180, 608, 608, 608, 580, 310, 608, - 315, 608, 179, 180, 314, 608, 179, 180, 313, 312, 608, 179, 180, 608, 608, - 608, 608, 316, 179, 180, 268, 268, 608, 608, 179, 180, 315, 608, 608, 314, - 215, 216, 317, 317, 317, 317, 608, 608, 608, 215, - - 216, 608, 608, 316, 608, 608, 608, 608, 608, 608, 608, 608, 270, 270, 323, - 268, 215, 216, 608, 608, 608, 608, 321, 608, 319, 319, 319, 319, 608, 608, - 608, 608, 608, 608, 608, 608, 131, 132, 608, 270, 608, 129, 608, 325, 608, - 608, 608, 608, 321, 322, 318, 608, 608, 608, 608, 608, 608, 608, 131, 132, - 608, 331, 608, 608, 608, 129, 608, 608, 608, 326, 608, 608, 608, 608, 322, - 608, 608, 280, 332, 332, 131, 132, 320, 324, 132, 334, 608, 331, 608, 330, - 608, 608, 608, 608, 326, 608, 608, 608, 608, 608, - - 131, 132, 608, 129, 131, 132, 608, 131, 132, 338, 334, 608, 608, 608, 330, - 608, 131, 132, 339, 339, 608, 336, 131, 132, 608, 337, 608, 608, 608, 608, - 608, 608, 608, 608, 608, 338, 608, 608, 608, 608, 342, 608, 608, 608, 608, - 341, 336, 608, 333, 132, 337, 343, 131, 132, 345, 131, 132, 608, 608, 131, - 132, 608, 608, 608, 608, 342, 608, 608, 344, 608, 608, 341, 608, 131, 132, - 608, 608, 343, 608, 608, 345, 347, 348, 349, 608, 608, 608, 354, 340, 132, - 346, 131, 132, 344, 608, 357, 131, 132, 351, 351, - - 608, 131, 132, 608, 131, 132, 608, 608, 608, 608, 608, 608, 608, 354, 608, - 346, 350, 608, 608, 608, 357, 608, 608, 131, 132, 353, 179, 180, 608, 179, - 180, 608, 355, 608, 608, 608, 608, 356, 131, 132, 608, 350, 608, 608, 608, - 608, 131, 132, 608, 608, 608, 353, 358, 608, 608, 608, 608, 361, 355, 608, - 360, 608, 608, 356, 608, 608, 608, 608, 352, 132, 608, 131, 132, 359, 179, - 180, 608, 608, 358, 179, 180, 608, 608, 361, 608, 360, 608, 608, 608, 608, - 608, 608, 608, 179, 180, 608, 179, 180, 363, 359, - - 608, 608, 179, 180, 608, 215, 216, 608, 608, 608, 608, 608, 608, 608, 362, - 179, 180, 608, 364, 371, 365, 608, 608, 608, 363, 608, 608, 608, 608, 608, - 608, 608, 323, 608, 608, 608, 608, 608, 608, 362, 608, 608, 608, 364, 215, - 216, 365, 368, 215, 216, 608, 131, 132, 375, 375, 608, 608, 369, 129, 608, - 608, 608, 374, 608, 608, 608, 608, 370, 608, 608, 131, 132, 608, 368, 608, - 608, 608, 608, 608, 131, 132, 608, 608, 369, 608, 608, 608, 608, 374, 332, - 332, 608, 370, 608, 379, 131, 132, 608, 131, 132, - - 382, 377, 377, 377, 377, 608, 608, 608, 608, 608, 608, 608, 608, 608, 383, - 608, 332, 608, 339, 339, 379, 608, 608, 376, 132, 608, 382, 608, 608, 608, - 384, 384, 384, 384, 608, 381, 131, 132, 608, 388, 383, 608, 129, 608, 608, - 608, 608, 131, 132, 608, 608, 608, 608, 131, 132, 608, 386, 608, 391, 378, - 608, 381, 608, 608, 608, 388, 608, 608, 608, 608, 608, 387, 390, 339, 608, - 389, 608, 131, 132, 608, 608, 393, 386, 608, 391, 394, 608, 608, 385, 131, - 132, 608, 608, 395, 392, 608, 387, 608, 390, 129, - - 608, 389, 608, 131, 132, 608, 131, 132, 608, 608, 608, 608, 131, 132, 608, - 351, 351, 131, 132, 608, 392, 608, 608, 608, 608, 608, 396, 397, 397, 397, - 397, 608, 608, 608, 608, 608, 131, 132, 608, 399, 399, 131, 132, 608, 608, - 131, 132, 608, 608, 608, 608, 608, 396, 131, 132, 608, 608, 608, 402, 608, - 608, 608, 608, 608, 608, 608, 351, 608, 608, 608, 131, 132, 608, 608, 608, - 608, 608, 400, 608, 608, 608, 608, 608, 608, 402, 398, 608, 405, 403, 608, - 406, 608, 129, 608, 608, 179, 180, 608, 608, 608, - - 608, 608, 400, 608, 608, 408, 608, 404, 608, 401, 132, 608, 608, 405, 403, - 407, 406, 608, 409, 410, 608, 608, 608, 608, 608, 179, 180, 608, 608, 179, - 180, 408, 404, 608, 179, 180, 411, 608, 179, 180, 407, 608, 179, 180, 409, - 410, 608, 608, 608, 608, 608, 179, 180, 608, 608, 608, 608, 608, 608, 608, - 179, 180, 411, 131, 132, 608, 215, 216, 608, 608, 608, 412, 608, 608, 608, - 375, 375, 608, 608, 414, 608, 419, 608, 608, 215, 216, 608, 420, 420, 420, - 420, 608, 608, 608, 415, 608, 608, 412, 608, 608, - - 608, 416, 608, 608, 608, 414, 608, 419, 131, 132, 608, 608, 608, 608, 608, - 131, 132, 608, 131, 132, 415, 608, 422, 608, 608, 608, 416, 426, 608, 424, - 131, 132, 427, 608, 131, 132, 608, 608, 608, 425, 608, 608, 608, 608, 608, - 421, 608, 375, 422, 608, 608, 608, 608, 426, 608, 424, 608, 427, 131, 132, - 608, 608, 131, 132, 608, 425, 131, 132, 429, 608, 608, 608, 608, 129, 131, - 132, 608, 430, 608, 428, 608, 608, 608, 608, 608, 131, 132, 608, 608, 608, - 608, 608, 432, 608, 429, 608, 608, 608, 608, 431, - - 608, 608, 608, 430, 428, 608, 131, 132, 399, 399, 434, 131, 132, 608, 131, - 132, 608, 608, 432, 433, 435, 435, 435, 435, 431, 437, 437, 608, 608, 608, - 608, 131, 132, 608, 608, 608, 434, 608, 131, 132, 608, 608, 608, 608, 433, - 439, 608, 608, 608, 608, 131, 132, 608, 131, 132, 608, 608, 608, 440, 608, - 608, 608, 608, 608, 608, 608, 399, 441, 608, 608, 608, 439, 608, 608, 608, - 608, 608, 608, 436, 608, 608, 608, 608, 608, 440, 608, 447, 608, 442, 179, - 180, 608, 129, 441, 443, 438, 132, 444, 608, 608, - - 608, 608, 179, 180, 608, 446, 608, 608, 608, 179, 180, 608, 447, 445, 442, - 448, 608, 608, 608, 608, 443, 608, 608, 444, 608, 179, 180, 608, 608, 608, - 608, 446, 215, 216, 608, 449, 179, 180, 445, 179, 180, 448, 179, 180, 457, - 179, 180, 608, 608, 608, 608, 451, 608, 608, 608, 608, 608, 608, 608, 608, - 449, 215, 216, 608, 608, 452, 131, 132, 608, 608, 457, 456, 608, 453, 608, - 608, 459, 451, 131, 132, 608, 131, 132, 608, 608, 608, 608, 608, 608, 131, - 132, 452, 608, 462, 608, 460, 608, 456, 608, 453, - - 608, 461, 459, 608, 608, 608, 608, 608, 608, 131, 132, 608, 131, 132, 463, - 131, 132, 608, 131, 132, 608, 460, 608, 465, 465, 608, 461, 608, 608, 437, - 437, 608, 608, 608, 131, 132, 608, 608, 608, 608, 463, 467, 467, 467, 467, - 131, 132, 608, 131, 132, 608, 608, 608, 608, 131, 132, 464, 608, 608, 608, - 131, 132, 608, 608, 608, 131, 132, 608, 131, 132, 608, 608, 608, 608, 608, - 608, 608, 608, 608, 608, 608, 464, 131, 132, 437, 608, 608, 179, 180, 608, - 608, 608, 608, 466, 132, 469, 608, 608, 608, 468, - - 608, 608, 608, 608, 608, 608, 608, 608, 470, 608, 129, 608, 179, 180, 608, - 608, 608, 608, 608, 608, 608, 469, 608, 471, 215, 216, 608, 608, 472, 608, - 608, 608, 179, 180, 470, 475, 475, 473, 474, 608, 608, 608, 608, 608, 608, - 608, 608, 479, 608, 471, 608, 608, 179, 180, 472, 608, 608, 608, 608, 608, - 179, 180, 473, 608, 474, 179, 180, 478, 608, 179, 180, 483, 608, 479, 608, - 608, 215, 216, 484, 480, 608, 608, 179, 180, 608, 608, 485, 608, 608, 131, - 132, 608, 608, 478, 608, 608, 608, 483, 608, 608, - - 608, 608, 131, 132, 480, 476, 132, 608, 488, 608, 131, 132, 608, 608, 608, - 608, 608, 131, 132, 608, 608, 608, 608, 490, 608, 465, 465, 608, 608, 489, - 437, 437, 491, 608, 488, 608, 608, 493, 493, 493, 493, 608, 467, 467, 467, - 467, 608, 486, 132, 490, 608, 608, 492, 608, 489, 608, 131, 132, 491, 608, - 131, 132, 608, 608, 608, 608, 608, 608, 608, 131, 132, 608, 608, 608, 131, - 132, 608, 492, 608, 608, 495, 131, 132, 496, 131, 132, 608, 608, 608, 497, - 608, 608, 608, 608, 608, 494, 608, 465, 608, 608, - - 468, 608, 608, 515, 608, 608, 495, 608, 608, 496, 608, 608, 608, 179, 180, - 497, 504, 475, 475, 608, 608, 608, 608, 129, 179, 180, 608, 179, 180, 498, - 498, 498, 498, 179, 180, 608, 608, 608, 179, 180, 503, 608, 504, 499, 608, - 500, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 179, 180, 475, 608, - 508, 131, 132, 608, 608, 608, 503, 608, 608, 499, 608, 500, 516, 132, 608, - 505, 608, 608, 608, 608, 608, 608, 131, 132, 129, 511, 508, 501, 608, 608, - 608, 513, 608, 608, 608, 608, 514, 131, 132, 484, - - 505, 608, 608, 608, 608, 608, 131, 132, 608, 608, 608, 511, 608, 608, 608, - 608, 608, 513, 517, 608, 608, 608, 514, 608, 608, 129, 608, 131, 132, 608, - 131, 132, 608, 608, 608, 608, 608, 608, 131, 132, 608, 131, 132, 608, 517, - 608, 608, 521, 608, 608, 608, 523, 522, 608, 608, 608, 608, 608, 528, 608, - 608, 608, 608, 608, 608, 131, 132, 608, 608, 608, 179, 180, 608, 521, 179, - 180, 608, 523, 522, 526, 608, 179, 180, 608, 528, 608, 131, 132, 530, 608, - 608, 608, 540, 608, 131, 132, 608, 131, 132, 608, - - 608, 608, 608, 608, 526, 131, 132, 538, 608, 531, 131, 132, 608, 530, 608, - 131, 132, 539, 540, 131, 132, 608, 608, 608, 608, 608, 608, 608, 608, 131, - 132, 542, 515, 538, 608, 531, 608, 608, 608, 608, 608, 608, 608, 539, 608, - 131, 132, 608, 608, 608, 608, 608, 608, 131, 132, 608, 608, 608, 129, 549, - 608, 608, 548, 131, 132, 554, 608, 608, 608, 608, 608, 608, 608, 608, 131, - 132, 608, 608, 608, 608, 608, 555, 608, 571, 608, 549, 608, 608, 548, 608, - 608, 554, 608, 608, 608, 608, 131, 132, 608, 608, - - 543, 132, 608, 608, 131, 132, 559, 555, 608, 131, 132, 608, 131, 132, 608, - 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 542, 608, 608, 131, 132, - 608, 608, 559, 131, 132, 608, 608, 608, 131, 132, 608, 608, 131, 132, 608, - 608, 131, 132, 608, 565, 608, 129, 572, 132, 608, 608, 608, 608, 608, 608, - 608, 608, 608, 608, 608, 571, 574, 574, 608, 608, 595, 595, 608, 608, 608, - 565, 608, 608, 582, 582, 582, 582, 599, 599, 599, 599, 131, 132, 608, 608, - 608, 129, 608, 608, 608, 608, 608, 608, 608, 608, - - 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, - 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, - 608, 608, 608, 608, 608, 608, 575, 608, 608, 608, 596, 45, 45, 45, 93, - 93, 93, 120, 608, 120, 122, 608, 122, 160, 608, 160, 162, 608, 162, 164, - 608, 164, 166, 608, 166, 168, 608, 168, 171, 608, 171, 173, 608, 173, 194, - 608, 194, 196, 608, 196, 207, 608, 207, 209, 608, 209, 220, 608, 220, 253, - 608, 253, 254, 608, 254, 255, 608, 255, 11, 608, - - 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, - 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, - 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, - 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, - 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608}; - -static const flex_int16_t yy_chk[3774] = { - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 2, 3, 27, 6, 27, 2, 327, 3, 6, 4, 2, 2, 2, 2, 2, - 4, 10, 627, 624, 621, 4, 10, 20, 286, 20, 613, - - 20, 20, 20, 20, 23, 327, 23, 607, 23, 23, 23, 23, 58, 596, 58, - 328, 58, 58, 58, 58, 61, 592, 61, 286, 61, 61, 61, 61, 86, 580, - 86, 575, 86, 86, 86, 86, 557, 547, 27, 27, 328, 536, 533, 2, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 158, 158, 158, 158, 14, 21, - 21, 25, 25, 52, 63, 63, 82, 21, 100, 21, 335, 21, 21, 21, 21, - 118, 22, 510, 22, 7, 22, 22, 22, 22, 24, 40, 24, 127, 24, 24, - 24, 24, 133, 501, 494, 335, 40, 40, 40, 40, 65, 468, 65, 169, 7, - 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, - - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 14, 413, 21, - 65, 25, 52, 436, 63, 82, 421, 100, 22, 22, 272, 272, 272, 272, 118, - 398, 24, 24, 291, 291, 291, 291, 8, 413, 40, 65, 127, 303, 303, 303, - 303, 133, 65, 65, 89, 385, 89, 378, 89, 89, 89, 89, 169, 317, 317, - 317, 317, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 26, 367, 26, 29, 329, 29, 192, - 28, 205, 28, 366, 91, 91, 320, 372, 29, 318, 30, 423, 30, 104, 373, - 104, 26, 104, 104, 104, 104, 304, 26, 26, 292, 26, 28, 109, 109, 366, - 287, 30, 157, 372, 29, 30, 423, 31, 235, 31, 373, 273, 26, 157, 157, - 157, 157, 26, 26, 31, 26, 66, 28, 66, 454, - - 26, 26, 30, 29, 29, 235, 30, 28, 28, 455, 32, 31, 32, 192, 31, - 205, 209, 30, 30, 91, 31, 34, 477, 34, 454, 32, 33, 380, 33, 529, - 207, 235, 66, 206, 455, 32, 31, 34, 529, 31, 32, 36, 109, 36, 31, - 31, 157, 477, 35, 33, 35, 32, 235, 380, 37, 33, 37, 66, 66, 66, - 36, 32, 500, 34, 35, 32, 37, 36, 417, 196, 35, 194, 32, 32, 193, - 33, 319, 319, 319, 319, 33, 173, 171, 34, 34, 170, 36, 500, 33, 33, - 35, 159, 37, 36, 417, 43, 35, 43, 529, 43, - - 43, 43, 43, 36, 36, 377, 377, 377, 377, 134, 35, 35, 384, 384, 384, - 384, 37, 37, 38, 38, 38, 128, 38, 38, 38, 38, 39, 39, 39, 38, - 39, 39, 39, 39, 44, 44, 44, 39, 44, 44, 44, 44, 60, 418, 60, - 44, 60, 60, 60, 60, 122, 450, 59, 59, 67, 38, 67, 43, 43, 527, - 59, 458, 59, 39, 59, 59, 59, 59, 62, 418, 62, 44, 62, 62, 62, - 62, 68, 450, 68, 120, 69, 481, 69, 70, 527, 70, 71, 458, 71, 482, - 72, 119, 72, 73, 487, 73, 116, 499, 103, 70, - - 280, 68, 102, 71, 60, 60, 69, 481, 74, 73, 74, 502, 75, 101, 75, - 482, 67, 67, 96, 72, 487, 506, 59, 499, 280, 70, 93, 68, 93, 71, - 62, 62, 69, 92, 280, 73, 85, 502, 68, 68, 74, 75, 69, 69, 72, - 70, 70, 506, 71, 71, 280, 84, 72, 72, 550, 73, 73, 76, 76, 76, - 280, 76, 76, 76, 76, 74, 75, 83, 76, 280, 74, 74, 78, 64, 75, - 75, 77, 77, 77, 550, 77, 77, 77, 77, 558, 87, 87, 77, 93, 93, - 57, 54, 507, 87, 76, 87, 509, 87, 87, 87, - - 87, 88, 512, 88, 563, 88, 88, 88, 88, 558, 90, 53, 90, 77, 90, - 90, 90, 90, 507, 94, 94, 94, 509, 94, 94, 94, 94, 48, 512, 563, - 94, 95, 95, 95, 518, 95, 95, 95, 95, 105, 105, 110, 95, 110, 129, - 520, 129, 105, 47, 105, 41, 105, 105, 105, 105, 87, 94, 524, 19, 111, - 518, 111, 16, 88, 88, 519, 519, 532, 95, 15, 11, 520, 90, 90, 106, - 534, 106, 566, 106, 106, 106, 106, 107, 524, 107, 111, 107, 107, 107, 107, - 108, 0, 108, 532, 108, 108, 108, 108, 112, 537, - - 112, 534, 566, 110, 110, 577, 129, 129, 113, 105, 113, 111, 124, 544, 124, - 0, 124, 124, 124, 124, 0, 111, 111, 112, 113, 537, 0, 114, 114, 114, - 577, 114, 114, 114, 114, 519, 106, 106, 114, 544, 115, 115, 115, 0, 115, - 115, 115, 115, 586, 112, 113, 115, 108, 108, 223, 223, 397, 397, 397, 397, - 112, 112, 0, 323, 114, 0, 223, 223, 223, 223, 113, 113, 0, 586, 125, - 551, 125, 115, 125, 125, 125, 125, 130, 0, 130, 323, 130, 130, 130, 130, - 131, 131, 131, 552, 131, 131, 131, 131, 132, 132, - - 132, 551, 132, 132, 132, 132, 135, 545, 135, 132, 136, 323, 136, 137, 137, - 138, 545, 138, 140, 552, 140, 137, 556, 137, 223, 560, 136, 131, 561, 135, - 562, 564, 323, 598, 139, 132, 139, 141, 0, 141, 143, 568, 143, 0, 130, - 130, 138, 0, 556, 140, 0, 560, 136, 141, 561, 135, 562, 564, 598, 139, - 142, 139, 142, 143, 144, 569, 144, 568, 135, 135, 0, 138, 136, 136, 140, - 142, 545, 138, 138, 141, 140, 140, 0, 137, 137, 139, 145, 139, 145, 143, - 144, 569, 152, 142, 152, 0, 139, 139, 146, 141, - - 141, 142, 143, 143, 570, 146, 152, 146, 535, 535, 147, 145, 147, 149, 0, - 149, 144, 150, 142, 150, 573, 146, 142, 142, 147, 0, 144, 144, 148, 148, - 570, 153, 152, 153, 535, 0, 148, 145, 148, 156, 147, 156, 154, 150, 154, - 149, 573, 146, 145, 145, 147, 153, 0, 0, 152, 152, 155, 155, 0, 151, - 535, 151, 156, 0, 155, 147, 155, 146, 146, 150, 149, 154, 147, 147, 151, - 149, 149, 153, 535, 150, 150, 576, 177, 151, 177, 163, 151, 163, 156, 163, - 163, 163, 163, 153, 153, 0, 154, 578, 148, 148, - - 151, 156, 156, 0, 154, 154, 0, 576, 182, 151, 182, 174, 151, 174, 0, - 174, 174, 174, 174, 0, 579, 151, 151, 578, 0, 0, 155, 155, 175, 183, - 175, 183, 175, 175, 175, 175, 178, 0, 178, 0, 178, 178, 178, 178, 177, - 177, 579, 163, 163, 179, 179, 179, 0, 179, 179, 179, 179, 180, 180, 180, - 0, 180, 180, 180, 180, 184, 0, 184, 180, 581, 182, 182, 0, 185, 0, - 185, 186, 0, 186, 187, 0, 187, 420, 420, 420, 420, 179, 188, 186, 188, - 0, 183, 183, 185, 180, 581, 187, 0, 178, 178, - - 200, 0, 200, 188, 189, 0, 189, 188, 583, 191, 0, 191, 567, 567, 186, - 435, 435, 435, 435, 185, 584, 191, 187, 493, 493, 493, 493, 184, 184, 188, - 587, 189, 589, 188, 583, 185, 185, 0, 186, 186, 0, 187, 187, 190, 0, - 190, 584, 191, 593, 188, 188, 498, 498, 498, 498, 585, 587, 189, 589, 0, - 190, 0, 200, 200, 585, 597, 189, 189, 601, 0, 190, 191, 191, 197, 593, - 197, 602, 197, 197, 197, 197, 0, 567, 198, 603, 198, 190, 198, 198, 198, - 198, 597, 0, 201, 601, 201, 190, 201, 201, 201, - - 201, 213, 602, 213, 0, 190, 190, 202, 202, 202, 603, 202, 202, 202, 202, - 203, 203, 203, 0, 203, 203, 203, 203, 210, 585, 210, 203, 210, 210, 210, - 210, 211, 217, 211, 217, 211, 211, 211, 211, 0, 0, 214, 230, 214, 202, - 214, 214, 214, 214, 230, 0, 230, 203, 0, 0, 201, 201, 0, 0, 217, - 219, 484, 219, 213, 213, 215, 215, 215, 515, 215, 215, 215, 215, 216, 216, - 216, 0, 216, 216, 216, 216, 221, 221, 484, 216, 217, 218, 219, 218, 221, - 515, 221, 0, 0, 217, 217, 0, 222, 222, 225, - - 218, 225, 215, 214, 214, 222, 0, 222, 0, 484, 216, 230, 230, 219, 0, - 226, 515, 226, 225, 227, 0, 227, 219, 219, 588, 588, 218, 224, 224, 224, - 484, 224, 224, 224, 224, 0, 0, 515, 224, 0, 0, 228, 0, 228, 225, - 226, 0, 0, 218, 218, 590, 221, 221, 228, 231, 227, 231, 228, 229, 590, - 229, 225, 225, 232, 224, 232, 0, 222, 222, 0, 226, 0, 229, 233, 231, - 233, 0, 226, 226, 228, 227, 227, 227, 228, 238, 0, 238, 234, 0, 234, - 236, 0, 236, 232, 588, 0, 0, 233, 229, 0, - - 231, 234, 0, 228, 228, 0, 239, 238, 239, 582, 582, 582, 582, 0, 0, - 236, 231, 231, 232, 590, 229, 229, 0, 233, 0, 232, 232, 234, 0, 0, - 240, 240, 0, 238, 0, 233, 233, 239, 0, 0, 0, 236, 240, 240, 240, - 240, 238, 238, 604, 234, 234, 0, 236, 236, 237, 237, 237, 604, 237, 237, - 237, 237, 239, 0, 242, 237, 242, 0, 239, 239, 241, 241, 241, 542, 241, - 241, 241, 241, 243, 0, 243, 241, 244, 0, 244, 245, 0, 245, 246, 0, - 246, 237, 243, 0, 242, 542, 243, 245, 244, 247, - - 240, 247, 248, 0, 248, 0, 249, 241, 249, 0, 0, 246, 599, 599, 599, - 599, 0, 604, 243, 242, 0, 542, 243, 245, 244, 0, 242, 242, 0, 248, - 605, 247, 249, 0, 252, 0, 252, 246, 249, 605, 243, 243, 542, 0, 244, - 244, 0, 245, 245, 0, 246, 246, 257, 0, 257, 248, 247, 0, 249, 250, - 250, 247, 247, 249, 248, 248, 252, 257, 249, 249, 0, 250, 250, 250, 250, - 251, 251, 251, 0, 251, 251, 251, 251, 256, 0, 256, 251, 258, 571, 258, - 259, 252, 259, 257, 0, 0, 252, 252, 0, 605, - - 260, 0, 260, 0, 262, 0, 262, 259, 256, 261, 571, 261, 251, 0, 257, - 257, 263, 0, 263, 0, 0, 262, 264, 0, 264, 260, 0, 0, 265, 250, - 265, 0, 261, 259, 256, 0, 571, 266, 0, 266, 0, 0, 264, 263, 0, - 256, 256, 262, 0, 258, 258, 260, 259, 259, 267, 0, 267, 571, 261, 0, - 266, 0, 260, 260, 265, 0, 262, 262, 264, 263, 0, 261, 261, 0, 276, - 0, 276, 267, 263, 263, 268, 268, 0, 0, 264, 264, 266, 0, 0, 265, - 265, 265, 268, 268, 268, 268, 274, 0, 274, 266, - - 266, 0, 0, 267, 269, 269, 269, 0, 269, 269, 269, 269, 270, 270, 277, - 269, 267, 267, 275, 0, 275, 277, 274, 277, 270, 270, 270, 270, 271, 271, - 271, 0, 271, 271, 271, 271, 276, 276, 279, 271, 279, 269, 278, 278, 278, - 283, 0, 283, 274, 275, 268, 0, 0, 0, 285, 0, 285, 0, 274, 274, - 282, 283, 282, 0, 0, 271, 281, 281, 281, 279, 281, 281, 281, 281, 275, - 0, 0, 281, 284, 284, 275, 275, 270, 277, 277, 285, 284, 283, 284, 282, - 288, 0, 288, 289, 279, 289, 0, 290, 0, 290, - - 279, 279, 0, 281, 278, 278, 0, 283, 283, 290, 285, 295, 0, 295, 282, - 0, 285, 285, 293, 293, 0, 288, 282, 282, 0, 289, 293, 0, 293, 294, - 0, 294, 0, 0, 296, 290, 296, 0, 0, 297, 295, 297, 298, 0, 298, - 294, 288, 0, 284, 284, 289, 296, 288, 288, 298, 289, 289, 0, 0, 290, - 290, 299, 0, 299, 309, 295, 309, 306, 297, 306, 0, 294, 0, 295, 295, - 0, 300, 296, 300, 0, 298, 300, 300, 300, 301, 0, 301, 306, 293, 293, - 299, 294, 294, 297, 0, 309, 296, 296, 302, 302, - - 0, 297, 297, 0, 298, 298, 302, 0, 302, 305, 0, 305, 307, 306, 307, - 299, 301, 308, 0, 308, 309, 0, 0, 299, 299, 305, 309, 309, 0, 306, - 306, 312, 307, 312, 313, 0, 313, 308, 300, 300, 310, 301, 310, 314, 0, - 314, 301, 301, 0, 0, 0, 305, 310, 311, 0, 311, 0, 313, 307, 0, - 312, 0, 0, 308, 0, 0, 0, 0, 302, 302, 0, 305, 305, 311, 307, - 307, 0, 0, 310, 308, 308, 0, 315, 313, 315, 312, 316, 0, 316, 321, - 0, 321, 0, 312, 312, 0, 313, 313, 316, 311, - - 0, 0, 310, 310, 0, 314, 314, 0, 322, 0, 322, 0, 0, 0, 315, - 311, 311, 326, 321, 326, 322, 324, 324, 324, 316, 324, 324, 324, 324, 0, - 0, 0, 324, 325, 0, 325, 330, 0, 330, 315, 0, 0, 0, 321, 315, - 315, 322, 325, 316, 316, 0, 321, 321, 331, 331, 0, 0, 325, 324, 0, - 0, 331, 330, 331, 0, 0, 0, 325, 0, 0, 322, 322, 0, 325, 334, - 0, 334, 0, 0, 326, 326, 0, 0, 325, 0, 337, 0, 337, 330, 332, - 332, 338, 325, 338, 334, 325, 325, 0, 330, 330, - - 337, 332, 332, 332, 332, 333, 333, 333, 0, 333, 333, 333, 333, 0, 338, - 336, 333, 336, 339, 339, 334, 0, 0, 331, 331, 0, 337, 342, 0, 342, - 339, 339, 339, 339, 0, 336, 334, 334, 0, 342, 338, 341, 333, 341, 345, - 0, 345, 337, 337, 0, 344, 0, 344, 338, 338, 343, 341, 343, 345, 332, - 0, 336, 340, 340, 340, 342, 340, 340, 340, 340, 0, 341, 344, 340, 346, - 343, 346, 336, 336, 347, 0, 347, 341, 348, 345, 348, 0, 0, 339, 342, - 342, 349, 0, 349, 346, 0, 341, 0, 344, 340, - - 0, 343, 0, 341, 341, 0, 345, 345, 350, 0, 350, 0, 344, 344, 0, - 351, 351, 343, 343, 0, 346, 0, 0, 0, 0, 0, 350, 351, 351, 351, - 351, 0, 0, 354, 0, 354, 346, 346, 0, 353, 353, 347, 347, 0, 0, - 348, 348, 353, 0, 353, 0, 0, 350, 349, 349, 352, 352, 352, 354, 352, - 352, 352, 352, 355, 0, 355, 352, 357, 0, 357, 350, 350, 356, 0, 356, - 0, 358, 353, 358, 0, 359, 0, 359, 0, 354, 351, 0, 357, 355, 360, - 358, 360, 352, 0, 0, 354, 354, 0, 361, 0, - - 361, 364, 353, 364, 362, 360, 362, 356, 0, 353, 353, 0, 0, 357, 355, - 359, 358, 0, 361, 362, 0, 0, 363, 0, 363, 355, 355, 0, 0, 357, - 357, 360, 356, 0, 356, 356, 363, 0, 358, 358, 359, 0, 359, 359, 361, - 362, 365, 0, 365, 0, 0, 360, 360, 368, 0, 368, 374, 0, 374, 0, - 361, 361, 363, 364, 364, 0, 362, 362, 369, 0, 369, 365, 370, 0, 370, - 375, 375, 0, 0, 368, 0, 374, 0, 0, 363, 363, 0, 375, 375, 375, - 375, 0, 0, 0, 369, 0, 379, 365, 379, 0, - - 386, 370, 386, 0, 383, 368, 383, 374, 365, 365, 0, 0, 381, 0, 381, - 368, 368, 0, 374, 374, 369, 0, 379, 382, 0, 382, 370, 383, 0, 381, - 369, 369, 386, 0, 370, 370, 376, 376, 376, 382, 376, 376, 376, 376, 388, - 375, 388, 376, 379, 387, 0, 387, 389, 383, 389, 381, 0, 386, 379, 379, - 0, 0, 386, 386, 0, 382, 383, 383, 388, 390, 0, 390, 0, 376, 381, - 381, 391, 389, 391, 387, 0, 0, 0, 0, 0, 382, 382, 0, 392, 0, - 392, 396, 391, 396, 388, 0, 0, 0, 0, 390, - - 0, 0, 0, 389, 387, 0, 388, 388, 399, 399, 396, 387, 387, 0, 389, - 389, 0, 0, 391, 392, 399, 399, 399, 399, 390, 400, 400, 402, 0, 402, - 0, 390, 390, 400, 0, 400, 396, 0, 391, 391, 403, 0, 403, 0, 392, - 402, 0, 404, 0, 404, 392, 392, 0, 396, 396, 401, 401, 401, 403, 401, - 401, 401, 401, 405, 0, 405, 401, 404, 0, 0, 410, 402, 410, 0, 406, - 0, 406, 407, 399, 407, 409, 0, 409, 408, 403, 408, 410, 0, 405, 402, - 402, 0, 401, 404, 406, 400, 400, 407, 0, 411, - - 0, 411, 403, 403, 412, 409, 412, 0, 0, 404, 404, 0, 410, 408, 405, - 411, 425, 0, 425, 422, 406, 422, 0, 407, 0, 405, 405, 414, 0, 414, - 0, 409, 410, 410, 0, 412, 406, 406, 408, 407, 407, 411, 409, 409, 422, - 408, 408, 419, 0, 419, 415, 414, 415, 416, 0, 416, 424, 0, 424, 0, - 412, 411, 411, 0, 0, 415, 412, 412, 0, 0, 422, 419, 427, 416, 427, - 0, 424, 414, 425, 425, 0, 422, 422, 426, 0, 426, 428, 0, 428, 414, - 414, 415, 429, 429, 429, 426, 0, 419, 430, 416, - - 430, 427, 424, 431, 0, 431, 432, 0, 432, 419, 419, 0, 415, 415, 430, - 416, 416, 0, 424, 424, 433, 426, 433, 434, 434, 439, 427, 439, 0, 437, - 437, 434, 0, 434, 427, 427, 0, 0, 0, 0, 430, 437, 437, 437, 437, - 426, 426, 0, 428, 428, 440, 0, 440, 0, 429, 429, 433, 0, 0, 0, - 430, 430, 447, 0, 447, 431, 431, 0, 432, 432, 441, 0, 441, 438, 438, - 438, 0, 438, 438, 438, 438, 433, 433, 433, 438, 0, 0, 439, 439, 0, - 442, 0, 442, 434, 434, 441, 0, 0, 443, 437, - - 443, 0, 0, 444, 0, 444, 0, 445, 442, 445, 438, 0, 440, 440, 448, - 0, 448, 0, 0, 0, 446, 441, 446, 443, 447, 447, 0, 452, 444, 452, - 0, 0, 441, 441, 442, 449, 449, 445, 446, 0, 451, 0, 451, 449, 0, - 449, 0, 452, 453, 443, 453, 0, 442, 442, 444, 456, 0, 456, 0, 0, - 443, 443, 445, 0, 446, 444, 444, 451, 0, 445, 445, 456, 0, 452, 0, - 0, 448, 448, 457, 453, 0, 0, 446, 446, 0, 457, 457, 457, 0, 452, - 452, 0, 0, 451, 459, 0, 459, 456, 460, 0, - - 460, 0, 451, 451, 453, 449, 449, 461, 459, 461, 453, 453, 462, 0, 462, - 0, 0, 456, 456, 464, 0, 464, 463, 461, 463, 465, 465, 0, 0, 460, - 467, 467, 462, 0, 459, 0, 0, 465, 465, 465, 465, 0, 467, 467, 467, - 467, 0, 457, 457, 461, 0, 470, 463, 470, 460, 0, 459, 459, 462, 0, - 460, 460, 469, 0, 469, 471, 0, 471, 0, 461, 461, 472, 0, 472, 462, - 462, 473, 463, 473, 0, 469, 464, 464, 471, 463, 463, 466, 466, 466, 472, - 466, 466, 466, 466, 474, 465, 474, 466, 0, 479, - - 467, 479, 0, 490, 0, 0, 469, 0, 0, 471, 490, 0, 490, 470, 470, - 472, 479, 475, 475, 0, 478, 0, 478, 466, 469, 469, 0, 471, 471, 475, - 475, 475, 475, 472, 472, 483, 0, 483, 473, 473, 478, 0, 479, 475, 480, - 475, 480, 476, 476, 476, 0, 476, 476, 476, 476, 0, 474, 474, 476, 0, - 483, 479, 479, 0, 0, 485, 478, 485, 492, 475, 492, 475, 490, 490, 0, - 480, 489, 0, 489, 488, 0, 488, 478, 478, 476, 485, 483, 475, 486, 486, - 486, 488, 486, 486, 486, 486, 489, 483, 483, 486, - - 480, 0, 0, 491, 0, 491, 480, 480, 495, 0, 495, 485, 496, 0, 496, - 0, 0, 488, 491, 497, 0, 497, 489, 0, 503, 486, 503, 485, 485, 0, - 492, 492, 504, 0, 504, 505, 0, 505, 489, 489, 0, 488, 488, 511, 491, - 511, 0, 503, 508, 0, 508, 505, 504, 517, 0, 517, 0, 513, 511, 513, - 0, 0, 0, 0, 0, 491, 491, 523, 0, 523, 495, 495, 0, 503, 496, - 496, 0, 505, 504, 508, 0, 497, 497, 514, 511, 514, 503, 503, 513, 0, - 0, 521, 523, 521, 504, 504, 0, 505, 505, 0, - - 0, 522, 0, 522, 508, 511, 511, 521, 0, 514, 508, 508, 528, 513, 528, - 517, 517, 522, 523, 513, 513, 516, 516, 516, 0, 516, 516, 516, 516, 523, - 523, 526, 516, 521, 531, 514, 531, 0, 526, 0, 526, 0, 530, 522, 530, - 514, 514, 540, 0, 540, 538, 0, 538, 521, 521, 0, 0, 0, 516, 531, - 0, 0, 530, 522, 522, 538, 539, 0, 539, 0, 0, 549, 0, 549, 528, - 528, 554, 0, 554, 0, 548, 539, 548, 565, 555, 531, 555, 0, 530, 0, - 565, 538, 565, 0, 0, 0, 531, 531, 0, 0, - - 526, 526, 0, 0, 530, 530, 548, 539, 0, 540, 540, 0, 538, 538, 543, - 543, 543, 0, 543, 543, 543, 543, 0, 0, 559, 543, 559, 0, 539, 539, - 0, 0, 548, 549, 549, 0, 0, 0, 554, 554, 0, 0, 548, 548, 0, - 0, 555, 555, 0, 559, 0, 543, 565, 565, 572, 572, 572, 0, 572, 572, - 572, 572, 0, 0, 0, 572, 574, 574, 0, 0, 595, 595, 0, 0, 0, - 559, 0, 0, 574, 574, 574, 574, 595, 595, 595, 595, 559, 559, 0, 0, - 0, 572, 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 574, 0, 0, 0, 595, 609, 609, 609, 610, - 610, 610, 611, 0, 611, 612, 0, 612, 614, 0, 614, 615, 0, 615, 616, - 0, 616, 617, 0, 617, 618, 0, 618, 619, 0, 619, 620, 0, 620, 622, - 0, 622, 623, 0, 623, 625, 0, 625, 626, 0, 626, 628, 0, 628, 629, - 0, 629, 630, 0, 630, 631, 0, 631, 608, 608, - - 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, - 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, - 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, - 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, - 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608}; +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static const flex_int16_t yy_accept[609] = + { 0, + 0, 0, 16, 16, 0, 0, 0, 0, 0, 0, + 100, 98, 73, 74, 98, 98, 76, 77, 98, 98, + 98, 95, 94, 95, 98, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 98, 98, 74, + 12, 13, 93, 98, 16, 15, 16, 12, 13, 44, + 20, 21, 44, 44, 24, 25, 44, 44, 44, 41, + 22, 41, 44, 44, 41, 41, 41, 41, 41, 41, + 41, 41, 41, 41, 41, 44, 44, 12, 13, 51, + 45, 46, 51, 51, 51, 51, 51, 48, 51, 48, + 51, 51, 48, 51, 51, 12, 13, 60, 55, 56, + + 60, 60, 60, 60, 60, 57, 60, 57, 60, 57, + 57, 57, 57, 60, 60, 12, 13, 74, 0, 0, + 97, 0, 1, 0, 96, 73, 75, 0, 95, 95, + 0, 0, 74, 0, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 74, 93, 0, 12, + 1, 13, 93, 16, 1, 12, 1, 13, 21, 0, + 0, 43, 0, 0, 42, 20, 41, 41, 0, 0, + 23, 36, 26, 27, 41, 41, 28, 41, 41, 41, + 41, 46, 0, 0, 50, 0, 0, 49, 45, 48, + + 48, 0, 0, 47, 56, 0, 0, 59, 0, 0, + 58, 55, 57, 57, 0, 0, 57, 57, 57, 1, + 95, 95, 0, 0, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 0, 95, 0, 95, 95, 0, + 0, 95, 95, 95, 95, 95, 95, 95, 95, 0, + 0, 95, 1, 1, 1, 41, 41, 29, 41, 41, + 41, 41, 41, 41, 57, 57, 57, 0, 0, 0, + 0, 89, 0, 95, 95, 17, 95, 95, 95, 0, + 0, 95, 95, 95, 95, 0, 0, 95, 95, 95, + 80, 0, 95, 95, 95, 95, 95, 95, 95, 95, + + 95, 95, 92, 0, 95, 41, 41, 41, 41, 41, + 41, 41, 41, 52, 57, 57, 82, 0, 81, 0, + 95, 95, 0, 0, 95, 69, 0, 0, 0, 95, + 95, 0, 0, 95, 0, 95, 95, 95, 0, 0, + 95, 95, 95, 95, 95, 95, 70, 71, 72, 95, + 0, 0, 95, 41, 41, 41, 41, 41, 41, 41, + 41, 57, 57, 62, 95, 0, 0, 95, 95, 95, + 69, 0, 0, 95, 0, 0, 91, 0, 95, 0, + 95, 95, 95, 90, 0, 95, 95, 95, 95, 95, + 95, 95, 70, 71, 72, 95, 84, 0, 0, 95, + + 0, 41, 41, 37, 41, 41, 38, 41, 41, 57, + 57, 95, 0, 95, 95, 95, 0, 0, 95, 85, + 0, 95, 0, 95, 18, 95, 95, 14, 95, 95, + 67, 19, 95, 95, 78, 0, 0, 0, 35, 33, + 41, 41, 41, 41, 41, 41, 53, 54, 95, 0, + 95, 95, 95, 0, 0, 95, 95, 0, 95, 95, + 95, 95, 95, 68, 0, 0, 79, 0, 41, 31, + 41, 41, 30, 34, 0, 0, 0, 95, 95, 95, + 0, 0, 95, 0, 95, 0, 0, 95, 95, 95, + 95, 61, 83, 0, 39, 32, 40, 86, 0, 0, + + 0, 0, 95, 95, 95, 0, 0, 95, 0, 0, + 95, 0, 95, 95, 0, 0, 5, 0, 0, 0, + 95, 95, 95, 0, 10, 95, 0, 6, 0, 95, + 95, 0, 0, 0, 0, 0, 0, 95, 95, 63, + 11, 0, 0, 0, 0, 3, 0, 95, 66, 0, + 0, 0, 8, 65, 64, 0, 0, 0, 95, 0, + 0, 0, 0, 0, 95, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, + 4, 0, 0, 9, 0, 0, 0, 0, 88, 7, + + 0, 0, 0, 0, 0, 2, 0, 0 + } ; + +static const YY_CHAR yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 3, 1, 4, 1, 1, 1, 1, 5, 6, + 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 14, 14, 14, 14, 14, 14, 1, 18, 1, + 19, 20, 1, 21, 22, 23, 24, 25, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 40, 41, 42, 43, 44, 45, 46, 38, + 47, 47, 47, 47, 38, 47, 48, 49, 50, 51, + + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, + 62, 63, 38, 64, 65, 66, 67, 68, 69, 70, + 71, 38, 47, 47, 47, 47, 1, 47, 72, 73, + 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, + 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, + 73, 73, 73, 73, 73, 73, 73, 73, 73, 74, + 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, + 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, + 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, + 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, + + 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, + 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, + 74, 74, 74, 73, 73, 73, 73, 73, 73, 73, + 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, + 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, + 73, 73, 1, 1, 1 + } ; + +static const YY_CHAR yy_meta[75] = + { 0, + 1, 2, 1, 1, 1, 1, 1, 1, 1, 3, + 3, 3, 1, 3, 3, 3, 3, 1, 1, 1, + 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 1, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3 + } ; + +static const flex_int16_t yy_base[632] = + { 0, + 0, 72, 74, 82, 144, 70, 218, 291, 364, 83, + 871, 3699, 3699, 241, 866, 858, 3699, 3699, 839, 87, + 243, 252, 95, 260, 245, 429, 67, 436, 432, 446, + 473, 501, 517, 512, 539, 532, 545, 609, 617, 268, + 831, 0, 586, 625, 0, 3699, 829, 808, 0, 3699, + 3699, 246, 808, 787, 3699, 3699, 771, 103, 651, 633, + 111, 659, 248, 755, 276, 487, 645, 667, 671, 674, + 677, 681, 684, 699, 703, 748, 767, 753, 0, 3699, + 3699, 249, 764, 747, 717, 119, 784, 792, 340, 801, + 448, 715, 717, 810, 822, 699, 0, 3699, 3699, 251, + + 710, 698, 679, 449, 838, 865, 873, 881, 471, 832, + 850, 889, 899, 918, 931, 677, 0, 258, 671, 676, + 3699, 646, 0, 903, 965, 3699, 270, 601, 835, 973, + 981, 989, 275, 589, 997, 1001, 1012, 1006, 1025, 1009, + 1028, 1051, 1031, 1055, 1077, 1096, 1101, 1127, 1104, 1108, + 1150, 1083, 1122, 1133, 1155, 1130, 475, 226, 571, 0, + 0, 0, 1176, 0, 0, 0, 0, 0, 286, 565, + 579, 3699, 577, 1202, 1219, 3699, 1173, 1227, 1240, 1248, + 3699, 1199, 1220, 1256, 1264, 1267, 1270, 1278, 1295, 1334, + 1300, 442, 554, 568, 3699, 565, 1364, 1374, 3699, 1291, + + 1384, 1398, 1406, 3699, 444, 513, 527, 3699, 512, 1414, + 1422, 3699, 1392, 1432, 1456, 1464, 1423, 1477, 1451, 0, + 1480, 1496, 953, 1518, 1490, 1506, 1510, 1532, 1549, 1440, + 1545, 1554, 1564, 1578, 481, 1581, 1645, 1575, 1597, 1629, + 1661, 1655, 1669, 1673, 1676, 1679, 1690, 1693, 1697, 1758, + 1766, 1725, 0, 0, 0, 1774, 1743, 1778, 1781, 1791, + 1800, 1795, 1807, 1813, 1819, 1828, 1845, 1879, 1895, 1911, + 1919, 312, 466, 1887, 1909, 1865, 1912, 1933, 1929, 698, + 1957, 1951, 1936, 1977, 1945, 68, 455, 1981, 1984, 1988, + 320, 449, 2017, 2020, 2002, 2025, 2030, 2033, 2052, 2067, + + 2075, 2097, 329, 446, 2100, 2058, 2103, 2108, 2055, 2131, + 2144, 2122, 2125, 2134, 2173, 2177, 345, 434, 563, 431, + 2180, 2199, 961, 2212, 2224, 2208, 39, 77, 422, 2227, + 2252, 2288, 2296, 2265, 213, 2306, 2276, 2282, 2317, 2353, + 2332, 2318, 2346, 2341, 2335, 2365, 2370, 2374, 2382, 2399, + 2414, 2446, 2438, 2424, 2454, 2463, 2458, 2467, 2471, 2480, + 2489, 2495, 2513, 2492, 2537, 419, 419, 2544, 2559, 2563, + 3699, 418, 424, 2547, 2574, 2627, 592, 332, 2587, 498, + 2603, 2614, 2595, 599, 330, 2591, 2640, 2635, 2643, 2660, + 2667, 2679, 3699, 3699, 3699, 2682, 943, 310, 2707, 2724, + + 2746, 2718, 2731, 2738, 2754, 2765, 2768, 2774, 2771, 2761, + 2790, 2795, 271, 2818, 2841, 2844, 545, 616, 2838, 1269, + 301, 2810, 417, 2847, 2807, 2874, 2863, 2877, 2883, 2889, + 2894, 2897, 2911, 2922, 1302, 298, 2928, 2964, 2916, 2941, + 2961, 2981, 2989, 2994, 2998, 3011, 2953, 3005, 3034, 622, + 3031, 3018, 3039, 459, 471, 3046, 3076, 632, 3085, 3089, + 3098, 3103, 3113, 3110, 3124, 3177, 3129, 266, 3153, 3142, + 3156, 3162, 3167, 3185, 3216, 3238, 483, 3211, 3190, 3235, + 652, 668, 3226, 1459, 3256, 3279, 659, 3270, 3267, 3201, + 3294, 3259, 1310, 259, 3299, 3303, 3310, 1338, 665, 523, + + 258, 682, 3315, 3323, 3326, 686, 759, 3339, 767, 242, + 3334, 768, 3348, 3374, 1466, 3412, 3344, 799, 864, 810, + 3382, 3392, 3358, 823, 3699, 3429, 617, 3403, 527, 3433, + 3425, 838, 122, 853, 1107, 121, 865, 3441, 3457, 3438, + 3699, 1671, 3505, 884, 1005, 3699, 117, 3471, 3462, 712, + 954, 961, 3699, 3467, 3475, 993, 116, 745, 3515, 996, + 996, 995, 762, 1002, 3481, 838, 1311, 1019, 1036, 1069, + 1786, 3545, 1091, 3565, 111, 1160, 866, 1163, 1191, 109, + 1234, 1596, 1276, 1291, 1353, 906, 1296, 1523, 1297, 1548, + 3699, 101, 1319, 3699, 3569, 93, 1331, 994, 1699, 3699, + + 1339, 1341, 1350, 1646, 1728, 3699, 87, 3699, 3641, 3644, + 3647, 3650, 97, 3653, 3656, 3659, 3662, 3665, 3668, 3671, + 91, 3674, 3677, 90, 3680, 3683, 89, 3686, 3689, 3692, + 3695 + } ; + +static const flex_int16_t yy_def[632] = + { 0, + 608, 1, 609, 609, 608, 5, 610, 610, 608, 9, + 608, 608, 608, 608, 611, 612, 608, 608, 608, 608, + 608, 613, 608, 613, 608, 613, 613, 613, 613, 613, + 613, 613, 613, 613, 613, 613, 613, 613, 613, 608, + 614, 615, 613, 613, 616, 608, 616, 617, 618, 608, + 608, 608, 619, 620, 608, 608, 608, 608, 608, 621, + 608, 621, 608, 608, 621, 621, 621, 621, 621, 621, + 621, 621, 621, 621, 621, 621, 621, 614, 615, 608, + 608, 608, 622, 623, 608, 608, 608, 624, 608, 624, + 608, 608, 624, 624, 624, 614, 615, 608, 608, 608, + + 625, 626, 608, 608, 608, 627, 608, 627, 608, 627, + 627, 627, 627, 627, 627, 614, 615, 608, 608, 611, + 608, 612, 628, 608, 608, 608, 608, 608, 613, 613, + 613, 613, 608, 608, 613, 613, 613, 613, 613, 613, + 613, 613, 613, 613, 613, 613, 613, 613, 613, 613, + 613, 613, 613, 613, 613, 613, 608, 608, 608, 614, + 629, 615, 613, 616, 630, 617, 631, 618, 608, 608, + 619, 608, 620, 608, 608, 608, 621, 621, 621, 621, + 608, 621, 621, 621, 621, 621, 621, 621, 621, 621, + 621, 608, 608, 622, 608, 623, 608, 608, 608, 624, + + 624, 624, 624, 608, 608, 608, 625, 608, 626, 608, + 608, 608, 627, 627, 627, 627, 627, 627, 627, 628, + 613, 613, 608, 613, 613, 613, 613, 613, 613, 613, + 613, 613, 613, 613, 608, 613, 613, 613, 613, 608, + 613, 613, 613, 613, 613, 613, 613, 613, 613, 608, + 613, 613, 629, 630, 631, 621, 621, 621, 621, 621, + 621, 621, 621, 621, 627, 627, 627, 608, 613, 608, + 613, 608, 608, 613, 613, 613, 613, 613, 613, 608, + 613, 613, 613, 613, 613, 608, 608, 613, 613, 613, + 608, 608, 613, 613, 613, 613, 613, 613, 613, 613, + + 613, 613, 608, 608, 613, 621, 621, 621, 621, 621, + 621, 621, 621, 627, 627, 627, 608, 608, 608, 608, + 613, 613, 608, 613, 613, 613, 608, 608, 608, 613, + 613, 608, 613, 613, 608, 613, 613, 613, 608, 613, + 613, 613, 613, 613, 613, 613, 613, 613, 613, 613, + 608, 613, 613, 621, 621, 621, 621, 621, 621, 621, + 621, 627, 627, 613, 613, 608, 608, 613, 613, 613, + 608, 608, 608, 613, 608, 613, 608, 608, 613, 608, + 613, 613, 613, 608, 608, 613, 613, 613, 613, 613, + 613, 613, 608, 608, 608, 613, 608, 608, 608, 613, + + 613, 621, 621, 621, 621, 621, 621, 621, 621, 627, + 627, 613, 608, 613, 613, 613, 608, 608, 613, 608, + 608, 613, 608, 613, 613, 613, 613, 613, 613, 613, + 613, 613, 613, 613, 608, 608, 608, 613, 621, 621, + 621, 621, 621, 621, 621, 621, 627, 627, 613, 608, + 613, 613, 613, 608, 608, 613, 613, 608, 613, 613, + 613, 613, 613, 613, 608, 613, 608, 608, 621, 621, + 621, 621, 621, 621, 608, 613, 608, 613, 613, 613, + 608, 608, 613, 608, 613, 613, 608, 613, 613, 613, + 613, 613, 608, 608, 621, 621, 621, 608, 608, 608, + + 608, 608, 613, 613, 613, 608, 608, 613, 608, 608, + 613, 608, 613, 613, 608, 613, 613, 608, 608, 608, + 613, 613, 613, 608, 608, 613, 608, 613, 608, 613, + 613, 608, 608, 608, 608, 608, 608, 613, 613, 613, + 608, 608, 613, 608, 608, 608, 608, 613, 613, 608, + 608, 608, 608, 613, 613, 608, 608, 608, 613, 608, + 608, 608, 608, 608, 613, 608, 608, 608, 608, 608, + 608, 613, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, + + 608, 608, 608, 608, 608, 608, 608, 0, 608, 608, + 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, + 608 + } ; + +static const flex_int16_t yy_nxt[3774] = + { 0, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, + 22, 23, 12, 24, 24, 24, 24, 25, 12, 12, + 12, 26, 27, 28, 29, 30, 31, 27, 27, 32, + 27, 27, 27, 27, 27, 27, 33, 27, 34, 35, + 36, 27, 37, 27, 27, 27, 12, 26, 27, 28, + 29, 30, 31, 27, 27, 32, 27, 27, 27, 27, + 27, 27, 33, 34, 35, 36, 27, 37, 27, 27, + 27, 38, 39, 27, 40, 46, 608, 78, 608, 41, + 372, 47, 79, 46, 42, 43, 43, 43, 43, 48, + 116, 213, 200, 177, 49, 117, 124, 335, 124, 129, + + 125, 125, 125, 125, 124, 372, 124, 605, 125, 125, + 125, 125, 174, 595, 174, 373, 175, 175, 175, 175, + 174, 590, 174, 335, 175, 175, 175, 175, 197, 571, + 197, 574, 198, 198, 198, 198, 542, 545, 131, 132, + 373, 535, 515, 44, 50, 51, 52, 53, 54, 55, + 56, 57, 58, 59, 60, 61, 50, 62, 62, 62, + 62, 63, 64, 50, 50, 65, 66, 67, 67, 67, + 67, 67, 67, 68, 69, 67, 70, 67, 67, 71, + 72, 67, 73, 74, 75, 67, 67, 67, 67, 67, + 50, 65, 66, 67, 67, 67, 67, 67, 67, 68, + + 69, 67, 70, 67, 67, 71, 72, 73, 74, 75, + 67, 67, 67, 67, 67, 76, 77, 67, 80, 81, + 82, 83, 84, 80, 80, 85, 86, 87, 88, 89, + 80, 90, 90, 90, 90, 91, 92, 80, 80, 158, + 158, 158, 158, 118, 126, 127, 126, 133, 169, 176, + 169, 192, 124, 205, 124, 380, 125, 125, 125, 125, + 118, 124, 484, 124, 80, 130, 130, 130, 130, 124, + 157, 124, 127, 130, 130, 130, 130, 133, 475, 465, + 380, 158, 158, 158, 158, 608, 437, 608, 169, 94, + 95, 80, 81, 82, 83, 84, 80, 80, 96, 86, + + 87, 88, 89, 97, 90, 90, 90, 90, 91, 92, + 80, 80, 119, 450, 128, 182, 134, 170, 399, 170, + 193, 375, 206, 131, 132, 272, 272, 272, 272, 119, + 351, 131, 132, 291, 291, 291, 291, 80, 450, 159, + 182, 128, 303, 303, 303, 303, 134, 179, 180, 197, + 339, 197, 332, 198, 198, 198, 198, 170, 317, 317, + 317, 317, 94, 95, 98, 99, 100, 101, 102, 98, + 98, 103, 104, 105, 106, 107, 98, 108, 108, 108, + 108, 109, 98, 98, 98, 110, 110, 111, 110, 110, + 110, 110, 110, 112, 110, 110, 110, 110, 110, 110, + + 110, 110, 113, 110, 110, 110, 110, 110, 110, 110, + 98, 110, 110, 111, 110, 110, 110, 110, 110, 112, + 110, 110, 110, 110, 110, 110, 110, 113, 110, 110, + 110, 110, 110, 110, 110, 114, 115, 110, 608, 323, + 608, 608, 280, 608, 192, 608, 205, 608, 413, 199, + 192, 270, 417, 140, 268, 608, 458, 608, 210, 418, + 210, 135, 211, 211, 211, 211, 250, 136, 137, 240, + 138, 139, 212, 205, 413, 235, 141, 157, 417, 140, + 142, 458, 608, 235, 608, 418, 223, 135, 158, 158, + 158, 158, 136, 137, 143, 138, 608, 139, 608, 481, + + 131, 132, 141, 131, 132, 286, 142, 131, 132, 482, + 608, 144, 608, 193, 145, 206, 208, 131, 132, 193, + 143, 608, 502, 608, 481, 146, 608, 423, 608, 545, + 208, 286, 183, 205, 482, 147, 144, 151, 546, 145, + 148, 608, 206, 608, 131, 132, 159, 502, 608, 149, + 608, 146, 287, 423, 608, 150, 608, 183, 179, 180, + 154, 147, 519, 151, 152, 148, 156, 155, 454, 195, + 153, 195, 131, 132, 192, 149, 319, 319, 319, 319, + 150, 172, 172, 131, 132, 169, 154, 519, 131, 132, + 152, 157, 156, 155, 454, 124, 153, 124, 547, 163, + + 163, 163, 163, 131, 132, 377, 377, 377, 377, 133, + 131, 132, 384, 384, 384, 384, 131, 132, 608, 608, + 608, 127, 608, 608, 608, 608, 608, 608, 608, 118, + 608, 608, 608, 608, 608, 608, 608, 129, 608, 608, + 608, 608, 174, 455, 174, 157, 178, 178, 178, 178, + 121, 477, 176, 169, 608, 129, 608, 131, 132, 544, + 174, 487, 174, 129, 175, 175, 175, 175, 174, 455, + 174, 129, 178, 178, 178, 178, 608, 477, 608, 121, + 608, 506, 608, 608, 544, 608, 608, 487, 608, 507, + 608, 118, 608, 608, 512, 608, 161, 518, 123, 186, + + 280, 184, 208, 187, 179, 180, 185, 506, 608, 189, + 608, 520, 608, 208, 608, 507, 179, 180, 161, 188, + 512, 524, 170, 518, 327, 186, 608, 184, 608, 187, + 179, 180, 185, 204, 328, 189, 123, 520, 179, 180, + 190, 191, 179, 180, 188, 179, 180, 524, 179, 180, + 327, 195, 179, 180, 560, 179, 180, 608, 608, 608, + 328, 608, 608, 608, 608, 190, 191, 195, 169, 329, + 179, 180, 161, 181, 179, 180, 608, 608, 608, 560, + 608, 608, 608, 608, 564, 199, 192, 177, 202, 203, + 123, 172, 525, 197, 177, 197, 527, 198, 198, 198, + + 198, 197, 529, 197, 569, 201, 201, 201, 201, 564, + 197, 172, 197, 177, 201, 201, 201, 201, 525, 608, + 608, 608, 527, 608, 608, 608, 608, 167, 529, 569, + 192, 608, 608, 608, 534, 608, 608, 608, 608, 212, + 205, 608, 200, 608, 608, 537, 608, 210, 165, 210, + 161, 211, 211, 211, 211, 193, 200, 541, 123, 608, + 534, 608, 121, 202, 203, 535, 535, 550, 200, 121, + 608, 537, 202, 203, 210, 551, 210, 573, 214, 214, + 214, 214, 210, 541, 210, 217, 211, 211, 211, 211, + 210, 608, 210, 550, 214, 214, 214, 214, 608, 553, + + 608, 551, 573, 215, 216, 584, 131, 132, 608, 206, + 608, 217, 124, 558, 124, 608, 125, 125, 125, 125, + 608, 215, 216, 218, 219, 553, 608, 608, 608, 608, + 584, 608, 608, 608, 608, 536, 215, 216, 205, 558, + 608, 608, 608, 608, 608, 608, 608, 608, 593, 218, + 219, 213, 215, 216, 223, 223, 397, 397, 397, 397, + 215, 216, 608, 323, 213, 608, 272, 272, 272, 272, + 215, 216, 608, 593, 124, 561, 124, 213, 125, 125, + 125, 125, 124, 608, 124, 366, 130, 130, 130, 130, + 608, 608, 608, 562, 608, 608, 608, 608, 608, 608, + + 608, 561, 608, 608, 608, 608, 608, 545, 608, 129, + 608, 366, 608, 223, 223, 608, 546, 608, 608, 562, + 608, 608, 563, 608, 273, 566, 222, 129, 567, 221, + 568, 570, 367, 601, 608, 129, 608, 608, 608, 608, + 608, 576, 608, 608, 131, 132, 225, 608, 563, 228, + 608, 566, 222, 229, 567, 221, 568, 570, 601, 226, + 608, 227, 608, 232, 608, 577, 608, 576, 131, 132, + 608, 225, 131, 132, 228, 230, 547, 131, 132, 229, + 131, 132, 608, 224, 132, 226, 608, 227, 608, 232, + 233, 577, 608, 231, 608, 608, 131, 132, 235, 131, + + 132, 230, 131, 132, 578, 608, 247, 608, 535, 535, + 608, 234, 608, 608, 608, 608, 233, 608, 231, 608, + 581, 236, 131, 132, 238, 608, 131, 132, 240, 240, + 578, 608, 247, 608, 552, 608, 608, 234, 608, 608, + 239, 608, 608, 243, 608, 242, 581, 236, 131, 132, + 238, 248, 608, 608, 131, 132, 250, 250, 608, 608, + 552, 608, 252, 608, 608, 239, 608, 237, 132, 243, + 242, 249, 131, 132, 244, 131, 132, 248, 536, 131, + 132, 583, 608, 245, 608, 124, 246, 124, 252, 163, + 163, 163, 163, 131, 132, 608, 249, 585, 241, 132, + + 244, 131, 132, 608, 131, 132, 608, 583, 608, 245, + 608, 174, 246, 174, 608, 175, 175, 175, 175, 608, + 586, 131, 132, 585, 608, 608, 251, 132, 174, 608, + 174, 608, 175, 175, 175, 175, 174, 608, 174, 608, + 178, 178, 178, 178, 179, 180, 586, 131, 132, 608, + 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 608, 608, 608, 608, 608, 608, 608, 177, 587, + 179, 180, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 608, 420, 420, 420, 420, 177, 608, 257, 608, + 608, 179, 180, 256, 177, 587, 258, 608, 179, 180, + + 608, 608, 608, 259, 608, 608, 608, 260, 588, 608, + 608, 608, 574, 574, 257, 435, 435, 435, 435, 256, + 589, 264, 258, 493, 493, 493, 493, 179, 180, 259, + 594, 261, 597, 260, 588, 179, 180, 608, 179, 180, + 608, 179, 180, 608, 608, 608, 589, 264, 598, 179, + 180, 498, 498, 498, 498, 590, 594, 261, 597, 608, + 262, 608, 202, 203, 591, 600, 179, 180, 602, 608, + 263, 179, 180, 197, 598, 197, 603, 198, 198, 198, + 198, 608, 575, 197, 604, 197, 262, 198, 198, 198, + 198, 600, 608, 197, 602, 197, 263, 201, 201, 201, + + 201, 608, 603, 608, 608, 179, 180, 608, 608, 608, + 604, 608, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 608, 608, 210, 592, 210, 200, 211, 211, 211, + 211, 210, 608, 210, 608, 211, 211, 211, 211, 608, + 608, 210, 280, 210, 200, 214, 214, 214, 214, 608, + 608, 608, 200, 608, 608, 202, 203, 608, 608, 265, + 608, 484, 608, 215, 216, 608, 608, 608, 515, 608, + 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 268, 268, 509, 213, 265, 608, 267, 608, 608, + 532, 608, 608, 608, 215, 216, 608, 270, 270, 608, + + 266, 608, 213, 215, 216, 608, 608, 608, 608, 509, + 213, 281, 132, 267, 608, 608, 532, 608, 274, 608, + 608, 608, 215, 216, 595, 595, 266, 608, 608, 608, + 510, 608, 608, 608, 608, 608, 608, 533, 223, 608, + 608, 608, 608, 608, 274, 275, 608, 608, 215, 216, + 590, 269, 132, 277, 608, 276, 608, 278, 608, 591, + 608, 131, 132, 608, 129, 608, 608, 271, 132, 608, + 275, 608, 279, 608, 282, 608, 608, 131, 132, 277, + 276, 131, 132, 278, 608, 608, 608, 608, 608, 608, + 608, 608, 608, 283, 596, 608, 608, 284, 279, 608, + + 282, 285, 608, 131, 132, 608, 608, 289, 608, 582, + 582, 582, 582, 608, 608, 288, 131, 132, 283, 592, + 131, 132, 608, 284, 608, 131, 132, 285, 608, 608, + 240, 240, 608, 289, 608, 131, 132, 290, 608, 608, + 608, 288, 291, 291, 291, 291, 131, 132, 605, 131, + 132, 608, 131, 132, 608, 608, 608, 606, 608, 608, + 608, 608, 290, 608, 608, 235, 608, 608, 131, 132, + 608, 608, 608, 542, 608, 608, 608, 608, 608, 608, + 608, 240, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 129, 294, 608, 293, 556, 295, 297, 296, 608, + + 292, 608, 608, 608, 608, 608, 608, 129, 608, 608, + 608, 298, 599, 599, 599, 599, 608, 607, 294, 293, + 608, 556, 295, 297, 296, 608, 131, 132, 608, 300, + 605, 299, 301, 608, 608, 608, 608, 298, 302, 606, + 131, 132, 557, 608, 131, 132, 608, 131, 132, 608, + 131, 132, 608, 608, 608, 300, 299, 608, 301, 250, + 250, 131, 132, 302, 131, 132, 305, 307, 131, 132, + 608, 303, 303, 303, 303, 608, 608, 608, 608, 608, + 608, 608, 608, 608, 608, 608, 250, 608, 571, 608, + 608, 305, 608, 307, 608, 608, 131, 132, 608, 607, + + 608, 608, 608, 608, 608, 608, 608, 308, 306, 608, + 579, 608, 129, 608, 179, 180, 608, 608, 608, 608, + 608, 311, 608, 608, 608, 309, 608, 608, 608, 304, + 608, 608, 310, 308, 306, 608, 579, 608, 608, 608, + 608, 608, 313, 312, 608, 179, 180, 311, 608, 179, + 180, 309, 179, 180, 608, 608, 608, 580, 310, 608, + 315, 608, 179, 180, 314, 608, 179, 180, 313, 312, + 608, 179, 180, 608, 608, 608, 608, 316, 179, 180, + 268, 268, 608, 608, 179, 180, 315, 608, 608, 314, + 215, 216, 317, 317, 317, 317, 608, 608, 608, 215, + + 216, 608, 608, 316, 608, 608, 608, 608, 608, 608, + 608, 608, 270, 270, 323, 268, 215, 216, 608, 608, + 608, 608, 321, 608, 319, 319, 319, 319, 608, 608, + 608, 608, 608, 608, 608, 608, 131, 132, 608, 270, + 608, 129, 608, 325, 608, 608, 608, 608, 321, 322, + 318, 608, 608, 608, 608, 608, 608, 608, 131, 132, + 608, 331, 608, 608, 608, 129, 608, 608, 608, 326, + 608, 608, 608, 608, 322, 608, 608, 280, 332, 332, + 131, 132, 320, 324, 132, 334, 608, 331, 608, 330, + 608, 608, 608, 608, 326, 608, 608, 608, 608, 608, + + 131, 132, 608, 129, 131, 132, 608, 131, 132, 338, + 334, 608, 608, 608, 330, 608, 131, 132, 339, 339, + 608, 336, 131, 132, 608, 337, 608, 608, 608, 608, + 608, 608, 608, 608, 608, 338, 608, 608, 608, 608, + 342, 608, 608, 608, 608, 341, 336, 608, 333, 132, + 337, 343, 131, 132, 345, 131, 132, 608, 608, 131, + 132, 608, 608, 608, 608, 342, 608, 608, 344, 608, + 608, 341, 608, 131, 132, 608, 608, 343, 608, 608, + 345, 347, 348, 349, 608, 608, 608, 354, 340, 132, + 346, 131, 132, 344, 608, 357, 131, 132, 351, 351, + + 608, 131, 132, 608, 131, 132, 608, 608, 608, 608, + 608, 608, 608, 354, 608, 346, 350, 608, 608, 608, + 357, 608, 608, 131, 132, 353, 179, 180, 608, 179, + 180, 608, 355, 608, 608, 608, 608, 356, 131, 132, + 608, 350, 608, 608, 608, 608, 131, 132, 608, 608, + 608, 353, 358, 608, 608, 608, 608, 361, 355, 608, + 360, 608, 608, 356, 608, 608, 608, 608, 352, 132, + 608, 131, 132, 359, 179, 180, 608, 608, 358, 179, + 180, 608, 608, 361, 608, 360, 608, 608, 608, 608, + 608, 608, 608, 179, 180, 608, 179, 180, 363, 359, + + 608, 608, 179, 180, 608, 215, 216, 608, 608, 608, + 608, 608, 608, 608, 362, 179, 180, 608, 364, 371, + 365, 608, 608, 608, 363, 608, 608, 608, 608, 608, + 608, 608, 323, 608, 608, 608, 608, 608, 608, 362, + 608, 608, 608, 364, 215, 216, 365, 368, 215, 216, + 608, 131, 132, 375, 375, 608, 608, 369, 129, 608, + 608, 608, 374, 608, 608, 608, 608, 370, 608, 608, + 131, 132, 608, 368, 608, 608, 608, 608, 608, 131, + 132, 608, 608, 369, 608, 608, 608, 608, 374, 332, + 332, 608, 370, 608, 379, 131, 132, 608, 131, 132, + + 382, 377, 377, 377, 377, 608, 608, 608, 608, 608, + 608, 608, 608, 608, 383, 608, 332, 608, 339, 339, + 379, 608, 608, 376, 132, 608, 382, 608, 608, 608, + 384, 384, 384, 384, 608, 381, 131, 132, 608, 388, + 383, 608, 129, 608, 608, 608, 608, 131, 132, 608, + 608, 608, 608, 131, 132, 608, 386, 608, 391, 378, + 608, 381, 608, 608, 608, 388, 608, 608, 608, 608, + 608, 387, 390, 339, 608, 389, 608, 131, 132, 608, + 608, 393, 386, 608, 391, 394, 608, 608, 385, 131, + 132, 608, 608, 395, 392, 608, 387, 608, 390, 129, + + 608, 389, 608, 131, 132, 608, 131, 132, 608, 608, + 608, 608, 131, 132, 608, 351, 351, 131, 132, 608, + 392, 608, 608, 608, 608, 608, 396, 397, 397, 397, + 397, 608, 608, 608, 608, 608, 131, 132, 608, 399, + 399, 131, 132, 608, 608, 131, 132, 608, 608, 608, + 608, 608, 396, 131, 132, 608, 608, 608, 402, 608, + 608, 608, 608, 608, 608, 608, 351, 608, 608, 608, + 131, 132, 608, 608, 608, 608, 608, 400, 608, 608, + 608, 608, 608, 608, 402, 398, 608, 405, 403, 608, + 406, 608, 129, 608, 608, 179, 180, 608, 608, 608, + + 608, 608, 400, 608, 608, 408, 608, 404, 608, 401, + 132, 608, 608, 405, 403, 407, 406, 608, 409, 410, + 608, 608, 608, 608, 608, 179, 180, 608, 608, 179, + 180, 408, 404, 608, 179, 180, 411, 608, 179, 180, + 407, 608, 179, 180, 409, 410, 608, 608, 608, 608, + 608, 179, 180, 608, 608, 608, 608, 608, 608, 608, + 179, 180, 411, 131, 132, 608, 215, 216, 608, 608, + 608, 412, 608, 608, 608, 375, 375, 608, 608, 414, + 608, 419, 608, 608, 215, 216, 608, 420, 420, 420, + 420, 608, 608, 608, 415, 608, 608, 412, 608, 608, + + 608, 416, 608, 608, 608, 414, 608, 419, 131, 132, + 608, 608, 608, 608, 608, 131, 132, 608, 131, 132, + 415, 608, 422, 608, 608, 608, 416, 426, 608, 424, + 131, 132, 427, 608, 131, 132, 608, 608, 608, 425, + 608, 608, 608, 608, 608, 421, 608, 375, 422, 608, + 608, 608, 608, 426, 608, 424, 608, 427, 131, 132, + 608, 608, 131, 132, 608, 425, 131, 132, 429, 608, + 608, 608, 608, 129, 131, 132, 608, 430, 608, 428, + 608, 608, 608, 608, 608, 131, 132, 608, 608, 608, + 608, 608, 432, 608, 429, 608, 608, 608, 608, 431, + + 608, 608, 608, 430, 428, 608, 131, 132, 399, 399, + 434, 131, 132, 608, 131, 132, 608, 608, 432, 433, + 435, 435, 435, 435, 431, 437, 437, 608, 608, 608, + 608, 131, 132, 608, 608, 608, 434, 608, 131, 132, + 608, 608, 608, 608, 433, 439, 608, 608, 608, 608, + 131, 132, 608, 131, 132, 608, 608, 608, 440, 608, + 608, 608, 608, 608, 608, 608, 399, 441, 608, 608, + 608, 439, 608, 608, 608, 608, 608, 608, 436, 608, + 608, 608, 608, 608, 440, 608, 447, 608, 442, 179, + 180, 608, 129, 441, 443, 438, 132, 444, 608, 608, + + 608, 608, 179, 180, 608, 446, 608, 608, 608, 179, + 180, 608, 447, 445, 442, 448, 608, 608, 608, 608, + 443, 608, 608, 444, 608, 179, 180, 608, 608, 608, + 608, 446, 215, 216, 608, 449, 179, 180, 445, 179, + 180, 448, 179, 180, 457, 179, 180, 608, 608, 608, + 608, 451, 608, 608, 608, 608, 608, 608, 608, 608, + 449, 215, 216, 608, 608, 452, 131, 132, 608, 608, + 457, 456, 608, 453, 608, 608, 459, 451, 131, 132, + 608, 131, 132, 608, 608, 608, 608, 608, 608, 131, + 132, 452, 608, 462, 608, 460, 608, 456, 608, 453, + + 608, 461, 459, 608, 608, 608, 608, 608, 608, 131, + 132, 608, 131, 132, 463, 131, 132, 608, 131, 132, + 608, 460, 608, 465, 465, 608, 461, 608, 608, 437, + 437, 608, 608, 608, 131, 132, 608, 608, 608, 608, + 463, 467, 467, 467, 467, 131, 132, 608, 131, 132, + 608, 608, 608, 608, 131, 132, 464, 608, 608, 608, + 131, 132, 608, 608, 608, 131, 132, 608, 131, 132, + 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 464, 131, 132, 437, 608, 608, 179, 180, 608, + 608, 608, 608, 466, 132, 469, 608, 608, 608, 468, + + 608, 608, 608, 608, 608, 608, 608, 608, 470, 608, + 129, 608, 179, 180, 608, 608, 608, 608, 608, 608, + 608, 469, 608, 471, 215, 216, 608, 608, 472, 608, + 608, 608, 179, 180, 470, 475, 475, 473, 474, 608, + 608, 608, 608, 608, 608, 608, 608, 479, 608, 471, + 608, 608, 179, 180, 472, 608, 608, 608, 608, 608, + 179, 180, 473, 608, 474, 179, 180, 478, 608, 179, + 180, 483, 608, 479, 608, 608, 215, 216, 484, 480, + 608, 608, 179, 180, 608, 608, 485, 608, 608, 131, + 132, 608, 608, 478, 608, 608, 608, 483, 608, 608, + + 608, 608, 131, 132, 480, 476, 132, 608, 488, 608, + 131, 132, 608, 608, 608, 608, 608, 131, 132, 608, + 608, 608, 608, 490, 608, 465, 465, 608, 608, 489, + 437, 437, 491, 608, 488, 608, 608, 493, 493, 493, + 493, 608, 467, 467, 467, 467, 608, 486, 132, 490, + 608, 608, 492, 608, 489, 608, 131, 132, 491, 608, + 131, 132, 608, 608, 608, 608, 608, 608, 608, 131, + 132, 608, 608, 608, 131, 132, 608, 492, 608, 608, + 495, 131, 132, 496, 131, 132, 608, 608, 608, 497, + 608, 608, 608, 608, 608, 494, 608, 465, 608, 608, + + 468, 608, 608, 515, 608, 608, 495, 608, 608, 496, + 608, 608, 608, 179, 180, 497, 504, 475, 475, 608, + 608, 608, 608, 129, 179, 180, 608, 179, 180, 498, + 498, 498, 498, 179, 180, 608, 608, 608, 179, 180, + 503, 608, 504, 499, 608, 500, 608, 608, 608, 608, + 608, 608, 608, 608, 608, 608, 179, 180, 475, 608, + 508, 131, 132, 608, 608, 608, 503, 608, 608, 499, + 608, 500, 516, 132, 608, 505, 608, 608, 608, 608, + 608, 608, 131, 132, 129, 511, 508, 501, 608, 608, + 608, 513, 608, 608, 608, 608, 514, 131, 132, 484, + + 505, 608, 608, 608, 608, 608, 131, 132, 608, 608, + 608, 511, 608, 608, 608, 608, 608, 513, 517, 608, + 608, 608, 514, 608, 608, 129, 608, 131, 132, 608, + 131, 132, 608, 608, 608, 608, 608, 608, 131, 132, + 608, 131, 132, 608, 517, 608, 608, 521, 608, 608, + 608, 523, 522, 608, 608, 608, 608, 608, 528, 608, + 608, 608, 608, 608, 608, 131, 132, 608, 608, 608, + 179, 180, 608, 521, 179, 180, 608, 523, 522, 526, + 608, 179, 180, 608, 528, 608, 131, 132, 530, 608, + 608, 608, 540, 608, 131, 132, 608, 131, 132, 608, + + 608, 608, 608, 608, 526, 131, 132, 538, 608, 531, + 131, 132, 608, 530, 608, 131, 132, 539, 540, 131, + 132, 608, 608, 608, 608, 608, 608, 608, 608, 131, + 132, 542, 515, 538, 608, 531, 608, 608, 608, 608, + 608, 608, 608, 539, 608, 131, 132, 608, 608, 608, + 608, 608, 608, 131, 132, 608, 608, 608, 129, 549, + 608, 608, 548, 131, 132, 554, 608, 608, 608, 608, + 608, 608, 608, 608, 131, 132, 608, 608, 608, 608, + 608, 555, 608, 571, 608, 549, 608, 608, 548, 608, + 608, 554, 608, 608, 608, 608, 131, 132, 608, 608, + + 543, 132, 608, 608, 131, 132, 559, 555, 608, 131, + 132, 608, 131, 132, 608, 608, 608, 608, 608, 608, + 608, 608, 608, 608, 608, 542, 608, 608, 131, 132, + 608, 608, 559, 131, 132, 608, 608, 608, 131, 132, + 608, 608, 131, 132, 608, 608, 131, 132, 608, 565, + 608, 129, 572, 132, 608, 608, 608, 608, 608, 608, + 608, 608, 608, 608, 608, 571, 574, 574, 608, 608, + 595, 595, 608, 608, 608, 565, 608, 608, 582, 582, + 582, 582, 599, 599, 599, 599, 131, 132, 608, 608, + 608, 129, 608, 608, 608, 608, 608, 608, 608, 608, + + 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 608, 608, 608, 608, 608, 575, 608, 608, 608, + 596, 45, 45, 45, 93, 93, 93, 120, 608, 120, + 122, 608, 122, 160, 608, 160, 162, 608, 162, 164, + 608, 164, 166, 608, 166, 168, 608, 168, 171, 608, + 171, 173, 608, 173, 194, 608, 194, 196, 608, 196, + 207, 608, 207, 209, 608, 209, 220, 608, 220, 253, + 608, 253, 254, 608, 254, 255, 608, 255, 11, 608, + + 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 608, 608 + } ; + +static const flex_int16_t yy_chk[3774] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 2, 3, 27, 6, 27, 2, + 327, 3, 6, 4, 2, 2, 2, 2, 2, 4, + 10, 627, 624, 621, 4, 10, 20, 286, 20, 613, + + 20, 20, 20, 20, 23, 327, 23, 607, 23, 23, + 23, 23, 58, 596, 58, 328, 58, 58, 58, 58, + 61, 592, 61, 286, 61, 61, 61, 61, 86, 580, + 86, 575, 86, 86, 86, 86, 557, 547, 27, 27, + 328, 536, 533, 2, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 158, + 158, 158, 158, 14, 21, 21, 25, 25, 52, 63, + 63, 82, 21, 100, 21, 335, 21, 21, 21, 21, + 118, 22, 510, 22, 7, 22, 22, 22, 22, 24, + 40, 24, 127, 24, 24, 24, 24, 133, 501, 494, + 335, 40, 40, 40, 40, 65, 468, 65, 169, 7, + 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, + + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 14, 413, 21, 65, 25, 52, 436, 63, + 82, 421, 100, 22, 22, 272, 272, 272, 272, 118, + 398, 24, 24, 291, 291, 291, 291, 8, 413, 40, + 65, 127, 303, 303, 303, 303, 133, 65, 65, 89, + 385, 89, 378, 89, 89, 89, 89, 169, 317, 317, + 317, 317, 8, 8, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 26, 367, + 26, 29, 329, 29, 192, 28, 205, 28, 366, 91, + 91, 320, 372, 29, 318, 30, 423, 30, 104, 373, + 104, 26, 104, 104, 104, 104, 304, 26, 26, 292, + 26, 28, 109, 109, 366, 287, 30, 157, 372, 29, + 30, 423, 31, 235, 31, 373, 273, 26, 157, 157, + 157, 157, 26, 26, 31, 26, 66, 28, 66, 454, + + 26, 26, 30, 29, 29, 235, 30, 28, 28, 455, + 32, 31, 32, 192, 31, 205, 209, 30, 30, 91, + 31, 34, 477, 34, 454, 32, 33, 380, 33, 529, + 207, 235, 66, 206, 455, 32, 31, 34, 529, 31, + 32, 36, 109, 36, 31, 31, 157, 477, 35, 33, + 35, 32, 235, 380, 37, 33, 37, 66, 66, 66, + 36, 32, 500, 34, 35, 32, 37, 36, 417, 196, + 35, 194, 32, 32, 193, 33, 319, 319, 319, 319, + 33, 173, 171, 34, 34, 170, 36, 500, 33, 33, + 35, 159, 37, 36, 417, 43, 35, 43, 529, 43, + + 43, 43, 43, 36, 36, 377, 377, 377, 377, 134, + 35, 35, 384, 384, 384, 384, 37, 37, 38, 38, + 38, 128, 38, 38, 38, 38, 39, 39, 39, 38, + 39, 39, 39, 39, 44, 44, 44, 39, 44, 44, + 44, 44, 60, 418, 60, 44, 60, 60, 60, 60, + 122, 450, 59, 59, 67, 38, 67, 43, 43, 527, + 59, 458, 59, 39, 59, 59, 59, 59, 62, 418, + 62, 44, 62, 62, 62, 62, 68, 450, 68, 120, + 69, 481, 69, 70, 527, 70, 71, 458, 71, 482, + 72, 119, 72, 73, 487, 73, 116, 499, 103, 70, + + 280, 68, 102, 71, 60, 60, 69, 481, 74, 73, + 74, 502, 75, 101, 75, 482, 67, 67, 96, 72, + 487, 506, 59, 499, 280, 70, 93, 68, 93, 71, + 62, 62, 69, 92, 280, 73, 85, 502, 68, 68, + 74, 75, 69, 69, 72, 70, 70, 506, 71, 71, + 280, 84, 72, 72, 550, 73, 73, 76, 76, 76, + 280, 76, 76, 76, 76, 74, 75, 83, 76, 280, + 74, 74, 78, 64, 75, 75, 77, 77, 77, 550, + 77, 77, 77, 77, 558, 87, 87, 77, 93, 93, + 57, 54, 507, 87, 76, 87, 509, 87, 87, 87, + + 87, 88, 512, 88, 563, 88, 88, 88, 88, 558, + 90, 53, 90, 77, 90, 90, 90, 90, 507, 94, + 94, 94, 509, 94, 94, 94, 94, 48, 512, 563, + 94, 95, 95, 95, 518, 95, 95, 95, 95, 105, + 105, 110, 95, 110, 129, 520, 129, 105, 47, 105, + 41, 105, 105, 105, 105, 87, 94, 524, 19, 111, + 518, 111, 16, 88, 88, 519, 519, 532, 95, 15, + 11, 520, 90, 90, 106, 534, 106, 566, 106, 106, + 106, 106, 107, 524, 107, 111, 107, 107, 107, 107, + 108, 0, 108, 532, 108, 108, 108, 108, 112, 537, + + 112, 534, 566, 110, 110, 577, 129, 129, 113, 105, + 113, 111, 124, 544, 124, 0, 124, 124, 124, 124, + 0, 111, 111, 112, 113, 537, 0, 114, 114, 114, + 577, 114, 114, 114, 114, 519, 106, 106, 114, 544, + 115, 115, 115, 0, 115, 115, 115, 115, 586, 112, + 113, 115, 108, 108, 223, 223, 397, 397, 397, 397, + 112, 112, 0, 323, 114, 0, 223, 223, 223, 223, + 113, 113, 0, 586, 125, 551, 125, 115, 125, 125, + 125, 125, 130, 0, 130, 323, 130, 130, 130, 130, + 131, 131, 131, 552, 131, 131, 131, 131, 132, 132, + + 132, 551, 132, 132, 132, 132, 135, 545, 135, 132, + 136, 323, 136, 137, 137, 138, 545, 138, 140, 552, + 140, 137, 556, 137, 223, 560, 136, 131, 561, 135, + 562, 564, 323, 598, 139, 132, 139, 141, 0, 141, + 143, 568, 143, 0, 130, 130, 138, 0, 556, 140, + 0, 560, 136, 141, 561, 135, 562, 564, 598, 139, + 142, 139, 142, 143, 144, 569, 144, 568, 135, 135, + 0, 138, 136, 136, 140, 142, 545, 138, 138, 141, + 140, 140, 0, 137, 137, 139, 145, 139, 145, 143, + 144, 569, 152, 142, 152, 0, 139, 139, 146, 141, + + 141, 142, 143, 143, 570, 146, 152, 146, 535, 535, + 147, 145, 147, 149, 0, 149, 144, 150, 142, 150, + 573, 146, 142, 142, 147, 0, 144, 144, 148, 148, + 570, 153, 152, 153, 535, 0, 148, 145, 148, 156, + 147, 156, 154, 150, 154, 149, 573, 146, 145, 145, + 147, 153, 0, 0, 152, 152, 155, 155, 0, 151, + 535, 151, 156, 0, 155, 147, 155, 146, 146, 150, + 149, 154, 147, 147, 151, 149, 149, 153, 535, 150, + 150, 576, 177, 151, 177, 163, 151, 163, 156, 163, + 163, 163, 163, 153, 153, 0, 154, 578, 148, 148, + + 151, 156, 156, 0, 154, 154, 0, 576, 182, 151, + 182, 174, 151, 174, 0, 174, 174, 174, 174, 0, + 579, 151, 151, 578, 0, 0, 155, 155, 175, 183, + 175, 183, 175, 175, 175, 175, 178, 0, 178, 0, + 178, 178, 178, 178, 177, 177, 579, 163, 163, 179, + 179, 179, 0, 179, 179, 179, 179, 180, 180, 180, + 0, 180, 180, 180, 180, 184, 0, 184, 180, 581, + 182, 182, 0, 185, 0, 185, 186, 0, 186, 187, + 0, 187, 420, 420, 420, 420, 179, 188, 186, 188, + 0, 183, 183, 185, 180, 581, 187, 0, 178, 178, + + 200, 0, 200, 188, 189, 0, 189, 188, 583, 191, + 0, 191, 567, 567, 186, 435, 435, 435, 435, 185, + 584, 191, 187, 493, 493, 493, 493, 184, 184, 188, + 587, 189, 589, 188, 583, 185, 185, 0, 186, 186, + 0, 187, 187, 190, 0, 190, 584, 191, 593, 188, + 188, 498, 498, 498, 498, 585, 587, 189, 589, 0, + 190, 0, 200, 200, 585, 597, 189, 189, 601, 0, + 190, 191, 191, 197, 593, 197, 602, 197, 197, 197, + 197, 0, 567, 198, 603, 198, 190, 198, 198, 198, + 198, 597, 0, 201, 601, 201, 190, 201, 201, 201, + + 201, 213, 602, 213, 0, 190, 190, 202, 202, 202, + 603, 202, 202, 202, 202, 203, 203, 203, 0, 203, + 203, 203, 203, 210, 585, 210, 203, 210, 210, 210, + 210, 211, 217, 211, 217, 211, 211, 211, 211, 0, + 0, 214, 230, 214, 202, 214, 214, 214, 214, 230, + 0, 230, 203, 0, 0, 201, 201, 0, 0, 217, + 219, 484, 219, 213, 213, 215, 215, 215, 515, 215, + 215, 215, 215, 216, 216, 216, 0, 216, 216, 216, + 216, 221, 221, 484, 216, 217, 218, 219, 218, 221, + 515, 221, 0, 0, 217, 217, 0, 222, 222, 225, + + 218, 225, 215, 214, 214, 222, 0, 222, 0, 484, + 216, 230, 230, 219, 0, 226, 515, 226, 225, 227, + 0, 227, 219, 219, 588, 588, 218, 224, 224, 224, + 484, 224, 224, 224, 224, 0, 0, 515, 224, 0, + 0, 228, 0, 228, 225, 226, 0, 0, 218, 218, + 590, 221, 221, 228, 231, 227, 231, 228, 229, 590, + 229, 225, 225, 232, 224, 232, 0, 222, 222, 0, + 226, 0, 229, 233, 231, 233, 0, 226, 226, 228, + 227, 227, 227, 228, 238, 0, 238, 234, 0, 234, + 236, 0, 236, 232, 588, 0, 0, 233, 229, 0, + + 231, 234, 0, 228, 228, 0, 239, 238, 239, 582, + 582, 582, 582, 0, 0, 236, 231, 231, 232, 590, + 229, 229, 0, 233, 0, 232, 232, 234, 0, 0, + 240, 240, 0, 238, 0, 233, 233, 239, 0, 0, + 0, 236, 240, 240, 240, 240, 238, 238, 604, 234, + 234, 0, 236, 236, 237, 237, 237, 604, 237, 237, + 237, 237, 239, 0, 242, 237, 242, 0, 239, 239, + 241, 241, 241, 542, 241, 241, 241, 241, 243, 0, + 243, 241, 244, 0, 244, 245, 0, 245, 246, 0, + 246, 237, 243, 0, 242, 542, 243, 245, 244, 247, + + 240, 247, 248, 0, 248, 0, 249, 241, 249, 0, + 0, 246, 599, 599, 599, 599, 0, 604, 243, 242, + 0, 542, 243, 245, 244, 0, 242, 242, 0, 248, + 605, 247, 249, 0, 252, 0, 252, 246, 249, 605, + 243, 243, 542, 0, 244, 244, 0, 245, 245, 0, + 246, 246, 257, 0, 257, 248, 247, 0, 249, 250, + 250, 247, 247, 249, 248, 248, 252, 257, 249, 249, + 0, 250, 250, 250, 250, 251, 251, 251, 0, 251, + 251, 251, 251, 256, 0, 256, 251, 258, 571, 258, + 259, 252, 259, 257, 0, 0, 252, 252, 0, 605, + + 260, 0, 260, 0, 262, 0, 262, 259, 256, 261, + 571, 261, 251, 0, 257, 257, 263, 0, 263, 0, + 0, 262, 264, 0, 264, 260, 0, 0, 265, 250, + 265, 0, 261, 259, 256, 0, 571, 266, 0, 266, + 0, 0, 264, 263, 0, 256, 256, 262, 0, 258, + 258, 260, 259, 259, 267, 0, 267, 571, 261, 0, + 266, 0, 260, 260, 265, 0, 262, 262, 264, 263, + 0, 261, 261, 0, 276, 0, 276, 267, 263, 263, + 268, 268, 0, 0, 264, 264, 266, 0, 0, 265, + 265, 265, 268, 268, 268, 268, 274, 0, 274, 266, + + 266, 0, 0, 267, 269, 269, 269, 0, 269, 269, + 269, 269, 270, 270, 277, 269, 267, 267, 275, 0, + 275, 277, 274, 277, 270, 270, 270, 270, 271, 271, + 271, 0, 271, 271, 271, 271, 276, 276, 279, 271, + 279, 269, 278, 278, 278, 283, 0, 283, 274, 275, + 268, 0, 0, 0, 285, 0, 285, 0, 274, 274, + 282, 283, 282, 0, 0, 271, 281, 281, 281, 279, + 281, 281, 281, 281, 275, 0, 0, 281, 284, 284, + 275, 275, 270, 277, 277, 285, 284, 283, 284, 282, + 288, 0, 288, 289, 279, 289, 0, 290, 0, 290, + + 279, 279, 0, 281, 278, 278, 0, 283, 283, 290, + 285, 295, 0, 295, 282, 0, 285, 285, 293, 293, + 0, 288, 282, 282, 0, 289, 293, 0, 293, 294, + 0, 294, 0, 0, 296, 290, 296, 0, 0, 297, + 295, 297, 298, 0, 298, 294, 288, 0, 284, 284, + 289, 296, 288, 288, 298, 289, 289, 0, 0, 290, + 290, 299, 0, 299, 309, 295, 309, 306, 297, 306, + 0, 294, 0, 295, 295, 0, 300, 296, 300, 0, + 298, 300, 300, 300, 301, 0, 301, 306, 293, 293, + 299, 294, 294, 297, 0, 309, 296, 296, 302, 302, + + 0, 297, 297, 0, 298, 298, 302, 0, 302, 305, + 0, 305, 307, 306, 307, 299, 301, 308, 0, 308, + 309, 0, 0, 299, 299, 305, 309, 309, 0, 306, + 306, 312, 307, 312, 313, 0, 313, 308, 300, 300, + 310, 301, 310, 314, 0, 314, 301, 301, 0, 0, + 0, 305, 310, 311, 0, 311, 0, 313, 307, 0, + 312, 0, 0, 308, 0, 0, 0, 0, 302, 302, + 0, 305, 305, 311, 307, 307, 0, 0, 310, 308, + 308, 0, 315, 313, 315, 312, 316, 0, 316, 321, + 0, 321, 0, 312, 312, 0, 313, 313, 316, 311, + + 0, 0, 310, 310, 0, 314, 314, 0, 322, 0, + 322, 0, 0, 0, 315, 311, 311, 326, 321, 326, + 322, 324, 324, 324, 316, 324, 324, 324, 324, 0, + 0, 0, 324, 325, 0, 325, 330, 0, 330, 315, + 0, 0, 0, 321, 315, 315, 322, 325, 316, 316, + 0, 321, 321, 331, 331, 0, 0, 325, 324, 0, + 0, 331, 330, 331, 0, 0, 0, 325, 0, 0, + 322, 322, 0, 325, 334, 0, 334, 0, 0, 326, + 326, 0, 0, 325, 0, 337, 0, 337, 330, 332, + 332, 338, 325, 338, 334, 325, 325, 0, 330, 330, + + 337, 332, 332, 332, 332, 333, 333, 333, 0, 333, + 333, 333, 333, 0, 338, 336, 333, 336, 339, 339, + 334, 0, 0, 331, 331, 0, 337, 342, 0, 342, + 339, 339, 339, 339, 0, 336, 334, 334, 0, 342, + 338, 341, 333, 341, 345, 0, 345, 337, 337, 0, + 344, 0, 344, 338, 338, 343, 341, 343, 345, 332, + 0, 336, 340, 340, 340, 342, 340, 340, 340, 340, + 0, 341, 344, 340, 346, 343, 346, 336, 336, 347, + 0, 347, 341, 348, 345, 348, 0, 0, 339, 342, + 342, 349, 0, 349, 346, 0, 341, 0, 344, 340, + + 0, 343, 0, 341, 341, 0, 345, 345, 350, 0, + 350, 0, 344, 344, 0, 351, 351, 343, 343, 0, + 346, 0, 0, 0, 0, 0, 350, 351, 351, 351, + 351, 0, 0, 354, 0, 354, 346, 346, 0, 353, + 353, 347, 347, 0, 0, 348, 348, 353, 0, 353, + 0, 0, 350, 349, 349, 352, 352, 352, 354, 352, + 352, 352, 352, 355, 0, 355, 352, 357, 0, 357, + 350, 350, 356, 0, 356, 0, 358, 353, 358, 0, + 359, 0, 359, 0, 354, 351, 0, 357, 355, 360, + 358, 360, 352, 0, 0, 354, 354, 0, 361, 0, + + 361, 364, 353, 364, 362, 360, 362, 356, 0, 353, + 353, 0, 0, 357, 355, 359, 358, 0, 361, 362, + 0, 0, 363, 0, 363, 355, 355, 0, 0, 357, + 357, 360, 356, 0, 356, 356, 363, 0, 358, 358, + 359, 0, 359, 359, 361, 362, 365, 0, 365, 0, + 0, 360, 360, 368, 0, 368, 374, 0, 374, 0, + 361, 361, 363, 364, 364, 0, 362, 362, 369, 0, + 369, 365, 370, 0, 370, 375, 375, 0, 0, 368, + 0, 374, 0, 0, 363, 363, 0, 375, 375, 375, + 375, 0, 0, 0, 369, 0, 379, 365, 379, 0, + + 386, 370, 386, 0, 383, 368, 383, 374, 365, 365, + 0, 0, 381, 0, 381, 368, 368, 0, 374, 374, + 369, 0, 379, 382, 0, 382, 370, 383, 0, 381, + 369, 369, 386, 0, 370, 370, 376, 376, 376, 382, + 376, 376, 376, 376, 388, 375, 388, 376, 379, 387, + 0, 387, 389, 383, 389, 381, 0, 386, 379, 379, + 0, 0, 386, 386, 0, 382, 383, 383, 388, 390, + 0, 390, 0, 376, 381, 381, 391, 389, 391, 387, + 0, 0, 0, 0, 0, 382, 382, 0, 392, 0, + 392, 396, 391, 396, 388, 0, 0, 0, 0, 390, + + 0, 0, 0, 389, 387, 0, 388, 388, 399, 399, + 396, 387, 387, 0, 389, 389, 0, 0, 391, 392, + 399, 399, 399, 399, 390, 400, 400, 402, 0, 402, + 0, 390, 390, 400, 0, 400, 396, 0, 391, 391, + 403, 0, 403, 0, 392, 402, 0, 404, 0, 404, + 392, 392, 0, 396, 396, 401, 401, 401, 403, 401, + 401, 401, 401, 405, 0, 405, 401, 404, 0, 0, + 410, 402, 410, 0, 406, 0, 406, 407, 399, 407, + 409, 0, 409, 408, 403, 408, 410, 0, 405, 402, + 402, 0, 401, 404, 406, 400, 400, 407, 0, 411, + + 0, 411, 403, 403, 412, 409, 412, 0, 0, 404, + 404, 0, 410, 408, 405, 411, 425, 0, 425, 422, + 406, 422, 0, 407, 0, 405, 405, 414, 0, 414, + 0, 409, 410, 410, 0, 412, 406, 406, 408, 407, + 407, 411, 409, 409, 422, 408, 408, 419, 0, 419, + 415, 414, 415, 416, 0, 416, 424, 0, 424, 0, + 412, 411, 411, 0, 0, 415, 412, 412, 0, 0, + 422, 419, 427, 416, 427, 0, 424, 414, 425, 425, + 0, 422, 422, 426, 0, 426, 428, 0, 428, 414, + 414, 415, 429, 429, 429, 426, 0, 419, 430, 416, + + 430, 427, 424, 431, 0, 431, 432, 0, 432, 419, + 419, 0, 415, 415, 430, 416, 416, 0, 424, 424, + 433, 426, 433, 434, 434, 439, 427, 439, 0, 437, + 437, 434, 0, 434, 427, 427, 0, 0, 0, 0, + 430, 437, 437, 437, 437, 426, 426, 0, 428, 428, + 440, 0, 440, 0, 429, 429, 433, 0, 0, 0, + 430, 430, 447, 0, 447, 431, 431, 0, 432, 432, + 441, 0, 441, 438, 438, 438, 0, 438, 438, 438, + 438, 433, 433, 433, 438, 0, 0, 439, 439, 0, + 442, 0, 442, 434, 434, 441, 0, 0, 443, 437, + + 443, 0, 0, 444, 0, 444, 0, 445, 442, 445, + 438, 0, 440, 440, 448, 0, 448, 0, 0, 0, + 446, 441, 446, 443, 447, 447, 0, 452, 444, 452, + 0, 0, 441, 441, 442, 449, 449, 445, 446, 0, + 451, 0, 451, 449, 0, 449, 0, 452, 453, 443, + 453, 0, 442, 442, 444, 456, 0, 456, 0, 0, + 443, 443, 445, 0, 446, 444, 444, 451, 0, 445, + 445, 456, 0, 452, 0, 0, 448, 448, 457, 453, + 0, 0, 446, 446, 0, 457, 457, 457, 0, 452, + 452, 0, 0, 451, 459, 0, 459, 456, 460, 0, + + 460, 0, 451, 451, 453, 449, 449, 461, 459, 461, + 453, 453, 462, 0, 462, 0, 0, 456, 456, 464, + 0, 464, 463, 461, 463, 465, 465, 0, 0, 460, + 467, 467, 462, 0, 459, 0, 0, 465, 465, 465, + 465, 0, 467, 467, 467, 467, 0, 457, 457, 461, + 0, 470, 463, 470, 460, 0, 459, 459, 462, 0, + 460, 460, 469, 0, 469, 471, 0, 471, 0, 461, + 461, 472, 0, 472, 462, 462, 473, 463, 473, 0, + 469, 464, 464, 471, 463, 463, 466, 466, 466, 472, + 466, 466, 466, 466, 474, 465, 474, 466, 0, 479, + + 467, 479, 0, 490, 0, 0, 469, 0, 0, 471, + 490, 0, 490, 470, 470, 472, 479, 475, 475, 0, + 478, 0, 478, 466, 469, 469, 0, 471, 471, 475, + 475, 475, 475, 472, 472, 483, 0, 483, 473, 473, + 478, 0, 479, 475, 480, 475, 480, 476, 476, 476, + 0, 476, 476, 476, 476, 0, 474, 474, 476, 0, + 483, 479, 479, 0, 0, 485, 478, 485, 492, 475, + 492, 475, 490, 490, 0, 480, 489, 0, 489, 488, + 0, 488, 478, 478, 476, 485, 483, 475, 486, 486, + 486, 488, 486, 486, 486, 486, 489, 483, 483, 486, + + 480, 0, 0, 491, 0, 491, 480, 480, 495, 0, + 495, 485, 496, 0, 496, 0, 0, 488, 491, 497, + 0, 497, 489, 0, 503, 486, 503, 485, 485, 0, + 492, 492, 504, 0, 504, 505, 0, 505, 489, 489, + 0, 488, 488, 511, 491, 511, 0, 503, 508, 0, + 508, 505, 504, 517, 0, 517, 0, 513, 511, 513, + 0, 0, 0, 0, 0, 491, 491, 523, 0, 523, + 495, 495, 0, 503, 496, 496, 0, 505, 504, 508, + 0, 497, 497, 514, 511, 514, 503, 503, 513, 0, + 0, 521, 523, 521, 504, 504, 0, 505, 505, 0, + + 0, 522, 0, 522, 508, 511, 511, 521, 0, 514, + 508, 508, 528, 513, 528, 517, 517, 522, 523, 513, + 513, 516, 516, 516, 0, 516, 516, 516, 516, 523, + 523, 526, 516, 521, 531, 514, 531, 0, 526, 0, + 526, 0, 530, 522, 530, 514, 514, 540, 0, 540, + 538, 0, 538, 521, 521, 0, 0, 0, 516, 531, + 0, 0, 530, 522, 522, 538, 539, 0, 539, 0, + 0, 549, 0, 549, 528, 528, 554, 0, 554, 0, + 548, 539, 548, 565, 555, 531, 555, 0, 530, 0, + 565, 538, 565, 0, 0, 0, 531, 531, 0, 0, + + 526, 526, 0, 0, 530, 530, 548, 539, 0, 540, + 540, 0, 538, 538, 543, 543, 543, 0, 543, 543, + 543, 543, 0, 0, 559, 543, 559, 0, 539, 539, + 0, 0, 548, 549, 549, 0, 0, 0, 554, 554, + 0, 0, 548, 548, 0, 0, 555, 555, 0, 559, + 0, 543, 565, 565, 572, 572, 572, 0, 572, 572, + 572, 572, 0, 0, 0, 572, 574, 574, 0, 0, + 595, 595, 0, 0, 0, 559, 0, 0, 574, 574, + 574, 574, 595, 595, 595, 595, 559, 559, 0, 0, + 0, 572, 0, 0, 0, 0, 0, 0, 0, 0, + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 574, 0, 0, 0, + 595, 609, 609, 609, 610, 610, 610, 611, 0, 611, + 612, 0, 612, 614, 0, 614, 615, 0, 615, 616, + 0, 616, 617, 0, 617, 618, 0, 618, 619, 0, + 619, 620, 0, 620, 622, 0, 622, 623, 0, 623, + 625, 0, 625, 626, 0, 626, 628, 0, 628, 629, + 0, 629, 630, 0, 630, 631, 0, 631, 608, 608, + + 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, + 608, 608, 608 + } ; static yy_state_type yy_last_accepting_state; static char *yy_last_accepting_cpos; @@ -1451,7 +1766,7 @@ char *yytext; #include #include #include -#ifdef HAVE_UNISTD_H +#ifdef HAVE_UNISTD_H #include #endif #include @@ -1463,72 +1778,73 @@ char *yytext; #include "ppparse.h" enum { - CB_COMPILE_STATUS_NONE, - CB_COMPILE_STATUS_TRUE, - CB_COMPILE_STATUS_FALSE, - CB_COMPILE_STATUS_FALSE_END, - CB_COMPILE_STATUS_TRUE_ELSE, - CB_COMPILE_STATUS_FALSE_ELSE, - CB_COMPILE_STATUS_ERROR + CB_COMPILE_STATUS_NONE, + CB_COMPILE_STATUS_TRUE, + CB_COMPILE_STATUS_FALSE, + CB_COMPILE_STATUS_FALSE_END, + CB_COMPILE_STATUS_TRUE_ELSE, + CB_COMPILE_STATUS_FALSE_ELSE, + CB_COMPILE_STATUS_ERROR }; -static char *plexbuff1 = NULL; -static char *plexbuff2 = NULL; -static size_t newline_count = 0; -static size_t within_comment = 0; -static size_t inside_bracket = 0; -static size_t consecutive_quotation = 0; -static int quotation_mark = 0; -static int last_line_1 = -1; -static int last_line_2 = -1; +static char *plexbuff1 = NULL; +static char *plexbuff2 = NULL; +static size_t newline_count = 0; +static size_t within_comment = 0; +static size_t inside_bracket = 0; +static size_t consecutive_quotation = 0; +static int quotation_mark = 0; +static int last_line_1 = -1; +static int last_line_2 = -1; /* for COBOL68 style COPY in data description entry */ -static int suppress_echo = 0; -static int current_division = PP_OUT_OF_DIVISION; -static int omit_data_entry_name = 0; -static int omit_data_redef_name = 0; +static int suppress_echo = 0; +static int current_division = PP_OUT_OF_DIVISION; +static int omit_data_entry_name = 0; +static int omit_data_redef_name = 0; #define MAX_DEPTH 10 -static int cb_compile_status = CB_COMPILE_STATUS_NONE; -static int cb_compile_status_list[MAX_DEPTH]; -static int compile_directive_depth = -1; +static int cb_compile_status = CB_COMPILE_STATUS_NONE; +static int cb_compile_status_list[MAX_DEPTH]; +static int compile_directive_depth = -1; + -static struct cb_replace_list *current_replace_list = NULL; +static struct cb_replace_list *current_replace_list = NULL; -static struct cb_replace_list *current_copy_replace_list = NULL; +static struct cb_replace_list *current_copy_replace_list = NULL; -static struct cb_joining_ext *current_joining_ext = NULL; +static struct cb_joining_ext *current_joining_ext = NULL; -static struct cb_text_list *text_queue1 = NULL; /* for COPY REPLACING */ -static struct cb_text_list *text_queue2 = NULL; /* for REPLACE */ +static struct cb_text_list *text_queue1 = NULL; /* for COPY REPLACING */ +static struct cb_text_list *text_queue2 = NULL; /* for REPLACE */ static struct copy_info { - struct copy_info *next; - char *file; - int line; - int replacing; - int joining; - int quotation_mark; - YY_BUFFER_STATE buffer; + struct copy_info *next; + char *file; + int line; + int replacing; + int joining; + int quotation_mark; + YY_BUFFER_STATE buffer; } *copy_stack = NULL; -#define YY_INPUT(buf, result, max_size) result = ppinput(buf, max_size); +#define YY_INPUT(buf, result, max_size) result = ppinput (buf, max_size); -static int ppinput(char *buf, int max_size); -static void ppecho(const char *text); +static int ppinput (char *buf, int max_size); +static void ppecho (const char *text); -#ifdef I18N_UTF8 -static void convert_ucs_hyphen_minus(char *namebuf); +#ifdef I18N_UTF8 +static void convert_ucs_hyphen_minus (char *namebuf); #endif /*I18N_UTF8*/ -static void ppecho_dataname(char *datanamebuf); +static void ppecho_dataname (char *datanamebuf); -static void switch_to_buffer(const int lineno, const char *filename, - YY_BUFFER_STATE buffer); +static void switch_to_buffer (const int lineno, const char *filename, + YY_BUFFER_STATE buffer); -#line 1846 "pplex.c" +#line 1845 "pplex.c" -#line 1848 "pplex.c" +#line 1847 "pplex.c" #define INITIAL 0 #define PROCESS_STATE 1 @@ -1540,36 +1856,36 @@ static void switch_to_buffer(const int lineno, const char *filename, #define YY_EXTRA_TYPE void * #endif -static int yy_init_globals(void); +static int yy_init_globals ( void ); /* Accessor methods to globals. These are made visible to non-reentrant scanners for convenience. */ -int yylex_destroy(void); +int yylex_destroy ( void ); -int yyget_debug(void); +int yyget_debug ( void ); -void yyset_debug(int debug_flag); +void yyset_debug ( int debug_flag ); -YY_EXTRA_TYPE yyget_extra(void); +YY_EXTRA_TYPE yyget_extra ( void ); -void yyset_extra(YY_EXTRA_TYPE user_defined); +void yyset_extra ( YY_EXTRA_TYPE user_defined ); -FILE *yyget_in(void); +FILE *yyget_in ( void ); -void yyset_in(FILE *_in_str); +void yyset_in ( FILE * _in_str ); -FILE *yyget_out(void); +FILE *yyget_out ( void ); -void yyset_out(FILE *_out_str); +void yyset_out ( FILE * _out_str ); -int yyget_leng(void); + int yyget_leng ( void ); -char *yyget_text(void); +char *yyget_text ( void ); -int yyget_lineno(void); +int yyget_lineno ( void ); -void yyset_lineno(int _line_number); +void yyset_lineno ( int _line_number ); /* Macros after this point can all be overridden by user definitions in * section 1. @@ -1577,31 +1893,31 @@ void yyset_lineno(int _line_number); #ifndef YY_SKIP_YYWRAP #ifdef __cplusplus -extern "C" int yywrap(void); +extern "C" int yywrap ( void ); #else -extern int yywrap(void); +extern int yywrap ( void ); #endif #endif #ifndef YY_NO_UNPUT - -static void yyunput(int c, char *buf_ptr); - + + static void yyunput ( int c, char *buf_ptr ); + #endif #ifndef yytext_ptr -static void yy_flex_strncpy(char *, const char *, int); +static void yy_flex_strncpy ( char *, const char *, int ); #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen(const char *); +static int yy_flex_strlen ( const char * ); #endif #ifndef YY_NO_INPUT #ifdef __cplusplus -static int yyinput(void); +static int yyinput ( void ); #else -static int input(void); +static int input ( void ); #endif #endif @@ -1621,40 +1937,42 @@ static int input(void); /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO \ - do { \ - if (fwrite(yytext, (size_t)yyleng, 1, yyout)) { \ - } \ - } while (0) +#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, * is returned in "result". */ #ifndef YY_INPUT -#define YY_INPUT(buf, result, max_size) \ - if (YY_CURRENT_BUFFER_LVALUE->yy_is_interactive) { \ - int c = '*'; \ - int n; \ - for (n = 0; n < max_size && (c = getc(yyin)) != EOF && c != '\n'; ++n) \ - buf[n] = (char)c; \ - if (c == '\n') \ - buf[n++] = (char)c; \ - if (c == EOF && ferror(yyin)) \ - YY_FATAL_ERROR("input in flex scanner failed"); \ - result = n; \ - } else { \ - errno = 0; \ - while ((result = (int)fread(buf, 1, (yy_size_t)max_size, yyin)) == 0 && \ - ferror(yyin)) { \ - if (errno != EINTR) { \ - YY_FATAL_ERROR("input in flex scanner failed"); \ - break; \ - } \ - errno = 0; \ - clearerr(yyin); \ - } \ - } +#define YY_INPUT(buf,result,max_size) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + int n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \ + { \ + if( errno != EINTR) \ + { \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + break; \ + } \ + errno=0; \ + clearerr(yyin); \ + } \ + }\ +\ #endif @@ -1673,7 +1991,7 @@ static int input(void); /* Report a fatal error. */ #ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error(msg) +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) #endif /* end tables serialization structures and prototypes */ @@ -1684,9 +2002,9 @@ static int input(void); #ifndef YY_DECL #define YY_DECL_IS_OURS 1 -extern int yylex(void); +extern int yylex (void); -#define YY_DECL int yylex(void) +#define YY_DECL int yylex (void) #endif /* !YY_DECL */ /* Code executed at the beginning of each rule, after yytext and yyleng @@ -1698,942 +2016,839 @@ extern int yylex(void); /* Code executed at the end of each rule. */ #ifndef YY_BREAK -#define YY_BREAK /*LINTED*/ break; +#define YY_BREAK /*LINTED*/break; #endif -#define YY_RULE_SETUP \ - if (yyleng > 0) \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (yytext[yyleng - 1] == '\n'); \ - YY_USER_ACTION +#define YY_RULE_SETUP \ + if ( yyleng > 0 ) \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \ + (yytext[yyleng - 1] == '\n'); \ + YY_USER_ACTION /** The main scanner function which does all the work. */ -YY_DECL { - yy_state_type yy_current_state; - char *yy_cp, *yy_bp; - int yy_act; - - if (!(yy_init)) { - (yy_init) = 1; +YY_DECL +{ + yy_state_type yy_current_state; + char *yy_cp, *yy_bp; + int yy_act; + + if ( !(yy_init) ) + { + (yy_init) = 1; #ifdef YY_USER_INIT - YY_USER_INIT; + YY_USER_INIT; #endif - if (!(yy_start)) - (yy_start) = 1; /* first start state */ + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ - if (!yyin) - yyin = stdin; + if ( ! yyin ) + yyin = stdin; - if (!yyout) - yyout = stdout; + if ( ! yyout ) + yyout = stdout; - if (!YY_CURRENT_BUFFER) { - yyensure_buffer_stack(); - YY_CURRENT_BUFFER_LVALUE = yy_create_buffer(yyin, YY_BUF_SIZE); - } + if ( ! YY_CURRENT_BUFFER ) { + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer( yyin, YY_BUF_SIZE ); + } - yy_load_buffer_state(); - } + yy_load_buffer_state( ); + } - { + { #line 126 "pplex.l" -#line 2070 "pplex.c" - - while (/*CONSTCOND*/ 1) /* loops until end-of-file is reached */ - { - yy_cp = (yy_c_buf_p); - - /* Support of yytext. */ - *yy_cp = (yy_hold_char); - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = (yy_start); - yy_current_state += YY_AT_BOL(); - yy_match: - do { - YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; - if (yy_accept[yy_current_state]) { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) { - yy_current_state = (int)yy_def[yy_current_state]; - if (yy_current_state >= 609) - yy_c = yy_meta[yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - ++yy_cp; - } while (yy_current_state != 608); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - - yy_find_action: - yy_act = yy_accept[yy_current_state]; - - YY_DO_BEFORE_ACTION; - - do_action: /* This label is used only to access EOF actions. */ - - switch (yy_act) { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = (yy_hold_char); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; - - case 1: - YY_RULE_SETUP + + + + +#line 2069 "pplex.c" + + while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ + { + yy_cp = (yy_c_buf_p); + + /* Support of yytext. */ + *yy_cp = (yy_hold_char); + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = (yy_start); + yy_current_state += YY_AT_BOL(); +yy_match: + do + { + YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 609 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + ++yy_cp; + } + while ( yy_current_state != 608 ); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + + YY_DO_BEFORE_ACTION; + +do_action: /* This label is used only to access EOF actions. */ + + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + +case 1: +YY_RULE_SETUP #line 131 "pplex.l" - { - ppecho(" "); - } - YY_BREAK - case 2: - YY_RULE_SETUP +{ + ppecho (" "); +} + YY_BREAK +case 2: +YY_RULE_SETUP #line 135 "pplex.l" - { - identification_division_line_number = cb_source_line; - ppecho("IDENTIFICATION DIVISION."); - } - YY_BREAK - case 3: - YY_RULE_SETUP +{ + identification_division_line_number = cb_source_line; + ppecho ("IDENTIFICATION DIVISION."); +} + YY_BREAK +case 3: +YY_RULE_SETUP #line 139 "pplex.l" - { - ppecho("ID DIVISION."); - } - YY_BREAK - case 4: - YY_RULE_SETUP +{ ppecho ("ID DIVISION."); } + YY_BREAK +case 4: +YY_RULE_SETUP #line 140 "pplex.l" - { - ppecho("FUNCTION DIVISION."); - } - YY_BREAK - case 5: - YY_RULE_SETUP +{ ppecho ("FUNCTION DIVISION."); } + YY_BREAK +case 5: +YY_RULE_SETUP #line 141 "pplex.l" - { - ppecho(yytext); - return PROGRAM_ID; - } - YY_BREAK - case 6: - YY_RULE_SETUP +{ ppecho (yytext); return PROGRAM_ID; } + YY_BREAK +case 6: +YY_RULE_SETUP #line 142 "pplex.l" - { - ppecho(yytext); - return FUNCTION_ID; - } - YY_BREAK - case 7: - YY_RULE_SETUP +{ ppecho (yytext); return FUNCTION_ID; } + YY_BREAK +case 7: +YY_RULE_SETUP #line 143 "pplex.l" - { - ppecho("ENVIRONMENT DIVISION"); - return ENVIRONMENT_DIVISION; - } - YY_BREAK - case 8: - YY_RULE_SETUP +{ ppecho ("ENVIRONMENT DIVISION"); return ENVIRONMENT_DIVISION; } + YY_BREAK +case 8: +YY_RULE_SETUP #line 144 "pplex.l" - { - position_in_source_code = POSITION_AFTER_WORKING_STORAGE; - ppecho("DATA DIVISION"); - return DATA_DIVISION; - } - YY_BREAK - case 9: - YY_RULE_SETUP +{ + position_in_source_code = POSITION_AFTER_WORKING_STORAGE; + ppecho ("DATA DIVISION"); + return DATA_DIVISION; +} + YY_BREAK +case 9: +YY_RULE_SETUP #line 149 "pplex.l" - { - if (copy_stack->next == NULL) { - procedure_division_line_number = cb_source_line; - position_in_source_code = POSITION_AFTER_PROCEDURE_DIVISION; - } - ppecho("PROCEDURE DIVISION"); - return PROCEDURE_DIVISION; - } - YY_BREAK - case 10: - YY_RULE_SETUP +{ + if(copy_stack->next == NULL) { + procedure_division_line_number = cb_source_line; + position_in_source_code = POSITION_AFTER_PROCEDURE_DIVISION; + } + ppecho ("PROCEDURE DIVISION"); + return PROCEDURE_DIVISION; +} + YY_BREAK +case 10: +YY_RULE_SETUP #line 157 "pplex.l" - { - ppecho("END PROGRAM"); - return END_PROGRAM; - } - YY_BREAK - case 11: - YY_RULE_SETUP +{ ppecho ("END PROGRAM"); return END_PROGRAM; } + YY_BREAK +case 11: +YY_RULE_SETUP #line 158 "pplex.l" - { - ppecho("END FUNCTION"); - return END_FUNCTION; - } - YY_BREAK - case 12: +{ ppecho ("END FUNCTION"); return END_FUNCTION; } + YY_BREAK +case 12: #line 161 "pplex.l" - case 13: - YY_RULE_SETUP +case 13: +YY_RULE_SETUP #line 161 "pplex.l" - { - ppecho(" "); - if (cb_source_format != CB_FORMAT_FIXED) { - ppecho(yytext); - } - } - YY_BREAK - case 14: - YY_RULE_SETUP +{ + ppecho (" "); + if (cb_source_format != CB_FORMAT_FIXED) { + ppecho (yytext); + } +} + YY_BREAK +case 14: +YY_RULE_SETUP #line 168 "pplex.l" - { - BEGIN PROCESS_STATE; - } - YY_BREAK - - case 15: - /* rule 15 can match eol */ - YY_RULE_SETUP +{ BEGIN PROCESS_STATE; } + YY_BREAK + +case 15: +/* rule 15 can match eol */ +YY_RULE_SETUP #line 171 "pplex.l" - { - BEGIN INITIAL; - unput('\n'); - } - YY_BREAK - case 16: - YY_RULE_SETUP +{ BEGIN INITIAL; unput ('\n'); } + YY_BREAK +case 16: +YY_RULE_SETUP #line 172 "pplex.l" - { - cb_warning(_("PROCESS statement is ignored")); - } - YY_BREAK +{ cb_warning (_("PROCESS statement is ignored")); } + YY_BREAK - case 17: - YY_RULE_SETUP +case 17: +YY_RULE_SETUP #line 175 "pplex.l" - { - BEGIN COPY_STATE; - return COPY; - } - YY_BREAK - case 18: - YY_RULE_SETUP +{ BEGIN COPY_STATE; return COPY; } + YY_BREAK +case 18: +YY_RULE_SETUP #line 176 "pplex.l" - { - BEGIN COPY_STATE; - return COPY; - } - YY_BREAK - case 19: - YY_RULE_SETUP +{ BEGIN COPY_STATE; return COPY; } + YY_BREAK +case 19: +YY_RULE_SETUP #line 177 "pplex.l" - { - BEGIN COPY_STATE; - return REPLACE; - } - YY_BREAK - - case 20: - /* rule 20 can match eol */ - YY_RULE_SETUP +{ BEGIN COPY_STATE; return REPLACE; } + YY_BREAK + +case 20: +/* rule 20 can match eol */ +YY_RULE_SETUP #line 180 "pplex.l" - { - ECHO; - cb_source_line++; - } - YY_BREAK - case 21: - YY_RULE_SETUP +{ ECHO; cb_source_line++; } + YY_BREAK +case 21: +YY_RULE_SETUP #line 181 "pplex.l" - { /* ignore */ - } - YY_BREAK - case 22: - YY_RULE_SETUP +{ /* ignore */ } + YY_BREAK +case 22: +YY_RULE_SETUP #line 182 "pplex.l" - { - BEGIN INITIAL; - return '.'; - } - YY_BREAK - case 23: - YY_RULE_SETUP +{ BEGIN INITIAL; return '.'; } + YY_BREAK +case 23: +YY_RULE_SETUP #line 183 "pplex.l" - { - BEGIN PSEUDO_STATE; - return EQEQ; - } - YY_BREAK - case 24: - YY_RULE_SETUP +{ BEGIN PSEUDO_STATE; return EQEQ; } + YY_BREAK +case 24: +YY_RULE_SETUP #line 184 "pplex.l" - { - return '('; - } - YY_BREAK - case 25: - YY_RULE_SETUP +{ return '('; } + YY_BREAK +case 25: +YY_RULE_SETUP #line 185 "pplex.l" - { - return ')'; - } - YY_BREAK - case 26: - YY_RULE_SETUP +{ return ')'; } + YY_BREAK +case 26: +YY_RULE_SETUP #line 186 "pplex.l" - { - return BY; - } - YY_BREAK - case 27: - YY_RULE_SETUP +{ return BY; } + YY_BREAK +case 27: +YY_RULE_SETUP #line 187 "pplex.l" - { - return IN; - } - YY_BREAK - case 28: - YY_RULE_SETUP +{ return IN; } + YY_BREAK +case 28: +YY_RULE_SETUP #line 188 "pplex.l" - { - return OF; - } - YY_BREAK - case 29: - YY_RULE_SETUP +{ return OF; } + YY_BREAK +case 29: +YY_RULE_SETUP #line 189 "pplex.l" - { - return OFF; - } - YY_BREAK - case 30: - YY_RULE_SETUP +{ return OFF; } + YY_BREAK +case 30: +YY_RULE_SETUP #line 190 "pplex.l" - { - return SUPPRESS; - } - YY_BREAK - case 31: - YY_RULE_SETUP +{ return SUPPRESS; } + YY_BREAK +case 31: +YY_RULE_SETUP #line 191 "pplex.l" - { - return PRINTING; - } - YY_BREAK - case 32: - YY_RULE_SETUP +{ return PRINTING; } + YY_BREAK +case 32: +YY_RULE_SETUP #line 192 "pplex.l" - { - return REPLACING; - } - YY_BREAK - case 33: - YY_RULE_SETUP +{ return REPLACING; } + YY_BREAK +case 33: +YY_RULE_SETUP #line 193 "pplex.l" - { - return LEADING; - } - YY_BREAK - case 34: - YY_RULE_SETUP +{ return LEADING; } + YY_BREAK +case 34: +YY_RULE_SETUP #line 194 "pplex.l" - { - return TRAILING; - } - YY_BREAK - case 35: - YY_RULE_SETUP +{ return TRAILING; } + YY_BREAK +case 35: +YY_RULE_SETUP #line 195 "pplex.l" - { - return JOINING; - } - YY_BREAK - case 36: - YY_RULE_SETUP +{ return JOINING; } + YY_BREAK +case 36: +YY_RULE_SETUP #line 196 "pplex.l" - { - return AS; - } - YY_BREAK - case 37: - YY_RULE_SETUP +{ return AS; } + YY_BREAK +case 37: +YY_RULE_SETUP #line 197 "pplex.l" - { - return PREFIX; - } - YY_BREAK - case 38: - YY_RULE_SETUP +{ return PREFIX; } + YY_BREAK +case 38: +YY_RULE_SETUP #line 198 "pplex.l" - { - return SUFFIX; - } - YY_BREAK - case 39: - YY_RULE_SETUP +{ return SUFFIX; } + YY_BREAK +case 39: +YY_RULE_SETUP #line 199 "pplex.l" - { - return PREFIXING; - } - YY_BREAK - case 40: - YY_RULE_SETUP +{ return PREFIXING; } + YY_BREAK +case 40: +YY_RULE_SETUP #line 200 "pplex.l" - { - return SUFFIXING; - } - YY_BREAK - case 41: - YY_RULE_SETUP +{ return SUFFIXING; } + YY_BREAK +case 41: +YY_RULE_SETUP #line 201 "pplex.l" - { -#ifdef I18N_UTF8 - convert_ucs_hyphen_minus(yytext); +{ +#ifdef I18N_UTF8 + convert_ucs_hyphen_minus (yytext); #endif /*I18N_UTF8*/ - pplval.s = strdup(yytext); - return TOKEN; - } - YY_BREAK - case 42: + pplval.s = strdup (yytext); return TOKEN; } + YY_BREAK +case 42: #line 207 "pplex.l" - case 43: +case 43: #line 208 "pplex.l" - case 44: - YY_RULE_SETUP +case 44: +YY_RULE_SETUP #line 208 "pplex.l" - { - pplval.s = strdup(yytext); - return TOKEN; - } - YY_BREAK - - case 45: - /* rule 45 can match eol */ - YY_RULE_SETUP +{ pplval.s = strdup (yytext); return TOKEN; } + YY_BREAK + + +case 45: +/* rule 45 can match eol */ +YY_RULE_SETUP #line 212 "pplex.l" - { - ECHO; - cb_source_line++; - } - YY_BREAK - case 46: - YY_RULE_SETUP +{ ECHO; cb_source_line++; } + YY_BREAK +case 46: +YY_RULE_SETUP #line 213 "pplex.l" - { - pplval.s = strdup(" "); - return TOKEN; - } - YY_BREAK - case 47: - YY_RULE_SETUP +{ pplval.s = strdup (" "); return TOKEN; } + YY_BREAK +case 47: +YY_RULE_SETUP #line 214 "pplex.l" - { - BEGIN COPY_STATE; - return EQEQ; - } - YY_BREAK - case 48: - YY_RULE_SETUP +{ BEGIN COPY_STATE; return EQEQ; } + YY_BREAK +case 48: +YY_RULE_SETUP #line 215 "pplex.l" - { -#ifdef I18N_UTF8 - convert_ucs_hyphen_minus(yytext); +{ +#ifdef I18N_UTF8 + convert_ucs_hyphen_minus (yytext); #endif /*I18N_UTF8*/ - pplval.s = strdup(yytext); - return TOKEN; - } - YY_BREAK - case 49: + pplval.s = strdup (yytext); return TOKEN; } + YY_BREAK +case 49: #line 221 "pplex.l" - case 50: +case 50: #line 222 "pplex.l" - case 51: - YY_RULE_SETUP +case 51: +YY_RULE_SETUP #line 222 "pplex.l" - { - pplval.s = strdup(yytext); - return TOKEN; - } - YY_BREAK - - case 52: - YY_RULE_SETUP +{ pplval.s = strdup (yytext); return TOKEN; } + YY_BREAK + + +case 52: +YY_RULE_SETUP #line 226 "pplex.l" - { - suppress_echo = 0; - BEGIN COPY_STATE; - return COPY; - } - YY_BREAK - case 53: - YY_RULE_SETUP +{ suppress_echo = 0; BEGIN COPY_STATE; return COPY; } + YY_BREAK +case 53: +YY_RULE_SETUP #line 227 "pplex.l" - { - suppress_echo = 0; - BEGIN COPY_STATE; - return COPY; - } - YY_BREAK - case 54: - YY_RULE_SETUP +{ suppress_echo = 0; BEGIN COPY_STATE; return COPY; } + YY_BREAK +case 54: +YY_RULE_SETUP #line 228 "pplex.l" - { - suppress_echo = 0; - BEGIN COPY_STATE; - return REPLACE; - } - YY_BREAK - case 55: - /* rule 55 can match eol */ - YY_RULE_SETUP +{ suppress_echo = 0; BEGIN COPY_STATE; return REPLACE; } + YY_BREAK +case 55: +/* rule 55 can match eol */ +YY_RULE_SETUP #line 229 "pplex.l" - { - ECHO; - cb_source_line++; - } - YY_BREAK - case 56: - YY_RULE_SETUP +{ ECHO; cb_source_line++; } + YY_BREAK +case 56: +YY_RULE_SETUP #line 230 "pplex.l" - { - ppecho(" "); - } - YY_BREAK - case 57: - YY_RULE_SETUP +{ ppecho (" "); } + YY_BREAK +case 57: +YY_RULE_SETUP #line 231 "pplex.l" - { - BEGIN INITIAL; - if (!strcasecmp(yytext, "FILLER")) { - ppecho(yytext); - } else { - ppecho_dataname(yytext); - } - suppress_echo = 0; - if (cb_cobol68_copy_in_data_description) { - pplval.s = strdup(yytext); - return TOKEN; - } - } - YY_BREAK - case 58: +{ + BEGIN INITIAL; + if (!strcasecmp (yytext, "FILLER")) { + ppecho (yytext); + } else { + ppecho_dataname (yytext); + } + suppress_echo = 0; + if (cb_cobol68_copy_in_data_description) { + pplval.s = strdup (yytext); + return TOKEN; + } + } + YY_BREAK +case 58: #line 245 "pplex.l" - case 59: +case 59: #line 246 "pplex.l" - case 60: - YY_RULE_SETUP +case 60: +YY_RULE_SETUP #line 246 "pplex.l" - { - suppress_echo = 0; - BEGIN INITIAL; - ppecho(yytext); - } - YY_BREAK - - case 61: - YY_RULE_SETUP +{ suppress_echo = 0; BEGIN INITIAL; ppecho (yytext); } + YY_BREAK + +case 61: +YY_RULE_SETUP #line 249 "pplex.l" - { - suppress_echo = (omit_data_redef_name) ? 1 : 0; - ppecho(yytext); - BEGIN DATANAME_JOIN_STATE; - if (cb_cobol68_copy_in_data_description) { - return REDEFINES; - } - } - YY_BREAK - case 62: +{ + suppress_echo = (omit_data_redef_name) ? 1 : 0; + ppecho (yytext); + BEGIN DATANAME_JOIN_STATE; + if (cb_cobol68_copy_in_data_description) { + return REDEFINES; + } +} + YY_BREAK +case 62: #line 259 "pplex.l" - case 63: +case 63: #line 260 "pplex.l" - case 64: +case 64: #line 261 "pplex.l" - case 65: +case 65: #line 262 "pplex.l" - case 66: +case 66: #line 263 "pplex.l" - case 67: +case 67: #line 264 "pplex.l" - case 68: - YY_RULE_SETUP +case 68: +YY_RULE_SETUP #line 264 "pplex.l" - { - /* these words are treated as comments */ - if (cb_verify(cb_author_paragraph, yytext)) { - /* skip comments until the end of line */ - int c; - - within_comment = 1; - while ((c = input()) != EOF) { - if (c == '\n') { - break; - } - } - unput(c); - } - } - YY_BREAK - case 69: +{ + /* these words are treated as comments */ + if (cb_verify (cb_author_paragraph, yytext)) { + /* skip comments until the end of line */ + int c; + + within_comment = 1; + while ((c = input ()) != EOF) { + if (c == '\n') { + break; + } + } + unput (c); + } +} + YY_BREAK +case 69: #line 281 "pplex.l" - case 70: +case 70: #line 282 "pplex.l" - case 71: +case 71: #line 283 "pplex.l" - case 72: - YY_RULE_SETUP +case 72: +YY_RULE_SETUP #line 283 "pplex.l" - { - /* these words are comments in IBM COBOL */ - if (cb_verify(cb_eject_statement, yytext)) { - /* do nothing for now */ - } else { - /* ECHO; */ /* comment should be suppressed, shouldn't it? */ - } - } - YY_BREAK - case 73: - /* rule 73 can match eol */ - YY_RULE_SETUP +{ + /* these words are comments in IBM COBOL */ + if (cb_verify (cb_eject_statement, yytext)) { + /* do nothing for now */ + } else { + /* ECHO; */ /* comment should be suppressed, shouldn't it? */ + } +} + YY_BREAK +case 73: +/* rule 73 can match eol */ +YY_RULE_SETUP #line 292 "pplex.l" - { - ppecho("\n"); - cb_source_line++; - } - YY_BREAK - case 74: - YY_RULE_SETUP +{ ppecho ("\n"); cb_source_line++; } + YY_BREAK +case 74: +YY_RULE_SETUP #line 294 "pplex.l" - { - ppecho(" "); - } - YY_BREAK - case 75: - YY_RULE_SETUP +{ ppecho (" "); } + YY_BREAK +case 75: +YY_RULE_SETUP #line 296 "pplex.l" - { - if (inside_bracket) { - ppecho(", "); - } else { - ppecho(" "); - } - } - YY_BREAK - case 76: - YY_RULE_SETUP +{ + if (inside_bracket) { + ppecho (", "); + } else { + ppecho (" "); + } +} + YY_BREAK +case 76: +YY_RULE_SETUP #line 304 "pplex.l" - { - inside_bracket++; - ppecho("("); - } - YY_BREAK - case 77: - YY_RULE_SETUP +{ + inside_bracket++; + ppecho ("("); +} + YY_BREAK +case 77: +YY_RULE_SETUP #line 309 "pplex.l" - { - if (inside_bracket) { - inside_bracket--; - } - ppecho(")"); - } - YY_BREAK - case 78: +{ + if (inside_bracket) { + inside_bracket--; + } + ppecho (")"); +} + YY_BREAK +case 78: /* rule 78 can match eol */ #line 317 "pplex.l" - case 79: +case 79: /* rule 79 can match eol */ #line 318 "pplex.l" - case 80: +case 80: /* rule 80 can match eol */ #line 319 "pplex.l" - case 81: +case 81: /* rule 81 can match eol */ #line 320 "pplex.l" - case 82: +case 82: /* rule 82 can match eol */ #line 321 "pplex.l" - case 83: +case 83: /* rule 83 can match eol */ #line 322 "pplex.l" - case 84: +case 84: /* rule 84 can match eol */ #line 323 "pplex.l" - case 85: +case 85: /* rule 85 can match eol */ #line 324 "pplex.l" - case 86: +case 86: /* rule 86 can match eol */ #line 325 "pplex.l" - case 87: +case 87: /* rule 87 can match eol */ #line 326 "pplex.l" - case 88: +case 88: /* rule 88 can match eol */ #line 327 "pplex.l" - case 89: +case 89: /* rule 89 can match eol */ #line 328 "pplex.l" - case 90: +case 90: /* rule 90 can match eol */ #line 329 "pplex.l" - case 91: +case 91: /* rule 91 can match eol */ #line 330 "pplex.l" - case 92: - /* rule 92 can match eol */ - YY_RULE_SETUP +case 92: +/* rule 92 can match eol */ +YY_RULE_SETUP #line 330 "pplex.l" - { - /* each numeric is not a level-number */ - char *p, *pcrnt; - cobc_mbspc2ascii(yytext); - pcrnt = yytext; - while (*pcrnt) { - for (p = pcrnt; *p && *p != ' ' && *p != '\n'; p++) - ; - for (; *p == ' ' || *p == '\n'; p++) { - if (*p == '\n') { - cb_source_line++; - } - *p = '\0'; - } - ppecho(pcrnt); - if (*p) { - ppecho(" "); - } - pcrnt = p; - } - } - YY_BREAK - case 93: - YY_RULE_SETUP +{ + /* each numeric is not a level-number */ + char *p, *pcrnt; + cobc_mbspc2ascii (yytext); + pcrnt = yytext; + while (*pcrnt) { + for (p = pcrnt; *p && *p != ' ' && *p != '\n' ; p++) + ; + for ( ; *p == ' ' || *p == '\n'; p++) { + if (*p == '\n') { + cb_source_line++; + } + *p = '\0'; + } + ppecho (pcrnt); + if (*p) { + ppecho (" "); + } + pcrnt = p; + } +} + YY_BREAK +case 93: +YY_RULE_SETUP #line 352 "pplex.l" - { - char *p = yytext; - cobc_mbspc2ascii(yytext); - while (*p == ' ') { - p++; - } - suppress_echo = (omit_data_entry_name) ? 1 : 0; - ppecho(p); - if (current_division == PP_DATA_DIVISION) { - BEGIN DATANAME_JOIN_STATE; - if (cb_cobol68_copy_in_data_description) { - return LEVEL_NUMBER; - } - } - } - YY_BREAK - case 94: - YY_RULE_SETUP +{ + char *p = yytext; + cobc_mbspc2ascii (yytext); + while (*p == ' ') { + p++; + } + suppress_echo = (omit_data_entry_name) ? 1 : 0; + ppecho (p); + if (current_division == PP_DATA_DIVISION) { + BEGIN DATANAME_JOIN_STATE; + if (cb_cobol68_copy_in_data_description) { + return LEVEL_NUMBER; + } + } +} + YY_BREAK +case 94: +YY_RULE_SETUP #line 368 "pplex.l" - { - ppecho(yytext); - return yytext[0]; - } - YY_BREAK - case 95: - YY_RULE_SETUP +{ + ppecho (yytext); + return yytext[0]; +} + YY_BREAK +case 95: +YY_RULE_SETUP #line 373 "pplex.l" - { -#ifdef I18N_UTF8 - convert_ucs_hyphen_minus(yytext); +{ +#ifdef I18N_UTF8 + convert_ucs_hyphen_minus (yytext); #endif /*I18N_UTF8*/ - ppecho(yytext); - } - YY_BREAK - case 96: + ppecho (yytext); } + YY_BREAK +case 96: #line 379 "pplex.l" - case 97: +case 97: #line 380 "pplex.l" - case 98: - YY_RULE_SETUP +case 98: +YY_RULE_SETUP #line 380 "pplex.l" - { - ppecho(yytext); - } - YY_BREAK - case YY_STATE_EOF(INITIAL): - case YY_STATE_EOF(PROCESS_STATE): - case YY_STATE_EOF(COPY_STATE): - case YY_STATE_EOF(PSEUDO_STATE): - case YY_STATE_EOF(DATANAME_JOIN_STATE): +{ ppecho (yytext); } + YY_BREAK +case YY_STATE_EOF(INITIAL): +case YY_STATE_EOF(PROCESS_STATE): +case YY_STATE_EOF(COPY_STATE): +case YY_STATE_EOF(PSEUDO_STATE): +case YY_STATE_EOF(DATANAME_JOIN_STATE): #line 382 "pplex.l" - { - struct copy_info *p; - - p = copy_stack; - - yy_delete_buffer(YY_CURRENT_BUFFER); - - /* Terminate at the end of all input */ - if (p->next == NULL) { - within_comment = 0; - newline_count = 0; - inside_bracket = 0; - current_replace_list = NULL; - current_copy_replace_list = NULL; - current_joining_ext = NULL; - text_queue1 = text_queue2 = NULL; - copy_stack = NULL; - quotation_mark = 0; - consecutive_quotation = 0; - last_line_1 = -1; - last_line_2 = -1; - yyterminate(); - } - - /* Close the current file */ - fclose(ppin); - - /* Switch to the last buffer */ - if (p->replacing) { - pp_set_copy_replace_list(NULL); - } - if (p->joining) { - pp_set_joining_ext(NULL); - } - switch_to_buffer(p->line, p->file, p->buffer); - quotation_mark = p->quotation_mark; - - copy_stack = p->next; - free(p); - } - YY_BREAK - case 99: - YY_RULE_SETUP +{ + struct copy_info *p; + + p = copy_stack; + + yy_delete_buffer (YY_CURRENT_BUFFER); + + /* Terminate at the end of all input */ + if (p->next == NULL) { + within_comment = 0; + newline_count = 0; + inside_bracket = 0; + current_replace_list = NULL; + current_copy_replace_list = NULL; + current_joining_ext = NULL; + text_queue1 = text_queue2 = NULL; + copy_stack = NULL; + quotation_mark = 0; + consecutive_quotation = 0; + last_line_1 = -1; + last_line_2 = -1; + yyterminate (); + } + + /* Close the current file */ + fclose (ppin); + + /* Switch to the last buffer */ + if (p->replacing) { + pp_set_copy_replace_list (NULL); + } + if (p->joining) { + pp_set_joining_ext (NULL); + } + switch_to_buffer (p->line, p->file, p->buffer); + quotation_mark = p->quotation_mark; + + copy_stack = p->next; + free (p); +} + YY_BREAK +case 99: +YY_RULE_SETUP #line 423 "pplex.l" - YY_FATAL_ERROR("flex scanner jammed"); - YY_BREAK -#line 2722 "pplex.c" - - case YY_END_OF_BUFFER: { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int)(yy_cp - (yytext_ptr)) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = (yy_hold_char); - YY_RESTORE_YY_MORE_OFFSET - - if (YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW) { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ((yy_c_buf_p) <= - &YY_CURRENT_BUFFER_LVALUE - ->yy_ch_buf[(yy_n_chars)]) { /* This was really a NUL. */ - yy_state_type yy_next_state; - - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state(); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans(yy_current_state); - - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - - if (yy_next_state) { - /* Consume the NUL. */ - yy_cp = ++(yy_c_buf_p); - yy_current_state = yy_next_state; - goto yy_match; - } - - else { - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; - } - } - - else - switch (yy_get_next_buffer()) { - case EOB_ACT_END_OF_FILE: { - (yy_did_buffer_switch_on_eof) = 0; - - if (yywrap()) { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else { - if (!(yy_did_buffer_switch_on_eof)) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state(); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - (yy_c_buf_p) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; - - yy_current_state = yy_get_previous_state(); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR("fatal flex scanner internal error--no action found"); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of user's declarations */ +YY_FATAL_ERROR( "flex scanner jammed" ); + YY_BREAK +#line 2721 "pplex.c" + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = (yy_hold_char); + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++(yy_c_buf_p); + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_END_OF_FILE: + { + (yy_did_buffer_switch_on_eof) = 0; + + if ( yywrap( ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ + } /* end of user's declarations */ } /* end of yylex */ /* yy_get_next_buffer - try to read in a new buffer @@ -2643,149 +2858,170 @@ YY_DECL { * EOB_ACT_CONTINUE_SCAN - continue scanning from current position * EOB_ACT_END_OF_FILE - end of file */ -static int yy_get_next_buffer(void) { - char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - char *source = (yytext_ptr); - int number_to_move, i; - int ret_val; - - if ((yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1]) - YY_FATAL_ERROR("fatal flex scanner internal error--end of buffer missed"); - - if (YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == - 0) { /* Don't try to fill the buffer, so this is an EOF. */ - if ((yy_c_buf_p) - (yytext_ptr)-YY_MORE_ADJ == 1) { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (int)((yy_c_buf_p) - (yytext_ptr)-1); - - for (i = 0; i < number_to_move; ++i) - *(dest++) = *(source++); - - if (YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; - - else { - int num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - - while (num_to_read <= 0) { /* Not enough room in the buffer - grow it. */ - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; - - int yy_c_buf_p_offset = (int)((yy_c_buf_p)-b->yy_ch_buf); - - if (b->yy_is_our_buffer) { - int new_size = b->yy_buf_size * 2; - - if (new_size <= 0) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - yyrealloc((void *)b->yy_ch_buf, (yy_size_t)(b->yy_buf_size + 2)); - } else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = NULL; - - if (!b->yy_ch_buf) - YY_FATAL_ERROR("fatal error - scanner input buffer overflow"); - - (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - } - - if (num_to_read > YY_READ_BUF_SIZE) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT((&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), num_to_read); - - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - if ((yy_n_chars) == 0) { - if (number_to_move == YY_MORE_ADJ) { - ret_val = EOB_ACT_END_OF_FILE; - yyrestart(yyin); - } - - else { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { - /* Extend the array by 50%, plus the number we really need. */ - int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *)yyrealloc( - (void *)YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t)new_size); - if (!YY_CURRENT_BUFFER_LVALUE->yy_ch_buf) - YY_FATAL_ERROR("out of dynamic memory in yy_get_next_buffer()"); - /* "- 2" to take care of EOB's */ - YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int)(new_size - 2); - } - - (yy_n_chars) += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; - - (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; - - return ret_val; +static int yy_get_next_buffer (void) +{ + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + char *source = (yytext_ptr); + int number_to_move, i; + int ret_val; + + if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1); + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + + else + { + int num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; + + int yy_c_buf_p_offset = + (int) ((yy_c_buf_p) - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yyrealloc( (void *) b->yy_ch_buf, + (yy_size_t) (b->yy_buf_size + 2) ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = NULL; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; + + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + if ( (yy_n_chars) == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart( yyin ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc( + (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + /* "- 2" to take care of EOB's */ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2); + } + + (yy_n_chars) += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + + (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; } /* yy_get_previous_state - get the state just before the EOB char was reached */ -static yy_state_type yy_get_previous_state(void) { - yy_state_type yy_current_state; - char *yy_cp; - - yy_current_state = (yy_start); - yy_current_state += YY_AT_BOL(); - - for (yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp) { - YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if (yy_accept[yy_current_state]) { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) { - yy_current_state = (int)yy_def[yy_current_state]; - if (yy_current_state >= 609) - yy_c = yy_meta[yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - } - - return yy_current_state; + static yy_state_type yy_get_previous_state (void) +{ + yy_state_type yy_current_state; + char *yy_cp; + + yy_current_state = (yy_start); + yy_current_state += YY_AT_BOL(); + + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + { + YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 609 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + } + + return yy_current_state; } /* yy_try_NUL_trans - try to make a transition on the NUL character @@ -2793,589 +3029,650 @@ static yy_state_type yy_get_previous_state(void) { * synopsis * next_state = yy_try_NUL_trans( current_state ); */ -static yy_state_type yy_try_NUL_trans(yy_state_type yy_current_state) { - int yy_is_jam; - char *yy_cp = (yy_c_buf_p); - - YY_CHAR yy_c = 1; - if (yy_accept[yy_current_state]) { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) { - yy_current_state = (int)yy_def[yy_current_state]; - if (yy_current_state >= 609) - yy_c = yy_meta[yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - yy_is_jam = (yy_current_state == 608); - - return yy_is_jam ? 0 : yy_current_state; + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) +{ + int yy_is_jam; + char *yy_cp = (yy_c_buf_p); + + YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 609 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + yy_is_jam = (yy_current_state == 608); + + return yy_is_jam ? 0 : yy_current_state; } #ifndef YY_NO_UNPUT -static void yyunput(int c, char *yy_bp) { - char *yy_cp; - - yy_cp = (yy_c_buf_p); - - /* undo effects of setting up yytext */ - *yy_cp = (yy_hold_char); - - if (yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + - 2) { /* need to shift things up to make room */ - /* +2 for EOB chars. */ - int number_to_move = (yy_n_chars) + 2; - char *dest = &YY_CURRENT_BUFFER_LVALUE - ->yy_ch_buf[YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; - char *source = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; - - while (source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf) - *--dest = *--source; - - yy_cp += (int)(dest - source); - yy_bp += (int)(dest - source); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = - (int)YY_CURRENT_BUFFER_LVALUE->yy_buf_size; - - if (yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2) - YY_FATAL_ERROR("flex scanner push-back overflow"); - } - - *--yy_cp = (char)c; - - (yytext_ptr) = yy_bp; - (yy_hold_char) = *yy_cp; - (yy_c_buf_p) = yy_cp; + static void yyunput (int c, char * yy_bp ) +{ + char *yy_cp; + + yy_cp = (yy_c_buf_p); + + /* undo effects of setting up yytext */ + *yy_cp = (yy_hold_char); + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + int number_to_move = (yy_n_chars) + 2; + char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; + char *source = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; + + while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + *--dest = *--source; + + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = + (yy_n_chars) = (int) YY_CURRENT_BUFFER_LVALUE->yy_buf_size; + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + *--yy_cp = (char) c; + + (yytext_ptr) = yy_bp; + (yy_hold_char) = *yy_cp; + (yy_c_buf_p) = yy_cp; } #endif #ifndef YY_NO_INPUT #ifdef __cplusplus -static int yyinput(void) + static int yyinput (void) #else -static int input(void) + static int input (void) #endif { - int c; - - *(yy_c_buf_p) = (yy_hold_char); - - if (*(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR) { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ((yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]) - /* This was really a NUL. */ - *(yy_c_buf_p) = '\0'; - - else { /* need more input */ - int offset = (int)((yy_c_buf_p) - (yytext_ptr)); - ++(yy_c_buf_p); - - switch (yy_get_next_buffer()) { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - yyrestart(yyin); - - /*FALLTHROUGH*/ - - case EOB_ACT_END_OF_FILE: { - if (yywrap()) - return 0; - - if (!(yy_did_buffer_switch_on_eof)) - YY_NEW_FILE; + int c; + + *(yy_c_buf_p) = (yy_hold_char); + + if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + /* This was really a NUL. */ + *(yy_c_buf_p) = '\0'; + + else + { /* need more input */ + int offset = (int) ((yy_c_buf_p) - (yytext_ptr)); + ++(yy_c_buf_p); + + switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart( yyin ); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( yywrap( ) ) + return 0; + + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; #ifdef __cplusplus - return yyinput(); + return yyinput(); #else - return input(); + return input(); #endif - } + } - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = (yytext_ptr) + offset; - break; - } - } - } + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = (yytext_ptr) + offset; + break; + } + } + } - c = *(unsigned char *)(yy_c_buf_p); /* cast for 8-bit char's */ - *(yy_c_buf_p) = '\0'; /* preserve yytext */ - (yy_hold_char) = *++(yy_c_buf_p); + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve yytext */ + (yy_hold_char) = *++(yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\n'); + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\n'); - return c; + return c; } -#endif /* ifndef YY_NO_INPUT */ +#endif /* ifndef YY_NO_INPUT */ /** Immediately switch to a different input stream. * @param input_file A readable stream. - * + * * @note This function does not reset the start condition to @c INITIAL . */ -void yyrestart(FILE *input_file) { - - if (!YY_CURRENT_BUFFER) { - yyensure_buffer_stack(); - YY_CURRENT_BUFFER_LVALUE = yy_create_buffer(yyin, YY_BUF_SIZE); - } - - yy_init_buffer(YY_CURRENT_BUFFER, input_file); - yy_load_buffer_state(); + void yyrestart (FILE * input_file ) +{ + + if ( ! YY_CURRENT_BUFFER ){ + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer( yyin, YY_BUF_SIZE ); + } + + yy_init_buffer( YY_CURRENT_BUFFER, input_file ); + yy_load_buffer_state( ); } /** Switch to a different input buffer. * @param new_buffer The new input buffer. - * + * */ -void yy_switch_to_buffer(YY_BUFFER_STATE new_buffer) { - - /* TODO. We should be able to replace this entire function body - * with - * yypop_buffer_state(); - * yypush_buffer_state(new_buffer); - */ - yyensure_buffer_stack(); - if (YY_CURRENT_BUFFER == new_buffer) - return; - - if (YY_CURRENT_BUFFER) { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state(); - - /* We don't actually know whether we did this switch during - * EOF (yywrap()) processing, but the only time this flag - * is looked at is after yywrap() is called, so it's safe - * to go ahead and always set it. - */ - (yy_did_buffer_switch_on_eof) = 1; + void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) +{ + + /* TODO. We should be able to replace this entire function body + * with + * yypop_buffer_state(); + * yypush_buffer_state(new_buffer); + */ + yyensure_buffer_stack (); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + yy_load_buffer_state( ); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + (yy_did_buffer_switch_on_eof) = 1; } -static void yy_load_buffer_state(void) { - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - (yy_hold_char) = *(yy_c_buf_p); +static void yy_load_buffer_state (void) +{ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + (yy_hold_char) = *(yy_c_buf_p); } /** Allocate and initialize an input buffer state. * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c - * YY_BUF_SIZE. - * + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * * @return the allocated buffer state. */ -YY_BUFFER_STATE yy_create_buffer(FILE *file, int size) { - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE)yyalloc(sizeof(struct yy_buffer_state)); - if (!b) - YY_FATAL_ERROR("out of dynamic memory in yy_create_buffer()"); + YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - b->yy_buf_size = size; + b->yy_buf_size = size; - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *)yyalloc((yy_size_t)(b->yy_buf_size + 2)); - if (!b->yy_ch_buf) - YY_FATAL_ERROR("out of dynamic memory in yy_create_buffer()"); + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - b->yy_is_our_buffer = 1; + b->yy_is_our_buffer = 1; - yy_init_buffer(b, file); + yy_init_buffer( b, file ); - return b; + return b; } /** Destroy the buffer. * @param b a buffer created with yy_create_buffer() - * + * */ -void yy_delete_buffer(YY_BUFFER_STATE b) { - - if (!b) - return; + void yy_delete_buffer (YY_BUFFER_STATE b ) +{ + + if ( ! b ) + return; - if (b == YY_CURRENT_BUFFER) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE)0; + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - if (b->yy_is_our_buffer) - yyfree((void *)b->yy_ch_buf); + if ( b->yy_is_our_buffer ) + yyfree( (void *) b->yy_ch_buf ); - yyfree((void *)b); + yyfree( (void *) b ); } /* Initializes or reinitializes a buffer. * This function is sometimes called more than once on the same buffer, * such as during a yyrestart() or at EOF. */ -static void yy_init_buffer(YY_BUFFER_STATE b, FILE *file) + static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) { - int oerrno = errno; + int oerrno = errno; + + yy_flush_buffer( b ); - yy_flush_buffer(b); + b->yy_input_file = file; + b->yy_fill_buffer = 1; - b->yy_input_file = file; - b->yy_fill_buffer = 1; - - /* If b is the current buffer, then yy_init_buffer was _probably_ - * called from yyrestart() or through yy_get_next_buffer. - * In that case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER) { - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } - - b->yy_is_interactive = 0; + /* If b is the current buffer, then yy_init_buffer was _probably_ + * called from yyrestart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } - errno = oerrno; + b->yy_is_interactive = 0; + + errno = oerrno; } /** Discard all buffered characters. On the next scan, YY_INPUT will be called. * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * + * */ -void yy_flush_buffer(YY_BUFFER_STATE b) { - if (!b) - return; + void yy_flush_buffer (YY_BUFFER_STATE b ) +{ + if ( ! b ) + return; - b->yy_n_chars = 0; + b->yy_n_chars = 0; - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - b->yy_buf_pos = &b->yy_ch_buf[0]; + b->yy_buf_pos = &b->yy_ch_buf[0]; - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; - if (b == YY_CURRENT_BUFFER) - yy_load_buffer_state(); + if ( b == YY_CURRENT_BUFFER ) + yy_load_buffer_state( ); } /** Pushes the new state onto the stack. The new state becomes * the current state. This function will allocate the stack * if necessary. * @param new_buffer The new state. - * + * */ -void yypush_buffer_state(YY_BUFFER_STATE new_buffer) { - if (new_buffer == NULL) - return; - - yyensure_buffer_stack(); - - /* This block is copied from yy_switch_to_buffer. */ - if (YY_CURRENT_BUFFER) { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - (yy_buffer_stack_top)++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; - - /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state(); - (yy_did_buffer_switch_on_eof) = 1; +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) +{ + if (new_buffer == NULL) + return; + + yyensure_buffer_stack(); + + /* This block is copied from yy_switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + (yy_buffer_stack_top)++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from yy_switch_to_buffer. */ + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; } /** Removes and deletes the top of the stack, if present. * The next element becomes the new top. - * + * */ -void yypop_buffer_state(void) { - if (!YY_CURRENT_BUFFER) - return; - - yy_delete_buffer(YY_CURRENT_BUFFER); - YY_CURRENT_BUFFER_LVALUE = NULL; - if ((yy_buffer_stack_top) > 0) - --(yy_buffer_stack_top); - - if (YY_CURRENT_BUFFER) { - yy_load_buffer_state(); - (yy_did_buffer_switch_on_eof) = 1; - } +void yypop_buffer_state (void) +{ + if (!YY_CURRENT_BUFFER) + return; + + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + if ((yy_buffer_stack_top) > 0) + --(yy_buffer_stack_top); + + if (YY_CURRENT_BUFFER) { + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; + } } /* Allocates the stack if it does not exist. * Guarantees space for at least one push. */ -static void yyensure_buffer_stack(void) { - yy_size_t num_to_alloc; - - if (!(yy_buffer_stack)) { - - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ - (yy_buffer_stack) = (struct yy_buffer_state **)yyalloc( - num_to_alloc * sizeof(struct yy_buffer_state *)); - if (!(yy_buffer_stack)) - YY_FATAL_ERROR("out of dynamic memory in yyensure_buffer_stack()"); - - memset((yy_buffer_stack), 0, - num_to_alloc * sizeof(struct yy_buffer_state *)); - - (yy_buffer_stack_max) = num_to_alloc; - (yy_buffer_stack_top) = 0; - return; - } - - if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1) { - - /* Increase the buffer to prepare for a possible push. */ - yy_size_t grow_size = 8 /* arbitrary grow size */; - - num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state **)yyrealloc( - (yy_buffer_stack), num_to_alloc * sizeof(struct yy_buffer_state *)); - if (!(yy_buffer_stack)) - YY_FATAL_ERROR("out of dynamic memory in yyensure_buffer_stack()"); +static void yyensure_buffer_stack (void) +{ + yy_size_t num_to_alloc; + + if (!(yy_buffer_stack)) { - /* zero only the new slots.*/ - memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, - grow_size * sizeof(struct yy_buffer_state *)); - (yy_buffer_stack_max) = num_to_alloc; - } + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ + (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + (yy_buffer_stack_max) = num_to_alloc; + (yy_buffer_stack_top) = 0; + return; + } + + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + + /* Increase the buffer to prepare for a possible push. */ + yy_size_t grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = (yy_buffer_stack_max) + grow_size; + (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc + ((yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); + (yy_buffer_stack_max) = num_to_alloc; + } } -/** Setup the input buffer state to scan directly from a user-specified - * character buffer. +/** Setup the input buffer state to scan directly from a user-specified character buffer. * @param base the character buffer * @param size the size in bytes of the character buffer - * + * * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE yy_scan_buffer(char *base, yy_size_t size) { - YY_BUFFER_STATE b; - - if (size < 2 || base[size - 2] != YY_END_OF_BUFFER_CHAR || - base[size - 1] != YY_END_OF_BUFFER_CHAR) - /* They forgot to leave room for the EOB's. */ - return NULL; - - b = (YY_BUFFER_STATE)yyalloc(sizeof(struct yy_buffer_state)); - if (!b) - YY_FATAL_ERROR("out of dynamic memory in yy_scan_buffer()"); - - b->yy_buf_size = (int)(size - 2); /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = NULL; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - yy_switch_to_buffer(b); - - return b; +YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) +{ + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return NULL; + + b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); + + b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = NULL; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + yy_switch_to_buffer( b ); + + return b; } /** Setup the input buffer state to scan a string. The next call to yylex() will * scan from a @e copy of @a str. * @param yystr a NUL-terminated string to scan - * + * * @return the newly allocated buffer state object. * @note If you want to scan bytes that may contain NUL values, then use * yy_scan_bytes() instead. */ -YY_BUFFER_STATE yy_scan_string(const char *yystr) { - - return yy_scan_bytes(yystr, (int)strlen(yystr)); +YY_BUFFER_STATE yy_scan_string (const char * yystr ) +{ + + return yy_scan_bytes( yystr, (int) strlen(yystr) ); } -/** Setup the input buffer state to scan the given bytes. The next call to - * yylex() will scan from a @e copy of @a bytes. +/** Setup the input buffer state to scan the given bytes. The next call to yylex() will + * scan from a @e copy of @a bytes. * @param yybytes the byte buffer to scan * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. - * + * * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE yy_scan_bytes(const char *yybytes, int _yybytes_len) { - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - int i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = (yy_size_t)(_yybytes_len + 2); - buf = (char *)yyalloc(n); - if (!buf) - YY_FATAL_ERROR("out of dynamic memory in yy_scan_bytes()"); - - for (i = 0; i < _yybytes_len; ++i) - buf[i] = yybytes[i]; - - buf[_yybytes_len] = buf[_yybytes_len + 1] = YY_END_OF_BUFFER_CHAR; - - b = yy_scan_buffer(buf, n); - if (!b) - YY_FATAL_ERROR("bad buffer in yy_scan_bytes()"); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; +YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) +{ + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + int i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = (yy_size_t) (_yybytes_len + 2); + buf = (char *) yyalloc( n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); + + for ( i = 0; i < _yybytes_len; ++i ) + buf[i] = yybytes[i]; + + buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; + + b = yy_scan_buffer( buf, n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; } #ifndef YY_EXIT_FAILURE #define YY_EXIT_FAILURE 2 #endif -static void yynoreturn yy_fatal_error(const char *msg) { - fprintf(stderr, "%s\n", msg); - exit(YY_EXIT_FAILURE); +static void yynoreturn yy_fatal_error (const char* msg ) +{ + fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); } /* Redefine yyless() so it works in section 3 code. */ #undef yyless -#define yyless(n) \ - do { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg); \ - yytext[yyleng] = (yy_hold_char); \ - (yy_c_buf_p) = yytext + yyless_macro_arg; \ - (yy_hold_char) = *(yy_c_buf_p); \ - *(yy_c_buf_p) = '\0'; \ - yyleng = yyless_macro_arg; \ - } while (0) +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + yytext[yyleng] = (yy_hold_char); \ + (yy_c_buf_p) = yytext + yyless_macro_arg; \ + (yy_hold_char) = *(yy_c_buf_p); \ + *(yy_c_buf_p) = '\0'; \ + yyleng = yyless_macro_arg; \ + } \ + while ( 0 ) /* Accessor methods (get/set functions) to struct members. */ /** Get the current line number. - * + * */ -int yyget_lineno(void) { return yylineno; } +int yyget_lineno (void) +{ + + return yylineno; +} /** Get the input stream. - * + * */ -FILE *yyget_in(void) { return yyin; } +FILE *yyget_in (void) +{ + return yyin; +} /** Get the output stream. - * + * */ -FILE *yyget_out(void) { return yyout; } +FILE *yyget_out (void) +{ + return yyout; +} /** Get the length of the current token. - * + * */ -int yyget_leng(void) { return yyleng; } +int yyget_leng (void) +{ + return yyleng; +} /** Get the current token. - * + * */ -char *yyget_text(void) { return yytext; } +char *yyget_text (void) +{ + return yytext; +} /** Set the current line number. * @param _line_number line number - * + * */ -void yyset_lineno(int _line_number) { yylineno = _line_number; } +void yyset_lineno (int _line_number ) +{ + + yylineno = _line_number; +} /** Set the input stream. This does not discard the current * input buffer. * @param _in_str A readable stream. - * + * * @see yy_switch_to_buffer */ -void yyset_in(FILE *_in_str) { yyin = _in_str; } +void yyset_in (FILE * _in_str ) +{ + yyin = _in_str ; +} -void yyset_out(FILE *_out_str) { yyout = _out_str; } +void yyset_out (FILE * _out_str ) +{ + yyout = _out_str ; +} -int yyget_debug(void) { return yy_flex_debug; } +int yyget_debug (void) +{ + return yy_flex_debug; +} -void yyset_debug(int _bdebug) { yy_flex_debug = _bdebug; } +void yyset_debug (int _bdebug ) +{ + yy_flex_debug = _bdebug ; +} -static int yy_init_globals(void) { - /* Initialization is the same as for the non-reentrant scanner. - * This function is called from yylex_destroy(), so don't allocate here. - */ +static int yy_init_globals (void) +{ + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from yylex_destroy(), so don't allocate here. + */ - (yy_buffer_stack) = NULL; - (yy_buffer_stack_top) = 0; - (yy_buffer_stack_max) = 0; - (yy_c_buf_p) = NULL; - (yy_init) = 0; - (yy_start) = 0; + (yy_buffer_stack) = NULL; + (yy_buffer_stack_top) = 0; + (yy_buffer_stack_max) = 0; + (yy_c_buf_p) = NULL; + (yy_init) = 0; + (yy_start) = 0; /* Defined in main.c */ #ifdef YY_STDINIT - yyin = stdin; - yyout = stdout; + yyin = stdin; + yyout = stdout; #else - yyin = NULL; - yyout = NULL; + yyin = NULL; + yyout = NULL; #endif - /* For future reference: Set errno on error, since we are called by - * yylex_init() - */ - return 0; + /* For future reference: Set errno on error, since we are called by + * yylex_init() + */ + return 0; } /* yylex_destroy is for both reentrant and non-reentrant scanners. */ -int yylex_destroy(void) { - - /* Pop the buffer stack, destroying each element. */ - while (YY_CURRENT_BUFFER) { - yy_delete_buffer(YY_CURRENT_BUFFER); - YY_CURRENT_BUFFER_LVALUE = NULL; - yypop_buffer_state(); - } - - /* Destroy the stack itself. */ - yyfree((yy_buffer_stack)); - (yy_buffer_stack) = NULL; - - /* Reset the globals. This is important in a non-reentrant scanner so the next - * time yylex() is called, initialization will occur. */ - yy_init_globals(); - - return 0; +int yylex_destroy (void) +{ + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + yy_delete_buffer( YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + yypop_buffer_state(); + } + + /* Destroy the stack itself. */ + yyfree((yy_buffer_stack) ); + (yy_buffer_stack) = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next time + * yylex() is called, initialization will occur. */ + yy_init_globals( ); + + return 0; } /* @@ -3383,1024 +3680,1089 @@ int yylex_destroy(void) { */ #ifndef yytext_ptr -static void yy_flex_strncpy(char *s1, const char *s2, int n) { - - int i; - for (i = 0; i < n; ++i) - s1[i] = s2[i]; +static void yy_flex_strncpy (char* s1, const char * s2, int n ) +{ + + int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; } #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen(const char *s) { - int n; - for (n = 0; s[n]; ++n) - ; +static int yy_flex_strlen (const char * s ) +{ + int n; + for ( n = 0; s[n]; ++n ) + ; - return n; + return n; } #endif -void *yyalloc(yy_size_t size) { return malloc(size); } - -void *yyrealloc(void *ptr, yy_size_t size) { +void *yyalloc (yy_size_t size ) +{ + return malloc(size); +} - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return realloc(ptr, size); +void *yyrealloc (void * ptr, yy_size_t size ) +{ + + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return realloc(ptr, size); } -void yyfree(void *ptr) { - free((char *)ptr); /* see yyrealloc() for (char *) cast */ +void yyfree (void * ptr ) +{ + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ } #define YYTABLES_NAME "yytables" #line 423 "pplex.l" -void pp_set_replace_list(struct cb_replace_list *list) { - current_replace_list = list; + +void +pp_set_replace_list (struct cb_replace_list *list) +{ + current_replace_list = list; } -void pp_set_copy_replace_list(struct cb_replace_list *list) { - current_copy_replace_list = list; +void +pp_set_copy_replace_list (struct cb_replace_list *list) +{ + current_copy_replace_list = list; } -void pp_set_joining_ext(struct cb_joining_ext *ext) { - current_joining_ext = ext; +void +pp_set_joining_ext (struct cb_joining_ext *ext) +{ + current_joining_ext = ext; } -#ifdef I18N_UTF8 -#define UTF8_FULLWIDTH_HYPHEN_MINUS "\xEF\xBC\x8D" -#define UTF8_MINUS_SIGN "\xE2\x88\x92" +#ifdef I18N_UTF8 +# define UTF8_FULLWIDTH_HYPHEN_MINUS "\xEF\xBC\x8D" +# define UTF8_MINUS_SIGN "\xE2\x88\x92" #else /*!I18N_UTF8*/ -#define SJIS_MINUS_SIGN "\x81\x7c" +# define SJIS_MINUS_SIGN "\x81\x7c" #endif /*I18N_UTF8*/ -#ifdef I18N_UTF8 -static void convert_ucs_hyphen_minus(char *namebuf) { - char *p = namebuf; - while (NULL != (p = strstr(p, UTF8_MINUS_SIGN))) { - memcpy(p, UTF8_FULLWIDTH_HYPHEN_MINUS, 3); - p += 3; - } - return; +#ifdef I18N_UTF8 +static void +convert_ucs_hyphen_minus (char *namebuf) +{ + char *p = namebuf; + while (NULL != (p = strstr (p, UTF8_MINUS_SIGN))) { + *p = '_'; + memmove(p+1, p+3, strlen(p+3)+1); + p++; + } + + p = namebuf; + while (NULL != (p = strstr (p, UTF8_FULLWIDTH_HYPHEN_MINUS))) { + *p = '_'; + memmove(p+1, p+3, strlen(p+3)+1); + p++; + } + return; } #endif /*I18N_UTF8*/ -static void ppecho_dataname(char *namebuf) { - int extlen, namelen, seplen; - const char *ext; - const char *sep; +static void +ppecho_dataname (char *namebuf) +{ + int extlen, namelen, seplen; + const char *ext; + const char *sep; -#ifdef I18N_UTF8 - convert_ucs_hyphen_minus(namebuf); +#ifdef I18N_UTF8 + convert_ucs_hyphen_minus (namebuf); #endif /*I18N_UTF8*/ - if (!current_joining_ext) { - ppecho(namebuf); - } else { - ext = current_joining_ext->ext; - if (!plexbuff1) { - plexbuff1 = cobc_malloc(COB_SMALL_BUFF); - } - extlen = strlen(ext); - namelen = strlen(namebuf); -#ifdef I18N_UTF8 - if (!utf8_ext_pick((unsigned char *)ext)) { - sep = "-"; - seplen = 1; - } else { - sep = UTF8_FULLWIDTH_HYPHEN_MINUS; - seplen = 3; - } -#else /*!I18N_UTF8*/ - if (!sjis_pick((unsigned char *)ext)) { - sep = "-"; - seplen = 1; - } else { - sep = SJIS_MINUS_SIGN; - seplen = 2; - } + if (!current_joining_ext) { + ppecho (namebuf); + } else { + ext = current_joining_ext->ext; + if (!plexbuff1) { + plexbuff1 = cobc_malloc (COB_SMALL_BUFF); + } + extlen = strlen (ext); + namelen = strlen (namebuf); +#ifdef I18N_UTF8 + if (!utf8_ext_pick ((unsigned char*) ext)) { + sep = "-"; + seplen = 1; + } else { + sep = UTF8_FULLWIDTH_HYPHEN_MINUS; + seplen = 3; + } +#else /*!I18N_UTF8*/ + if (!sjis_pick ((unsigned char*) ext)) { + sep = "-"; + seplen = 1; + } else { + sep = SJIS_MINUS_SIGN; + seplen = 2; + } #endif /*I18N_UTF8*/ - if (current_joining_ext->type == joining_as_prefix) { - memcpy(plexbuff1, ext, extlen); - memcpy(&(plexbuff1[extlen]), sep, seplen); - memcpy(&(plexbuff1[extlen + seplen]), &(namebuf[0]), namelen + 1); - } else if (current_joining_ext->type == joining_as_suffix) { - memcpy(plexbuff1, &(namebuf[0]), namelen); - memcpy(&(plexbuff1[namelen]), sep, seplen); - memcpy(&(plexbuff1[namelen + seplen]), ext, extlen + 1); - } else if (current_joining_ext->type == prefixing) { - memcpy(plexbuff1, ext, extlen); - memcpy(&(plexbuff1[extlen]), &(namebuf[0]), namelen + 1); - } else if (current_joining_ext->type == suffixing) { - memcpy(plexbuff1, &(namebuf[0]), namelen); - memcpy(&(plexbuff1[namelen]), ext, extlen + 1); - } - ppecho(plexbuff1); - } + if (current_joining_ext->type == joining_as_prefix) { + memcpy (plexbuff1, ext, extlen); + memcpy (&(plexbuff1[extlen]), sep, seplen); + memcpy (&(plexbuff1[extlen+seplen]), &(namebuf[0]), namelen+1); + } else if (current_joining_ext->type == joining_as_suffix) { + memcpy (plexbuff1, &(namebuf[0]), namelen); + memcpy (&(plexbuff1[namelen]), sep, seplen); + memcpy (&(plexbuff1[namelen+seplen]), ext, extlen+1); + } else if (current_joining_ext->type == prefixing) { + memcpy (plexbuff1, ext, extlen); + memcpy (&(plexbuff1[extlen]), &(namebuf[0]), namelen+1); + } else if (current_joining_ext->type == suffixing) { + memcpy (plexbuff1, &(namebuf[0]), namelen); + memcpy (&(plexbuff1[namelen]), ext, extlen+1); + } + ppecho (plexbuff1); + } } -static void switch_to_buffer(const int line, const char *file, - YY_BUFFER_STATE buffer) { - char *p; - - cb_source_line = line; - cb_source_file = strdup(file); - for (p = cb_source_file; *p; p++) { - if (*p == '\\') { - *p = '/'; - } - } - yy_switch_to_buffer(buffer); - fprintf(yyout, "# %d \"%s\"\n", line, cb_source_file); +static void +switch_to_buffer (const int line, const char *file, YY_BUFFER_STATE buffer) +{ + char *p; + + cb_source_line = line; + cb_source_file = strdup (file); + for (p = cb_source_file; *p; p++) { + if (*p == '\\') { + *p = '/'; + } + } + yy_switch_to_buffer (buffer); + fprintf (yyout, "# %d \"%s\"\n", line, cb_source_file); } -int ppopen(const char *name, struct cb_joining_ext *joining_ext, - struct cb_replace_list *replace_list) { - struct copy_info *p; - - for (; newline_count > 0; newline_count--) { - ungetc('\n', ppin); - } - - /* Open the copy file */ - ppin = fopen(name, "rb"); - if (!ppin) { - if (cb_source_file) { - cb_error(_("%s: %s"), name, strerror(errno)); - } else { - perror(name); - } - return -1; - } - - /* Add to dependency list */ - if (cb_depend_file) { - cb_depend_list = cb_text_list_add(cb_depend_list, name); - } - - /* Preserve the current buffer */ - p = cobc_malloc(sizeof(struct copy_info)); - p->line = cb_source_line; - p->file = cb_source_file; - p->replacing = replace_list ? 1 : 0; - p->joining = joining_ext ? 1 : 0; - p->buffer = YY_CURRENT_BUFFER; - p->quotation_mark = quotation_mark; - p->next = copy_stack; - copy_stack = p; - - /* Switch to new buffer */ - if (replace_list) { - pp_set_copy_replace_list(replace_list); - } - if (joining_ext) { - pp_set_joining_ext(joining_ext); - } - switch_to_buffer(1, name, yy_create_buffer(ppin, YY_BUF_SIZE)); - return 0; +int +ppopen (const char *name, struct cb_joining_ext *joining_ext, struct cb_replace_list *replace_list) +{ + struct copy_info *p; + + for (; newline_count > 0; newline_count--) { + ungetc ('\n', ppin); + } + + /* Open the copy file */ + ppin = fopen (name, "rb"); + if (!ppin) { + if (cb_source_file) { + cb_error (_("%s: %s"), name, strerror (errno)); + } else { + perror (name); + } + return -1; + } + + /* Add to dependency list */ + if (cb_depend_file) { + cb_depend_list = cb_text_list_add (cb_depend_list, name); + } + + /* Preserve the current buffer */ + p = cobc_malloc (sizeof (struct copy_info)); + p->line = cb_source_line; + p->file = cb_source_file; + p->replacing = replace_list ? 1 : 0; + p->joining = joining_ext ? 1 : 0; + p->buffer = YY_CURRENT_BUFFER; + p->quotation_mark = quotation_mark; + p->next = copy_stack; + copy_stack = p; + + /* Switch to new buffer */ + if (replace_list) { + pp_set_copy_replace_list (replace_list); + } + if (joining_ext) { + pp_set_joining_ext (joining_ext); + } + switch_to_buffer (1, name, yy_create_buffer (ppin, YY_BUF_SIZE)); + return 0; } -int ppcopy(const char *name, const char *lib, - struct cb_joining_ext *joining_ext, - struct cb_replace_list *replace_list) { - struct cb_text_list *il; - struct cb_text_list *el; - char *s; - struct stat st; - - if (lib) { - if (!plexbuff1) { - plexbuff1 = cobc_malloc(COB_SMALL_BUFF); - } - snprintf(plexbuff1, COB_SMALL_MAX, "%s/%s", lib, name); - s = plexbuff1; - } else { - s = (char *)name; - } - - /* Find the file */ - if (stat(s, &st) == 0) { - return ppopen(s, joining_ext, replace_list); - } - if (!plexbuff2) { - plexbuff2 = cobc_malloc(COB_SMALL_BUFF); - } - for (el = cb_extension_list; el; el = el->next) { - snprintf(plexbuff2, COB_SMALL_MAX, "%s%s", s, el->text); - if (stat(plexbuff2, &st) == 0) { - return ppopen(plexbuff2, joining_ext, replace_list); - } - } - if (*s != '/') { - for (il = cb_include_list; il; il = il->next) { - for (el = cb_extension_list; el; el = el->next) { - snprintf(plexbuff2, COB_SMALL_MAX, "%s/%s%s", il->text, name, el->text); - if (stat(plexbuff2, &st) == 0) { - return ppopen(plexbuff2, joining_ext, replace_list); - } - } - } - } - cb_error(_("%s: %s"), name, strerror(errno)); - return -1; +int +ppcopy (const char *name, const char *lib, struct cb_joining_ext *joining_ext, struct cb_replace_list *replace_list) +{ + struct cb_text_list *il; + struct cb_text_list *el; + char *s; + struct stat st; + + if (lib) { + if (!plexbuff1) { + plexbuff1 = cobc_malloc (COB_SMALL_BUFF); + } + snprintf (plexbuff1, COB_SMALL_MAX, "%s/%s", lib, name); + s = plexbuff1; + } else { + s = (char *)name; + } + + /* Find the file */ + if (stat (s, &st) == 0) { + return ppopen (s, joining_ext, replace_list); + } + if (!plexbuff2) { + plexbuff2 = cobc_malloc (COB_SMALL_BUFF); + } + for (el = cb_extension_list; el; el = el->next) { + snprintf (plexbuff2, COB_SMALL_MAX, "%s%s", s, el->text); + if (stat (plexbuff2, &st) == 0) { + return ppopen (plexbuff2, joining_ext, replace_list); + } + } + if (*s != '/') { + for (il = cb_include_list; il; il = il->next) { + for (el = cb_extension_list; el; el = el->next) { + snprintf (plexbuff2, COB_SMALL_MAX, "%s/%s%s", + il->text, name, el->text); + if (stat (plexbuff2, &st) == 0) { + return ppopen (plexbuff2, joining_ext, replace_list); + } + } + } + } + cb_error (_("%s: %s"), name, strerror (errno)); + return -1; } /* Check directives */ /* This is horrible but we have to parse directives directly after the read */ /* as flex buffers up input and it is then too late to use the flex parser */ -static void check_directive(char *buff, int *line_size) { - char *s; - char *dirptr; - size_t cnt; - int n; - char sbuff[5][256]; - - if (cb_source_format == CB_FORMAT_FIXED) { - if (*line_size < 8) { - return; - } - if (buff[6] != ' ') { - return; - } - s = &buff[7]; - } else { - s = buff; - } - for (; *s == ' '; s++) { - ; - } - dirptr = s; - if (*s != '>') { - return; - } - s++; - if (*s != '>') { - return; - } - s++; - if (*s == 'D') { - if (cb_flag_debugging_line) { - memset(dirptr, ' ', 3); - } else { - for (cnt = 0; cnt < newline_count; cnt++) { - buff[cnt] = '\n'; - } - buff[cnt] = 0; - strcat(buff, " *> DEBUG\n"); - *line_size = strlen(buff); - newline_count = 0; - } - return; - } - memset(sbuff[0], 0, sizeof(sbuff)); - n = sscanf(s, "%255s %255s %255s %255s %255s", sbuff[0], sbuff[1], sbuff[2], - sbuff[3], sbuff[4]); - for (cnt = 0; cnt < newline_count; cnt++) { - buff[cnt] = '\n'; - } - buff[cnt] = 0; - newline_count = 0; - strcat(buff, " *> DIRECTIVE\n"); - *line_size = strlen(buff); - if (n < 2 || strcasecmp(sbuff[0], "SOURCE")) { - cb_warning(_("Invalid directive - ignored")); - return; - } - switch (n) { - case 2: - if (!strcasecmp(sbuff[1], "FIXED")) { - cb_source_format = CB_FORMAT_FIXED; - return; - } - if (!strcasecmp(sbuff[1], "FREE")) { - cb_source_format = CB_FORMAT_FREE; - return; - } - if (!strcasecmp(sbuff[1], "FREE_1COL_ASTER")) { - cb_source_format = CB_FORMAT_FREE_1COL_ASTER; - cb_source_format1 = 1; - return; - } - break; - case 3: - if (strcasecmp(sbuff[1], "FORMAT") && strcasecmp(sbuff[1], "IS")) { - break; - } - if (!strcasecmp(sbuff[2], "FIXED")) { - cb_source_format = CB_FORMAT_FIXED; - return; - } - if (!strcasecmp(sbuff[2], "FREE")) { - cb_source_format = CB_FORMAT_FREE; - return; - } - if (!strcasecmp(sbuff[2], "FREE_1COL_ASTER")) { - cb_source_format = CB_FORMAT_FREE_1COL_ASTER; - cb_source_format1 = 1; - return; - } - break; - default: - if (strcasecmp(sbuff[1], "FORMAT")) { - break; - } - if (strcasecmp(sbuff[2], "IS")) { - break; - } - if (!strcasecmp(sbuff[3], "FIXED")) { - cb_source_format = CB_FORMAT_FIXED; - return; - } - if (!strcasecmp(sbuff[3], "FREE")) { - cb_source_format = CB_FORMAT_FREE; - return; - } - if (!strcasecmp(sbuff[3], "FREE_1COL_ASTER")) { - cb_source_format = CB_FORMAT_FREE_1COL_ASTER; - cb_source_format1 = 1; - return; - } - break; - } - cb_warning(_("Invalid directive - ignored")); +static void +check_directive (char *buff, int *line_size) +{ + char *s; + char *dirptr; + size_t cnt; + int n; + char sbuff[5][256]; + + if (cb_source_format == CB_FORMAT_FIXED) { + if (*line_size < 8) { + return; + } + if (buff[6] != ' ') { + return; + } + s = &buff[7]; + } else { + s = buff; + } + for (; *s == ' '; s++) { + ; + } + dirptr = s; + if (*s != '>') { + return; + } + s++; + if (*s != '>') { + return; + } + s++; + if (*s == 'D') { + if (cb_flag_debugging_line) { + memset (dirptr, ' ', 3); + } else { + for (cnt = 0; cnt < newline_count; cnt++) { + buff[cnt] = '\n'; + } + buff[cnt] = 0; + strcat (buff, " *> DEBUG\n"); + *line_size = strlen (buff); + newline_count = 0; + } + return; + } + memset (sbuff[0], 0, sizeof (sbuff)); + n = sscanf (s, "%255s %255s %255s %255s %255s", + sbuff[0], sbuff[1], sbuff[2], sbuff[3], sbuff[4]); + for (cnt = 0; cnt < newline_count; cnt++) { + buff[cnt] = '\n'; + } + buff[cnt] = 0; + newline_count = 0; + strcat (buff, " *> DIRECTIVE\n"); + *line_size = strlen (buff); + if (n < 2 || strcasecmp (sbuff[0], "SOURCE")) { + cb_warning (_("Invalid directive - ignored")); + return; + } + switch (n) { + case 2: + if (!strcasecmp (sbuff[1], "FIXED")) { + cb_source_format = CB_FORMAT_FIXED; + return; + } + if (!strcasecmp (sbuff[1], "FREE")) { + cb_source_format = CB_FORMAT_FREE; + return; + } + if (!strcasecmp (sbuff[1], "FREE_1COL_ASTER")) { + cb_source_format = CB_FORMAT_FREE_1COL_ASTER; + cb_source_format1 = 1; + return; + } + break; + case 3: + if (strcasecmp (sbuff[1], "FORMAT") && + strcasecmp (sbuff[1], "IS")) { + break; + } + if (!strcasecmp (sbuff[2], "FIXED")) { + cb_source_format = CB_FORMAT_FIXED; + return; + } + if (!strcasecmp (sbuff[2], "FREE")) { + cb_source_format = CB_FORMAT_FREE; + return; + } + if (!strcasecmp (sbuff[2], "FREE_1COL_ASTER")) { + cb_source_format = CB_FORMAT_FREE_1COL_ASTER; + cb_source_format1 = 1; + return; + } + if (!strcasecmp (sbuff[2], "VARIABLE")){ + cb_source_format = CB_FORMAT_VARIABLE; + } + break; + default: + if (strcasecmp (sbuff[1], "FORMAT")) { + break; + } + if (strcasecmp (sbuff[2], "IS")) { + break; + } + if (!strcasecmp (sbuff[3], "FIXED")) { + cb_source_format = CB_FORMAT_FIXED; + return; + } + if (!strcasecmp (sbuff[3], "FREE")) { + cb_source_format = CB_FORMAT_FREE; + return; + } + if (!strcasecmp (sbuff[3], "FREE_1COL_ASTER")) { + cb_source_format = CB_FORMAT_FREE_1COL_ASTER; + cb_source_format1 = 1; + return; + } + if (!strcasecmp (sbuff[3], "VARIABLE")){ + cb_source_format = CB_FORMAT_VARIABLE; + } + break; + } + cb_warning (_("Invalid directive - ignored")); } -static void check_dollar_directive(char *buff, int *line_size) { - struct cb_constant_list *l; - char *s; - size_t cnt; - int n; - char sbuff[5][256]; - int isDEFINED, isNOT; - int i; - COB_UNUSED(n); - - if (cb_source_format == CB_FORMAT_FIXED) { - if (*line_size < 8) { - return; - } - if (buff[6] != '$') { - return; - } - if (*line_size > cb_text_column + 1) { - strcpy(buff + cb_text_column, "\n"); - } - s = &buff[6]; - } else { - if (buff[1] != '$') { - return; - } - s = buff; - } - - memset(sbuff[0], 0, sizeof(sbuff)); - n = sscanf(s, "%255s %255s %255s %255s %255s", sbuff[0], sbuff[1], sbuff[2], - sbuff[3], sbuff[4]); - for (cnt = 0; cnt < newline_count; cnt++) { - buff[cnt] = '\n'; - } - buff[cnt] = 0; - newline_count = 0; - strcat(buff, " *> DIRECTIVE\n"); - *line_size = strlen(buff); - - if (strcasecmp(sbuff[0], "$IF") == 0) { - compile_directive_depth++; - if (compile_directive_depth >= MAX_DEPTH) { - compile_directive_depth = -1; - cb_compile_status = CB_COMPILE_STATUS_ERROR; - cb_error(_("$IF is nested more than 10 times")); - return; - } - if (compile_directive_depth < 0) { - compile_directive_depth = -1; - cb_compile_status = CB_COMPILE_STATUS_ERROR; - cb_error(_("Fatal error in $IF statement")); - return; - } - if (strlen(sbuff[1]) <= 0) { - cb_compile_status = CB_COMPILE_STATUS_ERROR; - cb_error(_("Arguments not enough to $IF statemen")); - return; - } - - isDEFINED = 0; - isNOT = 0; - cb_compile_status_list[compile_directive_depth] = CB_COMPILE_STATUS_FALSE; - if (strcasecmp(sbuff[2], "NOT") == 0) { - isNOT = 1; - cb_compile_status_list[compile_directive_depth] = CB_COMPILE_STATUS_TRUE; - } - if (strcasecmp(sbuff[2 + isNOT], "DEFINED") == 0) { - isDEFINED = 1; - } else if (strcasecmp(sbuff[2 + isNOT], "=") != 0 || - strlen(sbuff[3 + isNOT]) <= 0) { - cb_compile_status = CB_COMPILE_STATUS_ERROR; - cb_error(_("Invalid argument $IF statemen")); - return; - } - l = cb_const_list; - while (l) { - if (strcasecmp(l->name, sbuff[1]) == 0) { - if (isDEFINED) { - if (isNOT) - cb_compile_status_list[compile_directive_depth] = - CB_COMPILE_STATUS_FALSE; - else - cb_compile_status_list[compile_directive_depth] = - CB_COMPILE_STATUS_TRUE; - break; - } else { - switch (l->type) { - case CB_CONSTANT_TYPE_ALPANUM: - if (strlen(sbuff[3 + isNOT]) < 3 || - sbuff[3 + isNOT] != strchr(sbuff[3 + isNOT], '\"') || - sbuff[3 + isNOT] == strrchr(sbuff[3 + isNOT], '\"') || - strlen(strchr(sbuff[3 + isNOT] + 1, '\"')) > 1) { - cb_compile_status = CB_COMPILE_STATUS_ERROR; - cb_error(_("%s is not a string"), sbuff[3 + isNOT]); - return; - } - strcpy(strchr(sbuff[3 + isNOT] + 1, '\"'), ""); - if (strcasecmp(sbuff[3 + isNOT] + 1, l->alphavalue) == 0) { - if (isNOT) - cb_compile_status_list[compile_directive_depth] = - CB_COMPILE_STATUS_FALSE; - else - cb_compile_status_list[compile_directive_depth] = - CB_COMPILE_STATUS_TRUE; - } - break; - case CB_CONSTANT_TYPE_NUMERIC: - // TODO - break; - default: - break; - } - break; - } - } - l = l->next; - } - } else if (strcasecmp(sbuff[0], "$ELSE") == 0) { - if (compile_directive_depth >= MAX_DEPTH) { - compile_directive_depth = -1; - cb_compile_status = CB_COMPILE_STATUS_ERROR; - cb_error(_("Fatal error in $ELSE statement")); - return; - } - if (compile_directive_depth < 0) { - compile_directive_depth = -1; - cb_compile_status = CB_COMPILE_STATUS_ERROR; - cb_error(_("$IF has no defined before the $ELSE")); - return; - } - if (cb_compile_status_list[compile_directive_depth] == - CB_COMPILE_STATUS_TRUE_ELSE || - cb_compile_status_list[compile_directive_depth] == - CB_COMPILE_STATUS_FALSE_ELSE) { - compile_directive_depth = -1; - cb_compile_status = CB_COMPILE_STATUS_ERROR; - cb_error(_("$ELSE has continued")); - return; - } - if (cb_compile_status_list[compile_directive_depth] == - CB_COMPILE_STATUS_FALSE) - cb_compile_status_list[compile_directive_depth] = - CB_COMPILE_STATUS_TRUE_ELSE; - else - cb_compile_status_list[compile_directive_depth] = - CB_COMPILE_STATUS_FALSE_ELSE; - } else if (strcasecmp(sbuff[0], "$END") == 0) { - if (compile_directive_depth >= MAX_DEPTH) { - compile_directive_depth = -1; - cb_compile_status = CB_COMPILE_STATUS_ERROR; - cb_error(_("Fatal error in $END statement")); - return; - } - if (compile_directive_depth < 0) { - compile_directive_depth = -1; - cb_compile_status = CB_COMPILE_STATUS_ERROR; - cb_error(_("$IF has no defined before the $END")); - return; - } - cb_compile_status_list[compile_directive_depth] = CB_COMPILE_STATUS_NONE; - compile_directive_depth--; - } else if (strcasecmp(sbuff[0], "$SET") == 0) { - if (strcasecmp(sbuff[1], "SOURCEFORMAT(FREE)") == 0) { - cb_source_format = CB_FORMAT_FREE; - return; - } else if (strcasecmp(sbuff[1], "SOURCEFORMAT(FIXED)") == 0) { - cb_source_format = CB_FORMAT_FIXED; - return; - } else if (strcasecmp(sbuff[1], "SOURCEFORMAT(FREE_1COL_ASTER)") == 0) { - cb_source_format = CB_FORMAT_FREE_1COL_ASTER; - cb_source_format1 = 1; - return; - } else { - cb_compile_status = CB_COMPILE_STATUS_ERROR; - cb_error(_("Invalid $SET")); - return; - } - } else { - cb_compile_status = CB_COMPILE_STATUS_ERROR; - cb_error(_("Invalid $ statements")); - return; - } - - if (compile_directive_depth > -1) { - for (i = 0; i <= compile_directive_depth; i++) { - if (cb_compile_status_list[i] != CB_COMPILE_STATUS_TRUE && - cb_compile_status_list[i] != CB_COMPILE_STATUS_TRUE_ELSE) { - cb_compile_status = CB_COMPILE_STATUS_FALSE; - return; - } - } - } - if (*buff == '\n') { - cb_compile_status = CB_COMPILE_STATUS_FALSE_END; - } else { - cb_compile_status = CB_COMPILE_STATUS_TRUE; - } +static void +check_dollar_directive (char *buff, int *line_size) +{ + struct cb_constant_list *l; + char *s; + size_t cnt; + int n; + char sbuff[5][256]; + int isDEFINED, isNOT; + int i; + COB_UNUSED(n); + + if (cb_source_format == CB_FORMAT_FIXED) { + if (*line_size < 8) { + return; + } + if (buff[6] != '$') { + return; + } + if (*line_size > cb_text_column + 1) { + strcpy (buff + cb_text_column, "\n"); + } + s = &buff[6]; + } else { + if (buff[1] != '$') { + return; + } + s = buff; + } + + memset (sbuff[0], 0, sizeof (sbuff)); + n = sscanf (s, "%255s %255s %255s %255s %255s", + sbuff[0], sbuff[1], sbuff[2], sbuff[3], sbuff[4]); + for (cnt = 0; cnt < newline_count; cnt++) { + buff[cnt] = '\n'; + } + buff[cnt] = 0; + newline_count = 0; + strcat (buff, " *> DIRECTIVE\n"); + *line_size = strlen (buff); + + if (strcasecmp (sbuff[0], "$IF") == 0) { + compile_directive_depth++; + if (compile_directive_depth >= MAX_DEPTH) { + compile_directive_depth = -1; + cb_compile_status = CB_COMPILE_STATUS_ERROR; + cb_error (_("$IF is nested more than 10 times")); + return; + } + if (compile_directive_depth < 0) { + compile_directive_depth = -1; + cb_compile_status = CB_COMPILE_STATUS_ERROR; + cb_error (_("Fatal error in $IF statement")); + return; + } + if (strlen (sbuff[1]) <= 0) { + cb_compile_status = CB_COMPILE_STATUS_ERROR; + cb_error (_("Arguments not enough to $IF statemen")); + return; + } + + isDEFINED = 0; + isNOT = 0; + cb_compile_status_list[compile_directive_depth] = CB_COMPILE_STATUS_FALSE; + if (strcasecmp (sbuff[2], "NOT") == 0) { + isNOT = 1; + cb_compile_status_list[compile_directive_depth] = CB_COMPILE_STATUS_TRUE; + } + if (strcasecmp (sbuff[2+isNOT], "DEFINED") == 0) { + isDEFINED = 1; + } else if (strcasecmp (sbuff[2+isNOT], "=") != 0 || + strlen (sbuff[3+isNOT]) <= 0) { + cb_compile_status = CB_COMPILE_STATUS_ERROR; + cb_error (_("Invalid argument $IF statemen")); + return; + } + l = cb_const_list; + while (l) { + if (strcasecmp (l->name, sbuff[1]) == 0) { + if (isDEFINED) { + if (isNOT) cb_compile_status_list[compile_directive_depth] = CB_COMPILE_STATUS_FALSE; + else cb_compile_status_list[compile_directive_depth] = CB_COMPILE_STATUS_TRUE; + break; + } else { + switch (l->type) { + case CB_CONSTANT_TYPE_ALPANUM: + if (strlen (sbuff[3+isNOT]) < 3 || + sbuff[3+isNOT] != strchr (sbuff[3+isNOT], '\"') || + sbuff[3+isNOT] == strrchr (sbuff[3+isNOT], '\"') || + strlen (strchr (sbuff[3+isNOT]+1, '\"')) > 1) { + cb_compile_status = CB_COMPILE_STATUS_ERROR; + cb_error (_("%s is not a string"), sbuff[3+isNOT]); + return; + } + strcpy (strchr (sbuff[3+isNOT]+1, '\"'), ""); + if (strcasecmp (sbuff[3+isNOT]+1, l->alphavalue) == 0) { + if (isNOT) cb_compile_status_list[compile_directive_depth] = CB_COMPILE_STATUS_FALSE; + else cb_compile_status_list[compile_directive_depth] = CB_COMPILE_STATUS_TRUE; + } + break; + case CB_CONSTANT_TYPE_NUMERIC: + //TODO + break; + default: + break; + } + break; + } + } + l = l->next; + } + } else if (strcasecmp (sbuff[0], "$ELSE") == 0) { + if (compile_directive_depth >= MAX_DEPTH) { + compile_directive_depth = -1; + cb_compile_status = CB_COMPILE_STATUS_ERROR; + cb_error (_("Fatal error in $ELSE statement")); + return; + } + if (compile_directive_depth < 0) { + compile_directive_depth = -1; + cb_compile_status = CB_COMPILE_STATUS_ERROR; + cb_error (_("$IF has no defined before the $ELSE")); + return; + } + if (cb_compile_status_list[compile_directive_depth] == CB_COMPILE_STATUS_TRUE_ELSE || + cb_compile_status_list[compile_directive_depth] == CB_COMPILE_STATUS_FALSE_ELSE) { + compile_directive_depth = -1; + cb_compile_status = CB_COMPILE_STATUS_ERROR; + cb_error (_("$ELSE has continued")); + return; + } + if (cb_compile_status_list[compile_directive_depth] == CB_COMPILE_STATUS_FALSE) + cb_compile_status_list[compile_directive_depth] = CB_COMPILE_STATUS_TRUE_ELSE; + else cb_compile_status_list[compile_directive_depth] = CB_COMPILE_STATUS_FALSE_ELSE; + } else if (strcasecmp (sbuff[0], "$END") == 0) { + if (compile_directive_depth >= MAX_DEPTH) { + compile_directive_depth = -1; + cb_compile_status = CB_COMPILE_STATUS_ERROR; + cb_error (_("Fatal error in $END statement")); + return; + } + if (compile_directive_depth < 0) { + compile_directive_depth = -1; + cb_compile_status = CB_COMPILE_STATUS_ERROR; + cb_error (_("$IF has no defined before the $END")); + return; + } + cb_compile_status_list[compile_directive_depth] = CB_COMPILE_STATUS_NONE; + compile_directive_depth--; + } else if (strcasecmp (sbuff[0], "$SET") == 0) { + if (strcasecmp (sbuff[1], "SOURCEFORMAT(FREE)") == 0) { + cb_source_format = CB_FORMAT_FREE; + return; + } else if (strcasecmp (sbuff[1], "SOURCEFORMAT(FIXED)") == 0) { + cb_source_format = CB_FORMAT_FIXED; + return; + } else if (strcasecmp (sbuff[1], "SOURCEFORMAT(FREE_1COL_ASTER)") == 0) { + cb_source_format = CB_FORMAT_FREE_1COL_ASTER; + cb_source_format1 = 1; + return; + } else if (strcasecmp (sbuff[1], "SOURCEFORMAT(VARIABLE)") == 0){ + cb_source_format = CB_FORMAT_VARIABLE; + } else { + cb_compile_status = CB_COMPILE_STATUS_ERROR; + cb_error (_("Invalid $SET")); + return; + } + } else { + cb_compile_status = CB_COMPILE_STATUS_ERROR; + cb_error (_("Invalid $ statements")); + return; + } + + if (compile_directive_depth > -1) { + for (i = 0; i <= compile_directive_depth; i++) { + if (cb_compile_status_list[i] != CB_COMPILE_STATUS_TRUE && + cb_compile_status_list[i] != CB_COMPILE_STATUS_TRUE_ELSE) { + cb_compile_status = CB_COMPILE_STATUS_FALSE; + return; + } + } + } + if (*buff == '\n') { + cb_compile_status = CB_COMPILE_STATUS_FALSE_END; + } else { + cb_compile_status = CB_COMPILE_STATUS_TRUE; + } } /* * Read line */ -static int ppinput(char *buff, int max_size) { +static int +ppinput (char *buff, int max_size) +{ - char *bp; - size_t gotcr; - size_t continuation = 0; - int ipchar; - int i; - int n; - int coln; - char *str1 = NULL; - char *str2 = NULL; - int comment_counter = 0; + char *bp; + size_t gotcr; + size_t continuation = 0; + int ipchar; + int i; + int n; + int coln; + int buff_len = 0; + char *str1 = NULL; + char *str2 = NULL; + int comment_counter = 0; start: - /* read a line */ - gotcr = 0; - ipchar = 0; - for (n = 0; n < 256 && ipchar != '\n';) { - ipchar = getc(ppin); - if (ipchar == EOF) { - if (n > 0) { - break; - } - if (newline_count == 0) { - return 0; - } - memset(buff, '\n', newline_count); - buff[newline_count] = 0; - newline_count = 0; - return strlen(buff); - } - if (n == 0 && cb_source_format != CB_FORMAT_FIXED && - cb_source_format1 != 1) { - if (ipchar != ' ' && ipchar != '\n') { - buff[n++] = ' '; - } - } - if (gotcr) { - if (ipchar != '\n') { - buff[n++] = '\r'; - } - gotcr = 0; - } - if (ipchar == '\r') { - gotcr = 1; - } else if (ipchar == '\t') { - buff[n++] = ' '; - while (n % cb_tab_width != 0) { - buff[n++] = ' '; - } - } else { - buff[n++] = ipchar; - } - } - - if (buff[n - 1] != '\n') { - cb_warning(_("Line not terminated by a newline")); - buff[n++] = '\n'; - } - buff[n] = 0; - if (cb_source_format1 == 1 && buff[0] == '*' && buff[1] != '>') { - strcpy(buff, "\n"); - return strlen(buff); - } - str1 = strstr(buff, "*>"); - if (str1 != NULL) { - if ((str1 - buff) >= 7) { - str2 = strstr(str1, "\""); - if (str2 == NULL) { - buff[str1 - buff] = '\n'; - buff[str1 - buff + 1] = '\0'; - n = strlen(buff); - } - } - } - check_directive(buff, &n); - check_dollar_directive(buff, &n); - if (cb_compile_status == CB_COMPILE_STATUS_ERROR) { - return YY_NULL; - } - if (cb_compile_status == CB_COMPILE_STATUS_FALSE) { - newline_count++; - comment_counter++; - goto start; - } - if (cb_compile_status == CB_COMPILE_STATUS_FALSE_END) { - cb_compile_status = CB_COMPILE_STATUS_NONE; - newline_count++; - comment_counter++; - goto start; - } - - /* nothing more to do with free format */ - if (cb_source_format != CB_FORMAT_FIXED) { - return n; - } - - /* line too short */ - if (n < 8) { - newline_count++; - comment_counter++; - goto start; - } - - if (cb_flag_mfcomment) { - if (buff[0] == '*' || buff[0] == '/') { - /*if(!cb_flag_no_cobol_comment) { - register_comment(0, buff, comment_counter++); - }*/ - newline_count++; - goto start; - } - } - /* check the indicator (column 7) */ - bp = buff + 7; - switch (buff[6]) { - case ' ': - break; - case '-': - continuation = 1; - break; - case 'd': - case 'D': - /* debugging line */ - if (cb_flag_debugging_line) { - break; - } - newline_count++; - comment_counter++; - goto start; - case '*': - case '/': - /* comment line */ - /*if(!cb_flag_no_cobol_comment) { - register_comment(6, buff, comment_counter++); - }*/ - newline_count++; - goto start; - default: - /* invalid indicator */ - cb_error(_("Invalid indicator '%c' at column 7"), buff[6]); - return YY_NULL; - } - - /* skip comments that follow after AUTHORS, etc. */ - if (within_comment) { - /* Check all of "Area A" */ - switch (n) { - case 8: - if (buff[7] == ' ') { - newline_count++; - comment_counter++; - goto start; - } - break; - case 9: - if (!memcmp(&buff[7], " ", 2)) { - newline_count++; - comment_counter++; - goto start; - } - break; - case 10: - if (!memcmp(&buff[7], " ", 3)) { - newline_count++; - comment_counter++; - goto start; - } - break; - default: - if (!memcmp(&buff[7], " ", 4)) { - newline_count++; - comment_counter++; - goto start; - } - break; - } - within_comment = 0; - } - - /* check the text that is longer than cb_text_column */ - if (n > cb_text_column + 1) { - - /* show warning if it is not whitespaces */ - if (cb_warn_column_overflow && last_line_2 < cb_source_line - 1) { - for (coln = cb_text_column; coln < n; coln++) { - if (buff[coln] != ' ' && buff[coln] != '\n') { - cb_warning(_("Source text after column %d"), cb_text_column); - break; - } - } - } - - /* remove it */ - strcpy(buff + cb_text_column, "\n"); - last_line_2 = cb_source_line; - n = cb_text_column + 1; - } - - /* skip blank lines */ - for (i = 7; buff[i] == ' '; i++) - ; - if (buff[i] == '\n') { - newline_count++; - comment_counter++; - goto start; - } + /* read a line */ + gotcr = 0; + ipchar = 0; + for (n = 0; n < 256 && ipchar != '\n';) { + ipchar = getc (ppin); + if (ipchar == EOF) { + if (n > 0) { + break; + } + if (newline_count == 0) { + return 0; + } + memset (buff, '\n', newline_count); + buff[newline_count] = 0; + newline_count = 0; + return strlen (buff); + } + if (n == 0 && cb_source_format != CB_FORMAT_FIXED && cb_source_format1 != 1 + && cb_source_format != CB_FORMAT_VARIABLE) { + if (ipchar != ' ' && ipchar != '\n') { + buff[n++] = ' '; + } + } + if (gotcr) { + if (ipchar != '\n') { + buff[n++] = '\r'; + } + gotcr = 0; + } + if (ipchar == '\r') { + gotcr = 1; + } else if (ipchar == '\t') { + buff[n++] = ' '; + while (n % cb_tab_width != 0) { + buff[n++] = ' '; + } + } else { + buff[n++] = ipchar; + } + } + + if (buff[n - 1] != '\n') { + cb_warning (_("Line not terminated by a newline")); + buff[n++] = '\n'; + } + buff[n] = 0; + if (cb_source_format1 == 1 && buff[0] == '*' && buff[1] != '>') { + strcpy (buff, "\n"); + return strlen (buff); + } + str1 = strstr (buff, "*>"); + if (str1 != NULL) { + if ((str1-buff) >= 7) { + str2 = strstr (str1, "\""); + if (str2 == NULL) { + buff[str1-buff] = '\n'; + buff[str1-buff +1] = '\0'; + n = strlen (buff); + } + } + } + check_directive (buff, &n); + check_dollar_directive (buff, &n); + if (cb_compile_status == CB_COMPILE_STATUS_ERROR) { + return YY_NULL; + } + if (cb_compile_status == CB_COMPILE_STATUS_FALSE) { + newline_count++; + comment_counter++; + goto start; + } + if (cb_compile_status == CB_COMPILE_STATUS_FALSE_END) { + cb_compile_status = CB_COMPILE_STATUS_NONE; + newline_count++; + comment_counter++; + goto start; + } + + /* nothing more to do with free format */ + if (cb_source_format != CB_FORMAT_FIXED && cb_source_format != CB_FORMAT_VARIABLE) { + return n; + } + + /* line too short */ + if (n < 8) { + newline_count++; + comment_counter++; + goto start; + } + + if (cb_flag_mfcomment) { + if (buff[0] == '*' || buff[0] == '/') { + /*if(!cb_flag_no_cobol_comment) { + register_comment(0, buff, comment_counter++); + }*/ + newline_count++; + goto start; + } + } + /* check the indicator (column 7) */ + bp = buff + 7; + switch (buff[6]) { + case ' ': + break; + case '-': + continuation = 1; + break; + case 'd': + case 'D': + /* debugging line */ + if (cb_flag_debugging_line) { + break; + } + newline_count++; + comment_counter++; + goto start; + case '*': + case '/': + /* comment line */ + /*if(!cb_flag_no_cobol_comment) { + register_comment(6, buff, comment_counter++); + }*/ + newline_count++; + goto start; + default: + /* invalid indicator */ + cb_error (_("Invalid indicator '%c' at column 7"), buff[6]); + return YY_NULL; + } + + /* skip comments that follow after AUTHORS, etc. */ + if (within_comment) { + /* Check all of "Area A" */ + switch (n) { + case 8: + if (buff[7] == ' ') { + newline_count++; + comment_counter++; + goto start; + } + break; + case 9: + if (!memcmp (&buff[7], " ", 2)) { + newline_count++; + comment_counter++; + goto start; + } + break; + case 10: + if (!memcmp (&buff[7], " ", 3)) { + newline_count++; + comment_counter++; + goto start; + } + break; + default: + if (!memcmp (&buff[7], " ", 4)) { + newline_count++; + comment_counter++; + goto start; + } + break; + } + within_comment = 0; + } - if (continuation) { - /* line continuation */ - for (; *bp == ' '; bp++) - ; - - /* validate concatenation */ - if (consecutive_quotation) { - if (bp[0] == quotation_mark && bp[1] == quotation_mark) { - bp++; - } else { - cb_error(_("Invalid line continuation")); - return YY_NULL; - } - quotation_mark = 0; - consecutive_quotation = 0; - } else if (quotation_mark) { - /* literal concatenation */ - if (*bp == quotation_mark) { - bp++; - } else { - cb_error(_("Invalid line continuation")); - return YY_NULL; - } - } - } else { - /* normal line */ - quotation_mark = 0; - consecutive_quotation = 0; - } - - /* check if string literal is to be continued */ - for (i = bp - buff; buff[i] != '\n'; i++) { - if (buff[i] == '\'' || buff[i] == '\"') { - if (quotation_mark == 0) { - /* literal start */ - quotation_mark = buff[i]; - } else if (quotation_mark == buff[i]) { - if (i == cb_text_column - 1) { - /* consecutive quotation */ - consecutive_quotation = 1; - } else { - /* literal end */ - quotation_mark = 0; - } - } - } - } - - /* truncate trailing spaces, including the newline */ - if (quotation_mark) { - for (; i < 72;) { - buff[i++] = ' '; - } - buff[i] = 0; - } else { - for (i--; buff[i] == ' '; i--) - ; - if (buff[i] == '\'' || buff[i] == '\"') { - buff[++i] = ' '; - } - buff[i + 1] = 0; - } - - if (continuation) { - memmove(buff, bp, strlen(bp) + 1); - newline_count++; - comment_counter++; - } else { - /* insert newlines at the start of the buffer */ - memmove(buff + newline_count, bp, strlen(bp) + 1); - memset(buff, '\n', newline_count); - newline_count = 1; - } +#ifdef I18N_UTF8 + unsigned char *p = (unsigned char *)buff; + if(utf8_ext_pick(p)){ + buff_len = (int) utf8_calc_sjis_size(p, strlen(buff)); + }else{ + buff_len = n; + } +#else /*!I18N_UTF8*/ + buff_len = n; +#endif /*I18N_UTF8*/ - return strlen(buff); + /* check the text that is longer than cb_text_column */ + if (buff_len > cb_text_column + 1 && cb_source_format != CB_FORMAT_VARIABLE) { + + /* show warning if it is not whitespaces */ + if (cb_warn_column_overflow && last_line_2 < cb_source_line - 1) { + for (coln = cb_text_column; coln < n; coln++) { + if (buff[coln] != ' ' && buff[coln] != '\n') { + cb_warning (_("Source text after column %d"), + cb_text_column); + break; + } + } + } + + /* remove it */ +#ifdef I18N_UTF8 + p = (unsigned char *) buff; + strcpy (buff + utf8_calc_sjis_column(p, cb_text_column), "\n"); +#else /*!I18N_UTF8*/ + strcpy (buff + cb_text_column, "\n"); +#endif /*I18N_UTF8*/ + last_line_2 = cb_source_line; + n = cb_text_column + 1; + } + + /* skip blank lines */ + for (i = 7; buff[i] == ' '; i++) ; + if (buff[i] == '\n') { + newline_count++; + comment_counter++; + goto start; + } + + if (continuation) { + /* line continuation */ + for (; *bp == ' '; bp++) ; + + /* validate concatenation */ + if (consecutive_quotation) { + if (bp[0] == quotation_mark && bp[1] == quotation_mark) { + bp++; + } else { + cb_error (_("Invalid line continuation")); + return YY_NULL; + } + quotation_mark = 0; + consecutive_quotation = 0; + } else if (quotation_mark) { + /* literal concatenation */ + if (*bp == quotation_mark) { + bp++; + } else { + cb_error (_("Invalid line continuation")); + return YY_NULL; + } + } + } else { + /* normal line */ + quotation_mark = 0; + consecutive_quotation = 0; + } + + /* check if string literal is to be continued */ + for (i = bp - buff; buff[i] != '\n'; i++) { + if (buff[i] == '\'' || buff[i] == '\"') { + if (quotation_mark == 0) { + /* literal start */ + quotation_mark = buff[i]; + } else if (quotation_mark == buff[i]) { + if (i == cb_text_column - 1) { + /* consecutive quotation */ + consecutive_quotation = 1; + } else { + /* literal end */ + quotation_mark = 0; + } + } + } + } + + /* truncate trailing spaces, including the newline */ + if (quotation_mark) { + for (; i < 72;) { + buff[i++] = ' '; + } + buff[i] = 0; + } else { + for (i--; buff[i] == ' '; i--) ; + if (buff[i] == '\'' || buff[i] == '\"') { + buff[++i] = ' '; + } + buff[i + 1] = 0; + } + + if (continuation) { + memmove (buff, bp, strlen (bp) + 1); + newline_count++; + comment_counter++; + } else { + /* insert newlines at the start of the buffer */ + memmove (buff + newline_count, bp, strlen (bp) + 1); + memset (buff, '\n', newline_count); + newline_count = 1; + } + + return strlen (buff); } -static void ppecho_0(const char *text, struct cb_text_list **pqueue, - struct cb_replace_list **preplace, - void(ppecho_proc)(const char *)) { - - struct cb_replace_list *r; - struct cb_text_list *l; - struct cb_text_list *queue; - - if (suppress_echo) { - /* generate no output */ - } else if (*pqueue == NULL && (text[0] == ' ' || text[0] == '\n')) { - ppecho_proc(text); - } else if (!*preplace) { - for (; *pqueue; *pqueue = (*pqueue)->next) { - ppecho_proc((*pqueue)->text); - } - ppecho_proc(text); - } else { - /* Do replacement */ - - *pqueue = cb_text_list_add(*pqueue, text); - - while (*pqueue) { - for (r = *preplace; r; r = r->next) { - queue = *pqueue; - for (l = r->old_text; l; l = l->next) { - while (l && (l->text[0] == ' ' || l->text[0] == '\n')) { - l = l->next; - } - if (l == NULL) { - break; - } - while (queue && (queue->text[0] == ' ' || queue->text[0] == '\n')) { - queue = queue->next; - } - if (queue == NULL) { - return; /* partial match */ - } - if (r->replace_type == CB_REPLACE_LEADING) { - break; - } else if (r->replace_type == CB_REPLACE_TRAILING) { - break; - } else if (r->replace_type == CB_REPLACE_OTHER) { - if (strcasecmp(l->text, queue->text) != 0) { - break; - } - } - queue = queue->next; - } - if (r->replace_type == CB_REPLACE_LEADING) { - if (!l || !queue) { - continue; - } - if (strncasecmp(l->text, queue->text, strlen(l->text)) == 0) { - break; - } - } else if (r->replace_type == CB_REPLACE_TRAILING) { - if (!l || !queue || strlen(queue->text) < strlen(r->old_text->text)) { - continue; - } - if (strcasecmp(queue->text + strlen(queue->text) - - strlen(r->old_text->text), - r->old_text->text) == 0) { - break; - } - } else if (l == NULL) { - /* match */ - break; - } - } - - /* match */ - if (r && r->replace_type == CB_REPLACE_LEADING) { - int oldlen = strlen(l->text); - for (l = *pqueue; l != queue; l = l->next) { - ppecho_proc(l->text); - } - l = r->new_text; - while (l && (l->text[0] == ' ' || l->text[0] == '\n')) { - l = l->next; - } - if (l) { - ppecho_proc(l->text); - } - ppecho_proc(queue->text + oldlen); - queue = queue->next; - } else if (r && r->replace_type == CB_REPLACE_TRAILING) { - int i; - int oldlen = strlen(l->text); - for (l = *pqueue; l != queue; l = l->next) { - ppecho_proc(l->text); - } - for (i = 0; i < strlen(queue->text) - oldlen; i++) { - fputc(queue->text[i], ppout); - } - l = r->new_text; - while (l && (l->text[0] == ' ' || l->text[0] == '\n')) { - l = l->next; - } - if (l) { - ppecho_proc(l->text); - } - queue = queue->next; - } else if (r && l == NULL) { - for (l = r->new_text; l; l = l->next) { - ppecho_proc(l->text); - } - } else { - /* no match */ - if (!*pqueue) { - break; - } - ppecho_proc((*pqueue)->text); - queue = (*pqueue)->next; - } - - while (*pqueue != queue) { - if (!*pqueue) - break; - - l = (*pqueue)->next; - free(*pqueue); - *pqueue = l; - } - } - } +static void +ppecho_0 (const char *text, + struct cb_text_list **pqueue, + struct cb_replace_list **preplace, + void (ppecho_proc)(const char *)) { + + struct cb_replace_list *r; + struct cb_text_list *l; + struct cb_text_list *queue; + + if (suppress_echo) { + /* generate no output */ + } else if (*pqueue == NULL && (text[0] == ' ' || text[0] == '\n')) { + ppecho_proc (text); + } else if (!*preplace) { + for (; *pqueue; *pqueue = (*pqueue)->next) { + ppecho_proc ((*pqueue)->text); + } + ppecho_proc (text); + } else { + /* Do replacement */ + + *pqueue = cb_text_list_add (*pqueue, text); + + while (*pqueue) { + for (r = *preplace; r; r = r->next) { + queue = *pqueue; + for (l = r->old_text; l; l = l->next) { + while (l && (l->text[0] == ' ' || l->text[0] == '\n')) { + l = l->next; + } + if (l == NULL) { + break; + } + while (queue && (queue->text[0] == ' ' || + queue->text[0] == '\n')) { + queue = queue->next; + } + if (queue == NULL) { + return; /* partial match */ + } + if (r->replace_type == CB_REPLACE_LEADING) { + break; + } else if (r->replace_type == CB_REPLACE_TRAILING) { + break; + } else if (r->replace_type == CB_REPLACE_OTHER) { + if (strcasecmp (l->text, queue->text) != 0) { + break; + } + } + queue = queue->next; + } + if (r->replace_type == CB_REPLACE_LEADING) { + if (!l || !queue) { + continue; + } + if (strncasecmp (l->text, queue->text, strlen (l->text)) == 0) { + break; + } + } else if (r->replace_type == CB_REPLACE_TRAILING) { + if (!l || !queue || strlen (queue->text) < strlen (r->old_text->text)) { + continue; + } + if (strcasecmp (queue->text + strlen (queue->text) - strlen (r->old_text->text), r->old_text->text) == 0) { + break; + } + } else if (l == NULL) { + /* match */ + break; + } + } + + /* match */ + if (r && r->replace_type == CB_REPLACE_LEADING) { + int oldlen = strlen (l->text); + for (l = *pqueue; l != queue; l = l->next) { + ppecho_proc (l->text); + } + l = r->new_text; + while (l && (l->text[0] == ' ' || l->text[0] == '\n')) { + l = l->next; + } + if (l) { + ppecho_proc (l->text); + } + ppecho_proc (queue->text + oldlen); + queue = queue->next; + } else if (r && r->replace_type == CB_REPLACE_TRAILING) { + int i; + int oldlen = strlen (l->text); + for (l = *pqueue; l != queue; l = l->next) { + ppecho_proc (l->text); + } + for (i = 0; i < strlen (queue->text) - oldlen; i++) { + fputc (queue->text[i], ppout); + } + l = r->new_text; + while (l && (l->text[0] == ' ' || l->text[0] == '\n')) { + l = l->next; + } + if (l) { + ppecho_proc (l->text); + } + queue = queue->next; + } else if (r && l == NULL) { + for (l = r->new_text; l; l = l->next) { + ppecho_proc (l->text); + } + } else { + /* no match */ + if (!*pqueue) { + break; + } + ppecho_proc ((*pqueue)->text); + queue = (*pqueue)->next; + } + + while (*pqueue != queue) { + if (!*pqueue) break; + + l = (*pqueue)->next; + free (*pqueue); + *pqueue = l; + } + } + } } -static void ppecho_final(const char *text) { fputs(text, ppout); } - -static void ppecho_2(const char *text) { - /* process REPLACE */ - ppecho_0(text, &text_queue2, ¤t_replace_list, ppecho_final); +static void +ppecho_final (const char *text) +{ + fputs (text, ppout); } -static void ppecho_1(const char *text) { - /* process COPY REPLACING */ - ppecho_0(text, &text_queue1, ¤t_copy_replace_list, ppecho_2); +static void +ppecho_2 (const char *text) +{ + /* process REPLACE */ + ppecho_0 (text, &text_queue2, ¤t_replace_list, ppecho_final); } -static void ppecho(const char *text) { ppecho_1(text); } +static void +ppecho_1 (const char *text) +{ + /* process COPY REPLACING */ + ppecho_0 (text, &text_queue1, ¤t_copy_replace_list, ppecho_2); +} -void pp_set_current_division(int divno) { current_division = divno; } +static void +ppecho (const char *text) +{ + ppecho_1 (text); +} -void pp_omit_data_entry_name(int on_off) { omit_data_entry_name = on_off; } +void pp_set_current_division (int divno) +{ + current_division = divno; +} -void pp_omit_data_redef_name(int on_off) { omit_data_redef_name = on_off; } +void pp_omit_data_entry_name (int on_off) +{ + omit_data_entry_name = on_off; +} -void register_comment(int comment_mark_index, char *buffer, int delta) { - struct comment_info *p = malloc(sizeof(struct comment_info)); - p->file = cb_source_file; - p->line = cb_source_line + delta + 1; +void pp_omit_data_redef_name (int on_off) +{ + omit_data_redef_name = on_off; +} - // Remove the unnecessary part of the comment - int str_len_original_line = strlen(buffer); - int comment_end_index; - if (buffer[str_len_original_line - 1] == '\n') { - if (str_len_original_line >= 2 && - buffer[str_len_original_line - 1] == '\r') { - comment_end_index = str_len_original_line - 2; - } else { - comment_end_index = str_len_original_line - 1; - } - } else { - comment_end_index = str_len_original_line; - } - int comment_len = comment_end_index - comment_mark_index - 1; - p->comment = malloc(comment_len + 1); - memcpy(p->comment, buffer + comment_mark_index + 1, comment_len); - p->comment[comment_len] = '\0'; - - p->prev = comment_info_list_last; - p->next = NULL; - p->is_base_cobol_file = copy_stack->next == NULL; - p->position_in_source_code = position_in_source_code; - if (comment_info_list_last != NULL) { - comment_info_list_last->next = p; - } - comment_info_list_last = p; - if (comment_info_list_head == NULL) { - comment_info_list_head = p; - } +void register_comment(int comment_mark_index, char* buffer, int delta) { + struct comment_info* p = malloc(sizeof(struct comment_info)); + p->file = cb_source_file; + p->line = cb_source_line + delta + 1; + + // Remove the unnecessary part of the comment + int str_len_original_line = strlen(buffer); + int comment_end_index; + if(buffer[str_len_original_line - 1] == '\n') { + if(str_len_original_line >= 2 && buffer[str_len_original_line - 1] == '\r') { + comment_end_index = str_len_original_line - 2; + } else { + comment_end_index = str_len_original_line - 1; + } + } else { + comment_end_index = str_len_original_line; + } + int comment_len = comment_end_index - comment_mark_index - 1; + p->comment = malloc(comment_len + 1); + memcpy(p->comment, buffer + comment_mark_index + 1, comment_len); + p->comment[comment_len] = '\0'; + + p->prev = comment_info_list_last; + p->next = NULL; + p->is_base_cobol_file = copy_stack->next == NULL; + p->position_in_source_code = position_in_source_code; + if(comment_info_list_last != NULL) { + comment_info_list_last->next = p; + } + comment_info_list_last = p; + if(comment_info_list_head == NULL) { + comment_info_list_head = p; + } } diff --git a/cobj/pplex.l b/cobj/pplex.l index 5d80e3f7..57aef810 100644 --- a/cobj/pplex.l +++ b/cobj/pplex.l @@ -453,8 +453,16 @@ convert_ucs_hyphen_minus (char *namebuf) { char *p = namebuf; while (NULL != (p = strstr (p, UTF8_MINUS_SIGN))) { - memcpy (p, UTF8_FULLWIDTH_HYPHEN_MINUS, 3); - p += 3; + *p = '_'; + memmove(p+1, p+3, strlen(p+3)+1); + p++; + } + + p = namebuf; + while (NULL != (p = strstr (p, UTF8_FULLWIDTH_HYPHEN_MINUS))) { + *p = '_'; + memmove(p+1, p+3, strlen(p+3)+1); + p++; } return; } @@ -722,6 +730,9 @@ check_directive (char *buff, int *line_size) cb_source_format1 = 1; return; } + if (!strcasecmp (sbuff[2], "VARIABLE")){ + cb_source_format = CB_FORMAT_VARIABLE; + } break; default: if (strcasecmp (sbuff[1], "FORMAT")) { @@ -743,6 +754,9 @@ check_directive (char *buff, int *line_size) cb_source_format1 = 1; return; } + if (!strcasecmp (sbuff[3], "VARIABLE")){ + cb_source_format = CB_FORMAT_VARIABLE; + } break; } cb_warning (_("Invalid directive - ignored")); @@ -908,6 +922,8 @@ check_dollar_directive (char *buff, int *line_size) cb_source_format = CB_FORMAT_FREE_1COL_ASTER; cb_source_format1 = 1; return; + } else if (strcasecmp (sbuff[1], "SOURCEFORMAT(VARIABLE)") == 0){ + cb_source_format = CB_FORMAT_VARIABLE; } else { cb_compile_status = CB_COMPILE_STATUS_ERROR; cb_error (_("Invalid $SET")); @@ -950,6 +966,7 @@ ppinput (char *buff, int max_size) int i; int n; int coln; + int buff_len = 0; char *str1 = NULL; char *str2 = NULL; int comment_counter = 0; @@ -972,7 +989,8 @@ start: newline_count = 0; return strlen (buff); } - if (n == 0 && cb_source_format != CB_FORMAT_FIXED && cb_source_format1 != 1) { + if (n == 0 && cb_source_format != CB_FORMAT_FIXED && cb_source_format1 != 1 + && cb_source_format != CB_FORMAT_VARIABLE) { if (ipchar != ' ' && ipchar != '\n') { buff[n++] = ' '; } @@ -1033,7 +1051,7 @@ start: } /* nothing more to do with free format */ - if (cb_source_format != CB_FORMAT_FIXED) { + if (cb_source_format != CB_FORMAT_FIXED && cb_source_format != CB_FORMAT_VARIABLE) { return n; } @@ -1120,8 +1138,19 @@ start: within_comment = 0; } +#ifdef I18N_UTF8 + unsigned char *p = (unsigned char *)buff; + if(utf8_ext_pick(p)){ + buff_len = (int) utf8_calc_sjis_size(p, strlen(buff)); + }else{ + buff_len = n; + } +#else /*!I18N_UTF8*/ + buff_len = n; +#endif /*I18N_UTF8*/ + /* check the text that is longer than cb_text_column */ - if (n > cb_text_column + 1) { + if (buff_len > cb_text_column + 1 && cb_source_format != CB_FORMAT_VARIABLE) { /* show warning if it is not whitespaces */ if (cb_warn_column_overflow && last_line_2 < cb_source_line - 1) { @@ -1135,7 +1164,12 @@ start: } /* remove it */ +#ifdef I18N_UTF8 + p = (unsigned char *) buff; + strcpy (buff + utf8_calc_sjis_column(p, cb_text_column), "\n"); +#else /*!I18N_UTF8*/ strcpy (buff + cb_text_column, "\n"); +#endif /*I18N_UTF8*/ last_line_2 = cb_source_line; n = cb_text_column + 1; } diff --git a/cobj/pplex.l.m4 b/cobj/pplex.l.m4 index 8a5d4a60..dbdc4cd7 100644 --- a/cobj/pplex.l.m4 +++ b/cobj/pplex.l.m4 @@ -468,8 +468,16 @@ convert_ucs_hyphen_minus (char *namebuf) { char *p = namebuf; while (NULL != (p = strstr (p, UTF8_MINUS_SIGN))) { - memcpy (p, UTF8_FULLWIDTH_HYPHEN_MINUS, 3); - p += 3; + *p = '_'; + memmove(p+1, p+3, strlen(p+3)+1); + p++; + } + + p = namebuf; + while (NULL != (p = strstr (p, UTF8_FULLWIDTH_HYPHEN_MINUS))) { + *p = '_'; + memmove(p+1, p+3, strlen(p+3)+1); + p++; } return; } @@ -737,6 +745,9 @@ check_directive (char *buff, int *line_size) cb_source_format1 = 1; return; } + if (!strcasecmp (sbuff[2], "VARIABLE")){ + cb_source_format = CB_FORMAT_VARIABLE; + } break; default: if (strcasecmp (sbuff[1], "FORMAT")) { @@ -758,6 +769,9 @@ check_directive (char *buff, int *line_size) cb_source_format1 = 1; return; } + if (!strcasecmp (sbuff[3], "VARIABLE")){ + cb_source_format = CB_FORMAT_VARIABLE; + } break; } cb_warning (_("Invalid directive - ignored")); @@ -923,6 +937,8 @@ check_dollar_directive (char *buff, int *line_size) cb_source_format = CB_FORMAT_FREE_1COL_ASTER; cb_source_format1 = 1; return; + } else if (strcasecmp (sbuff[1], "SOURCEFORMAT(VARIABLE)") == 0){ + cb_source_format = CB_FORMAT_VARIABLE; } else { cb_compile_status = CB_COMPILE_STATUS_ERROR; cb_error (_("Invalid $SET")); @@ -965,6 +981,7 @@ ppinput (char *buff, int max_size) int i; int n; int coln; + int buff_len = 0; char *str1 = NULL; char *str2 = NULL; int comment_counter = 0; @@ -987,7 +1004,8 @@ start: newline_count = 0; return strlen (buff); } - if (n == 0 && cb_source_format != CB_FORMAT_FIXED && cb_source_format1 != 1) { + if (n == 0 && cb_source_format != CB_FORMAT_FIXED && cb_source_format1 != 1 + && cb_source_format != CB_FORMAT_VARIABLE) { if (ipchar != ' ' && ipchar != '\n') { buff[n++] = ' '; } @@ -1048,7 +1066,7 @@ start: } /* nothing more to do with free format */ - if (cb_source_format != CB_FORMAT_FIXED) { + if (cb_source_format != CB_FORMAT_FIXED && cb_source_format != CB_FORMAT_VARIABLE) { return n; } @@ -1135,8 +1153,19 @@ start: within_comment = 0; } +#ifdef I18N_UTF8 + unsigned char *p = (unsigned char *)buff; + if(utf8_ext_pick(p)){ + buff_len = (int) utf8_calc_sjis_size(p, strlen(buff)); + }else{ + buff_len = n; + } +#else /*!I18N_UTF8*/ + buff_len = n; +#endif /*I18N_UTF8*/ + /* check the text that is longer than cb_text_column */ - if (n > cb_text_column + 1) { + if (buff_len > cb_text_column + 1 && cb_source_format != CB_FORMAT_VARIABLE) { /* show warning if it is not whitespaces */ if (cb_warn_column_overflow && last_line_2 < cb_source_line - 1) { @@ -1150,7 +1179,12 @@ start: } /* remove it */ +#ifdef I18N_UTF8 + p = (unsigned char *) buff; + strcpy (buff + utf8_calc_sjis_column(p, cb_text_column), "\n"); +#else /*!I18N_UTF8*/ strcpy (buff + cb_text_column, "\n"); +#endif /*I18N_UTF8*/ last_line_2 = cb_source_line; n = cb_text_column + 1; } diff --git a/cobj/ppparse.c b/cobj/ppparse.c index 1ae5a9c2..5b7832e7 100644 --- a/cobj/ppparse.c +++ b/cobj/ppparse.c @@ -436,7 +436,7 @@ void *malloc(YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ #ifndef YYFREE #define YYFREE free #if !defined free && !defined EXIT_SUCCESS -void free(void *); /* INFRINGES ON USER NAME SPACE */ +void free(void *); /* INFRINGES ON USER NAME SPACE */ #endif #endif #endif diff --git a/cobj/scanner.c b/cobj/scanner.c index b3f0cd5f..fa122cb5 100644 --- a/cobj/scanner.c +++ b/cobj/scanner.c @@ -1,6 +1,6 @@ -#line 2 "scanner.c" +#line 1 "scanner.c" -#line 4 "scanner.c" +#line 3 "scanner.c" #define YY_INT_ALIGNED short int @@ -1276,9 +1276,9 @@ static int scan_numeric (char *text); static int scan_picture (char *text); static void count_lines (char *text); -#line 1280 "scanner.c" +#line 1279 "scanner.c" -#line 1282 "scanner.c" +#line 1281 "scanner.c" #define INITIAL 0 #define DECIMAL_IS_PERIOD 1 @@ -1522,7 +1522,7 @@ YY_DECL -#line 1526 "scanner.c" +#line 1525 "scanner.c" while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ { @@ -2596,7 +2596,7 @@ YY_RULE_SETUP #line 791 "scanner.l" YY_FATAL_ERROR( "flex scanner jammed" ); YY_BREAK -#line 2600 "scanner.c" +#line 2599 "scanner.c" case YY_END_OF_BUFFER: { diff --git a/cobj/scanner.l.m4 b/cobj/scanner.l.m4 index 4384bfb4..377f0f52 100644 --- a/cobj/scanner.l.m4 +++ b/cobj/scanner.l.m4 @@ -815,6 +815,12 @@ read_literal (int mark, enum cb_category category) } while ((c = input ()) != EOF) { +#if EOF != 0 + if (unlikely (c == 0)){ + cb_error(_("The literal is not properly closed by %c."), mark); + break; + } +#endif plexbuff[i++] = c; if (c == mark && (c = input ()) != mark) { i--; diff --git a/cobj/system.def b/cobj/system.def index fc6c1646..298c9e1c 100644 --- a/cobj/system.def +++ b/cobj/system.def @@ -61,7 +61,7 @@ COB_SYSTEM_GEN ("C$JUSTIFY", 1, cob_acuw_justify) COB_SYSTEM_GEN ("C$CALLEDBY", 1, calledBy) COB_SYSTEM_GEN ("C$MAKEDIR", 1, cob_acuw_mkdir) COB_SYSTEM_GEN ("C$NARG", 1, cob_return_args) -COB_SYSTEM_GEN ("C$SLEEP", 1, cob_acuw_sleep) +COB_SYSTEM_GEN ("C$SLEEP", 1, C$SLEEP) 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) diff --git a/cobj/tree.c b/cobj/tree.c index a7298644..d0462bb3 100644 --- a/cobj/tree.c +++ b/cobj/tree.c @@ -92,6 +92,7 @@ cb_tree cb_true; cb_tree cb_false; cb_tree cb_null; cb_tree cb_zero; +cb_tree cb_zen_zero; cb_tree cb_one; cb_tree cb_space; cb_tree cb_blank; @@ -124,8 +125,13 @@ static char *to_cname(const char *s) { unsigned char *p; copy = strdup(s); - for (p = (unsigned char *)copy; *p; p++) { - *p = (*p == '-') ? '_' : (unsigned char)toupper(*p); + for (p = (unsigned char *)copy; *p;) { + if ((0x81 <= *p && *p <= 0x9F) || (0xE0 <= *p && *p <= 0xFC)) { + p += 2; + } else { + *p = (*p == '-') ? '_' : (unsigned char)toupper(*p); + p++; + } } return copy; } @@ -449,6 +455,31 @@ struct cb_literal *build_literal(enum cb_category category, return p; } +struct cb_literal *build_concat_literal(enum cb_category category, + const unsigned char *data, size_t size1, + size_t size2, size_t *sgmt_sizes, + size_t sgmt_count) { + struct cb_literal *p; + size_t size = size1 + size2; + p = make_tree(CB_TAG_LITERAL, category, sizeof(struct cb_literal)); + p->data = cobc_malloc((size_t)(size + 1)); + p->size = size; + memcpy(p->data, data, (size_t)size); + + // set segment sizes + if (!sgmt_sizes) { + p->segment_sizes = cobc_malloc(sizeof(size_t) * 2); + p->segment_sizes[0] = size1; + } else { + p->segment_sizes = cobc_malloc(sizeof(size_t) * (sgmt_count + 1)); + memcpy(p->segment_sizes, sgmt_sizes, sizeof(size_t) * sgmt_count); + } + p->segment_sizes[sgmt_count] = size2; + p->segment_count = sgmt_count + 1; + + return p; +} + char *cb_name(cb_tree x) { if (!treenamebuff) { treenamebuff = cobc_malloc(COB_NORMAL_BUFF); @@ -759,6 +790,7 @@ void cb_init_constants(void) { cb_false = make_constant(CB_CATEGORY_BOOLEAN, "0"); cb_null = make_constant(CB_CATEGORY_DATA_POINTER, "0"); cb_zero = make_constant(CB_CATEGORY_NUMERIC, "CobolConstant.zero"); + cb_zen_zero = make_constant(CB_CATEGORY_NUMERIC, "CobolConstant.zenZero"); cb_one = make_constant(CB_CATEGORY_NUMERIC, "CobolConstant.One"); cb_space = make_constant(CB_CATEGORY_ALPHANUMERIC, "CobolConstant.space"); cb_blank = make_constant(CB_CATEGORY_ALPHANUMERIC, "CobolConstant.blank"); @@ -1023,6 +1055,22 @@ cb_tree cb_build_national_literal(const unsigned char *data, size_t size) { return CB_TREE(build_literal(CB_CATEGORY_NATIONAL, data, size)); } +cb_tree cb_build_concat_alphanumeric_literal(const unsigned char *data, + size_t size1, size_t size2, + size_t *sgmt_sizes, + size_t sgmt_count) { + return CB_TREE(build_concat_literal(CB_CATEGORY_ALPHANUMERIC, data, size1, + size2, sgmt_sizes, sgmt_count)); +} + +cb_tree cb_build_concat_national_literal(const unsigned char *data, + size_t size1, size_t size2, + size_t *sgmt_sizes, + size_t sgmt_count) { + return CB_TREE(build_concat_literal(CB_CATEGORY_NATIONAL, data, size1, size2, + sgmt_sizes, sgmt_count)); +} + cb_tree cb_concat_literals(cb_tree x1, cb_tree x2) { unsigned char *buff; cb_tree x; @@ -1030,14 +1078,17 @@ cb_tree cb_concat_literals(cb_tree x1, cb_tree x2) { unsigned char *data2; size_t size1; size_t size2; + struct cb_literal *l; if (x1 == cb_error_node || x2 == cb_error_node) { return cb_error_node; } if (CB_LITERAL_P(x1)) { + l = CB_LITERAL(x1); data1 = CB_LITERAL(x1)->data; size1 = CB_LITERAL(x1)->size; } else if (CB_CONST_P(x1)) { + l = CB_LITERAL(x1); size1 = 1; if (x1 == cb_space) { data1 = (unsigned char *)" "; @@ -1083,8 +1134,18 @@ cb_tree cb_concat_literals(cb_tree x1, cb_tree x2) { buff = cobc_malloc(size1 + size2 + 3); memcpy(buff, data1, size1); memcpy(buff + size1, data2, size2); - x = cb_build_alphanumeric_literal(buff, size1 + size2); + if (!l->segment_count) { + l->segment_count = 1; + } + if (x1->category == CB_CATEGORY_NATIONAL) { + x = cb_build_concat_national_literal(buff, size1, size2, l->segment_sizes, + l->segment_count); + } else { + x = cb_build_concat_alphanumeric_literal( + buff, size1, size2, l->segment_sizes, l->segment_count); + } free(buff); + return x; } @@ -1460,12 +1521,7 @@ cb_tree cb_build_picture(const char *str) { size += n; } else if (c == 'N' || (category == PIC_NATIONAL_EDITED && (c == '0' || c == 'B' || c == '/'))) { -#ifdef I18N_UTF8 - /* I18N_UTF8: 3bytes for BMP. */ - size += n * 2; -#else /*!I18N_UTF8*/ size += n; -#endif /*I18N_UTF8*/ } /* store in the buffer */ @@ -1509,14 +1565,15 @@ cb_tree cb_build_picture(const char *str) { break; case PIC_NATIONAL: pic->category = CB_CATEGORY_NATIONAL; -#ifdef I18N_UTF8 - /* I18N_UTF8: NATIONAL allocates 3bytes/char for BMP. */ - CHECK_CHARACTER_LENGTH(cb_max_utf8_character_data_size, - "National field cannot be larger than %d digits"); -#else /*!I18N_UTF8*/ + // #ifdef I18N_UTF8 + // /* I18N_UTF8: NATIONAL allocates 3bytes/char for BMP. */ + // CHECK_CHARACTER_LENGTH(cb_max_utf8_character_data_size, + // "National field cannot be larger than %d + // digits"); + // #else /*!I18N_UTF8*/ CHECK_CHARACTER_LENGTH(cb_max_sjis_character_data_size, "National field cannot be larger than %d digits"); -#endif /*I18N_UTF8*/ + // #endif /*I18N_UTF8*/ break; case PIC_NUMERIC_EDITED: pic->str = cobc_malloc(idx + 1); @@ -1542,16 +1599,16 @@ cb_tree cb_build_picture(const char *str) { memcpy(pic->str, buff, idx); pic->category = CB_CATEGORY_NATIONAL_EDITED; pic->lenstr = idx; -#ifdef I18N_UTF8 - /* I18N_UTF8: NATIONAL allocates 3bytes/char for BMP. */ - CHECK_CHARACTER_LENGTH( - cb_max_utf8_character_data_size, - "NationalEdit field cannot be larger than %d digits"); -#else /*!I18N_UTF8*/ + // #ifdef I18N_UTF8 + // /* I18N_UTF8: NATIONAL allocates 3bytes/char for BMP. */ + // CHECK_CHARACTER_LENGTH( + // cb_max_utf8_character_data_size, + // "NationalEdit field cannot be larger than %d digits"); + // #else /*!I18N_UTF8*/ CHECK_CHARACTER_LENGTH( cb_max_sjis_character_data_size, "NationalEdit field cannot be larger than %d digits"); -#endif /*I18N_UTF8*/ + // #endif /*I18N_UTF8*/ break; default: goto error; @@ -1719,10 +1776,10 @@ struct cb_file *build_file(cb_tree name) { p->cname = to_cname(p->name); p->organization = cb_default_organization; - ; p->access_mode = COB_ACCESS_SEQUENTIAL; p->handler = CB_LABEL(cb_standard_error_handler); p->handler_prog = current_program; + p->lock_mode = cb_default_select_lock_mode; if (external_flg == 1) { p->external_assign = 1; } @@ -2511,6 +2568,19 @@ cb_tree cb_build_continue(void) { return CB_TREE(p); } +/* + * SWITCH + */ + +cb_tree cb_build_switch(cb_tree test, cb_tree case_list) { + struct cb_switch *p; + + p = make_tree(CB_TAG_SWITCH, CB_CATEGORY_UNKNOWN, sizeof(struct cb_switch)); + p->test = test; + p->case_list = case_list; + return CB_TREE(p); +} + /* * FUNCTION */ @@ -2714,22 +2784,31 @@ cb_tree cb_build_intrinsic(cb_tree name, cb_tree args, cb_tree refmod) { char *cb_get_hexword(char *name) { unsigned char *p; - int non_sjis = 0; + int non_sjis_utf8 = 0; char *rt = NULL; for (p = (unsigned char *)name; *p;) { unsigned char c = *p; +#ifdef I18N_UTF8 + int n; + if ((n = COB_U8BYTE_1(c))) { + p += n; + } else { + non_sjis_utf8 = 1; + break; + } +#else /*!I18N_UTF8*/ if (c < 0x80) { p++; } else if ((0x81 <= c && c <= 0x9F) || (0xE0 <= c && c <= 0xEF)) { p += 2; } else { - non_sjis = 1; + non_sjis_utf8 = 1; break; } +#endif /*I18N_UTF8*/ } - - if (!non_sjis) { + if (!non_sjis_utf8) { rt = strdup(name); } else { rt = cobc_malloc(strlen(name) * 2 + 7); diff --git a/cobj/tree.h b/cobj/tree.h index 4e79b45a..c652cd63 100644 --- a/cobj/tree.h +++ b/cobj/tree.h @@ -85,6 +85,8 @@ enum cb_tag { CB_TAG_JAVA_CONTINUE, CB_TAG_JAVA_BREAK, + + CB_TAG_SWITCH, }; enum cb_alphabet_name_type { @@ -220,6 +222,56 @@ enum cb_usage { enum cb_operand_type { CB_SENDING_OPERAND, CB_RECEIVING_OPERAND }; +enum cb_system_routine { + SYSTEM, + CBL_AND, + CBL_CHANGE_DIR, + CBL_CHECK_FILE_EXIST, + CBL_CLOSE_FILE, + CBL_COPY_FILE, + CBL_CREATE_DIR, + CBL_CREATE_FILE, + CBL_DELETE_DIR, + CBL_DELETE_FILE, + CBL_EQ, + CBL_ERROR_PROC, + CBL_EXIT_PROC, + CBL_FLUSH_FILE, + CBL_GET_CURRENT_DIR, + CBL_IMP, + CBL_NIMP, + CBL_NOR, + CBL_NOT, + CBL_OC_NANOSLEEP, + CBL_OPEN_FILE, + CBL_OR, + CBL_READ_FILE, + CBL_RENAME_FILE, + CBL_TOLOWER, + CBL_TOUPPER, + CBL_WRITE_FILE, + CBL_XOR, + CBL_OC_KEISEN, + CBL_OC_ATTRIBUTE, + C$CHDIR, + C$COPY, + C$DELETE, + C$FILEINFO, + C$LIST_DIRECTORY, + C$GETPID, + C$JUSTIFY, + C$CALLEDBY, + C$MAKEDIR, + C$NARG, + C$SLEEP, + C$PARAMSIZE, + C$TOUPPER, + C$TOLOWER, + CBL_X91, + CBL_XF4, + CBL_XF5 +}; + /* * Tree */ @@ -271,6 +323,7 @@ extern cb_tree cb_true; extern cb_tree cb_false; extern cb_tree cb_null; extern cb_tree cb_zero; +extern cb_tree cb_zen_zero; extern cb_tree cb_one; extern cb_tree cb_space; extern cb_tree cb_blank; @@ -414,9 +467,17 @@ extern cb_tree cb_build_system_name(enum cb_system_name_category category, * Literal */ +struct cb_literal_segment { + size_t size; + unsigned char *data; + struct cb_literal_segment *next; +}; + struct cb_literal { struct cb_tree_common common; size_t size; + size_t *segment_sizes; /* segment sizes for strings concatenated with '&' */ + size_t segment_count; unsigned char *data; signed char all; signed char sign; /* unsigned: 0 negative: -1 positive: 1 */ @@ -436,6 +497,14 @@ extern cb_tree cb_build_alphanumeric_literal(const unsigned char *data, extern cb_tree cb_build_national_literal(const unsigned char *data, size_t size); extern cb_tree cb_concat_literals(cb_tree x1, cb_tree x2); +extern cb_tree cb_build_concat_alphanumeric_literal(const unsigned char *data, + size_t size1, size_t size2, + size_t *sgmt_sizes, + size_t sgmt_count); +extern cb_tree cb_build_concat_national_literal(const unsigned char *data, + size_t size1, size_t size2, + size_t *sgmt_sizes, + size_t sgmt_count); /* * Decimal @@ -513,7 +582,7 @@ struct cb_field { cb_tree key; /* KEY */ cb_tree ref; /* reference used in SEARCH ALL */ cb_tree val; /* value to be compared in SEARCH ALL */ - } * keys; + } *keys; int nkeys; /* the number of keys */ int param_num; /* CHAINING param number */ struct cb_picture *pic; /* PICTURE */ @@ -1118,6 +1187,24 @@ extern cb_tree cb_build_perform(int type); extern cb_tree cb_build_perform_varying(cb_tree name, cb_tree from, cb_tree step, cb_tree until); +/* + * switch (evaluate) + */ + +struct cb_switch { + struct cb_tree_common common; + cb_tree test; + cb_tree case_list; +}; + +#define CB_SWITCH(x) (CB_TREE_CAST(CB_TAG_SWITCH, struct cb_switch, x)) +#define CB_SWITCH_P(x) (CB_TREE_TAG(x) == CB_TAG_SWITCH) + +extern cb_tree cb_build_switch(cb_tree test, cb_tree case_tree); + +extern int cb_literal_to_int_for_switch_label(struct cb_literal *lit, + int *result); + /* * SORT */ @@ -1367,6 +1454,10 @@ extern void level_except_error(cb_tree x, const char *clause); struct cb_literal *build_literal(enum cb_category category, const unsigned char *data, size_t size); +struct cb_literal *build_concat_literal(enum cb_category category, + const unsigned char *data, size_t size1, + size_t size2, size_t *sgmt_sizes, + size_t sgmt_count); /* field.c */ extern size_t cb_needs_01; diff --git a/cobj/typeck.c b/cobj/typeck.c index 95db7b33..bcc17371 100644 --- a/cobj/typeck.c +++ b/cobj/typeck.c @@ -114,16 +114,6 @@ static const char *const bin_set_funcs[] = {NULL, "setSwpS56Binary", "setSwpS64Binary"}; -static const char *const bin_compare_funcs[] = { - "cmpU8Binary", "cmpU16Binary", "cmpU24Binary", "cmpU32Binary", - "cmpU40Binary", "cmpU48Binary", "cmpU56Binary", "cmpU64Binary", - "cmpS8Binary", "cmpS16Binary", "cmpS24Binary", "cmpS32Binary", - "cmpS40Binary", "cmpS48Binary", "cmpS56Binary", "cmpS64Binary", - "cmpU8Binary", "cmpSwpU16Binary", "cmpSwpU24Binary", "cmpSwpU32Binary", - "cmpSwpU40Binary", "cmpSwpU48Binary", "cmpSwpU56Binary", "cmpSwpU64Binary", - "cmpS8Binary", "cmpSwpS16Binary", "cmpSwpS24Binary", "cmpSwpS32Binary", - "cmpSwpS40Binary", "cmpSwpS48Binary", "cmpSwpS56Binary", "cmpSwpS64Binary"}; - static const char *const bin_add_funcs[] = { "addU8Binary", "addU16Binary", "addU24Binary", "addU32Binary", "addU40Binary", "addU48Binary", "addU56Binary", "addU64Binary", @@ -385,6 +375,26 @@ char *cb_encode_program_id(const char *name) { p += sprintf((char *)p, "_%02X", *s++); } /* encode invalid letters */ +#ifdef I18N_UTF8 + int n, i; + + for (; *s; s++) { + if (isalnum(*s) || *s == '_') { + *p++ = *s; + } else if (*s == '-') { + *p++ = '_'; + *p++ = '_'; + } else if ((n = COB_U8BYTE_1(*s))) { + p += sprintf((char *)p, "_"); + for (i = 0; i < n; i++) { + p += sprintf((char *)p, "%02X", s[i]); + } + s += n - 1; + } else { + p += sprintf((char *)p, "_%02X", *s); + } + } +#else /*!I18N_UTF8*/ for (; *s; s++) { if (isalnum(*s) || *s == '_') { *p++ = *s; @@ -395,7 +405,9 @@ char *cb_encode_program_id(const char *name) { p += sprintf((char *)p, "_%02X", *s); } } +#endif *p = 0; + return strdup((char *)buff); } @@ -671,6 +683,7 @@ cb_tree cb_build_identifier(cb_tree x) { cb_tree sub; int size; int n; + int name_size; if (x == cb_error_node) { return cb_error_node; @@ -751,6 +764,13 @@ cb_tree cb_build_identifier(cb_tree x) { } } +#ifdef I18N_UTF8 + name_size = + utf8_calc_sjis_size((const unsigned char *)name, strlen(name)); +#else /*!I18N_UTF8*/ + name_size = strlen(name); +#endif /*I18N_UTF8*/ + /* run-time check */ if (CB_EXCEPTION_ENABLE(COB_EC_BOUND_SUBSCRIPT)) { if (p->occurs_depending) { @@ -764,7 +784,7 @@ cb_tree cb_build_identifier(cb_tree x) { e2 = cb_build_funcall_5( "CobolCheck.checkSubscript", cb_build_cast_integer(sub), cb_int1, cb_build_cast_integer(p->occurs_depending), - cb_build_string0((ucharptr)name), cb_int(strlen(name))); + cb_build_string0((ucharptr)name), cb_int(name_size)); } else { e1 = cb_build_funcall_4( "CobolCheck.checkOdo", cb_int(p->occurs_max), @@ -774,7 +794,7 @@ cb_tree cb_build_identifier(cb_tree x) { e2 = cb_build_funcall_5( "CobolCheck.checkSubscript", cb_build_cast_integer(sub), cb_int1, cb_int(p->occurs_max), - cb_build_string0((ucharptr)name), cb_int(strlen(name))); + cb_build_string0((ucharptr)name), cb_int(name_size)); } r->check = cb_list_add(r->check, e1); r->check = cb_list_add(r->check, e2); @@ -783,7 +803,7 @@ cb_tree cb_build_identifier(cb_tree x) { e1 = cb_build_funcall_5( "CobolCheck.checkSubscript", cb_build_cast_integer(sub), cb_int1, cb_int(p->occurs_max), - cb_build_string0((ucharptr)name), cb_int(strlen(name))); + cb_build_string0((ucharptr)name), cb_int(name_size)); r->check = cb_list_add(r->check, e1); } } @@ -830,18 +850,6 @@ cb_tree cb_build_identifier(cb_tree x) { #endif /*I18N_UTF8*/ /* run-time check */ -#ifdef I18N_UTF8 - /* I18N_UTF8: No wide char support. */ - if (CB_EXCEPTION_ENABLE(COB_EC_BOUND_REF_MOD)) { - if (!CB_LITERAL_P(r->offset) || (r->length && !CB_LITERAL_P(r->length))) { - e1 = cb_build_funcall_4( - "CobolUtil.cobCheckRefMod", cb_build_cast_integer(r->offset), - r->length ? cb_build_cast_integer(r->length) : cb_int1, - cb_int(f->size), cb_build_string0((ucharptr)f->name)); - r->check = cb_list_add(r->check, e1); - } - } -#else /*!I18N_UTF8*/ if (CB_EXCEPTION_ENABLE(COB_EC_BOUND_REF_MOD)) { if (!CB_LITERAL_P(r->offset) || (r->length && !CB_LITERAL_P(r->length))) { if (cb_tree_category(CB_TREE(r)) == CB_CATEGORY_NATIONAL || @@ -861,7 +869,6 @@ cb_tree cb_build_identifier(cb_tree x) { r->check = cb_list_add(r->check, e1); } } -#endif /*I18N_UTF8*/ } if (f->storage == CB_STORAGE_CONSTANT) { @@ -2239,28 +2246,24 @@ static cb_tree build_cond_88(cb_tree x) { } static cb_tree cb_build_optim_cond(struct cb_binary_op *p) { - struct cb_field *f; - struct cb_field *fy; - const char *s; - size_t n; if (CB_REF_OR_FIELD_P(p->y)) { - fy = cb_field(p->y); + struct cb_field *fy = cb_field(p->y); if (!fy->pic->have_sign && (fy->usage == CB_USAGE_BINARY || fy->usage == CB_USAGE_COMP_5 || fy->usage == CB_USAGE_COMP_X)) { - return cb_build_method_call_2("cmpUint", p->x, + return cb_build_method_call_2("cmpInteger", p->x, cb_build_cast_integer(p->y)); } } if (CB_REF_OR_FIELD_P(p->x)) { - f = cb_field(p->x); + struct cb_field *f = cb_field(p->x); if (!f->pic->scale && f->usage == CB_USAGE_PACKED) { if (f->pic->digits < 10) { - return cb_build_method_call_2("cmpInt", p->x, + return cb_build_method_call_2("cmpInteger", p->x, cb_build_cast_integer(p->y)); } else { - return cb_build_method_call_2("cmpInt", p->x, + return cb_build_method_call_2("cmpInteger", p->x, cb_build_cast_integer(p->y)); } } @@ -2291,38 +2294,12 @@ static cb_tree cb_build_optim_cond(struct cb_binary_op *p) { if (!f->pic->scale && (f->usage == CB_USAGE_BINARY || f->usage == CB_USAGE_COMP_5 || f->usage == CB_USAGE_INDEX || f->usage == CB_USAGE_COMP_X)) { - n = (f->size - 1) + (8 * (f->pic->have_sign ? 1 : 0)) + - (16 * (f->flag_binary_swap ? 1 : 0)); -#if defined(COB_NON_ALIGNED) && !defined(_MSC_VER) - switch (f->size) { - case 2: -#ifdef COB_SHORT_BORK - s = bin_compare_funcs[n]; - break; -#endif - case 4: - case 8: - if (f->storage != CB_STORAGE_LINKAGE && f->indexes == 0 && - (f->offset % f->size) == 0) { - s = align_bin_compare_funcs[n]; - } else { - s = bin_compare_funcs[n]; - } - break; - default: - s = bin_compare_funcs[n]; - break; - } -#else - s = bin_compare_funcs[n]; -#endif - if (s) { - return cb_build_method_call_2(s, cb_build_cast_address(p->x), - cb_build_cast_integer(p->y)); - } + return cb_build_method_call_2("cmpInteger", p->x, + cb_build_cast_integer(p->y)); } } - return cb_build_method_call_2("cmpInt", p->x, cb_build_cast_integer(p->y)); + return cb_build_method_call_2("cmpInteger", p->x, + cb_build_cast_integer(p->y)); } static int cb_chk_num_cond(cb_tree x, cb_tree y) { @@ -2562,38 +2539,13 @@ cb_tree cb_build_cond(cb_tree x) { */ static cb_tree cb_build_optim_add(cb_tree v, cb_tree n) { - size_t z; - const char *s; - struct cb_field *f; - if (CB_REF_OR_FIELD_P(v)) { - f = cb_field(v); + struct cb_field *f = cb_field(v); if (!f->pic->scale && (f->usage == CB_USAGE_BINARY || f->usage == CB_USAGE_COMP_5 || f->usage == CB_USAGE_COMP_X)) { - z = (f->size - 1) + (8 * (f->pic->have_sign ? 1 : 0)) + - (16 * (f->flag_binary_swap ? 1 : 0)); -#if defined(COB_NON_ALIGNED) && !defined(_MSC_VER) - switch (f->size) { - case 2: -#ifdef COB_SHORT_BORK - s = bin_add_funcs[z]; - break; -#endif - case 4: - case 8: - if (f->storage != CB_STORAGE_LINKAGE && f->indexes == 0 && - (f->offset % f->size) == 0) { - s = align_bin_add_funcs[z]; - } else { - s = bin_add_funcs[z]; - } - break; - default: - s = bin_add_funcs[z]; - break; - } -#else + size_t z = (f->size - 1) + (8 * (f->pic->have_sign ? 1 : 0)) + + (16 * (f->flag_binary_swap ? 1 : 0)); if (f->usage == CB_USAGE_COMP_5) { switch (f->size) { case 1: @@ -2603,8 +2555,7 @@ static cb_tree cb_build_optim_add(cb_tree v, cb_tree n) { return cb_build_assign(v, cb_build_binary_op(v, '+', n)); } } - s = bin_add_funcs[z]; -#endif + const char *s = bin_add_funcs[z]; if (s) { return cb_build_method_call_2(s, cb_build_cast_address(v), cb_build_cast_integer(n)); @@ -2619,38 +2570,14 @@ static cb_tree cb_build_optim_add(cb_tree v, cb_tree n) { } static cb_tree cb_build_optim_sub(cb_tree v, cb_tree n) { - size_t z; - const char *s; - struct cb_field *f; if (CB_REF_OR_FIELD_P(v)) { - f = cb_field(v); + struct cb_field *f = cb_field(v); if (!f->pic->scale && (f->usage == CB_USAGE_BINARY || f->usage == CB_USAGE_COMP_5 || f->usage == CB_USAGE_COMP_X)) { - z = (f->size - 1) + (8 * (f->pic->have_sign ? 1 : 0)) + - (16 * (f->flag_binary_swap ? 1 : 0)); -#if defined(COB_NON_ALIGNED) && !defined(_MSC_VER) - switch (f->size) { - case 2: -#ifdef COB_SHORT_BORK - s = bin_sub_funcs[z]; - break; -#endif - case 4: - case 8: - if (f->storage != CB_STORAGE_LINKAGE && f->indexes == 0 && - (f->offset % f->size) == 0) { - s = align_bin_sub_funcs[z]; - } else { - s = bin_sub_funcs[z]; - } - break; - default: - s = bin_sub_funcs[z]; - break; - } -#else + size_t z = (f->size - 1) + (8 * (f->pic->have_sign ? 1 : 0)) + + (16 * (f->flag_binary_swap ? 1 : 0)); if (f->usage == CB_USAGE_COMP_5) { switch (f->size) { case 1: @@ -2660,8 +2587,7 @@ static cb_tree cb_build_optim_sub(cb_tree v, cb_tree n) { return cb_build_assign(v, cb_build_binary_op(v, '-', n)); } } - s = bin_sub_funcs[z]; -#endif + const char *s = bin_sub_funcs[z]; if (s) { return cb_build_method_call_2(s, cb_build_cast_address(v), cb_build_cast_integer(n)); @@ -2675,19 +2601,9 @@ cb_tree cb_build_add(cb_tree v, cb_tree n, cb_tree round_opt) { cb_tree opt; struct cb_field *f; -#ifdef COB_NON_ALIGNED - if (CB_INDEX_P(v)) { - return cb_build_move(cb_build_binary_op(v, '+', n), v); - } - if (CB_TREE_CLASS(v) == CB_CLASS_POINTER) { - current_program->gen_ptrmanip = 1; - return cb_build_funcall_3("cob_pointer_manip", v, n, cb_int0); - } -#else if (CB_INDEX_P(v) || CB_TREE_CLASS(v) == CB_CLASS_POINTER) { return cb_build_move(cb_build_binary_op(v, '+', n), v); } -#endif if (CB_REF_OR_FIELD_P(v)) { f = cb_field(v); @@ -2715,19 +2631,9 @@ cb_tree cb_build_sub(cb_tree v, cb_tree n, cb_tree round_opt) { cb_tree opt; struct cb_field *f; -#ifdef COB_NON_ALIGNED - if (CB_INDEX_P(v)) { - return cb_build_move(cb_build_binary_op(v, '-', n), v); - } - if (CB_TREE_CLASS(v) == CB_CLASS_POINTER) { - current_program->gen_ptrmanip = 1; - return cb_build_funcall_3("cob_pointer_manip", v, n, cb_int1); - } -#else if (CB_INDEX_P(v) || CB_TREE_CLASS(v) == CB_CLASS_POINTER) { return cb_build_move(cb_build_binary_op(v, '-', n), v); } -#endif if (CB_REF_OR_FIELD_P(v)) { f = cb_field(v); @@ -3193,13 +3099,47 @@ void cb_emit_call(cb_tree prog, cb_tree cb_using, cb_tree returning, const struct system_table *psyst; for (psyst = (const struct system_table *)&system_tab[0]; psyst->syst_name; psyst++) { - if (!strcmp((const char *)CB_LITERAL(prog)->data, - (const char *)psyst->syst_name)) { + const char *data = (const char *)CB_LITERAL(prog)->data; + if (!strcmp(data, (const char *)psyst->syst_name)) { + // error if the subroutine is not implemented + switch (psyst - &system_tab[0]) { + case CBL_CHANGE_DIR: + case CBL_CHECK_FILE_EXIST: + case CBL_CLOSE_FILE: + case CBL_COPY_FILE: + case CBL_CREATE_DIR: + case CBL_CREATE_FILE: + case CBL_DELETE_DIR: + case CBL_DELETE_FILE: + case CBL_ERROR_PROC: + case CBL_EXIT_PROC: + case CBL_FLUSH_FILE: + case CBL_GET_CURRENT_DIR: + case CBL_IMP: + case CBL_OPEN_FILE: + case CBL_READ_FILE: + case CBL_RENAME_FILE: + case CBL_WRITE_FILE: + case CBL_OC_KEISEN: + case CBL_OC_ATTRIBUTE: + case C$CHDIR: + case C$COPY: + case C$DELETE: + case C$FILEINFO: + case C$GETPID: + case C$JUSTIFY: + case C$MAKEDIR: + case C$NARG: + case C$PARAMSIZE: + cb_error(_("%s not implemented"), data); + return; + } if (psyst->syst_params > cb_list_length(cb_using)) { cb_error(_("Wrong number of CALL parameters for '%s'"), (char *)psyst->syst_name); return; } + is_sys_call = 1; break; } @@ -3673,8 +3613,154 @@ static cb_tree build_evaluate(cb_tree subject_list, cb_tree case_list) { } } +int cb_literal_to_int_for_switch_label(struct cb_literal *lit, int *result) { + const char *min_num_abs = + "2147483648"; // -1 * (the minimum value of int of Java) + const char *max_num = "2147483647"; // the maximum value of int of Java + const int len_boundary = + 10; // string length of min_num_abs (== string length of max_num) + if (lit->size > len_boundary) { + // the value of the literal is out of range + *result = 0; + return 0; + } + + size_t i; + const char *boundary = lit->sign < 0 ? min_num_abs : max_num; + if (lit->size == len_boundary) { + for (i = 0; i < len_boundary; ++i) { + if (boundary[i] < lit->data[i]) { + // the value of the literal is out of range + *result = 0; + return 0; + } + } + } + + int ret = 0; + for (i = 0; i < lit->size; ++i) { + ret = ret * 10 + lit->data[i] - '0'; + } + *result = 1; + return lit->sign < 0 ? -ret : ret; +} + +// Determine a given label exists in the list of existing labels +// If a given label exists in the list, return 1. Otherwise return 0; +static int is_switch_label_duplicate(int label, const int *existing_label_list, + int list_len) { + int i = 0; + for (; i < list_len; ++i) { + if (existing_label_list[i] == label) { + return 1; + } + } + return 0; +} + +static cb_tree convert_evaluate_stmt_to_switch_stmt(cb_tree subject_list, + cb_tree case_list) { + cb_tree subjs; + cb_tree whens; + cb_tree objs; + + cb_tree case_tree = case_list; + int when_count = 0; + int other_exists = 0; + + // The length of subject_list must be 1 + if (subject_list == NULL || CB_CHAIN(subject_list)) { + return NULL; + } + + // Determine if a given evaluate statement can be converted to a switch + // statement + int case_count = 0; + for (; case_tree; case_tree = CB_CHAIN(case_tree), ++case_count) { + whens = CB_VALUE(case_tree); + /* for each WHEN sequence */ + int flag_other_exists = 1; + for (; whens; whens = CB_CHAIN(whens)) { + for (subjs = subject_list, objs = CB_VALUE(whens); subjs && objs; + subjs = CB_CHAIN(subjs), objs = CB_CHAIN(objs)) { + cb_tree subj = CB_VALUE(subjs); + cb_tree obj = CB_VALUE(objs); + if (!subj || CB_TREE_CATEGORY(subj) != CB_CATEGORY_NUMERIC) { + return NULL; + } + if (obj) { + if (CB_LIST_P(obj)) { + flag_other_exists = 0; + } + if (CB_STATEMENT_P(obj)) { + continue; + } + if (CB_PAIR_P(obj)) { + // WHEN NOT + if (CB_PURPOSE_INT(obj)) { + return NULL; + } + cb_tree when_target = CB_PAIR_Y(obj); + if (CB_PAIR_P(when_target)) { + cb_tree primary_target = CB_PAIR_X(when_target); + cb_tree thru_target = CB_PAIR_Y(when_target); + if (!CB_LITERAL_P(primary_target) || thru_target) { + return NULL; + } + struct cb_literal *lit = CB_LITERAL(primary_target); + if (lit->data == NULL || lit->scale != 0) { + return NULL; + } + ++when_count; + } + } + } + } + } + other_exists |= flag_other_exists; + } + // Build Switch statement + int *cases = malloc(when_count * sizeof(int)); + int case_index = 0; + for (case_tree = case_list; case_tree; case_tree = CB_CHAIN(case_tree)) { + whens = CB_VALUE(case_tree); + /* for each WHEN sequence */ + for (; whens; whens = CB_CHAIN(whens)) { + for (objs = CB_VALUE(whens); objs; objs = CB_CHAIN(objs)) { + cb_tree obj = CB_VALUE(objs); + if (obj && CB_PAIR_P(obj)) { + cb_tree when_target = CB_PAIR_Y(obj); + struct cb_literal *primary_target = + CB_LITERAL(CB_PAIR_X(when_target)); + int result; + int label = + cb_literal_to_int_for_switch_label(primary_target, &result); + // If calculating a switch label fails, the evaluate statement cannot + // be converted to switch statement + if (!result) { + return NULL; + } + // If a duplicate label is found, the evaluate statement cannot be + // converted to switch statement + if (is_switch_label_duplicate(label, cases, case_index)) { + return NULL; + } + cases[case_index++] = label; + } + } + } + } + return cb_build_switch(CB_VALUE(subject_list), case_list); +} + void cb_emit_evaluate(cb_tree subject_list, cb_tree case_list) { - cb_emit(build_evaluate(subject_list, case_list)); + cb_tree switch_stmt = + convert_evaluate_stmt_to_switch_stmt(subject_list, case_list); + if (switch_stmt) { + cb_emit(switch_stmt); + } else { + cb_emit(build_evaluate(subject_list, case_list)); + } } /* @@ -3941,17 +4027,17 @@ static int check_equal_data_size(cb_tree x, cb_tree y) { return rt; } -static int cb_validate_inspect_replaceable(cb_tree x, cb_tree y) { - int rt = 0; - - if (y == cb_zero || y == cb_space || y == cb_quote || y == cb_high || - y == cb_low) { - /* always replaceable */ - } else if (check_equal_data_size(x, y)) { - rt = 1; - } - return rt; -} +// static int cb_validate_inspect_replaceable(cb_tree x, cb_tree y) { +// int rt = 0; +// +// if (y == cb_zero || y == cb_space || y == cb_quote || y == cb_high || +// y == cb_low) { +// /* always replaceable */ +// } else if (check_equal_data_size(x, y)) { +// rt = 1; +// } +// return rt; +// } static int cb_validate_inspect_convertible(cb_tree x, cb_tree y) { unsigned char *data1; @@ -4125,7 +4211,14 @@ cb_tree cb_build_replacing_characters(cb_tree x, cb_tree l, cb_tree var) { cb_tree cb_build_replacing_all(cb_tree x, cb_tree y, cb_tree l, cb_tree var) { #ifdef I18N_UTF8 - cb_validate_inspect_replaceable(x, y); + // cb_validate_inspect_replaceable(x, y); + + if (CB_LITERAL_P(x)) { + const unsigned char *p = CB_LITERAL(x)->data; + if (COB_U8BYTE_1(*p) == 3 && y == cb_zero) { + y = cb_zen_zero; + } + } #else /*I18N_UTF8*/ /* * caution: cb_validate_inspect() never returns error (<0) @@ -4202,6 +4295,7 @@ static int move_error(cb_tree src, cb_tree dst, const size_t value_flag, return 0; } loc = src->source_line ? src : dst; + if (value_flag) { /* VALUE clause */ cb_warning_x(loc, msg); @@ -4656,10 +4750,8 @@ int validate_move(cb_tree src, cb_tree dst, size_t is_value) { if ((int)i < 0) { goto invalid_national; } - if (size >= 0 && i > size) { - goto size_overflow; - } - } else if (size >= 0 && (int)l->size > size) { + } + if (size >= 0 && utf8_calc_sjis_size(l->data, l->size) > size) { goto size_overflow; } #else /*!I18N_UTF8*/ @@ -4977,31 +5069,11 @@ static cb_tree cb_build_move_num_zero(cb_tree x) { return cb_build_memset(x, 0); } switch (f->size) { -#ifdef COB_NON_ALIGNED - case 1: - return cb_build_assign(x, cb_int0); - case 2: -#ifdef COB_SHORT_BORK - if (f->storage != CB_STORAGE_LINKAGE && f->indexes == 0 && - (f->offset % 4 == 0)) { - return cb_build_assign(x, cb_int0); - } - break; -#endif - case 4: - case 8: - if (f->storage != CB_STORAGE_LINKAGE && f->indexes == 0 && - (f->offset % f->size == 0)) { - return cb_build_assign(x, cb_int0); - } - break; -#else case 1: case 2: case 4: case 8: return cb_build_assign(x, cb_int0); -#endif } return cb_build_memset(x, 0); case CB_USAGE_DISPLAY: @@ -5225,6 +5297,7 @@ static cb_tree cb_build_move_literal(cb_tree src, cb_tree dst) { int val; int n; unsigned char bbyte; + size_t dst_size; l = CB_LITERAL(src); f = cb_field(dst); @@ -5282,17 +5355,34 @@ static cb_tree cb_build_move_literal(cb_tree src, cb_tree dst) { ((cat == CB_CATEGORY_ALPHABETIC || cat == CB_CATEGORY_ALPHANUMERIC) && f->size < (int)(l->size + 16) && !cb_field_variable_size(f))) { - buff = cobc_malloc((size_t)f->size); +#ifdef I18N_UTF8 + if (!utf8_ext_pick(l->data)) { + diff = (int)(f->size - l->size); + dst_size = f->size; + } else { + diff = (int)(f->size - utf8_calc_sjis_size(l->data, l->size)); + if (diff > 0) { + dst_size = strlen((char *)l->data) + diff; + } else { + dst_size = strlen((char *)l->data); + } + } + buff = cobc_malloc(dst_size); +#else /*!I18N_UTF8*/ diff = (int)(f->size - l->size); + dst_size = (size_t)f->size; + buff = cobc_malloc(dst_size); +#endif /*I18N_UTF8*/ + if (cat == CB_CATEGORY_NUMERIC) { if (diff <= 0) { - memcpy(buff, l->data - diff, (size_t)f->size); + memcpy(buff, l->data - diff, dst_size); } else { memset(buff, '0', (size_t)diff); memcpy(buff + diff, l->data, (size_t)l->size); } if (f->pic->have_sign) { - p = &buff[f->size - 1]; + p = &buff[dst_size - 1]; if (cb_display_sign) { cob_put_sign_ebcdic(p, l->sign); } else if (l->sign < 0) { @@ -5306,14 +5396,14 @@ static cb_tree cb_build_move_literal(cb_tree src, cb_tree dst) { } else { if (f->flag_justified) { if (diff <= 0) { - memcpy(buff, l->data - diff, (size_t)f->size); + memcpy(buff, l->data - diff, dst_size); } else { memset(buff, ' ', (size_t)diff); memcpy(buff + diff, l->data, (size_t)l->size); } } else { if (diff <= 0) { - memcpy(buff, l->data, (size_t)f->size); + memcpy(buff, l->data, dst_size); } else { memcpy(buff, l->data, (size_t)l->size); memset(buff + l->size, ' ', (size_t)diff); @@ -5321,22 +5411,22 @@ static cb_tree cb_build_move_literal(cb_tree src, cb_tree dst) { } } bbyte = *buff; - if (f->size == 1) { + if (dst_size == 1) { free(buff); return cb_build_funcall_2("$E", dst, cb_int(bbyte)); } - for (i = 0; i < f->size; i++) { + for (i = 0; i < dst_size; i++) { if (bbyte != buff[i]) { break; } } - if (i == f->size) { + if (i == dst_size) { free(buff); return cb_build_method_call_3("fillBytes", cb_build_cast_address(dst), cb_int(bbyte), cb_build_cast_length(dst)); } return cb_build_method_call_3("setBytes", cb_build_cast_address(dst), - cb_build_string(buff, f->size), + cb_build_string(buff, dst_size), cb_build_cast_length(dst)); } else if (cb_fits_int(src) && f->size <= 8 && (f->usage == CB_USAGE_BINARY || f->usage == CB_USAGE_COMP_5 || @@ -5374,15 +5464,7 @@ static cb_tree cb_build_move_literal(cb_tree src, cb_tree dst) { #endif case 4: case 8: -#ifdef COB_NON_ALIGNED - if (f->storage != CB_STORAGE_LINKAGE && f->indexes == 0 && - (f->offset % f->size == 0)) { - return cb_build_assign(dst, cb_int(val)); - } - break; -#else return cb_build_assign(dst, cb_int(val)); -#endif } return cb_build_move_call(src, dst); } else if (cb_fits_int(src) && f->usage == CB_USAGE_PACKED) { diff --git a/config.h.in b/config.h.in index 6fbf66ec..b6c1932a 100644 --- a/config.h.in +++ b/config.h.in @@ -36,17 +36,23 @@ /* Strip command */ #undef COB_STRIP_CMD -/* Define to 1 if using 'alloca.c'. */ +/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP + systems. This function is required for `alloca.c' support on those systems. + */ +#undef CRAY_STACKSEG_END + +/* Define to 1 if using `alloca.c'. */ #undef C_ALLOCA /* Define to 1 if translation of program messages to the user's native language is requested. */ #undef ENABLE_NLS -/* Define to 1 if you have 'alloca', as a function or macro. */ +/* Define to 1 if you have `alloca', as a function or macro. */ #undef HAVE_ALLOCA -/* Define to 1 if works. */ +/* Define to 1 if you have and it should be used (not on Ultrix). + */ #undef HAVE_ALLOCA_H /* Has __attribute__((aligned)) */ @@ -60,9 +66,6 @@ the CoreFoundation framework. */ #undef HAVE_CFPREFERENCESCOPYAPPVALUE -/* curses has color_set function */ -#undef HAVE_COLOR_SET - /* Define if the GNU dcgettext() function is already present or preinstalled. */ #undef HAVE_DCGETTEXT @@ -85,9 +88,6 @@ /* Define if the GNU gettext() function is already present or preinstalled. */ #undef HAVE_GETTEXT -/* Define to 1 if you have the `gettimeofday' function. */ -#undef HAVE_GETTIMEOFDAY - /* Define if you have the iconv() function and it works. */ #undef HAVE_ICONV @@ -112,6 +112,9 @@ /* Define to 1 if you have the `memmove' function. */ #undef HAVE_MEMMOVE +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + /* Define to 1 if you have the `memset' function. */ #undef HAVE_MEMSET @@ -130,9 +133,6 @@ /* Define to 1 if you have the header file. */ #undef HAVE_STDINT_H -/* Define to 1 if you have the header file. */ -#undef HAVE_STDIO_H - /* Define to 1 if you have the header file. */ #undef HAVE_STDLIB_H @@ -222,9 +222,7 @@ STACK_DIRECTION = 0 => direction of growth unknown */ #undef STACK_DIRECTION -/* Define to 1 if all of the C90 standard headers exist (not just the ones - required in a freestanding environment). This macro is provided for - backward compatibility; new code need not use it. */ +/* Define to 1 if you have the ANSI C header files. */ #undef STDC_HEADERS /* Define to 1 if your declares `struct tm'. */ diff --git a/config/Makefile.in b/config/Makefile.in index ae8a2663..9b11aece 100644 --- a/config/Makefile.in +++ b/config/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.16.5 from Makefile.am. +# Makefile.in generated by automake 1.16.2 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2021 Free Software Foundation, Inc. +# Copyright (C) 1994-2020 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -202,8 +202,6 @@ COB_SHARED_OPT = @COB_SHARED_OPT@ COB_SPLITKEY_FLAGS = @COB_SPLITKEY_FLAGS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ -CSCOPE = @CSCOPE@ -CTAGS = @CTAGS@ CXXCPP = @CXXCPP@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ @@ -215,7 +213,6 @@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ -ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ @@ -404,6 +401,7 @@ ctags CTAGS: cscope cscopelist: + distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am diff --git a/configure b/configure index ab62668d..6e97ce2b 100755 --- a/configure +++ b/configure @@ -1,12 +1,11 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.71 for opensource COBOL 4J 1.1.2. +# Generated by GNU Autoconf 2.69 for opensource COBOL 4J 1.1.14. # # Report bugs to . # # -# Copyright (C) 1992-1996, 1998-2017, 2020-2021 Free Software Foundation, -# Inc. +# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. # # # This configure script is free software; the Free Software Foundation @@ -17,16 +16,14 @@ # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh -as_nop=: -if test ${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1 -then : +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST -else $as_nop +else case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( @@ -36,46 +33,46 @@ esac fi - -# Reset variables that may have inherited troublesome values from -# the environment. - -# IFS needs to be set, to space, tab, and newline, in precisely that order. -# (If _AS_PATH_WALK were called with IFS unset, it would have the -# side effect of setting IFS to empty, thus disabling word splitting.) -# Quoting is to prevent editors from complaining about space-tab. as_nl=' ' export as_nl -IFS=" "" $as_nl" - -PS1='$ ' -PS2='> ' -PS4='+ ' - -# Ensure predictable behavior from utilities with locale-dependent output. -LC_ALL=C -export LC_ALL -LANGUAGE=C -export LANGUAGE - -# We cannot yet rely on "unset" to work, but we need these variables -# to be unset--not just set to an empty or harmless value--now, to -# avoid bugs in old shells (e.g. pre-3.0 UWIN ksh). This construct -# also avoids known problems related to "unset" and subshell syntax -# in other old shells (e.g. bash 2.01 and pdksh 5.2.14). -for as_var in BASH_ENV ENV MAIL MAILPATH CDPATH -do eval test \${$as_var+y} \ - && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : -done - -# Ensure that fds 0, 1, and 2 are open. -if (exec 3>&0) 2>/dev/null; then :; else exec 0&1) 2>/dev/null; then :; else exec 1>/dev/null; fi -if (exec 3>&2) ; then :; else exec 2>/dev/null; fi +# Printing a long string crashes Solaris 7 /usr/bin/printf. +as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo +# Prefer a ksh shell builtin over an external printf program on Solaris, +# but without wasting forks for bash or zsh. +if test -z "$BASH_VERSION$ZSH_VERSION" \ + && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='print -r --' + as_echo_n='print -rn --' +elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='printf %s\n' + as_echo_n='printf %s' +else + if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then + as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' + as_echo_n='/usr/ucb/echo -n' + else + as_echo_body='eval expr "X$1" : "X\\(.*\\)"' + as_echo_n_body='eval + arg=$1; + case $arg in #( + *"$as_nl"*) + expr "X$arg" : "X\\(.*\\)$as_nl"; + arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; + esac; + expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" + ' + export as_echo_n_body + as_echo_n='sh -c $as_echo_n_body as_echo' + fi + export as_echo_body + as_echo='sh -c $as_echo_body as_echo' +fi # The user is always right. -if ${PATH_SEPARATOR+false} :; then +if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || @@ -84,6 +81,13 @@ if ${PATH_SEPARATOR+false} :; then fi +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +IFS=" "" $as_nl" + # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in #(( @@ -92,12 +96,8 @@ case $0 in #(( for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac - test -r "$as_dir$0" && as_myself=$as_dir$0 && break + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break done IFS=$as_save_IFS @@ -109,10 +109,30 @@ if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then - printf "%s\n" "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi +# Unset variables that we do not need and which cause bugs (e.g. in +# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" +# suppresses any "Segmentation fault" message there. '((' could +# trigger a bug in pdksh 5.2.14. +for as_var in BASH_ENV ENV MAIL MAILPATH +do eval test x\${$as_var+set} = xset \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# CDPATH. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH # Use a proper internal environment variable to ensure we don't fall # into an infinite loop, continuously re-executing ourselves. @@ -134,22 +154,20 @@ esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. -printf "%s\n" "$0: could not re-execute with $CONFIG_SHELL" >&2 -exit 255 +$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 +as_fn_exit 255 fi # We don't want this to propagate to other subprocesses. { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then - as_bourne_compatible="as_nop=: -if test \${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1 -then : + as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which # is contrary to our usage. Disable this feature. alias -g '\${1+\"\$@\"}'='\"\$@\"' setopt NO_GLOB_SUBST -else \$as_nop +else case \`(set -o) 2>/dev/null\` in #( *posix*) : set -o posix ;; #( @@ -169,15 +187,12 @@ as_fn_success || { exitcode=1; echo as_fn_success failed.; } as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } -if ( set x; as_fn_ret_success y && test x = \"\$1\" ) -then : +if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : -else \$as_nop +else exitcode=1; echo positional parameters were not saved. fi test x\$exitcode = x0 || exit 1 -blah=\$(echo \$(echo blah)) -test x\"\$blah\" = xblah || exit 1 test -x / || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO @@ -192,38 +207,30 @@ test \$(( 1 + 1 )) = 2 || exit 1 PATH=/empty FPATH=/empty; export PATH FPATH test \"X\`printf %s \$ECHO\`\" = \"X\$ECHO\" \\ || test \"X\`print -r -- \$ECHO\`\" = \"X\$ECHO\" ) || exit 1" - if (eval "$as_required") 2>/dev/null -then : + if (eval "$as_required") 2>/dev/null; then : as_have_required=yes -else $as_nop +else as_have_required=no fi - if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null -then : + if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : -else $as_nop +else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR as_found=false for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. as_found=: case $as_dir in #( /*) for as_base in sh bash ksh sh5; do # Try only shells that exist, to save several forks. - as_shell=$as_dir$as_base + as_shell=$as_dir/$as_base if { test -f "$as_shell" || test -f "$as_shell.exe"; } && - as_run=a "$as_shell" -c "$as_bourne_compatible""$as_required" 2>/dev/null -then : + { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : CONFIG_SHELL=$as_shell as_have_required=yes - if as_run=a "$as_shell" -c "$as_bourne_compatible""$as_suggested" 2>/dev/null -then : + if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : break 2 fi fi @@ -231,21 +238,14 @@ fi esac as_found=false done -IFS=$as_save_IFS -if $as_found -then : - -else $as_nop - if { test -f "$SHELL" || test -f "$SHELL.exe"; } && - as_run=a "$SHELL" -c "$as_bourne_compatible""$as_required" 2>/dev/null -then : +$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && + { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : CONFIG_SHELL=$SHELL as_have_required=yes -fi -fi +fi; } +IFS=$as_save_IFS - if test "x$CONFIG_SHELL" != x -then : + if test "x$CONFIG_SHELL" != x; then : export CONFIG_SHELL # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also @@ -263,19 +263,18 @@ esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. -printf "%s\n" "$0: could not re-execute with $CONFIG_SHELL" >&2 +$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 exit 255 fi - if test x$as_have_required = xno -then : - printf "%s\n" "$0: This script requires a shell more modern than all" - printf "%s\n" "$0: the shells that I found on your system." - if test ${ZSH_VERSION+y} ; then - printf "%s\n" "$0: In particular, zsh $ZSH_VERSION has bugs and should" - printf "%s\n" "$0: be upgraded to zsh 4.3.4 or later." + if test x$as_have_required = xno; then : + $as_echo "$0: This script requires a shell more modern than all" + $as_echo "$0: the shells that I found on your system." + if test x${ZSH_VERSION+set} = xset ; then + $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" + $as_echo "$0: be upgraded to zsh 4.3.4 or later." else - printf "%s\n" "$0: Please tell bug-autoconf@gnu.org and + $as_echo "$0: Please tell bug-autoconf@gnu.org and $0: ws-opensource-cobol-contact@osscons.jp about your $0: system, including any error possibly output before this $0: message. Then install a modern shell, or manually run @@ -303,7 +302,6 @@ as_fn_unset () } as_unset=as_fn_unset - # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. @@ -321,14 +319,6 @@ as_fn_exit () as_fn_set_status $1 exit $1 } # as_fn_exit -# as_fn_nop -# --------- -# Do nothing but, unlike ":", preserve the value of $?. -as_fn_nop () -{ - return $? -} -as_nop=as_fn_nop # as_fn_mkdir_p # ------------- @@ -343,7 +333,7 @@ as_fn_mkdir_p () as_dirs= while :; do case $as_dir in #( - *\'*) as_qdir=`printf "%s\n" "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" @@ -352,7 +342,7 @@ $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || -printf "%s\n" X"$as_dir" | +$as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q @@ -391,13 +381,12 @@ as_fn_executable_p () # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. -if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null -then : +if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' -else $as_nop +else as_fn_append () { eval $1=\$$1\$2 @@ -409,27 +398,18 @@ fi # as_fn_append # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. -if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null -then : +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' -else $as_nop +else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith -# as_fn_nop -# --------- -# Do nothing but, unlike ":", preserve the value of $?. -as_fn_nop () -{ - return $? -} -as_nop=as_fn_nop # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- @@ -441,9 +421,9 @@ as_fn_error () as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 + $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi - printf "%s\n" "$as_me: error: $2" >&2 + $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error @@ -470,7 +450,7 @@ as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || -printf "%s\n" X/"$0" | +$as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q @@ -514,7 +494,7 @@ as_cr_alnum=$as_cr_Letters$as_cr_digits s/-\n.*// ' >$as_me.lineno && chmod +x "$as_me.lineno" || - { printf "%s\n" "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } + { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } # If we had to re-execute with $CONFIG_SHELL, we're ensured to have # already done that, so ensure we don't try to do so again and fall @@ -528,10 +508,6 @@ as_cr_alnum=$as_cr_Letters$as_cr_digits exit } - -# Determine whether it's possible to make 'echo' print without a newline. -# These variables are no longer used directly by Autoconf, but are AC_SUBSTed -# for compatibility with existing Makefiles. ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) @@ -545,13 +521,6 @@ case `echo -n x` in #((((( ECHO_N='-n';; esac -# For backward compatibility with old third-party macros, we provide -# the shell variables $as_echo and $as_echo_n. New code should use -# AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively. -as_echo='printf %s\n' -as_echo_n='printf %s' - - rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file @@ -620,46 +589,49 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='opensource COBOL 4J' -PACKAGE_TARNAME='opensource-cobol-4j-1.1.2' -PACKAGE_VERSION='1.1.2' -PACKAGE_STRING='opensource COBOL 4J 1.1.2' +PACKAGE_TARNAME='opensource-cobol-4j-1.1.14' +PACKAGE_VERSION='1.1.14' +PACKAGE_STRING='opensource COBOL 4J 1.1.14' PACKAGE_BUGREPORT='ws-opensource-cobol-contact@osscons.jp' PACKAGE_URL='' ac_unique_file="libcobj.h" # Factoring default headers for most tests. ac_includes_default="\ -#include -#ifdef HAVE_STDIO_H -# include +#include +#ifdef HAVE_SYS_TYPES_H +# include #endif -#ifdef HAVE_STDLIB_H +#ifdef HAVE_SYS_STAT_H +# include +#endif +#ifdef STDC_HEADERS # include +# include +#else +# ifdef HAVE_STDLIB_H +# include +# endif #endif #ifdef HAVE_STRING_H +# if !defined STDC_HEADERS && defined HAVE_MEMORY_H +# include +# endif # include #endif +#ifdef HAVE_STRINGS_H +# include +#endif #ifdef HAVE_INTTYPES_H # include #endif #ifdef HAVE_STDINT_H # include #endif -#ifdef HAVE_STRINGS_H -# include -#endif -#ifdef HAVE_SYS_TYPES_H -# include -#endif -#ifdef HAVE_SYS_STAT_H -# include -#endif #ifdef HAVE_UNISTD_H # include #endif" -ac_header_c_list= -ac_func_c_list= gt_needs= ac_subst_vars='am__EXEEXT_FALSE am__EXEEXT_TRUE @@ -761,9 +733,6 @@ AM_BACKSLASH AM_DEFAULT_VERBOSITY AM_DEFAULT_V AM_V -CSCOPE -ETAGS -CTAGS am__untar am__tar AMTAR @@ -931,6 +900,8 @@ do *) ac_optarg=yes ;; esac + # Accept the important Cygnus configure options, so we can diagnose typos. + case $ac_dashdash$ac_option in --) ac_dashdash=yes ;; @@ -971,9 +942,9 @@ do ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && - as_fn_error $? "invalid feature name: \`$ac_useropt'" + as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt - ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" @@ -997,9 +968,9 @@ do ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && - as_fn_error $? "invalid feature name: \`$ac_useropt'" + as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt - ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" @@ -1210,9 +1181,9 @@ do ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && - as_fn_error $? "invalid package name: \`$ac_useropt'" + as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt - ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" @@ -1226,9 +1197,9 @@ do ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && - as_fn_error $? "invalid package name: \`$ac_useropt'" + as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt - ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" @@ -1272,9 +1243,9 @@ Try \`$0 --help' for more information" *) # FIXME: should be removed in autoconf 3.0. - printf "%s\n" "$as_me: WARNING: you should use --build, --host, --target" >&2 + $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && - printf "%s\n" "$as_me: WARNING: invalid host type: $ac_option" >&2 + $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" ;; @@ -1290,7 +1261,7 @@ if test -n "$ac_unrecognized_opts"; then case $enable_option_checking in no) ;; fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; - *) printf "%s\n" "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; + *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; esac fi @@ -1354,7 +1325,7 @@ $as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_myself" : 'X\(//\)[^/]' \| \ X"$as_myself" : 'X\(//\)$' \| \ X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || -printf "%s\n" X"$as_myself" | +$as_echo X"$as_myself" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q @@ -1411,7 +1382,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 opensource COBOL 4J 1.1.2 to adapt to many kinds of systems. +\`configure' configures opensource COBOL 4J 1.1.14 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1461,7 +1432,7 @@ Fine tuning of the installation directories: --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root - [DATAROOTDIR/doc/opensource-cobol-4j-1.1.2] + [DATAROOTDIR/doc/opensource-cobol-4j-1.1.14] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] @@ -1483,7 +1454,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of opensource COBOL 4J 1.1.2:";; + short | recursive ) echo "Configuration of opensource COBOL 4J 1.1.14:";; esac cat <<\_ACEOF @@ -1563,9 +1534,9 @@ if test "$ac_init_help" = "recursive"; then case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) - ac_dir_suffix=/`printf "%s\n" "$ac_dir" | sed 's|^\.[\\/]||'` + ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. - ac_top_builddir_sub=`printf "%s\n" "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` + ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; @@ -1593,8 +1564,7 @@ esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix cd "$ac_dir" || { ac_status=$?; continue; } - # Check for configure.gnu first; this name is used for a wrapper for - # Metaconfig's "Configure" on case-insensitive file systems. + # Check for guested configure. if test -f "$ac_srcdir/configure.gnu"; then echo && $SHELL "$ac_srcdir/configure.gnu" --help=recursive @@ -1602,7 +1572,7 @@ ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix echo && $SHELL "$ac_srcdir/configure" --help=recursive else - printf "%s\n" "$as_me: WARNING: no configuration information is in $ac_dir" >&2 + $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 fi || ac_status=$? cd "$ac_pwd" || { ac_status=$?; break; } done @@ -1611,10 +1581,10 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -opensource COBOL 4J configure 1.1.2 -generated by GNU Autoconf 2.71 +opensource COBOL 4J configure 1.1.14 +generated by GNU Autoconf 2.69 -Copyright (C) 2021 Free Software Foundation, Inc. +Copyright (C) 2012 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF @@ -1631,14 +1601,14 @@ fi ac_fn_c_try_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - rm -f conftest.$ac_objext conftest.beam + rm -f conftest.$ac_objext if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -printf "%s\n" "$ac_try_echo"; } >&5 +$as_echo "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>conftest.err ac_status=$? if test -s conftest.err; then @@ -1646,15 +1616,14 @@ printf "%s\n" "$ac_try_echo"; } >&5 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_c_werror_flag" || test ! -s conftest.err - } && test -s conftest.$ac_objext -then : + } && test -s conftest.$ac_objext; then : ac_retval=0 -else $as_nop - printf "%s\n" "$as_me: failed program was:" >&5 +else + $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 @@ -1676,7 +1645,7 @@ case "(($ac_try" in *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -printf "%s\n" "$ac_try_echo"; } >&5 +$as_echo "$ac_try_echo"; } >&5 (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err ac_status=$? if test -s conftest.err; then @@ -1684,15 +1653,14 @@ printf "%s\n" "$ac_try_echo"; } >&5 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } > conftest.i && { test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || test ! -s conftest.err - } -then : + }; then : ac_retval=0 -else $as_nop - printf "%s\n" "$as_me: failed program was:" >&5 +else + $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 @@ -1708,14 +1676,14 @@ fi ac_fn_c_try_link () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - rm -f conftest.$ac_objext conftest.beam conftest$ac_exeext + rm -f conftest.$ac_objext conftest$ac_exeext if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -printf "%s\n" "$ac_try_echo"; } >&5 +$as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>conftest.err ac_status=$? if test -s conftest.err; then @@ -1723,18 +1691,17 @@ printf "%s\n" "$ac_try_echo"; } >&5 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_c_werror_flag" || test ! -s conftest.err } && test -s conftest$ac_exeext && { test "$cross_compiling" = yes || test -x conftest$ac_exeext - } -then : + }; then : ac_retval=0 -else $as_nop - printf "%s\n" "$as_me: failed program was:" >&5 +else + $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 @@ -1756,44 +1723,83 @@ fi ac_fn_c_check_header_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 -printf %s "checking for $2... " >&6; } -if eval test \${$3+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 #include <$2> _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : eval "$3=yes" -else $as_nop +else eval "$3=no" fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi eval ac_res=\$$3 - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -printf "%s\n" "$ac_res" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_header_compile +# ac_fn_c_try_run LINENO +# ---------------------- +# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes +# that executables *can* be run. +ac_fn_c_try_run () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' + { { case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then : + ac_retval=0 +else + $as_echo "$as_me: program exited with status $ac_status" >&5 + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=$ac_status +fi + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_c_try_run + # ac_fn_c_check_func LINENO FUNC VAR # ---------------------------------- # Tests whether FUNC exists, setting the cache variable VAR accordingly ac_fn_c_check_func () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 -printf %s "checking for $2... " >&6; } -if eval test \${$3+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Define $2 to an innocuous variant, in case declares $2. @@ -1801,9 +1807,16 @@ else $as_nop #define $2 innocuous_$2 /* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $2 (); below. */ + which can conflict with char $2 (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif -#include #undef $2 /* Override any GCC internal prototype to avoid an error. @@ -1821,25 +1834,24 @@ choke me #endif int -main (void) +main () { return $2 (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : +if ac_fn_c_try_link "$LINENO"; then : eval "$3=yes" -else $as_nop +else eval "$3=no" fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi eval ac_res=\$$3 - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -printf "%s\n" "$ac_res" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_func @@ -1856,7 +1868,7 @@ case "(($ac_try" in *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -printf "%s\n" "$ac_try_echo"; } >&5 +$as_echo "$ac_try_echo"; } >&5 (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err ac_status=$? if test -s conftest.err; then @@ -1864,15 +1876,14 @@ printf "%s\n" "$ac_try_echo"; } >&5 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } > conftest.i && { test -z "$ac_cxx_preproc_warn_flag$ac_cxx_werror_flag" || test ! -s conftest.err - } -then : + }; then : ac_retval=0 -else $as_nop - printf "%s\n" "$as_me: failed program was:" >&5 +else + $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 @@ -1888,14 +1899,14 @@ fi ac_fn_cxx_try_link () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - rm -f conftest.$ac_objext conftest.beam conftest$ac_exeext + rm -f conftest.$ac_objext conftest$ac_exeext if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -printf "%s\n" "$ac_try_echo"; } >&5 +$as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>conftest.err ac_status=$? if test -s conftest.err; then @@ -1903,18 +1914,17 @@ printf "%s\n" "$ac_try_echo"; } >&5 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_cxx_werror_flag" || test ! -s conftest.err } && test -s conftest$ac_exeext && { test "$cross_compiling" = yes || test -x conftest$ac_exeext - } -then : + }; then : ac_retval=0 -else $as_nop - printf "%s\n" "$as_me: failed program was:" >&5 +else + $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 @@ -1935,14 +1945,14 @@ fi ac_fn_f77_try_link () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - rm -f conftest.$ac_objext conftest.beam conftest$ac_exeext + rm -f conftest.$ac_objext conftest$ac_exeext if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -printf "%s\n" "$ac_try_echo"; } >&5 +$as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>conftest.err ac_status=$? if test -s conftest.err; then @@ -1950,18 +1960,17 @@ printf "%s\n" "$ac_try_echo"; } >&5 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_f77_werror_flag" || test ! -s conftest.err } && test -s conftest$ac_exeext && { test "$cross_compiling" = yes || test -x conftest$ac_exeext - } -then : + }; then : ac_retval=0 -else $as_nop - printf "%s\n" "$as_me: failed program was:" >&5 +else + $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 @@ -1976,48 +1985,96 @@ fi } # ac_fn_f77_try_link -# ac_fn_c_try_run LINENO -# ---------------------- -# Try to run conftest.$ac_ext, and return whether this succeeded. Assumes that -# executables *can* be run. -ac_fn_c_try_run () +# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES +# ------------------------------------------------------- +# Tests whether HEADER exists, giving a warning if it cannot be compiled using +# the include files in INCLUDES and setting the cache variable VAR +# accordingly. +ac_fn_c_check_header_mongrel () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - if { { ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -printf "%s\n" "$ac_try_echo"; } >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' - { { case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -printf "%s\n" "$ac_try_echo"; } >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; } -then : - ac_retval=0 -else $as_nop - printf "%s\n" "$as_me: program exited with status $ac_status" >&5 - printf "%s\n" "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 + if eval \${$3+:} false; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } +else + # Is the header compilable? +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5 +$as_echo_n "checking $2 usability... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +#include <$2> +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_header_compiler=yes +else + ac_header_compiler=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5 +$as_echo "$ac_header_compiler" >&6; } - ac_retval=$ac_status +# Is the header present? +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5 +$as_echo_n "checking $2 presence... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include <$2> +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + ac_header_preproc=yes +else + ac_header_preproc=no +fi +rm -f conftest.err conftest.i conftest.$ac_ext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5 +$as_echo "$ac_header_preproc" >&6; } + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #(( + yes:no: ) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5 +$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 +$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} + ;; + no:yes:* ) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5 +$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: check for missing prerequisite headers?" >&5 +$as_echo "$as_me: WARNING: $2: check for missing prerequisite headers?" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5 +$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&5 +$as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 +$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} +( $as_echo "## ----------------------------------------------------- ## +## Report this to ws-opensource-cobol-contact@osscons.jp ## +## ----------------------------------------------------- ##" + ) | sed "s/^/$as_me: WARNING: /" >&2 + ;; +esac + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + eval "$3=\$ac_header_compiler" +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } fi - rm -rf conftest.dSYM conftest_ipa8_conftest.oo eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno - as_fn_set_status $ac_retval -} # ac_fn_c_try_run +} # ac_fn_c_check_header_mongrel # ac_fn_c_check_type LINENO TYPE VAR INCLUDES # ------------------------------------------- @@ -2026,18 +2083,17 @@ fi ac_fn_c_check_type () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 -printf %s "checking for $2... " >&6; } -if eval test \${$3+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else eval "$3=no" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int -main (void) +main () { if (sizeof ($2)) return 0; @@ -2045,13 +2101,12 @@ if (sizeof ($2)) return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int -main (void) +main () { if (sizeof (($2))) return 0; @@ -2059,50 +2114,29 @@ if (sizeof (($2))) return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : -else $as_nop +else eval "$3=yes" fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi eval ac_res=\$$3 - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -printf "%s\n" "$ac_res" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_type -ac_configure_args_raw= -for ac_arg -do - case $ac_arg in - *\'*) - ac_arg=`printf "%s\n" "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; - esac - as_fn_append ac_configure_args_raw " '$ac_arg'" -done - -case $ac_configure_args_raw in - *$as_nl*) - ac_safe_unquote= ;; - *) - ac_unsafe_z='|&;<>()$`\\"*?[ '' ' # This string ends in space, tab. - ac_unsafe_a="$ac_unsafe_z#~" - ac_safe_unquote="s/ '\\([^$ac_unsafe_a][^$ac_unsafe_z]*\\)'/ \\1/g" - ac_configure_args_raw=` printf "%s\n" "$ac_configure_args_raw" | sed "$ac_safe_unquote"`;; -esac - cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by opensource COBOL 4J $as_me 1.1.2, which was -generated by GNU Autoconf 2.71. Invocation command line was +It was created by opensource COBOL 4J $as_me 1.1.14, which was +generated by GNU Autoconf 2.69. Invocation command line was - $ $0$ac_configure_args_raw + $ $0 $@ _ACEOF exec 5>>config.log @@ -2135,12 +2169,8 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac - printf "%s\n" "PATH: $as_dir" + test -z "$as_dir" && as_dir=. + $as_echo "PATH: $as_dir" done IFS=$as_save_IFS @@ -2175,7 +2205,7 @@ do | -silent | --silent | --silen | --sile | --sil) continue ;; *\'*) - ac_arg=`printf "%s\n" "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; esac case $ac_pass in 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; @@ -2210,13 +2240,11 @@ done # WARNING: Use '\'' to represent an apostrophe within the trap. # WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. trap 'exit_status=$? - # Sanitize IFS. - IFS=" "" $as_nl" # Save into config.log some information that might help in debugging. { echo - printf "%s\n" "## ---------------- ## + $as_echo "## ---------------- ## ## Cache variables. ## ## ---------------- ##" echo @@ -2227,8 +2255,8 @@ trap 'exit_status=$? case $ac_val in #( *${as_nl}*) case $ac_var in #( - *_cv_*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 -printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; + *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( @@ -2252,7 +2280,7 @@ printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ) echo - printf "%s\n" "## ----------------- ## + $as_echo "## ----------------- ## ## Output variables. ## ## ----------------- ##" echo @@ -2260,14 +2288,14 @@ printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} do eval ac_val=\$$ac_var case $ac_val in - *\'\''*) ac_val=`printf "%s\n" "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac - printf "%s\n" "$ac_var='\''$ac_val'\''" + $as_echo "$ac_var='\''$ac_val'\''" done | sort echo if test -n "$ac_subst_files"; then - printf "%s\n" "## ------------------- ## + $as_echo "## ------------------- ## ## File substitutions. ## ## ------------------- ##" echo @@ -2275,15 +2303,15 @@ printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} do eval ac_val=\$$ac_var case $ac_val in - *\'\''*) ac_val=`printf "%s\n" "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac - printf "%s\n" "$ac_var='\''$ac_val'\''" + $as_echo "$ac_var='\''$ac_val'\''" done | sort echo fi if test -s confdefs.h; then - printf "%s\n" "## ----------- ## + $as_echo "## ----------- ## ## confdefs.h. ## ## ----------- ##" echo @@ -2291,8 +2319,8 @@ printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} echo fi test "$ac_signal" != 0 && - printf "%s\n" "$as_me: caught signal $ac_signal" - printf "%s\n" "$as_me: exit $exit_status" + $as_echo "$as_me: caught signal $ac_signal" + $as_echo "$as_me: exit $exit_status" } >&5 rm -f core *.core core.conftest.* && rm -f -r conftest* confdefs* conf$$* $ac_clean_files && @@ -2306,48 +2334,63 @@ ac_signal=0 # confdefs.h avoids OS command line length limits that DEFS can exceed. rm -f -r conftest* confdefs.h -printf "%s\n" "/* confdefs.h */" > confdefs.h +$as_echo "/* confdefs.h */" > confdefs.h # Predefined preprocessor variables. -printf "%s\n" "#define PACKAGE_NAME \"$PACKAGE_NAME\"" >>confdefs.h +cat >>confdefs.h <<_ACEOF +#define PACKAGE_NAME "$PACKAGE_NAME" +_ACEOF -printf "%s\n" "#define PACKAGE_TARNAME \"$PACKAGE_TARNAME\"" >>confdefs.h +cat >>confdefs.h <<_ACEOF +#define PACKAGE_TARNAME "$PACKAGE_TARNAME" +_ACEOF -printf "%s\n" "#define PACKAGE_VERSION \"$PACKAGE_VERSION\"" >>confdefs.h +cat >>confdefs.h <<_ACEOF +#define PACKAGE_VERSION "$PACKAGE_VERSION" +_ACEOF -printf "%s\n" "#define PACKAGE_STRING \"$PACKAGE_STRING\"" >>confdefs.h +cat >>confdefs.h <<_ACEOF +#define PACKAGE_STRING "$PACKAGE_STRING" +_ACEOF -printf "%s\n" "#define PACKAGE_BUGREPORT \"$PACKAGE_BUGREPORT\"" >>confdefs.h +cat >>confdefs.h <<_ACEOF +#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" +_ACEOF -printf "%s\n" "#define PACKAGE_URL \"$PACKAGE_URL\"" >>confdefs.h +cat >>confdefs.h <<_ACEOF +#define PACKAGE_URL "$PACKAGE_URL" +_ACEOF # Let the site file select an alternate cache file if it wants to. # Prefer an explicitly selected file to automatically selected ones. +ac_site_file1=NONE +ac_site_file2=NONE if test -n "$CONFIG_SITE"; then - ac_site_files="$CONFIG_SITE" + # We do not want a PATH search for config.site. + case $CONFIG_SITE in #(( + -*) ac_site_file1=./$CONFIG_SITE;; + */*) ac_site_file1=$CONFIG_SITE;; + *) ac_site_file1=./$CONFIG_SITE;; + esac elif test "x$prefix" != xNONE; then - ac_site_files="$prefix/share/config.site $prefix/etc/config.site" + ac_site_file1=$prefix/share/config.site + ac_site_file2=$prefix/etc/config.site else - ac_site_files="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" + ac_site_file1=$ac_default_prefix/share/config.site + ac_site_file2=$ac_default_prefix/etc/config.site fi - -for ac_site_file in $ac_site_files +for ac_site_file in "$ac_site_file1" "$ac_site_file2" do - case $ac_site_file in #( - */*) : - ;; #( - *) : - ac_site_file=./$ac_site_file ;; -esac - if test -f "$ac_site_file" && test -r "$ac_site_file"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 -printf "%s\n" "$as_me: loading site script $ac_site_file" >&6;} + test "x$ac_site_file" = xNONE && continue + if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 +$as_echo "$as_me: loading site script $ac_site_file" >&6;} sed 's/^/| /' "$ac_site_file" >&5 . "$ac_site_file" \ - || { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} + || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "failed to load site script $ac_site_file See \`config.log' for more details" "$LINENO" 5; } fi @@ -2357,436 +2400,20 @@ if test -r "$cache_file"; then # Some versions of bash will fail to source /dev/null (special files # actually), so we avoid doing that. DJGPP emulates it as a regular file. if test /dev/null != "$cache_file" && test -f "$cache_file"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 -printf "%s\n" "$as_me: loading cache $cache_file" >&6;} + { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 +$as_echo "$as_me: loading cache $cache_file" >&6;} case $cache_file in [\\/]* | ?:[\\/]* ) . "$cache_file";; *) . "./$cache_file";; esac fi -else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 -printf "%s\n" "$as_me: creating cache $cache_file" >&6;} - >$cache_file -fi - -# Test code for whether the C compiler supports C89 (global declarations) -ac_c_conftest_c89_globals=' -/* Does the compiler advertise C89 conformance? - Do not test the value of __STDC__, because some compilers set it to 0 - while being otherwise adequately conformant. */ -#if !defined __STDC__ -# error "Compiler does not advertise C89 conformance" -#endif - -#include -#include -struct stat; -/* Most of the following tests are stolen from RCS 5.7 src/conf.sh. */ -struct buf { int x; }; -struct buf * (*rcsopen) (struct buf *, struct stat *, int); -static char *e (p, i) - char **p; - int i; -{ - return p[i]; -} -static char *f (char * (*g) (char **, int), char **p, ...) -{ - char *s; - va_list v; - va_start (v,p); - s = g (p, va_arg (v,int)); - va_end (v); - return s; -} - -/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has - function prototypes and stuff, but not \xHH hex character constants. - These do not provoke an error unfortunately, instead are silently treated - as an "x". The following induces an error, until -std is added to get - proper ANSI mode. Curiously \x00 != x always comes out true, for an - array size at least. It is necessary to write \x00 == 0 to get something - that is true only with -std. */ -int osf4_cc_array ['\''\x00'\'' == 0 ? 1 : -1]; - -/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters - inside strings and character constants. */ -#define FOO(x) '\''x'\'' -int xlc6_cc_array[FOO(a) == '\''x'\'' ? 1 : -1]; - -int test (int i, double x); -struct s1 {int (*f) (int a);}; -struct s2 {int (*f) (double a);}; -int pairnames (int, char **, int *(*)(struct buf *, struct stat *, int), - int, int);' - -# Test code for whether the C compiler supports C89 (body of main). -ac_c_conftest_c89_main=' -ok |= (argc == 0 || f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]); -' - -# Test code for whether the C compiler supports C99 (global declarations) -ac_c_conftest_c99_globals=' -// Does the compiler advertise C99 conformance? -#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L -# error "Compiler does not advertise C99 conformance" -#endif - -#include -extern int puts (const char *); -extern int printf (const char *, ...); -extern int dprintf (int, const char *, ...); -extern void *malloc (size_t); - -// Check varargs macros. These examples are taken from C99 6.10.3.5. -// dprintf is used instead of fprintf to avoid needing to declare -// FILE and stderr. -#define debug(...) dprintf (2, __VA_ARGS__) -#define showlist(...) puts (#__VA_ARGS__) -#define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__)) -static void -test_varargs_macros (void) -{ - int x = 1234; - int y = 5678; - debug ("Flag"); - debug ("X = %d\n", x); - showlist (The first, second, and third items.); - report (x>y, "x is %d but y is %d", x, y); -} - -// Check long long types. -#define BIG64 18446744073709551615ull -#define BIG32 4294967295ul -#define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0) -#if !BIG_OK - #error "your preprocessor is broken" -#endif -#if BIG_OK -#else - #error "your preprocessor is broken" -#endif -static long long int bignum = -9223372036854775807LL; -static unsigned long long int ubignum = BIG64; - -struct incomplete_array -{ - int datasize; - double data[]; -}; - -struct named_init { - int number; - const wchar_t *name; - double average; -}; - -typedef const char *ccp; - -static inline int -test_restrict (ccp restrict text) -{ - // See if C++-style comments work. - // Iterate through items via the restricted pointer. - // Also check for declarations in for loops. - for (unsigned int i = 0; *(text+i) != '\''\0'\''; ++i) - continue; - return 0; -} - -// Check varargs and va_copy. -static bool -test_varargs (const char *format, ...) -{ - va_list args; - va_start (args, format); - va_list args_copy; - va_copy (args_copy, args); - - const char *str = ""; - int number = 0; - float fnumber = 0; - - while (*format) - { - switch (*format++) - { - case '\''s'\'': // string - str = va_arg (args_copy, const char *); - break; - case '\''d'\'': // int - number = va_arg (args_copy, int); - break; - case '\''f'\'': // float - fnumber = va_arg (args_copy, double); - break; - default: - break; - } - } - va_end (args_copy); - va_end (args); - - return *str && number && fnumber; -} -' - -# Test code for whether the C compiler supports C99 (body of main). -ac_c_conftest_c99_main=' - // Check bool. - _Bool success = false; - success |= (argc != 0); - - // Check restrict. - if (test_restrict ("String literal") == 0) - success = true; - char *restrict newvar = "Another string"; - - // Check varargs. - success &= test_varargs ("s, d'\'' f .", "string", 65, 34.234); - test_varargs_macros (); - - // Check flexible array members. - struct incomplete_array *ia = - malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10)); - ia->datasize = 10; - for (int i = 0; i < ia->datasize; ++i) - ia->data[i] = i * 1.234; - - // Check named initializers. - struct named_init ni = { - .number = 34, - .name = L"Test wide string", - .average = 543.34343, - }; - - ni.number = 58; - - int dynamic_array[ni.number]; - dynamic_array[0] = argv[0][0]; - dynamic_array[ni.number - 1] = 543; - - // work around unused variable warnings - ok |= (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == '\''x'\'' - || dynamic_array[ni.number - 1] != 543); -' - -# Test code for whether the C compiler supports C11 (global declarations) -ac_c_conftest_c11_globals=' -// Does the compiler advertise C11 conformance? -#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L -# error "Compiler does not advertise C11 conformance" -#endif - -// Check _Alignas. -char _Alignas (double) aligned_as_double; -char _Alignas (0) no_special_alignment; -extern char aligned_as_int; -char _Alignas (0) _Alignas (int) aligned_as_int; - -// Check _Alignof. -enum -{ - int_alignment = _Alignof (int), - int_array_alignment = _Alignof (int[100]), - char_alignment = _Alignof (char) -}; -_Static_assert (0 < -_Alignof (int), "_Alignof is signed"); - -// Check _Noreturn. -int _Noreturn does_not_return (void) { for (;;) continue; } - -// Check _Static_assert. -struct test_static_assert -{ - int x; - _Static_assert (sizeof (int) <= sizeof (long int), - "_Static_assert does not work in struct"); - long int y; -}; - -// Check UTF-8 literals. -#define u8 syntax error! -char const utf8_literal[] = u8"happens to be ASCII" "another string"; - -// Check duplicate typedefs. -typedef long *long_ptr; -typedef long int *long_ptr; -typedef long_ptr long_ptr; - -// Anonymous structures and unions -- taken from C11 6.7.2.1 Example 1. -struct anonymous -{ - union { - struct { int i; int j; }; - struct { int k; long int l; } w; - }; - int m; -} v1; -' - -# Test code for whether the C compiler supports C11 (body of main). -ac_c_conftest_c11_main=' - _Static_assert ((offsetof (struct anonymous, i) - == offsetof (struct anonymous, w.k)), - "Anonymous union alignment botch"); - v1.i = 2; - v1.w.k = 5; - ok |= v1.i != 5; -' - -# Test code for whether the C compiler supports C11 (complete). -ac_c_conftest_c11_program="${ac_c_conftest_c89_globals} -${ac_c_conftest_c99_globals} -${ac_c_conftest_c11_globals} - -int -main (int argc, char **argv) -{ - int ok = 0; - ${ac_c_conftest_c89_main} - ${ac_c_conftest_c99_main} - ${ac_c_conftest_c11_main} - return ok; -} -" - -# Test code for whether the C compiler supports C99 (complete). -ac_c_conftest_c99_program="${ac_c_conftest_c89_globals} -${ac_c_conftest_c99_globals} - -int -main (int argc, char **argv) -{ - int ok = 0; - ${ac_c_conftest_c89_main} - ${ac_c_conftest_c99_main} - return ok; -} -" - -# Test code for whether the C compiler supports C89 (complete). -ac_c_conftest_c89_program="${ac_c_conftest_c89_globals} - -int -main (int argc, char **argv) -{ - int ok = 0; - ${ac_c_conftest_c89_main} - return ok; -} -" - -as_fn_append ac_header_c_list " stdio.h stdio_h HAVE_STDIO_H" -as_fn_append ac_header_c_list " stdlib.h stdlib_h HAVE_STDLIB_H" -as_fn_append ac_header_c_list " string.h string_h HAVE_STRING_H" -as_fn_append ac_header_c_list " inttypes.h inttypes_h HAVE_INTTYPES_H" -as_fn_append ac_header_c_list " stdint.h stdint_h HAVE_STDINT_H" -as_fn_append ac_header_c_list " strings.h strings_h HAVE_STRINGS_H" -as_fn_append ac_header_c_list " sys/stat.h sys_stat_h HAVE_SYS_STAT_H" -as_fn_append ac_header_c_list " sys/types.h sys_types_h HAVE_SYS_TYPES_H" -as_fn_append ac_header_c_list " unistd.h unistd_h HAVE_UNISTD_H" -as_fn_append ac_func_c_list " vprintf HAVE_VPRINTF" -gt_needs="$gt_needs " - -# Auxiliary files required by this configure script. -ac_aux_files="config.rpath ltmain.sh config.guess config.sub compile missing install-sh" - -# Locations in which to look for auxiliary files. -ac_aux_dir_candidates="${srcdir}${PATH_SEPARATOR}${srcdir}/..${PATH_SEPARATOR}${srcdir}/../.." - -# Search for a directory containing all of the required auxiliary files, -# $ac_aux_files, from the $PATH-style list $ac_aux_dir_candidates. -# If we don't find one directory that contains all the files we need, -# we report the set of missing files from the *first* directory in -# $ac_aux_dir_candidates and give up. -ac_missing_aux_files="" -ac_first_candidate=: -printf "%s\n" "$as_me:${as_lineno-$LINENO}: looking for aux files: $ac_aux_files" >&5 -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -as_found=false -for as_dir in $ac_aux_dir_candidates -do - IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac - as_found=: - - printf "%s\n" "$as_me:${as_lineno-$LINENO}: trying $as_dir" >&5 - ac_aux_dir_found=yes - ac_install_sh= - for ac_aux in $ac_aux_files - do - # As a special case, if "install-sh" is required, that requirement - # can be satisfied by any of "install-sh", "install.sh", or "shtool", - # and $ac_install_sh is set appropriately for whichever one is found. - if test x"$ac_aux" = x"install-sh" - then - if test -f "${as_dir}install-sh"; then - printf "%s\n" "$as_me:${as_lineno-$LINENO}: ${as_dir}install-sh found" >&5 - ac_install_sh="${as_dir}install-sh -c" - elif test -f "${as_dir}install.sh"; then - printf "%s\n" "$as_me:${as_lineno-$LINENO}: ${as_dir}install.sh found" >&5 - ac_install_sh="${as_dir}install.sh -c" - elif test -f "${as_dir}shtool"; then - printf "%s\n" "$as_me:${as_lineno-$LINENO}: ${as_dir}shtool found" >&5 - ac_install_sh="${as_dir}shtool install -c" - else - ac_aux_dir_found=no - if $ac_first_candidate; then - ac_missing_aux_files="${ac_missing_aux_files} install-sh" - else - break - fi - fi - else - if test -f "${as_dir}${ac_aux}"; then - printf "%s\n" "$as_me:${as_lineno-$LINENO}: ${as_dir}${ac_aux} found" >&5 - else - ac_aux_dir_found=no - if $ac_first_candidate; then - ac_missing_aux_files="${ac_missing_aux_files} ${ac_aux}" - else - break - fi - fi - fi - done - if test "$ac_aux_dir_found" = yes; then - ac_aux_dir="$as_dir" - break - fi - ac_first_candidate=false - - as_found=false -done -IFS=$as_save_IFS -if $as_found -then : - -else $as_nop - as_fn_error $? "cannot find required auxiliary files:$ac_missing_aux_files" "$LINENO" 5 -fi - - -# These three variables are undocumented and unsupported, -# and are intended to be withdrawn in a future Autoconf release. -# They can cause serious problems if a builder's source tree is in a directory -# whose full name contains unusual characters. -if test -f "${ac_aux_dir}config.guess"; then - ac_config_guess="$SHELL ${ac_aux_dir}config.guess" -fi -if test -f "${ac_aux_dir}config.sub"; then - ac_config_sub="$SHELL ${ac_aux_dir}config.sub" -fi -if test -f "$ac_aux_dir/configure"; then - ac_configure="$SHELL ${ac_aux_dir}configure" +else + { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 +$as_echo "$as_me: creating cache $cache_file" >&6;} + >$cache_file fi +gt_needs="$gt_needs " # Check that the precious variables saved in the cache have kept the same # value. ac_cache_corrupted=false @@ -2797,12 +2424,12 @@ for ac_var in $ac_precious_vars; do eval ac_new_val=\$ac_env_${ac_var}_value case $ac_old_set,$ac_new_set in set,) - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 -printf "%s\n" "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 +$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} ac_cache_corrupted=: ;; ,set) - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 -printf "%s\n" "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 +$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} ac_cache_corrupted=: ;; ,);; *) @@ -2811,24 +2438,24 @@ printf "%s\n" "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} ac_old_val_w=`echo x $ac_old_val` ac_new_val_w=`echo x $ac_new_val` if test "$ac_old_val_w" != "$ac_new_val_w"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 -printf "%s\n" "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 +$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} ac_cache_corrupted=: else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 -printf "%s\n" "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 +$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} eval $ac_var=\$ac_old_val fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 -printf "%s\n" "$as_me: former value: \`$ac_old_val'" >&2;} - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 -printf "%s\n" "$as_me: current value: \`$ac_new_val'" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 +$as_echo "$as_me: former value: \`$ac_old_val'" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 +$as_echo "$as_me: current value: \`$ac_new_val'" >&2;} fi;; esac # Pass precious variables to config.status. if test "$ac_new_set" = set; then case $ac_new_val in - *\'*) ac_arg=$ac_var=`printf "%s\n" "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; + *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; *) ac_arg=$ac_var=$ac_new_val ;; esac case " $ac_configure_args " in @@ -2838,12 +2465,11 @@ printf "%s\n" "$as_me: current value: \`$ac_new_val'" >&2;} fi done if $ac_cache_corrupted; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 -printf "%s\n" "$as_me: error: changes in the environment can compromise the build" >&2;} - as_fn_error $? "run \`${MAKE-make} distclean' and/or \`rm $cache_file' - and start over" "$LINENO" 5 + { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 +$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} + as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 fi ## -------------------- ## ## Main body of script. ## @@ -2886,9 +2512,36 @@ fi am__api_version='1.16' +ac_aux_dir= +for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do + if test -f "$ac_dir/install-sh"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install-sh -c" + break + elif test -f "$ac_dir/install.sh"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install.sh -c" + break + elif test -f "$ac_dir/shtool"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/shtool install -c" + break + fi +done +if test -z "$ac_aux_dir"; then + as_fn_error $? "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5 +fi + +# These three variables are undocumented and unsupported, +# and are intended to be withdrawn in a future Autoconf release. +# They can cause serious problems if a builder's source tree is in a directory +# whose full name contains unusual characters. +ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var. +ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var. +ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. - # Find a good install program. We prefer a C program (faster), +# Find a good install program. We prefer a C program (faster), # so one script is as good as another. But avoid the broken or # incompatible versions: # SysV /etc/install, /usr/sbin/install @@ -2902,25 +2555,20 @@ am__api_version='1.16' # OS/2's system install, which has a completely different semantic # ./install, which can be erroneously created by make from ./install.sh. # Reject install programs that cannot install multiple files. -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5 -printf %s "checking for a BSD-compatible install... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5 +$as_echo_n "checking for a BSD-compatible install... " >&6; } if test -z "$INSTALL"; then -if test ${ac_cv_path_install+y} -then : - printf %s "(cached) " >&6 -else $as_nop +if ${ac_cv_path_install+:} false; then : + $as_echo_n "(cached) " >&6 +else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac - # Account for fact that we put trailing slashes in our PATH walk. -case $as_dir in #(( - ./ | /[cC]/* | \ + test -z "$as_dir" && as_dir=. + # Account for people who put trailing slashes in PATH elements. +case $as_dir/ in #(( + ./ | .// | /[cC]/* | \ /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \ /usr/ucb/* ) ;; @@ -2930,13 +2578,13 @@ case $as_dir in #(( # by default. for ac_prog in ginstall scoinst install; do for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_prog$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then if test $ac_prog = install && - grep dspmsg "$as_dir$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # AIX install. It has an incompatible calling convention. : elif test $ac_prog = install && - grep pwplus "$as_dir$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # program-specific install script used by HP pwplus--don't use. : else @@ -2944,12 +2592,12 @@ case $as_dir in #(( echo one > conftest.one echo two > conftest.two mkdir conftest.dir - if "$as_dir$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir/" && + if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" && test -s conftest.one && test -s conftest.two && test -s conftest.dir/conftest.one && test -s conftest.dir/conftest.two then - ac_cv_path_install="$as_dir$ac_prog$ac_exec_ext -c" + ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" break 3 fi fi @@ -2965,7 +2613,7 @@ IFS=$as_save_IFS rm -rf conftest.one conftest.two conftest.dir fi - if test ${ac_cv_path_install+y}; then + if test "${ac_cv_path_install+set}" = set; then INSTALL=$ac_cv_path_install else # As a last resort, use the slow shell script. Don't cache a @@ -2975,8 +2623,8 @@ fi INSTALL=$ac_install_sh fi fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5 -printf "%s\n" "$INSTALL" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5 +$as_echo "$INSTALL" >&6; } # Use test -z because SunOS4 sh mishandles braces in ${var-val}. # It thinks the first close brace ends the variable substitution. @@ -2986,8 +2634,8 @@ test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether build environment is sane" >&5 -printf %s "checking whether build environment is sane... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether build environment is sane" >&5 +$as_echo_n "checking whether build environment is sane... " >&6; } # Reject unsafe characters in $srcdir or the absolute working directory # name. Accept space and tab only in the latter. am_lf=' @@ -3041,8 +2689,8 @@ else as_fn_error $? "newly created file is older than distributed files! Check your system clock" "$LINENO" 5 fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -printf "%s\n" "yes" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } # If we didn't sleep, we still need to ensure time stamps of config.status and # generated files are strictly newer. am_sleep_pid= @@ -3061,23 +2709,26 @@ test "$program_suffix" != NONE && # Double any \ or $. # By default was `s,x,x', remove it if useless. ac_script='s/[\\$]/&&/g;s/;s,x,x,$//' -program_transform_name=`printf "%s\n" "$program_transform_name" | sed "$ac_script"` - +program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"` # Expand $ac_aux_dir to an absolute path. am_aux_dir=`cd "$ac_aux_dir" && pwd` - - if test x"${MISSING+set}" != xset; then - MISSING="\${SHELL} '$am_aux_dir/missing'" +if test x"${MISSING+set}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; + *) + MISSING="\${SHELL} $am_aux_dir/missing" ;; + esac fi # Use eval to expand $SHELL if eval "$MISSING --is-lightweight"; then am_missing_run="$MISSING " else am_missing_run= - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: 'missing' script is too old or missing" >&5 -printf "%s\n" "$as_me: WARNING: 'missing' script is too old or missing" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 'missing' script is too old or missing" >&5 +$as_echo "$as_me: WARNING: 'missing' script is too old or missing" >&2;} fi if test x"${install_sh+set}" != xset; then @@ -3097,12 +2748,11 @@ if test "$cross_compiling" != no; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. set dummy ${ac_tool_prefix}strip; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_STRIP+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_STRIP+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$STRIP"; then ac_cv_prog_STRIP="$STRIP" # Let the user override the test. else @@ -3110,15 +2760,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_STRIP="${ac_tool_prefix}strip" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3129,11 +2775,11 @@ fi fi STRIP=$ac_cv_prog_STRIP if test -n "$STRIP"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 -printf "%s\n" "$STRIP" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 +$as_echo "$STRIP" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi @@ -3142,12 +2788,11 @@ if test -z "$ac_cv_prog_STRIP"; then ac_ct_STRIP=$STRIP # Extract the first word of "strip", so it can be a program name with args. set dummy strip; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_ac_ct_STRIP+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_STRIP+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$ac_ct_STRIP"; then ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. else @@ -3155,15 +2800,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_STRIP="strip" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3174,11 +2815,11 @@ fi fi ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP if test -n "$ac_ct_STRIP"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 -printf "%s\n" "$ac_ct_STRIP" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 +$as_echo "$ac_ct_STRIP" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi if test "x$ac_ct_STRIP" = x; then @@ -3186,8 +2827,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac STRIP=$ac_ct_STRIP @@ -3199,31 +2840,25 @@ fi fi INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" - - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a race-free mkdir -p" >&5 -printf %s "checking for a race-free mkdir -p... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a thread-safe mkdir -p" >&5 +$as_echo_n "checking for a thread-safe mkdir -p... " >&6; } if test -z "$MKDIR_P"; then - if test ${ac_cv_path_mkdir+y} -then : - printf %s "(cached) " >&6 -else $as_nop + if ${ac_cv_path_mkdir+:} false; then : + $as_echo_n "(cached) " >&6 +else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/opt/sfw/bin do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_prog in mkdir gmkdir; do for ac_exec_ext in '' $ac_executable_extensions; do - as_fn_executable_p "$as_dir$ac_prog$ac_exec_ext" || continue - case `"$as_dir$ac_prog$ac_exec_ext" --version 2>&1` in #( - 'mkdir ('*'coreutils) '* | \ - 'BusyBox '* | \ + as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext" || continue + case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #( + 'mkdir (GNU coreutils) '* | \ + 'mkdir (coreutils) '* | \ 'mkdir (fileutils) '4.1*) - ac_cv_path_mkdir=$as_dir$ac_prog$ac_exec_ext + ac_cv_path_mkdir=$as_dir/$ac_prog$ac_exec_ext break 3;; esac done @@ -3234,7 +2869,7 @@ IFS=$as_save_IFS fi test -d ./--version && rmdir ./--version - if test ${ac_cv_path_mkdir+y}; then + if test "${ac_cv_path_mkdir+set}" = set; then MKDIR_P="$ac_cv_path_mkdir -p" else # As a last resort, use the slow shell script. Don't cache a @@ -3244,19 +2879,18 @@ fi MKDIR_P="$ac_install_sh -d" fi fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5 -printf "%s\n" "$MKDIR_P" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5 +$as_echo "$MKDIR_P" >&6; } for ac_prog in gawk mawk nawk awk do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_AWK+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_AWK+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$AWK"; then ac_cv_prog_AWK="$AWK" # Let the user override the test. else @@ -3264,15 +2898,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_AWK="$ac_prog" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3283,25 +2913,24 @@ fi fi AWK=$ac_cv_prog_AWK if test -n "$AWK"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5 -printf "%s\n" "$AWK" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5 +$as_echo "$AWK" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi test -n "$AWK" && break done -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 -printf %s "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 +$as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; } set x ${MAKE-make} -ac_make=`printf "%s\n" "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` -if eval test \${ac_cv_prog_make_${ac_make}_set+y} -then : - printf %s "(cached) " >&6 -else $as_nop +ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` +if eval \${ac_cv_prog_make_${ac_make}_set+:} false; then : + $as_echo_n "(cached) " >&6 +else cat >conftest.make <<\_ACEOF SHELL = /bin/sh all: @@ -3317,12 +2946,12 @@ esac rm -f conftest.make fi if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -printf "%s\n" "yes" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } SET_MAKE= else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } SET_MAKE="MAKE=${MAKE-make}" fi @@ -3336,8 +2965,7 @@ fi rmdir .tst 2>/dev/null # Check whether --enable-silent-rules was given. -if test ${enable_silent_rules+y} -then : +if test "${enable_silent_rules+set}" = set; then : enableval=$enable_silent_rules; fi @@ -3347,13 +2975,12 @@ case $enable_silent_rules in # ((( *) AM_DEFAULT_VERBOSITY=1;; esac am_make=${MAKE-make} -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $am_make supports nested variables" >&5 -printf %s "checking whether $am_make supports nested variables... " >&6; } -if test ${am_cv_make_support_nested_variables+y} -then : - printf %s "(cached) " >&6 -else $as_nop - if printf "%s\n" 'TRUE=$(BAR$(V)) +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $am_make supports nested variables" >&5 +$as_echo_n "checking whether $am_make supports nested variables... " >&6; } +if ${am_cv_make_support_nested_variables+:} false; then : + $as_echo_n "(cached) " >&6 +else + if $as_echo 'TRUE=$(BAR$(V)) BAR0=false BAR1=true V=1 @@ -3365,8 +2992,8 @@ else am_cv_make_support_nested_variables=no fi fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_make_support_nested_variables" >&5 -printf "%s\n" "$am_cv_make_support_nested_variables" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_make_support_nested_variables" >&5 +$as_echo "$am_cv_make_support_nested_variables" >&6; } if test $am_cv_make_support_nested_variables = yes; then AM_V='$(V)' AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)' @@ -3397,14 +3024,18 @@ fi # Define the identity of the package. - PACKAGE='opensource-cobol-4j-1.1.2' - VERSION='1.1.2' + PACKAGE='opensource-cobol-4j-1.1.14' + VERSION='1.1.14' -printf "%s\n" "#define PACKAGE \"$PACKAGE\"" >>confdefs.h +cat >>confdefs.h <<_ACEOF +#define PACKAGE "$PACKAGE" +_ACEOF -printf "%s\n" "#define VERSION \"$VERSION\"" >>confdefs.h +cat >>confdefs.h <<_ACEOF +#define VERSION "$VERSION" +_ACEOF # Some tools Automake needs. @@ -3444,20 +3075,6 @@ am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -' -# Variables for tags utilities; see am/tags.am -if test -z "$CTAGS"; then - CTAGS=ctags -fi - -if test -z "$ETAGS"; then - ETAGS=etags -fi - -if test -z "$CSCOPE"; then - CSCOPE=cscope -fi - - # POSIX will say in a future version that running "rm -f" with no argument # is OK; and we want to be able to make that assumption in our Makefile @@ -3502,18 +3119,17 @@ END fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5 -printf %s "checking whether to enable maintainer-specific portions of Makefiles... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5 +$as_echo_n "checking whether to enable maintainer-specific portions of Makefiles... " >&6; } # Check whether --enable-maintainer-mode was given. -if test ${enable_maintainer_mode+y} -then : +if test "${enable_maintainer_mode+set}" = set; then : enableval=$enable_maintainer_mode; USE_MAINTAINER_MODE=$enableval -else $as_nop +else USE_MAINTAINER_MODE=no fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $USE_MAINTAINER_MODE" >&5 -printf "%s\n" "$USE_MAINTAINER_MODE" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $USE_MAINTAINER_MODE" >&5 +$as_echo "$USE_MAINTAINER_MODE" >&6; } if test $USE_MAINTAINER_MODE = yes; then MAINTAINER_MODE_TRUE= MAINTAINER_MODE_FALSE='#' @@ -3549,8 +3165,7 @@ fi - -printf "%s\n" "#define __USE_STRING_INLINES 1" >>confdefs.h +$as_echo "#define __USE_STRING_INLINES 1" >>confdefs.h LIBCOB_LIBS="-lm" @@ -3558,15 +3173,6 @@ LIBCOB_CFLAGS="$lt_prog_compiler_pic" save_libs="$LIBS" - - - - - - - - - ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -3577,12 +3183,11 @@ if test -n "$ac_tool_prefix"; then do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_CC+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else @@ -3590,15 +3195,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="$ac_tool_prefix$ac_prog" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3609,11 +3210,11 @@ fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 -printf "%s\n" "$CC" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi @@ -3626,12 +3227,11 @@ if test -z "$CC"; then do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_ac_ct_CC+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else @@ -3639,15 +3239,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CC="$ac_prog" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3658,11 +3254,11 @@ fi fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 -printf "%s\n" "$ac_ct_CC" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi @@ -3674,8 +3270,8 @@ done else case $cross_compiling:$ac_tool_warned in yes:) -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC @@ -3683,23 +3279,23 @@ esac fi -test -z "$CC" && { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "no acceptable C compiler found in \$PATH See \`config.log' for more details" "$LINENO" 5; } # Provide some information about the compiler. -printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 +$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 set X $ac_compile ac_compiler=$2 -for ac_option in --version -v -V -qversion -version; do +for ac_option in --version -v -V -qversion; do { { ac_try="$ac_compiler $ac_option >&5" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -printf "%s\n" "$ac_try_echo"; } >&5 +$as_echo "$ac_try_echo"; } >&5 (eval "$ac_compiler $ac_option >&5") 2>conftest.err ac_status=$? if test -s conftest.err; then @@ -3709,7 +3305,7 @@ printf "%s\n" "$ac_try_echo"; } >&5 cat conftest.er1 >&5 fi rm -f conftest.er1 conftest.err - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } done @@ -3717,7 +3313,7 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main (void) +main () { ; @@ -3729,9 +3325,9 @@ ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" # Try to create an executable without -o first, disregard a.out. # It will help us diagnose broken compilers, and finding out an intuition # of exeext. -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 -printf %s "checking whether the C compiler works... " >&6; } -ac_link_default=`printf "%s\n" "$ac_link" | sed 's/ -o *conftest[^ ]*//'` +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 +$as_echo_n "checking whether the C compiler works... " >&6; } +ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` # The possible output files: ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" @@ -3752,12 +3348,11 @@ case "(($ac_try" in *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -printf "%s\n" "$ac_try_echo"; } >&5 +$as_echo "$ac_try_echo"; } >&5 (eval "$ac_link_default") 2>&5 ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } -then : + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. # So ignore a value of `no', otherwise this would lead to `EXEEXT = no' # in a Makefile. We should not override ac_cv_exeext if it was cached, @@ -3774,7 +3369,7 @@ do # certainly right. break;; *.* ) - if test ${ac_cv_exeext+y} && test "$ac_cv_exeext" != no; + if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; then :; else ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` fi @@ -3790,46 +3385,44 @@ do done test "$ac_cv_exeext" = no && ac_cv_exeext= -else $as_nop +else ac_file='' fi -if test -z "$ac_file" -then : - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } -printf "%s\n" "$as_me: failed program was:" >&5 +if test -z "$ac_file"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +$as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 -{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "C compiler cannot create executables See \`config.log' for more details" "$LINENO" 5; } -else $as_nop - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -printf "%s\n" "yes" >&6; } -fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 -printf %s "checking for C compiler default output file name... " >&6; } -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 -printf "%s\n" "$ac_file" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 +$as_echo_n "checking for C compiler default output file name... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 +$as_echo "$ac_file" >&6; } ac_exeext=$ac_cv_exeext rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out ac_clean_files=$ac_clean_files_save -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 -printf %s "checking for suffix of executables... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 +$as_echo_n "checking for suffix of executables... " >&6; } if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -printf "%s\n" "$ac_try_echo"; } >&5 +$as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } -then : + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : # If both `conftest.exe' and `conftest' are `present' (well, observable) # catch `conftest.exe'. For instance with Cygwin, `ls conftest' will # work properly (i.e., refer to `conftest.exe'), while it won't with @@ -3843,15 +3436,15 @@ for ac_file in conftest.exe conftest conftest.*; do * ) break;; esac done -else $as_nop - { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of executables: cannot compile and link See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest conftest$ac_cv_exeext -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 -printf "%s\n" "$ac_cv_exeext" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 +$as_echo "$ac_cv_exeext" >&6; } rm -f conftest.$ac_ext EXEEXT=$ac_cv_exeext @@ -3860,7 +3453,7 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int -main (void) +main () { FILE *f = fopen ("conftest.out", "w"); return ferror (f) || fclose (f) != 0; @@ -3872,8 +3465,8 @@ _ACEOF ac_clean_files="$ac_clean_files conftest.out" # Check that the compiler produces executables we can run. If not, either # the compiler is broken, or we cross compile. -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 -printf %s "checking whether we are cross compiling... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 +$as_echo_n "checking whether we are cross compiling... " >&6; } if test "$cross_compiling" != yes; then { { ac_try="$ac_link" case "(($ac_try" in @@ -3881,10 +3474,10 @@ case "(($ac_try" in *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -printf "%s\n" "$ac_try_echo"; } >&5 +$as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if { ac_try='./conftest$ac_cv_exeext' { { case "(($ac_try" in @@ -3892,40 +3485,39 @@ printf "%s\n" "$ac_try_echo"; } >&5 *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -printf "%s\n" "$ac_try_echo"; } >&5 +$as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then cross_compiling=no else if test "$cross_compiling" = maybe; then cross_compiling=yes else - { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} -as_fn_error 77 "cannot run C compiled programs. + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot run C compiled programs. If you meant to cross compile, use \`--host'. See \`config.log' for more details" "$LINENO" 5; } fi fi fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 -printf "%s\n" "$cross_compiling" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 +$as_echo "$cross_compiling" >&6; } rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out ac_clean_files=$ac_clean_files_save -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 -printf %s "checking for suffix of object files... " >&6; } -if test ${ac_cv_objext+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 +$as_echo_n "checking for suffix of object files... " >&6; } +if ${ac_cv_objext+:} false; then : + $as_echo_n "(cached) " >&6 +else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main (void) +main () { ; @@ -3939,12 +3531,11 @@ case "(($ac_try" in *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -printf "%s\n" "$ac_try_echo"; } >&5 +$as_echo "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>&5 ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } -then : + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : for ac_file in conftest.o conftest.obj conftest.*; do test -f "$ac_file" || continue; case $ac_file in @@ -3953,32 +3544,31 @@ then : break;; esac done -else $as_nop - printf "%s\n" "$as_me: failed program was:" >&5 +else + $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 -{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of object files: cannot compile See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest.$ac_cv_objext conftest.$ac_ext fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 -printf "%s\n" "$ac_cv_objext" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 +$as_echo "$ac_cv_objext" >&6; } OBJEXT=$ac_cv_objext ac_objext=$OBJEXT -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports GNU C" >&5 -printf %s "checking whether the compiler supports GNU C... " >&6; } -if test ${ac_cv_c_compiler_gnu+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 +$as_echo_n "checking whether we are using the GNU C compiler... " >&6; } +if ${ac_cv_c_compiler_gnu+:} false; then : + $as_echo_n "(cached) " >&6 +else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main (void) +main () { #ifndef __GNUC__ choke me @@ -3988,33 +3578,29 @@ main (void) return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : ac_compiler_gnu=yes -else $as_nop +else ac_compiler_gnu=no fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_cv_c_compiler_gnu=$ac_compiler_gnu fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 -printf "%s\n" "$ac_cv_c_compiler_gnu" >&6; } -ac_compiler_gnu=$ac_cv_c_compiler_gnu - +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 +$as_echo "$ac_cv_c_compiler_gnu" >&6; } if test $ac_compiler_gnu = yes; then GCC=yes else GCC= fi -ac_test_CFLAGS=${CFLAGS+y} +ac_test_CFLAGS=${CFLAGS+set} ac_save_CFLAGS=$CFLAGS -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 -printf %s "checking whether $CC accepts -g... " >&6; } -if test ${ac_cv_prog_cc_g+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 +$as_echo_n "checking whether $CC accepts -g... " >&6; } +if ${ac_cv_prog_cc_g+:} false; then : + $as_echo_n "(cached) " >&6 +else ac_save_c_werror_flag=$ac_c_werror_flag ac_c_werror_flag=yes ac_cv_prog_cc_g=no @@ -4023,60 +3609,57 @@ else $as_nop /* end confdefs.h. */ int -main (void) +main () { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_g=yes -else $as_nop +else CFLAGS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main (void) +main () { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : -else $as_nop +else ac_c_werror_flag=$ac_save_c_werror_flag CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main (void) +main () { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_g=yes fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_c_werror_flag=$ac_save_c_werror_flag fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 -printf "%s\n" "$ac_cv_prog_cc_g" >&6; } -if test $ac_test_CFLAGS; then +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 +$as_echo "$ac_cv_prog_cc_g" >&6; } +if test "$ac_test_CFLAGS" = set; then CFLAGS=$ac_save_CFLAGS elif test $ac_cv_prog_cc_g = yes; then if test "$GCC" = yes; then @@ -4091,144 +3674,94 @@ else CFLAGS= fi fi -ac_prog_cc_stdc=no -if test x$ac_prog_cc_stdc = xno -then : - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C11 features" >&5 -printf %s "checking for $CC option to enable C11 features... " >&6; } -if test ${ac_cv_prog_cc_c11+y} -then : - printf %s "(cached) " >&6 -else $as_nop - ac_cv_prog_cc_c11=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 +$as_echo_n "checking for $CC option to accept ISO C89... " >&6; } +if ${ac_cv_prog_cc_c89+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_cv_prog_cc_c89=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -$ac_c_conftest_c11_program -_ACEOF -for ac_arg in '' -std=gnu11 -do - CC="$ac_save_CC $ac_arg" - if ac_fn_c_try_compile "$LINENO" -then : - ac_cv_prog_cc_c11=$ac_arg -fi -rm -f core conftest.err conftest.$ac_objext conftest.beam - test "x$ac_cv_prog_cc_c11" != "xno" && break -done -rm -f conftest.$ac_ext -CC=$ac_save_CC -fi +#include +#include +struct stat; +/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ +struct buf { int x; }; +FILE * (*rcsopen) (struct buf *, struct stat *, int); +static char *e (p, i) + char **p; + int i; +{ + return p[i]; +} +static char *f (char * (*g) (char **, int), char **p, ...) +{ + char *s; + va_list v; + va_start (v,p); + s = g (p, va_arg (v,int)); + va_end (v); + return s; +} -if test "x$ac_cv_prog_cc_c11" = xno -then : - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 -printf "%s\n" "unsupported" >&6; } -else $as_nop - if test "x$ac_cv_prog_cc_c11" = x -then : - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 -printf "%s\n" "none needed" >&6; } -else $as_nop - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c11" >&5 -printf "%s\n" "$ac_cv_prog_cc_c11" >&6; } - CC="$CC $ac_cv_prog_cc_c11" -fi - ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c11 - ac_prog_cc_stdc=c11 -fi -fi -if test x$ac_prog_cc_stdc = xno -then : - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C99 features" >&5 -printf %s "checking for $CC option to enable C99 features... " >&6; } -if test ${ac_cv_prog_cc_c99+y} -then : - printf %s "(cached) " >&6 -else $as_nop - ac_cv_prog_cc_c99=no -ac_save_CC=$CC -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -$ac_c_conftest_c99_program -_ACEOF -for ac_arg in '' -std=gnu99 -std=c99 -c99 -qlanglvl=extc1x -qlanglvl=extc99 -AC99 -D_STDC_C99= -do - CC="$ac_save_CC $ac_arg" - if ac_fn_c_try_compile "$LINENO" -then : - ac_cv_prog_cc_c99=$ac_arg -fi -rm -f core conftest.err conftest.$ac_objext conftest.beam - test "x$ac_cv_prog_cc_c99" != "xno" && break -done -rm -f conftest.$ac_ext -CC=$ac_save_CC -fi +/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has + function prototypes and stuff, but not '\xHH' hex character constants. + These don't provoke an error unfortunately, instead are silently treated + as 'x'. The following induces an error, until -std is added to get + proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an + array size at least. It's necessary to write '\x00'==0 to get something + that's true only with -std. */ +int osf4_cc_array ['\x00' == 0 ? 1 : -1]; -if test "x$ac_cv_prog_cc_c99" = xno -then : - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 -printf "%s\n" "unsupported" >&6; } -else $as_nop - if test "x$ac_cv_prog_cc_c99" = x -then : - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 -printf "%s\n" "none needed" >&6; } -else $as_nop - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c99" >&5 -printf "%s\n" "$ac_cv_prog_cc_c99" >&6; } - CC="$CC $ac_cv_prog_cc_c99" -fi - ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99 - ac_prog_cc_stdc=c99 -fi -fi -if test x$ac_prog_cc_stdc = xno -then : - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C89 features" >&5 -printf %s "checking for $CC option to enable C89 features... " >&6; } -if test ${ac_cv_prog_cc_c89+y} -then : - printf %s "(cached) " >&6 -else $as_nop - ac_cv_prog_cc_c89=no -ac_save_CC=$CC -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -$ac_c_conftest_c89_program +/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters + inside strings and character constants. */ +#define FOO(x) 'x' +int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; + +int test (int i, double x); +struct s1 {int (*f) (int a);}; +struct s2 {int (*f) (double a);}; +int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); +int argc; +char **argv; +int +main () +{ +return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; + ; + return 0; +} _ACEOF -for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ + -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" do CC="$ac_save_CC $ac_arg" - if ac_fn_c_try_compile "$LINENO" -then : + if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_c89=$ac_arg fi -rm -f core conftest.err conftest.$ac_objext conftest.beam +rm -f core conftest.err conftest.$ac_objext test "x$ac_cv_prog_cc_c89" != "xno" && break done rm -f conftest.$ac_ext CC=$ac_save_CC -fi -if test "x$ac_cv_prog_cc_c89" = xno -then : - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 -printf "%s\n" "unsupported" >&6; } -else $as_nop - if test "x$ac_cv_prog_cc_c89" = x -then : - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 -printf "%s\n" "none needed" >&6; } -else $as_nop - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 -printf "%s\n" "$ac_cv_prog_cc_c89" >&6; } - CC="$CC $ac_cv_prog_cc_c89" -fi - ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89 - ac_prog_cc_stdc=c89 fi +# AC_CACHE_VAL +case "x$ac_cv_prog_cc_c89" in + x) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +$as_echo "none needed" >&6; } ;; + xno) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +$as_echo "unsupported" >&6; } ;; + *) + CC="$CC $ac_cv_prog_cc_c89" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 +$as_echo "$ac_cv_prog_cc_c89" >&6; } ;; +esac +if test "x$ac_cv_prog_cc_c89" != xno; then : + fi ac_ext=c @@ -4237,23 +3770,21 @@ ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu - - ac_ext=c +ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC understands -c and -o together" >&5 -printf %s "checking whether $CC understands -c and -o together... " >&6; } -if test ${am_cv_prog_cc_c_o+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC understands -c and -o together" >&5 +$as_echo_n "checking whether $CC understands -c and -o together... " >&6; } +if ${am_cv_prog_cc_c_o+:} false; then : + $as_echo_n "(cached) " >&6 +else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main (void) +main () { ; @@ -4281,8 +3812,8 @@ _ACEOF rm -f core conftest* unset am_i fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_prog_cc_c_o" >&5 -printf "%s\n" "$am_cv_prog_cc_c_o" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_prog_cc_c_o" >&5 +$as_echo "$am_cv_prog_cc_c_o" >&6; } if test "$am_cv_prog_cc_c_o" != yes; then # Losing compiler, so override with the script. # FIXME: It is wrong to rewrite CC. @@ -4301,8 +3832,8 @@ DEPDIR="${am__leading_dot}deps" ac_config_commands="$ac_config_commands depfiles" -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} supports the include directive" >&5 -printf %s "checking whether ${MAKE-make} supports the include directive... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} supports the include directive" >&5 +$as_echo_n "checking whether ${MAKE-make} supports the include directive... " >&6; } cat > confinc.mk << 'END' am__doit: @echo this is the am__doit target >confinc.out @@ -4338,12 +3869,11 @@ esac fi done rm -f confinc.* confmf.* -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${_am_result}" >&5 -printf "%s\n" "${_am_result}" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${_am_result}" >&5 +$as_echo "${_am_result}" >&6; } # Check whether --enable-dependency-tracking was given. -if test ${enable_dependency_tracking+y} -then : +if test "${enable_dependency_tracking+set}" = set; then : enableval=$enable_dependency_tracking; fi @@ -4364,12 +3894,11 @@ fi depcc="$CC" am_compiler_list= -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 -printf %s "checking dependency style of $depcc... " >&6; } -if test ${am_cv_CC_dependencies_compiler_type+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 +$as_echo_n "checking dependency style of $depcc... " >&6; } +if ${am_cv_CC_dependencies_compiler_type+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then # We make a subdir and do the tests there. Otherwise we can end up # making bogus files that we don't know about and never remove. For @@ -4476,8 +4005,8 @@ else fi fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_CC_dependencies_compiler_type" >&5 -printf "%s\n" "$am_cv_CC_dependencies_compiler_type" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_CC_dependencies_compiler_type" >&5 +$as_echo "$am_cv_CC_dependencies_compiler_type" >&6; } CCDEPMODE=depmode=$am_cv_CC_dependencies_compiler_type if @@ -4496,36 +4025,40 @@ ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 -printf %s "checking how to run the C preprocessor... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 +$as_echo_n "checking how to run the C preprocessor... " >&6; } # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= fi if test -z "$CPP"; then - if test ${ac_cv_prog_CPP+y} -then : - printf %s "(cached) " >&6 -else $as_nop - # Double quotes because $CC needs to be expanded - for CPP in "$CC -E" "$CC -E -traditional-cpp" cpp /lib/cpp + if ${ac_cv_prog_CPP+:} false; then : + $as_echo_n "(cached) " >&6 +else + # Double quotes because CPP needs to be expanded + for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" do ac_preproc_ok=false for ac_c_preproc_warn_flag in '' yes do # Use a header file that comes with gcc, so configuring glibc # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. "Syntax error" is here to catch this case. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include +#ifdef __STDC__ +# include +#else +# include +#endif Syntax error _ACEOF -if ac_fn_c_try_cpp "$LINENO" -then : +if ac_fn_c_try_cpp "$LINENO"; then : -else $as_nop +else # Broken: fails on valid input. continue fi @@ -4537,11 +4070,10 @@ rm -f conftest.err conftest.i conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF -if ac_fn_c_try_cpp "$LINENO" -then : +if ac_fn_c_try_cpp "$LINENO"; then : # Broken: success on invalid input. continue -else $as_nop +else # Passes both tests. ac_preproc_ok=: break @@ -4551,8 +4083,7 @@ rm -f conftest.err conftest.i conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. rm -f conftest.i conftest.err conftest.$ac_ext -if $ac_preproc_ok -then : +if $ac_preproc_ok; then : break fi @@ -4564,24 +4095,29 @@ fi else ac_cv_prog_CPP=$CPP fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 -printf "%s\n" "$CPP" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 +$as_echo "$CPP" >&6; } ac_preproc_ok=false for ac_c_preproc_warn_flag in '' yes do # Use a header file that comes with gcc, so configuring glibc # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. "Syntax error" is here to catch this case. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include +#ifdef __STDC__ +# include +#else +# include +#endif Syntax error _ACEOF -if ac_fn_c_try_cpp "$LINENO" -then : +if ac_fn_c_try_cpp "$LINENO"; then : -else $as_nop +else # Broken: fails on valid input. continue fi @@ -4593,11 +4129,10 @@ rm -f conftest.err conftest.i conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF -if ac_fn_c_try_cpp "$LINENO" -then : +if ac_fn_c_try_cpp "$LINENO"; then : # Broken: success on invalid input. continue -else $as_nop +else # Passes both tests. ac_preproc_ok=: break @@ -4607,12 +4142,11 @@ rm -f conftest.err conftest.i conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. rm -f conftest.i conftest.err conftest.$ac_ext -if $ac_preproc_ok -then : +if $ac_preproc_ok; then : -else $as_nop - { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "C preprocessor \"$CPP\" fails sanity check See \`config.log' for more details" "$LINENO" 5; } fi @@ -4623,12 +4157,11 @@ ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 -printf %s "checking for grep that handles long lines and -e... " >&6; } -if test ${ac_cv_path_GREP+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 +$as_echo_n "checking for grep that handles long lines and -e... " >&6; } +if ${ac_cv_path_GREP+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -z "$GREP"; then ac_path_GREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST @@ -4636,15 +4169,10 @@ else $as_nop 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 grep ggrep - do + test -z "$as_dir" && as_dir=. + for ac_prog in grep ggrep; do for ac_exec_ext in '' $ac_executable_extensions; do - ac_path_GREP="$as_dir$ac_prog$ac_exec_ext" + ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_GREP" || continue # Check for GNU ac_path_GREP and select it if it is found. # Check for GNU $ac_path_GREP @@ -4653,13 +4181,13 @@ case `"$ac_path_GREP" --version 2>&1` in ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; *) ac_count=0 - printf %s 0123456789 >"conftest.in" + $as_echo_n 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" 'GREP' >> "conftest.nl" + $as_echo 'GREP' >> "conftest.nl" "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "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 @@ -4687,17 +4215,16 @@ else fi fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 -printf "%s\n" "$ac_cv_path_GREP" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 +$as_echo "$ac_cv_path_GREP" >&6; } GREP="$ac_cv_path_GREP" -{ 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 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 +$as_echo_n "checking for egrep... " >&6; } +if ${ac_cv_path_EGREP+:} false; then : + $as_echo_n "(cached) " >&6 +else if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 then ac_cv_path_EGREP="$GREP -E" else @@ -4708,15 +4235,10 @@ else $as_nop 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 + test -z "$as_dir" && as_dir=. + 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" + 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 @@ -4725,13 +4247,13 @@ case `"$ac_path_EGREP" --version 2>&1` in ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; *) ac_count=0 - printf %s 0123456789 >"conftest.in" + $as_echo_n 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" + $as_echo '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 @@ -4760,8 +4282,8 @@ 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; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 +$as_echo "$ac_cv_path_EGREP" >&6; } EGREP="$ac_cv_path_EGREP" @@ -4771,21 +4293,19 @@ printf "%s\n" "$ac_cv_path_EGREP" >&6; } COB_CC="" # Check whether --with-cc was given. -if test ${with_cc+y} -then : +if test "${with_cc+set}" = set; then : withval=$with_cc; COB_CC=$withval -else $as_nop +else COB_CC=$CC fi # Check whether --with-seqra-extfh was given. -if test ${with_seqra_extfh+y} -then : +if test "${with_seqra_extfh+set}" = set; then : withval=$with_seqra_extfh; if test "$with_seqra_extfh" = "yes" then - printf "%s\n" "#define WITH_SEQRA_EXTFH 1" >>confdefs.h + $as_echo "#define WITH_SEQRA_EXTFH 1" >>confdefs.h fi fi @@ -4802,8 +4322,7 @@ fi GEN_DEBUG_OPT="no" # Check whether --enable-debug was given. -if test ${enable_debug+y} -then : +if test "${enable_debug+set}" = set; then : enableval=$enable_debug; if test "$enable_debug" = "yes" then GEN_DEBUG_OPT="yes" @@ -4812,22 +4331,20 @@ fi # Check whether --enable-param-check was given. -if test ${enable_param_check+y} -then : +if test "${enable_param_check+set}" = set; then : enableval=$enable_param_check; if test "$enable_param_check" = "yes" then - printf "%s\n" "#define COB_PARAM_CHECK 1" >>confdefs.h + $as_echo "#define COB_PARAM_CHECK 1" >>confdefs.h fi fi # Check whether --enable-utf8 was given. -if test ${enable_utf8+y} -then : +if test "${enable_utf8+set}" = set; then : enableval=$enable_utf8; if test "$enable_utf8" = "yes" then - printf "%s\n" "#define I18N_UTF8 1" >>confdefs.h + $as_echo "#define I18N_UTF8 1" >>confdefs.h COB_M4_FLAGS=-DM4.I18N_UTF8 fi @@ -4845,8 +4362,7 @@ fi WITH_VARSEQ=0 # Check whether --with-varseq was given. -if test ${with_varseq+y} -then : +if test "${with_varseq+set}" = set; then : withval=$with_varseq; case $with_varseq in yes) as_fn_error $? "\"You must give --with-varseq an argument.\"" "$LINENO" 5 ;; @@ -4859,7 +4375,9 @@ then : esac fi -printf "%s\n" "#define WITH_VARSEQ $WITH_VARSEQ" >>confdefs.h +cat >>confdefs.h <<_ACEOF +#define WITH_VARSEQ $WITH_VARSEQ +_ACEOF # Checks for programs. @@ -4867,15 +4385,15 @@ printf "%s\n" "#define WITH_VARSEQ $WITH_VARSEQ" >>confdefs.h with_tags= -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether ln -s works" >&5 -printf %s "checking whether ln -s works... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ln -s works" >&5 +$as_echo_n "checking whether ln -s works... " >&6; } LN_S=$as_ln_s if test "$LN_S" = "ln -s"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -printf "%s\n" "yes" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no, using $LN_S" >&5 -printf "%s\n" "no, using $LN_S" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no, using $LN_S" >&5 +$as_echo "no, using $LN_S" >&6; } fi @@ -4883,29 +4401,26 @@ enable_dlopen=yes +# Make sure we can run config.sub. +$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 || + as_fn_error $? "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5 - - # Make sure we can run config.sub. -$SHELL "${ac_aux_dir}config.sub" sun4 >/dev/null 2>&1 || - as_fn_error $? "cannot run $SHELL ${ac_aux_dir}config.sub" "$LINENO" 5 - -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking build system type" >&5 -printf %s "checking build system type... " >&6; } -if test ${ac_cv_build+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5 +$as_echo_n "checking build system type... " >&6; } +if ${ac_cv_build+:} false; then : + $as_echo_n "(cached) " >&6 +else ac_build_alias=$build_alias test "x$ac_build_alias" = x && - ac_build_alias=`$SHELL "${ac_aux_dir}config.guess"` + ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"` test "x$ac_build_alias" = x && as_fn_error $? "cannot guess build type; you must specify one" "$LINENO" 5 -ac_cv_build=`$SHELL "${ac_aux_dir}config.sub" $ac_build_alias` || - as_fn_error $? "$SHELL ${ac_aux_dir}config.sub $ac_build_alias failed" "$LINENO" 5 +ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` || + as_fn_error $? "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5 fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5 -printf "%s\n" "$ac_cv_build" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5 +$as_echo "$ac_cv_build" >&6; } case $ac_cv_build in *-*-*) ;; *) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;; @@ -4924,22 +4439,21 @@ IFS=$ac_save_IFS case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking host system type" >&5 -printf %s "checking host system type... " >&6; } -if test ${ac_cv_host+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5 +$as_echo_n "checking host system type... " >&6; } +if ${ac_cv_host+:} false; then : + $as_echo_n "(cached) " >&6 +else if test "x$host_alias" = x; then ac_cv_host=$ac_cv_build else - ac_cv_host=`$SHELL "${ac_aux_dir}config.sub" $host_alias` || - as_fn_error $? "$SHELL ${ac_aux_dir}config.sub $host_alias failed" "$LINENO" 5 + ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` || + as_fn_error $? "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5 fi fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5 -printf "%s\n" "$ac_cv_host" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5 +$as_echo "$ac_cv_host" >&6; } case $ac_cv_host in *-*-*) ;; *) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;; @@ -4965,12 +4479,11 @@ case $host in if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}as", so it can be a program name with args. set dummy ${ac_tool_prefix}as; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_AS+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_AS+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$AS"; then ac_cv_prog_AS="$AS" # Let the user override the test. else @@ -4978,15 +4491,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_AS="${ac_tool_prefix}as" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -4997,11 +4506,11 @@ fi fi AS=$ac_cv_prog_AS if test -n "$AS"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $AS" >&5 -printf "%s\n" "$AS" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AS" >&5 +$as_echo "$AS" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi @@ -5010,12 +4519,11 @@ if test -z "$ac_cv_prog_AS"; then ac_ct_AS=$AS # Extract the first word of "as", so it can be a program name with args. set dummy as; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_ac_ct_AS+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_AS+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$ac_ct_AS"; then ac_cv_prog_ac_ct_AS="$ac_ct_AS" # Let the user override the test. else @@ -5023,15 +4531,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_AS="as" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -5042,11 +4546,11 @@ fi fi ac_ct_AS=$ac_cv_prog_ac_ct_AS if test -n "$ac_ct_AS"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AS" >&5 -printf "%s\n" "$ac_ct_AS" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AS" >&5 +$as_echo "$ac_ct_AS" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi if test "x$ac_ct_AS" = x; then @@ -5054,8 +4558,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac AS=$ac_ct_AS @@ -5067,12 +4571,11 @@ fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}dlltool", so it can be a program name with args. set dummy ${ac_tool_prefix}dlltool; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_DLLTOOL+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_DLLTOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$DLLTOOL"; then ac_cv_prog_DLLTOOL="$DLLTOOL" # Let the user override the test. else @@ -5080,15 +4583,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_DLLTOOL="${ac_tool_prefix}dlltool" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -5099,11 +4598,11 @@ fi fi DLLTOOL=$ac_cv_prog_DLLTOOL if test -n "$DLLTOOL"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $DLLTOOL" >&5 -printf "%s\n" "$DLLTOOL" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DLLTOOL" >&5 +$as_echo "$DLLTOOL" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi @@ -5112,12 +4611,11 @@ if test -z "$ac_cv_prog_DLLTOOL"; then ac_ct_DLLTOOL=$DLLTOOL # Extract the first word of "dlltool", so it can be a program name with args. set dummy dlltool; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_ac_ct_DLLTOOL+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_DLLTOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$ac_ct_DLLTOOL"; then ac_cv_prog_ac_ct_DLLTOOL="$ac_ct_DLLTOOL" # Let the user override the test. else @@ -5125,15 +4623,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_DLLTOOL="dlltool" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -5144,11 +4638,11 @@ fi fi ac_ct_DLLTOOL=$ac_cv_prog_ac_ct_DLLTOOL if test -n "$ac_ct_DLLTOOL"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DLLTOOL" >&5 -printf "%s\n" "$ac_ct_DLLTOOL" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DLLTOOL" >&5 +$as_echo "$ac_ct_DLLTOOL" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi if test "x$ac_ct_DLLTOOL" = x; then @@ -5156,8 +4650,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac DLLTOOL=$ac_ct_DLLTOOL @@ -5169,12 +4663,11 @@ fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}objdump", so it can be a program name with args. set dummy ${ac_tool_prefix}objdump; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_OBJDUMP+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_OBJDUMP+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$OBJDUMP"; then ac_cv_prog_OBJDUMP="$OBJDUMP" # Let the user override the test. else @@ -5182,15 +4675,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_OBJDUMP="${ac_tool_prefix}objdump" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -5201,11 +4690,11 @@ fi fi OBJDUMP=$ac_cv_prog_OBJDUMP if test -n "$OBJDUMP"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5 -printf "%s\n" "$OBJDUMP" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5 +$as_echo "$OBJDUMP" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi @@ -5214,12 +4703,11 @@ if test -z "$ac_cv_prog_OBJDUMP"; then ac_ct_OBJDUMP=$OBJDUMP # Extract the first word of "objdump", so it can be a program name with args. set dummy objdump; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_ac_ct_OBJDUMP+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_OBJDUMP+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$ac_ct_OBJDUMP"; then ac_cv_prog_ac_ct_OBJDUMP="$ac_ct_OBJDUMP" # Let the user override the test. else @@ -5227,15 +4715,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_OBJDUMP="objdump" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -5246,11 +4730,11 @@ fi fi ac_ct_OBJDUMP=$ac_cv_prog_ac_ct_OBJDUMP if test -n "$ac_ct_OBJDUMP"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJDUMP" >&5 -printf "%s\n" "$ac_ct_OBJDUMP" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJDUMP" >&5 +$as_echo "$ac_ct_OBJDUMP" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi if test "x$ac_ct_OBJDUMP" = x; then @@ -5258,8 +4742,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OBJDUMP=$ac_ct_OBJDUMP @@ -5293,8 +4777,8 @@ test -z "$OBJDUMP" && OBJDUMP=objdump case `pwd` in *\ * | *\ *) - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5 -printf "%s\n" "$as_me: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&2;} ;; + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5 +$as_echo "$as_me: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&2;} ;; esac @@ -5314,7 +4798,6 @@ macro_revision='2.4.6' - ltmain=$ac_aux_dir/ltmain.sh # Backslashify metacharacters that are still active within @@ -5338,8 +4821,8 @@ ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO$ECHO -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to print strings" >&5 -printf %s "checking how to print strings... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to print strings" >&5 +$as_echo_n "checking how to print strings... " >&6; } # Test print first, because it will be a builtin if present. if test "X`( print -r -- -n ) 2>/dev/null`" = X-n && \ test "X`print -r -- $ECHO 2>/dev/null`" = "X$ECHO"; then @@ -5365,12 +4848,12 @@ func_echo_all () } case $ECHO in - printf*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: printf" >&5 -printf "%s\n" "printf" >&6; } ;; - print*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: print -r" >&5 -printf "%s\n" "print -r" >&6; } ;; - *) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: cat" >&5 -printf "%s\n" "cat" >&6; } ;; + printf*) { $as_echo "$as_me:${as_lineno-$LINENO}: result: printf" >&5 +$as_echo "printf" >&6; } ;; + print*) { $as_echo "$as_me:${as_lineno-$LINENO}: result: print -r" >&5 +$as_echo "print -r" >&6; } ;; + *) { $as_echo "$as_me:${as_lineno-$LINENO}: result: cat" >&5 +$as_echo "cat" >&6; } ;; esac @@ -5386,12 +4869,11 @@ esac -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5 -printf %s "checking for a sed that does not truncate output... " >&6; } -if test ${ac_cv_path_SED+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5 +$as_echo_n "checking for a sed that does not truncate output... " >&6; } +if ${ac_cv_path_SED+:} false; then : + $as_echo_n "(cached) " >&6 +else ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ for ac_i in 1 2 3 4 5 6 7; do ac_script="$ac_script$as_nl$ac_script" @@ -5405,15 +4887,10 @@ else $as_nop for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac - for ac_prog in sed gsed - do + test -z "$as_dir" && as_dir=. + for ac_prog in sed gsed; do for ac_exec_ext in '' $ac_executable_extensions; do - ac_path_SED="$as_dir$ac_prog$ac_exec_ext" + ac_path_SED="$as_dir/$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_SED" || continue # Check for GNU ac_path_SED and select it if it is found. # Check for GNU $ac_path_SED @@ -5422,13 +4899,13 @@ case `"$ac_path_SED" --version 2>&1` in ac_cv_path_SED="$ac_path_SED" ac_path_SED_found=:;; *) ac_count=0 - printf %s 0123456789 >"conftest.in" + $as_echo_n 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" '' >> "conftest.nl" + $as_echo '' >> "conftest.nl" "$ac_path_SED" -f conftest.sed < "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 @@ -5456,8 +4933,8 @@ else fi fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5 -printf "%s\n" "$ac_cv_path_SED" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5 +$as_echo "$ac_cv_path_SED" >&6; } SED="$ac_cv_path_SED" rm -f conftest.sed @@ -5474,12 +4951,11 @@ Xsed="$SED -e 1s/^X//" -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for fgrep" >&5 -printf %s "checking for fgrep... " >&6; } -if test ${ac_cv_path_FGREP+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for fgrep" >&5 +$as_echo_n "checking for fgrep... " >&6; } +if ${ac_cv_path_FGREP+:} false; then : + $as_echo_n "(cached) " >&6 +else if echo 'ab*c' | $GREP -F 'ab*c' >/dev/null 2>&1 then ac_cv_path_FGREP="$GREP -F" else @@ -5490,15 +4966,10 @@ else $as_nop 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 fgrep - do + test -z "$as_dir" && as_dir=. + for ac_prog in fgrep; do for ac_exec_ext in '' $ac_executable_extensions; do - ac_path_FGREP="$as_dir$ac_prog$ac_exec_ext" + ac_path_FGREP="$as_dir/$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_FGREP" || continue # Check for GNU ac_path_FGREP and select it if it is found. # Check for GNU $ac_path_FGREP @@ -5507,13 +4978,13 @@ case `"$ac_path_FGREP" --version 2>&1` in ac_cv_path_FGREP="$ac_path_FGREP" ac_path_FGREP_found=:;; *) ac_count=0 - printf %s 0123456789 >"conftest.in" + $as_echo_n 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" 'FGREP' >> "conftest.nl" + $as_echo 'FGREP' >> "conftest.nl" "$ac_path_FGREP" FGREP < "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 @@ -5542,8 +5013,8 @@ fi fi fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_FGREP" >&5 -printf "%s\n" "$ac_cv_path_FGREP" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_FGREP" >&5 +$as_echo "$ac_cv_path_FGREP" >&6; } FGREP="$ac_cv_path_FGREP" @@ -5568,18 +5039,17 @@ test -z "$GREP" && GREP=grep # Check whether --with-gnu-ld was given. -if test ${with_gnu_ld+y} -then : +if test "${with_gnu_ld+set}" = set; then : withval=$with_gnu_ld; test no = "$withval" || with_gnu_ld=yes -else $as_nop +else with_gnu_ld=no fi ac_prog=ld if test yes = "$GCC"; then # Check if gcc -print-prog-name=ld gives a path. - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 -printf %s "checking for ld used by $CC... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 +$as_echo_n "checking for ld used by $CC... " >&6; } case $host in *-*-mingw*) # gcc leaves a trailing carriage return, which upsets mingw @@ -5608,16 +5078,15 @@ printf %s "checking for ld used by $CC... " >&6; } ;; esac elif test yes = "$with_gnu_ld"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 -printf %s "checking for GNU ld... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 +$as_echo_n "checking for GNU ld... " >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 -printf %s "checking for non-GNU ld... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 +$as_echo_n "checking for non-GNU ld... " >&6; } fi -if test ${lt_cv_path_LD+y} -then : - printf %s "(cached) " >&6 -else $as_nop +if ${lt_cv_path_LD+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -z "$LD"; then lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR for ac_dir in $PATH; do @@ -5646,19 +5115,18 @@ fi LD=$lt_cv_path_LD if test -n "$LD"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $LD" >&5 -printf "%s\n" "$LD" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LD" >&5 +$as_echo "$LD" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi test -z "$LD" && as_fn_error $? "no acceptable ld found in \$PATH" "$LINENO" 5 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 -printf %s "checking if the linker ($LD) is GNU ld... " >&6; } -if test ${lt_cv_prog_gnu_ld+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 +$as_echo_n "checking if the linker ($LD) is GNU ld... " >&6; } +if ${lt_cv_prog_gnu_ld+:} false; then : + $as_echo_n "(cached) " >&6 +else # I'd rather use --version here, but apparently some GNU lds only accept -v. case `$LD -v 2>&1 &1 &5 -printf "%s\n" "$lt_cv_prog_gnu_ld" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_gnu_ld" >&5 +$as_echo "$lt_cv_prog_gnu_ld" >&6; } with_gnu_ld=$lt_cv_prog_gnu_ld @@ -5681,12 +5149,11 @@ with_gnu_ld=$lt_cv_prog_gnu_ld -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for BSD- or MS-compatible name lister (nm)" >&5 -printf %s "checking for BSD- or MS-compatible name lister (nm)... " >&6; } -if test ${lt_cv_path_NM+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for BSD- or MS-compatible name lister (nm)" >&5 +$as_echo_n "checking for BSD- or MS-compatible name lister (nm)... " >&6; } +if ${lt_cv_path_NM+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$NM"; then # Let the user override the test. lt_cv_path_NM=$NM @@ -5736,8 +5203,8 @@ else : ${lt_cv_path_NM=no} fi fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_NM" >&5 -printf "%s\n" "$lt_cv_path_NM" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_NM" >&5 +$as_echo "$lt_cv_path_NM" >&6; } if test no != "$lt_cv_path_NM"; then NM=$lt_cv_path_NM else @@ -5750,12 +5217,11 @@ else do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_DUMPBIN+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_DUMPBIN+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$DUMPBIN"; then ac_cv_prog_DUMPBIN="$DUMPBIN" # Let the user override the test. else @@ -5763,15 +5229,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_DUMPBIN="$ac_tool_prefix$ac_prog" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -5782,11 +5244,11 @@ fi fi DUMPBIN=$ac_cv_prog_DUMPBIN if test -n "$DUMPBIN"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $DUMPBIN" >&5 -printf "%s\n" "$DUMPBIN" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DUMPBIN" >&5 +$as_echo "$DUMPBIN" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi @@ -5799,12 +5261,11 @@ if test -z "$DUMPBIN"; then do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_ac_ct_DUMPBIN+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_DUMPBIN+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$ac_ct_DUMPBIN"; then ac_cv_prog_ac_ct_DUMPBIN="$ac_ct_DUMPBIN" # Let the user override the test. else @@ -5812,15 +5273,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_DUMPBIN="$ac_prog" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -5831,11 +5288,11 @@ fi fi ac_ct_DUMPBIN=$ac_cv_prog_ac_ct_DUMPBIN if test -n "$ac_ct_DUMPBIN"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DUMPBIN" >&5 -printf "%s\n" "$ac_ct_DUMPBIN" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DUMPBIN" >&5 +$as_echo "$ac_ct_DUMPBIN" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi @@ -5847,8 +5304,8 @@ done else case $cross_compiling:$ac_tool_warned in yes:) -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac DUMPBIN=$ac_ct_DUMPBIN @@ -5876,12 +5333,11 @@ test -z "$NM" && NM=nm -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking the name lister ($NM) interface" >&5 -printf %s "checking the name lister ($NM) interface... " >&6; } -if test ${lt_cv_nm_interface+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking the name lister ($NM) interface" >&5 +$as_echo_n "checking the name lister ($NM) interface... " >&6; } +if ${lt_cv_nm_interface+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_nm_interface="BSD nm" echo "int some_variable = 0;" > conftest.$ac_ext (eval echo "\"\$as_me:$LINENO: $ac_compile\"" >&5) @@ -5897,16 +5353,15 @@ else $as_nop fi rm -f conftest* fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_nm_interface" >&5 -printf "%s\n" "$lt_cv_nm_interface" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_nm_interface" >&5 +$as_echo "$lt_cv_nm_interface" >&6; } # find the maximum length of command line arguments -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking the maximum length of command line arguments" >&5 -printf %s "checking the maximum length of command line arguments... " >&6; } -if test ${lt_cv_sys_max_cmd_len+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking the maximum length of command line arguments" >&5 +$as_echo_n "checking the maximum length of command line arguments... " >&6; } +if ${lt_cv_sys_max_cmd_len+:} false; then : + $as_echo_n "(cached) " >&6 +else i=0 teststring=ABCD @@ -6033,11 +5488,11 @@ else $as_nop fi if test -n "$lt_cv_sys_max_cmd_len"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_max_cmd_len" >&5 -printf "%s\n" "$lt_cv_sys_max_cmd_len" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_max_cmd_len" >&5 +$as_echo "$lt_cv_sys_max_cmd_len" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none" >&5 -printf "%s\n" "none" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: none" >&5 +$as_echo "none" >&6; } fi max_cmd_len=$lt_cv_sys_max_cmd_len @@ -6081,12 +5536,11 @@ esac -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to $host format" >&5 -printf %s "checking how to convert $build file names to $host format... " >&6; } -if test ${lt_cv_to_host_file_cmd+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to $host format" >&5 +$as_echo_n "checking how to convert $build file names to $host format... " >&6; } +if ${lt_cv_to_host_file_cmd+:} false; then : + $as_echo_n "(cached) " >&6 +else case $host in *-*-mingw* ) case $build in @@ -6122,19 +5576,18 @@ esac fi to_host_file_cmd=$lt_cv_to_host_file_cmd -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_host_file_cmd" >&5 -printf "%s\n" "$lt_cv_to_host_file_cmd" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_host_file_cmd" >&5 +$as_echo "$lt_cv_to_host_file_cmd" >&6; } -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to toolchain format" >&5 -printf %s "checking how to convert $build file names to toolchain format... " >&6; } -if test ${lt_cv_to_tool_file_cmd+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to toolchain format" >&5 +$as_echo_n "checking how to convert $build file names to toolchain format... " >&6; } +if ${lt_cv_to_tool_file_cmd+:} false; then : + $as_echo_n "(cached) " >&6 +else #assume ordinary cross tools, or native build. lt_cv_to_tool_file_cmd=func_convert_file_noop case $host in @@ -6150,23 +5603,22 @@ esac fi to_tool_file_cmd=$lt_cv_to_tool_file_cmd -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_tool_file_cmd" >&5 -printf "%s\n" "$lt_cv_to_tool_file_cmd" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_tool_file_cmd" >&5 +$as_echo "$lt_cv_to_tool_file_cmd" >&6; } -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $LD option to reload object files" >&5 -printf %s "checking for $LD option to reload object files... " >&6; } -if test ${lt_cv_ld_reload_flag+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $LD option to reload object files" >&5 +$as_echo_n "checking for $LD option to reload object files... " >&6; } +if ${lt_cv_ld_reload_flag+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_ld_reload_flag='-r' fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_reload_flag" >&5 -printf "%s\n" "$lt_cv_ld_reload_flag" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_reload_flag" >&5 +$as_echo "$lt_cv_ld_reload_flag" >&6; } reload_flag=$lt_cv_ld_reload_flag case $reload_flag in "" | " "*) ;; @@ -6199,12 +5651,11 @@ esac if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}objdump", so it can be a program name with args. set dummy ${ac_tool_prefix}objdump; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_OBJDUMP+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_OBJDUMP+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$OBJDUMP"; then ac_cv_prog_OBJDUMP="$OBJDUMP" # Let the user override the test. else @@ -6212,15 +5663,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_OBJDUMP="${ac_tool_prefix}objdump" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6231,11 +5678,11 @@ fi fi OBJDUMP=$ac_cv_prog_OBJDUMP if test -n "$OBJDUMP"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5 -printf "%s\n" "$OBJDUMP" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5 +$as_echo "$OBJDUMP" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi @@ -6244,12 +5691,11 @@ if test -z "$ac_cv_prog_OBJDUMP"; then ac_ct_OBJDUMP=$OBJDUMP # Extract the first word of "objdump", so it can be a program name with args. set dummy objdump; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_ac_ct_OBJDUMP+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_OBJDUMP+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$ac_ct_OBJDUMP"; then ac_cv_prog_ac_ct_OBJDUMP="$ac_ct_OBJDUMP" # Let the user override the test. else @@ -6257,15 +5703,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_OBJDUMP="objdump" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6276,11 +5718,11 @@ fi fi ac_ct_OBJDUMP=$ac_cv_prog_ac_ct_OBJDUMP if test -n "$ac_ct_OBJDUMP"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJDUMP" >&5 -printf "%s\n" "$ac_ct_OBJDUMP" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJDUMP" >&5 +$as_echo "$ac_ct_OBJDUMP" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi if test "x$ac_ct_OBJDUMP" = x; then @@ -6288,8 +5730,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OBJDUMP=$ac_ct_OBJDUMP @@ -6305,12 +5747,11 @@ test -z "$OBJDUMP" && OBJDUMP=objdump -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to recognize dependent libraries" >&5 -printf %s "checking how to recognize dependent libraries... " >&6; } -if test ${lt_cv_deplibs_check_method+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to recognize dependent libraries" >&5 +$as_echo_n "checking how to recognize dependent libraries... " >&6; } +if ${lt_cv_deplibs_check_method+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_file_magic_cmd='$MAGIC_CMD' lt_cv_file_magic_test_file= lt_cv_deplibs_check_method='unknown' @@ -6428,7 +5869,7 @@ linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) lt_cv_deplibs_check_method=pass_all ;; -netbsd* | netbsdelf*-gnu) +netbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$' else @@ -6506,8 +5947,8 @@ os2*) esac fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_deplibs_check_method" >&5 -printf "%s\n" "$lt_cv_deplibs_check_method" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_deplibs_check_method" >&5 +$as_echo "$lt_cv_deplibs_check_method" >&6; } file_magic_glob= want_nocaseglob=no @@ -6551,12 +5992,11 @@ test -z "$deplibs_check_method" && deplibs_check_method=unknown if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}dlltool", so it can be a program name with args. set dummy ${ac_tool_prefix}dlltool; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_DLLTOOL+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_DLLTOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$DLLTOOL"; then ac_cv_prog_DLLTOOL="$DLLTOOL" # Let the user override the test. else @@ -6564,15 +6004,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_DLLTOOL="${ac_tool_prefix}dlltool" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6583,11 +6019,11 @@ fi fi DLLTOOL=$ac_cv_prog_DLLTOOL if test -n "$DLLTOOL"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $DLLTOOL" >&5 -printf "%s\n" "$DLLTOOL" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DLLTOOL" >&5 +$as_echo "$DLLTOOL" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi @@ -6596,12 +6032,11 @@ if test -z "$ac_cv_prog_DLLTOOL"; then ac_ct_DLLTOOL=$DLLTOOL # Extract the first word of "dlltool", so it can be a program name with args. set dummy dlltool; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_ac_ct_DLLTOOL+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_DLLTOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$ac_ct_DLLTOOL"; then ac_cv_prog_ac_ct_DLLTOOL="$ac_ct_DLLTOOL" # Let the user override the test. else @@ -6609,15 +6044,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_DLLTOOL="dlltool" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6628,11 +6059,11 @@ fi fi ac_ct_DLLTOOL=$ac_cv_prog_ac_ct_DLLTOOL if test -n "$ac_ct_DLLTOOL"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DLLTOOL" >&5 -printf "%s\n" "$ac_ct_DLLTOOL" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DLLTOOL" >&5 +$as_echo "$ac_ct_DLLTOOL" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi if test "x$ac_ct_DLLTOOL" = x; then @@ -6640,8 +6071,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac DLLTOOL=$ac_ct_DLLTOOL @@ -6658,12 +6089,11 @@ test -z "$DLLTOOL" && DLLTOOL=dlltool -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to associate runtime and link libraries" >&5 -printf %s "checking how to associate runtime and link libraries... " >&6; } -if test ${lt_cv_sharedlib_from_linklib_cmd+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to associate runtime and link libraries" >&5 +$as_echo_n "checking how to associate runtime and link libraries... " >&6; } +if ${lt_cv_sharedlib_from_linklib_cmd+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_sharedlib_from_linklib_cmd='unknown' case $host_os in @@ -6686,8 +6116,8 @@ cygwin* | mingw* | pw32* | cegcc*) esac fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sharedlib_from_linklib_cmd" >&5 -printf "%s\n" "$lt_cv_sharedlib_from_linklib_cmd" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sharedlib_from_linklib_cmd" >&5 +$as_echo "$lt_cv_sharedlib_from_linklib_cmd" >&6; } sharedlib_from_linklib_cmd=$lt_cv_sharedlib_from_linklib_cmd test -z "$sharedlib_from_linklib_cmd" && sharedlib_from_linklib_cmd=$ECHO @@ -6703,12 +6133,11 @@ if test -n "$ac_tool_prefix"; then do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_AR+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_AR+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$AR"; then ac_cv_prog_AR="$AR" # Let the user override the test. else @@ -6716,15 +6145,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_AR="$ac_tool_prefix$ac_prog" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6735,11 +6160,11 @@ fi fi AR=$ac_cv_prog_AR if test -n "$AR"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $AR" >&5 -printf "%s\n" "$AR" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5 +$as_echo "$AR" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi @@ -6752,12 +6177,11 @@ if test -z "$AR"; then do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_ac_ct_AR+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_AR+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$ac_ct_AR"; then ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test. else @@ -6765,15 +6189,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_AR="$ac_prog" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6784,11 +6204,11 @@ fi fi ac_ct_AR=$ac_cv_prog_ac_ct_AR if test -n "$ac_ct_AR"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5 -printf "%s\n" "$ac_ct_AR" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5 +$as_echo "$ac_ct_AR" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi @@ -6800,8 +6220,8 @@ done else case $cross_compiling:$ac_tool_warned in yes:) -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac AR=$ac_ct_AR @@ -6809,7 +6229,7 @@ esac fi : ${AR=ar} -: ${AR_FLAGS=cr} +: ${AR_FLAGS=cru} @@ -6821,32 +6241,30 @@ fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for archiver @FILE support" >&5 -printf %s "checking for archiver @FILE support... " >&6; } -if test ${lt_cv_ar_at_file+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for archiver @FILE support" >&5 +$as_echo_n "checking for archiver @FILE support... " >&6; } +if ${lt_cv_ar_at_file+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_ar_at_file=no cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main (void) +main () { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : echo conftest.$ac_objext > conftest.lst lt_ar_try='$AR $AR_FLAGS libconftest.a @conftest.lst >&5' { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$lt_ar_try\""; } >&5 (eval $lt_ar_try) 2>&5 ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if test 0 -eq "$ac_status"; then # Ensure the archiver fails upon bogus file names. @@ -6854,7 +6272,7 @@ then : { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$lt_ar_try\""; } >&5 (eval $lt_ar_try) 2>&5 ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if test 0 -ne "$ac_status"; then lt_cv_ar_at_file=@ @@ -6863,11 +6281,11 @@ then : rm -f conftest.* libconftest.a fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ar_at_file" >&5 -printf "%s\n" "$lt_cv_ar_at_file" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ar_at_file" >&5 +$as_echo "$lt_cv_ar_at_file" >&6; } if test no = "$lt_cv_ar_at_file"; then archiver_list_spec= @@ -6884,12 +6302,11 @@ fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. set dummy ${ac_tool_prefix}strip; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_STRIP+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_STRIP+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$STRIP"; then ac_cv_prog_STRIP="$STRIP" # Let the user override the test. else @@ -6897,15 +6314,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_STRIP="${ac_tool_prefix}strip" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6916,11 +6329,11 @@ fi fi STRIP=$ac_cv_prog_STRIP if test -n "$STRIP"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 -printf "%s\n" "$STRIP" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 +$as_echo "$STRIP" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi @@ -6929,12 +6342,11 @@ if test -z "$ac_cv_prog_STRIP"; then ac_ct_STRIP=$STRIP # Extract the first word of "strip", so it can be a program name with args. set dummy strip; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_ac_ct_STRIP+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_STRIP+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$ac_ct_STRIP"; then ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. else @@ -6942,15 +6354,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_STRIP="strip" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6961,11 +6369,11 @@ fi fi ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP if test -n "$ac_ct_STRIP"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 -printf "%s\n" "$ac_ct_STRIP" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 +$as_echo "$ac_ct_STRIP" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi if test "x$ac_ct_STRIP" = x; then @@ -6973,8 +6381,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac STRIP=$ac_ct_STRIP @@ -6993,12 +6401,11 @@ test -z "$STRIP" && STRIP=: if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. set dummy ${ac_tool_prefix}ranlib; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_RANLIB+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_RANLIB+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$RANLIB"; then ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. else @@ -7006,15 +6413,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7025,11 +6428,11 @@ fi fi RANLIB=$ac_cv_prog_RANLIB if test -n "$RANLIB"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5 -printf "%s\n" "$RANLIB" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5 +$as_echo "$RANLIB" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi @@ -7038,12 +6441,11 @@ if test -z "$ac_cv_prog_RANLIB"; then ac_ct_RANLIB=$RANLIB # Extract the first word of "ranlib", so it can be a program name with args. set dummy ranlib; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_ac_ct_RANLIB+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_RANLIB+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$ac_ct_RANLIB"; then ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. else @@ -7051,15 +6453,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_RANLIB="ranlib" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7070,11 +6468,11 @@ fi fi ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB if test -n "$ac_ct_RANLIB"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5 -printf "%s\n" "$ac_ct_RANLIB" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5 +$as_echo "$ac_ct_RANLIB" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi if test "x$ac_ct_RANLIB" = x; then @@ -7082,8 +6480,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac RANLIB=$ac_ct_RANLIB @@ -7172,12 +6570,11 @@ compiler=$CC # Check for command to grab the raw symbol name followed by C symbol from nm. -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking command to parse $NM output from $compiler object" >&5 -printf %s "checking command to parse $NM output from $compiler object... " >&6; } -if test ${lt_cv_sys_global_symbol_pipe+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking command to parse $NM output from $compiler object" >&5 +$as_echo_n "checking command to parse $NM output from $compiler object... " >&6; } +if ${lt_cv_sys_global_symbol_pipe+:} false; then : + $as_echo_n "(cached) " >&6 +else # These are sane defaults that work on at least a few old systems. # [They come from Ultrix. What could be older than Ultrix?!! ;)] @@ -7329,12 +6726,15 @@ _LT_EOF if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then # Now try to grab the symbols. nlist=conftest.nm - $ECHO "$as_me:$LINENO: $NM conftest.$ac_objext | $lt_cv_sys_global_symbol_pipe > $nlist" >&5 - if eval "$NM" conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist 2>&5 && test -s "$nlist"; then + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist\""; } >&5 + (eval $NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && test -s "$nlist"; then # Try sorting and uniquifying the output. if sort "$nlist" | uniq > "$nlist"T; then mv -f "$nlist"T "$nlist" @@ -7402,7 +6802,7 @@ _LT_EOF if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 (eval $ac_link) 2>&5 ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && test -s conftest$ac_exeext; then pipe_works=yes fi @@ -7437,11 +6837,11 @@ if test -z "$lt_cv_sys_global_symbol_pipe"; then lt_cv_sys_global_symbol_to_cdecl= fi if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: failed" >&5 -printf "%s\n" "failed" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: failed" >&5 +$as_echo "failed" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ok" >&5 -printf "%s\n" "ok" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5 +$as_echo "ok" >&6; } fi # Response file support. @@ -7487,14 +6887,13 @@ fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for sysroot" >&5 -printf %s "checking for sysroot... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sysroot" >&5 +$as_echo_n "checking for sysroot... " >&6; } # Check whether --with-sysroot was given. -if test ${with_sysroot+y} -then : +if test "${with_sysroot+set}" = set; then : withval=$with_sysroot; -else $as_nop +else with_sysroot=no fi @@ -7512,25 +6911,24 @@ case $with_sysroot in #( no|'') ;; #( *) - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $with_sysroot" >&5 -printf "%s\n" "$with_sysroot" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_sysroot" >&5 +$as_echo "$with_sysroot" >&6; } as_fn_error $? "The sysroot must be an absolute path." "$LINENO" 5 ;; esac - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${lt_sysroot:-no}" >&5 -printf "%s\n" "${lt_sysroot:-no}" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${lt_sysroot:-no}" >&5 +$as_echo "${lt_sysroot:-no}" >&6; } -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a working dd" >&5 -printf %s "checking for a working dd... " >&6; } -if test ${ac_cv_path_lt_DD+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a working dd" >&5 +$as_echo_n "checking for a working dd... " >&6; } +if ${ac_cv_path_lt_DD+:} false; then : + $as_echo_n "(cached) " >&6 +else printf 0123456789abcdef0123456789abcdef >conftest.i cat conftest.i conftest.i >conftest2.i : ${lt_DD:=$DD} @@ -7541,15 +6939,10 @@ if test -z "$lt_DD"; then for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac - for ac_prog in dd - do + test -z "$as_dir" && as_dir=. + for ac_prog in dd; do for ac_exec_ext in '' $ac_executable_extensions; do - ac_path_lt_DD="$as_dir$ac_prog$ac_exec_ext" + ac_path_lt_DD="$as_dir/$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_lt_DD" || continue if "$ac_path_lt_DD" bs=32 count=1 conftest.out 2>/dev/null; then cmp -s conftest.i conftest.out \ @@ -7569,16 +6962,15 @@ fi rm -f conftest.i conftest2.i conftest.out fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_lt_DD" >&5 -printf "%s\n" "$ac_cv_path_lt_DD" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_lt_DD" >&5 +$as_echo "$ac_cv_path_lt_DD" >&6; } -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to truncate binary pipes" >&5 -printf %s "checking how to truncate binary pipes... " >&6; } -if test ${lt_cv_truncate_bin+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to truncate binary pipes" >&5 +$as_echo_n "checking how to truncate binary pipes... " >&6; } +if ${lt_cv_truncate_bin+:} false; then : + $as_echo_n "(cached) " >&6 +else printf 0123456789abcdef0123456789abcdef >conftest.i cat conftest.i conftest.i >conftest2.i lt_cv_truncate_bin= @@ -7589,8 +6981,8 @@ fi rm -f conftest.i conftest2.i conftest.out test -z "$lt_cv_truncate_bin" && lt_cv_truncate_bin="$SED -e 4q" fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_truncate_bin" >&5 -printf "%s\n" "$lt_cv_truncate_bin" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_truncate_bin" >&5 +$as_echo "$lt_cv_truncate_bin" >&6; } @@ -7613,8 +7005,7 @@ func_cc_basename () } # Check whether --enable-libtool-lock was given. -if test ${enable_libtool_lock+y} -then : +if test "${enable_libtool_lock+set}" = set; then : enableval=$enable_libtool_lock; fi @@ -7630,7 +7021,7 @@ ia64-*-hpux*) if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then case `/usr/bin/file conftest.$ac_objext` in *ELF-32*) @@ -7650,7 +7041,7 @@ ia64-*-hpux*) if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then if test yes = "$lt_cv_prog_gnu_ld"; then case `/usr/bin/file conftest.$ac_objext` in @@ -7688,7 +7079,7 @@ mips64*-*linux*) if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then emul=elf case `/usr/bin/file conftest.$ac_objext` in @@ -7729,7 +7120,7 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*) if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then case `/usr/bin/file conftest.o` in *32-bit*) @@ -7792,12 +7183,11 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*) # On SCO OpenServer 5, we need -belf to get full-featured binaries. SAVE_CFLAGS=$CFLAGS CFLAGS="$CFLAGS -belf" - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the C compiler needs -belf" >&5 -printf %s "checking whether the C compiler needs -belf... " >&6; } -if test ${lt_cv_cc_needs_belf+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler needs -belf" >&5 +$as_echo_n "checking whether the C compiler needs -belf... " >&6; } +if ${lt_cv_cc_needs_belf+:} false; then : + $as_echo_n "(cached) " >&6 +else ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -7808,20 +7198,19 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu /* end confdefs.h. */ int -main (void) +main () { ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : +if ac_fn_c_try_link "$LINENO"; then : lt_cv_cc_needs_belf=yes -else $as_nop +else lt_cv_cc_needs_belf=no fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext ac_ext=c ac_cpp='$CPP $CPPFLAGS' @@ -7830,8 +7219,8 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $ ac_compiler_gnu=$ac_cv_c_compiler_gnu fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_cc_needs_belf" >&5 -printf "%s\n" "$lt_cv_cc_needs_belf" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_cc_needs_belf" >&5 +$as_echo "$lt_cv_cc_needs_belf" >&6; } if test yes != "$lt_cv_cc_needs_belf"; then # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf CFLAGS=$SAVE_CFLAGS @@ -7844,7 +7233,7 @@ printf "%s\n" "$lt_cv_cc_needs_belf" >&6; } if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then case `/usr/bin/file conftest.o` in *64-bit*) @@ -7881,12 +7270,11 @@ need_locks=$enable_libtool_lock if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}mt", so it can be a program name with args. set dummy ${ac_tool_prefix}mt; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_MANIFEST_TOOL+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_MANIFEST_TOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$MANIFEST_TOOL"; then ac_cv_prog_MANIFEST_TOOL="$MANIFEST_TOOL" # Let the user override the test. else @@ -7894,15 +7282,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_MANIFEST_TOOL="${ac_tool_prefix}mt" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7913,11 +7297,11 @@ fi fi MANIFEST_TOOL=$ac_cv_prog_MANIFEST_TOOL if test -n "$MANIFEST_TOOL"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $MANIFEST_TOOL" >&5 -printf "%s\n" "$MANIFEST_TOOL" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MANIFEST_TOOL" >&5 +$as_echo "$MANIFEST_TOOL" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi @@ -7926,12 +7310,11 @@ if test -z "$ac_cv_prog_MANIFEST_TOOL"; then ac_ct_MANIFEST_TOOL=$MANIFEST_TOOL # Extract the first word of "mt", so it can be a program name with args. set dummy mt; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_ac_ct_MANIFEST_TOOL+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_MANIFEST_TOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$ac_ct_MANIFEST_TOOL"; then ac_cv_prog_ac_ct_MANIFEST_TOOL="$ac_ct_MANIFEST_TOOL" # Let the user override the test. else @@ -7939,15 +7322,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_MANIFEST_TOOL="mt" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7958,11 +7337,11 @@ fi fi ac_ct_MANIFEST_TOOL=$ac_cv_prog_ac_ct_MANIFEST_TOOL if test -n "$ac_ct_MANIFEST_TOOL"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_MANIFEST_TOOL" >&5 -printf "%s\n" "$ac_ct_MANIFEST_TOOL" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_MANIFEST_TOOL" >&5 +$as_echo "$ac_ct_MANIFEST_TOOL" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi if test "x$ac_ct_MANIFEST_TOOL" = x; then @@ -7970,8 +7349,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac MANIFEST_TOOL=$ac_ct_MANIFEST_TOOL @@ -7981,12 +7360,11 @@ else fi test -z "$MANIFEST_TOOL" && MANIFEST_TOOL=mt -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $MANIFEST_TOOL is a manifest tool" >&5 -printf %s "checking if $MANIFEST_TOOL is a manifest tool... " >&6; } -if test ${lt_cv_path_mainfest_tool+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $MANIFEST_TOOL is a manifest tool" >&5 +$as_echo_n "checking if $MANIFEST_TOOL is a manifest tool... " >&6; } +if ${lt_cv_path_mainfest_tool+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_path_mainfest_tool=no echo "$as_me:$LINENO: $MANIFEST_TOOL '-?'" >&5 $MANIFEST_TOOL '-?' 2>conftest.err > conftest.out @@ -7996,8 +7374,8 @@ else $as_nop fi rm -f conftest* fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_mainfest_tool" >&5 -printf "%s\n" "$lt_cv_path_mainfest_tool" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_mainfest_tool" >&5 +$as_echo "$lt_cv_path_mainfest_tool" >&6; } if test yes != "$lt_cv_path_mainfest_tool"; then MANIFEST_TOOL=: fi @@ -8012,12 +7390,11 @@ fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}dsymutil", so it can be a program name with args. set dummy ${ac_tool_prefix}dsymutil; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_DSYMUTIL+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_DSYMUTIL+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$DSYMUTIL"; then ac_cv_prog_DSYMUTIL="$DSYMUTIL" # Let the user override the test. else @@ -8025,15 +7402,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_DSYMUTIL="${ac_tool_prefix}dsymutil" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8044,11 +7417,11 @@ fi fi DSYMUTIL=$ac_cv_prog_DSYMUTIL if test -n "$DSYMUTIL"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $DSYMUTIL" >&5 -printf "%s\n" "$DSYMUTIL" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DSYMUTIL" >&5 +$as_echo "$DSYMUTIL" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi @@ -8057,12 +7430,11 @@ if test -z "$ac_cv_prog_DSYMUTIL"; then ac_ct_DSYMUTIL=$DSYMUTIL # Extract the first word of "dsymutil", so it can be a program name with args. set dummy dsymutil; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_ac_ct_DSYMUTIL+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_DSYMUTIL+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$ac_ct_DSYMUTIL"; then ac_cv_prog_ac_ct_DSYMUTIL="$ac_ct_DSYMUTIL" # Let the user override the test. else @@ -8070,15 +7442,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_DSYMUTIL="dsymutil" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8089,11 +7457,11 @@ fi fi ac_ct_DSYMUTIL=$ac_cv_prog_ac_ct_DSYMUTIL if test -n "$ac_ct_DSYMUTIL"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DSYMUTIL" >&5 -printf "%s\n" "$ac_ct_DSYMUTIL" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DSYMUTIL" >&5 +$as_echo "$ac_ct_DSYMUTIL" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi if test "x$ac_ct_DSYMUTIL" = x; then @@ -8101,8 +7469,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac DSYMUTIL=$ac_ct_DSYMUTIL @@ -8114,12 +7482,11 @@ fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}nmedit", so it can be a program name with args. set dummy ${ac_tool_prefix}nmedit; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_NMEDIT+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_NMEDIT+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$NMEDIT"; then ac_cv_prog_NMEDIT="$NMEDIT" # Let the user override the test. else @@ -8127,15 +7494,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_NMEDIT="${ac_tool_prefix}nmedit" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8146,11 +7509,11 @@ fi fi NMEDIT=$ac_cv_prog_NMEDIT if test -n "$NMEDIT"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $NMEDIT" >&5 -printf "%s\n" "$NMEDIT" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $NMEDIT" >&5 +$as_echo "$NMEDIT" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi @@ -8159,12 +7522,11 @@ if test -z "$ac_cv_prog_NMEDIT"; then ac_ct_NMEDIT=$NMEDIT # Extract the first word of "nmedit", so it can be a program name with args. set dummy nmedit; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_ac_ct_NMEDIT+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_NMEDIT+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$ac_ct_NMEDIT"; then ac_cv_prog_ac_ct_NMEDIT="$ac_ct_NMEDIT" # Let the user override the test. else @@ -8172,15 +7534,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_NMEDIT="nmedit" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8191,11 +7549,11 @@ fi fi ac_ct_NMEDIT=$ac_cv_prog_ac_ct_NMEDIT if test -n "$ac_ct_NMEDIT"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_NMEDIT" >&5 -printf "%s\n" "$ac_ct_NMEDIT" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_NMEDIT" >&5 +$as_echo "$ac_ct_NMEDIT" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi if test "x$ac_ct_NMEDIT" = x; then @@ -8203,8 +7561,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac NMEDIT=$ac_ct_NMEDIT @@ -8216,12 +7574,11 @@ fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}lipo", so it can be a program name with args. set dummy ${ac_tool_prefix}lipo; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_LIPO+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_LIPO+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$LIPO"; then ac_cv_prog_LIPO="$LIPO" # Let the user override the test. else @@ -8229,15 +7586,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_LIPO="${ac_tool_prefix}lipo" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8248,11 +7601,11 @@ fi fi LIPO=$ac_cv_prog_LIPO if test -n "$LIPO"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $LIPO" >&5 -printf "%s\n" "$LIPO" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIPO" >&5 +$as_echo "$LIPO" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi @@ -8261,12 +7614,11 @@ if test -z "$ac_cv_prog_LIPO"; then ac_ct_LIPO=$LIPO # Extract the first word of "lipo", so it can be a program name with args. set dummy lipo; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_ac_ct_LIPO+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_LIPO+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$ac_ct_LIPO"; then ac_cv_prog_ac_ct_LIPO="$ac_ct_LIPO" # Let the user override the test. else @@ -8274,15 +7626,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_LIPO="lipo" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8293,11 +7641,11 @@ fi fi ac_ct_LIPO=$ac_cv_prog_ac_ct_LIPO if test -n "$ac_ct_LIPO"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_LIPO" >&5 -printf "%s\n" "$ac_ct_LIPO" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_LIPO" >&5 +$as_echo "$ac_ct_LIPO" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi if test "x$ac_ct_LIPO" = x; then @@ -8305,8 +7653,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac LIPO=$ac_ct_LIPO @@ -8318,12 +7666,11 @@ fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}otool", so it can be a program name with args. set dummy ${ac_tool_prefix}otool; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_OTOOL+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_OTOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$OTOOL"; then ac_cv_prog_OTOOL="$OTOOL" # Let the user override the test. else @@ -8331,15 +7678,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_OTOOL="${ac_tool_prefix}otool" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8350,11 +7693,11 @@ fi fi OTOOL=$ac_cv_prog_OTOOL if test -n "$OTOOL"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $OTOOL" >&5 -printf "%s\n" "$OTOOL" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OTOOL" >&5 +$as_echo "$OTOOL" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi @@ -8363,12 +7706,11 @@ if test -z "$ac_cv_prog_OTOOL"; then ac_ct_OTOOL=$OTOOL # Extract the first word of "otool", so it can be a program name with args. set dummy otool; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_ac_ct_OTOOL+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_OTOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$ac_ct_OTOOL"; then ac_cv_prog_ac_ct_OTOOL="$ac_ct_OTOOL" # Let the user override the test. else @@ -8376,15 +7718,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_OTOOL="otool" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8395,11 +7733,11 @@ fi fi ac_ct_OTOOL=$ac_cv_prog_ac_ct_OTOOL if test -n "$ac_ct_OTOOL"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL" >&5 -printf "%s\n" "$ac_ct_OTOOL" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL" >&5 +$as_echo "$ac_ct_OTOOL" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi if test "x$ac_ct_OTOOL" = x; then @@ -8407,8 +7745,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OTOOL=$ac_ct_OTOOL @@ -8420,12 +7758,11 @@ fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}otool64", so it can be a program name with args. set dummy ${ac_tool_prefix}otool64; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_OTOOL64+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_OTOOL64+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$OTOOL64"; then ac_cv_prog_OTOOL64="$OTOOL64" # Let the user override the test. else @@ -8433,15 +7770,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_OTOOL64="${ac_tool_prefix}otool64" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8452,11 +7785,11 @@ fi fi OTOOL64=$ac_cv_prog_OTOOL64 if test -n "$OTOOL64"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $OTOOL64" >&5 -printf "%s\n" "$OTOOL64" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OTOOL64" >&5 +$as_echo "$OTOOL64" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi @@ -8465,12 +7798,11 @@ if test -z "$ac_cv_prog_OTOOL64"; then ac_ct_OTOOL64=$OTOOL64 # Extract the first word of "otool64", so it can be a program name with args. set dummy otool64; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_prog_ac_ct_OTOOL64+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_OTOOL64+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$ac_ct_OTOOL64"; then ac_cv_prog_ac_ct_OTOOL64="$ac_ct_OTOOL64" # Let the user override the test. else @@ -8478,15 +7810,11 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_OTOOL64="otool64" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8497,11 +7825,11 @@ fi fi ac_ct_OTOOL64=$ac_cv_prog_ac_ct_OTOOL64 if test -n "$ac_ct_OTOOL64"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL64" >&5 -printf "%s\n" "$ac_ct_OTOOL64" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL64" >&5 +$as_echo "$ac_ct_OTOOL64" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi if test "x$ac_ct_OTOOL64" = x; then @@ -8509,8 +7837,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OTOOL64=$ac_ct_OTOOL64 @@ -8545,12 +7873,11 @@ fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for -single_module linker flag" >&5 -printf %s "checking for -single_module linker flag... " >&6; } -if test ${lt_cv_apple_cc_single_mod+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -single_module linker flag" >&5 +$as_echo_n "checking for -single_module linker flag... " >&6; } +if ${lt_cv_apple_cc_single_mod+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_apple_cc_single_mod=no if test -z "$LT_MULTI_MODULE"; then # By default we will add the -single_module flag. You can override @@ -8579,15 +7906,14 @@ else $as_nop rm -f conftest.* fi fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_apple_cc_single_mod" >&5 -printf "%s\n" "$lt_cv_apple_cc_single_mod" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_apple_cc_single_mod" >&5 +$as_echo "$lt_cv_apple_cc_single_mod" >&6; } - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for -exported_symbols_list linker flag" >&5 -printf %s "checking for -exported_symbols_list linker flag... " >&6; } -if test ${lt_cv_ld_exported_symbols_list+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -exported_symbols_list linker flag" >&5 +$as_echo_n "checking for -exported_symbols_list linker flag... " >&6; } +if ${lt_cv_ld_exported_symbols_list+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_ld_exported_symbols_list=no save_LDFLAGS=$LDFLAGS echo "_main" > conftest.sym @@ -8596,41 +7922,39 @@ else $as_nop /* end confdefs.h. */ int -main (void) +main () { ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : +if ac_fn_c_try_link "$LINENO"; then : lt_cv_ld_exported_symbols_list=yes -else $as_nop +else lt_cv_ld_exported_symbols_list=no fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LDFLAGS=$save_LDFLAGS fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_exported_symbols_list" >&5 -printf "%s\n" "$lt_cv_ld_exported_symbols_list" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_exported_symbols_list" >&5 +$as_echo "$lt_cv_ld_exported_symbols_list" >&6; } - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for -force_load linker flag" >&5 -printf %s "checking for -force_load linker flag... " >&6; } -if test ${lt_cv_ld_force_load+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -force_load linker flag" >&5 +$as_echo_n "checking for -force_load linker flag... " >&6; } +if ${lt_cv_ld_force_load+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_ld_force_load=no cat > conftest.c << _LT_EOF int forced_loaded() { return 2;} _LT_EOF echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&5 $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&5 - echo "$AR cr libconftest.a conftest.o" >&5 - $AR cr libconftest.a conftest.o 2>&5 + echo "$AR cru libconftest.a conftest.o" >&5 + $AR cru libconftest.a conftest.o 2>&5 echo "$RANLIB libconftest.a" >&5 $RANLIB libconftest.a 2>&5 cat > conftest.c << _LT_EOF @@ -8650,8 +7974,8 @@ _LT_EOF rm -rf conftest.dSYM fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_force_load" >&5 -printf "%s\n" "$lt_cv_ld_force_load" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_force_load" >&5 +$as_echo "$lt_cv_ld_force_load" >&6; } case $host_os in rhapsody* | darwin1.[012]) _lt_dar_allow_undefined='$wl-undefined ${wl}suppress' ;; @@ -8662,11 +7986,11 @@ printf "%s\n" "$lt_cv_ld_force_load" >&6; } # to the OS version, if on x86, and 10.4, the deployment # target defaults to 10.4. Don't you love it? case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in - 10.0,*86*-darwin8*|10.0,*-darwin[912]*) + 10.0,*86*-darwin8*|10.0,*-darwin[91]*) _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; 10.[012][,.]*) _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; - 10.*|11.*) + 10.*) _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; esac ;; @@ -8722,43 +8046,149 @@ func_munge_path_list () esac } -ac_header= ac_cache= -for ac_item in $ac_header_c_list -do - if test $ac_cache; then - ac_fn_c_check_header_compile "$LINENO" $ac_header ac_cv_header_$ac_cache "$ac_includes_default" - if eval test \"x\$ac_cv_header_$ac_cache\" = xyes; then - printf "%s\n" "#define $ac_item 1" >> confdefs.h - fi - ac_header= ac_cache= - elif test $ac_header; then - ac_cache=$ac_item - else - ac_header=$ac_item - fi -done +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 +$as_echo_n "checking for ANSI C header files... " >&6; } +if ${ac_cv_header_stdc+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include +#include + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_header_stdc=yes +else + ac_cv_header_stdc=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +if test $ac_cv_header_stdc = yes; then + # SunOS 4.x string.h does not declare mem*, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "memchr" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "free" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* +fi +if test $ac_cv_header_stdc = yes; then + # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. + if test "$cross_compiling" = yes; then : + : +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#if ((' ' & 0x0FF) == 0x020) +# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) +#else +# define ISLOWER(c) \ + (('a' <= (c) && (c) <= 'i') \ + || ('j' <= (c) && (c) <= 'r') \ + || ('s' <= (c) && (c) <= 'z')) +# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) +#endif +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) +int +main () +{ + int i; + for (i = 0; i < 256; i++) + if (XOR (islower (i), ISLOWER (i)) + || toupper (i) != TOUPPER (i)) + return 2; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : +else + ac_cv_header_stdc=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 +$as_echo "$ac_cv_header_stdc" >&6; } +if test $ac_cv_header_stdc = yes; then +$as_echo "#define STDC_HEADERS 1" >>confdefs.h -if test $ac_cv_header_stdlib_h = yes && test $ac_cv_header_string_h = yes -then : +fi -printf "%s\n" "#define STDC_HEADERS 1" >>confdefs.h +# On IRIX 5.3, sys/types and inttypes.h are conflicting. +for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ + inttypes.h stdint.h unistd.h +do : + as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` +ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default +" +if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF fi -ac_fn_c_check_header_compile "$LINENO" "dlfcn.h" "ac_cv_header_dlfcn_h" "$ac_includes_default + +done + + +for ac_header in dlfcn.h +do : + ac_fn_c_check_header_compile "$LINENO" "dlfcn.h" "ac_cv_header_dlfcn_h" "$ac_includes_default " -if test "x$ac_cv_header_dlfcn_h" = xyes -then : - printf "%s\n" "#define HAVE_DLFCN_H 1" >>confdefs.h +if test "x$ac_cv_header_dlfcn_h" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_DLFCN_H 1 +_ACEOF fi +done + @@ -8782,8 +8212,7 @@ func_stripname_cnf () # Check whether --enable-shared was given. -if test ${enable_shared+y} -then : +if test "${enable_shared+set}" = set; then : enableval=$enable_shared; p=${PACKAGE-default} case $enableval in yes) enable_shared=yes ;; @@ -8801,7 +8230,7 @@ then : IFS=$lt_save_ifs ;; esac -else $as_nop +else enable_shared=yes fi @@ -8814,8 +8243,7 @@ fi # Check whether --enable-static was given. -if test ${enable_static+y} -then : +if test "${enable_static+set}" = set; then : enableval=$enable_static; p=${PACKAGE-default} case $enableval in yes) enable_static=yes ;; @@ -8833,7 +8261,7 @@ then : IFS=$lt_save_ifs ;; esac -else $as_nop +else enable_static=yes fi @@ -8847,8 +8275,7 @@ fi # Check whether --with-pic was given. -if test ${with_pic+y} -then : +if test "${with_pic+set}" = set; then : withval=$with_pic; lt_p=${PACKAGE-default} case $withval in yes|no) pic_mode=$withval ;; @@ -8865,7 +8292,7 @@ then : IFS=$lt_save_ifs ;; esac -else $as_nop +else pic_mode=default fi @@ -8877,8 +8304,7 @@ fi # Check whether --enable-fast-install was given. -if test ${enable_fast_install+y} -then : +if test "${enable_fast_install+set}" = set; then : enableval=$enable_fast_install; p=${PACKAGE-default} case $enableval in yes) enable_fast_install=yes ;; @@ -8896,7 +8322,7 @@ then : IFS=$lt_save_ifs ;; esac -else $as_nop +else enable_fast_install=yes fi @@ -8910,12 +8336,11 @@ fi shared_archive_member_spec= case $host,$enable_shared in power*-*-aix[5-9]*,yes) - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking which variant of shared library versioning to provide" >&5 -printf %s "checking which variant of shared library versioning to provide... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking which variant of shared library versioning to provide" >&5 +$as_echo_n "checking which variant of shared library versioning to provide... " >&6; } # Check whether --with-aix-soname was given. -if test ${with_aix_soname+y} -then : +if test "${with_aix_soname+set}" = set; then : withval=$with_aix_soname; case $withval in aix|svr4|both) ;; @@ -8924,19 +8349,18 @@ then : ;; esac lt_cv_with_aix_soname=$with_aix_soname -else $as_nop - if test ${lt_cv_with_aix_soname+y} -then : - printf %s "(cached) " >&6 -else $as_nop +else + if ${lt_cv_with_aix_soname+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_with_aix_soname=aix fi with_aix_soname=$lt_cv_with_aix_soname fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $with_aix_soname" >&5 -printf "%s\n" "$with_aix_soname" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_aix_soname" >&5 +$as_echo "$with_aix_soname" >&6; } if test aix != "$with_aix_soname"; then # For the AIX way of multilib, we name the shared archive member # based on the bitwidth used, traditionally 'shr.o' or 'shr_64.o', @@ -9018,12 +8442,11 @@ if test -n "${ZSH_VERSION+set}"; then setopt NO_GLOB_SUBST fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for objdir" >&5 -printf %s "checking for objdir... " >&6; } -if test ${lt_cv_objdir+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for objdir" >&5 +$as_echo_n "checking for objdir... " >&6; } +if ${lt_cv_objdir+:} false; then : + $as_echo_n "(cached) " >&6 +else rm -f .libs 2>/dev/null mkdir .libs 2>/dev/null if test -d .libs; then @@ -9034,15 +8457,17 @@ else fi rmdir .libs 2>/dev/null fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_objdir" >&5 -printf "%s\n" "$lt_cv_objdir" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_objdir" >&5 +$as_echo "$lt_cv_objdir" >&6; } objdir=$lt_cv_objdir -printf "%s\n" "#define LT_OBJDIR \"$lt_cv_objdir/\"" >>confdefs.h +cat >>confdefs.h <<_ACEOF +#define LT_OBJDIR "$lt_cv_objdir/" +_ACEOF @@ -9088,12 +8513,11 @@ test -z "$MAGIC_CMD" && MAGIC_CMD=file case $deplibs_check_method in file_magic*) if test "$file_magic_cmd" = '$MAGIC_CMD'; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for ${ac_tool_prefix}file" >&5 -printf %s "checking for ${ac_tool_prefix}file... " >&6; } -if test ${lt_cv_path_MAGIC_CMD+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${ac_tool_prefix}file" >&5 +$as_echo_n "checking for ${ac_tool_prefix}file... " >&6; } +if ${lt_cv_path_MAGIC_CMD+:} false; then : + $as_echo_n "(cached) " >&6 +else case $MAGIC_CMD in [\\/*] | ?:[\\/]*) lt_cv_path_MAGIC_CMD=$MAGIC_CMD # Let the user override the test with a path. @@ -9142,11 +8566,11 @@ fi MAGIC_CMD=$lt_cv_path_MAGIC_CMD if test -n "$MAGIC_CMD"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 -printf "%s\n" "$MAGIC_CMD" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 +$as_echo "$MAGIC_CMD" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi @@ -9155,12 +8579,11 @@ fi if test -z "$lt_cv_path_MAGIC_CMD"; then if test -n "$ac_tool_prefix"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for file" >&5 -printf %s "checking for file... " >&6; } -if test ${lt_cv_path_MAGIC_CMD+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for file" >&5 +$as_echo_n "checking for file... " >&6; } +if ${lt_cv_path_MAGIC_CMD+:} false; then : + $as_echo_n "(cached) " >&6 +else case $MAGIC_CMD in [\\/*] | ?:[\\/]*) lt_cv_path_MAGIC_CMD=$MAGIC_CMD # Let the user override the test with a path. @@ -9209,11 +8632,11 @@ fi MAGIC_CMD=$lt_cv_path_MAGIC_CMD if test -n "$MAGIC_CMD"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 -printf "%s\n" "$MAGIC_CMD" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 +$as_echo "$MAGIC_CMD" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi @@ -9294,12 +8717,11 @@ if test yes = "$GCC"; then lt_prog_compiler_no_builtin_flag=' -fno-builtin' ;; esac - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -fno-rtti -fno-exceptions" >&5 -printf %s "checking if $compiler supports -fno-rtti -fno-exceptions... " >&6; } -if test ${lt_cv_prog_compiler_rtti_exceptions+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -fno-rtti -fno-exceptions" >&5 +$as_echo_n "checking if $compiler supports -fno-rtti -fno-exceptions... " >&6; } +if ${lt_cv_prog_compiler_rtti_exceptions+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_prog_compiler_rtti_exceptions=no ac_outfile=conftest.$ac_objext echo "$lt_simple_compile_test_code" > conftest.$ac_ext @@ -9330,8 +8752,8 @@ else $as_nop $RM conftest* fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_rtti_exceptions" >&5 -printf "%s\n" "$lt_cv_prog_compiler_rtti_exceptions" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_rtti_exceptions" >&5 +$as_echo "$lt_cv_prog_compiler_rtti_exceptions" >&6; } if test yes = "$lt_cv_prog_compiler_rtti_exceptions"; then lt_prog_compiler_no_builtin_flag="$lt_prog_compiler_no_builtin_flag -fno-rtti -fno-exceptions" @@ -9528,12 +8950,6 @@ lt_prog_compiler_static= lt_prog_compiler_pic='-KPIC' lt_prog_compiler_static='-static' ;; - # flang / f18. f95 an alias for gfortran or flang on Debian - flang* | f18* | f95*) - lt_prog_compiler_wl='-Wl,' - lt_prog_compiler_pic='-fPIC' - lt_prog_compiler_static='-static' - ;; # icc used to be incompatible with GCC. # ICC 10 doesn't accept -KPIC any more. icc* | ifort*) @@ -9694,28 +9110,26 @@ case $host_os in ;; esac -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5 -printf %s "checking for $compiler option to produce PIC... " >&6; } -if test ${lt_cv_prog_compiler_pic+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5 +$as_echo_n "checking for $compiler option to produce PIC... " >&6; } +if ${lt_cv_prog_compiler_pic+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_prog_compiler_pic=$lt_prog_compiler_pic fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic" >&5 -printf "%s\n" "$lt_cv_prog_compiler_pic" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic" >&5 +$as_echo "$lt_cv_prog_compiler_pic" >&6; } lt_prog_compiler_pic=$lt_cv_prog_compiler_pic # # Check to make sure the PIC flag actually works. # if test -n "$lt_prog_compiler_pic"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic works" >&5 -printf %s "checking if $compiler PIC flag $lt_prog_compiler_pic works... " >&6; } -if test ${lt_cv_prog_compiler_pic_works+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic works" >&5 +$as_echo_n "checking if $compiler PIC flag $lt_prog_compiler_pic works... " >&6; } +if ${lt_cv_prog_compiler_pic_works+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_prog_compiler_pic_works=no ac_outfile=conftest.$ac_objext echo "$lt_simple_compile_test_code" > conftest.$ac_ext @@ -9746,8 +9160,8 @@ else $as_nop $RM conftest* fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works" >&5 -printf "%s\n" "$lt_cv_prog_compiler_pic_works" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works" >&5 +$as_echo "$lt_cv_prog_compiler_pic_works" >&6; } if test yes = "$lt_cv_prog_compiler_pic_works"; then case $lt_prog_compiler_pic in @@ -9775,12 +9189,11 @@ fi # Check to make sure the static flag actually works. # wl=$lt_prog_compiler_wl eval lt_tmp_static_flag=\"$lt_prog_compiler_static\" -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5 -printf %s "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; } -if test ${lt_cv_prog_compiler_static_works+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5 +$as_echo_n "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; } +if ${lt_cv_prog_compiler_static_works+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_prog_compiler_static_works=no save_LDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS $lt_tmp_static_flag" @@ -9804,8 +9217,8 @@ else $as_nop LDFLAGS=$save_LDFLAGS fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works" >&5 -printf "%s\n" "$lt_cv_prog_compiler_static_works" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works" >&5 +$as_echo "$lt_cv_prog_compiler_static_works" >&6; } if test yes = "$lt_cv_prog_compiler_static_works"; then : @@ -9819,12 +9232,11 @@ fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 -printf %s "checking if $compiler supports -c -o file.$ac_objext... " >&6; } -if test ${lt_cv_prog_compiler_c_o+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if ${lt_cv_prog_compiler_c_o+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_prog_compiler_c_o=no $RM -r conftest 2>/dev/null mkdir conftest @@ -9867,20 +9279,19 @@ else $as_nop $RM conftest* fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 -printf "%s\n" "$lt_cv_prog_compiler_c_o" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 +$as_echo "$lt_cv_prog_compiler_c_o" >&6; } - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 -printf %s "checking if $compiler supports -c -o file.$ac_objext... " >&6; } -if test ${lt_cv_prog_compiler_c_o+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if ${lt_cv_prog_compiler_c_o+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_prog_compiler_c_o=no $RM -r conftest 2>/dev/null mkdir conftest @@ -9923,8 +9334,8 @@ else $as_nop $RM conftest* fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 -printf "%s\n" "$lt_cv_prog_compiler_c_o" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 +$as_echo "$lt_cv_prog_compiler_c_o" >&6; } @@ -9932,19 +9343,19 @@ printf "%s\n" "$lt_cv_prog_compiler_c_o" >&6; } hard_links=nottested if test no = "$lt_cv_prog_compiler_c_o" && test no != "$need_locks"; then # do not overwrite the value of need_locks provided by the user - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5 -printf %s "checking if we can lock with hard links... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5 +$as_echo_n "checking if we can lock with hard links... " >&6; } hard_links=yes $RM conftest* ln conftest.a conftest.b 2>/dev/null && hard_links=no touch conftest.a ln conftest.a conftest.b 2>&5 || hard_links=no ln conftest.a conftest.b 2>/dev/null && hard_links=no - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5 -printf "%s\n" "$hard_links" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5 +$as_echo "$hard_links" >&6; } if test no = "$hard_links"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&5 -printf "%s\n" "$as_me: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&5 +$as_echo "$as_me: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&2;} need_locks=warn fi else @@ -9956,8 +9367,8 @@ fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 -printf %s "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +$as_echo_n "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } runpath_var= allow_undefined_flag= @@ -10015,9 +9426,6 @@ printf %s "checking whether the $compiler linker ($LD) supports shared libraries openbsd* | bitrig*) with_gnu_ld=no ;; - linux* | k*bsd*-gnu | gnu*) - link_all_deplibs=no - ;; esac ld_shlibs=yes @@ -10272,7 +9680,7 @@ _LT_EOF fi ;; - netbsd* | netbsdelf*-gnu) + netbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then archive_cmds='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' wlarc= @@ -10515,23 +9923,21 @@ _LT_EOF if test set = "${lt_cv_aix_libpath+set}"; then aix_libpath=$lt_cv_aix_libpath else - if test ${lt_cv_aix_libpath_+y} -then : - printf %s "(cached) " >&6 -else $as_nop + if ${lt_cv_aix_libpath_+:} false; then : + $as_echo_n "(cached) " >&6 +else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main (void) +main () { ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : +if ac_fn_c_try_link "$LINENO"; then : lt_aix_libpath_sed=' /Import File Strings/,/^$/ { @@ -10546,7 +9952,7 @@ then : lt_cv_aix_libpath_=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` fi fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext if test -z "$lt_cv_aix_libpath_"; then lt_cv_aix_libpath_=/usr/lib:/lib @@ -10570,23 +9976,21 @@ fi if test set = "${lt_cv_aix_libpath+set}"; then aix_libpath=$lt_cv_aix_libpath else - if test ${lt_cv_aix_libpath_+y} -then : - printf %s "(cached) " >&6 -else $as_nop + if ${lt_cv_aix_libpath_+:} false; then : + $as_echo_n "(cached) " >&6 +else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main (void) +main () { ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : +if ac_fn_c_try_link "$LINENO"; then : lt_aix_libpath_sed=' /Import File Strings/,/^$/ { @@ -10601,7 +10005,7 @@ then : lt_cv_aix_libpath_=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` fi fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext if test -z "$lt_cv_aix_libpath_"; then lt_cv_aix_libpath_=/usr/lib:/lib @@ -10852,12 +10256,11 @@ fi # Older versions of the 11.00 compiler do not understand -b yet # (HP92453-01 A.11.01.20 doesn't, HP92453-01 B.11.X.35175-35176.GP does) - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $CC understands -b" >&5 -printf %s "checking if $CC understands -b... " >&6; } -if test ${lt_cv_prog_compiler__b+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC understands -b" >&5 +$as_echo_n "checking if $CC understands -b... " >&6; } +if ${lt_cv_prog_compiler__b+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_prog_compiler__b=no save_LDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS -b" @@ -10881,8 +10284,8 @@ else $as_nop LDFLAGS=$save_LDFLAGS fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler__b" >&5 -printf "%s\n" "$lt_cv_prog_compiler__b" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler__b" >&5 +$as_echo "$lt_cv_prog_compiler__b" >&6; } if test yes = "$lt_cv_prog_compiler__b"; then archive_cmds='$CC -b $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags' @@ -10922,34 +10325,31 @@ fi # work, assume that -exports_file does not work either and # implicitly export all symbols. # This should be the same for all languages, so no per-tag cache variable. - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the $host_os linker accepts -exported_symbol" >&5 -printf %s "checking whether the $host_os linker accepts -exported_symbol... " >&6; } -if test ${lt_cv_irix_exported_symbol+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $host_os linker accepts -exported_symbol" >&5 +$as_echo_n "checking whether the $host_os linker accepts -exported_symbol... " >&6; } +if ${lt_cv_irix_exported_symbol+:} false; then : + $as_echo_n "(cached) " >&6 +else save_LDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS -shared $wl-exported_symbol ${wl}foo $wl-update_registry $wl/dev/null" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int foo (void) { return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : +if ac_fn_c_try_link "$LINENO"; then : lt_cv_irix_exported_symbol=yes -else $as_nop +else lt_cv_irix_exported_symbol=no fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LDFLAGS=$save_LDFLAGS fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_irix_exported_symbol" >&5 -printf "%s\n" "$lt_cv_irix_exported_symbol" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_irix_exported_symbol" >&5 +$as_echo "$lt_cv_irix_exported_symbol" >&6; } if test yes = "$lt_cv_irix_exported_symbol"; then archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations $wl-exports_file $wl$export_symbols -o $lib' fi - link_all_deplibs=no else archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -exports_file $export_symbols -o $lib' @@ -10971,7 +10371,7 @@ printf "%s\n" "$lt_cv_irix_exported_symbol" >&6; } esac ;; - netbsd* | netbsdelf*-gnu) + netbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out else @@ -11226,8 +10626,8 @@ printf "%s\n" "$lt_cv_irix_exported_symbol" >&6; } fi fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs" >&5 -printf "%s\n" "$ld_shlibs" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs" >&5 +$as_echo "$ld_shlibs" >&6; } test no = "$ld_shlibs" && can_build_shared=no with_gnu_ld=$with_gnu_ld @@ -11263,19 +10663,18 @@ x|xyes) # Test whether the compiler implicitly links with -lc since on some # systems, -lgcc has to come before -lc. If gcc already passes -lc # to ld, don't add -lc before -lgcc. - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5 -printf %s "checking whether -lc should be explicitly linked in... " >&6; } -if test ${lt_cv_archive_cmds_need_lc+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5 +$as_echo_n "checking whether -lc should be explicitly linked in... " >&6; } +if ${lt_cv_archive_cmds_need_lc+:} false; then : + $as_echo_n "(cached) " >&6 +else $RM conftest* echo "$lt_simple_compile_test_code" > conftest.$ac_ext if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } 2>conftest.err; then soname=conftest lib=conftest @@ -11293,7 +10692,7 @@ else $as_nop if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1\""; } >&5 (eval $archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) 2>&5 ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } then lt_cv_archive_cmds_need_lc=no @@ -11307,8 +10706,8 @@ else $as_nop $RM conftest* fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_archive_cmds_need_lc" >&5 -printf "%s\n" "$lt_cv_archive_cmds_need_lc" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_archive_cmds_need_lc" >&5 +$as_echo "$lt_cv_archive_cmds_need_lc" >&6; } archive_cmds_need_lc=$lt_cv_archive_cmds_need_lc ;; esac @@ -11467,8 +10866,8 @@ esac - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5 -printf %s "checking dynamic linker characteristics... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5 +$as_echo_n "checking dynamic linker characteristics... " >&6; } if test yes = "$GCC"; then case $host_os in @@ -12029,10 +11428,9 @@ linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) shlibpath_overrides_runpath=no # Some binutils ld are patched to set DT_RUNPATH - if test ${lt_cv_shlibpath_overrides_runpath+y} -then : - printf %s "(cached) " >&6 -else $as_nop + if ${lt_cv_shlibpath_overrides_runpath+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_shlibpath_overrides_runpath=no save_LDFLAGS=$LDFLAGS save_libdir=$libdir @@ -12042,21 +11440,19 @@ else $as_nop /* end confdefs.h. */ int -main (void) +main () { ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : - if ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null -then : +if ac_fn_c_try_link "$LINENO"; then : + if ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null; then : lt_cv_shlibpath_overrides_runpath=yes fi fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LDFLAGS=$save_LDFLAGS libdir=$save_libdir @@ -12070,6 +11466,9 @@ fi # before this can be enabled. hardcode_into_libs=yes + # Add ABI-specific directories to the system library path. + sys_lib_dlsearch_path_spec="/lib64 /usr/lib64 /lib /usr/lib" + # Ideally, we could use ldconfig to report *all* directores which are # searched for libraries, however this is still not possible. Aside from not # being certain /sbin/ldconfig is available, command @@ -12078,7 +11477,7 @@ fi # appending ld.so.conf contents (and includes) to the search path. if test -f /etc/ld.so.conf; then lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` - sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" + sys_lib_dlsearch_path_spec="$sys_lib_dlsearch_path_spec $lt_ld_extra" fi # We used to test for /lib/ld.so.1 and disable shared libraries on @@ -12090,18 +11489,6 @@ fi dynamic_linker='GNU/Linux ld.so' ;; -netbsdelf*-gnu) - version_type=linux - need_lib_prefix=no - need_version=no - library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' - soname_spec='${libname}${release}${shared_ext}$major' - shlibpath_var=LD_LIBRARY_PATH - shlibpath_overrides_runpath=no - hardcode_into_libs=yes - dynamic_linker='NetBSD ld.elf_so' - ;; - netbsd*) version_type=sunos need_lib_prefix=no @@ -12300,8 +11687,8 @@ uts4*) dynamic_linker=no ;; esac -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5 -printf "%s\n" "$dynamic_linker" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5 +$as_echo "$dynamic_linker" >&6; } test no = "$dynamic_linker" && can_build_shared=no variables_saved_for_relink="PATH $shlibpath_var $runpath_var" @@ -12422,8 +11809,8 @@ configure_time_lt_sys_library_path=$LT_SYS_LIBRARY_PATH - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5 -printf %s "checking how to hardcode library paths into programs... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5 +$as_echo_n "checking how to hardcode library paths into programs... " >&6; } hardcode_action= if test -n "$hardcode_libdir_flag_spec" || test -n "$runpath_var" || @@ -12447,8 +11834,8 @@ else # directories. hardcode_action=unsupported fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $hardcode_action" >&5 -printf "%s\n" "$hardcode_action" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $hardcode_action" >&5 +$as_echo "$hardcode_action" >&6; } if test relink = "$hardcode_action" || test yes = "$inherit_rpath"; then @@ -12492,12 +11879,11 @@ else darwin*) # if libdl is installed we need to link against it - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 -printf %s "checking for dlopen in -ldl... " >&6; } -if test ${ac_cv_lib_dl_dlopen+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 +$as_echo_n "checking for dlopen in -ldl... " >&6; } +if ${ac_cv_lib_dl_dlopen+:} false; then : + $as_echo_n "(cached) " >&6 +else ac_check_lib_save_LIBS=$LIBS LIBS="-ldl $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -12506,31 +11892,32 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif char dlopen (); int -main (void) +main () { return dlopen (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : +if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_dl_dlopen=yes -else $as_nop +else ac_cv_lib_dl_dlopen=no fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 -printf "%s\n" "$ac_cv_lib_dl_dlopen" >&6; } -if test "x$ac_cv_lib_dl_dlopen" = xyes -then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 +$as_echo "$ac_cv_lib_dl_dlopen" >&6; } +if test "x$ac_cv_lib_dl_dlopen" = xyes; then : lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-ldl -else $as_nop +else lt_cv_dlopen=dyld lt_cv_dlopen_libs= @@ -12550,16 +11937,14 @@ fi *) ac_fn_c_check_func "$LINENO" "shl_load" "ac_cv_func_shl_load" -if test "x$ac_cv_func_shl_load" = xyes -then : +if test "x$ac_cv_func_shl_load" = xyes; then : lt_cv_dlopen=shl_load -else $as_nop - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5 -printf %s "checking for shl_load in -ldld... " >&6; } -if test ${ac_cv_lib_dld_shl_load+y} -then : - printf %s "(cached) " >&6 -else $as_nop +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5 +$as_echo_n "checking for shl_load in -ldld... " >&6; } +if ${ac_cv_lib_dld_shl_load+:} false; then : + $as_echo_n "(cached) " >&6 +else ac_check_lib_save_LIBS=$LIBS LIBS="-ldld $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -12568,42 +11953,41 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif char shl_load (); int -main (void) +main () { return shl_load (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : +if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_dld_shl_load=yes -else $as_nop +else ac_cv_lib_dld_shl_load=no fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5 -printf "%s\n" "$ac_cv_lib_dld_shl_load" >&6; } -if test "x$ac_cv_lib_dld_shl_load" = xyes -then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5 +$as_echo "$ac_cv_lib_dld_shl_load" >&6; } +if test "x$ac_cv_lib_dld_shl_load" = xyes; then : lt_cv_dlopen=shl_load lt_cv_dlopen_libs=-ldld -else $as_nop +else ac_fn_c_check_func "$LINENO" "dlopen" "ac_cv_func_dlopen" -if test "x$ac_cv_func_dlopen" = xyes -then : +if test "x$ac_cv_func_dlopen" = xyes; then : lt_cv_dlopen=dlopen -else $as_nop - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 -printf %s "checking for dlopen in -ldl... " >&6; } -if test ${ac_cv_lib_dl_dlopen+y} -then : - printf %s "(cached) " >&6 -else $as_nop +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 +$as_echo_n "checking for dlopen in -ldl... " >&6; } +if ${ac_cv_lib_dl_dlopen+:} false; then : + $as_echo_n "(cached) " >&6 +else ac_check_lib_save_LIBS=$LIBS LIBS="-ldl $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -12612,37 +11996,37 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif char dlopen (); int -main (void) +main () { return dlopen (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : +if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_dl_dlopen=yes -else $as_nop +else ac_cv_lib_dl_dlopen=no fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 -printf "%s\n" "$ac_cv_lib_dl_dlopen" >&6; } -if test "x$ac_cv_lib_dl_dlopen" = xyes -then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 +$as_echo "$ac_cv_lib_dl_dlopen" >&6; } +if test "x$ac_cv_lib_dl_dlopen" = xyes; then : lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-ldl -else $as_nop - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for dlopen in -lsvld" >&5 -printf %s "checking for dlopen in -lsvld... " >&6; } -if test ${ac_cv_lib_svld_dlopen+y} -then : - printf %s "(cached) " >&6 -else $as_nop +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -lsvld" >&5 +$as_echo_n "checking for dlopen in -lsvld... " >&6; } +if ${ac_cv_lib_svld_dlopen+:} false; then : + $as_echo_n "(cached) " >&6 +else ac_check_lib_save_LIBS=$LIBS LIBS="-lsvld $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -12651,37 +12035,37 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif char dlopen (); int -main (void) +main () { return dlopen (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : +if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_svld_dlopen=yes -else $as_nop +else ac_cv_lib_svld_dlopen=no fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_svld_dlopen" >&5 -printf "%s\n" "$ac_cv_lib_svld_dlopen" >&6; } -if test "x$ac_cv_lib_svld_dlopen" = xyes -then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_svld_dlopen" >&5 +$as_echo "$ac_cv_lib_svld_dlopen" >&6; } +if test "x$ac_cv_lib_svld_dlopen" = xyes; then : lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-lsvld -else $as_nop - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for dld_link in -ldld" >&5 -printf %s "checking for dld_link in -ldld... " >&6; } -if test ${ac_cv_lib_dld_dld_link+y} -then : - printf %s "(cached) " >&6 -else $as_nop +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dld_link in -ldld" >&5 +$as_echo_n "checking for dld_link in -ldld... " >&6; } +if ${ac_cv_lib_dld_dld_link+:} false; then : + $as_echo_n "(cached) " >&6 +else ac_check_lib_save_LIBS=$LIBS LIBS="-ldld $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -12690,29 +12074,30 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif char dld_link (); int -main (void) +main () { return dld_link (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : +if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_dld_dld_link=yes -else $as_nop +else ac_cv_lib_dld_dld_link=no fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_dld_link" >&5 -printf "%s\n" "$ac_cv_lib_dld_dld_link" >&6; } -if test "x$ac_cv_lib_dld_dld_link" = xyes -then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_dld_link" >&5 +$as_echo "$ac_cv_lib_dld_dld_link" >&6; } +if test "x$ac_cv_lib_dld_dld_link" = xyes; then : lt_cv_dlopen=dld_link lt_cv_dlopen_libs=-ldld fi @@ -12751,12 +12136,11 @@ fi save_LIBS=$LIBS LIBS="$lt_cv_dlopen_libs $LIBS" - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether a program can dlopen itself" >&5 -printf %s "checking whether a program can dlopen itself... " >&6; } -if test ${lt_cv_dlopen_self+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a program can dlopen itself" >&5 +$as_echo_n "checking whether a program can dlopen itself... " >&6; } +if ${lt_cv_dlopen_self+:} false; then : + $as_echo_n "(cached) " >&6 +else if test yes = "$cross_compiling"; then : lt_cv_dlopen_self=cross else @@ -12835,7 +12219,7 @@ _LT_EOF if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 (eval $ac_link) 2>&5 ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && test -s "conftest$ac_exeext" 2>/dev/null; then (./conftest; exit; ) >&5 2>/dev/null lt_status=$? @@ -12853,17 +12237,16 @@ rm -fr conftest* fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self" >&5 -printf "%s\n" "$lt_cv_dlopen_self" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self" >&5 +$as_echo "$lt_cv_dlopen_self" >&6; } if test yes = "$lt_cv_dlopen_self"; then wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\" - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether a statically linked program can dlopen itself" >&5 -printf %s "checking whether a statically linked program can dlopen itself... " >&6; } -if test ${lt_cv_dlopen_self_static+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a statically linked program can dlopen itself" >&5 +$as_echo_n "checking whether a statically linked program can dlopen itself... " >&6; } +if ${lt_cv_dlopen_self_static+:} false; then : + $as_echo_n "(cached) " >&6 +else if test yes = "$cross_compiling"; then : lt_cv_dlopen_self_static=cross else @@ -12942,7 +12325,7 @@ _LT_EOF if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 (eval $ac_link) 2>&5 ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && test -s "conftest$ac_exeext" 2>/dev/null; then (./conftest; exit; ) >&5 2>/dev/null lt_status=$? @@ -12960,8 +12343,8 @@ rm -fr conftest* fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self_static" >&5 -printf "%s\n" "$lt_cv_dlopen_self_static" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self_static" >&5 +$as_echo "$lt_cv_dlopen_self_static" >&6; } fi CPPFLAGS=$save_CPPFLAGS @@ -12999,13 +12382,13 @@ fi striplib= old_striplib= -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether stripping libraries is possible" >&5 -printf %s "checking whether stripping libraries is possible... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether stripping libraries is possible" >&5 +$as_echo_n "checking whether stripping libraries is possible... " >&6; } if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then test -z "$old_striplib" && old_striplib="$STRIP --strip-debug" test -z "$striplib" && striplib="$STRIP --strip-unneeded" - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -printf "%s\n" "yes" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } else # FIXME - insert some real tests, host_os isn't really good enough case $host_os in @@ -13013,16 +12396,16 @@ else if test -n "$STRIP"; then striplib="$STRIP -x" old_striplib="$STRIP -S" - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -printf "%s\n" "yes" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi ;; *) - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } ;; esac fi @@ -13039,13 +12422,13 @@ fi # Report what library types will actually be built - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if libtool supports shared libraries" >&5 -printf %s "checking if libtool supports shared libraries... " >&6; } - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $can_build_shared" >&5 -printf "%s\n" "$can_build_shared" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if libtool supports shared libraries" >&5 +$as_echo_n "checking if libtool supports shared libraries... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $can_build_shared" >&5 +$as_echo "$can_build_shared" >&6; } - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to build shared libraries" >&5 -printf %s "checking whether to build shared libraries... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build shared libraries" >&5 +$as_echo_n "checking whether to build shared libraries... " >&6; } test no = "$can_build_shared" && enable_shared=no # On AIX, shared libraries and static libraries use the same namespace, and @@ -13069,15 +12452,15 @@ printf %s "checking whether to build shared libraries... " >&6; } fi ;; esac - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $enable_shared" >&5 -printf "%s\n" "$enable_shared" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_shared" >&5 +$as_echo "$enable_shared" >&6; } - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to build static libraries" >&5 -printf %s "checking whether to build static libraries... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build static libraries" >&5 +$as_echo_n "checking whether to build static libraries... " >&6; } # Make sure either enable_shared or enable_static is yes. test yes = "$enable_shared" || enable_static=yes - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $enable_static" >&5 -printf "%s\n" "$enable_static" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_static" >&5 +$as_echo "$enable_static" >&6; } @@ -13099,32 +12482,36 @@ ac_cpp='$CXXCPP $CPPFLAGS' ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_cxx_compiler_gnu -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to run the C++ preprocessor" >&5 -printf %s "checking how to run the C++ preprocessor... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C++ preprocessor" >&5 +$as_echo_n "checking how to run the C++ preprocessor... " >&6; } if test -z "$CXXCPP"; then - if test ${ac_cv_prog_CXXCPP+y} -then : - printf %s "(cached) " >&6 -else $as_nop - # Double quotes because $CXX needs to be expanded - for CXXCPP in "$CXX -E" cpp /lib/cpp + if ${ac_cv_prog_CXXCPP+:} false; then : + $as_echo_n "(cached) " >&6 +else + # Double quotes because CXXCPP needs to be expanded + for CXXCPP in "$CXX -E" "/lib/cpp" do ac_preproc_ok=false for ac_cxx_preproc_warn_flag in '' yes do # Use a header file that comes with gcc, so configuring glibc # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. "Syntax error" is here to catch this case. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include +#ifdef __STDC__ +# include +#else +# include +#endif Syntax error _ACEOF -if ac_fn_cxx_try_cpp "$LINENO" -then : +if ac_fn_cxx_try_cpp "$LINENO"; then : -else $as_nop +else # Broken: fails on valid input. continue fi @@ -13136,11 +12523,10 @@ rm -f conftest.err conftest.i conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF -if ac_fn_cxx_try_cpp "$LINENO" -then : +if ac_fn_cxx_try_cpp "$LINENO"; then : # Broken: success on invalid input. continue -else $as_nop +else # Passes both tests. ac_preproc_ok=: break @@ -13150,8 +12536,7 @@ rm -f conftest.err conftest.i conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. rm -f conftest.i conftest.err conftest.$ac_ext -if $ac_preproc_ok -then : +if $ac_preproc_ok; then : break fi @@ -13163,24 +12548,29 @@ fi else ac_cv_prog_CXXCPP=$CXXCPP fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CXXCPP" >&5 -printf "%s\n" "$CXXCPP" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CXXCPP" >&5 +$as_echo "$CXXCPP" >&6; } ac_preproc_ok=false for ac_cxx_preproc_warn_flag in '' yes do # Use a header file that comes with gcc, so configuring glibc # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. "Syntax error" is here to catch this case. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include +#ifdef __STDC__ +# include +#else +# include +#endif Syntax error _ACEOF -if ac_fn_cxx_try_cpp "$LINENO" -then : +if ac_fn_cxx_try_cpp "$LINENO"; then : -else $as_nop +else # Broken: fails on valid input. continue fi @@ -13192,11 +12582,10 @@ rm -f conftest.err conftest.i conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF -if ac_fn_cxx_try_cpp "$LINENO" -then : +if ac_fn_cxx_try_cpp "$LINENO"; then : # Broken: success on invalid input. continue -else $as_nop +else # Passes both tests. ac_preproc_ok=: break @@ -13206,12 +12595,11 @@ rm -f conftest.err conftest.i conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. rm -f conftest.i conftest.err conftest.$ac_ext -if $ac_preproc_ok -then : +if $ac_preproc_ok; then : -else $as_nop - { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "C++ preprocessor \"$CXXCPP\" fails sanity check See \`config.log' for more details" "$LINENO" 5; } fi @@ -13347,18 +12735,17 @@ cc_basename=$func_cc_basename_result # Check whether --with-gnu-ld was given. -if test ${with_gnu_ld+y} -then : +if test "${with_gnu_ld+set}" = set; then : withval=$with_gnu_ld; test no = "$withval" || with_gnu_ld=yes -else $as_nop +else with_gnu_ld=no fi ac_prog=ld if test yes = "$GCC"; then # Check if gcc -print-prog-name=ld gives a path. - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 -printf %s "checking for ld used by $CC... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 +$as_echo_n "checking for ld used by $CC... " >&6; } case $host in *-*-mingw*) # gcc leaves a trailing carriage return, which upsets mingw @@ -13387,16 +12774,15 @@ printf %s "checking for ld used by $CC... " >&6; } ;; esac elif test yes = "$with_gnu_ld"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 -printf %s "checking for GNU ld... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 +$as_echo_n "checking for GNU ld... " >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 -printf %s "checking for non-GNU ld... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 +$as_echo_n "checking for non-GNU ld... " >&6; } fi -if test ${lt_cv_path_LD+y} -then : - printf %s "(cached) " >&6 -else $as_nop +if ${lt_cv_path_LD+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -z "$LD"; then lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR for ac_dir in $PATH; do @@ -13425,19 +12811,18 @@ fi LD=$lt_cv_path_LD if test -n "$LD"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $LD" >&5 -printf "%s\n" "$LD" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LD" >&5 +$as_echo "$LD" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi test -z "$LD" && as_fn_error $? "no acceptable ld found in \$PATH" "$LINENO" 5 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 -printf %s "checking if the linker ($LD) is GNU ld... " >&6; } -if test ${lt_cv_prog_gnu_ld+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 +$as_echo_n "checking if the linker ($LD) is GNU ld... " >&6; } +if ${lt_cv_prog_gnu_ld+:} false; then : + $as_echo_n "(cached) " >&6 +else # I'd rather use --version here, but apparently some GNU lds only accept -v. case `$LD -v 2>&1 &1 &5 -printf "%s\n" "$lt_cv_prog_gnu_ld" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_gnu_ld" >&5 +$as_echo "$lt_cv_prog_gnu_ld" >&6; } with_gnu_ld=$lt_cv_prog_gnu_ld @@ -13494,7 +12879,7 @@ with_gnu_ld=$lt_cv_prog_gnu_ld # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' else GXX=no @@ -13503,8 +12888,8 @@ with_gnu_ld=$lt_cv_prog_gnu_ld fi # PORTME: fill in a description of your system's C++ link characteristics - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 -printf %s "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +$as_echo_n "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } ld_shlibs_CXX=yes case $host_os in aix3*) @@ -13642,23 +13027,21 @@ printf %s "checking whether the $compiler linker ($LD) supports shared libraries if test set = "${lt_cv_aix_libpath+set}"; then aix_libpath=$lt_cv_aix_libpath else - if test ${lt_cv_aix_libpath__CXX+y} -then : - printf %s "(cached) " >&6 -else $as_nop + if ${lt_cv_aix_libpath__CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main (void) +main () { ; return 0; } _ACEOF -if ac_fn_cxx_try_link "$LINENO" -then : +if ac_fn_cxx_try_link "$LINENO"; then : lt_aix_libpath_sed=' /Import File Strings/,/^$/ { @@ -13673,7 +13056,7 @@ then : lt_cv_aix_libpath__CXX=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` fi fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext if test -z "$lt_cv_aix_libpath__CXX"; then lt_cv_aix_libpath__CXX=/usr/lib:/lib @@ -13698,23 +13081,21 @@ fi if test set = "${lt_cv_aix_libpath+set}"; then aix_libpath=$lt_cv_aix_libpath else - if test ${lt_cv_aix_libpath__CXX+y} -then : - printf %s "(cached) " >&6 -else $as_nop + if ${lt_cv_aix_libpath__CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main (void) +main () { ; return 0; } _ACEOF -if ac_fn_cxx_try_link "$LINENO" -then : +if ac_fn_cxx_try_link "$LINENO"; then : lt_aix_libpath_sed=' /Import File Strings/,/^$/ { @@ -13729,7 +13110,7 @@ then : lt_cv_aix_libpath__CXX=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` fi fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext if test -z "$lt_cv_aix_libpath__CXX"; then lt_cv_aix_libpath__CXX=/usr/lib:/lib @@ -13990,7 +13371,7 @@ fi # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. - output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP " \-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' ;; *) if test yes = "$GXX"; then @@ -14055,7 +13436,7 @@ fi # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. - output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP " \-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' ;; *) if test yes = "$GXX"; then @@ -14394,7 +13775,7 @@ fi # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' else # FIXME: insert proper C++ library support @@ -14478,7 +13859,7 @@ fi # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' else # g++ 2.7 appears to require '-G' NOT '-shared' on this # platform. @@ -14489,7 +13870,7 @@ fi # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' + output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' fi hardcode_libdir_flag_spec_CXX='$wl-R $wl$libdir' @@ -14580,8 +13961,8 @@ fi ;; esac - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs_CXX" >&5 -printf "%s\n" "$ld_shlibs_CXX" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs_CXX" >&5 +$as_echo "$ld_shlibs_CXX" >&6; } test no = "$ld_shlibs_CXX" && can_build_shared=no GCC_CXX=$GXX @@ -14619,7 +14000,7 @@ esac if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then # Parse the compiler output and extract the necessary # objects, libraries and library flags. @@ -15002,7 +14383,7 @@ lt_prog_compiler_static_CXX= ;; esac ;; - netbsd* | netbsdelf*-gnu) + netbsd*) ;; *qnx* | *nto*) # QNX uses GNU C++, but need to define -shared option too, otherwise @@ -15100,28 +14481,26 @@ case $host_os in ;; esac -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5 -printf %s "checking for $compiler option to produce PIC... " >&6; } -if test ${lt_cv_prog_compiler_pic_CXX+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5 +$as_echo_n "checking for $compiler option to produce PIC... " >&6; } +if ${lt_cv_prog_compiler_pic_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_prog_compiler_pic_CXX=$lt_prog_compiler_pic_CXX fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_CXX" >&5 -printf "%s\n" "$lt_cv_prog_compiler_pic_CXX" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_CXX" >&5 +$as_echo "$lt_cv_prog_compiler_pic_CXX" >&6; } lt_prog_compiler_pic_CXX=$lt_cv_prog_compiler_pic_CXX # # Check to make sure the PIC flag actually works. # if test -n "$lt_prog_compiler_pic_CXX"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic_CXX works" >&5 -printf %s "checking if $compiler PIC flag $lt_prog_compiler_pic_CXX works... " >&6; } -if test ${lt_cv_prog_compiler_pic_works_CXX+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic_CXX works" >&5 +$as_echo_n "checking if $compiler PIC flag $lt_prog_compiler_pic_CXX works... " >&6; } +if ${lt_cv_prog_compiler_pic_works_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_prog_compiler_pic_works_CXX=no ac_outfile=conftest.$ac_objext echo "$lt_simple_compile_test_code" > conftest.$ac_ext @@ -15152,8 +14531,8 @@ else $as_nop $RM conftest* fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works_CXX" >&5 -printf "%s\n" "$lt_cv_prog_compiler_pic_works_CXX" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works_CXX" >&5 +$as_echo "$lt_cv_prog_compiler_pic_works_CXX" >&6; } if test yes = "$lt_cv_prog_compiler_pic_works_CXX"; then case $lt_prog_compiler_pic_CXX in @@ -15175,12 +14554,11 @@ fi # Check to make sure the static flag actually works. # wl=$lt_prog_compiler_wl_CXX eval lt_tmp_static_flag=\"$lt_prog_compiler_static_CXX\" -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5 -printf %s "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; } -if test ${lt_cv_prog_compiler_static_works_CXX+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5 +$as_echo_n "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; } +if ${lt_cv_prog_compiler_static_works_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_prog_compiler_static_works_CXX=no save_LDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS $lt_tmp_static_flag" @@ -15204,8 +14582,8 @@ else $as_nop LDFLAGS=$save_LDFLAGS fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works_CXX" >&5 -printf "%s\n" "$lt_cv_prog_compiler_static_works_CXX" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works_CXX" >&5 +$as_echo "$lt_cv_prog_compiler_static_works_CXX" >&6; } if test yes = "$lt_cv_prog_compiler_static_works_CXX"; then : @@ -15216,12 +14594,11 @@ fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 -printf %s "checking if $compiler supports -c -o file.$ac_objext... " >&6; } -if test ${lt_cv_prog_compiler_c_o_CXX+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if ${lt_cv_prog_compiler_c_o_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_prog_compiler_c_o_CXX=no $RM -r conftest 2>/dev/null mkdir conftest @@ -15264,17 +14641,16 @@ else $as_nop $RM conftest* fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o_CXX" >&5 -printf "%s\n" "$lt_cv_prog_compiler_c_o_CXX" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o_CXX" >&5 +$as_echo "$lt_cv_prog_compiler_c_o_CXX" >&6; } - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 -printf %s "checking if $compiler supports -c -o file.$ac_objext... " >&6; } -if test ${lt_cv_prog_compiler_c_o_CXX+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if ${lt_cv_prog_compiler_c_o_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_prog_compiler_c_o_CXX=no $RM -r conftest 2>/dev/null mkdir conftest @@ -15317,8 +14693,8 @@ else $as_nop $RM conftest* fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o_CXX" >&5 -printf "%s\n" "$lt_cv_prog_compiler_c_o_CXX" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o_CXX" >&5 +$as_echo "$lt_cv_prog_compiler_c_o_CXX" >&6; } @@ -15326,19 +14702,19 @@ printf "%s\n" "$lt_cv_prog_compiler_c_o_CXX" >&6; } hard_links=nottested if test no = "$lt_cv_prog_compiler_c_o_CXX" && test no != "$need_locks"; then # do not overwrite the value of need_locks provided by the user - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5 -printf %s "checking if we can lock with hard links... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5 +$as_echo_n "checking if we can lock with hard links... " >&6; } hard_links=yes $RM conftest* ln conftest.a conftest.b 2>/dev/null && hard_links=no touch conftest.a ln conftest.a conftest.b 2>&5 || hard_links=no ln conftest.a conftest.b 2>/dev/null && hard_links=no - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5 -printf "%s\n" "$hard_links" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5 +$as_echo "$hard_links" >&6; } if test no = "$hard_links"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&5 -printf "%s\n" "$as_me: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&5 +$as_echo "$as_me: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&2;} need_locks=warn fi else @@ -15347,8 +14723,8 @@ fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 -printf %s "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +$as_echo_n "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } export_symbols_cmds_CXX='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' exclude_expsyms_CXX='_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*' @@ -15382,16 +14758,13 @@ printf %s "checking whether the $compiler linker ($LD) supports shared libraries ;; esac ;; - linux* | k*bsd*-gnu | gnu*) - link_all_deplibs_CXX=no - ;; *) export_symbols_cmds_CXX='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' ;; esac -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs_CXX" >&5 -printf "%s\n" "$ld_shlibs_CXX" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs_CXX" >&5 +$as_echo "$ld_shlibs_CXX" >&6; } test no = "$ld_shlibs_CXX" && can_build_shared=no with_gnu_ld_CXX=$with_gnu_ld @@ -15418,19 +14791,18 @@ x|xyes) # Test whether the compiler implicitly links with -lc since on some # systems, -lgcc has to come before -lc. If gcc already passes -lc # to ld, don't add -lc before -lgcc. - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5 -printf %s "checking whether -lc should be explicitly linked in... " >&6; } -if test ${lt_cv_archive_cmds_need_lc_CXX+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5 +$as_echo_n "checking whether -lc should be explicitly linked in... " >&6; } +if ${lt_cv_archive_cmds_need_lc_CXX+:} false; then : + $as_echo_n "(cached) " >&6 +else $RM conftest* echo "$lt_simple_compile_test_code" > conftest.$ac_ext if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } 2>conftest.err; then soname=conftest lib=conftest @@ -15448,7 +14820,7 @@ else $as_nop if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$archive_cmds_CXX 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1\""; } >&5 (eval $archive_cmds_CXX 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) 2>&5 ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } then lt_cv_archive_cmds_need_lc_CXX=no @@ -15462,8 +14834,8 @@ else $as_nop $RM conftest* fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_archive_cmds_need_lc_CXX" >&5 -printf "%s\n" "$lt_cv_archive_cmds_need_lc_CXX" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_archive_cmds_need_lc_CXX" >&5 +$as_echo "$lt_cv_archive_cmds_need_lc_CXX" >&6; } archive_cmds_need_lc_CXX=$lt_cv_archive_cmds_need_lc_CXX ;; esac @@ -15532,8 +14904,8 @@ esac - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5 -printf %s "checking dynamic linker characteristics... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5 +$as_echo_n "checking dynamic linker characteristics... " >&6; } library_names_spec= libname_spec='lib$name' @@ -16021,10 +15393,9 @@ linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) shlibpath_overrides_runpath=no # Some binutils ld are patched to set DT_RUNPATH - if test ${lt_cv_shlibpath_overrides_runpath+y} -then : - printf %s "(cached) " >&6 -else $as_nop + if ${lt_cv_shlibpath_overrides_runpath+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_shlibpath_overrides_runpath=no save_LDFLAGS=$LDFLAGS save_libdir=$libdir @@ -16034,21 +15405,19 @@ else $as_nop /* end confdefs.h. */ int -main (void) +main () { ; return 0; } _ACEOF -if ac_fn_cxx_try_link "$LINENO" -then : - if ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null -then : +if ac_fn_cxx_try_link "$LINENO"; then : + if ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null; then : lt_cv_shlibpath_overrides_runpath=yes fi fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LDFLAGS=$save_LDFLAGS libdir=$save_libdir @@ -16062,6 +15431,9 @@ fi # before this can be enabled. hardcode_into_libs=yes + # Add ABI-specific directories to the system library path. + sys_lib_dlsearch_path_spec="/lib64 /usr/lib64 /lib /usr/lib" + # Ideally, we could use ldconfig to report *all* directores which are # searched for libraries, however this is still not possible. Aside from not # being certain /sbin/ldconfig is available, command @@ -16070,7 +15442,7 @@ fi # appending ld.so.conf contents (and includes) to the search path. if test -f /etc/ld.so.conf; then lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` - sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" + sys_lib_dlsearch_path_spec="$sys_lib_dlsearch_path_spec $lt_ld_extra" fi # We used to test for /lib/ld.so.1 and disable shared libraries on @@ -16082,18 +15454,6 @@ fi dynamic_linker='GNU/Linux ld.so' ;; -netbsdelf*-gnu) - version_type=linux - need_lib_prefix=no - need_version=no - library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' - soname_spec='${libname}${release}${shared_ext}$major' - shlibpath_var=LD_LIBRARY_PATH - shlibpath_overrides_runpath=no - hardcode_into_libs=yes - dynamic_linker='NetBSD ld.elf_so' - ;; - netbsd*) version_type=sunos need_lib_prefix=no @@ -16292,8 +15652,8 @@ uts4*) dynamic_linker=no ;; esac -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5 -printf "%s\n" "$dynamic_linker" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5 +$as_echo "$dynamic_linker" >&6; } test no = "$dynamic_linker" && can_build_shared=no variables_saved_for_relink="PATH $shlibpath_var $runpath_var" @@ -16357,8 +15717,8 @@ configure_time_lt_sys_library_path=$LT_SYS_LIBRARY_PATH - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5 -printf %s "checking how to hardcode library paths into programs... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5 +$as_echo_n "checking how to hardcode library paths into programs... " >&6; } hardcode_action_CXX= if test -n "$hardcode_libdir_flag_spec_CXX" || test -n "$runpath_var_CXX" || @@ -16382,8 +15742,8 @@ else # directories. hardcode_action_CXX=unsupported fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $hardcode_action_CXX" >&5 -printf "%s\n" "$hardcode_action_CXX" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $hardcode_action_CXX" >&5 +$as_echo "$hardcode_action_CXX" >&6; } if test relink = "$hardcode_action_CXX" || test yes = "$inherit_rpath_CXX"; then @@ -16523,13 +15883,13 @@ cc_basename=$func_cc_basename_result GCC=$G77 if test -n "$compiler"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if libtool supports shared libraries" >&5 -printf %s "checking if libtool supports shared libraries... " >&6; } - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $can_build_shared" >&5 -printf "%s\n" "$can_build_shared" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if libtool supports shared libraries" >&5 +$as_echo_n "checking if libtool supports shared libraries... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $can_build_shared" >&5 +$as_echo "$can_build_shared" >&6; } - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to build shared libraries" >&5 -printf %s "checking whether to build shared libraries... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build shared libraries" >&5 +$as_echo_n "checking whether to build shared libraries... " >&6; } test no = "$can_build_shared" && enable_shared=no # On AIX, shared libraries and static libraries use the same namespace, and @@ -16552,15 +15912,15 @@ printf %s "checking whether to build shared libraries... " >&6; } fi ;; esac - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $enable_shared" >&5 -printf "%s\n" "$enable_shared" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_shared" >&5 +$as_echo "$enable_shared" >&6; } - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to build static libraries" >&5 -printf %s "checking whether to build static libraries... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build static libraries" >&5 +$as_echo_n "checking whether to build static libraries... " >&6; } # Make sure either enable_shared or enable_static is yes. test yes = "$enable_shared" || enable_static=yes - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $enable_static" >&5 -printf "%s\n" "$enable_static" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_static" >&5 +$as_echo "$enable_static" >&6; } GCC_F77=$G77 LD_F77=$LD @@ -16751,12 +16111,6 @@ lt_prog_compiler_static_F77= lt_prog_compiler_pic_F77='-KPIC' lt_prog_compiler_static_F77='-static' ;; - # flang / f18. f95 an alias for gfortran or flang on Debian - flang* | f18* | f95*) - lt_prog_compiler_wl_F77='-Wl,' - lt_prog_compiler_pic_F77='-fPIC' - lt_prog_compiler_static_F77='-static' - ;; # icc used to be incompatible with GCC. # ICC 10 doesn't accept -KPIC any more. icc* | ifort*) @@ -16917,28 +16271,26 @@ case $host_os in ;; esac -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5 -printf %s "checking for $compiler option to produce PIC... " >&6; } -if test ${lt_cv_prog_compiler_pic_F77+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5 +$as_echo_n "checking for $compiler option to produce PIC... " >&6; } +if ${lt_cv_prog_compiler_pic_F77+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_prog_compiler_pic_F77=$lt_prog_compiler_pic_F77 fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_F77" >&5 -printf "%s\n" "$lt_cv_prog_compiler_pic_F77" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_F77" >&5 +$as_echo "$lt_cv_prog_compiler_pic_F77" >&6; } lt_prog_compiler_pic_F77=$lt_cv_prog_compiler_pic_F77 # # Check to make sure the PIC flag actually works. # if test -n "$lt_prog_compiler_pic_F77"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic_F77 works" >&5 -printf %s "checking if $compiler PIC flag $lt_prog_compiler_pic_F77 works... " >&6; } -if test ${lt_cv_prog_compiler_pic_works_F77+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic_F77 works" >&5 +$as_echo_n "checking if $compiler PIC flag $lt_prog_compiler_pic_F77 works... " >&6; } +if ${lt_cv_prog_compiler_pic_works_F77+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_prog_compiler_pic_works_F77=no ac_outfile=conftest.$ac_objext echo "$lt_simple_compile_test_code" > conftest.$ac_ext @@ -16969,8 +16321,8 @@ else $as_nop $RM conftest* fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works_F77" >&5 -printf "%s\n" "$lt_cv_prog_compiler_pic_works_F77" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works_F77" >&5 +$as_echo "$lt_cv_prog_compiler_pic_works_F77" >&6; } if test yes = "$lt_cv_prog_compiler_pic_works_F77"; then case $lt_prog_compiler_pic_F77 in @@ -16992,12 +16344,11 @@ fi # Check to make sure the static flag actually works. # wl=$lt_prog_compiler_wl_F77 eval lt_tmp_static_flag=\"$lt_prog_compiler_static_F77\" -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5 -printf %s "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; } -if test ${lt_cv_prog_compiler_static_works_F77+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5 +$as_echo_n "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; } +if ${lt_cv_prog_compiler_static_works_F77+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_prog_compiler_static_works_F77=no save_LDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS $lt_tmp_static_flag" @@ -17021,8 +16372,8 @@ else $as_nop LDFLAGS=$save_LDFLAGS fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works_F77" >&5 -printf "%s\n" "$lt_cv_prog_compiler_static_works_F77" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works_F77" >&5 +$as_echo "$lt_cv_prog_compiler_static_works_F77" >&6; } if test yes = "$lt_cv_prog_compiler_static_works_F77"; then : @@ -17033,12 +16384,11 @@ fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 -printf %s "checking if $compiler supports -c -o file.$ac_objext... " >&6; } -if test ${lt_cv_prog_compiler_c_o_F77+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if ${lt_cv_prog_compiler_c_o_F77+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_prog_compiler_c_o_F77=no $RM -r conftest 2>/dev/null mkdir conftest @@ -17081,17 +16431,16 @@ else $as_nop $RM conftest* fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o_F77" >&5 -printf "%s\n" "$lt_cv_prog_compiler_c_o_F77" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o_F77" >&5 +$as_echo "$lt_cv_prog_compiler_c_o_F77" >&6; } - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 -printf %s "checking if $compiler supports -c -o file.$ac_objext... " >&6; } -if test ${lt_cv_prog_compiler_c_o_F77+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if ${lt_cv_prog_compiler_c_o_F77+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_prog_compiler_c_o_F77=no $RM -r conftest 2>/dev/null mkdir conftest @@ -17134,8 +16483,8 @@ else $as_nop $RM conftest* fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o_F77" >&5 -printf "%s\n" "$lt_cv_prog_compiler_c_o_F77" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o_F77" >&5 +$as_echo "$lt_cv_prog_compiler_c_o_F77" >&6; } @@ -17143,19 +16492,19 @@ printf "%s\n" "$lt_cv_prog_compiler_c_o_F77" >&6; } hard_links=nottested if test no = "$lt_cv_prog_compiler_c_o_F77" && test no != "$need_locks"; then # do not overwrite the value of need_locks provided by the user - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5 -printf %s "checking if we can lock with hard links... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5 +$as_echo_n "checking if we can lock with hard links... " >&6; } hard_links=yes $RM conftest* ln conftest.a conftest.b 2>/dev/null && hard_links=no touch conftest.a ln conftest.a conftest.b 2>&5 || hard_links=no ln conftest.a conftest.b 2>/dev/null && hard_links=no - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5 -printf "%s\n" "$hard_links" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5 +$as_echo "$hard_links" >&6; } if test no = "$hard_links"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&5 -printf "%s\n" "$as_me: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&5 +$as_echo "$as_me: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&2;} need_locks=warn fi else @@ -17164,8 +16513,8 @@ fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 -printf %s "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +$as_echo_n "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } runpath_var= allow_undefined_flag_F77= @@ -17223,9 +16572,6 @@ printf %s "checking whether the $compiler linker ($LD) supports shared libraries openbsd* | bitrig*) with_gnu_ld=no ;; - linux* | k*bsd*-gnu | gnu*) - link_all_deplibs_F77=no - ;; esac ld_shlibs_F77=yes @@ -17480,7 +16826,7 @@ _LT_EOF fi ;; - netbsd* | netbsdelf*-gnu) + netbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then archive_cmds_F77='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' wlarc= @@ -17723,17 +17069,15 @@ _LT_EOF if test set = "${lt_cv_aix_libpath+set}"; then aix_libpath=$lt_cv_aix_libpath else - if test ${lt_cv_aix_libpath__F77+y} -then : - printf %s "(cached) " >&6 -else $as_nop + if ${lt_cv_aix_libpath__F77+:} false; then : + $as_echo_n "(cached) " >&6 +else cat > conftest.$ac_ext <<_ACEOF program main end _ACEOF -if ac_fn_f77_try_link "$LINENO" -then : +if ac_fn_f77_try_link "$LINENO"; then : lt_aix_libpath_sed=' /Import File Strings/,/^$/ { @@ -17748,7 +17092,7 @@ then : lt_cv_aix_libpath__F77=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` fi fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext if test -z "$lt_cv_aix_libpath__F77"; then lt_cv_aix_libpath__F77=/usr/lib:/lib @@ -17772,17 +17116,15 @@ fi if test set = "${lt_cv_aix_libpath+set}"; then aix_libpath=$lt_cv_aix_libpath else - if test ${lt_cv_aix_libpath__F77+y} -then : - printf %s "(cached) " >&6 -else $as_nop + if ${lt_cv_aix_libpath__F77+:} false; then : + $as_echo_n "(cached) " >&6 +else cat > conftest.$ac_ext <<_ACEOF program main end _ACEOF -if ac_fn_f77_try_link "$LINENO" -then : +if ac_fn_f77_try_link "$LINENO"; then : lt_aix_libpath_sed=' /Import File Strings/,/^$/ { @@ -17797,7 +17139,7 @@ then : lt_cv_aix_libpath__F77=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` fi fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext if test -z "$lt_cv_aix_libpath__F77"; then lt_cv_aix_libpath__F77=/usr/lib:/lib @@ -18078,12 +17420,11 @@ fi # work, assume that -exports_file does not work either and # implicitly export all symbols. # This should be the same for all languages, so no per-tag cache variable. - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the $host_os linker accepts -exported_symbol" >&5 -printf %s "checking whether the $host_os linker accepts -exported_symbol... " >&6; } -if test ${lt_cv_irix_exported_symbol+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $host_os linker accepts -exported_symbol" >&5 +$as_echo_n "checking whether the $host_os linker accepts -exported_symbol... " >&6; } +if ${lt_cv_irix_exported_symbol+:} false; then : + $as_echo_n "(cached) " >&6 +else save_LDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS -shared $wl-exported_symbol ${wl}foo $wl-update_registry $wl/dev/null" cat > conftest.$ac_ext <<_ACEOF @@ -18091,22 +17432,20 @@ else $as_nop subroutine foo end _ACEOF -if ac_fn_f77_try_link "$LINENO" -then : +if ac_fn_f77_try_link "$LINENO"; then : lt_cv_irix_exported_symbol=yes -else $as_nop +else lt_cv_irix_exported_symbol=no fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LDFLAGS=$save_LDFLAGS fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_irix_exported_symbol" >&5 -printf "%s\n" "$lt_cv_irix_exported_symbol" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_irix_exported_symbol" >&5 +$as_echo "$lt_cv_irix_exported_symbol" >&6; } if test yes = "$lt_cv_irix_exported_symbol"; then archive_expsym_cmds_F77='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations $wl-exports_file $wl$export_symbols -o $lib' fi - link_all_deplibs_F77=no else archive_cmds_F77='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' archive_expsym_cmds_F77='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -exports_file $export_symbols -o $lib' @@ -18128,7 +17467,7 @@ printf "%s\n" "$lt_cv_irix_exported_symbol" >&6; } esac ;; - netbsd* | netbsdelf*-gnu) + netbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then archive_cmds_F77='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out else @@ -18383,8 +17722,8 @@ printf "%s\n" "$lt_cv_irix_exported_symbol" >&6; } fi fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs_F77" >&5 -printf "%s\n" "$ld_shlibs_F77" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs_F77" >&5 +$as_echo "$ld_shlibs_F77" >&6; } test no = "$ld_shlibs_F77" && can_build_shared=no with_gnu_ld_F77=$with_gnu_ld @@ -18411,19 +17750,18 @@ x|xyes) # Test whether the compiler implicitly links with -lc since on some # systems, -lgcc has to come before -lc. If gcc already passes -lc # to ld, don't add -lc before -lgcc. - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5 -printf %s "checking whether -lc should be explicitly linked in... " >&6; } -if test ${lt_cv_archive_cmds_need_lc_F77+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5 +$as_echo_n "checking whether -lc should be explicitly linked in... " >&6; } +if ${lt_cv_archive_cmds_need_lc_F77+:} false; then : + $as_echo_n "(cached) " >&6 +else $RM conftest* echo "$lt_simple_compile_test_code" > conftest.$ac_ext if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } 2>conftest.err; then soname=conftest lib=conftest @@ -18441,7 +17779,7 @@ else $as_nop if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$archive_cmds_F77 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1\""; } >&5 (eval $archive_cmds_F77 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) 2>&5 ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } then lt_cv_archive_cmds_need_lc_F77=no @@ -18455,8 +17793,8 @@ else $as_nop $RM conftest* fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_archive_cmds_need_lc_F77" >&5 -printf "%s\n" "$lt_cv_archive_cmds_need_lc_F77" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_archive_cmds_need_lc_F77" >&5 +$as_echo "$lt_cv_archive_cmds_need_lc_F77" >&6; } archive_cmds_need_lc_F77=$lt_cv_archive_cmds_need_lc_F77 ;; esac @@ -18525,8 +17863,8 @@ esac - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5 -printf %s "checking dynamic linker characteristics... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5 +$as_echo_n "checking dynamic linker characteristics... " >&6; } library_names_spec= libname_spec='lib$name' @@ -19014,10 +18352,9 @@ linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) shlibpath_overrides_runpath=no # Some binutils ld are patched to set DT_RUNPATH - if test ${lt_cv_shlibpath_overrides_runpath+y} -then : - printf %s "(cached) " >&6 -else $as_nop + if ${lt_cv_shlibpath_overrides_runpath+:} false; then : + $as_echo_n "(cached) " >&6 +else lt_cv_shlibpath_overrides_runpath=no save_LDFLAGS=$LDFLAGS save_libdir=$libdir @@ -19028,14 +18365,12 @@ else $as_nop end _ACEOF -if ac_fn_f77_try_link "$LINENO" -then : - if ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null -then : +if ac_fn_f77_try_link "$LINENO"; then : + if ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null; then : lt_cv_shlibpath_overrides_runpath=yes fi fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LDFLAGS=$save_LDFLAGS libdir=$save_libdir @@ -19049,6 +18384,9 @@ fi # before this can be enabled. hardcode_into_libs=yes + # Add ABI-specific directories to the system library path. + sys_lib_dlsearch_path_spec="/lib64 /usr/lib64 /lib /usr/lib" + # Ideally, we could use ldconfig to report *all* directores which are # searched for libraries, however this is still not possible. Aside from not # being certain /sbin/ldconfig is available, command @@ -19057,7 +18395,7 @@ fi # appending ld.so.conf contents (and includes) to the search path. if test -f /etc/ld.so.conf; then lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` - sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" + sys_lib_dlsearch_path_spec="$sys_lib_dlsearch_path_spec $lt_ld_extra" fi # We used to test for /lib/ld.so.1 and disable shared libraries on @@ -19069,18 +18407,6 @@ fi dynamic_linker='GNU/Linux ld.so' ;; -netbsdelf*-gnu) - version_type=linux - need_lib_prefix=no - need_version=no - library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' - soname_spec='${libname}${release}${shared_ext}$major' - shlibpath_var=LD_LIBRARY_PATH - shlibpath_overrides_runpath=no - hardcode_into_libs=yes - dynamic_linker='NetBSD ld.elf_so' - ;; - netbsd*) version_type=sunos need_lib_prefix=no @@ -19279,8 +18605,8 @@ uts4*) dynamic_linker=no ;; esac -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5 -printf "%s\n" "$dynamic_linker" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5 +$as_echo "$dynamic_linker" >&6; } test no = "$dynamic_linker" && can_build_shared=no variables_saved_for_relink="PATH $shlibpath_var $runpath_var" @@ -19344,8 +18670,8 @@ configure_time_lt_sys_library_path=$LT_SYS_LIBRARY_PATH - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5 -printf %s "checking how to hardcode library paths into programs... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5 +$as_echo_n "checking how to hardcode library paths into programs... " >&6; } hardcode_action_F77= if test -n "$hardcode_libdir_flag_spec_F77" || test -n "$runpath_var_F77" || @@ -19369,8 +18695,8 @@ else # directories. hardcode_action_F77=unsupported fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $hardcode_action_F77" >&5 -printf "%s\n" "$hardcode_action_F77" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $hardcode_action_F77" >&5 +$as_echo "$hardcode_action_F77" >&6; } if test relink = "$hardcode_action_F77" || test yes = "$inherit_rpath_F77"; then @@ -19421,14 +18747,13 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu # Only expand once: -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 -printf %s "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 +$as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; } set x ${MAKE-make} -ac_make=`printf "%s\n" "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` -if eval test \${ac_cv_prog_make_${ac_make}_set+y} -then : - printf %s "(cached) " >&6 -else $as_nop +ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` +if eval \${ac_cv_prog_make_${ac_make}_set+:} false; then : + $as_echo_n "(cached) " >&6 +else cat >conftest.make <<\_ACEOF SHELL = /bin/sh all: @@ -19441,171 +18766,158 @@ case `${MAKE-make} -f conftest.make 2>/dev/null` in *) eval ac_cv_prog_make_${ac_make}_set=no;; esac -rm -f conftest.make -fi -if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -printf "%s\n" "yes" >&6; } - SET_MAKE= -else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } - SET_MAKE="MAKE=${MAKE-make}" -fi - - -# 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 +rm -f conftest.make fi - - fi +if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + SET_MAKE= +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + SET_MAKE="MAKE=${MAKE-make}" 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" +# Checks for header files. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 +$as_echo_n "checking for ANSI C header files... " >&6; } +if ${ac_cv_header_stdc+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include +#include -ac_fn_c_check_header_compile "$LINENO" "stdint.h" "ac_cv_header_stdint_h" "$ac_includes_default" -if test "x$ac_cv_header_stdint_h" = xyes -then : - printf "%s\n" "#define HAVE_STDINT_H 1" >>confdefs.h +int +main () +{ + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_header_stdc=yes +else + ac_cv_header_stdc=no fi -ac_fn_c_check_header_compile "$LINENO" "sys/types.h" "ac_cv_header_sys_types_h" "$ac_includes_default" -if test "x$ac_cv_header_sys_types_h" = xyes -then : - printf "%s\n" "#define HAVE_SYS_TYPES_H 1" >>confdefs.h +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -ac_fn_c_check_header_compile "$LINENO" "signal.h" "ac_cv_header_signal_h" "$ac_includes_default" -if test "x$ac_cv_header_signal_h" = xyes -then : - printf "%s\n" "#define HAVE_SIGNAL_H 1" >>confdefs.h +if test $ac_cv_header_stdc = yes; then + # SunOS 4.x string.h does not declare mem*, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "memchr" >/dev/null 2>&1; then : +else + ac_cv_header_stdc=no fi -ac_fn_c_check_header_compile "$LINENO" "fcntl.h" "ac_cv_header_fcntl_h" "$ac_includes_default" -if test "x$ac_cv_header_fcntl_h" = xyes -then : - printf "%s\n" "#define HAVE_FCNTL_H 1" >>confdefs.h +rm -f conftest* fi -ac_fn_c_check_header_compile "$LINENO" "malloc.h" "ac_cv_header_malloc_h" "$ac_includes_default" -if test "x$ac_cv_header_malloc_h" = xyes -then : - printf "%s\n" "#define HAVE_MALLOC_H 1" >>confdefs.h +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "free" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no fi -ac_fn_c_check_header_compile "$LINENO" "locale.h" "ac_cv_header_locale_h" "$ac_includes_default" -if test "x$ac_cv_header_locale_h" = xyes -then : - printf "%s\n" "#define HAVE_LOCALE_H 1" >>confdefs.h +rm -f conftest* fi -ac_fn_c_check_header_compile "$LINENO" "stddef.h" "ac_cv_header_stddef_h" "$ac_includes_default" -if test "x$ac_cv_header_stddef_h" = xyes -then : - printf "%s\n" "#define HAVE_STDDEF_H 1" >>confdefs.h +if test $ac_cv_header_stdc = yes; then + # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. + if test "$cross_compiling" = yes; then : + : +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#if ((' ' & 0x0FF) == 0x020) +# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) +#else +# define ISLOWER(c) \ + (('a' <= (c) && (c) <= 'i') \ + || ('j' <= (c) && (c) <= 'r') \ + || ('s' <= (c) && (c) <= 'z')) +# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) +#endif + +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) +int +main () +{ + int i; + for (i = 0; i < 256; i++) + if (XOR (islower (i), ISLOWER (i)) + || toupper (i) != TOUPPER (i)) + return 2; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + +else + ac_cv_header_stdc=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext fi -ac_fn_c_check_header_compile "$LINENO" "wchar.h" "ac_cv_header_wchar_h" "$ac_includes_default" -if test "x$ac_cv_header_wchar_h" = xyes -then : - printf "%s\n" "#define HAVE_WCHAR_H 1" >>confdefs.h fi -ac_fn_c_check_header_compile "$LINENO" "dlfcn.h" "ac_cv_header_dlfcn_h" "$ac_includes_default" -if test "x$ac_cv_header_dlfcn_h" = xyes -then : - printf "%s\n" "#define HAVE_DLFCN_H 1" >>confdefs.h +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 +$as_echo "$ac_cv_header_stdc" >&6; } +if test $ac_cv_header_stdc = yes; then + +$as_echo "#define STDC_HEADERS 1" >>confdefs.h fi -ac_fn_c_check_header_compile "$LINENO" "sys/time.h" "ac_cv_header_sys_time_h" "$ac_includes_default" -if test "x$ac_cv_header_sys_time_h" = xyes -then : - printf "%s\n" "#define HAVE_SYS_TIME_H 1" >>confdefs.h + +for ac_header in stdint.h sys/types.h signal.h fcntl.h malloc.h locale.h \ + stddef.h wchar.h dlfcn.h sys/time.h +do : + as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` +ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" +if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF fi +done + # Checks for typedefs, structures, and compiler characteristics. -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for an ANSI C-conforming const" >&5 -printf %s "checking for an ANSI C-conforming const... " >&6; } -if test ${ac_cv_c_const+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for an ANSI C-conforming const" >&5 +$as_echo_n "checking for an ANSI C-conforming const... " >&6; } +if ${ac_cv_c_const+:} false; then : + $as_echo_n "(cached) " >&6 +else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main (void) +main () { #ifndef __cplusplus @@ -19618,7 +18930,7 @@ main (void) /* NEC SVR4.0.2 mips cc rejects this. */ struct point {int x, y;}; static struct point const zero = {0,0}; - /* IBM XL C 1.02.0.0 rejects this. + /* AIX XL C 1.02.0.0 rejects this. It does not let you subtract one const X* pointer from another in an arm of an if-expression whose if-part is not a constant expression */ @@ -19646,7 +18958,7 @@ main (void) iptr p = 0; ++p; } - { /* IBM XL C 1.02.0.0 rejects this sort of thing, saying + { /* AIX XL C 1.02.0.0 rejects this sort of thing, saying "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */ struct s { int j; const int *ap[3]; } bx; struct s *b = &bx; b->j = 5; @@ -19662,28 +18974,26 @@ main (void) return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : ac_cv_c_const=yes -else $as_nop +else ac_cv_c_const=no fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_const" >&5 -printf "%s\n" "$ac_cv_c_const" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_const" >&5 +$as_echo "$ac_cv_c_const" >&6; } if test $ac_cv_c_const = no; then -printf "%s\n" "#define const /**/" >>confdefs.h +$as_echo "#define const /**/" >>confdefs.h fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether byte ordering is bigendian" >&5 -printf %s "checking whether byte ordering is bigendian... " >&6; } -if test ${ac_cv_c_bigendian+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether byte ordering is bigendian" >&5 +$as_echo_n "checking whether byte ordering is bigendian... " >&6; } +if ${ac_cv_c_bigendian+:} false; then : + $as_echo_n "(cached) " >&6 +else ac_cv_c_bigendian=unknown # See if we're dealing with a universal compiler. cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -19694,8 +19004,7 @@ else $as_nop typedef int dummy; _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : # Check for potential -arch flags. It is not universal unless # there are at least two -arch flags with different values. @@ -19719,7 +19028,7 @@ then : fi done fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext if test $ac_cv_c_bigendian = unknown; then # See if sys/param.h defines the BYTE_ORDER macro. cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -19728,7 +19037,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext #include int -main (void) +main () { #if ! (defined BYTE_ORDER && defined BIG_ENDIAN \ && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \ @@ -19740,8 +19049,7 @@ main (void) return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : # It does; now see whether it defined to BIG_ENDIAN or not. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -19749,7 +19057,7 @@ then : #include int -main (void) +main () { #if BYTE_ORDER != BIG_ENDIAN not big endian @@ -19759,15 +19067,14 @@ main (void) return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : ac_cv_c_bigendian=yes -else $as_nop +else ac_cv_c_bigendian=no fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi if test $ac_cv_c_bigendian = unknown; then # See if defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris). @@ -19776,7 +19083,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext #include int -main (void) +main () { #if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN) bogus endian macros @@ -19786,15 +19093,14 @@ main (void) return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : # It does; now see whether it defined to _BIG_ENDIAN or not. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int -main (void) +main () { #ifndef _BIG_ENDIAN not big endian @@ -19804,33 +19110,31 @@ main (void) return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : ac_cv_c_bigendian=yes -else $as_nop +else ac_cv_c_bigendian=no fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi if test $ac_cv_c_bigendian = unknown; then # Compile a test program. - if test "$cross_compiling" = yes -then : + if test "$cross_compiling" = yes; then : # Try to guess by grepping values from an object file. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -unsigned short int ascii_mm[] = +short int ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 }; - unsigned short int ascii_ii[] = + short int ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 }; int use_ascii (int i) { return ascii_mm[i] + ascii_ii[i]; } - unsigned short int ebcdic_ii[] = + short int ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 }; - unsigned short int ebcdic_mm[] = + short int ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 }; int use_ebcdic (int i) { return ebcdic_mm[i] + ebcdic_ii[i]; @@ -19838,15 +19142,14 @@ unsigned short int ascii_mm[] = extern int foo; int -main (void) +main () { return use_ascii (foo) == use_ebcdic (foo); ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : if grep BIGenDianSyS conftest.$ac_objext >/dev/null; then ac_cv_c_bigendian=yes fi @@ -19859,13 +19162,13 @@ then : fi fi fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext -else $as_nop +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default int -main (void) +main () { /* Are we little or big endian? From Harbison&Steele. */ @@ -19881,10 +19184,9 @@ main (void) return 0; } _ACEOF -if ac_fn_c_try_run "$LINENO" -then : +if ac_fn_c_try_run "$LINENO"; then : ac_cv_c_bigendian=no -else $as_nop +else ac_cv_c_bigendian=yes fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -19893,17 +19195,17 @@ fi fi fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_bigendian" >&5 -printf "%s\n" "$ac_cv_c_bigendian" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_bigendian" >&5 +$as_echo "$ac_cv_c_bigendian" >&6; } case $ac_cv_c_bigendian in #( yes) - printf "%s\n" "#define WORDS_BIGENDIAN 1" >>confdefs.h + $as_echo "#define WORDS_BIGENDIAN 1" >>confdefs.h ;; #( no) ;; #( universal) -printf "%s\n" "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h +$as_echo "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h ;; #( *) @@ -19912,28 +19214,28 @@ printf "%s\n" "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h esac ac_fn_c_check_type "$LINENO" "size_t" "ac_cv_type_size_t" "$ac_includes_default" -if test "x$ac_cv_type_size_t" = xyes -then : +if test "x$ac_cv_type_size_t" = xyes; then : -else $as_nop +else -printf "%s\n" "#define size_t unsigned int" >>confdefs.h +cat >>confdefs.h <<_ACEOF +#define size_t unsigned int +_ACEOF fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether struct tm is in sys/time.h or time.h" >&5 -printf %s "checking whether struct tm is in sys/time.h or time.h... " >&6; } -if test ${ac_cv_struct_tm+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether struct tm is in sys/time.h or time.h" >&5 +$as_echo_n "checking whether struct tm is in sys/time.h or time.h... " >&6; } +if ${ac_cv_struct_tm+:} false; then : + $as_echo_n "(cached) " >&6 +else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include int -main (void) +main () { struct tm tm; int *p = &tm.tm_sec; @@ -19942,51 +19244,48 @@ struct tm tm; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : ac_cv_struct_tm=time.h -else $as_nop +else ac_cv_struct_tm=sys/time.h fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_struct_tm" >&5 -printf "%s\n" "$ac_cv_struct_tm" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_struct_tm" >&5 +$as_echo "$ac_cv_struct_tm" >&6; } if test $ac_cv_struct_tm = sys/time.h; then -printf "%s\n" "#define TM_IN_SYS_TIME 1" >>confdefs.h +$as_echo "#define TM_IN_SYS_TIME 1" >>confdefs.h fi # AX_C___ATTRIBUTE__ -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for inline" >&5 -printf %s "checking for inline... " >&6; } -if test ${ac_cv_c_inline+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for inline" >&5 +$as_echo_n "checking for inline... " >&6; } +if ${ac_cv_c_inline+:} false; then : + $as_echo_n "(cached) " >&6 +else ac_cv_c_inline=no for ac_kw in inline __inline__ __inline; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifndef __cplusplus typedef int foo_t; -static $ac_kw foo_t static_foo (void) {return 0; } -$ac_kw foo_t foo (void) {return 0; } +static $ac_kw foo_t static_foo () {return 0; } +$ac_kw foo_t foo () {return 0; } #endif _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : ac_cv_c_inline=$ac_kw fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext test "$ac_cv_c_inline" != no && break done fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_inline" >&5 -printf "%s\n" "$ac_cv_c_inline" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_inline" >&5 +$as_echo "$ac_cv_c_inline" >&6; } case $ac_cv_c_inline in inline | yes) ;; @@ -20005,7 +19304,7 @@ esac if test "$ac_cv_c_inline" != no then - printf "%s\n" "#define COB_HAS_INLINE 1" >>confdefs.h + $as_echo "#define COB_HAS_INLINE 1" >>confdefs.h fi @@ -20013,17 +19312,16 @@ fi # Checks for library functions. # The Ultrix 4.2 mips builtin alloca declared by alloca.h only works # for constant arguments. Useless! -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for working alloca.h" >&5 -printf %s "checking for working alloca.h... " >&6; } -if test ${ac_cv_working_alloca_h+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for working alloca.h" >&5 +$as_echo_n "checking for working alloca.h... " >&6; } +if ${ac_cv_working_alloca_h+:} false; then : + $as_echo_n "(cached) " >&6 +else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int -main (void) +main () { char *p = (char *) alloca (2 * sizeof (int)); if (p) return 0; @@ -20031,52 +19329,52 @@ char *p = (char *) alloca (2 * sizeof (int)); return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : +if ac_fn_c_try_link "$LINENO"; then : ac_cv_working_alloca_h=yes -else $as_nop +else ac_cv_working_alloca_h=no fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_working_alloca_h" >&5 -printf "%s\n" "$ac_cv_working_alloca_h" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_working_alloca_h" >&5 +$as_echo "$ac_cv_working_alloca_h" >&6; } if test $ac_cv_working_alloca_h = yes; then -printf "%s\n" "#define HAVE_ALLOCA_H 1" >>confdefs.h +$as_echo "#define HAVE_ALLOCA_H 1" >>confdefs.h fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for alloca" >&5 -printf %s "checking for alloca... " >&6; } -if test ${ac_cv_func_alloca_works+y} -then : - printf %s "(cached) " >&6 -else $as_nop - if test $ac_cv_working_alloca_h = yes; then - ac_cv_func_alloca_works=yes +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for alloca" >&5 +$as_echo_n "checking for alloca... " >&6; } +if ${ac_cv_func_alloca_works+:} false; then : + $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include -#include -#ifndef alloca -# ifdef __GNUC__ -# define alloca __builtin_alloca -# elif defined _MSC_VER +#ifdef __GNUC__ +# define alloca __builtin_alloca +#else +# ifdef _MSC_VER # include # define alloca _alloca # else -# ifdef __cplusplus -extern "C" -# endif +# ifdef HAVE_ALLOCA_H +# include +# else +# ifdef _AIX + #pragma alloca +# else +# ifndef alloca /* predefined by HP cc +Olibcalls */ void *alloca (size_t); +# endif +# endif +# endif # endif #endif int -main (void) +main () { char *p = (char *) alloca (1); if (p) return 0; @@ -20084,22 +19382,20 @@ char *p = (char *) alloca (1); return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : +if ac_fn_c_try_link "$LINENO"; then : ac_cv_func_alloca_works=yes -else $as_nop +else ac_cv_func_alloca_works=no fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_alloca_works" >&5 -printf "%s\n" "$ac_cv_func_alloca_works" >&6; } -fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_alloca_works" >&5 +$as_echo "$ac_cv_func_alloca_works" >&6; } if test $ac_cv_func_alloca_works = yes; then -printf "%s\n" "#define HAVE_ALLOCA 1" >>confdefs.h +$as_echo "#define HAVE_ALLOCA 1" >>confdefs.h else # The SVR3 libPW and SVR4 libucb both contain incompatible functions @@ -20109,19 +19405,58 @@ else ALLOCA=\${LIBOBJDIR}alloca.$ac_objext -printf "%s\n" "#define C_ALLOCA 1" >>confdefs.h +$as_echo "#define C_ALLOCA 1" >>confdefs.h + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether \`alloca.c' needs Cray hooks" >&5 +$as_echo_n "checking whether \`alloca.c' needs Cray hooks... " >&6; } +if ${ac_cv_os_cray+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#if defined CRAY && ! defined CRAY2 +webecray +#else +wenotbecray +#endif + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "webecray" >/dev/null 2>&1; then : + ac_cv_os_cray=yes +else + ac_cv_os_cray=no +fi +rm -f conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_os_cray" >&5 +$as_echo "$ac_cv_os_cray" >&6; } +if test $ac_cv_os_cray = yes; then + for ac_func in _getb67 GETB67 getb67; do + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes"; then : + +cat >>confdefs.h <<_ACEOF +#define CRAY_STACKSEG_END $ac_func +_ACEOF + + break +fi + done +fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking stack direction for C alloca" >&5 -printf %s "checking stack direction for C alloca... " >&6; } -if test ${ac_cv_c_stack_direction+y} -then : - printf %s "(cached) " >&6 -else $as_nop - if test "$cross_compiling" = yes -then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking stack direction for C alloca" >&5 +$as_echo_n "checking stack direction for C alloca... " >&6; } +if ${ac_cv_c_stack_direction+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test "$cross_compiling" = yes; then : ac_cv_c_stack_direction=0 -else $as_nop +else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default @@ -20142,10 +19477,9 @@ main (int argc, char **argv) return find_stack_direction (0, argc + !argv + 20) < 0; } _ACEOF -if ac_fn_c_try_run "$LINENO" -then : +if ac_fn_c_try_run "$LINENO"; then : ac_cv_c_stack_direction=1 -else $as_nop +else ac_cv_c_stack_direction=-1 fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -20153,110 +19487,46 @@ rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ fi fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_stack_direction" >&5 -printf "%s\n" "$ac_cv_c_stack_direction" >&6; } -printf "%s\n" "#define STACK_DIRECTION $ac_cv_c_stack_direction" >>confdefs.h - - -fi - -ac_func= -for ac_item in $ac_func_c_list -do - if test $ac_func; then - ac_fn_c_check_func "$LINENO" $ac_func ac_cv_func_$ac_func - if eval test \"x\$ac_cv_func_$ac_func\" = xyes; then - echo "#define $ac_item 1" >> confdefs.h - fi - ac_func= - else - ac_func=$ac_item - fi -done - -if test "x$ac_cv_func_vprintf" = xno -then : - ac_fn_c_check_func "$LINENO" "_doprnt" "ac_cv_func__doprnt" -if test "x$ac_cv_func__doprnt" = xyes -then : - -printf "%s\n" "#define HAVE_DOPRNT 1" >>confdefs.h - -fi - -fi -ac_fn_c_check_func "$LINENO" "memmove" "ac_cv_func_memmove" -if test "x$ac_cv_func_memmove" = xyes -then : - printf "%s\n" "#define HAVE_MEMMOVE 1" >>confdefs.h - -fi -ac_fn_c_check_func "$LINENO" "memset" "ac_cv_func_memset" -if test "x$ac_cv_func_memset" = xyes -then : - printf "%s\n" "#define HAVE_MEMSET 1" >>confdefs.h - -fi -ac_fn_c_check_func "$LINENO" "setlocale" "ac_cv_func_setlocale" -if test "x$ac_cv_func_setlocale" = xyes -then : - printf "%s\n" "#define HAVE_SETLOCALE 1" >>confdefs.h +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_stack_direction" >&5 +$as_echo "$ac_cv_c_stack_direction" >&6; } +cat >>confdefs.h <<_ACEOF +#define STACK_DIRECTION $ac_cv_c_stack_direction +_ACEOF -fi -ac_fn_c_check_func "$LINENO" "fcntl" "ac_cv_func_fcntl" -if test "x$ac_cv_func_fcntl" = xyes -then : - printf "%s\n" "#define HAVE_FCNTL 1" >>confdefs.h fi -ac_fn_c_check_func "$LINENO" "strerror" "ac_cv_func_strerror" -if test "x$ac_cv_func_strerror" = xyes -then : - printf "%s\n" "#define HAVE_STRERROR 1" >>confdefs.h -fi -ac_fn_c_check_func "$LINENO" "strcasecmp" "ac_cv_func_strcasecmp" -if test "x$ac_cv_func_strcasecmp" = xyes -then : - printf "%s\n" "#define HAVE_STRCASECMP 1" >>confdefs.h +for ac_func in vprintf +do : + ac_fn_c_check_func "$LINENO" "vprintf" "ac_cv_func_vprintf" +if test "x$ac_cv_func_vprintf" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_VPRINTF 1 +_ACEOF -fi -ac_fn_c_check_func "$LINENO" "strchr" "ac_cv_func_strchr" -if test "x$ac_cv_func_strchr" = xyes -then : - printf "%s\n" "#define HAVE_STRCHR 1" >>confdefs.h +ac_fn_c_check_func "$LINENO" "_doprnt" "ac_cv_func__doprnt" +if test "x$ac_cv_func__doprnt" = xyes; then : -fi -ac_fn_c_check_func "$LINENO" "strrchr" "ac_cv_func_strrchr" -if test "x$ac_cv_func_strrchr" = xyes -then : - printf "%s\n" "#define HAVE_STRRCHR 1" >>confdefs.h +$as_echo "#define HAVE_DOPRNT 1" >>confdefs.h fi -ac_fn_c_check_func "$LINENO" "strdup" "ac_cv_func_strdup" -if test "x$ac_cv_func_strdup" = xyes -then : - printf "%s\n" "#define HAVE_STRDUP 1" >>confdefs.h fi -ac_fn_c_check_func "$LINENO" "strstr" "ac_cv_func_strstr" -if test "x$ac_cv_func_strstr" = xyes -then : - printf "%s\n" "#define HAVE_STRSTR 1" >>confdefs.h +done -fi -ac_fn_c_check_func "$LINENO" "strtol" "ac_cv_func_strtol" -if test "x$ac_cv_func_strtol" = xyes -then : - printf "%s\n" "#define HAVE_STRTOL 1" >>confdefs.h -fi -ac_fn_c_check_func "$LINENO" "gettimeofday" "ac_cv_func_gettimeofday" -if test "x$ac_cv_func_gettimeofday" = xyes -then : - printf "%s\n" "#define HAVE_GETTIMEOFDAY 1" >>confdefs.h +for ac_func in memmove memset setlocale fcntl strerror \ + strcasecmp strchr strrchr strdup strstr strtol +do : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF fi +done # Check for timezone @@ -20264,19 +19534,18 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int -main (void) +main () { timezone = 3600; ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : - printf "%s\n" "#define HAVE_TIMEZONE 1" >>confdefs.h +if ac_fn_c_try_compile "$LINENO"; then : + $as_echo "#define HAVE_TIMEZONE 1" >>confdefs.h fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext # Checks for internationalization stuff @@ -20298,10 +19567,9 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext # Check whether --with-gnu-ld was given. -if test ${with_gnu_ld+y} -then : +if test "${with_gnu_ld+set}" = set; then : withval=$with_gnu_ld; test "$withval" = no || with_gnu_ld=yes -else $as_nop +else with_gnu_ld=no fi @@ -20319,26 +19587,25 @@ if test "${PATH_SEPARATOR+set}" != set; then fi if test -n "$LD"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for ld" >&5 -printf %s "checking for ld... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld" >&5 +$as_echo_n "checking for ld... " >&6; } elif test "$GCC" = yes; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 -printf %s "checking for ld used by $CC... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 +$as_echo_n "checking for ld used by $CC... " >&6; } elif test "$with_gnu_ld" = yes; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 -printf %s "checking for GNU ld... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 +$as_echo_n "checking for GNU ld... " >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 -printf %s "checking for non-GNU ld... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 +$as_echo_n "checking for non-GNU ld... " >&6; } fi if test -n "$LD"; then # Let the user override the test with a path. : else - if test ${acl_cv_path_LD+y} -then : - printf %s "(cached) " >&6 -else $as_nop + if ${acl_cv_path_LD+:} false; then : + $as_echo_n "(cached) " >&6 +else acl_cv_path_LD= # Final result of this test ac_prog=ld # Program to search in $PATH @@ -20407,8 +19674,7 @@ else $as_nop #endif _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : # The compiler produces 64-bit code. Add option '-b64' so that the # linker groks 64-bit object files. case "$acl_cv_path_LD " in @@ -20417,7 +19683,7 @@ then : esac fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ;; sparc64-*-netbsd*) cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -20429,10 +19695,9 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext #endif _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : -else $as_nop +else # The compiler produces 32-bit code. Add option '-m elf32_sparc' # so that the linker groks 32-bit object files. case "$acl_cv_path_LD " in @@ -20441,7 +19706,7 @@ else $as_nop esac fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ;; esac @@ -20450,19 +19715,18 @@ fi LD="$acl_cv_path_LD" fi if test -n "$LD"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $LD" >&5 -printf "%s\n" "$LD" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LD" >&5 +$as_echo "$LD" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } as_fn_error $? "no acceptable ld found in \$PATH" "$LINENO" 5 fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 -printf %s "checking if the linker ($LD) is GNU ld... " >&6; } -if test ${acl_cv_prog_gnu_ld+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 +$as_echo_n "checking if the linker ($LD) is GNU ld... " >&6; } +if ${acl_cv_prog_gnu_ld+:} false; then : + $as_echo_n "(cached) " >&6 +else # I'd rather use --version here, but apparently some GNU lds only accept -v. case `$LD -v 2>&1 &1 &5 -printf "%s\n" "$acl_cv_prog_gnu_ld" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $acl_cv_prog_gnu_ld" >&5 +$as_echo "$acl_cv_prog_gnu_ld" >&6; } with_gnu_ld=$acl_cv_prog_gnu_ld - - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for shared library run path origin" >&5 -printf %s "checking for shared library run path origin... " >&6; } -if test ${acl_cv_rpath+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shared library run path origin" >&5 +$as_echo_n "checking for shared library run path origin... " >&6; } +if ${acl_cv_rpath+:} false; then : + $as_echo_n "(cached) " >&6 +else CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \ ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh @@ -20495,8 +19757,8 @@ else $as_nop acl_cv_rpath=done fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $acl_cv_rpath" >&5 -printf "%s\n" "$acl_cv_rpath" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $acl_cv_rpath" >&5 +$as_echo "$acl_cv_rpath" >&6; } wl="$acl_cv_wl" acl_libext="$acl_cv_libext" acl_shlibext="$acl_cv_shlibext" @@ -20507,22 +19769,20 @@ printf "%s\n" "$acl_cv_rpath" >&6; } acl_hardcode_direct="$acl_cv_hardcode_direct" acl_hardcode_minus_L="$acl_cv_hardcode_minus_L" # Check whether --enable-rpath was given. -if test ${enable_rpath+y} -then : +if test "${enable_rpath+set}" = set; then : enableval=$enable_rpath; : -else $as_nop +else enable_rpath=yes fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking 32-bit host C ABI" >&5 -printf %s "checking 32-bit host C ABI... " >&6; } -if test ${gl_cv_host_cpu_c_abi_32bit+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking 32-bit host C ABI" >&5 +$as_echo_n "checking 32-bit host C ABI... " >&6; } +if ${gl_cv_host_cpu_c_abi_32bit+:} false; then : + $as_echo_n "(cached) " >&6 +else if test -n "$gl_cv_host_cpu_c_abi"; then case "$gl_cv_host_cpu_c_abi" in i386 | x86_64-x32 | arm | armhf | arm64-ilp32 | hppa | ia64-ilp32 | mips | mipsn32 | powerpc | riscv*-ilp32* | s390 | sparc) @@ -20584,13 +19844,12 @@ else $as_nop #endif _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : gl_cv_host_cpu_c_abi_32bit=no -else $as_nop +else gl_cv_host_cpu_c_abi_32bit=yes fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ;; arm* | aarch64 ) @@ -20609,13 +19868,12 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext #endif _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : gl_cv_host_cpu_c_abi_32bit=no -else $as_nop +else gl_cv_host_cpu_c_abi_32bit=yes fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ;; hppa1.0 | hppa1.1 | hppa2.0* | hppa64 ) @@ -20630,13 +19888,12 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext #endif _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : gl_cv_host_cpu_c_abi_32bit=no -else $as_nop +else gl_cv_host_cpu_c_abi_32bit=yes fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ;; ia64* ) @@ -20651,13 +19908,12 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext #endif _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : gl_cv_host_cpu_c_abi_32bit=yes -else $as_nop +else gl_cv_host_cpu_c_abi_32bit=no fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ;; mips* ) @@ -20672,13 +19928,12 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext #endif _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : gl_cv_host_cpu_c_abi_32bit=no -else $as_nop +else gl_cv_host_cpu_c_abi_32bit=yes fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ;; powerpc* ) @@ -20697,13 +19952,12 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext #endif _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : gl_cv_host_cpu_c_abi_32bit=no -else $as_nop +else gl_cv_host_cpu_c_abi_32bit=yes fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ;; rs6000 ) @@ -20722,13 +19976,12 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext #endif _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : gl_cv_host_cpu_c_abi_32bit=no -else $as_nop +else gl_cv_host_cpu_c_abi_32bit=yes fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ;; s390* ) @@ -20743,13 +19996,12 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext #endif _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : gl_cv_host_cpu_c_abi_32bit=no -else $as_nop +else gl_cv_host_cpu_c_abi_32bit=yes fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ;; sparc | sparc64 ) @@ -20764,13 +20016,12 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext #endif _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : gl_cv_host_cpu_c_abi_32bit=no -else $as_nop +else gl_cv_host_cpu_c_abi_32bit=yes fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ;; *) @@ -20780,8 +20031,8 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $gl_cv_host_cpu_c_abi_32bit" >&5 -printf "%s\n" "$gl_cv_host_cpu_c_abi_32bit" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_host_cpu_c_abi_32bit" >&5 +$as_echo "$gl_cv_host_cpu_c_abi_32bit" >&6; } HOST_CPU_C_ABI_32BIT="$gl_cv_host_cpu_c_abi_32bit" @@ -20789,13 +20040,11 @@ printf "%s\n" "$gl_cv_host_cpu_c_abi_32bit" >&6; } - - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for ELF binary format" >&5 -printf %s "checking for ELF binary format... " >&6; } -if test ${gl_cv_elf+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ELF binary format" >&5 +$as_echo_n "checking for ELF binary format... " >&6; } +if ${gl_cv_elf+:} false; then : + $as_echo_n "(cached) " >&6 +else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef __ELF__ @@ -20804,18 +20053,17 @@ else $as_nop _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "Extensible Linking Format" >/dev/null 2>&1 -then : + $EGREP "Extensible Linking Format" >/dev/null 2>&1; then : gl_cv_elf=yes -else $as_nop +else gl_cv_elf=no fi -rm -rf conftest* +rm -f conftest* fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $gl_cv_elf" >&5 -printf "%s\n" "$gl_cv_elf" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_elf" >&5 +$as_echo "$gl_cv_elf" >&6; } if test $gl_cv_elf; then # Extract the ELF class of a file (5th byte) in decimal. # Cf. https://en.wikipedia.org/wiki/Executable_and_Linkable_Format#File_header @@ -20863,12 +20111,11 @@ printf "%s\n" "$gl_cv_elf" >&6; } } fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for the common suffixes of directories in the library search path" >&5 -printf %s "checking for the common suffixes of directories in the library search path... " >&6; } -if test ${acl_cv_libdirstems+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for the common suffixes of directories in the library search path" >&5 +$as_echo_n "checking for the common suffixes of directories in the library search path... " >&6; } +if ${acl_cv_libdirstems+:} false; then : + $as_echo_n "(cached) " >&6 +else acl_libdirstem=lib acl_libdirstem2= acl_libdirstem3= @@ -20932,8 +20179,8 @@ else $as_nop acl_cv_libdirstems="$acl_libdirstem,$acl_libdirstem2,$acl_libdirstem3" fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $acl_cv_libdirstems" >&5 -printf "%s\n" "$acl_cv_libdirstems" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $acl_cv_libdirstems" >&5 +$as_echo "$acl_cv_libdirstems" >&6; } acl_libdirstem=`echo "$acl_cv_libdirstems" | sed -e 's/,.*//'` acl_libdirstem2=`echo "$acl_cv_libdirstems" | sed -e 's/^[^,]*,//' -e 's/,.*//'` acl_libdirstem3=`echo "$acl_cv_libdirstems" | sed -e 's/^[^,]*,[^,]*,//' -e 's/,.*//'` @@ -20965,8 +20212,7 @@ printf "%s\n" "$acl_cv_libdirstems" >&6; } # Check whether --with-libiconv-prefix was given. -if test ${with_libiconv_prefix+y} -then : +if test "${with_libiconv_prefix+set}" = set; then : withval=$with_libiconv_prefix; if test "X$withval" = "Xno"; then use_additional=no @@ -21457,12 +20703,11 @@ fi done - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for iconv" >&5 -printf %s "checking for iconv... " >&6; } -if test ${am_cv_func_iconv+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for iconv" >&5 +$as_echo_n "checking for iconv... " >&6; } +if ${am_cv_func_iconv+:} false; then : + $as_echo_n "(cached) " >&6 +else am_cv_func_iconv="no, consider installing GNU libiconv" am_cv_lib_iconv=no @@ -21473,7 +20718,7 @@ else $as_nop #include int -main (void) +main () { iconv_t cd = iconv_open("",""); iconv(cd,NULL,NULL,NULL,NULL); @@ -21482,11 +20727,10 @@ iconv_t cd = iconv_open("",""); return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : +if ac_fn_c_try_link "$LINENO"; then : am_cv_func_iconv=yes fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext if test "$am_cv_func_iconv" != yes; then am_save_LIBS="$LIBS" @@ -21498,7 +20742,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam \ #include int -main (void) +main () { iconv_t cd = iconv_open("",""); iconv(cd,NULL,NULL,NULL,NULL); @@ -21507,26 +20751,24 @@ iconv_t cd = iconv_open("",""); return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : +if ac_fn_c_try_link "$LINENO"; then : am_cv_lib_iconv=yes am_cv_func_iconv=yes fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS="$am_save_LIBS" fi fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_func_iconv" >&5 -printf "%s\n" "$am_cv_func_iconv" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_func_iconv" >&5 +$as_echo "$am_cv_func_iconv" >&6; } if test "$am_cv_func_iconv" = yes; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for working iconv" >&5 -printf %s "checking for working iconv... " >&6; } -if test ${am_cv_func_iconv_works+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working iconv" >&5 +$as_echo_n "checking for working iconv... " >&6; } +if ${am_cv_func_iconv_works+:} false; then : + $as_echo_n "(cached) " >&6 +else am_save_LIBS="$LIBS" if test $am_cv_lib_iconv = yes; then @@ -21534,13 +20776,12 @@ else $as_nop fi am_cv_func_iconv_works=no for ac_iconv_const in '' 'const'; do - if test "$cross_compiling" = yes -then : + if test "$cross_compiling" = yes; then : case "$host_os" in aix* | hpux*) am_cv_func_iconv_works="guessing no" ;; *) am_cv_func_iconv_works="guessing yes" ;; esac -else $as_nop +else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -21552,7 +20793,7 @@ else $as_nop #endif int -main (void) +main () { int result = 0; /* Test against AIX 5.1 bug: Failures are not distinguishable from successful @@ -21664,8 +20905,7 @@ int result = 0; return 0; } _ACEOF -if ac_fn_c_try_run "$LINENO" -then : +if ac_fn_c_try_run "$LINENO"; then : am_cv_func_iconv_works=yes fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -21677,8 +20917,8 @@ fi LIBS="$am_save_LIBS" fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_func_iconv_works" >&5 -printf "%s\n" "$am_cv_func_iconv_works" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_func_iconv_works" >&5 +$as_echo "$am_cv_func_iconv_works" >&6; } case "$am_cv_func_iconv_works" in *no) am_func_iconv=no am_cv_lib_iconv=no ;; *) am_func_iconv=yes ;; @@ -21688,14 +20928,14 @@ printf "%s\n" "$am_cv_func_iconv_works" >&6; } fi if test "$am_func_iconv" = yes; then -printf "%s\n" "#define HAVE_ICONV 1" >>confdefs.h +$as_echo "#define HAVE_ICONV 1" >>confdefs.h fi if test "$am_cv_lib_iconv" = yes; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to link with libiconv" >&5 -printf %s "checking how to link with libiconv... " >&6; } - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $LIBICONV" >&5 -printf "%s\n" "$LIBICONV" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to link with libiconv" >&5 +$as_echo_n "checking how to link with libiconv... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIBICONV" >&5 +$as_echo "$LIBICONV" >&6; } else CPPFLAGS="$am_save_CPPFLAGS" LIBICONV= @@ -21705,12 +20945,11 @@ printf "%s\n" "$LIBICONV" >&6; } if test "$am_cv_func_iconv" = yes; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for iconv declaration" >&5 -printf %s "checking for iconv declaration... " >&6; } - if test ${am_cv_proto_iconv+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for iconv declaration" >&5 +$as_echo_n "checking for iconv declaration... " >&6; } + if ${am_cv_proto_iconv+:} false; then : + $as_echo_n "(cached) " >&6 +else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -21728,33 +20967,34 @@ size_t iconv(); #endif int -main (void) +main () { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : +if ac_fn_c_try_compile "$LINENO"; then : am_cv_proto_iconv_arg1="" -else $as_nop +else am_cv_proto_iconv_arg1="const" fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);" fi am_cv_proto_iconv=`echo "$am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'` - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_proto_iconv" >&5 -printf "%s\n" " +$as_echo " $am_cv_proto_iconv" >&6; } else am_cv_proto_iconv_arg1="" fi -printf "%s\n" "#define ICONV_CONST $am_cv_proto_iconv_arg1" >>confdefs.h +cat >>confdefs.h <<_ACEOF +#define ICONV_CONST $am_cv_proto_iconv_arg1 +_ACEOF @@ -21764,22 +21004,21 @@ printf "%s\n" "#define ICONV_CONST $am_cv_proto_iconv_arg1" >>confdefs.h # FreeBSD has gnugetopt library - needs checking ac_fn_c_check_func "$LINENO" "getopt_long_only" "ac_cv_func_getopt_long_only" -if test "x$ac_cv_func_getopt_long_only" = xyes -then : - ac_fn_c_check_header_compile "$LINENO" "kpathsea/getopt.h" "ac_cv_header_kpathsea_getopt_h" "$ac_includes_default" -if test "x$ac_cv_header_kpathsea_getopt_h" = xyes -then : - printf "%s\n" "#define HAVE_KPATHSEA_GETOPT_H 1" >>confdefs.h +if test "x$ac_cv_func_getopt_long_only" = xyes; then : + for ac_header in kpathsea/getopt.h getopt.h +do : + as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` +ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" +if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF fi -ac_fn_c_check_header_compile "$LINENO" "getopt.h" "ac_cv_header_getopt_h" "$ac_includes_default" -if test "x$ac_cv_header_getopt_h" = xyes -then : - printf "%s\n" "#define HAVE_GETOPT_H 1" >>confdefs.h -fi +done -else $as_nop +else case " $LIBOBJS " in *" getopt.$ac_objext "* ) ;; *) LIBOBJS="$LIBOBJS getopt.$ac_objext" @@ -21801,23 +21040,21 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int -main (void) +main () { nanosleep (NULL, NULL); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : - -else $as_nop - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for nanosleep in -lrt" >&5 -printf %s "checking for nanosleep in -lrt... " >&6; } -if test ${ac_cv_lib_rt_nanosleep+y} -then : - printf %s "(cached) " >&6 -else $as_nop +if ac_fn_c_try_link "$LINENO"; then : + +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for nanosleep in -lrt" >&5 +$as_echo_n "checking for nanosleep in -lrt... " >&6; } +if ${ac_cv_lib_rt_nanosleep+:} false; then : + $as_echo_n "(cached) " >&6 +else ac_check_lib_save_LIBS=$LIBS LIBS="-lrt $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -21826,30 +21063,33 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif char nanosleep (); int -main (void) +main () { return nanosleep (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : +if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_rt_nanosleep=yes -else $as_nop +else ac_cv_lib_rt_nanosleep=no fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_nanosleep" >&5 -printf "%s\n" "$ac_cv_lib_rt_nanosleep" >&6; } -if test "x$ac_cv_lib_rt_nanosleep" = xyes -then : - printf "%s\n" "#define HAVE_LIBRT 1" >>confdefs.h +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_nanosleep" >&5 +$as_echo "$ac_cv_lib_rt_nanosleep" >&6; } +if test "x$ac_cv_lib_rt_nanosleep" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBRT 1 +_ACEOF LIBS="-lrt $LIBS" @@ -21859,12 +21099,11 @@ fi then LIBCOB_LIBS="$LIBCOB_LIBS -lrt" else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for nanosleep in -lposix4" >&5 -printf %s "checking for nanosleep in -lposix4... " >&6; } -if test ${ac_cv_lib_posix4_nanosleep+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for nanosleep in -lposix4" >&5 +$as_echo_n "checking for nanosleep in -lposix4... " >&6; } +if ${ac_cv_lib_posix4_nanosleep+:} false; then : + $as_echo_n "(cached) " >&6 +else ac_check_lib_save_LIBS=$LIBS LIBS="-lposix4 $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -21873,30 +21112,33 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif char nanosleep (); int -main (void) +main () { return nanosleep (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : +if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_posix4_nanosleep=yes -else $as_nop +else ac_cv_lib_posix4_nanosleep=no fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_posix4_nanosleep" >&5 -printf "%s\n" "$ac_cv_lib_posix4_nanosleep" >&6; } -if test "x$ac_cv_lib_posix4_nanosleep" = xyes -then : - printf "%s\n" "#define HAVE_LIBPOSIX4 1" >>confdefs.h +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_posix4_nanosleep" >&5 +$as_echo "$ac_cv_lib_posix4_nanosleep" >&6; } +if test "x$ac_cv_lib_posix4_nanosleep" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBPOSIX4 1 +_ACEOF LIBS="-lposix4 $LIBS" @@ -21908,23 +21150,22 @@ fi fi fi fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext # Checks for gettext. - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether NLS is requested" >&5 -printf %s "checking whether NLS is requested... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether NLS is requested" >&5 +$as_echo_n "checking whether NLS is requested... " >&6; } # Check whether --enable-nls was given. -if test ${enable_nls+y} -then : +if test "${enable_nls+set}" = set; then : enableval=$enable_nls; USE_NLS=$enableval -else $as_nop +else USE_NLS=yes fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $USE_NLS" >&5 -printf "%s\n" "$USE_NLS" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $USE_NLS" >&5 +$as_echo "$USE_NLS" >&6; } @@ -21963,12 +21204,11 @@ rm -f conf$$.file # Extract the first word of "msgfmt", so it can be a program name with args. set dummy msgfmt; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_path_MSGFMT+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_MSGFMT+:} false; then : + $as_echo_n "(cached) " >&6 +else case "$MSGFMT" in [\\/]* | ?:[\\/]*) ac_cv_path_MSGFMT="$MSGFMT" # Let the user override the test with a path. @@ -21996,21 +21236,20 @@ esac fi MSGFMT="$ac_cv_path_MSGFMT" if test "$MSGFMT" != ":"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $MSGFMT" >&5 -printf "%s\n" "$MSGFMT" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MSGFMT" >&5 +$as_echo "$MSGFMT" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi # Extract the first word of "gmsgfmt", so it can be a program name with args. set dummy gmsgfmt; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_path_GMSGFMT+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_GMSGFMT+:} false; then : + $as_echo_n "(cached) " >&6 +else case $GMSGFMT in [\\/]* | ?:[\\/]*) ac_cv_path_GMSGFMT="$GMSGFMT" # Let the user override the test with a path. @@ -22020,15 +21259,11 @@ else $as_nop for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac + test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then - ac_cv_path_GMSGFMT="$as_dir$ac_word$ac_exec_ext" - printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_GMSGFMT="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -22041,11 +21276,11 @@ esac fi GMSGFMT=$ac_cv_path_GMSGFMT if test -n "$GMSGFMT"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $GMSGFMT" >&5 -printf "%s\n" "$GMSGFMT" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $GMSGFMT" >&5 +$as_echo "$GMSGFMT" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi @@ -22086,12 +21321,11 @@ rm -f conf$$.file # Extract the first word of "xgettext", so it can be a program name with args. set dummy xgettext; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_path_XGETTEXT+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_XGETTEXT+:} false; then : + $as_echo_n "(cached) " >&6 +else case "$XGETTEXT" in [\\/]* | ?:[\\/]*) ac_cv_path_XGETTEXT="$XGETTEXT" # Let the user override the test with a path. @@ -22119,11 +21353,11 @@ esac fi XGETTEXT="$ac_cv_path_XGETTEXT" if test "$XGETTEXT" != ":"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $XGETTEXT" >&5 -printf "%s\n" "$XGETTEXT" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $XGETTEXT" >&5 +$as_echo "$XGETTEXT" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi rm -f messages.po @@ -22164,12 +21398,11 @@ rm -f conf$$.file # Extract the first word of "msgmerge", so it can be a program name with args. set dummy msgmerge; ac_word=$2 -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -printf %s "checking for $ac_word... " >&6; } -if test ${ac_cv_path_MSGMERGE+y} -then : - printf %s "(cached) " >&6 -else $as_nop +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_MSGMERGE+:} false; then : + $as_echo_n "(cached) " >&6 +else case "$MSGMERGE" in [\\/]* | ?:[\\/]*) ac_cv_path_MSGMERGE="$MSGMERGE" # Let the user override the test with a path. @@ -22196,11 +21429,11 @@ esac fi MSGMERGE="$ac_cv_path_MSGMERGE" if test "$MSGMERGE" != ":"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $MSGMERGE" >&5 -printf "%s\n" "$MSGMERGE" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MSGMERGE" >&5 +$as_echo "$MSGMERGE" >&6; } else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 -printf "%s\n" "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } fi @@ -22244,76 +21477,72 @@ fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for CFPreferencesCopyAppValue" >&5 -printf %s "checking for CFPreferencesCopyAppValue... " >&6; } -if test ${gt_cv_func_CFPreferencesCopyAppValue+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for CFPreferencesCopyAppValue" >&5 +$as_echo_n "checking for CFPreferencesCopyAppValue... " >&6; } +if ${gt_cv_func_CFPreferencesCopyAppValue+:} false; then : + $as_echo_n "(cached) " >&6 +else gt_save_LIBS="$LIBS" LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int -main (void) +main () { CFPreferencesCopyAppValue(NULL, NULL) ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : +if ac_fn_c_try_link "$LINENO"; then : gt_cv_func_CFPreferencesCopyAppValue=yes -else $as_nop +else gt_cv_func_CFPreferencesCopyAppValue=no fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS="$gt_save_LIBS" fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $gt_cv_func_CFPreferencesCopyAppValue" >&5 -printf "%s\n" "$gt_cv_func_CFPreferencesCopyAppValue" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_func_CFPreferencesCopyAppValue" >&5 +$as_echo "$gt_cv_func_CFPreferencesCopyAppValue" >&6; } if test $gt_cv_func_CFPreferencesCopyAppValue = yes; then -printf "%s\n" "#define HAVE_CFPREFERENCESCOPYAPPVALUE 1" >>confdefs.h +$as_echo "#define HAVE_CFPREFERENCESCOPYAPPVALUE 1" >>confdefs.h fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for CFLocaleCopyPreferredLanguages" >&5 -printf %s "checking for CFLocaleCopyPreferredLanguages... " >&6; } -if test ${gt_cv_func_CFLocaleCopyPreferredLanguages+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for CFLocaleCopyPreferredLanguages" >&5 +$as_echo_n "checking for CFLocaleCopyPreferredLanguages... " >&6; } +if ${gt_cv_func_CFLocaleCopyPreferredLanguages+:} false; then : + $as_echo_n "(cached) " >&6 +else gt_save_LIBS="$LIBS" LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int -main (void) +main () { CFLocaleCopyPreferredLanguages(); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : +if ac_fn_c_try_link "$LINENO"; then : gt_cv_func_CFLocaleCopyPreferredLanguages=yes -else $as_nop +else gt_cv_func_CFLocaleCopyPreferredLanguages=no fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS="$gt_save_LIBS" fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $gt_cv_func_CFLocaleCopyPreferredLanguages" >&5 -printf "%s\n" "$gt_cv_func_CFLocaleCopyPreferredLanguages" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_func_CFLocaleCopyPreferredLanguages" >&5 +$as_echo "$gt_cv_func_CFLocaleCopyPreferredLanguages" >&6; } if test $gt_cv_func_CFLocaleCopyPreferredLanguages = yes; then -printf "%s\n" "#define HAVE_CFLOCALECOPYPREFERREDLANGUAGES 1" >>confdefs.h +$as_echo "#define HAVE_CFLOCALECOPYPREFERREDLANGUAGES 1" >>confdefs.h fi INTL_MACOSX_LIBS= @@ -22359,12 +21588,11 @@ typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1]; gt_expression_test_code= fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GNU gettext in libc" >&5 -printf %s "checking for GNU gettext in libc... " >&6; } -if eval test \${$gt_func_gnugettext_libc+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU gettext in libc" >&5 +$as_echo_n "checking for GNU gettext in libc... " >&6; } +if eval \${$gt_func_gnugettext_libc+:} false; then : + $as_echo_n "(cached) " >&6 +else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -22379,7 +21607,7 @@ extern int *_nl_domain_bindings; $gt_revision_test_code int -main (void) +main () { bindtextdomain ("", ""); @@ -22389,18 +21617,17 @@ return * gettext ("")$gt_expression_test_code + __GNU_GETTEXT_SYMBOL_EXPRESSION return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : +if ac_fn_c_try_link "$LINENO"; then : eval "$gt_func_gnugettext_libc=yes" -else $as_nop +else eval "$gt_func_gnugettext_libc=no" fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi eval ac_res=\$$gt_func_gnugettext_libc - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -printf "%s\n" "$ac_res" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then @@ -22433,12 +21660,11 @@ printf "%s\n" "$ac_res" >&6; } done - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for iconv" >&5 -printf %s "checking for iconv... " >&6; } -if test ${am_cv_func_iconv+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for iconv" >&5 +$as_echo_n "checking for iconv... " >&6; } +if ${am_cv_func_iconv+:} false; then : + $as_echo_n "(cached) " >&6 +else am_cv_func_iconv="no, consider installing GNU libiconv" am_cv_lib_iconv=no @@ -22449,7 +21675,7 @@ else $as_nop #include int -main (void) +main () { iconv_t cd = iconv_open("",""); iconv(cd,NULL,NULL,NULL,NULL); @@ -22458,11 +21684,10 @@ iconv_t cd = iconv_open("",""); return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : +if ac_fn_c_try_link "$LINENO"; then : am_cv_func_iconv=yes fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext if test "$am_cv_func_iconv" != yes; then am_save_LIBS="$LIBS" @@ -22474,7 +21699,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam \ #include int -main (void) +main () { iconv_t cd = iconv_open("",""); iconv(cd,NULL,NULL,NULL,NULL); @@ -22483,26 +21708,24 @@ iconv_t cd = iconv_open("",""); return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : +if ac_fn_c_try_link "$LINENO"; then : am_cv_lib_iconv=yes am_cv_func_iconv=yes fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS="$am_save_LIBS" fi fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_func_iconv" >&5 -printf "%s\n" "$am_cv_func_iconv" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_func_iconv" >&5 +$as_echo "$am_cv_func_iconv" >&6; } if test "$am_cv_func_iconv" = yes; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for working iconv" >&5 -printf %s "checking for working iconv... " >&6; } -if test ${am_cv_func_iconv_works+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working iconv" >&5 +$as_echo_n "checking for working iconv... " >&6; } +if ${am_cv_func_iconv_works+:} false; then : + $as_echo_n "(cached) " >&6 +else am_save_LIBS="$LIBS" if test $am_cv_lib_iconv = yes; then @@ -22510,13 +21733,12 @@ else $as_nop fi am_cv_func_iconv_works=no for ac_iconv_const in '' 'const'; do - if test "$cross_compiling" = yes -then : + if test "$cross_compiling" = yes; then : case "$host_os" in aix* | hpux*) am_cv_func_iconv_works="guessing no" ;; *) am_cv_func_iconv_works="guessing yes" ;; esac -else $as_nop +else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -22528,7 +21750,7 @@ else $as_nop #endif int -main (void) +main () { int result = 0; /* Test against AIX 5.1 bug: Failures are not distinguishable from successful @@ -22640,8 +21862,7 @@ int result = 0; return 0; } _ACEOF -if ac_fn_c_try_run "$LINENO" -then : +if ac_fn_c_try_run "$LINENO"; then : am_cv_func_iconv_works=yes fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -22653,8 +21874,8 @@ fi LIBS="$am_save_LIBS" fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_func_iconv_works" >&5 -printf "%s\n" "$am_cv_func_iconv_works" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_func_iconv_works" >&5 +$as_echo "$am_cv_func_iconv_works" >&6; } case "$am_cv_func_iconv_works" in *no) am_func_iconv=no am_cv_lib_iconv=no ;; *) am_func_iconv=yes ;; @@ -22664,14 +21885,14 @@ printf "%s\n" "$am_cv_func_iconv_works" >&6; } fi if test "$am_func_iconv" = yes; then -printf "%s\n" "#define HAVE_ICONV 1" >>confdefs.h +$as_echo "#define HAVE_ICONV 1" >>confdefs.h fi if test "$am_cv_lib_iconv" = yes; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to link with libiconv" >&5 -printf %s "checking how to link with libiconv... " >&6; } - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $LIBICONV" >&5 -printf "%s\n" "$LIBICONV" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to link with libiconv" >&5 +$as_echo_n "checking how to link with libiconv... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIBICONV" >&5 +$as_echo "$LIBICONV" >&6; } else CPPFLAGS="$am_save_CPPFLAGS" LIBICONV= @@ -22704,8 +21925,7 @@ printf "%s\n" "$LIBICONV" >&6; } # Check whether --with-libintl-prefix was given. -if test ${with_libintl_prefix+y} -then : +if test "${with_libintl_prefix+set}" = set; then : withval=$with_libintl_prefix; if test "X$withval" = "Xno"; then use_additional=no @@ -23165,12 +22385,11 @@ fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GNU gettext in libintl" >&5 -printf %s "checking for GNU gettext in libintl... " >&6; } -if eval test \${$gt_func_gnugettext_libintl+y} -then : - printf %s "(cached) " >&6 -else $as_nop + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU gettext in libintl" >&5 +$as_echo_n "checking for GNU gettext in libintl... " >&6; } +if eval \${$gt_func_gnugettext_libintl+:} false; then : + $as_echo_n "(cached) " >&6 +else gt_save_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $INCINTL" gt_save_LIBS="$LIBS" @@ -23193,7 +22412,7 @@ const char *_nl_expand_alias (const char *); $gt_revision_test_code int -main (void) +main () { bindtextdomain ("", ""); @@ -23203,13 +22422,12 @@ return * gettext ("")$gt_expression_test_code + __GNU_GETTEXT_SYMBOL_EXPRESSION return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : +if ac_fn_c_try_link "$LINENO"; then : eval "$gt_func_gnugettext_libintl=yes" -else $as_nop +else eval "$gt_func_gnugettext_libintl=no" fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" != yes; } && test -n "$LIBICONV"; then LIBS="$LIBS $LIBICONV" @@ -23231,7 +22449,7 @@ const char *_nl_expand_alias (const char *); $gt_revision_test_code int -main (void) +main () { bindtextdomain ("", ""); @@ -23241,22 +22459,21 @@ return * gettext ("")$gt_expression_test_code + __GNU_GETTEXT_SYMBOL_EXPRESSION return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO" -then : +if ac_fn_c_try_link "$LINENO"; then : LIBINTL="$LIBINTL $LIBICONV" LTLIBINTL="$LTLIBINTL $LTLIBICONV" eval "$gt_func_gnugettext_libintl=yes" fi -rm -f core conftest.err conftest.$ac_objext conftest.beam \ +rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi CPPFLAGS="$gt_save_CPPFLAGS" LIBS="$gt_save_LIBS" fi eval ac_res=\$$gt_func_gnugettext_libintl - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -printf "%s\n" "$ac_res" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } fi if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" = "yes"; } \ @@ -23283,20 +22500,20 @@ printf "%s\n" "$ac_res" >&6; } if test "$gt_use_preinstalled_gnugettext" = "yes" \ || test "$nls_cv_use_gnu_gettext" = "yes"; then -printf "%s\n" "#define ENABLE_NLS 1" >>confdefs.h +$as_echo "#define ENABLE_NLS 1" >>confdefs.h else USE_NLS=no fi fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to use NLS" >&5 -printf %s "checking whether to use NLS... " >&6; } - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $USE_NLS" >&5 -printf "%s\n" "$USE_NLS" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to use NLS" >&5 +$as_echo_n "checking whether to use NLS... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $USE_NLS" >&5 +$as_echo "$USE_NLS" >&6; } if test "$USE_NLS" = "yes"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking where the gettext function comes from" >&5 -printf %s "checking where the gettext function comes from... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking where the gettext function comes from" >&5 +$as_echo_n "checking where the gettext function comes from... " >&6; } if test "$gt_use_preinstalled_gnugettext" = "yes"; then if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then gt_source="external libintl" @@ -23306,18 +22523,18 @@ printf %s "checking where the gettext function comes from... " >&6; } else gt_source="included intl directory" fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $gt_source" >&5 -printf "%s\n" "$gt_source" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_source" >&5 +$as_echo "$gt_source" >&6; } fi if test "$USE_NLS" = "yes"; then if test "$gt_use_preinstalled_gnugettext" = "yes"; then if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to link with libintl" >&5 -printf %s "checking how to link with libintl... " >&6; } - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $LIBINTL" >&5 -printf "%s\n" "$LIBINTL" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to link with libintl" >&5 +$as_echo_n "checking how to link with libintl... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIBINTL" >&5 +$as_echo "$LIBINTL" >&6; } for element in $INCINTL; do haveit= @@ -23344,10 +22561,10 @@ printf "%s\n" "$LIBINTL" >&6; } fi -printf "%s\n" "#define HAVE_GETTEXT 1" >>confdefs.h +$as_echo "#define HAVE_GETTEXT 1" >>confdefs.h -printf "%s\n" "#define HAVE_DCGETTEXT 1" >>confdefs.h +$as_echo "#define HAVE_DCGETTEXT 1" >>confdefs.h fi @@ -23371,19 +22588,18 @@ then fi # Checks for workable strftime -if test "$cross_compiling" = yes -then : - { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +if test "$cross_compiling" = yes; then : + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot run test program while cross compiling See \`config.log' for more details" "$LINENO" 5; } -else $as_nop +else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include int -main (void) +main () { time_t ticks; @@ -23402,9 +22618,8 @@ main (void) return 0; } _ACEOF -if ac_fn_c_try_run "$LINENO" -then : - printf "%s\n" "#define COB_STRFTIME 1" >>confdefs.h +if ac_fn_c_try_run "$LINENO"; then : + $as_echo "#define COB_STRFTIME 1" >>confdefs.h fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -23413,18 +22628,17 @@ fi # Checks for size of long -if test "$cross_compiling" = yes -then : - { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +if test "$cross_compiling" = yes; then : + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot run test program while cross compiling See \`config.log' for more details" "$LINENO" 5; } -else $as_nop +else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main (void) +main () { if (sizeof(long int) == sizeof(long long)) @@ -23435,9 +22649,8 @@ main (void) return 0; } _ACEOF -if ac_fn_c_try_run "$LINENO" -then : - printf "%s\n" "#define COB_LI_IS_LL 1" >>confdefs.h +if ac_fn_c_try_run "$LINENO"; then : + $as_echo "#define COB_LI_IS_LL 1" >>confdefs.h fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -23525,19 +22738,18 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main (void) +main () { int testint; ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : - printf "%s\n" "#define HAVE_PSIGN_OPT 1" >>confdefs.h +if ac_fn_c_try_compile "$LINENO"; then : + $as_echo "#define HAVE_PSIGN_OPT 1" >>confdefs.h fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext CFLAGS="$MYOLDCFLAGS" # Check if aligned attribute works @@ -23545,19 +22757,18 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main (void) +main () { char testchar[4] __attribute__((aligned)); ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO" -then : - printf "%s\n" "#define HAVE_ATTRIBUTE_ALIGNED 1" >>confdefs.h +if ac_fn_c_try_compile "$LINENO"; then : + $as_echo "#define HAVE_ATTRIBUTE_ALIGNED 1" >>confdefs.h fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext # Special stuff @@ -23584,7 +22795,7 @@ case $host_os in if test "`basename $CC`" != "gcc" then COB_SHARED_OPT="-b" - printf "%s\n" "#define _XOPEN_SOURCE_EXTENDED 1" >>confdefs.h + $as_echo "#define _XOPEN_SOURCE_EXTENDED 1" >>confdefs.h rm -f hptest* echo 'int main() { return 0; }' > hptest.c @@ -23623,12 +22834,12 @@ esac if test "`basename $CC`" = "gcc" then - CFLAGS="$CFLAGS -fsigned-char -Wall -Wwrite-strings -Wmissing-prototypes -Wno-format-security" + CFLAGS="$CFLAGS -fsigned-char -Wall -Wwrite-strings -Wmissing-prototypes -Wno-format-security -Wno-parentheses" fi if test "x$lt_cv_dlopen_self" != "xyes" then - printf "%s\n" "#define COB_NO_SELFOPEN 1" >>confdefs.h + $as_echo "#define COB_NO_SELFOPEN 1" >>confdefs.h fi @@ -23636,19 +22847,31 @@ COB_SPLITKEY_FLAGS="yes" # Generate the output -printf "%s\n" "#define COB_EXPORT_DYN \"$COB_EXPORT_DYN\"" >>confdefs.h +cat >>confdefs.h <<_ACEOF +#define COB_EXPORT_DYN "$COB_EXPORT_DYN" +_ACEOF -printf "%s\n" "#define COB_PIC_FLAGS \"$COB_PIC_FLAGS\"" >>confdefs.h +cat >>confdefs.h <<_ACEOF +#define COB_PIC_FLAGS "$COB_PIC_FLAGS" +_ACEOF -printf "%s\n" "#define COB_SHARED_OPT \"$COB_SHARED_OPT\"" >>confdefs.h +cat >>confdefs.h <<_ACEOF +#define COB_SHARED_OPT "$COB_SHARED_OPT" +_ACEOF -printf "%s\n" "#define COB_EXEEXT \"$COB_EXEEXT\"" >>confdefs.h +cat >>confdefs.h <<_ACEOF +#define COB_EXEEXT "$COB_EXEEXT" +_ACEOF -printf "%s\n" "#define COB_EXTRA_FLAGS \"$COB_EXTRA_FLAGS\"" >>confdefs.h +cat >>confdefs.h <<_ACEOF +#define COB_EXTRA_FLAGS "$COB_EXTRA_FLAGS" +_ACEOF if test "x$striplib" != "x" then - printf "%s\n" "#define COB_STRIP_CMD \"$striplib\"" >>confdefs.h + cat >>confdefs.h <<_ACEOF +#define COB_STRIP_CMD "$striplib" +_ACEOF # AC_SUBST(COB_STRIP_CMD) fi @@ -23711,8 +22934,8 @@ _ACEOF case $ac_val in #( *${as_nl}*) case $ac_var in #( - *_cv_*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 -printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; + *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( @@ -23742,15 +22965,15 @@ printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} /^ac_cv_env_/b end t clear :clear - s/^\([^=]*\)=\(.*[{}].*\)$/test ${\1+y} || &/ + s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ t end s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ :end' >>confcache if diff "$cache_file" confcache >/dev/null 2>&1; then :; else if test -w "$cache_file"; then if test "x$cache_file" != "x/dev/null"; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 -printf "%s\n" "$as_me: updating cache $cache_file" >&6;} + { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 +$as_echo "$as_me: updating cache $cache_file" >&6;} if test ! -f "$cache_file" || test -h "$cache_file"; then cat confcache >"$cache_file" else @@ -23764,8 +22987,8 @@ printf "%s\n" "$as_me: updating cache $cache_file" >&6;} fi fi else - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 -printf "%s\n" "$as_me: not updating unwritable cache $cache_file" >&6;} + { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 +$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;} fi fi rm -f confcache @@ -23782,7 +23005,7 @@ U= for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue # 1. Remove the extension, and $U if already installed. ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' - ac_i=`printf "%s\n" "$ac_i" | sed "$ac_script"` + ac_i=`$as_echo "$ac_i" | sed "$ac_script"` # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR # will be set to the directory where LIBOBJS objects are built. as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext" @@ -23793,14 +23016,14 @@ LIBOBJS=$ac_libobjs LTLIBOBJS=$ac_ltlibobjs -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking that generated files are newer than configure" >&5 -printf %s "checking that generated files are newer than configure... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking that generated files are newer than configure" >&5 +$as_echo_n "checking that generated files are newer than configure... " >&6; } if test -n "$am_sleep_pid"; then # Hide warnings about reused PIDs. wait $am_sleep_pid 2>/dev/null fi - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: done" >&5 -printf "%s\n" "done" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: done" >&5 +$as_echo "done" >&6; } if test -n "$EXEEXT"; then am__EXEEXT_TRUE= am__EXEEXT_FALSE='#' @@ -23831,8 +23054,8 @@ fi ac_write_fail=0 ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files $CONFIG_STATUS" -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 -printf "%s\n" "$as_me: creating $CONFIG_STATUS" >&6;} +{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 +$as_echo "$as_me: creating $CONFIG_STATUS" >&6;} as_write_fail=0 cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 #! $SHELL @@ -23855,16 +23078,14 @@ cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh -as_nop=: -if test ${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1 -then : +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST -else $as_nop +else case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( @@ -23874,46 +23095,46 @@ esac fi - -# Reset variables that may have inherited troublesome values from -# the environment. - -# IFS needs to be set, to space, tab, and newline, in precisely that order. -# (If _AS_PATH_WALK were called with IFS unset, it would have the -# side effect of setting IFS to empty, thus disabling word splitting.) -# Quoting is to prevent editors from complaining about space-tab. as_nl=' ' export as_nl -IFS=" "" $as_nl" - -PS1='$ ' -PS2='> ' -PS4='+ ' - -# Ensure predictable behavior from utilities with locale-dependent output. -LC_ALL=C -export LC_ALL -LANGUAGE=C -export LANGUAGE - -# We cannot yet rely on "unset" to work, but we need these variables -# to be unset--not just set to an empty or harmless value--now, to -# avoid bugs in old shells (e.g. pre-3.0 UWIN ksh). This construct -# also avoids known problems related to "unset" and subshell syntax -# in other old shells (e.g. bash 2.01 and pdksh 5.2.14). -for as_var in BASH_ENV ENV MAIL MAILPATH CDPATH -do eval test \${$as_var+y} \ - && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : -done - -# Ensure that fds 0, 1, and 2 are open. -if (exec 3>&0) 2>/dev/null; then :; else exec 0&1) 2>/dev/null; then :; else exec 1>/dev/null; fi -if (exec 3>&2) ; then :; else exec 2>/dev/null; fi +# Printing a long string crashes Solaris 7 /usr/bin/printf. +as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo +# Prefer a ksh shell builtin over an external printf program on Solaris, +# but without wasting forks for bash or zsh. +if test -z "$BASH_VERSION$ZSH_VERSION" \ + && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='print -r --' + as_echo_n='print -rn --' +elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='printf %s\n' + as_echo_n='printf %s' +else + if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then + as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' + as_echo_n='/usr/ucb/echo -n' + else + as_echo_body='eval expr "X$1" : "X\\(.*\\)"' + as_echo_n_body='eval + arg=$1; + case $arg in #( + *"$as_nl"*) + expr "X$arg" : "X\\(.*\\)$as_nl"; + arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; + esac; + expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" + ' + export as_echo_n_body + as_echo_n='sh -c $as_echo_n_body as_echo' + fi + export as_echo_body + as_echo='sh -c $as_echo_body as_echo' +fi # The user is always right. -if ${PATH_SEPARATOR+false} :; then +if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || @@ -23922,6 +23143,13 @@ if ${PATH_SEPARATOR+false} :; then fi +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +IFS=" "" $as_nl" + # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in #(( @@ -23930,12 +23158,8 @@ case $0 in #(( for as_dir in $PATH do IFS=$as_save_IFS - case $as_dir in #((( - '') as_dir=./ ;; - */) ;; - *) as_dir=$as_dir/ ;; - esac - test -r "$as_dir$0" && as_myself=$as_dir$0 && break + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break done IFS=$as_save_IFS @@ -23947,10 +23171,30 @@ if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then - printf "%s\n" "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi +# Unset variables that we do not need and which cause bugs (e.g. in +# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" +# suppresses any "Segmentation fault" message there. '((' could +# trigger a bug in pdksh 5.2.14. +for as_var in BASH_ENV ENV MAIL MAILPATH +do eval test x\${$as_var+set} = xset \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# CDPATH. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH # as_fn_error STATUS ERROR [LINENO LOG_FD] @@ -23963,14 +23207,13 @@ as_fn_error () as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 + $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi - printf "%s\n" "$as_me: error: $2" >&2 + $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error - # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. @@ -23997,20 +23240,18 @@ as_fn_unset () { eval $1=; unset $1;} } as_unset=as_fn_unset - # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. -if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null -then : +if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' -else $as_nop +else as_fn_append () { eval $1=\$$1\$2 @@ -24022,13 +23263,12 @@ fi # as_fn_append # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. -if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null -then : +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' -else $as_nop +else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` @@ -24059,7 +23299,7 @@ as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || -printf "%s\n" X/"$0" | +$as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q @@ -24081,10 +23321,6 @@ as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits - -# Determine whether it's possible to make 'echo' print without a newline. -# These variables are no longer used directly by Autoconf, but are AC_SUBSTed -# for compatibility with existing Makefiles. ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) @@ -24098,12 +23334,6 @@ case `echo -n x` in #((((( ECHO_N='-n';; esac -# For backward compatibility with old third-party macros, we provide -# the shell variables $as_echo and $as_echo_n. New code should use -# AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively. -as_echo='printf %s\n' -as_echo_n='printf %s' - rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file @@ -24145,7 +23375,7 @@ as_fn_mkdir_p () as_dirs= while :; do case $as_dir in #( - *\'*) as_qdir=`printf "%s\n" "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" @@ -24154,7 +23384,7 @@ $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || -printf "%s\n" X"$as_dir" | +$as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q @@ -24216,8 +23446,8 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by opensource COBOL 4J $as_me 1.1.2, which was -generated by GNU Autoconf 2.71. Invocation command line was +This file was extended by opensource COBOL 4J $as_me 1.1.14, which was +generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS @@ -24279,16 +23509,14 @@ $config_commands Report bugs to ." _ACEOF -ac_cs_config=`printf "%s\n" "$ac_configure_args" | sed "$ac_safe_unquote"` -ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\''/g"` cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 -ac_cs_config='$ac_cs_config_escaped' +ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -opensource COBOL 4J config.status 1.1.2 -configured by $0, generated by GNU Autoconf 2.71, +opensource COBOL 4J config.status 1.1.14 +configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" -Copyright (C) 2021 Free Software Foundation, Inc. +Copyright (C) 2012 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." @@ -24328,15 +23556,15 @@ do -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) ac_cs_recheck=: ;; --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) - printf "%s\n" "$ac_cs_version"; exit ;; + $as_echo "$ac_cs_version"; exit ;; --config | --confi | --conf | --con | --co | --c ) - printf "%s\n" "$ac_cs_config"; exit ;; + $as_echo "$ac_cs_config"; exit ;; --debug | --debu | --deb | --de | --d | -d ) debug=: ;; --file | --fil | --fi | --f ) $ac_shift case $ac_optarg in - *\'*) ac_optarg=`printf "%s\n" "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; + *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; '') as_fn_error $? "missing file argument" ;; esac as_fn_append CONFIG_FILES " '$ac_optarg'" @@ -24344,7 +23572,7 @@ do --header | --heade | --head | --hea ) $ac_shift case $ac_optarg in - *\'*) ac_optarg=`printf "%s\n" "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; + *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; esac as_fn_append CONFIG_HEADERS " '$ac_optarg'" ac_need_defaults=false;; @@ -24353,7 +23581,7 @@ do as_fn_error $? "ambiguous option: \`$1' Try \`$0 --help' for more information.";; --help | --hel | -h ) - printf "%s\n" "$ac_cs_usage"; exit ;; + $as_echo "$ac_cs_usage"; exit ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil | --si | --s) ac_cs_silent=: ;; @@ -24381,7 +23609,7 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 if \$ac_cs_recheck; then set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion shift - \printf "%s\n" "running CONFIG_SHELL=$SHELL \$*" >&6 + \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' export CONFIG_SHELL exec "\$@" @@ -24395,7 +23623,7 @@ exec 5>>config.log sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX ## Running $as_me. ## _ASBOX - printf "%s\n" "$ac_log" + $as_echo "$ac_log" } >&5 _ACEOF @@ -24403,7 +23631,6 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 # # INIT-COMMANDS # -ac_cv_exeext="$ac_cv_exeext" AMDEP_TRUE="$AMDEP_TRUE" MAKE="${MAKE-make}" @@ -24920,9 +24147,9 @@ done # We use the long form for the default assignment because of an extremely # bizarre bug on SunOS 4.1.3. if $ac_need_defaults; then - test ${CONFIG_FILES+y} || CONFIG_FILES=$config_files - test ${CONFIG_HEADERS+y} || CONFIG_HEADERS=$config_headers - test ${CONFIG_COMMANDS+y} || CONFIG_COMMANDS=$config_commands + test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files + test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers + test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands fi # Have a temporary directory for convenience. Make it in the build tree @@ -25258,7 +24485,7 @@ do esac || as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;; esac - case $ac_f in *\'*) ac_f=`printf "%s\n" "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac + case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac as_fn_append ac_file_inputs " '$ac_f'" done @@ -25266,17 +24493,17 @@ do # use $as_me), people would be surprised to read: # /* config.h. Generated by config.status. */ configure_input='Generated from '` - printf "%s\n" "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' + $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' `' by configure.' if test x"$ac_file" != x-; then configure_input="$ac_file. $configure_input" - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 -printf "%s\n" "$as_me: creating $ac_file" >&6;} + { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 +$as_echo "$as_me: creating $ac_file" >&6;} fi # Neutralize special characters interpreted by sed in replacement strings. case $configure_input in #( *\&* | *\|* | *\\* ) - ac_sed_conf_input=`printf "%s\n" "$configure_input" | + ac_sed_conf_input=`$as_echo "$configure_input" | sed 's/[\\\\&|]/\\\\&/g'`;; #( *) ac_sed_conf_input=$configure_input;; esac @@ -25293,7 +24520,7 @@ $as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$ac_file" : 'X\(//\)[^/]' \| \ X"$ac_file" : 'X\(//\)$' \| \ X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || -printf "%s\n" X"$ac_file" | +$as_echo X"$ac_file" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q @@ -25317,9 +24544,9 @@ printf "%s\n" X"$ac_file" | case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) - ac_dir_suffix=/`printf "%s\n" "$ac_dir" | sed 's|^\.[\\/]||'` + ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. - ac_top_builddir_sub=`printf "%s\n" "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` + ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; @@ -25381,8 +24608,8 @@ ac_sed_dataroot=' case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in *datarootdir*) ac_datarootdir_seen=yes;; *@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 -printf "%s\n" "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 +$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_datarootdir_hack=' @@ -25426,9 +24653,9 @@ test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } && { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \ "$ac_tmp/out"`; test -z "$ac_out"; } && - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&5 -printf "%s\n" "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' +$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&2;} rm -f "$ac_tmp/stdin" @@ -25444,20 +24671,20 @@ which seems to be undefined. Please make sure it is defined" >&2;} # if test x"$ac_file" != x-; then { - printf "%s\n" "/* $configure_input */" >&1 \ + $as_echo "/* $configure_input */" \ && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" } >"$ac_tmp/config.h" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 if diff "$ac_file" "$ac_tmp/config.h" >/dev/null 2>&1; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5 -printf "%s\n" "$as_me: $ac_file is unchanged" >&6;} + { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5 +$as_echo "$as_me: $ac_file is unchanged" >&6;} else rm -f "$ac_file" mv "$ac_tmp/config.h" "$ac_file" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 fi else - printf "%s\n" "/* $configure_input */" >&1 \ + $as_echo "/* $configure_input */" \ && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \ || as_fn_error $? "could not create -" "$LINENO" 5 fi @@ -25477,7 +24704,7 @@ $as_expr X"$_am_arg" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$_am_arg" : 'X\(//\)[^/]' \| \ X"$_am_arg" : 'X\(//\)$' \| \ X"$_am_arg" : 'X\(/\)' \| . 2>/dev/null || -printf "%s\n" X"$_am_arg" | +$as_echo X"$_am_arg" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q @@ -25497,8 +24724,8 @@ printf "%s\n" X"$_am_arg" | s/.*/./; q'`/stamp-h$_am_stamp_count ;; - :C) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5 -printf "%s\n" "$as_me: executing $ac_file commands" >&6;} + :C) { $as_echo "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5 +$as_echo "$as_me: executing $ac_file commands" >&6;} ;; esac @@ -25507,7 +24734,7 @@ printf "%s\n" "$as_me: executing $ac_file commands" >&6;} "tests/atconfig":C) cat >tests/atconfig </dev/null || -printf "%s\n" X"$am_mf" | +$as_echo X"$am_mf" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q @@ -25583,7 +24808,7 @@ printf "%s\n" X"$am_mf" | $as_expr X/"$am_mf" : '.*/\([^/][^/]*\)/*$' \| \ X"$am_mf" : 'X\(//\)$' \| \ X"$am_mf" : 'X\(/\)' \| . 2>/dev/null || -printf "%s\n" X/"$am_mf" | +$as_echo X/"$am_mf" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q @@ -25608,8 +24833,8 @@ printf "%s\n" X/"$am_mf" | (exit $ac_status); } || am_rc=$? done if test $am_rc -ne 0; then - { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "Something went wrong bootstrapping makefile fragments for automatic dependency tracking. If GNU make was not used, consider re-running the configure script with MAKE=\"gmake\" (or whatever is @@ -25640,6 +24865,7 @@ See \`config.log' for more details" "$LINENO" 5; } cat <<_LT_EOF >> "$cfgfile" #! $SHELL # Generated automatically by $as_me ($PACKAGE) $VERSION +# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: # NOTE: Changes made to this file will be lost: look at ltmain.sh. # Provide generalized library-building support services. @@ -26169,7 +25395,6 @@ _LT_EOF esac - ltmain=$ac_aux_dir/ltmain.sh @@ -26639,8 +25864,8 @@ if test "$no_create" != yes; then $ac_cs_success || as_fn_exit 1 fi if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 -printf "%s\n" "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 +$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} fi @@ -26678,4 +25903,3 @@ then fi echo " Use fcntl for file locking: ${ac_cv_func_fcntl}" echo "" - diff --git a/configure.ac b/configure.ac index 77876630..34b7526f 100644 --- a/configure.ac +++ b/configure.ac @@ -19,7 +19,7 @@ AC_PREREQ(2.59) -AC_INIT([opensource COBOL 4J],[1.1.2],[ws-opensource-cobol-contact@osscons.jp],[opensource-cobol-4j-1.1.2]) +AC_INIT([opensource COBOL 4J],[1.1.14],[ws-opensource-cobol-contact@osscons.jp],[opensource-cobol-4j-1.1.14]) AC_CONFIG_SRCDIR([libcobj.h]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_TESTDIR([tests]) @@ -71,7 +71,6 @@ AH_TEMPLATE([COB_HAS_INLINE], [Can use inline keyword]) 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]) AC_DEFINE(__USE_STRING_INLINES) @@ -179,7 +178,7 @@ fi AC_FUNC_ALLOCA AC_FUNC_VPRINTF AC_CHECK_FUNCS([memmove memset setlocale fcntl strerror \ - strcasecmp strchr strrchr strdup strstr strtol gettimeofday]) + strcasecmp strchr strrchr strdup strstr strtol]) # Check for timezone AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], [[timezone = 3600;]])], @@ -408,7 +407,7 @@ esac if test "`basename $CC`" = "gcc" then - CFLAGS="$CFLAGS -fsigned-char -Wall -Wwrite-strings -Wmissing-prototypes -Wno-format-security" + CFLAGS="$CFLAGS -fsigned-char -Wall -Wwrite-strings -Wmissing-prototypes -Wno-format-security -Wno-parentheses" fi if test "x$lt_cv_dlopen_self" != "xyes" diff --git a/copy/Makefile.in b/copy/Makefile.in index e0efa915..6a42f7fe 100644 --- a/copy/Makefile.in +++ b/copy/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.16.5 from Makefile.am. +# Makefile.in generated by automake 1.16.2 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2021 Free Software Foundation, Inc. +# Copyright (C) 1994-2020 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -201,8 +201,6 @@ COB_SHARED_OPT = @COB_SHARED_OPT@ COB_SPLITKEY_FLAGS = @COB_SPLITKEY_FLAGS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ -CSCOPE = @CSCOPE@ -CTAGS = @CTAGS@ CXXCPP = @CXXCPP@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ @@ -214,7 +212,6 @@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ -ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ @@ -396,6 +393,7 @@ ctags CTAGS: cscope cscopelist: + distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am diff --git a/doc/cobj-api_SpringBoot.md b/doc/cobj-api_SpringBoot.md new file mode 100755 index 00000000..0a041045 --- /dev/null +++ b/doc/cobj-api_SpringBoot.md @@ -0,0 +1,199 @@ +# Build a Spring Boot project using Visual Studio Code +1. Install the "Spring Boot Extension Pack", a Visual Studio Code extension. + ![alt text](../image/doc1.png) + +1. Install the "Java Extension Pack", a Visual Studio Code extension. +![alt text](../image/doc2.png) + +1. Select "Explorer" in the left sidebar and click "Create Java Project". +![alt text](../image/doc3.png) + +1. Select Spring Boot as the project type. +![alt text](../image/doc4.png) + +1. Select the build tool from Maven or Gradle. + +1. Select Spring Boot version. + +1. Select Java as the language. +![alt text](../image/doc5.png) + +1. Enter any Group ID. In this step, enter "com.example". +![alt text](../image/doc6.png) + +1. Enter any Artifact ID. In this step, enter "cobj_api_test". +![alt text](../image/doc7.png) + +1. Select the packaging type from jar or war. +1. Select the Java version. + +1. Select the dependent libraries. In this step, only Spring Web is selected, but other libraries can be selected as needed. +![alt text](../image/doc8.png) + +1. Select the directory to create the project in and press enter. +The project will be created according to the above steps. +![alt text](../image/doc9.png) + +# Create an API using Spring Boot/cobj-api +1. Prepare a COBOL program with a `LINKAGE SECTION`. In this procedure, the following sample program will be used. + + sample.cbl + ``` cobol + IDENTIFICATION DIVISION. + PROGRAM-ID. sample. + ENVIRONMENT DIVISION. + CONFIGURATION SECTION. + DATA DIVISION. + WORKING-STORAGE SECTION. + LINKAGE SECTION. + 01 DATA1 PIC 9(09). + 01 DATA2 PIC 9(09). + 01 DATA3 PIC 9(09). + 01 SUM-DATA PIC 9(09). + PROCEDURE DIVISION + USING DATA1, + DATA2, + DATA3, + SUM-DATA. + MAIN-SECTION. + ADD DATA1 DATA2 DATA3 TO SUM-DATA. + GOBACK. + + ``` + +2. Generate a JSON file from the COBOL program using `cobj` command. + ``` + cobj -info-json-dir=./ -java-package=com.example.cobj_api_test sample.cbl + ``` + * `-info-json-dir`:Option to generate a JSON file from the COBOL program. Specify the destination directory after "=". + * `-java-package`:Option to specify the package name of the generated Java file. Specify the package name after "=". + + This will generate sample.java and info_sample.json. + + info_sample.json describes the variables defined in the "LINKAGE SECTION" and their type names. + ``` + { + "opensourcecobol4j_version": "1.1.1", + "program_id": "sample", + "procedure_division_using_parameters": [ + { + "variable_name": "DATA1", + "java_type": "int" + }, + { + "variable_name": "DATA2", + "java_type": "int" + }, + { + "variable_name": "DATA3", + "java_type": "int" + }, + { + "variable_name": "SUM-DATA", + "java_type": "int" + } + ] + } + ``` +3. Generate Spring Boot Java files from the JSON file using `cobj-api` command. + ``` + cobj-api -java-package=com.example.cobj_api_test info_sample.json + ``` + * `-java-package`: An option to specify the package name of the generated Java file. + + This will generate sampleController.java and sampleRecord.java. +4. Place sample.java, sampleController.java, and sampleRecord.java in the created Spring Boot project. +In this procedure, they will be placed in "src/main/java/com/example/cobj_api_test". + + File structure + ``` + . + ├── HELP.md + ├── mvnw + ├── mvnw.cmd + ├── pom.xml + ├── src + │ ├── main + │ │ ├── java + │ │ │ └── com + │ │ │ └── example + │ │ │ └── cobj_api_test + │ │ │ ├── CobjApiTestApplication.java + │ │ │ ├── sample.java + │ │ │ ├── sampleController.java + │ │ │ └── sampleRecord.java + │ │ └── resources + │ └── test + └── target + ``` + + +5. Place libcobj.jar anywhere in the project. + + File structure + ``` + . + ├── HELP.md + |── lib + | └── libcobj.jar + ├── mvnw + ├── mvnw.cmd + ├── pom.xml + ├── src + │ ├── main + │ │ ├── java + │ │ │ └── com + │ │ │ └── example + │ │ │ └── cobj_api_test + │ │ │ ├── CobjApiTestApplication.java + │ │ │ ├── sample.java + │ │ │ ├── sampleController.java + │ │ │ └── sampleRecord.java + │ │ └── resources + │ └── test + └── target + ``` + * libcobj.jar is a jar file that is generated under "opensourcecobol4j/libcobj/app/build/lib/" when opensource COBOL 4J is installed. + +6. 依存関係の追加 +* For Gradle + Modify build.gradle as follows. + ``` + dependencies { + implementation files('lib/libcobj.jar') + implementation('org.springframework.boot:spring-boot-starter-web') { + exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' + } + } + ``` + * "spring-boot-starter-web" is a dependency that has been added by default in the previous steps. + * The provider included in "spring-boot-starter-web" conflicts with the provider included in libocbj.jar, so it needs to be excluded with `exclude group`. +* For Maven + Add the following dependency to pom.xml. + ``` + + libcobj + libcobj + 1.1.0(version of cobj) + system + ${basedir}/lib/libcobj.jar + + ``` +7. Build and launch the Spring Boot project. + Run the following command in the root directory of the project. +* For Gradle + ``` + ./gradlew bootRun + ``` +* For Maven + ``` + mvn spring-boot:run + ``` + +8. You can call the API by accessing `http://localhost:8080/?=&=&...` in your browser. + + In the case of the sample program used this time, if you access `http://localhost:8080/sample?DATA1=1&DATA2=2&DATA3=3`, you will get the following JSON: + ``` + {"statuscode":200,"DATA1":1,"DATA2":2,"DATA3":3,"SUM_DATA":6} + ``` + diff --git a/doc/cobj-api_SpringBoot_JP.md b/doc/cobj-api_SpringBoot_JP.md new file mode 100755 index 00000000..f24884b4 --- /dev/null +++ b/doc/cobj-api_SpringBoot_JP.md @@ -0,0 +1,199 @@ +# Visual Studio Code を用いた Spring Bootプロジェクトの構築方法 +1. Visual Studio Codeの拡張機能である、"Spring Boot Extension Pack"をインストールする. +![alt text](../image/doc1.png) + +1. Visual Studio Codeの拡張機能である、"Java Extension Pack"をインストールする. +![alt text](../image/doc2.png) + +1. 左側のサイドバーにある、"Explorer"を選択し、"Create Java Project"をクリックする。 +![alt text](../image/doc3.png) + +1. プロジェクトタイプはSpring Bootを選択する。 +![alt text](../image/doc4.png) + +1. ビルドツールをMavenかGradleから選択する。 + +1. Spring Bootのバージョンを選択する。 + +1. 使用言語はJavaを選択する。 +![alt text](../image/doc5.png) + +1. 任意の Group ID を入力する。この手順では、"com.example"を入力する。 +![alt text](../image/doc6.png) + +1. 任意の Artifact ID を入力する。この手順では、"cobj_api_test"を入力する。 +![alt text](../image/doc7.png) + +1. パッケージングタイプをJarかWarから選択する。 + +1. Javaのバージョンを選択する。 + +1. 依存するライブラリを選択する。この手順ではSpring Webのみを選択するが、必要に応じて他のライブラリを選択することもできる。 +![alt text](../image/doc8.png) + +1. プロジェクトを作成するディレクトリを選択し、enterを押す。 +上記の手順により、プロジェクトが作成される。 +![alt text](../image/doc9.png) + +# Spring Boot/cobj-api を用いたAPIの作成方法 +1. `LINKAGE SECTION`が記述されたCOBOLプログラムを用意する。 + 本手順では下記のサンプルプログラムを使用する。 + + sample.cbl + ``` cobol + IDENTIFICATION DIVISION. + PROGRAM-ID. sample. + ENVIRONMENT DIVISION. + CONFIGURATION SECTION. + DATA DIVISION. + WORKING-STORAGE SECTION. + LINKAGE SECTION. + 01 DATA1 PIC 9(09). + 01 DATA2 PIC 9(09). + 01 DATA3 PIC 9(09). + 01 SUM-DATA PIC 9(09). + PROCEDURE DIVISION + USING DATA1, + DATA2, + DATA3, + SUM-DATA. + MAIN-SECTION. + ADD DATA1 DATA2 DATA3 TO SUM-DATA. + GOBACK. + + ``` + +2. `cobj`コマンドでCOBOLプログラムからJSONファイルを生成する。 + ``` + cobj -info-json-dir=./ -java-package=com.example.cobj_api_test sample.cbl + ``` + * `-info-json-dir`:COBOLプログラムからJSONファイルを生成するオプション。"="の後ろに生成先のディレクトリを指定する。 + * `-java-package`:生成されるJavaファイルのパッケージ名を指定するオプション。"="の後ろにパッケージ名を指定する。 + + これにより、sample.java、info_sample.jsonが生成される。 + + info_sample.jsonには、"LINKAGE SECTION"で定義された変数と、その型名が記述される。 + ``` + { + "opensourcecobol4j_version": "1.1.1", + "program_id": "sample", + "procedure_division_using_parameters": [ + { + "variable_name": "DATA1", + "java_type": "int" + }, + { + "variable_name": "DATA2", + "java_type": "int" + }, + { + "variable_name": "DATA3", + "java_type": "int" + }, + { + "variable_name": "SUM-DATA", + "java_type": "int" + } + ] + } + ``` +3. `cobj-api`コマンドで、JSONファイルからSpring Boot向けのJavaファイルを生成する。 + ``` + cobj-api -java-package=com.example.cobj_api_test info_sample.json + ``` + * `-java-package`:生成されるJavaファイルのパッケージ名を指定するオプション。 + + これにより、sampleController.java、sampleRecord.javaが生成される。 +4. sample.java、sampleController.java、sampleRecord.javaを、作成したSpring Bootプロジェクトに配置する。 +本手順では、"src/main/java/com/example/cobj_api_test"に配置する。 + + ファイル構成: + ``` + . + ├── HELP.md + ├── mvnw + ├── mvnw.cmd + ├── pom.xml + ├── src + │ ├── main + │ │ ├── java + │ │ │ └── com + │ │ │ └── example + │ │ │ └── cobj_api_test + │ │ │ ├── CobjApiTestApplication.java + │ │ │ ├── sample.java + │ │ │ ├── sampleController.java + │ │ │ └── sampleRecord.java + │ │ └── resources + │ └── test + └── target + ``` + + +5. プロジェクトの任意の場所に、libcobj.jarを配置する。 + ファイル構成: + ``` + . + ├── HELP.md + |── lib + | └── libcobj.jar + ├── mvnw + ├── mvnw.cmd + ├── pom.xml + ├── src + │ ├── main + │ │ ├── java + │ │ │ └── com + │ │ │ └── example + │ │ │ └── cobj_api_test + │ │ │ ├── CobjApiTestApplication.java + │ │ │ ├── sample.java + │ │ │ ├── sampleController.java + │ │ │ └── sampleRecord.java + │ │ └── resources + │ └── test + └── target + ``` + * libcobj.jarは、opensource COBOL 4Jをインストールすると、"opensourcecobol4j/libcobj/app/build/lib/"配下に生成されるjarファイルである。 + +6. 依存関係の追加 +* Gradleの場合 + build.gradleを以下のように修正する。 + ``` + dependencies { + implementation files('lib/libcobj.jar') + implementation('org.springframework.boot:spring-boot-starter-web') { + exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' + } + } + ``` + * "spring-boot-starter-web"は、これまでの手順によりデフォルトで追加されている依存関係である。 + * "spring-boot-starter-web"に含まれているプロバイダーが、libocbj.jarに含まれているプロバイダーと競合するため、`exclude group`で除外する必要がある。 +* Mavenの場合 +pom.xmlに以下の依存関係を追加する。 + ``` + + libcobj + libcobj + 1.1.0(cobjのバージョン) + system + ${basedir}/lib/libcobj.jar + + ``` +7. Spring Bootプロジェクトをビルド及び起動する。 + プロジェクトのルートディレクトリで、以下のコマンドを実行する。 +* Gradleの場合 + ``` + ./gradlew bootRun + ``` +* Mavenの場合 + ``` + mvn spring-boot:run + ``` + +8. ブラウザで、`http://localhost:8080/?<データ名1>=<データ値1>&<データ名2>=<データ値2>&...`にアクセスすることで、APIを呼び出すことができる。 + + 今回使用したサンプルプログラムの場合、`http://localhost:8080/sample?DATA1=1&DATA2=2&DATA3=3`にアクセスすると、下記のようなJSONが返される。 + ``` + {"statuscode":200,"DATA1":1,"DATA2":2,"DATA3":3,"SUM_DATA":6} + ``` diff --git a/doc/configuration-params-JP.md b/doc/configuration-params-JP.md new file mode 100644 index 00000000..f4920966 --- /dev/null +++ b/doc/configuration-params-JP.md @@ -0,0 +1,98 @@ +# configuration-params-JP +## 概要 +opensource COBOL 4J のコンフィグファイルに記載されているパラメータについて説明する。 + +opensource COBOL 4J をインストールすると、デフォルトの設定ファイルが `/usr/local/share/opensource-cobol-4j-1.0.7/config/default.conf` に配置され、コンパイル時に参照されるようになっている。また、コンパイル時に `-conf` を使用することで参照するコンフィグファイルを変更することもできる。設定ファイルはリポジトリの `config` ディレクトリに格納されていて、デフォルトで参照される `default.conf` のほかに以下のものがある。これらは、それぞれファイル名に対応する方言を許容する設定ファイルである。 +* `boundary-limit.conf` +* `bs2000.conf` +* `cobol85.conf` +* `cobol2002.conf` +* `default-en.conf` +* `default-jp.conf` +* `ibm.conf` +* `jp-compat.conf` +* `mf.conf` +* `mvs.conf` + +これらの設定ファイルにあるほとんどのパラメータは `default.conf` のものと同じで値が異なる(`mvs.conf` に `not-reserved` というパラメータがあり、それは `default.conf` にはない)。パラメータ一覧の表にあるデフォルト値は `default.conf` のものである。 + +## 構文のサポートレベルについて +いくつかのパラメータは、値として `ok`, `archaic`, `obsolete`, `skip`, `ignore`, `unconformable`, `error` が選択できる。これにより、いくつかの構文をコンパイラがサポートするか、警告するか、拒否するかを選択することができる。 + +| レベル | 期待される表示(xxxは該当構文、〇〇〇はパラメータ一覧No.1のnameで設定した値が入る) | +| --- | --- | +| ok | 何も表示されない | +| archaic | 警告として xxx is archaic in 〇〇〇 が表示される| +| obsolete | 警告として xxx is obsolete in 〇〇〇 が表示される | +| skip | 何も表示されない | +| ignore | 警告として xxx ignored が表示される | +| unconformtable | エラーとして xxx does not conform to 〇〇〇 が表示される | +| error | 構文エラーが表示される | + +## パラメータ一覧 + +| No | パラメータ名 | 設定できる値 | デフォルト値 | パラメータの説明 | 備考 | +|----|--------------|--------------|--------------|------------------|------| +| 1 | name | 任意の文字列 | OpenCOBOL | 設定ファイル名 | | +| 2 | tab-width | 整数 | 8 | タブ文字を何文字分のスペースとして扱うかを決める | 動作が安定しない | +| 3 | text-column | 整数 | 72 | コードを何桁目まで記述できるかを決める | | +| 4 | default-organization | `record-sequential`, `line-sequential` | `record-sequential` | `SELECT`で`ORGANIZATION`が定義されていない場合に、ここにセットされている値を`ORGANIZATION`として扱う | | +| 5 | assign-clause | `cobol2002`, `mf`, `ibm`, `jph1` | `mf` | `SELECT`文の`ASSIGN`の書き方で、IBMやMFの書き方が使えるようになる | 動作が安定しない | +| 6 | filename-mapping | `yes`, `no` | `yes` | ファイル名を環境変数から取得することができる | | +| 7 | pretty-display | `yes`, `no` | `yes` | `USAGE BINARY`で定義したデータ項目の表示を設定する | 未実装 | +| 8 | auto-initialize | `yes`, `no` | `yes` | `WORKING-STORAGE SECTION`で`VALUE`を使って初期化していなくても自動で初期値を付与する | | +| 9 | complex-odo | `yes`, `no` | `no` | yesの場合は、集団項目の中(先頭や末尾ではなく)に`OCCURS ~ DEPENDING ON`があってもコンパイルが通る | | +| 10 | indirect-redefines | `yes`, `no` | `no` | `REDEFINES`を多段階で定義できるようにする | | +| 11 | binary-size | `2-4-8`, `1-2-4-8`, `1--8` | `1-2-4-8` | `PIC 9(n) BINARY`の変数が確保するバイト数を設定する | | +| 12 | binary-truncate | `yes`, `no` | `yes` | オーバーフロー時の切り捨てが発生した場合に例外を発生させる | 動作が安定しない | +| 13 | binary-byteorder | `native`, `big-endian` | `big-endian` | バイトの並びを設定する | Javaではバイトの並びはデフォルトでビッグエンディアンとなっている | +| 14 | abort-on-io-exception | `any`, `fatal`, `never` | `any` | ファイル操作のエラーハンドリングのレベルを設定する。ハンドリングのレベルによって、出力されるJavaのコードが違う。 | | +| 15 | larger-redefines-ok | `yes`, `no` | `no` | `REDEFINES`で定義した集団項目のサイズが元の集団項目のサイズを上回っている場合でもコンパイルできるようにする | | +| 16 | relaxed-syntax-check | `yes`, `no` | `no` | 以下のMFの書き方を許容できるようにする
・`INPUT-OUTPUT SECTION`という記述がなくてもよい
・`FILE SECTION`という記述がなくてもよい
・`REDEFINES`を書くときに、`PIC X(n) REDEFINES`のような書き方を許容する | | +| 17 | perform-osvs | `yes`, `no` | `no` | IBM OS/VS COBOLの方言を使えるようにする(PERFORMの扱い方が違う) | 未実装 | +| 18 | sticky-linkage | `yes`, `no` | `no` | `LINKAGE SECTION`にあるデータが`CALL`の呼び出しごとに初期化されずに保持されるようになる | 未実装 | +| 19 | assign_external | `yes`, `no` | `no` | 対象のCOBOLプログラムの`SELECT`文のすべての`ASSIGN`句に`EXTERNAL`が指定されているものとして扱うことができる | コンパイルオプションの`-assign_external`と同じ | +| 20 | relax-level-hierarchy | `yes`, `no` | `no` | データ項目の階層の数字の大小が不揃いでもコンパイルが通るようにする | | +| 21 | author-paragraph | `ok`, `archaic`, `obsolete`, `skip`, `ignore`, `unconformable`, `error` | `obsolete` | `AUTHOR`パラグラフを有効にするか決める | | +| 22 | memory-size-clause | `ok`, `archaic`, `obsolete`, `skip`, `ignore`, `unconformable`, `error` | `obsolete` | `OBJECT-COMPUTER`節の`MEMORY SIZE`指定を有効にするか決める | | +| 23 | multiple-file-tape-clause | `ok`, `archaic`, `obsolete`, `skip`, `ignore`, `unconformable`, `error` | `obsolete` | `I-O CONTROL`の`MULTIPLE FILE TAPE`指定を有効にするか決める | | +| 24 | label-records-clause | `ok`, `archaic`, `obsolete`, `skip`, `ignore`, `unconformable`, `error` | `obsolete` | `FILE CONTROL`の`FD`句で`LABEL RECORDS`の指定を有効にするか決める | | +| 25 | value-of-clause | `ok`, `archaic`, `obsolete`, `skip`, `ignore`, `unconformable`, `error` | `obsolete` | `FILE CONTROL`の`FD`句で`VALUE OF {WORD}`を有効にするか決める | | +| 26 | data-records-clause | `ok`, `archaic`, `obsolete`, `skip`, `ignore`, `unconformable`, `error` | `obsolete` | `FILE CONTROL`の`FD`句で`DATA RECORD`を有効にするか決める | | +| 27 | top-level-occurs-clause | `ok`, `archaic`, `obsolete`, `skip`, `ignore`, `unconformable`, `error` | `skip` | 01および77のデータ項目に`OCCURS`を使えるか決める | | +| 28 | synchronized-clause | `ok`, `archaic`, `obsolete`, `skip`, `ignore`, `unconformable`, `error` | `ok` | データ定義において`SYNCHRONIZED`を有効にするか決める | | +| 29 | goto-statement-without-name | `ok`, `archaic`, `obsolete`, `skip`, `ignore`, `unconformable`, `error` | `obsolete` | `GO TO`のあとに何も指定しない書き方を有効にするか決める | | +| 30 | stop-literal-statement | `ok`, `archaic`, `obsolete`, `skip`, `ignore`, `unconformable`, `error` | `obsolete` | `STOP LITERAL`を有効にするかを設定する | 未実装 | +| 31 | debugging-line | `ok`, `archaic`, `obsolete`, `skip`, `ignore`, `unconformable`, `error` | `obsolete` | `CONFIGURATION SECTION`の`SOURCE-COMPUTER`の指定で、`WITH DEBUGGING MODE`の記述を有効にするか決める | | +| 32 | padding-character-clause | `ok`, `archaic`, `obsolete`, `skip`, `ignore`, `unconformable`, `error` | `obsolete` | `SELECT`文で`PADDING CHARACTER`の記述を有効にするか決める | | +| 33 | next-sentence-phrase | `ok`, `archaic`, `obsolete`, `skip`, `ignore`, `unconformable`, `error` | `archaic` | `NEXT SENTENCE`を使えるかを決める | | +| 34 | eject-statement | `ok`, `archaic`, `obsolete`, `skip`, `ignore`, `unconformable`, `error` | `skip` | `EJECT`を使えるか決める | 未実装 | +| 35 | entry-statement | `ok`, `archaic`, `obsolete`, `skip`, `ignore`, `unconformable`, `error` | `obsolete` | `ENTRY`を使えるか決める | 未実装 | +| 36 | move-noninteger-to-alphanumeric | 同上 | `error` | 小数などの非整数を文字列型に`MOVE`できるようにする | 値がokの場合は警告が出て、errorの場合は出なかった | +| 37 | odo-without-to | `ok`, `archaic`, `obsolete`, `skip`, `ignore`, `unconformable`, `error` | `ok` | `OCCURS ~ DEPENDING ON`で`TO`を使って配列のサイズの最大値を定義していないときにエラーを出すようにする | | +| 38 | default-currency-symbol | 任意の1文字 | `$` | デフォルトの通貨記号(`$`、`\`など)を設定できる | | +| 39 | max-alpha-character-data-size | 整数 | 2147483647 | `PIC X`の最大サイズを設定する | | +| 40 | max-sjis-character-data-size | 整数 | 1073741823 | `PIC N`の最大サイズを設定する | | +| 41 | max-utf8-character-data-size | 整数 | 715827882 | `PIC N`の最大サイズを設定する | | +| 42 | c89-identifier-length-check | `yes`, `no` | `no` | `PROGRAM-ID`が31文字より多い場合に警告を出す | 動作が安定しない | +| 43 | allow-end-program-with-wrong-name | `yes`, `no` | `no` | `PROGRAM-ID`に書いてある単語と`END PROGRAM`に書いてある単語が異なるような記述を許容する | | +| 44 | allow-missing-also-clause-in-evaluate | `yes`, `no` | `no` | `EVALUATE`の条件式で`ALSO`が省略する記述を許容する | | +| 45 | allow-empty-imperative-statement | `yes`, `no` | `no` | `IF`や`EVALUATE`で空の無条件文を許容する | | +| 46 | enable-program-status-register | `yes`, `no` | `no` | `PROGRAM-STATUS`という特殊レジスタを使用できるようにする | | +| 47 | enable-sort-status-register | `yes`, `no` | `no` | `SORT-STATUS`という特殊レジスタを使用できるようにする | | +| 48 | enable-special-names-argument-clause | `yes`, `no` | `no` | `SPECIAL-NAMES`で`ARGUMENT-NUMBER`と`ARGUMENT-VALUE`を使えるようにする | | +| 49 | enable-special-names-environment-clause | `yes`, `no` | `no` | `SPECIAL-NAMES`で`ENVIRONMENT-NAME`と`ENVIRONMENT-VALUE`を使えるようにする | | +| 50 | enable-leng-intrinsic-function | `yes`, `no` | `no` | 組み込み関数`FUNCTION LENG`を使えるようにする | | +| 51 | enable-length-an-intrinsic-function | `yes`, `no` | `no` | 組み込み関数`FUNCTION LENGTH-AN`を使えるようにする | | +| 52 | enable-national-intrinsic-function | `yes`, `no` | `no` | 組み込み関数`FUNCTION NATIONAL`を使えるようにする | | +| 53 | use-invalidkey-handler-on-status34 | `yes`, `no` | `no` | SAMファイルの`READ/WRITE`で`INVALID KEY`の指定を可能にする | | +| 54 | cobol68-copy-in-data-description | `yes`, `no` | `no` | `DATA DIVISION`において、COBOL68スタイルの`COPY`を使えるか決める | [参考ページ](https://www.microfocus.com/documentation/visual-cobol/vc50all/DevHub/HRLHLHEXAM06.html) | +| 55 | switch-no-mnemonic | `yes`, `no` | `no` | `SPECIAL-NAMES`で設定するスイッチ名を別名がなくても参照可能にする | | +| 56 | allow-is-in-sort-key-spec | `yes`, `no` | `no` |`SORT`の`KEY`指定で`KEY IS`と書けるようにする | | +| 57 | allow-search-key-in-rhs | `yes`, `no` | `no` | `SEARCH ALL`文の検索条件の右辺にキー項目を記述できるようにする | | +| 58 | ignore-invalid-record-contains | `yes`, `no` | `no` | `FD`句の`RECORD CONTAINS`によるレコードのバイト数の制限を無視することができる | | +| 59 | enable-zero-division-error | `yes`, `no` | `no` | プログラムにゼロ除算があったときにコンパイルの段階でエラーを出す | | +| 60 | enable-check-subscript-out-of-bounds | `yes`, `no` | `no` | `OCCURS ~ DEPENDING ON`で定義した要素数以上の添え字にアクセスするコードがあった場合にコンパイルエラーを出す | | +| 61 | enable-expect-numeric-error | `yes`, `no` | `no` | 文字列型から数値型へのMOVEがあった場合、コンパイルエラーを出す | | +| 62 | enable-expect-compute-string-error | `yes`, `no` | `no` | 文字列と数値を計算しようとしたときにエラーを出す | 動作が安定しない | +| 63 | not-reserved | 任意の文字列 | `CYCLE`, `NORMAL` | 指定した文字列を予約語から一時的に除外する | mvs.confにあるパラメータでdefault.confにはない | \ No newline at end of file diff --git a/doc/converted_Java_file_JP.md b/doc/converted_Java_file_JP.md new file mode 100644 index 00000000..3dddf1c0 --- /dev/null +++ b/doc/converted_Java_file_JP.md @@ -0,0 +1,455 @@ +# opensource COBOL 4J: Java変換解説 + +## はじめに + +opensource COBOL 4Jは、COBOLプログラムをJavaプログラムに変換して実行するコンパイラである。 +本文書ではopensource COBOL 4JのCOBOLからJavaへの変換方法について、重要な箇所を解説する。 + +## 変数・集団項目 + +COBOLで定義された変数は、AbstractCobolFieldクラスのインスタンスへ変換される。 +**PICTURE句に応じて、各変数はAbstractCobolFieldクラスの派生クラスへと変換される。** +例えば、`PIC 9(5)`の変数はCobolNumericFieldクラスのインスタンスへ変換され、`PIC X(3)`の変数はCobolAlphanumericFieldに変換される。 + +また、AbstractCobolFieldは実際のデータをバイト配列として保持するCobolDataStorageクラスと、その他の情報を格納するCobolFieldAttributeクラスを持つ。 + +```mermaid +classDiagram + class AbstractCobolField { + - CobolDataStorage data + - CobolFieldAttribute attr + } +``` + +### CobolDataStorageクラス + +```mermaid +classDiagram + class CobolDataStorage { + - byte[] data + - int index + } +``` + +CobolDataStorageクラスはバイト配列dataと、そのバイト配列内でのデータの格納されている先頭位置を保持するindexを持つ。 + +```cobol + WORKING-STORAGE SECTION. + 01 REC. + 05 FIELD-A PIC X(10). + 05 FIELD-B PIC (5). + 05 FIELD-B PIC X(10). +``` + +上記の変数定義に対して、概ね下記のようなコードを生成することで、集団項目の機能を実現している。 +ただし、下記は説明のためのコードであり、実際に生成されるコードとは異なることに注意すること。 + +```java +byte[] bytes = new byte[25]; +// 集団項目RECに対応するCobolDataStorageクラスのインスタンス。 +// バイト配列dataを保持し、データの開始位置は0 +CobolDataStorage rec_storage = new CobolDataStorage(/* data= */ bytes, /* index= */ 0); +// 集団項目FIELD_Aに対応するCobolDataStorageクラスのインスタンス。 +// バイト配列dataを保持し、データの開始位置は0 +CobolDataStorage field_a_storage = rec_storage.getSubDataStorage(/* data= */ bytes, /* index= */ 0); +// 集団項目FIELD_Bに対応するCobolDataStorageクラスのインスタンス。 +// バイト配列dataを保持し、データの開始位置は10 +CobolDataStorage field_b_storage = rec_storage.getSubDataStorage(/* data= */ bytes, /* index= */ 10); +// 集団項目FIELD_Cに対応するCobolDataStorageクラスのインスタンス。 +// バイト配列dataを保持し、データの開始位置は15 +CobolDataStorage field_b_storage = rec_storage.getSubDataStorage(/* data= */ bytes, /* index= */ 15); +``` + +### CobolFieldAttributeクラス + +CobolFieldAttributeクラスは変数に関する様々な情報を保持するクラスである。 +CobolFieldAttributeクラスのメンバ変数に格納される情報は以下の通りである。 +#### type +typeは文字列型、数値型、集団項目等の情報を表すメンバ変数である。 +typeの保持する値に応じて、決まったAbstractCobolFieldクラスの派生クラスが使用される。 + +| 定数名 | 値 | AbstractCobolFieldの派生クラス | 説明 | +| --- | --- | --- | --- | +| COB_TYPE_UNKNOWN | 0x00 | なし | 未使用 | +| COB_TYPE_GROUP | 0x01 | CobolGroupField | 集団項目 | +| COB_TYPE_BOOLEAN | 0x02 | なし | 未使用 | +| COB_TYPE_NUMERIC_DISPLAY | 0x10 | CobolNumericField | 数値型(`PIC 9`, `PIC 99V9`等) | +| COB_TYPE_NUMERIC_BINARY | 0x11 | CobolNumericBinaryField | バイナリの数値型(`PIC 9 COMP`, `PIC 9 COMP-5`等) | +| COB_TYPE_NUMERIC_PACKED | 0x12 | CobolNumericPackedField | パック10進数(`PIC 9 COMP-3`)| +| COB_TYPE_NUMERIC_FLOAT | 0x13 | なし | COMP-1が指定されていることを示す。COMP-1は未実装。 | +| COB_TYPE_NUMERIC_DOUBLE | 0x14 | なし | COMP-2が指定されていることを示す。COMP-2は未実装。 | +| COB_TYPE_ALPHANUMERIC | 0x21 | CobolAlphanumericField |文字列型(`PIC X`, `PIC X(10)`等) | +| COB_TYPE_ALPHANUMERIC_ALL | 0x22 | CobolAlphanumericAllField | 文字列定数(SPACE等)に割り当てられる。 | +| COB_TYPE_ALPHANUMERIC_EDITED | 0x23 | CobolAlphanumericEditedField | 文字列編集項目 | +| COB_TYPE_NUMERIC_EDITED | 0x24 | CobolNumericEditedField | 数値編集項目 | +| COB_TYPE_NATIONAL | 0x40 | CobolNationalField |日本語型(`PIC N`, `PIC N(10)`等) | +| COB_TYPE_NATIONAL_EDITED | 0x41 | CobolNationalEditedField | 日本語編集項目 | +| COB_TYPE_NATIONAL_ALL | 0x42 | CobolNationalAllField | 日本語項目に代入する文字列定数(SPACE等)に割り当てられる。 | + +#### digits +digitsは`PIC 9(5)`等の数値型の変数のときに使われる、変数の桁数を表すメンバ変数である。 +例えば、`PIC 9(5)`の場合digitsには5が格納され、`PIC 9(3)V9(4)`の場合は7が格納される。 + +#### scale +scaleは小数点の位置を表すためのメンバ変数である。 +例えば`PIC 9(5)`の場合は`0`が格納され、`PIC 9(3)V9(4)`の場合は`4`が格納され、`PIC 9(3)PP`の場合は`-2`が格納される。 + +#### flag +flagはその他の情報を格納するためのメンバ変数である。 +下記の表に示す値をもとに、ビットごとの論理和を計算してflagに値を格納する。 + +例えば、`PIC S9(5) SIGN LEADING SEPARATE`の場合を考える。 +この場合は、下記の表のCOB_FLAG_SIGN, COB_FLAG_SIGN_SEPARATE, COB_FLAG_SIGN_LEADINGの3つの条件に合致するため、flagには0x01 | 0x02 | 0x04 (=0x07)が格納される。 + +| 定数名 | 値 | 説明 | +| --- | --- | --- | +| COB_FLAG_HAVE_SIGN | 0x01 | `PIC S9`等の符号付きの数値型であることを示す。 | +| COB_FLAG_SIGN_SEPARATE | 0x02 | `PIC S9 SIGN TRAILING SEPARATE`または`PIC S9 SIGN LEADING SEPARATE`のように符号の分離が指定されていることを示す。 | +| COB_FLAG_SIGN_LEADING | 0x04 | `PIC S9(2) SIGN LEADING`のように符号が先頭側に格納されることを示す。 | +| COB_FLAG_BLANK_ZERO | 0x08 | `PIC 9 BLANK WHEN ZERO`のようにBLANK WHEN ZERO指定されたことを示す。 | +| COB_FLAG_JUSTIFIED | 0x10 | `PIC X(3) JUSTIFIED RIGHT`のようにJUSTIFIED RIGHTが指定されたことを示す。 | +| COB_FLAG_BINARY_SWAP | 0x20 | COMP,COMP-4,BINARYのいずれかが指定されていることを示す。 | +| COB_FLAG_REAL_BINARY | 0x40 | SIGNED-SHORT,SIGNED-INT,SIGNED-LONG,UNSIGNED-SHORT,UNSIGNED-INT,UNSIGNED-LONGのいずれかが指定されていることを示す。 | +| COB_FLAG_IS_POINTER | 0x80 | POINTERが指定されていることを示す。POINTERは未実装。 | + +#### pic + +picはPICTURE句に書かれた文字列を保持するメンバ変数であるが、コンパイラが実行時に不要と判定した場合はnullが格納される。 + +編集項目の場合は特別なフォーマットのデータが格納される。 +例えば、PICTURE句が`PIC ++9(3),9(2)`の数値編集項目を考える。 +このPICTURE句は+が2文字、9が3文字、,が1文字、9が2文字の合計8文字の文字列であるため、picには +"+<<<2を示す4バイト整数>>>9<<<3を示す4バイト整数>>>,<<<1を示す4バイト整数>>>9<<<2を示す4バイト整数>>>" +が格納される。 + +## PROCEDURE DIVISION + +PROCEDURE DIVISIONの各命令は、その命令に対応するlibcobj.jarに定義されたメソッドの呼び出しに変換される。 +以下に代表的な命令の変換例を示す。 + +### DISPLAY文 + +COBOLのDISPLAY文は、CobolTerminalクラスのdisplayメソッドの呼び出すコードに変換される。 + +```cobol +DISPLAY "HELLO". +``` + +```java +/* a.cbl:6: DISPLAY */ +{ + CobolTerminal.display (0, 1, 1, c_1); +} +``` + +このように各文はブロック`{}`で囲まれ、その上にコメントで元のCOBOLソースコードのファイル名・行番号と、変換されたメソッドの呼び出しを示すコメントが付けられる。 + +### 制御文 +IF文やPERFORM VARYING文は、それぞれJavaのif文やfor文に変換される。 + +以下はIF文の変換例。 +```cobol + IF 1 = 1 THEN + DISPLAY "HELLO" + ELSE + DISPLAY "WORLD" + END-IF. +``` + +```java + /* a.cbl:6: IF */ + { + if (((long)c_1.cmpInt (1) == 0L)) + { + /* a.cbl:7: DISPLAY */ + { + CobolTerminal.display (0, 1, 1, c_2); + } + } + else + { + /* a.cbl:9: DISPLAY */ + { + CobolTerminal.display (0, 1, 1, c_3); + } + } + } +``` + +以下はPERFORM VARYING文の変換例。 + +```cobol + PERFORM VARYING C FROM 1 BY 1 UNTIL C > 5 + DISPLAY C + END-PERFORM. +``` + +```java +for (;;) + { + if (((long)b_C.cmpNumdisp (1, 5) > 0L)) + break; + { + /* a.cbl:8: DISPLAY */ + { + CobolTerminal.display (0, 1, 1, f_C); + } + } + f_C.addInt (1); + } +``` + +### CALL文 + +CALL文も、libcobj.jarに定義されたメソッドの呼び出しに変換される。 + +```cobol + CALL "sub". +``` + +```java +/* a.cbl:6: CALL */ +{ + CobolModule.getCurrentModule ().setParameters (); + call_sub = CobolResolve.resolve("sub", call_sub); + b_RETURN_CODE.set (call_sub.run ()); +} +``` + +opensource COBOL 4Jにおいて、CALL文で指定されたモジュール名は原則として実行時に解決される。 + +## プログラム全体の制御構造 + +COBOLでは、PROCEDURE DIVISION内はSECTIONやPARAGRAPHによって、分割される。 +分割された部分を指定して、PERFORM文で処理を呼び出したり、GO TO文で特定の箇所へジャンプしたりできる。 +これらの機能をJavaへ変換した際に、どのように実現されるかを解説する。 +以下のプログラムを例に、詳細を説明する。 + +```cobol + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + PROCEDURE DIVISION. + MAIN SECTION. + PERFORM A-01. + PERFORM A-02. + PERFORM SUB. + GO TO LAST-PROC. + SUB SECTION. + A-01. + DISPLAY "A-01 START". + DISPLAY "A-01 END". + A-02. + DISPLAY "SECT-02". + LAST-PROC SECTION. + LAST-MESSAGE. + DISPLAY "END". +``` + +opensouce COBOL 4Jでは、SECTION内やPARAGRAPHで分割された処理を切り出し、それらをCobolControlクラスから派生した無名クラスに変換する。 +変換後の無名クラスは、PROCEDURE DIVISION内で記述された順番通りに、CobolControlクラスの配列に格納される。 + +```java +public CobolControl[] contList = { + //... + //... + new CobolControl(l_MAIN_SECTION__DEFAULT_PARAGRAPH, CobolControl.LabelType.label) { + // MAIN SECTIONの処理 + //... + }, + new CobolControl(l_SUB, CobolControl.LabelType.section) { + // SUB SECTIONの処理 + //... + }, + new CobolControl(l_SUB__A_01, CobolControl.LabelType.label) { + // A-01の処理 + //... + }, + new CobolControl(l_SUB__A_01, CobolControl.LabelType.label) { + // A-02の処理 + //... + }, + new CobolControl(l_LAST_PROC, CobolControl.LabelType.section) { + // LAST-PROC SECTIONの処理 + //... + }, + new CobolControl(l_LAST_PROC__LAST_MESSAGE, CobolControl.LabelType.paragraph) { + // LAST-MESSAGEの処理 + //... + } +} + +``` + +例えば、COBOLソースコード中のA-01の処理は以下のように変換される。 + +```java +new CobolControl(l_SUB__A_01, CobolControl.LabelType.label) { + public Optional run() throws CobolRuntimeException, CobolGoBackException, CobolStopRunException { + /* prog.cbl:13: DISPLAY */ + { + CobolTerminal.display (0, 1, 1, c_1); + } + /* prog.cbl:14: DISPLAY */ + { + CobolTerminal.display (0, 1, 1, c_2); + } + + return Optional.of(contList[l_SUB__A_02]); + } +} +``` + +A-02の処理は以下のように変換される。 + +```java +new CobolControl(l_SUB__A_02, CobolControl.LabelType.label) { + public Optional run() throws CobolRuntimeException, CobolGoBackException, CobolStopRunException { + /* prog.cbl:16: DISPLAY */ + { + CobolTerminal.display (0, 1, 1, c_3); + } + + return Optional.of(contList[l_LAST_PROC]); + } +} +``` + +CobolControlクラスは、opensource COBOL 4Jが提供するランタイムであるlibcobj.jarに含まれるクラスである。 +runメソッドに、実際の処理が記述され、その他必要な情報はメンバ変数に格納される。 + +CobolControlの配列contListを使って、PROCEDURE DIVISION内の処理を実行する。 + +opensource COBOL 4Jでは、PERFORM文やGO TO文はCobolControlクラスの機能を利用して呼び出しやジャンプを実現するメソッドを用意している。 +PERFORM文やGO TO文はこれらのメソッドを呼び出すコードへと変換される。 +```java +CobolControl.perform(contList, l_SUB__A_01).run(); + +CobolControl.perform(contList, l_SUB__A_02).run(); + +CobolControl.perform(contList, l_SUB).run(); + +{ + if(true) return Optional.of(contList[l_LAST_PROC ]); + +} +``` + +※ Javaコンパイラは明らかに到達不可能なコードをエラーとして扱う。上記のコードの`if(true)`はこのコンパイルエラーを回避するために生成されている。 + +## libcobj/の解説 +libcobj.jarはopensource COBOL 4Jのランタイムであり、 +`opensourcecobol4j/libcobj/src/jp/osscons/opensourcecobol/libcobj`に格納されているJavaソースコードよりビルドされる。 +これらのソースコードの概要を以下に示す。 + +### callディレクトリ +`opensourcecobol4j/libcobj/src/jp/osscons/opensourcecobol/libcobj/call`に格納されているソースコードについて説明する。 +このディレクトリには、CALL文に関連するクラスが定義される。 + +| ファイル名 | 説明 | +| --- | --- | +| CobolCallDataContent.java | CALL文呼び出しの際に使用されるクラス。 | +| CobolResolve.java | 動的にJavaのクラスをロードする処理が定義されるクラス。 | +| CobolRunnable.java | CALL文で呼び出すJavaクラスが実装すべきインターフェース。 | +| CobolSystemRoutine.java | 一部の組み込み関数を実装するクラス。 | + +### commonディレクトリ +`opensourcecobol4j/libcobj/src/jp/osscons/opensourcecobol/libcobj/common`に格納されているソースコードについて説明する。 +このディレクトリには、その他のクラスが定義される。 + +| ファイル名 | 説明 | +| --- | --- | +| CobolCallParams.java | 未使用のクラス。 | +| CobolCheck.java | 実行時チェックに関する処理を実装するクラス。 | +| CobolConstant.java | 様々な定数を定義するクラス。 | +| CobolControl.java | セクションやラベル等の制御構造を実装するクラス。 | +| CobolExternal.java | EXTERNAL句実装のためのクラス。(実装は未完成) | +| CobolFrame.java | 未使用のクラス。 | +| CobolInspect.java | INSPECT文向けの機能を実装するクラス。 | +| CobolIntrinsic.java | 組み込み関数を定義するクラス。 | +| CobolModule.java | 実行時に様々な情報を保持するクラス。 | +| CobolString.java | STRING文やUNSTRING文に関する処理を定義するクラス。 | +| CobolUtil.java | 雑多な処理を定義するクラス。 | +| GetAbstractCobolField.java | AbstractCobolFieldを返すメソッドrunを実装したインターフェース。 | +| GetInt.java | AbstractCobolFieldを返すメソッドrunを実装したインターフェース。 | + +### dataディレクトリ +`opensourcecobol4j/libcobj/src/jp/osscons/opensourcecobol/libcobj/data`に格納されているソースコードについて説明する。 +このディレクトリには、COBOLプログラムで使用される変数に関するクラスが定義される。 + +| ファイル名 | 説明 | +| --- | --- | +| AbstractCobolField.java | 各COBOL変数のためのクラスの親クラス。 | +| CobolAlphanumericAllField.java | 文字列項目の定数のためのクラス。 | +| CobolAlphanumericEditedField.java | 文字列編集項目のためのクラス。 | +| CobolAlphanumericField.java | 文字列項目のためのクラス。 | +| CobolDataStorage.java | 変数のデータをbyte型データの配列として保持するクラス。 | +| CobolDecimal.java | 数値計算をするために使用するクラス。 | +| CobolFieldAttribute.java | COBOL変数の各種情報を保持するクラス。 | +| CobolFieldFactory.java | 動的にCOBOL変数のインスタンスを生成するためのクラス。 | +| CobolGroupField.java | 集団項目のためのクラス。 | +| CobolNationalAllField.java | 日本語文字列の定数のためのクラス。 | +| CobolNationalEditedField.java | 日本語編集項目のためのクラス。 | +| CobolNationalField.java | 日本語項目のためのクラス。 | +| CobolNumericBinaryField.java | COMP-5等のためのクラス。 | +| CobolNumericDoubleField.java | Javaのdouble型変数のためのクラス。 | +| CobolNumericEditedField.java | 数値編集項目のためのクラス。 | +| CobolNumericField.java | 数値型のためのクラス。 | +| CobolNumericPackedField.java | COMP-3のためのクラス。 | + +### exceptionsディレクトリ +`opensourcecobol4j/libcobj/src/jp/osscons/opensourcecobol/libcobj/exceptions`に格納されているソースコードについて説明する。 +このディレクトリには、COBOLプログラムの実行時に発生する例外を表すクラスが定義される。 + +| ファイル名 | 説明 | +| --- | --- | +| CobolExceptionId.java | 例外IDを定義するクラス。 | +| CobolException.java | 例外を示すクラスの親クラス。 | +| CobolExceptionTabCode.java | 例外コードを管理するクラス。 | +| CobolGoBackException.java | GO BACK実行時に使用する例外のためのクラス。 | +| CobolRuntimeException.java | 実行時エラーに関するクラス。 | +| CobolStopRunException.java | STOP RUN実行時に使用する例外のためのクラス。 | +| CobolUndefinedException.java | 未使用のクラス。 | +| RuntimeErrorHandler.java | 例外発生時のハンドラのためのインターフェース。 | +| RuntimeExitHandler.java | プログラム終了時のハンドラのためのインターフェース。 | + + +### fileディレクトリ +`opensourcecobol4j/libcobj/src/jp/osscons/opensourcecobol/libcobj/file`に格納されているソースコードについて説明する。 +このディレクトリには、COBOLプログラムが扱うファイルに関連するクラスが定義される。 + +| ファイル名 | 説明 | +| --- | --- | +| CobolFileFactory.java | ファイルに関するインスタンスを生成するクラス。 | +| CobolFile.java | ファイルに関する共通処理を実装するクラス。 | +| CobolFileKey.java | ファイルのキーに関する処理を実装するクラス。 | +| CobolFileSort.java | ソート処理を実装するクラス。 | +| CobolIndexedFile.java | INDEXEDファイルを実装するクラス。 | +| CobolItem.java | レコード等の情報を保持するクラス。| +| CobolLineSequentialFile.java | LINCE SEQUENTCIALファイルを実装するクラス。| +| CobolRelativeFile.java | RELATIVEファイルを実装するクラス。 | +| CobolSequentialFile.java | SEQUENCIALやLINCE SEQUENTCIALファイルを実装するクラス。 | +| CobolSort.java | SORTに関する情報を保持するクラス。 | +| FileIO.java | 索引ファイル以外のファイルで入出力に使用するクラス。 | +| FileStruct.java | ファイルに関する情報を保持するクラス。 | +| IndexedCursor.java | 索引ファイルの処理で使用するクラス。 | +| IndexedFile.java | 索引ファイルに関する情報を保持するクラス。 | +| KeyComponent.java | ファイルのキーに関連するクラス。 | +| Linage.java | LINAGEに関するクラス。 | +| MemoryStruct.java | ソート処理で使用するクラス。 | + +### termioディレクトリ +`opensourcecobol4j/libcobj/src/jp/osscons/opensourcecobol/libcobj/termio`に格納されているソースコードについて説明する。 +このディレクトリには、DISPLAY文やACCEPT文に関連するクラスが定義される。 + +| ファイル名 | 説明 | +| --- | --- | +| CobolTerminal.java | DISPLAY文やACCEPT文に関する処理を定義するクラス。 | + +### トップレベルディレクトリ +`opensourcecobol4j/libcobj/src/jp/osscons/opensourcecobol/libcobj/`の直下に格納されているソースコードについて説明する。 + +| ファイル名 | 説明 | +| --- | --- | +| Const.java | libcobj内部で使用する定数を定義するクラス。 | \ No newline at end of file diff --git a/doc/requirements-all.md b/doc/requirements-all.md index d9647262..4bd25f6d 100644 --- a/doc/requirements-all.md +++ b/doc/requirements-all.md @@ -1,5 +1,61 @@ | version (opensource COBOL 4J) | OS | version (JDK) | | -- | -- | -- | +| 1.1.14 | Windows | 21 | +| 1.1.14 | Ubuntu 24.04 | 21 | +| 1.1.14 | AlmaLinux 9 | 11 | +| 1.1.14 | Amazon Linux 2023 | 21 | +| 1.1.13 | Windows | 21 | +| 1.1.13 | Ubuntu 24.04 | 21 | +| 1.1.13 | AlmaLinux 9 | 11 | +| 1.1.13 | Amazon Linux 2023 | 21 | +| 1.1.12 | Windows | 21 | +| 1.1.12 | Ubuntu 24.04 | 21 | +| 1.1.12 | AlmaLinux 9 | 11 | +| 1.1.12 | Amazon Linux 2023 | 21 | +| 1.1.11 | Windows | 21 | +| 1.1.11 | Ubuntu 24.04 | 21 | +| 1.1.11 | AlmaLinux 9 | 11 | +| 1.1.11 | Amazon Linux 2023 | 21 | +| 1.1.10 | Windows | 21 | +| 1.1.10 | Ubuntu 24.04 | 21 | +| 1.1.10 | AlmaLinux 9 | 11 | +| 1.1.10 | Amazon Linux 2023 | 21 | +| 1.1.9 | Windows | 21 | +| 1.1.9 | Ubuntu 24.04 | 21 | +| 1.1.9 | AlmaLinux 9 | 11 | +| 1.1.9 | Amazon Linux 2023 | 21 | +| 1.1.8-hotfix1 | Windows | 21 | +| 1.1.8-hotfix1 | Ubuntu 24.04 | 21 | +| 1.1.8-hotfix1 | AlmaLinux 9 | 11 | +| 1.1.8-hotfix1 | Amazon Linux 2023 | 21 | +| 1.1.8 | Windows | 21 | +| 1.1.8 | Ubuntu 24.04 | 21 | +| 1.1.8 | AlmaLinux 9 | 11 | +| 1.1.8 | Amazon Linux 2023 | 21 | +| 1.1.7-hotfix1 | Windows | 21 | +| 1.1.7-hotfix1 | Ubuntu 24.04 | 21 | +| 1.1.7-hotfix1 | AlmaLinux 9 | 11 | +| 1.1.7-hotfix1 | Amazon Linux 2023 | 21 | +| 1.1.7 | Windows | 21 | +| 1.1.7 | Ubuntu 24.04 | 21 | +| 1.1.7 | AlmaLinux 9 | 11 | +| 1.1.7 | Amazon Linux 2023 | 21 | +| 1.1.6 | Windows | 21 | +| 1.1.6 | Ubuntu 24.04 | 21 | +| 1.1.6 | AlmaLinux 9 | 11 | +| 1.1.6 | Amazon Linux 2023 | 21 | +| 1.1.5 | Windows | 21 | +| 1.1.5 | Ubuntu 24.04 | 21 | +| 1.1.5 | AlmaLinux 9 | 11 | +| 1.1.5 | Amazon Linux 2023 | 21 | +| 1.1.4 | Windows | 21 | +| 1.1.4 | Ubuntu 24.04 | 21 | +| 1.1.4 | AlmaLinux 9 | 11 | +| 1.1.4 | Amazon Linux 2023 | 21 | +| 1.1.3 | Windows | 21 | +| 1.1.3 | Ubuntu 24.04 | 21 | +| 1.1.3 | AlmaLinux 9 | 11 | +| 1.1.3 | Amazon Linux 2023 | 21 | | 1.1.2 | Windows | 21 | | 1.1.2 | Ubuntu 24.04 | 21 | | 1.1.2 | AlmaLinux 9 | 11 | diff --git a/doc/specification-locking-indexed-file.md b/doc/specification-locking-indexed-file.md new file mode 100644 index 00000000..138996ca --- /dev/null +++ b/doc/specification-locking-indexed-file.md @@ -0,0 +1,44 @@ +# INDEXED File Locking Specification + +## LOCK MODE in the SELECT Statement + +- The SELECT statement's LOCK MODE can only specify AUTOMATIC or MANUAL. +- When omitted, the default value for LOCK MODE is MANUAL + - When `-lock-mode-automatic` is specified at compile time, the default value for omitted LOCK MODE becomes AUTOMATIC. + +## Record Locking Behavior + +- When a file is opened with OPEN I-O and a READ statement without WITH NO LOCK or WITH LOCK is executed: + - If the SELECT statement's LOCK MODE is MANUAL, the record is not locked + - If the SELECT statement's LOCK MODE is AUTOMATIC, the record is locked +- When a file is opened with OPEN I-O and a READ statement with WITH LOCK is executed, the record is locked +- When a file is opened with OPEN I-O and a READ statement with WITH NO LOCK is executed, the record is not locked +- When processing fails due to record locking, the file status becomes 51 + +## File Locking Behavior + +- When a file is opened with OPEN OUTPUT, a file lock is applied to the file +- When processing fails due to file locking, the file status becomes 61 + +## Migrating Legacy INDEXED Files to the New Version + +Legacy INDEXED files cannot be used directly with the new version of opensource COBOL 4J. +To convert INDEXED files created with legacy versions to be compatible with the new version, please use the following command: + +```sh +cobj-idx migrate <> +``` + +This command converts the specified INDEXED file to be compatible with the new version. + +## Unlocking INDEXED Files + +The following command can release all file locks and record locks on an INDEXED file: + +```sh +cobj-idx unlock <> +``` + +## Behavior When Opening Legacy INDEXED Files + +When attempting to open legacy INDEXED files, the file status becomes 92. diff --git a/doc/specification-locking-indexed-file_JP.md b/doc/specification-locking-indexed-file_JP.md new file mode 100644 index 00000000..93b851f3 --- /dev/null +++ b/doc/specification-locking-indexed-file_JP.md @@ -0,0 +1,45 @@ + +# INDEXEDファイルのロック仕様 + +## SELECT句のLOCK MODE + +- SELECT句のLOCK MODEにはAUTOMATICかMANUALのみ指定可能である。 +- 省略した場合のLOCK MODEのデフォルト値はMANUAL + - コンパイル時に`-lock-mode-automatic`を指定した場合、LOCK MODEを省略した場合のデフォルト値はAUTOMATICになる。 + +## レコードロックの動作 + +- OPEN I-Oでファイルを開き、WITH NO LOCKもWITH LOCKも指定されないREAD文を実行したとき + - SELECT句のLOCK MODEがMANUALの場合、当該レコードをロックしない + - SELECT句のLOCK MODEがAUTOMATICの場合、当該レコードをロックする +- OPEN I-Oでファイルを開き、WITH LOCK指定のあるREAD文を実行したとき、当該レコードをロックする +- OPEN I-Oでファイルを開き、WITH NO LOCK指定のあるREAD文を実行したとき、当該レコードをロックしない +- レコードロックにより処理が失敗した場合、ファイルステータスが51となる + +## ファイルロックの動作 + +- OPEN OUTPUTで開いたときに、当該ファイルにファイルロックがかかる +- ファイルロックにより処理が失敗した場合、ファイルステータスは61となる + +## 古いバージョンのINDEXEDファイルを新バージョンに対応させる。 + +古いバージョンのINDEXEDファイルは、直接最新バージョンのopensource COBOL 4Jでは使用できません。 +古いバージョンで作成したINDEXEDファイルを新バージョンに対応したものに変換するには、以下のコマンドを実行してください。 + +```sh +cobj-idx migrate <> +``` + +これにより、指定したINDEXEDファイルが新バージョンに対応したものに変換される。 + +## INDEXEDファイルのロックを解除する + +下記のコマンドで、INDEXEDファイルにかかったファイルロックとすべてのレコードロックを解除できる。 + +```sh +cobj-idx unlock <> +``` + +## 古いバージョンのINDEXEDファイルを開いたときの動作 + +古いバージョンのINDEXEDファイルを開こうとした場合、ファイルステータスが92となる。 \ No newline at end of file diff --git a/format b/format index b473f5f7..ba27e3fc 100755 --- a/format +++ b/format @@ -1,3 +1,3 @@ #!/bin/bash -cd libcobj && ./gradlew goJF +cd libcobj && ./gradlew spotlessApply cd ../cobj && ./format diff --git a/image/doc1.png b/image/doc1.png new file mode 100644 index 00000000..31c306b0 Binary files /dev/null and b/image/doc1.png differ diff --git a/image/doc2.png b/image/doc2.png new file mode 100644 index 00000000..1293aeba Binary files /dev/null and b/image/doc2.png differ diff --git a/image/doc3.png b/image/doc3.png new file mode 100644 index 00000000..273c3b45 Binary files /dev/null and b/image/doc3.png differ diff --git a/image/doc4.png b/image/doc4.png new file mode 100644 index 00000000..2f3c2faf Binary files /dev/null and b/image/doc4.png differ diff --git a/image/doc5.png b/image/doc5.png new file mode 100644 index 00000000..e9b1b4d3 Binary files /dev/null and b/image/doc5.png differ diff --git a/image/doc6.png b/image/doc6.png new file mode 100644 index 00000000..57b9c9f0 Binary files /dev/null and b/image/doc6.png differ diff --git a/image/doc7.png b/image/doc7.png new file mode 100644 index 00000000..39ebd124 Binary files /dev/null and b/image/doc7.png differ diff --git a/image/doc8.png b/image/doc8.png new file mode 100644 index 00000000..c007c7be Binary files /dev/null and b/image/doc8.png differ diff --git a/image/doc9.png b/image/doc9.png new file mode 100644 index 00000000..f7513097 Binary files /dev/null and b/image/doc9.png differ diff --git a/lib/Makefile.in b/lib/Makefile.in index 3d417791..668ecf73 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.16.5 from Makefile.am. +# Makefile.in generated by automake 1.16.2 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2021 Free Software Foundation, Inc. +# Copyright (C) 1994-2020 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -194,6 +194,8 @@ am__define_uniq_tagged_files = \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp \ $(top_srcdir)/mkinstalldirs ChangeLog getopt.c getopt.h \ getopt1.c @@ -231,8 +233,6 @@ COB_SHARED_OPT = @COB_SHARED_OPT@ COB_SPLITKEY_FLAGS = @COB_SPLITKEY_FLAGS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ -CSCOPE = @CSCOPE@ -CTAGS = @CTAGS@ CXXCPP = @CXXCPP@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ @@ -244,7 +244,6 @@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ -ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ @@ -498,6 +497,7 @@ cscopelist-am: $(am__tagged_files) distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am diff --git a/libcobj/.gitignore b/libcobj/.gitignore index 6015b00b..5054e8d2 100755 --- a/libcobj/.gitignore +++ b/libcobj/.gitignore @@ -1,7 +1,7 @@ -/bin/ -output/ -sqlite/sqlite.jar -*.class +/bin/ +output/ +sqlite/sqlite.jar +*.class # Ignore Gradle project-specific cache directory .gradle @@ -10,3 +10,4 @@ sqlite/sqlite.jar build app/src/main/java/javadoc.log +app/bin diff --git a/libcobj/Makefile.am b/libcobj/Makefile.am index 8096f0f5..9e2d467b 100644 --- a/libcobj/Makefile.am +++ b/libcobj/Makefile.am @@ -69,6 +69,7 @@ SRC_FILES = \ ./app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolResultString.java \ ./app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolResultDouble.java \ ./app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/IndexedFileUtilMain.java \ + ./app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/CobolFileKeyInfo.java \ ./app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/ErrorLib.java \ ./app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/LoadResult.java \ ./app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/UserDataFormat.java \ diff --git a/libcobj/Makefile.in b/libcobj/Makefile.in index 04530252..f38cb6ac 100644 --- a/libcobj/Makefile.in +++ b/libcobj/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.16.5 from Makefile.am. +# Makefile.in generated by automake 1.16.2 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2021 Free Software Foundation, Inc. +# Copyright (C) 1994-2020 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -152,8 +152,6 @@ COB_SHARED_OPT = @COB_SHARED_OPT@ COB_SPLITKEY_FLAGS = @COB_SPLITKEY_FLAGS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ -CSCOPE = @CSCOPE@ -CTAGS = @CTAGS@ CXXCPP = @CXXCPP@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ @@ -165,7 +163,6 @@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ -ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ @@ -349,6 +346,7 @@ SRC_FILES = \ ./app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolResultString.java \ ./app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolResultDouble.java \ ./app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/IndexedFileUtilMain.java \ + ./app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/CobolFileKeyInfo.java \ ./app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/ErrorLib.java \ ./app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/LoadResult.java \ ./app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/UserDataFormat.java \ @@ -407,6 +405,7 @@ ctags CTAGS: cscope cscopelist: + distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am diff --git a/libcobj/app/build.gradle.kts b/libcobj/app/build.gradle.kts index d317d07f..b57f5f3a 100644 --- a/libcobj/app/build.gradle.kts +++ b/libcobj/app/build.gradle.kts @@ -3,11 +3,11 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar plugins { application id("com.github.johnrengelman.shadow") version "8.1.1" + id("com.diffplug.spotless") version "7.2.1" id("java") - id("com.github.sherter.google-java-format") version "0.9" id("maven-publish") pmd - id("com.github.spotbugs") version "6.0.19" + id("com.github.spotbugs") version "6.4.5" } repositories { @@ -31,16 +31,16 @@ tasks { } dependencies { - implementation("com.google.guava:guava:33.2.1-jre") - implementation("org.xerial:sqlite-jdbc:3.46.0.0") - implementation("commons-cli:commons-cli:1.8.0") - testImplementation("org.junit.jupiter:junit-jupiter:5.10.3") + implementation("com.google.guava:guava:33.5.0-jre") + implementation("org.xerial:sqlite-jdbc:3.51.0.0") + implementation("commons-cli:commons-cli:1.10.0") + testImplementation("org.junit.jupiter:junit-jupiter:5.13.4") testRuntimeOnly("org.junit.platform:junit-platform-launcher") - implementation("org.json:json:20240303") + implementation("org.json:json:20250517") spotbugs("com.github.spotbugs:spotbugs:4.8.6") - implementation("org.slf4j:slf4j-api:2.0.13") - implementation("org.slf4j:slf4j-simple:2.0.13") + implementation("org.slf4j:slf4j-api:2.0.17") + implementation("org.slf4j:slf4j-simple:2.0.17") } java { @@ -59,6 +59,12 @@ spotbugs { excludeFilter.set(project.file("${rootDir}/config/spotbugsFilter.xml")) } +spotless { + java { + googleJavaFormat("1.17.0").aosp().reflowLongStrings().skipJavadocFormatting() + } +} + publishing { repositories { maven { @@ -74,7 +80,7 @@ publishing { register("gpr") { groupId = "jp.osscons.opensourcecobol" artifactId = "libcobj" - version = "1.1.2" + version = "1.1.14" from(components["java"]) } } diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/Const.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/Const.java index b308ad9e..2fbeb377 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/Const.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/Const.java @@ -1,27 +1,27 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ - -package jp.osscons.opensourcecobol.libcobj; - -/** TODO: 準備中 */ -public class Const { - - /** TODO: 準備中 */ - public static final String version = "1.1.2"; -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ + +package jp.osscons.opensourcecobol.libcobj; + +/** TODO: 準備中 */ +public class Const { + + /** TODO: 準備中 */ + public static final String version = "1.1.14"; +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/call/CobolResolve.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/call/CobolResolve.java index 0e0e82b9..e0930bf0 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/call/CobolResolve.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/call/CobolResolve.java @@ -34,477 +34,479 @@ /** 動的にクラスファイルを読み込んでCALL文のような機能を実装するためのクラス */ public class CobolResolve { - /** プログラム名とCobolRunnableインスタンスの対応表 */ - private static Map callTable; - - /** 例外コードと例外名の対応を表現する */ - public static Map cobException; - - /** 名前の変換方法(小文字か大文字)を示す変数 */ - private static int name_convert; - - // TODO resolve_pathsの利用方法 - /** システムで設定された区切り文字で区切られた0個以上のパス 動的に読み込むクラスファイルを検索する場所を示す. */ - private static List resolve_paths; - - /** システムで設定された区切り文字で区切られた0個以上のパス 動的に読み込むクラスファイルを検索するパッケージ名を示す. */ - private static List package_paths; - - static { - callTable = new HashMap<>(); - name_convert = 0; - resolve_paths = new ArrayList(); - package_paths = new ArrayList(); - cobException = new HashMap<>(); - - cobException.put(0xFFFF, "EC-ALL"); - cobException.put(0x0100, "EC-ARGUMENT"); - cobException.put(0x0101, "EC-ARGUMENT-FUNCTION"); - cobException.put(0x0102, "EC-ARGUMENT-IMP"); - cobException.put(0x0200, "EC-BOUND"); - cobException.put(0x0201, "EC-BOUND-IMP"); - cobException.put(0x0202, "EC-BOUND-ODO"); - cobException.put(0x0203, "EC-BOUND-OVERFLOW"); - cobException.put(0x0204, "EC-BOUND-PTR"); - cobException.put(0x0205, "EC-BOUND-REF-MOD"); - cobException.put(0x0206, "EC-BOUND-SET"); - cobException.put(0x0207, "EC-BOUND-SUBSCRIPT"); - cobException.put(0x0208, "EC-BOUND-TABLE-LIMIT"); - cobException.put(0x0300, "EC-DATA"); - cobException.put(0x0301, "EC-DATA-CONVERSION"); - cobException.put(0x0302, "EC-DATA-IMP"); - cobException.put(0x0303, "EC-DATA-INCOMPATIBLE"); - cobException.put(0x0304, "EC-DATA-INTEGRITY"); - cobException.put(0x0305, "EC-DATA-PTR-NULL"); - cobException.put(0x0306, "EC-DATA-INFINITY"); - cobException.put(0x0307, "EC-DATA-NEGATIVE-INFINITY"); - cobException.put(0x0308, "EC-DATA-NOT_A_NUMBER"); - cobException.put(0x0400, "EC-FLOW"); - cobException.put(0x0401, "EC-FLOW-GLOBAL-EXIT"); - cobException.put(0x0402, "EC-FLOW-GLOBAL-GOBACK"); - cobException.put(0x0403, "EC-FLOW-IMP"); - cobException.put(0x0404, "EC-FLOW-RELEASE"); - cobException.put(0x0405, "EC-FLOW-REPORT"); - cobException.put(0x0406, "EC-FLOW-RETURN"); - cobException.put(0x0407, "EC-FLOW-SEARCH"); - cobException.put(0x0408, "EC-FLOW-USE"); - cobException.put(0x0500, "EC-I-O"); - cobException.put(0x0501, "EC-I-O-AT-END"); - cobException.put(0x0502, "EC-I-O-EOP"); - cobException.put(0x0503, "EC-I-O-EOP-OVERFLOW"); - cobException.put(0x0504, "EC-I-O-FILE-SHARING"); - cobException.put(0x0505, "EC-I-O-IMP"); - cobException.put(0x0506, "EC-I-O-INVALID-KEY"); - cobException.put(0x0507, "EC-I-O-LINAGE"); - cobException.put(0x0508, "EC-I-O-LOGIC-ERROR"); - cobException.put(0x0509, "EC-I-O-PERMANENT-ERROR"); - cobException.put(0x050A, "EC-I-O-RECORD-OPERATION"); - cobException.put(0x0600, "EC-IMP"); - cobException.put(0x0601, "EC-IMP-ACCEPT"); - cobException.put(0x0602, "EC-IMP-DISPLAY"); - cobException.put(0x0700, "EC-LOCALE"); - cobException.put(0x0701, "EC-LOCALE-IMP"); - cobException.put(0x0702, "EC-LOCALE-INCOMPATIBLE"); - cobException.put(0x0703, "EC-LOCALE-INVALID"); - cobException.put(0x0704, "EC-LOCALE-INVALID-PTR"); - cobException.put(0x0705, "EC-LOCALE-MISSING"); - cobException.put(0x0706, "EC-LOCALE-SIZE"); - cobException.put(0x0800, "EC-OO"); - cobException.put(0x0801, "EC-OO-CONFORMANCE"); - cobException.put(0x0802, "EC-OO-EXCEPTION"); - cobException.put(0x0803, "EC-OO-IMP"); - cobException.put(0x0804, "EC-OO-METHOD"); - cobException.put(0x0805, "EC-OO-NULL"); - cobException.put(0x0806, "EC-OO-RESOURCE"); - cobException.put(0x0807, "EC-OO-UNIVERSAL"); - cobException.put(0x0900, "EC-ORDER"); - cobException.put(0x0901, "EC-ORDER-IMP"); - cobException.put(0x0902, "EC-ORDER-NOT-SUPPORTED"); - cobException.put(0x0A00, "EC-OVERFLOW"); - cobException.put(0x0A01, "EC-OVERFLOW-IMP"); - cobException.put(0x0A02, "EC-OVERFLOW-STRING"); - cobException.put(0x0A03, "EC-OVERFLOW-UNSTRING"); - cobException.put(0x0B00, "EC-PROGRAM"); - cobException.put(0x0B01, "EC-PROGRAM-ARG-MISMATCH"); - cobException.put(0x0B02, "EC-PROGRAM-ARG-OMITTED"); - cobException.put(0x0B03, "EC-PROGRAM-CANCEL-ACTIVE"); - cobException.put(0x0B04, "EC-PROGRAM-IMP"); - cobException.put(0x0B05, "EC-PROGRAM-NOT-FOUND"); - cobException.put(0x0B06, "EC-PROGRAM-PTR-NULL"); - cobException.put(0x0B07, "EC-PROGRAM-RECURSIVE-CALL"); - cobException.put(0x0B08, "EC-PROGRAM-RESOURCES"); - cobException.put(0x0C00, "EC-RAISING"); - cobException.put(0x0C01, "EC-RAISING-IMP"); - cobException.put(0x0C02, "EC-RAISING-NOT-SPECIFIED"); - cobException.put(0x0D00, "EC-RANGE"); - cobException.put(0x0D01, "EC-RANGE-IMP"); - cobException.put(0x0D02, "EC-RANGE-INDEX"); - cobException.put(0x0D03, "EC-RANGE-INSPECT-SIZE"); - cobException.put(0x0D04, "EC-RANGE-INVALID"); - cobException.put(0x0D05, "EC-RANGE-PERFORM-VARYING"); - cobException.put(0x0D06, "EC-RANGE-PTR"); - cobException.put(0x0D07, "EC-RANGE-SEARCH-INDEX"); - cobException.put(0x0D08, "EC-RANGE-SEARCH-NO-MATCH"); - cobException.put(0x0E00, "EC-REPORT"); - cobException.put(0x0E01, "EC-REPORT-ACTIVE"); - cobException.put(0x0E02, "EC-REPORT-COLUMN-OVERLAP"); - cobException.put(0x0E03, "EC-REPORT-FILE-MODE"); - cobException.put(0x0E04, "EC-REPORT-IMP"); - cobException.put(0x0E05, "EC-REPORT-INACTIVE"); - cobException.put(0x0E06, "EC-REPORT-LINE-OVERLAP"); - cobException.put(0x0E08, "EC-REPORT-NOT-TERMINATED"); - cobException.put(0x0E09, "EC-REPORT-PAGE-LIMIT"); - cobException.put(0x0E0A, "EC-REPORT-PAGE-WIDTH"); - cobException.put(0x0E0B, "EC-REPORT-SUM-SIZE"); - cobException.put(0x0E0C, "EC-REPORT-VARYING"); - cobException.put(0x0F00, "EC-SCREEN"); - cobException.put(0x0F01, "EC-SCREEN-FIELD-OVERLAP"); - cobException.put(0x0F02, "EC-SCREEN-IMP"); - cobException.put(0x0F03, "EC-SCREEN-ITEM-TRUNCATED"); - cobException.put(0x0F04, "EC-SCREEN-LINE-NUMBER"); - cobException.put(0x0F05, "EC-SCREEN-STARTING-COLUMN"); - cobException.put(0x1000, "EC-SIZE"); - cobException.put(0x1001, "EC-SIZE-ADDRESS"); - cobException.put(0x1002, "EC-SIZE-EXPONENTIATION"); - cobException.put(0x1003, "EC-SIZE-IMP"); - cobException.put(0x1004, "EC-SIZE-OVERFLOW"); - cobException.put(0x1005, "EC-SIZE-TRUNCATION"); - cobException.put(0x1006, "EC-SIZE-UNDERFLOW"); - cobException.put(0x1007, "EC-SIZE-ZERO-DIVIDE"); - cobException.put(0x1100, "EC-SORT-MERGE"); - cobException.put(0x1101, "EC-SORT-MERGE-ACTIVE"); - cobException.put(0x1102, "EC-SORT-MERGE-FILE-OPEN"); - cobException.put(0x1103, "EC-SORT-MERGE-IMP"); - cobException.put(0x1104, "EC-SORT-MERGE-RELEASE"); - cobException.put(0x1105, "EC-SORT-MERGE-RETURN"); - cobException.put(0x1106, "EC-SORT-MERGE-SEQUENCE"); - cobException.put(0x1200, "EC-STORAGE"); - cobException.put(0x1201, "EC-STORAGE-IMP"); - cobException.put(0x1202, "EC-STORAGE-NOT-ALLOC"); - cobException.put(0x1203, "EC-STORAGE-NOT-AVAIL"); - cobException.put(0x1300, "EC-USER"); - cobException.put(0x1400, "EC-VALIDATE"); - cobException.put(0x1401, "EC-VALIDATE-CONTENT"); - cobException.put(0x1402, "EC-VALIDATE-FORMAT"); - cobException.put(0x1403, "EC-VALIDATE-IMP"); - cobException.put(0x1404, "EC-VALIDATE-RELATION"); - cobException.put(0x1405, "EC-VALIDATE-VARYING"); - cobException.put(0x1500, "EC-FUNCTION"); - cobException.put(0x1501, "EC-FUNCTION-NOT-FOUND"); - cobException.put(0x1502, "EC-FUNCTION-PTR-INVALID"); - cobException.put(0x1503, "EC-FUNCTION-PTR-NULL"); - cobException.put(0x1600, "EC-XML"); - cobException.put(0x1601, "EC-XML-CODESET"); - cobException.put(0x1602, "EC-XML-CODESET-CONVERSION"); - cobException.put(0x1603, "EC-XML-COUNT"); - cobException.put(0x1604, "EC-XML-DOCUMENT-TYPE"); - cobException.put(0x1605, "EC-XML-IMPLICIT-CLOSE"); - cobException.put(0x1606, "EC-XML-INVALID"); - cobException.put(0x1607, "EC-XML-NAMESPACE"); - cobException.put(0x1608, "EC-XML-STACKED-OPEN"); - cobException.put(0x1609, "EC-XML-RANGE"); - } - - /** - * 下記の環境変数を読み込み、CobolResolve内で定義されたメソッドの動作が変わる。
- * 環境変数COB_LOAD_CASEにLOWERが指定されているときは、resolveメソッドに渡された引数を小文字に変換してから処理を開始する。
- * 環境変数COB_LOAD_CASEにUPPERが指定されているときは、resolveメソッドに渡された引数を大文字に変換してから処理を開始する。
- * 環境変数COB_LIBRARY_PATHにディレクトリパスが指定されている場合、 resolveメソッドが検索するモジュールのディレクトリパスのリストにそれを追加する。
- * 環境変数COB_PACKAGE_PATHにディレクトリパスが指定されている場合、 resolveメソッドが検索するモジュールのパッケージパスのリストにそれを追加する。 - * 環境変数COB_PRE_LOADは未実装 - */ - public static void cobolInitCall() { - - String s; - String buf; - - // //用途不明 - // call_filename_buff = cob_malloc (CALL_FILEBUFF_SIZE); - // call_entry_buff = cob_malloc (COB_SMALL_BUFF); - // call_entry2_buff = cob_malloc (COB_SMALL_BUFF); - - s = CobolUtil.getEnv("COB_LOAD_CASE"); - if (s != null) { - String sU = s.toUpperCase(); - if ("LOWER".equals(sU)) { - name_convert = 1; - } else if ("UPPER".equals(sU)) { - name_convert = 2; - } + /** プログラム名とCobolRunnableインスタンスの対応表 */ + private static Map callTable; + + /** 例外コードと例外名の対応を表現する */ + public static Map cobException; + + /** 名前の変換方法(小文字か大文字)を示す変数 */ + private static int name_convert; + + // TODO resolve_pathsの利用方法 + /** システムで設定された区切り文字で区切られた0個以上のパス 動的に読み込むクラスファイルを検索する場所を示す. */ + private static List resolve_paths; + + /** システムで設定された区切り文字で区切られた0個以上のパス 動的に読み込むクラスファイルを検索するパッケージ名を示す. */ + private static List package_paths; + + static { + callTable = new HashMap<>(); + name_convert = 0; + resolve_paths = new ArrayList(); + package_paths = new ArrayList(); + cobException = new HashMap<>(); + + cobException.put(0xFFFF, "EC-ALL"); + cobException.put(0x0100, "EC-ARGUMENT"); + cobException.put(0x0101, "EC-ARGUMENT-FUNCTION"); + cobException.put(0x0102, "EC-ARGUMENT-IMP"); + cobException.put(0x0200, "EC-BOUND"); + cobException.put(0x0201, "EC-BOUND-IMP"); + cobException.put(0x0202, "EC-BOUND-ODO"); + cobException.put(0x0203, "EC-BOUND-OVERFLOW"); + cobException.put(0x0204, "EC-BOUND-PTR"); + cobException.put(0x0205, "EC-BOUND-REF-MOD"); + cobException.put(0x0206, "EC-BOUND-SET"); + cobException.put(0x0207, "EC-BOUND-SUBSCRIPT"); + cobException.put(0x0208, "EC-BOUND-TABLE-LIMIT"); + cobException.put(0x0300, "EC-DATA"); + cobException.put(0x0301, "EC-DATA-CONVERSION"); + cobException.put(0x0302, "EC-DATA-IMP"); + cobException.put(0x0303, "EC-DATA-INCOMPATIBLE"); + cobException.put(0x0304, "EC-DATA-INTEGRITY"); + cobException.put(0x0305, "EC-DATA-PTR-NULL"); + cobException.put(0x0306, "EC-DATA-INFINITY"); + cobException.put(0x0307, "EC-DATA-NEGATIVE-INFINITY"); + cobException.put(0x0308, "EC-DATA-NOT_A_NUMBER"); + cobException.put(0x0400, "EC-FLOW"); + cobException.put(0x0401, "EC-FLOW-GLOBAL-EXIT"); + cobException.put(0x0402, "EC-FLOW-GLOBAL-GOBACK"); + cobException.put(0x0403, "EC-FLOW-IMP"); + cobException.put(0x0404, "EC-FLOW-RELEASE"); + cobException.put(0x0405, "EC-FLOW-REPORT"); + cobException.put(0x0406, "EC-FLOW-RETURN"); + cobException.put(0x0407, "EC-FLOW-SEARCH"); + cobException.put(0x0408, "EC-FLOW-USE"); + cobException.put(0x0500, "EC-I-O"); + cobException.put(0x0501, "EC-I-O-AT-END"); + cobException.put(0x0502, "EC-I-O-EOP"); + cobException.put(0x0503, "EC-I-O-EOP-OVERFLOW"); + cobException.put(0x0504, "EC-I-O-FILE-SHARING"); + cobException.put(0x0505, "EC-I-O-IMP"); + cobException.put(0x0506, "EC-I-O-INVALID-KEY"); + cobException.put(0x0507, "EC-I-O-LINAGE"); + cobException.put(0x0508, "EC-I-O-LOGIC-ERROR"); + cobException.put(0x0509, "EC-I-O-PERMANENT-ERROR"); + cobException.put(0x050A, "EC-I-O-RECORD-OPERATION"); + cobException.put(0x0600, "EC-IMP"); + cobException.put(0x0601, "EC-IMP-ACCEPT"); + cobException.put(0x0602, "EC-IMP-DISPLAY"); + cobException.put(0x0700, "EC-LOCALE"); + cobException.put(0x0701, "EC-LOCALE-IMP"); + cobException.put(0x0702, "EC-LOCALE-INCOMPATIBLE"); + cobException.put(0x0703, "EC-LOCALE-INVALID"); + cobException.put(0x0704, "EC-LOCALE-INVALID-PTR"); + cobException.put(0x0705, "EC-LOCALE-MISSING"); + cobException.put(0x0706, "EC-LOCALE-SIZE"); + cobException.put(0x0800, "EC-OO"); + cobException.put(0x0801, "EC-OO-CONFORMANCE"); + cobException.put(0x0802, "EC-OO-EXCEPTION"); + cobException.put(0x0803, "EC-OO-IMP"); + cobException.put(0x0804, "EC-OO-METHOD"); + cobException.put(0x0805, "EC-OO-NULL"); + cobException.put(0x0806, "EC-OO-RESOURCE"); + cobException.put(0x0807, "EC-OO-UNIVERSAL"); + cobException.put(0x0900, "EC-ORDER"); + cobException.put(0x0901, "EC-ORDER-IMP"); + cobException.put(0x0902, "EC-ORDER-NOT-SUPPORTED"); + cobException.put(0x0A00, "EC-OVERFLOW"); + cobException.put(0x0A01, "EC-OVERFLOW-IMP"); + cobException.put(0x0A02, "EC-OVERFLOW-STRING"); + cobException.put(0x0A03, "EC-OVERFLOW-UNSTRING"); + cobException.put(0x0B00, "EC-PROGRAM"); + cobException.put(0x0B01, "EC-PROGRAM-ARG-MISMATCH"); + cobException.put(0x0B02, "EC-PROGRAM-ARG-OMITTED"); + cobException.put(0x0B03, "EC-PROGRAM-CANCEL-ACTIVE"); + cobException.put(0x0B04, "EC-PROGRAM-IMP"); + cobException.put(0x0B05, "EC-PROGRAM-NOT-FOUND"); + cobException.put(0x0B06, "EC-PROGRAM-PTR-NULL"); + cobException.put(0x0B07, "EC-PROGRAM-RECURSIVE-CALL"); + cobException.put(0x0B08, "EC-PROGRAM-RESOURCES"); + cobException.put(0x0C00, "EC-RAISING"); + cobException.put(0x0C01, "EC-RAISING-IMP"); + cobException.put(0x0C02, "EC-RAISING-NOT-SPECIFIED"); + cobException.put(0x0D00, "EC-RANGE"); + cobException.put(0x0D01, "EC-RANGE-IMP"); + cobException.put(0x0D02, "EC-RANGE-INDEX"); + cobException.put(0x0D03, "EC-RANGE-INSPECT-SIZE"); + cobException.put(0x0D04, "EC-RANGE-INVALID"); + cobException.put(0x0D05, "EC-RANGE-PERFORM-VARYING"); + cobException.put(0x0D06, "EC-RANGE-PTR"); + cobException.put(0x0D07, "EC-RANGE-SEARCH-INDEX"); + cobException.put(0x0D08, "EC-RANGE-SEARCH-NO-MATCH"); + cobException.put(0x0E00, "EC-REPORT"); + cobException.put(0x0E01, "EC-REPORT-ACTIVE"); + cobException.put(0x0E02, "EC-REPORT-COLUMN-OVERLAP"); + cobException.put(0x0E03, "EC-REPORT-FILE-MODE"); + cobException.put(0x0E04, "EC-REPORT-IMP"); + cobException.put(0x0E05, "EC-REPORT-INACTIVE"); + cobException.put(0x0E06, "EC-REPORT-LINE-OVERLAP"); + cobException.put(0x0E08, "EC-REPORT-NOT-TERMINATED"); + cobException.put(0x0E09, "EC-REPORT-PAGE-LIMIT"); + cobException.put(0x0E0A, "EC-REPORT-PAGE-WIDTH"); + cobException.put(0x0E0B, "EC-REPORT-SUM-SIZE"); + cobException.put(0x0E0C, "EC-REPORT-VARYING"); + cobException.put(0x0F00, "EC-SCREEN"); + cobException.put(0x0F01, "EC-SCREEN-FIELD-OVERLAP"); + cobException.put(0x0F02, "EC-SCREEN-IMP"); + cobException.put(0x0F03, "EC-SCREEN-ITEM-TRUNCATED"); + cobException.put(0x0F04, "EC-SCREEN-LINE-NUMBER"); + cobException.put(0x0F05, "EC-SCREEN-STARTING-COLUMN"); + cobException.put(0x1000, "EC-SIZE"); + cobException.put(0x1001, "EC-SIZE-ADDRESS"); + cobException.put(0x1002, "EC-SIZE-EXPONENTIATION"); + cobException.put(0x1003, "EC-SIZE-IMP"); + cobException.put(0x1004, "EC-SIZE-OVERFLOW"); + cobException.put(0x1005, "EC-SIZE-TRUNCATION"); + cobException.put(0x1006, "EC-SIZE-UNDERFLOW"); + cobException.put(0x1007, "EC-SIZE-ZERO-DIVIDE"); + cobException.put(0x1100, "EC-SORT-MERGE"); + cobException.put(0x1101, "EC-SORT-MERGE-ACTIVE"); + cobException.put(0x1102, "EC-SORT-MERGE-FILE-OPEN"); + cobException.put(0x1103, "EC-SORT-MERGE-IMP"); + cobException.put(0x1104, "EC-SORT-MERGE-RELEASE"); + cobException.put(0x1105, "EC-SORT-MERGE-RETURN"); + cobException.put(0x1106, "EC-SORT-MERGE-SEQUENCE"); + cobException.put(0x1200, "EC-STORAGE"); + cobException.put(0x1201, "EC-STORAGE-IMP"); + cobException.put(0x1202, "EC-STORAGE-NOT-ALLOC"); + cobException.put(0x1203, "EC-STORAGE-NOT-AVAIL"); + cobException.put(0x1300, "EC-USER"); + cobException.put(0x1400, "EC-VALIDATE"); + cobException.put(0x1401, "EC-VALIDATE-CONTENT"); + cobException.put(0x1402, "EC-VALIDATE-FORMAT"); + cobException.put(0x1403, "EC-VALIDATE-IMP"); + cobException.put(0x1404, "EC-VALIDATE-RELATION"); + cobException.put(0x1405, "EC-VALIDATE-VARYING"); + cobException.put(0x1500, "EC-FUNCTION"); + cobException.put(0x1501, "EC-FUNCTION-NOT-FOUND"); + cobException.put(0x1502, "EC-FUNCTION-PTR-INVALID"); + cobException.put(0x1503, "EC-FUNCTION-PTR-NULL"); + cobException.put(0x1600, "EC-XML"); + cobException.put(0x1601, "EC-XML-CODESET"); + cobException.put(0x1602, "EC-XML-CODESET-CONVERSION"); + cobException.put(0x1603, "EC-XML-COUNT"); + cobException.put(0x1604, "EC-XML-DOCUMENT-TYPE"); + cobException.put(0x1605, "EC-XML-IMPLICIT-CLOSE"); + cobException.put(0x1606, "EC-XML-INVALID"); + cobException.put(0x1607, "EC-XML-NAMESPACE"); + cobException.put(0x1608, "EC-XML-STACKED-OPEN"); + cobException.put(0x1609, "EC-XML-RANGE"); } - s = CobolUtil.getEnv("COB_LIBRARY_PATH"); - if (s == null || s.equals("")) { - buf = "." + System.getProperty("path.separator") + CobolConstant.COB_LIBRARY_PATH; - } else { - buf = - s - + System.getProperty("path.separator") - + "." - + System.getProperty("path.separator") - + CobolConstant.COB_LIBRARY_PATH; + /** + * 下記の環境変数を読み込み、CobolResolve内で定義されたメソッドの動作が変わる。
+ * 環境変数COB_LOAD_CASEにLOWERが指定されているときは、resolveメソッドに渡された引数を小文字に変換してから処理を開始する。
+ * 環境変数COB_LOAD_CASEにUPPERが指定されているときは、resolveメソッドに渡された引数を大文字に変換してから処理を開始する。
+ * 環境変数COB_LIBRARY_PATHにディレクトリパスが指定されている場合、 resolveメソッドが検索するモジュールのディレクトリパスのリストにそれを追加する。
+ * 環境変数COB_PACKAGE_PATHにディレクトリパスが指定されている場合、 resolveメソッドが検索するモジュールのパッケージパスのリストにそれを追加する。 + * 環境変数COB_PRE_LOADは未実装 + */ + public static void cobolInitCall() { + + String s; + String buf; + + // //用途不明 + // call_filename_buff = cob_malloc (CALL_FILEBUFF_SIZE); + // call_entry_buff = cob_malloc (COB_SMALL_BUFF); + // call_entry2_buff = cob_malloc (COB_SMALL_BUFF); + + s = CobolUtil.getEnv("COB_LOAD_CASE"); + if (s != null) { + String sU = s.toUpperCase(); + if ("LOWER".equals(sU)) { + name_convert = 1; + } else if ("UPPER".equals(sU)) { + name_convert = 2; + } + } + + s = CobolUtil.getEnv("COB_LIBRARY_PATH"); + if (s == null || s.equals("")) { + buf = "." + System.getProperty("path.separator") + CobolConstant.COB_LIBRARY_PATH; + } else { + buf = + s + + System.getProperty("path.separator") + + "." + + System.getProperty("path.separator") + + CobolConstant.COB_LIBRARY_PATH; + } + setLibraryPath(buf); + + s = CobolUtil.getEnv("COB_PACKAGE_PATH"); + setPackagePath(s); + + // TODO プリロードの扱いを検討する + s = CobolUtil.getEnv("COB_PRE_LOAD"); + + // 用途不明 + // call_buffer = cob_malloc (CALL_BUFF_SIZE); + // call_lastsize = CALL_BUFF_SIZE; + // for (psyst = (struct system_table *)&system_tab[0]; psyst->syst_name; + // ++psyst) { + // insert (psyst->syst_name, psyst->syst_call, NULL); + // } } - setLibraryPath(buf); - - s = CobolUtil.getEnv("COB_PACKAGE_PATH"); - setPackagePath(s); - - // TODO プリロードの扱いを検討する - s = CobolUtil.getEnv("COB_PRE_LOAD"); - - // 用途不明 - // call_buffer = cob_malloc (CALL_BUFF_SIZE); - // call_lastsize = CALL_BUFF_SIZE; - // for (psyst = (struct system_table *)&system_tab[0]; psyst->syst_name; - // ++psyst) { - // insert (psyst->syst_name, psyst->syst_call, NULL); - // } - } - - /** - * ライブラリパスを更新する - * - * @param path 区切り文字で区切られた0個以上のパスを示す文字列 - */ - private static void setLibraryPath(String path) { - if (!resolve_paths.isEmpty()) { - resolve_paths.clear(); - } - - String[] paths = path.split(System.getProperty("path.separator")); - for (String path1 : paths) { - if (path1.length() > 0) { - resolve_paths.add(path1); - } - } - } - - /** - * パッケージへパスを更新する - * - * @param path 区切り文字で区切られた0個以上のパスを示す文字列 - */ - private static void setPackagePath(String path) { - if (!package_paths.isEmpty()) { - package_paths.clear(); + /** + * ライブラリパスを更新する + * + * @param path 区切り文字で区切られた0個以上のパスを示す文字列 + */ + private static void setLibraryPath(String path) { + if (!resolve_paths.isEmpty()) { + resolve_paths.clear(); + } + + String[] paths = path.split(System.getProperty("path.separator")); + + for (String path1 : paths) { + if (path1.length() > 0) { + resolve_paths.add(path1); + } + } } - String[] paths = path.split(System.getProperty("path.separator")); - - for (String path1 : paths) { - if (path1.length() > 0) { - package_paths.add(path1); - } - } - } - - /** - * パッケージ名とクラス名から、クラスを動的に読み込む。 このメソッドは以下のように、環境変数の設定値によって動作が変わる。
- * 環境変数COB_LOAD_CASEにLOWERが指定されているときは、cobolFieldの示す文字列全体を小文字に変換したものを検索する。
- * 環境変数COB_LOAD_CASEにUPPERが指定されているときは、cobolFieldの示す文字列全体を小文字に変換したものを検索する。
- * 環境変数COB_LIBRARY_PATHにディレクトリパスが指定されている場合、 このメソッドが検索するモジュールのディレクトリパスのリストにそれを追加する。
- * 環境変数COB_PACKAGE_PATHにディレクトリパスが指定されている場合、 このメソッドが検索するモジュールのパッケージパスのリストにそれを追加する。 - * - * @param packageName 検索するクラスのパッケージ名 - * @param cobolField 読み込むクラスの名前を格納するCOBOL変数 - * @param runner CobolRunnableを実装したクラス。nullでもよい。 - * @return runnerがnullでない場合はrunnerを返し、そうでないときはクラス名とパッケージ名を元に検索処理を実施する。 - * 検索して動的にクラスの読み込みに成功したら、それを返す。検索に失敗したら nullを返す。 - * @throws CobolRuntimeException TODO: 準備中 - */ - public static CobolRunnable resolve( - String packageName, AbstractCobolField cobolField, CobolRunnable runner) - throws CobolRuntimeException { - if (runner == null) { - return resolve(packageName, cobolField.fieldToString()); - } else { - return runner; + /** + * パッケージへパスを更新する + * + * @param path 区切り文字で区切られた0個以上のパスを示す文字列 + */ + private static void setPackagePath(String path) { + if (!package_paths.isEmpty()) { + package_paths.clear(); + } + + String[] paths = path.split(System.getProperty("path.separator")); + + for (String path1 : paths) { + if (path1.length() > 0) { + package_paths.add(path1); + } + } } - } - - /** - * パッケージ名とクラス名から、クラスを動的に読み込む。 このメソッドは以下のように、環境変数の設定値によって動作が変わる。
- * 環境変数COB_LOAD_CASEにLOWERが指定されているときは、nameの示す文字列全体を小文字に変換したものを検索する。
- * 環境変数COB_LOAD_CASEにUPPERが指定されているときは、nameの示す文字列全体を小文字に変換したものを検索する。
- * 環境変数COB_LIBRARY_PATHにディレクトリパスが指定されている場合、 このメソッドが検索するモジュールのディレクトリパスのリストにそれを追加する。
- * 環境変数COB_PACKAGE_PATHにディレクトリパスが指定されている場合、 このメソッドが検索するモジュールのパッケージパスのリストにそれを追加する。 - * - * @param packageName 検索するクラスのパッケージ名 - * @param name 読み込むクラスの名前 - * @param runner CobolRunnableを実装したクラス。nullでもよい。 - * @return runnerがnullでない場合はrunnerを返し、そうでないときはクラス名とパッケージ名を元に検索処理を実施する。 - * 検索して動的にクラスの読み込みに成功したら、それを返す。検索に失敗したら nullを返す。 - * @throws CobolRuntimeException TODO: 準備中 - */ - public static CobolRunnable resolve(String packageName, String name, CobolRunnable runner) - throws CobolRuntimeException { - if (runner == null) { - return resolve(packageName, name); - } else { - return runner; - } - } - - /** - * パッケージ名とクラス名から、クラスを動的に読み込む。 このメソッドは以下のように、環境変数の設定値によって動作が変わる。
- * 環境変数COB_LOAD_CASEにLOWERが指定されているときは、cobolFieldの示す文字列全体を小文字に変換したものを検索する。
- * 環境変数COB_LOAD_CASEにUPPERが指定されているときは、cobolFieldの示す文字列全体を小文字に変換したものを検索する。
- * 環境変数COB_LIBRARY_PATHにディレクトリパスが指定されている場合、 このメソッドが検索するモジュールのディレクトリパスのリストにそれを追加する。
- * 環境変数COB_PACKAGE_PATHにディレクトリパスが指定されている場合、 このメソッドが検索するモジュールのパッケージパスのリストにそれを追加する。 - * - * @param packageName パッケージ名 - * @param cobolField 読み込むクラスの名前 - * @return クラス名とパッケージ名を元に検索処理を実施する。 検索して動的にクラスの読み込みに成功したら、それを返す。検索に失敗したら nullを返す。 - * @throws CobolRuntimeException TODO: 準備中 - */ - public static CobolRunnable resolve(String packageName, AbstractCobolField cobolField) - throws CobolRuntimeException { - return resolve(packageName, cobolField.fieldToString()); - } - - /** - * パッケージ名とクラス名から、クラスを動的に読み込む。 このメソッドは以下のように、環境変数の設定値によって動作が変わる。
- * 環境変数COB_LOAD_CASEにLOWERが指定されているときは、nameの示す文字列全体を小文字に変換したものを検索する。
- * 環境変数COB_LOAD_CASEにUPPERが指定されているときは、nameの示す文字列全体を小文字に変換したものを検索する。
- * 環境変数COB_LIBRARY_PATHにディレクトリパスが指定されている場合、 このメソッドが検索するモジュールのディレクトリパスのリストにそれを追加する。
- * 環境変数COB_PACKAGE_PATHにディレクトリパスが指定されている場合、 このメソッドが検索するモジュールのパッケージパスのリストにそれを追加する。 - * - * @param packageName パッケージ名 - * @param name 読み込むクラスの名前 - * @return クラス名とパッケージ名を元に検索処理を実施する。 検索して動的にクラスの読み込みに成功したら、それを返す。検索に失敗したら nullを返す。 - * @throws CobolRuntimeException TODO: 準備中 - */ - public static CobolRunnable resolve(String packageName, String name) - throws CobolRuntimeException { - String fullName; - CobolRunnable runnable = null; - - /* encode program name */ - char c1 = name.charAt(0); - if (c1 >= '0' && c1 <= '9') { - name = "_" + name; - } - name = name.replaceAll("-", "__"); - /* search the cache */ - if (callTable.containsKey(name)) { - return callTable.get(name); + /** + * パッケージ名とクラス名から、クラスを動的に読み込む。 このメソッドは以下のように、環境変数の設定値によって動作が変わる。
+ * 環境変数COB_LOAD_CASEにLOWERが指定されているときは、cobolFieldの示す文字列全体を小文字に変換したものを検索する。
+ * 環境変数COB_LOAD_CASEにUPPERが指定されているときは、cobolFieldの示す文字列全体を小文字に変換したものを検索する。
+ * 環境変数COB_LIBRARY_PATHにディレクトリパスが指定されている場合、 このメソッドが検索するモジュールのディレクトリパスのリストにそれを追加する。
+ * 環境変数COB_PACKAGE_PATHにディレクトリパスが指定されている場合、 このメソッドが検索するモジュールのパッケージパスのリストにそれを追加する。 + * + * @param packageName 検索するクラスのパッケージ名 + * @param cobolField 読み込むクラスの名前を格納するCOBOL変数 + * @param runner CobolRunnableを実装したクラス。nullでもよい。 + * @return runnerがnullでない場合はrunnerを返し、そうでないときはクラス名とパッケージ名を元に検索処理を実施する。 + * 検索して動的にクラスの読み込みに成功したら、それを返す。検索に失敗したら nullを返す。 + * @throws CobolRuntimeException TODO: 準備中 + */ + public static CobolRunnable resolve( + String packageName, AbstractCobolField cobolField, CobolRunnable runner) + throws CobolRuntimeException { + if (runner == null) { + return resolve(packageName, cobolField.fieldToString()); + } else { + return runner; + } } - if (name_convert == 1) { - name = name.toLowerCase(); - } else if (name_convert == 2) { - name = name.toUpperCase(); + /** + * パッケージ名とクラス名から、クラスを動的に読み込む。 このメソッドは以下のように、環境変数の設定値によって動作が変わる。
+ * 環境変数COB_LOAD_CASEにLOWERが指定されているときは、nameの示す文字列全体を小文字に変換したものを検索する。
+ * 環境変数COB_LOAD_CASEにUPPERが指定されているときは、nameの示す文字列全体を小文字に変換したものを検索する。
+ * 環境変数COB_LIBRARY_PATHにディレクトリパスが指定されている場合、 このメソッドが検索するモジュールのディレクトリパスのリストにそれを追加する。
+ * 環境変数COB_PACKAGE_PATHにディレクトリパスが指定されている場合、 このメソッドが検索するモジュールのパッケージパスのリストにそれを追加する。 + * + * @param packageName 検索するクラスのパッケージ名 + * @param name 読み込むクラスの名前 + * @param runner CobolRunnableを実装したクラス。nullでもよい。 + * @return runnerがnullでない場合はrunnerを返し、そうでないときはクラス名とパッケージ名を元に検索処理を実施する。 + * 検索して動的にクラスの読み込みに成功したら、それを返す。検索に失敗したら nullを返す。 + * @throws CobolRuntimeException TODO: 準備中 + */ + public static CobolRunnable resolve(String packageName, String name, CobolRunnable runner) + throws CobolRuntimeException { + if (runner == null) { + return resolve(packageName, name); + } else { + return runner; + } } - if (packageName != null) { - fullName = packageName + "." + name; - } else { - fullName = name; + /** + * パッケージ名とクラス名から、クラスを動的に読み込む。 このメソッドは以下のように、環境変数の設定値によって動作が変わる。
+ * 環境変数COB_LOAD_CASEにLOWERが指定されているときは、cobolFieldの示す文字列全体を小文字に変換したものを検索する。
+ * 環境変数COB_LOAD_CASEにUPPERが指定されているときは、cobolFieldの示す文字列全体を小文字に変換したものを検索する。
+ * 環境変数COB_LIBRARY_PATHにディレクトリパスが指定されている場合、 このメソッドが検索するモジュールのディレクトリパスのリストにそれを追加する。
+ * 環境変数COB_PACKAGE_PATHにディレクトリパスが指定されている場合、 このメソッドが検索するモジュールのパッケージパスのリストにそれを追加する。 + * + * @param packageName パッケージ名 + * @param cobolField 読み込むクラスの名前 + * @return クラス名とパッケージ名を元に検索処理を実施する。 検索して動的にクラスの読み込みに成功したら、それを返す。検索に失敗したら nullを返す。 + * @throws CobolRuntimeException TODO: 準備中 + */ + public static CobolRunnable resolve(String packageName, AbstractCobolField cobolField) + throws CobolRuntimeException { + return resolve(packageName, cobolField.fieldToString()); } - /* search the main program */ - runnable = getInstance(fullName); - if (runnable != null) { - callTable.put(name, runnable); - return runnable; + /** + * パッケージ名とクラス名から、クラスを動的に読み込む。 このメソッドは以下のように、環境変数の設定値によって動作が変わる。
+ * 環境変数COB_LOAD_CASEにLOWERが指定されているときは、nameの示す文字列全体を小文字に変換したものを検索する。
+ * 環境変数COB_LOAD_CASEにUPPERが指定されているときは、nameの示す文字列全体を小文字に変換したものを検索する。
+ * 環境変数COB_LIBRARY_PATHにディレクトリパスが指定されている場合、 このメソッドが検索するモジュールのディレクトリパスのリストにそれを追加する。
+ * 環境変数COB_PACKAGE_PATHにディレクトリパスが指定されている場合、 このメソッドが検索するモジュールのパッケージパスのリストにそれを追加する。 + * + * @param packageName パッケージ名 + * @param name 読み込むクラスの名前 + * @return クラス名とパッケージ名を元に検索処理を実施する。 検索して動的にクラスの読み込みに成功したら、それを返す。検索に失敗したら nullを返す。 + * @throws CobolRuntimeException TODO: 準備中 + */ + public static CobolRunnable resolve(String packageName, String name) + throws CobolRuntimeException { + String fullName; + CobolRunnable runnable = null; + + /* encode program name */ + char c1 = name.charAt(0); + if (c1 >= '0' && c1 <= '9') { + name = "_" + name; + } + name = name.replaceAll("-", "__"); + + /* search the cache */ + if (callTable.containsKey(name)) { + return callTable.get(name); + } + + if (name_convert == 1) { + name = name.toLowerCase(); + } else if (name_convert == 2) { + name = name.toUpperCase(); + } + + if (packageName != null) { + fullName = packageName + "." + name; + } else { + fullName = name; + } + + /* search the main program */ + runnable = getInstance(fullName); + if (runnable != null) { + callTable.put(name, runnable); + return runnable; + } + + /* search external modules */ + for (String packagePath : package_paths) { + fullName = packagePath + "." + name; + runnable = getInstance(fullName); + if (runnable != null) { + callTable.put(name, runnable); + return runnable; + } + } + + // Not found + String msg = "Program not found: " + name; + throw new CobolRuntimeException(CobolExceptionId.COB_EC_PROGRAM_NOT_FOUND, msg); } - /* search external modules */ - for (String packagePath : package_paths) { - fullName = packagePath + "." + name; - runnable = getInstance(fullName); - if (runnable != null) { - callTable.put(name, runnable); - return runnable; - } + /** + * リフレクション機能を用いて動的にクラスファイルを読み込んでCobolRunnableのインスタンスを生成する + * + * @param name 読み込むクラスファイルのパス + * @return 読み込みに失敗したときはnull,其れ以外は読み込んだCobolRunnbableのインスタンス + */ + private static CobolRunnable getInstance(String name) { + CobolRunnable runnable = null; + + try { + Class c = Class.forName(name); + Constructor cons = c.getConstructor(); + runnable = (CobolRunnable) cons.newInstance(); + runnable = (CobolRunnable) c.getDeclaredConstructor().newInstance(); + callTable.put(name, runnable); + return runnable; + } catch (NoSuchMethodException + | SecurityException + | InstantiationException + | IllegalAccessException + | IllegalArgumentException + | InvocationTargetException + | ClassNotFoundException e) { + // TODO 自動生成された catch ブロック + return null; + } } - // Not found - String msg = "Program not found: " + name; - throw new CobolRuntimeException(CobolExceptionId.COB_EC_PROGRAM_NOT_FOUND, msg); - } - - /** - * リフレクション機能を用いて動的にクラスファイルを読み込んでCobolRunnableのインスタンスを生成する - * - * @param name 読み込むクラスファイルのパス - * @return 読み込みに失敗したときはnull,其れ以外は読み込んだCobolRunnbableのインスタンス - */ - private static CobolRunnable getInstance(String name) { - CobolRunnable runnable = null; - - try { - Class c = Class.forName(name); - Constructor cons = c.getConstructor(); - runnable = (CobolRunnable) cons.newInstance(); - runnable = (CobolRunnable) c.getDeclaredConstructor().newInstance(); - callTable.put(name, runnable); - return runnable; - } catch (NoSuchMethodException - | SecurityException - | InstantiationException - | IllegalAccessException - | IllegalArgumentException - | InvocationTargetException - | ClassNotFoundException e) { - // TODO 自動生成された catch ブロック - return null; - } - } - - /** - * 引数で与えられたプログラム名に対応するCobolRunnableのインスタンスの cancelメソッドを呼び出す - * - * @param cobolField プログラム名を示すCOBOL変数 - */ - public static void cancel(AbstractCobolField cobolField) { - cancel(cobolField.getString()); - } - - /** - * 引数で与えられたプログラム名に対応するCobolRunnableのインスタンスの cancelメソッドを呼び出す - * - * @param name プログラム名 - */ - public static void cancel(String name) { - if (name == null) { - throw new CobolRuntimeException( - CobolRuntimeException.COBOL_FATAL_ERROR, "NULL name parameter passed to 'cobcancel'"); + /** + * 引数で与えられたプログラム名に対応するCobolRunnableのインスタンスの cancelメソッドを呼び出す + * + * @param cobolField プログラム名を示すCOBOL変数 + */ + public static void cancel(AbstractCobolField cobolField) { + cancel(cobolField.getString()); } - CobolRunnable runnable = callTable.get(name); - if (runnable.isActive() == false) { - runnable.cancel(); + /** + * 引数で与えられたプログラム名に対応するCobolRunnableのインスタンスの cancelメソッドを呼び出す + * + * @param name プログラム名 + */ + public static void cancel(String name) { + if (name == null) { + throw new CobolRuntimeException( + CobolRuntimeException.COBOL_FATAL_ERROR, + "NULL name parameter passed to 'cobcancel'"); + } + + CobolRunnable runnable = callTable.get(name); + if (runnable.isActive() == false) { + runnable.cancel(); + } } - } - - /** - * 指定のプログラムのcancelメソッドを呼び出す - * - * @param f cancelを呼び出すプログラム名を示すCOBOL変数 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void fieldCancel(AbstractCobolField f) throws CobolStopRunException { - CobolResolve.cobCancel(f.fieldToString()); - } - /** - * 指定のプログラムのcancelメソッドを呼び出す - * - * @param name プログラム名 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void cobCancel(String name) throws CobolStopRunException { - if (name == null || name.equals("")) { - // TODO cob_runtime_errorの実装 - CobolStopRunException.stopRunAndThrow(1); + + /** + * 指定のプログラムのcancelメソッドを呼び出す + * + * @param f cancelを呼び出すプログラム名を示すCOBOL変数 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void fieldCancel(AbstractCobolField f) throws CobolStopRunException { + CobolResolve.cobCancel(f.fieldToString()); } - name = name.replaceAll("-", "__"); - CobolRunnable runner = callTable.get(name); - if (runner != null) { - runner.cancel(); + /** + * 指定のプログラムのcancelメソッドを呼び出す + * + * @param name プログラム名 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void cobCancel(String name) throws CobolStopRunException { + if (name == null || name.equals("")) { + // TODO cob_runtime_errorの実装 + CobolStopRunException.stopRunAndThrow(1); + } + + name = name.replaceAll("-", "__"); + CobolRunnable runner = callTable.get(name); + if (runner != null) { + runner.cancel(); + } } - } } diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/call/CobolRunnable.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/call/CobolRunnable.java index fae4de3d..a29809e5 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/call/CobolRunnable.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/call/CobolRunnable.java @@ -22,21 +22,21 @@ /** COBOLプログラムの実行単位が実装すべきインターフェース */ public interface CobolRunnable { - /** - * COBOLプログラムを実行する - * - * @param storages プログラムの入力データの可変長引数。CALL等の引数のデータ部分 - * @return プログラムの終了コード - */ - int run(CobolDataStorage... storages); + /** + * COBOLプログラムを実行する + * + * @param storages プログラムの入力データの可変長引数。CALL等の引数のデータ部分 + * @return プログラムの終了コード + */ + int run(CobolDataStorage... storages); - /** CANCELのためのメソッド */ - void cancel(); + /** CANCELのためのメソッド */ + void cancel(); - /** - * 取り扱いについては準備中 - * - * @return 準備中 - */ - boolean isActive(); + /** + * 取り扱いについては準備中 + * + * @return 準備中 + */ + boolean isActive(); } diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/call/CobolSystemRoutine.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/call/CobolSystemRoutine.java index f4935947..4e0865a2 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/call/CobolSystemRoutine.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/call/CobolSystemRoutine.java @@ -1,907 +1,949 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.call; - -import java.io.IOException; -import java.lang.ProcessBuilder.Redirect; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; -import jp.osscons.opensourcecobol.libcobj.common.CobolModule; -import jp.osscons.opensourcecobol.libcobj.common.CobolUtil; -import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; -import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; - -/** 組み込み関数を提供するクラス */ -public class CobolSystemRoutine { - private static final boolean runsOnWindows = "\\".equals(System.getProperty("file.separator")); - - /** - * 組み込み関数CBL_EXIT_PROCの実装。未実装。 - * - * @param x 未実装 - * @param pptr 未実装 - * @return 未実装 - */ - public static int CBL_EXIT_PROC(CobolDataStorage x, CobolDataStorage pptr) { - // TODO 実装 - return 0; - } - - /** - * 組み込み関数CBL_ERROR_PROCの実装。未実装。 - * - * @param x 未実装 - * @param pptr 未実装 - * @return 未実装 - */ - public static int CBL_ERROR_PROC(CobolDataStorage x, CobolDataStorage pptr) { - // TODO 実装 - return 0; - } - - /** - * 組み込み関数SYSTEMの実装。cmdに指定されたコマンドを実行する。 - * - * @param cmd コマンド文字列。Linux/Unix環境であればシェルコマンド、Windows環境であればコマンドプロンプトのコマンド。 - * @return コマンドの終了コード。 - * @throws CobolStopRunException TODO: 準備中 - * このメソッドは内部でCobolModule.getCurrentModule().cob_procedure_parametersを参照する。 - * このリストの形式に問題がある場合にスローされる。 - */ - public static int SYSTEM(CobolDataStorage cmd) throws CobolStopRunException { - int size = SYSTEM_getParameterSize(); - String cmdStr = new String(cmd.getByteArray(0, size)); - return SYSTEM_main(cmdStr); - } - - /** - * 組み込み関数SYSTEMの実装。cmdに指定されたコマンドを実行する。 - * - * @param cmd コマンド文字列。Linux/Unix環境であればシェルコマンド、Windows環境であればコマンドプロンプトのコマンド。 - * @return コマンドの終了コード。 - */ - public static int SYSTEM(String cmd) { - return SYSTEM_main(cmd); - } - - private static int SYSTEM_getParameterSize() throws CobolStopRunException { - CobolUtil.COB_CHK_PARMS("SYSTEM", 1); - List paramaters = CobolModule.getCurrentModule().cob_procedure_parameters; - if (!paramaters.isEmpty() && paramaters.get(0) != null) { - AbstractCobolField paramater = paramaters.get(0); - int size = paramater.getSize(); - if (size <= 0) { - CobolUtil.runtimeError("The size of the paramater to SYSTEM call is less than 1"); - CobolStopRunException.stopRunAndThrow(1); - } - return size; - } else { - CobolUtil.runtimeError("The size of the paramater is not specified"); - CobolStopRunException.stopRunAndThrow(1); - // not reached - return -1; - } - } - - private static int SYSTEM_main(String cmd) { - ProcessBuilder pb; - if (runsOnWindows) { - pb = new ProcessBuilder("cmd", "/c", cmd); - } else { - pb = new ProcessBuilder("sh", "-c", cmd); - } - pb.redirectInput(Redirect.INHERIT) - .redirectOutput(Redirect.INHERIT) - .redirectError(Redirect.INHERIT); - try { - Process process = pb.start(); - return process.waitFor(); - } catch (InterruptedException | IOException e) { - e.printStackTrace(); - return 1; - } - } - - /** - * 組み込み関数SYSTEMの実装。cmdに指定されたコマンドを実行する。 - * - * @param cmd コマンド文字列。Linux/Unix環境であればシェルコマンド、Windows環境であればコマンドプロンプトのコマンド。 - * @return コマンドの終了コード。 - */ - public static int SYSTEM(AbstractCobolField cmd) { - return SYSTEM(cmd.getString()); - } - - private interface Calculater { - byte calc(byte b1, byte b2); - } - - private static int CBL_COMMON_OPERATION( - String funcName, CobolDataStorage data1, CobolDataStorage data2, int length, Calculater c) { - CobolUtil.COB_CHK_PARMS(funcName, 3); - if (length <= 0) { - return 0; - } - for (int n = 0; n < length; ++n) { - byte b1 = data1.getByte(n); - byte b2 = data2.getByte(n); - data2.setByte(n, c.calc(b1, b2)); - } - return 0; - } - - /** - * 組み込み関数CBL_ANDの実装。1バイトごとに論理積を取る。 先頭lengthバイトのデータについて論理積を計算し、計算結果を2番目の引数の先頭に格納する。 - * - * @param data1 計算対象の1番目のCOBOL変数のバイト列。 - * @param data2 計算対象の2番目のCOBOL変数のバイト列。先頭lengthバイトに計算結果が格納される。 - * @param length 計算するバイト数。 - * @return 0 - */ - public static int CBL_AND(CobolDataStorage data1, CobolDataStorage data2, int length) { - return CBL_COMMON_OPERATION( - "CBL_AND", - data1, - data2, - length, - new Calculater() { - @Override - public byte calc(byte b1, byte b2) { - return (byte) (b1 & b2); - } - }); - } - /** - * 組み込み関数CBL_ANDの実装。1バイトごとに論理積を取る。 先頭lengthバイトのデータについて論理積を計算し、計算結果を2番目の引数の先頭に格納する。 - * - * @param data1 計算対象の1番目のCOBOL変数。 - * @param data2 計算対象の2番目の引数のバイト列。先頭lengthバイトに計算結果が格納される。 - * @param length 計算するバイト数。 - * @return 0 - */ - public static int CBL_AND(AbstractCobolField data1, CobolDataStorage data2, int length) { - return CBL_AND(data1.getDataStorage(), data2, length); - } - /** - * 組み込み関数CBL_ANDの実装。1バイトごとに論理積を取る。 先頭lengthバイトのデータについて論理積を計算し、計算結果を2番目の引数の先頭に格納する。 - * - * @param data1 計算対象の1番目のCOBOL変数のバイト列。 - * @param data2 計算対象の2番目のCOBOL変数のバイト列。その変数のバイト列の先頭lengthバイトに計算結果が格納される。 - * @param length 計算するバイト数。 - * @return 0 - */ - public static int CBL_AND(CobolDataStorage data1, AbstractCobolField data2, int length) { - return CBL_AND(data1, data2.getDataStorage(), length); - } - /** - * 組み込み関数CBL_ANDの実装。1バイトごとに論理積を取る。 先頭lengthバイトのデータについて論理積を計算し、計算結果を2番目の引数の先頭に格納する。 - * - * @param data1 計算対象の1番目のCOBOL変数。 - * @param data2 計算対象の2番目のCOBOL変数。その変数のバイト列の先頭lengthバイトに計算結果が格納される。 - * @param length 計算するバイト数。 - * @return 0 - */ - public static int CBL_AND(AbstractCobolField data1, AbstractCobolField data2, int length) { - return CBL_AND(data1.getDataStorage(), data2.getDataStorage(), length); - } - - /** - * 組み込み関数CBL_ORの実装。1バイトごとに論理和を取る。 先頭lengthバイトのデータについて論理和を計算し、計算結果を2番目の引数の先頭に格納する。 - * - * @param data1 計算対象の1番目のCOBOL変数のバイト列。 - * @param data2 計算対象の2番目のCOBOL変数のバイト列。先頭lengthバイトに計算結果が格納される。 - * @param length 計算するバイト数 - * @return 0 - */ - public static int CBL_OR(CobolDataStorage data1, CobolDataStorage data2, int length) { - return CBL_COMMON_OPERATION( - "CBL_OR", - data1, - data2, - length, - new Calculater() { - @Override - public byte calc(byte b1, byte b2) { - return (byte) (b1 | b2); - } - }); - } - - /** - * 組み込み関数CBL_ORの実装。1バイトごとに論理和を取る。 先頭lengthバイトのデータについて論理和を計算し、計算結果を2番目の引数の先頭に格納する。 - * - * @param data1 計算対象の1番目のCOBOL変数のバイト列。 - * @param data2 計算対象の2番目のCOBOL変数。そのバイト列の先頭lengthバイトに計算結果が格納される。 - * @param length 計算するバイト数 - * @return 0 - */ - public static int CBL_OR(AbstractCobolField data1, CobolDataStorage data2, int length) { - return CBL_OR(data1.getDataStorage(), data2, length); - } - - /** - * 組み込み関数CBL_ORの実装。1バイトごとに論理和を取る。 先頭lengthバイトのデータについて論理和を計算し、計算結果を2番目の引数の先頭に格納する。 - * - * @param data1 計算対象の1番目のCOBOL変数のバイト列。 - * @param data2 計算対象の2番目のCOBOL変数。先頭lengthバイトに計算結果が格納される。 - * @param length 計算するバイト数 - * @return 0 - */ - public static int CBL_OR(CobolDataStorage data1, AbstractCobolField data2, int length) { - return CBL_OR(data1, data2.getDataStorage(), length); - } - - /** - * 組み込み関数CBL_ORの実装。詳しい説明はTODO: 準備中 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_OR(AbstractCobolField data1, AbstractCobolField data2, int length) { - return CBL_OR(data1.getDataStorage(), data2.getDataStorage(), length); - } - - private static int byte2Int(byte x) { - return x & 0xFF; - } - - private static byte int2Byte(int x) { - return (byte) (x & 0xFF); - } - - /** - * 組み込み関数CBL_NORの実装。1バイトごとに排他的論理和を取る。 先頭lengthバイトのデータについて論理否定を計算し、計算結果を2番目の引数の先頭に格納する。 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_NOR(CobolDataStorage data1, CobolDataStorage data2, int length) { - return CBL_COMMON_OPERATION( - "CBL_NOR", - data1, - data2, - length, - new Calculater() { - @Override - public byte calc(byte b1, byte b2) { - return int2Byte(~(byte2Int(b1) | int2Byte(b2))); - } - }); - } - - /** - * TODO: 準備中 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_NOR(AbstractCobolField data1, CobolDataStorage data2, int length) { - return CBL_NOR(data1.getDataStorage(), data2, length); - } - - /** - * TODO: 準備中 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_NOR(CobolDataStorage data1, AbstractCobolField data2, int length) { - return CBL_NOR(data1, data2.getDataStorage(), length); - } - - /** - * TODO: 準備中 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_NOR(AbstractCobolField data1, AbstractCobolField data2, int length) { - return CBL_NOR(data1.getDataStorage(), data2.getDataStorage(), length); - } - - /** - * 組み込み関数CBL_XORの実装。1バイトごとに排他的論理和を取る。 先頭lengthバイトのデータについて排他的論理和を計算し、計算結果を2番目の引数の先頭に格納する。 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_XOR(CobolDataStorage data1, CobolDataStorage data2, int length) { - return CBL_COMMON_OPERATION( - "CBL_XOR", - data1, - data2, - length, - new Calculater() { - @Override - public byte calc(byte b1, byte b2) { - return (byte) (b1 ^ b2); - } - }); - } - - /** - * 組み込み関数CBL_XORの実装。詳しい説明はTODO: 準備中 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_XOR(AbstractCobolField data1, CobolDataStorage data2, int length) { - return CBL_XOR(data1.getDataStorage(), data2, length); - } - - /** - * 組み込み関数CBL_XORの実装。詳しい説明はTODO: 準備中 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_XOR(CobolDataStorage data1, AbstractCobolField data2, int length) { - return CBL_XOR(data1, data2.getDataStorage(), length); - } - - /** - * 組み込み関数CBL_XORの実装。詳しい説明はTODO: 準備中 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_XOR(AbstractCobolField data1, AbstractCobolField data2, int length) { - return CBL_XOR(data1.getDataStorage(), data2.getDataStorage(), length); - } - - /** - * 組み込み関数CBL_NIMPの実装。詳しい説明はTODO: 準備中 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_NIMP(CobolDataStorage data1, CobolDataStorage data2, int length) { - return CBL_COMMON_OPERATION( - "CBL_NIMP", - data1, - data2, - length, - new Calculater() { - @Override - public byte calc(byte b1, byte b2) { - return (byte) (b1 & (~b2)); - } - }); - } - - /** - * 組み込み関数CBL_NIMPの実装。詳しい説明はTODO: 準備中 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_NIMP(AbstractCobolField data1, CobolDataStorage data2, int length) { - return CBL_NIMP(data1.getDataStorage(), data2, length); - } - - /** - * TODO: 準備中 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_NIMP(CobolDataStorage data1, AbstractCobolField data2, int length) { - return CBL_NIMP(data1, data2.getDataStorage(), length); - } - - /** - * TODO: 準備中 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_NIMP(AbstractCobolField data1, AbstractCobolField data2, int length) { - return CBL_NIMP(data1.getDataStorage(), data2.getDataStorage(), length); - } - - /** - * TODO: 準備中 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_EQ(CobolDataStorage data1, CobolDataStorage data2, int length) { - return CBL_COMMON_OPERATION( - "CBL_EQ", - data1, - data2, - length, - new Calculater() { - @Override - public byte calc(byte b1, byte b2) { - return (byte) ~(b1 ^ b2); - } - }); - } - - /** - * TODO: 準備中 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_EQ(AbstractCobolField data1, CobolDataStorage data2, int length) { - return CBL_EQ(data1.getDataStorage(), data2, length); - } - - /** - * TODO: 準備中 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_EQ(CobolDataStorage data1, AbstractCobolField data2, int length) { - return CBL_EQ(data1, data2.getDataStorage(), length); - } - - /** - * TODO: 準備中 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_EQ(AbstractCobolField data1, AbstractCobolField data2, int length) { - return CBL_EQ(data1.getDataStorage(), data2.getDataStorage(), length); - } - - /** - * 組み込み関数CBL_NOTの実装。詳しい説明はTODO: 準備中 - * - * @param data TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_NOT(CobolDataStorage data, int length) { - CobolUtil.COB_CHK_PARMS("CBL_NOT", 2); - if (length <= 0) { - return 0; - } - for (int n = 0; n < length; ++n) { - byte b = data.getByte(n); - data.setByte(n, (byte) ~b); - } - return 0; - } - - /** - * TODO: 準備中 - * - * @param data TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_NOT(AbstractCobolField data, int length) { - return CBL_NOT(data.getDataStorage(), length); - } - - /** - * 組み込み関数CBL_XF4の実装。詳しい説明はTODO: 準備中 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_XF4(CobolDataStorage data1, CobolDataStorage data2) { - CobolUtil.COB_CHK_PARMS("CBL_XF4", 2); - for (int n = 0; n < 8; ++n) { - byte b1 = data1.getByte(n); - byte b2 = data2.getByte(n); - data1.setByte(n, (byte) (b1 | (b2 & 1) << (7 - n))); - } - return 0; - } - - /** - * TODO: 準備中 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_XF4(AbstractCobolField data1, CobolDataStorage data2) { - return CBL_XF4(data1.getDataStorage(), data2); - } - - /** - * TODO: 準備中 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_XF4(CobolDataStorage data1, AbstractCobolField data2) { - return CBL_XF4(data1, data2.getDataStorage()); - } - - /** - * TODO: 準備中 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_XF4(AbstractCobolField data1, AbstractCobolField data2) { - return CBL_XF4(data1.getDataStorage(), data2.getDataStorage()); - } - - /** - * 組み込み関数CBL_XF5の実装。詳しい説明はTODO: 準備中 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_XF5(CobolDataStorage data1, CobolDataStorage data2) { - CobolUtil.COB_CHK_PARMS("CBL_XF5", 2); - byte b1 = data1.getByte(0); - for (int n = 0; n < 8; ++n) { - data2.setByte(n, (byte) ((b1 & (1 << (7 - n))) != 0 ? 1 : 0)); - } - return 0; - } - - /** - * TODO: 準備中 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_XF5(AbstractCobolField data1, CobolDataStorage data2) { - return CBL_XF5(data1.getDataStorage(), data2); - } - - /** - * TODO: 準備中 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_XF5(CobolDataStorage data1, AbstractCobolField data2) { - return CBL_XF5(data1, data2.getDataStorage()); - } - - /** - * TODO: 準備中 - * - * @param data1 TODO: 準備中 - * @param data2 TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_XF5(AbstractCobolField data1, AbstractCobolField data2) { - return CBL_XF5(data1.getDataStorage(), data2.getDataStorage()); - } - - /** - * 組み込み関数CBL_X91の実装。詳しい説明はTODO: 準備中 - * - * @param result TODO: 準備中 - * @param func TODO: 準備中 - * @param parm TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_X91(CobolDataStorage result, CobolDataStorage func, CobolDataStorage parm) { - switch (func.getByte(0)) { - case 11: - for (int i = 0; i < 8; ++i) { - if (parm.getByte(i) == 0) { - CobolUtil.cobSwitch[i] = false; - } else if (parm.getByte(i) == 1) { - CobolUtil.cobSwitch[i] = true; - } - } - result.setByte(0, (byte) 0); - break; - case 12: - for (int i = 0; i < 8; ++i) { - parm.setByte(i, (byte) (CobolUtil.cobSwitch[i] ? 1 : 0)); - } - result.setByte(0, (byte) 0); - break; - case 16: - parm.setByte(0, (byte) CobolUtil.cobSaveCallParams); - result.setByte(0, (byte) 0); - break; - default: - result.setByte(0, (byte) 1); - break; - } - return 0; - } - - /** - * 組み込み関数CBL_TOLOWERの実装。詳しい説明はTODO: 準備中 - * - * @param data TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_TOLOWER(CobolDataStorage data, int length) { - CobolUtil.COB_CHK_PARMS("CBL_TOLOWER", 2); - if (length <= 0) { - return 0; - } - - for (int n = 0; n < length; ++n) { - byte b = data.getByte(n); - byte[] bytes = {b}; - byte result = new String(bytes).toLowerCase().getBytes()[0]; - data.setByte(n, result); - } - return 0; - } - - /** - * TODO: 準備中 - * - * @param data TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_TOLOWER(AbstractCobolField data, int length) { - return CBL_TOLOWER(data.getDataStorage(), length); - } - - /** - * 組み込み関数CBL_TOUPPERの実装。詳しい説明はTODO: 準備中 - * - * @param data TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_TOUPPER(CobolDataStorage data, int length) { - CobolUtil.COB_CHK_PARMS("CBL_TOUPPER", 2); - if (length <= 0) { - return 0; - } - - for (int n = 0; n < length; ++n) { - byte b = data.getByte(n); - byte[] bytes = {b}; - byte result = new String(bytes).toUpperCase().getBytes()[0]; - data.setByte(n, result); - } - return 0; - } - - /** - * TODO: 準備中 - * - * @param data TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_TOUPPER(AbstractCobolField data, int length) { - return CBL_TOUPPER(data.getDataStorage(), length); - } - - /** - * TODO: 準備中 - * - * @param data TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_OC_NANOSLEEP(CobolDataStorage data) { - CobolUtil.COB_CHK_PARMS("CBL_OC_NANOSLEEP", 1); - - AbstractCobolField param = CobolModule.getCurrentModule().cob_procedure_parameters.get(0); - if (param != null) { - long nsecs = param.getLong(); - System.out.println(nsecs); - if (nsecs > 0) { - try { - TimeUnit.NANOSECONDS.sleep(nsecs); - } catch (InterruptedException e) { - } - } - } - return 0; - } - - /** - * TODO: 準備中 - * - * @param field TODO: 準備中 - * @return TODO: 準備中 - */ - public static int CBL_OC_NANOSLEEP(AbstractCobolField field) { - CobolSystemRoutine.CBL_OC_NANOSLEEP(field.getDataStorage()); - return 0; - } - - /** - * TODO: 準備中 - * - * @param data TODO: 準備中 - * @return TODO: 準備中 - */ - public static int calledBy(CobolDataStorage data) { - CobolUtil.COB_CHK_PARMS("calledby", 1); - return CobolModule.calledBy(data); - } - - /** - * TODO: 準備中 - * - * @param data TODO: 準備中 - * @return TODO: 準備中 - */ - public static int listDir(CobolDataStorage... data) { - CobolUtil.COB_CHK_PARMS("listDirectory", 1); - List params = CobolModule.getCurrentModule().cob_procedure_parameters; - if (params == null) { - return -1; - } - int paramsSize = params.size(); - if (paramsSize < 1) { - return -1; - } - AbstractCobolField operationCodeFiled = params.get(0); - if (operationCodeFiled == null) { - return -1; - } - - int operationCode = params.get(0).getInt(); - switch (operationCode) { - case 1: // LISTDIR-OPEN(value:1) - if (paramsSize < 3) { - return -1; - } - return listDirOpen(params.get(1), params.get(2)); - case 2: // LISTDIR-OPEN(value:2) - if (paramsSize < 3) { - return -1; - } - return listDirNext(params.get(1), params.get(2)); - case 3: // LISTDIR-OPEN(value:3) - if (paramsSize < 2) { - return -1; - } - return lsitDirClose(params.get(1)); - default: - return -1; - } - } - - private static List dirList = null; - - private static int listDirOpen(AbstractCobolField dirPathField, AbstractCobolField patternField) { - // FIXME: now not use patternField. - String dirPath = strFromField(dirPathField); - try { - dirList = - Files.list(Paths.get(dirPath)).map(p -> p.getFileName()).collect(Collectors.toList()); - } catch (IOException e) { - return -1; - } - dirList.add(Paths.get(".")); - dirList.add(Paths.get("..")); - Collections.sort(dirList); - return 0; - } - - private static int listDirNext(AbstractCobolField handleField, AbstractCobolField fileNameField) { - // FIXME: now not use handleField. - if (dirList == null) { - return -1; - } - - CobolDataStorage storage = fileNameField.getDataStorage(); - int fieldSize = fileNameField.getSize(); - storage.memset(' ', fieldSize); - - if (dirList.isEmpty()) { - return -1; - } - - Path filePath = dirList.get(0); - dirList.remove(0); - byte[] filePathBytes = filePath.toString().getBytes(); - int filePathStringLength = filePathBytes.length; - int copySize = Math.min(fieldSize, filePathStringLength); - storage.memcpy(filePathBytes, copySize); - return 0; - } - - private static int lsitDirClose(AbstractCobolField handleField) { - // FIXME: now not use handleField - dirList = null; - return 0; - } - - private static String strFromField(AbstractCobolField field) { - if (field == null) { - return null; - } - - int i; - CobolDataStorage storage = field.getDataStorage(); - for (i = field.getSize() - 1; i >= 0; --i) { - byte b = storage.getByte(i); - if (b != ' ' && b != 0) { - break; - } - } - - StringBuilder sb = new StringBuilder(); - boolean quoteSwitch = false; - for (int n = 0; n <= i; ++n) { - byte b = storage.getByte(n); - if (b == '\'') { - quoteSwitch = !quoteSwitch; - continue; - } - if (quoteSwitch) { - sb.append((char) b); - continue; - } else if (b == ' ' || b == 0) { - break; - } else { - sb.append((char) b); - } - } - return sb.toString(); - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.call; + +import java.io.IOException; +import java.lang.ProcessBuilder.Redirect; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import jp.osscons.opensourcecobol.libcobj.common.CobolModule; +import jp.osscons.opensourcecobol.libcobj.common.CobolUtil; +import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; +import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; + +/** 組み込み関数を提供するクラス */ +public class CobolSystemRoutine { + private static final boolean runsOnWindows = "\\".equals(System.getProperty("file.separator")); + + /** + * 組み込み関数CBL_EXIT_PROCの実装。未実装。 + * + * @param x 未実装 + * @param pptr 未実装 + * @return 未実装 + */ + public static int CBL_EXIT_PROC(CobolDataStorage x, CobolDataStorage pptr) { + // TODO 実装 + return 0; + } + + /** + * 組み込み関数CBL_ERROR_PROCの実装。未実装。 + * + * @param x 未実装 + * @param pptr 未実装 + * @return 未実装 + */ + public static int CBL_ERROR_PROC(CobolDataStorage x, CobolDataStorage pptr) { + // TODO 実装 + return 0; + } + + /** + * 組み込み関数SYSTEMの実装。cmdに指定されたコマンドを実行する。 + * + * @param cmd コマンド文字列。Linux/Unix環境であればシェルコマンド、Windows環境であればコマンドプロンプトのコマンド。 + * @return コマンドの終了コード。 + * @throws CobolStopRunException TODO: 準備中 + * このメソッドは内部でCobolModule.getCurrentModule().cob_procedure_parametersを参照する。 + * このリストの形式に問題がある場合にスローされる。 + */ + public static int SYSTEM(CobolDataStorage cmd) throws CobolStopRunException { + int size = SYSTEM_getParameterSize(); + String cmdStr = new String(cmd.getByteArray(0, size), AbstractCobolField.charSetSJIS); + return SYSTEM_main(cmdStr); + } + + /** + * 組み込み関数SYSTEMの実装。cmdに指定されたコマンドを実行する。 + * + * @param cmd コマンド文字列。Linux/Unix環境であればシェルコマンド、Windows環境であればコマンドプロンプトのコマンド。 + * @return コマンドの終了コード。 + */ + public static int SYSTEM(String cmd) { + return SYSTEM_main(cmd); + } + + private static int SYSTEM_getParameterSize() throws CobolStopRunException { + CobolUtil.COB_CHK_PARMS("SYSTEM", 1); + List paramaters = + CobolModule.getCurrentModule().cob_procedure_parameters; + if (!paramaters.isEmpty() && paramaters.get(0) != null) { + AbstractCobolField paramater = paramaters.get(0); + int size = paramater.getSize(); + if (size <= 0) { + CobolUtil.runtimeError("The size of the paramater to SYSTEM call is less than 1"); + CobolStopRunException.stopRunAndThrow(1); + } + return size; + } else { + CobolUtil.runtimeError("The size of the paramater is not specified"); + CobolStopRunException.stopRunAndThrow(1); + // not reached + return -1; + } + } + + private static int SYSTEM_main(String cmd) { + ProcessBuilder pb; + if (runsOnWindows) { + pb = new ProcessBuilder("cmd", "/c", cmd); + } else { + pb = new ProcessBuilder("sh", "-c", cmd); + } + pb.redirectInput(Redirect.INHERIT) + .redirectOutput(Redirect.INHERIT) + .redirectError(Redirect.INHERIT); + try { + Process process = pb.start(); + return process.waitFor(); + } catch (InterruptedException | IOException e) { + e.printStackTrace(); + return 1; + } + } + + /** + * 組み込み関数SYSTEMの実装。cmdに指定されたコマンドを実行する。 + * + * @param cmd コマンド文字列。Linux/Unix環境であればシェルコマンド、Windows環境であればコマンドプロンプトのコマンド。 + * @return コマンドの終了コード。 + */ + public static int SYSTEM(AbstractCobolField cmd) { + return SYSTEM(cmd.getString()); + } + + /** + * 組み込み関数すうC$SLEEPの実装 + * opensource COBOLのlibcob/common.cのcob_acuw_sleep関数に相当する + * + * @param data C$SLEEPの引数として指定されたCOBOL変数のバイト列。 + */ + @SuppressWarnings("PMD.AvoidDollarSigns") + public static int C$SLEEP(CobolDataStorage data) { + CobolUtil.COB_CHK_PARMS("C$SLEEP", 3); + List params = CobolModule.getCurrentModule().cob_procedure_parameters; + if (!params.isEmpty() && params.get(0) != null) { + int n = params.get(0).getInt(); + if (n > 0 && n < 3600 * 24 * 7) { + try { + Thread.sleep(n * 1000L); + } catch (InterruptedException e) { + return 0; + } + } + } + return 0; + } + + private interface Calculater { + byte calc(byte b1, byte b2); + } + + private static int CBL_COMMON_OPERATION( + String funcName, + CobolDataStorage data1, + CobolDataStorage data2, + int length, + Calculater c) { + CobolUtil.COB_CHK_PARMS(funcName, 3); + if (length <= 0) { + return 0; + } + for (int n = 0; n < length; ++n) { + byte b1 = data1.getByte(n); + byte b2 = data2.getByte(n); + data2.setByte(n, c.calc(b1, b2)); + } + return 0; + } + + /** + * 組み込み関数CBL_ANDの実装。1バイトごとに論理積を取る。 先頭lengthバイトのデータについて論理積を計算し、計算結果を2番目の引数の先頭に格納する。 + * + * @param data1 計算対象の1番目のCOBOL変数のバイト列。 + * @param data2 計算対象の2番目のCOBOL変数のバイト列。先頭lengthバイトに計算結果が格納される。 + * @param length 計算するバイト数。 + * @return 0 + */ + public static int CBL_AND(CobolDataStorage data1, CobolDataStorage data2, int length) { + return CBL_COMMON_OPERATION( + "CBL_AND", + data1, + data2, + length, + new Calculater() { + @Override + public byte calc(byte b1, byte b2) { + return (byte) (b1 & b2); + } + }); + } + + /** + * 組み込み関数CBL_ANDの実装。1バイトごとに論理積を取る。 先頭lengthバイトのデータについて論理積を計算し、計算結果を2番目の引数の先頭に格納する。 + * + * @param data1 計算対象の1番目のCOBOL変数。 + * @param data2 計算対象の2番目の引数のバイト列。先頭lengthバイトに計算結果が格納される。 + * @param length 計算するバイト数。 + * @return 0 + */ + public static int CBL_AND(AbstractCobolField data1, CobolDataStorage data2, int length) { + return CBL_AND(data1.getDataStorage(), data2, length); + } + + /** + * 組み込み関数CBL_ANDの実装。1バイトごとに論理積を取る。 先頭lengthバイトのデータについて論理積を計算し、計算結果を2番目の引数の先頭に格納する。 + * + * @param data1 計算対象の1番目のCOBOL変数のバイト列。 + * @param data2 計算対象の2番目のCOBOL変数のバイト列。その変数のバイト列の先頭lengthバイトに計算結果が格納される。 + * @param length 計算するバイト数。 + * @return 0 + */ + public static int CBL_AND(CobolDataStorage data1, AbstractCobolField data2, int length) { + return CBL_AND(data1, data2.getDataStorage(), length); + } + + /** + * 組み込み関数CBL_ANDの実装。1バイトごとに論理積を取る。 先頭lengthバイトのデータについて論理積を計算し、計算結果を2番目の引数の先頭に格納する。 + * + * @param data1 計算対象の1番目のCOBOL変数。 + * @param data2 計算対象の2番目のCOBOL変数。その変数のバイト列の先頭lengthバイトに計算結果が格納される。 + * @param length 計算するバイト数。 + * @return 0 + */ + public static int CBL_AND(AbstractCobolField data1, AbstractCobolField data2, int length) { + return CBL_AND(data1.getDataStorage(), data2.getDataStorage(), length); + } + + /** + * 組み込み関数CBL_ORの実装。1バイトごとに論理和を取る。 先頭lengthバイトのデータについて論理和を計算し、計算結果を2番目の引数の先頭に格納する。 + * + * @param data1 計算対象の1番目のCOBOL変数のバイト列。 + * @param data2 計算対象の2番目のCOBOL変数のバイト列。先頭lengthバイトに計算結果が格納される。 + * @param length 計算するバイト数 + * @return 0 + */ + public static int CBL_OR(CobolDataStorage data1, CobolDataStorage data2, int length) { + return CBL_COMMON_OPERATION( + "CBL_OR", + data1, + data2, + length, + new Calculater() { + @Override + public byte calc(byte b1, byte b2) { + return (byte) (b1 | b2); + } + }); + } + + /** + * 組み込み関数CBL_ORの実装。1バイトごとに論理和を取る。 先頭lengthバイトのデータについて論理和を計算し、計算結果を2番目の引数の先頭に格納する。 + * + * @param data1 計算対象の1番目のCOBOL変数のバイト列。 + * @param data2 計算対象の2番目のCOBOL変数。そのバイト列の先頭lengthバイトに計算結果が格納される。 + * @param length 計算するバイト数 + * @return 0 + */ + public static int CBL_OR(AbstractCobolField data1, CobolDataStorage data2, int length) { + return CBL_OR(data1.getDataStorage(), data2, length); + } + + /** + * 組み込み関数CBL_ORの実装。1バイトごとに論理和を取る。 先頭lengthバイトのデータについて論理和を計算し、計算結果を2番目の引数の先頭に格納する。 + * + * @param data1 計算対象の1番目のCOBOL変数のバイト列。 + * @param data2 計算対象の2番目のCOBOL変数。先頭lengthバイトに計算結果が格納される。 + * @param length 計算するバイト数 + * @return 0 + */ + public static int CBL_OR(CobolDataStorage data1, AbstractCobolField data2, int length) { + return CBL_OR(data1, data2.getDataStorage(), length); + } + + /** + * 組み込み関数CBL_ORの実装。詳しい説明はTODO: 準備中 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_OR(AbstractCobolField data1, AbstractCobolField data2, int length) { + return CBL_OR(data1.getDataStorage(), data2.getDataStorage(), length); + } + + private static int byte2Int(byte x) { + return x & 0xFF; + } + + private static byte int2Byte(int x) { + return (byte) (x & 0xFF); + } + + /** + * 組み込み関数CBL_NORの実装。1バイトごとに排他的論理和を取る。 先頭lengthバイトのデータについて論理否定を計算し、計算結果を2番目の引数の先頭に格納する。 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_NOR(CobolDataStorage data1, CobolDataStorage data2, int length) { + return CBL_COMMON_OPERATION( + "CBL_NOR", + data1, + data2, + length, + new Calculater() { + @Override + public byte calc(byte b1, byte b2) { + return int2Byte(~(byte2Int(b1) | int2Byte(b2))); + } + }); + } + + /** + * TODO: 準備中 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_NOR(AbstractCobolField data1, CobolDataStorage data2, int length) { + return CBL_NOR(data1.getDataStorage(), data2, length); + } + + /** + * TODO: 準備中 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_NOR(CobolDataStorage data1, AbstractCobolField data2, int length) { + return CBL_NOR(data1, data2.getDataStorage(), length); + } + + /** + * TODO: 準備中 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_NOR(AbstractCobolField data1, AbstractCobolField data2, int length) { + return CBL_NOR(data1.getDataStorage(), data2.getDataStorage(), length); + } + + /** + * 組み込み関数CBL_XORの実装。1バイトごとに排他的論理和を取る。 先頭lengthバイトのデータについて排他的論理和を計算し、計算結果を2番目の引数の先頭に格納する。 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_XOR(CobolDataStorage data1, CobolDataStorage data2, int length) { + return CBL_COMMON_OPERATION( + "CBL_XOR", + data1, + data2, + length, + new Calculater() { + @Override + public byte calc(byte b1, byte b2) { + return (byte) (b1 ^ b2); + } + }); + } + + /** + * 組み込み関数CBL_XORの実装。詳しい説明はTODO: 準備中 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_XOR(AbstractCobolField data1, CobolDataStorage data2, int length) { + return CBL_XOR(data1.getDataStorage(), data2, length); + } + + /** + * 組み込み関数CBL_XORの実装。詳しい説明はTODO: 準備中 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_XOR(CobolDataStorage data1, AbstractCobolField data2, int length) { + return CBL_XOR(data1, data2.getDataStorage(), length); + } + + /** + * 組み込み関数CBL_XORの実装。詳しい説明はTODO: 準備中 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_XOR(AbstractCobolField data1, AbstractCobolField data2, int length) { + return CBL_XOR(data1.getDataStorage(), data2.getDataStorage(), length); + } + + /** + * 組み込み関数CBL_NIMPの実装。詳しい説明はTODO: 準備中 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_NIMP(CobolDataStorage data1, CobolDataStorage data2, int length) { + return CBL_COMMON_OPERATION( + "CBL_NIMP", + data1, + data2, + length, + new Calculater() { + @Override + public byte calc(byte b1, byte b2) { + return (byte) (b1 & (~b2)); + } + }); + } + + /** + * 組み込み関数CBL_NIMPの実装。詳しい説明はTODO: 準備中 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_NIMP(AbstractCobolField data1, CobolDataStorage data2, int length) { + return CBL_NIMP(data1.getDataStorage(), data2, length); + } + + /** + * TODO: 準備中 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_NIMP(CobolDataStorage data1, AbstractCobolField data2, int length) { + return CBL_NIMP(data1, data2.getDataStorage(), length); + } + + /** + * TODO: 準備中 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_NIMP(AbstractCobolField data1, AbstractCobolField data2, int length) { + return CBL_NIMP(data1.getDataStorage(), data2.getDataStorage(), length); + } + + /** + * TODO: 準備中 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_EQ(CobolDataStorage data1, CobolDataStorage data2, int length) { + return CBL_COMMON_OPERATION( + "CBL_EQ", + data1, + data2, + length, + new Calculater() { + @Override + public byte calc(byte b1, byte b2) { + return (byte) ~(b1 ^ b2); + } + }); + } + + /** + * TODO: 準備中 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_EQ(AbstractCobolField data1, CobolDataStorage data2, int length) { + return CBL_EQ(data1.getDataStorage(), data2, length); + } + + /** + * TODO: 準備中 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_EQ(CobolDataStorage data1, AbstractCobolField data2, int length) { + return CBL_EQ(data1, data2.getDataStorage(), length); + } + + /** + * TODO: 準備中 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_EQ(AbstractCobolField data1, AbstractCobolField data2, int length) { + return CBL_EQ(data1.getDataStorage(), data2.getDataStorage(), length); + } + + /** + * 組み込み関数CBL_NOTの実装。詳しい説明はTODO: 準備中 + * + * @param data TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_NOT(CobolDataStorage data, int length) { + CobolUtil.COB_CHK_PARMS("CBL_NOT", 2); + if (length <= 0) { + return 0; + } + for (int n = 0; n < length; ++n) { + byte b = data.getByte(n); + data.setByte(n, (byte) ~b); + } + return 0; + } + + /** + * TODO: 準備中 + * + * @param data TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_NOT(AbstractCobolField data, int length) { + return CBL_NOT(data.getDataStorage(), length); + } + + /** + * 組み込み関数CBL_XF4の実装。詳しい説明はTODO: 準備中 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_XF4(CobolDataStorage data1, CobolDataStorage data2) { + CobolUtil.COB_CHK_PARMS("CBL_XF4", 2); + for (int n = 0; n < 8; ++n) { + byte b1 = data1.getByte(n); + byte b2 = data2.getByte(n); + data1.setByte(n, (byte) (b1 | (b2 & 1) << (7 - n))); + } + return 0; + } + + /** + * TODO: 準備中 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_XF4(AbstractCobolField data1, CobolDataStorage data2) { + return CBL_XF4(data1.getDataStorage(), data2); + } + + /** + * TODO: 準備中 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_XF4(CobolDataStorage data1, AbstractCobolField data2) { + return CBL_XF4(data1, data2.getDataStorage()); + } + + /** + * TODO: 準備中 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_XF4(AbstractCobolField data1, AbstractCobolField data2) { + return CBL_XF4(data1.getDataStorage(), data2.getDataStorage()); + } + + /** + * 組み込み関数CBL_XF5の実装。詳しい説明はTODO: 準備中 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_XF5(CobolDataStorage data1, CobolDataStorage data2) { + CobolUtil.COB_CHK_PARMS("CBL_XF5", 2); + byte b1 = data1.getByte(0); + for (int n = 0; n < 8; ++n) { + data2.setByte(n, (byte) ((b1 & (1 << (7 - n))) != 0 ? 1 : 0)); + } + return 0; + } + + /** + * TODO: 準備中 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_XF5(AbstractCobolField data1, CobolDataStorage data2) { + return CBL_XF5(data1.getDataStorage(), data2); + } + + /** + * TODO: 準備中 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_XF5(CobolDataStorage data1, AbstractCobolField data2) { + return CBL_XF5(data1, data2.getDataStorage()); + } + + /** + * TODO: 準備中 + * + * @param data1 TODO: 準備中 + * @param data2 TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_XF5(AbstractCobolField data1, AbstractCobolField data2) { + return CBL_XF5(data1.getDataStorage(), data2.getDataStorage()); + } + + /** + * 組み込み関数CBL_X91の実装。詳しい説明はTODO: 準備中 + * + * @param result TODO: 準備中 + * @param func TODO: 準備中 + * @param parm TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_X91( + CobolDataStorage result, CobolDataStorage func, CobolDataStorage parm) { + switch (func.getByte(0)) { + case 11: + for (int i = 0; i < 8; ++i) { + if (parm.getByte(i) == 0) { + CobolUtil.cobSwitch[i] = false; + } else if (parm.getByte(i) == 1) { + CobolUtil.cobSwitch[i] = true; + } + } + result.setByte(0, (byte) 0); + break; + case 12: + for (int i = 0; i < 8; ++i) { + parm.setByte(i, (byte) (CobolUtil.cobSwitch[i] ? 1 : 0)); + } + result.setByte(0, (byte) 0); + break; + case 16: + parm.setByte(0, (byte) CobolUtil.cobSaveCallParams); + result.setByte(0, (byte) 0); + break; + default: + result.setByte(0, (byte) 1); + break; + } + return 0; + } + + /** + * 組み込み関数CBL_TOLOWERの実装。詳しい説明はTODO: 準備中 + * + * @param data TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_TOLOWER(CobolDataStorage data, int length) { + CobolUtil.COB_CHK_PARMS("CBL_TOLOWER", 2); + if (length <= 0) { + return 0; + } + + for (int n = 0; n < length; ++n) { + byte b = data.getByte(n); + byte[] bytes = {b}; + byte result = + new String(bytes, AbstractCobolField.charSetSJIS) + .toLowerCase() + .getBytes(AbstractCobolField.charSetSJIS)[0]; + data.setByte(n, result); + } + return 0; + } + + /** + * TODO: 準備中 + * + * @param data TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_TOLOWER(AbstractCobolField data, int length) { + return CBL_TOLOWER(data.getDataStorage(), length); + } + + /** + * 組み込み関数CBL_TOUPPERの実装。詳しい説明はTODO: 準備中 + * + * @param data TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_TOUPPER(CobolDataStorage data, int length) { + CobolUtil.COB_CHK_PARMS("CBL_TOUPPER", 2); + if (length <= 0) { + return 0; + } + + for (int n = 0; n < length; ++n) { + byte b = data.getByte(n); + byte[] bytes = {b}; + byte result = + new String(bytes, AbstractCobolField.charSetSJIS) + .toUpperCase() + .getBytes(AbstractCobolField.charSetSJIS)[0]; + data.setByte(n, result); + } + return 0; + } + + /** + * TODO: 準備中 + * + * @param data TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_TOUPPER(AbstractCobolField data, int length) { + return CBL_TOUPPER(data.getDataStorage(), length); + } + + /** + * TODO: 準備中 + * + * @param data TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_OC_NANOSLEEP(CobolDataStorage data) { + CobolUtil.COB_CHK_PARMS("CBL_OC_NANOSLEEP", 1); + + AbstractCobolField param = CobolModule.getCurrentModule().cob_procedure_parameters.get(0); + if (param != null) { + long nsecs = param.getLong(); + System.out.println(nsecs); + if (nsecs > 0) { + try { + TimeUnit.NANOSECONDS.sleep(nsecs); + } catch (InterruptedException e) { + } + } + } + return 0; + } + + /** + * TODO: 準備中 + * + * @param field TODO: 準備中 + * @return TODO: 準備中 + */ + public static int CBL_OC_NANOSLEEP(AbstractCobolField field) { + CobolSystemRoutine.CBL_OC_NANOSLEEP(field.getDataStorage()); + return 0; + } + + /** + * TODO: 準備中 + * + * @param data TODO: 準備中 + * @return TODO: 準備中 + */ + public static int calledBy(CobolDataStorage data) { + CobolUtil.COB_CHK_PARMS("calledby", 1); + return CobolModule.calledBy(data); + } + + /** + * TODO: 準備中 + * + * @param data TODO: 準備中 + * @return TODO: 準備中 + */ + public static int listDir(CobolDataStorage... data) { + CobolUtil.COB_CHK_PARMS("listDirectory", 1); + List params = CobolModule.getCurrentModule().cob_procedure_parameters; + if (params == null) { + return -1; + } + int paramsSize = params.size(); + if (paramsSize < 1) { + return -1; + } + AbstractCobolField operationCodeFiled = params.get(0); + if (operationCodeFiled == null) { + return -1; + } + + int operationCode = params.get(0).getInt(); + switch (operationCode) { + case 1: // LISTDIR-OPEN(value:1) + if (paramsSize < 3) { + return -1; + } + return listDirOpen(params.get(1), params.get(2)); + case 2: // LISTDIR-OPEN(value:2) + if (paramsSize < 3) { + return -1; + } + return listDirNext(params.get(1), params.get(2)); + case 3: // LISTDIR-OPEN(value:3) + if (paramsSize < 2) { + return -1; + } + return lsitDirClose(params.get(1)); + default: + return -1; + } + } + + private static List dirList = null; + + private static int listDirOpen( + AbstractCobolField dirPathField, AbstractCobolField patternField) { + // FIXME: now not use patternField. + String dirPath = strFromField(dirPathField); + try { + dirList = + Files.list(Paths.get(dirPath)) + .map(p -> p.getFileName()) + .collect(Collectors.toList()); + } catch (IOException e) { + return -1; + } + dirList.add(Paths.get(".")); + dirList.add(Paths.get("..")); + Collections.sort(dirList); + return 0; + } + + private static int listDirNext( + AbstractCobolField handleField, AbstractCobolField fileNameField) { + // FIXME: now not use handleField. + if (dirList == null) { + return -1; + } + + CobolDataStorage storage = fileNameField.getDataStorage(); + int fieldSize = fileNameField.getSize(); + storage.memset(' ', fieldSize); + + if (dirList.isEmpty()) { + return -1; + } + + Path filePath = dirList.get(0); + dirList.remove(0); + byte[] filePathBytes = filePath.toString().getBytes(AbstractCobolField.charSetSJIS); + int filePathStringLength = filePathBytes.length; + int copySize = Math.min(fieldSize, filePathStringLength); + storage.memcpy(filePathBytes, copySize); + return 0; + } + + private static int lsitDirClose(AbstractCobolField handleField) { + // FIXME: now not use handleField + dirList = null; + return 0; + } + + private static String strFromField(AbstractCobolField field) { + if (field == null) { + return null; + } + + int i; + CobolDataStorage storage = field.getDataStorage(); + for (i = field.getSize() - 1; i >= 0; --i) { + byte b = storage.getByte(i); + if (b != ' ' && b != 0) { + break; + } + } + + StringBuilder sb = new StringBuilder(); + boolean quoteSwitch = false; + for (int n = 0; n <= i; ++n) { + byte b = storage.getByte(n); + if (b == '\'') { + quoteSwitch = !quoteSwitch; + continue; + } + if (quoteSwitch) { + sb.append((char) b); + continue; + } else if (b == ' ' || b == 0) { + break; + } else { + sb.append((char) b); + } + } + return sb.toString(); + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolCallParams.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolCallParams.java index 3dd5479d..b7cd159f 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolCallParams.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolCallParams.java @@ -1,25 +1,25 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.common; - -/** TODO: 準備中 */ -public class CobolCallParams { - /** TODO: 準備中 */ - public static int callParams = 0; -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.common; + +/** TODO: 準備中 */ +public class CobolCallParams { + /** TODO: 準備中 */ + public static int callParams = 0; +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolCheck.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolCheck.java index d62d38e7..717594c9 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolCheck.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolCheck.java @@ -1,110 +1,111 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.common; - -import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; -import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionId; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; - -/** TODO: 準備中 */ -public class CobolCheck { - /** - * TODO: 準備中 - * - * @param i TODO: 準備中 - * @param min TODO: 準備中 - * @param max TODO: 準備中 - * @param name TODO: 準備中 - * @param len TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void checkSubscript(int i, int min, int max, byte[] name, int len) - throws CobolStopRunException { - if (i < min || max < i) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_BOUND_SUBSCRIPT); - CobolUtil.runtimeError( - String.format( - "Subscript of '%s' out of bounds: %d", - new String(name, AbstractCobolField.charSetSJIS), i)); - CobolStopRunException.stopRunAndThrow(1); - } - } - - /** - * TODO: 準備中 - * - * @param i TODO: 準備中 - * @param min TODO: 準備中 - * @param max TODO: 準備中 - * @param name TODO: 準備中 - * @param len TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void checkSubscript(long i, int min, int max, byte[] name, int len) - throws CobolStopRunException { - CobolCheck.checkSubscript((int) i, min, max, name, len); - } - - /** - * TODO: 準備中 - * - * @param i TODO: 準備中 - * @param min TODO: 準備中 - * @param max TODO: 準備中 - * @param name TODO: 準備中 - * @param len TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void checkSubscript(long i, int min, int max, CobolDataStorage name, int len) - throws CobolStopRunException { - CobolCheck.checkSubscript((int) i, min, max, name.getByteArrayRef(0, len), len); - } - - /** - * TODO: 準備中 - * - * @param i TODO: 準備中 - * @param min TODO: 準備中 - * @param max TODO: 準備中 - * @param name TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void checkOdo(int i, int min, int max, String name) throws CobolStopRunException { - if (i < min || max < i) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_BOUND_SUBSCRIPT); - CobolUtil.runtimeError(String.format("OCCURS DEPENDING ON '%s' out of bounds: %d", name, i)); - CobolStopRunException.stopRunAndThrow(1); - } - } - - /** - * TODO: 準備中 - * - * @param i TODO: 準備中 - * @param min TODO: 準備中 - * @param max TODO: 準備中 - * @param name TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void checkOdo(int i, int min, int max, byte[] name) throws CobolStopRunException { - CobolCheck.checkOdo(i, min, max, new String(name, AbstractCobolField.charSetSJIS)); - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.common; + +import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; +import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionId; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; + +/** TODO: 準備中 */ +public class CobolCheck { + /** + * TODO: 準備中 + * + * @param i TODO: 準備中 + * @param min TODO: 準備中 + * @param max TODO: 準備中 + * @param name TODO: 準備中 + * @param len TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void checkSubscript(int i, int min, int max, byte[] name, int len) + throws CobolStopRunException { + if (i < min || max < i) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_BOUND_SUBSCRIPT); + CobolUtil.runtimeError( + String.format( + "Subscript of '%s' out of bounds: %d", + new String(name, AbstractCobolField.charSetSJIS), i)); + CobolStopRunException.stopRunAndThrow(1); + } + } + + /** + * TODO: 準備中 + * + * @param i TODO: 準備中 + * @param min TODO: 準備中 + * @param max TODO: 準備中 + * @param name TODO: 準備中 + * @param len TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void checkSubscript(long i, int min, int max, byte[] name, int len) + throws CobolStopRunException { + CobolCheck.checkSubscript((int) i, min, max, name, len); + } + + /** + * TODO: 準備中 + * + * @param i TODO: 準備中 + * @param min TODO: 準備中 + * @param max TODO: 準備中 + * @param name TODO: 準備中 + * @param len TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void checkSubscript(long i, int min, int max, CobolDataStorage name, int len) + throws CobolStopRunException { + CobolCheck.checkSubscript((int) i, min, max, name.getByteArrayRef(0, len), len); + } + + /** + * TODO: 準備中 + * + * @param i TODO: 準備中 + * @param min TODO: 準備中 + * @param max TODO: 準備中 + * @param name TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void checkOdo(int i, int min, int max, String name) throws CobolStopRunException { + if (i < min || max < i) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_BOUND_SUBSCRIPT); + CobolUtil.runtimeError( + String.format("OCCURS DEPENDING ON '%s' out of bounds: %d", name, i)); + CobolStopRunException.stopRunAndThrow(1); + } + } + + /** + * TODO: 準備中 + * + * @param i TODO: 準備中 + * @param min TODO: 準備中 + * @param max TODO: 準備中 + * @param name TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void checkOdo(int i, int min, int max, byte[] name) throws CobolStopRunException { + CobolCheck.checkOdo(i, min, max, new String(name, AbstractCobolField.charSetSJIS)); + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolConstant.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolConstant.java index 604a7cc9..46828424 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolConstant.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolConstant.java @@ -1,156 +1,190 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.common; - -import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; -import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; -import jp.osscons.opensourcecobol.libcobj.data.CobolFieldAttribute; -import jp.osscons.opensourcecobol.libcobj.data.CobolFieldFactory; - -/** TODO: 準備中 */ -public class CobolConstant { - /** TODO: 準備中 */ - public static final CobolFieldAttribute allAttr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_ALL, 0, 0, 0, null); - /** TODO: 準備中 */ - public static final CobolFieldAttribute oneAttr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC, 1, 0, 0, null); - - /** TODO: 準備中 */ - public static final byte[] SJZERO = {(byte) 0x82, (byte) 0x4f}; - /** TODO: 準備中 */ - public static final byte[] SJSPC = {(byte) 0x81, (byte) 0x40}; - /** TODO: 準備中 */ - public static final byte[] SJBLK = {(byte) 0x81, (byte) 0x40}; - /** TODO: 準備中 */ - public static final byte[] SJQUOT = {(byte) 0x81, (byte) 0x68}; - /** TODO: 準備中 */ - public static final byte[] SJSLAS = {(byte) 0x81, (byte) 0x5e}; - /** TODO: 準備中 */ - public static final int SJCSIZ = 2; - - /** TODO: 準備中 */ - public static final byte[] ZENZERO = SJZERO; - /** TODO: 準備中 */ - public static final byte[] ZENSPC = SJSPC; - /** TODO: 準備中 */ - public static final byte[] ZENBLK = SJBLK; - /** TODO: 準備中 */ - public static final byte[] ZENQUOT = SJQUOT; - /** TODO: 準備中 */ - public static final byte[] ZENSLAS = SJSLAS; - /** TODO: 準備中 */ - public static final int ZENCSIZ = SJCSIZ; - - /** TODO: 準備中 */ - public static final AbstractCobolField zero = CobolFieldFactory.makeCobolField(1, "0", allAttr); - /** TODO: 準備中 */ - public static final AbstractCobolField space = CobolFieldFactory.makeCobolField(1, " ", allAttr); - /** TODO: 準備中 */ - public static final AbstractCobolField blank = CobolFieldFactory.makeCobolField(1, " ", allAttr); - - /** TODO: 準備中 */ - public static final AbstractCobolField high = - CobolFieldFactory.makeCobolField(1, CobolConstant.get0xFFStorage(), allAttr); - - /** TODO: 準備中 */ - public static final AbstractCobolField low = CobolFieldFactory.makeCobolField(1, "\0", allAttr); - /** TODO: 準備中 */ - public static final AbstractCobolField quote = CobolFieldFactory.makeCobolField(1, "\"", allAttr); - /** TODO: 準備中 */ - public static final AbstractCobolField one = CobolFieldFactory.makeCobolField(1, "1", oneAttr); - - /** TODO: 準備中 */ - public static final AbstractCobolField zenZero = - CobolFieldFactory.makeCobolField(ZENCSIZ, new CobolDataStorage(ZENZERO), allAttr); - /** TODO: 準備中 */ - public static final AbstractCobolField zenSpace = - CobolFieldFactory.makeCobolField(ZENCSIZ, new CobolDataStorage(ZENSPC), allAttr); - /** TODO: 準備中 */ - public static final AbstractCobolField zenBlank = - CobolFieldFactory.makeCobolField(ZENCSIZ, new CobolDataStorage(ZENBLK), allAttr); - /** TODO: 準備中 */ - public static final AbstractCobolField zenQuote = - CobolFieldFactory.makeCobolField(ZENCSIZ, new CobolDataStorage(ZENQUOT), allAttr); - - private static CobolDataStorage get0xFFStorage() { - byte[] bytes = new byte[1]; - bytes[0] = (byte) 0xff; - return new CobolDataStorage(bytes); - } - - /** TODO: 準備中 */ - public static final long[] exp10LL = { - 1L, - 10L, - 100L, - 1000L, - 10000L, - 100000L, - 1000000L, - 10000000L, - 100000000L, - 1000000000L, - 10000000000L, - 100000000000L, - 1000000000000L, - 10000000000000L, - 100000000000000L, - 1000000000000000L, - 10000000000000000L, - 100000000000000000L, - 1000000000000000000L - }; - - /** TODO: 準備中 */ - static final int COB_MINI_BUFF = 256; - /** TODO: 準備中 */ - static final int COB_SMALL_BUFF = 1024; - /** TODO: 準備中 */ - static final int COB_NORMAL_BUFF = 2048; - /** TODO: 準備中 */ - static final int COB_MEDIUM_BUFF = 8192; - /** TODO: 準備中 */ - static final int COB_LARGE_BUFF = 16384; - - /** TODO: 準備中 */ - static final int COB_MINI_MAX = COB_MINI_BUFF - 1; - /** TODO: 準備中 */ - static final int COB_SMALL_MAX = COB_SMALL_BUFF - 1; - /** TODO: 準備中 */ - static final int COB_NORMAL_MAX = COB_NORMAL_BUFF - 1; - /** TODO: 準備中 */ - static final int COB_MEDIUM_MAX = COB_MEDIUM_BUFF - 1; - /** TODO: 準備中 */ - static final int COB_LARGE_MAX = COB_LARGE_BUFF - 1; - - /** TODO: 準備中 */ - static final int COB_MAX_FIELD_PARAMS = 64; - /** TODO: 準備中 */ - static final int COB_FERROR_INITIALIZED = 0; - /** TODO: 準備中 */ - static final String COB_SOURCE_FILE = null; - /** TODO: 準備中 */ - static final int COB_PACKAGE_VERSION = 0; - /** TODO: 準備中 */ - static final int COB_PATCH_LEVEL = 0; - // TODO 標準パスの設定 - /** TODO: 準備中 */ - public static final String COB_LIBRARY_PATH = ""; -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.common; + +import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; +import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; +import jp.osscons.opensourcecobol.libcobj.data.CobolFieldAttribute; +import jp.osscons.opensourcecobol.libcobj.data.CobolFieldFactory; + +/** TODO: 準備中 */ +public class CobolConstant { + /** TODO: 準備中 */ + public static final CobolFieldAttribute allAttr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_ALL, 0, 0, 0, null); + + /** TODO: 準備中 */ + public static final CobolFieldAttribute oneAttr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC, 1, 0, 0, null); + + /** TODO: 準備中 */ + public static final byte[] SJZERO = {(byte) 0x82, (byte) 0x4f}; + + /** TODO: 準備中 */ + public static final byte[] SJSPC = {(byte) 0x81, (byte) 0x40}; + + /** TODO: 準備中 */ + public static final byte[] SJBLK = {(byte) 0x81, (byte) 0x40}; + + /** TODO: 準備中 */ + public static final byte[] SJQUOT = {(byte) 0x81, (byte) 0x68}; + + /** TODO: 準備中 */ + public static final byte[] SJSLAS = {(byte) 0x81, (byte) 0x5e}; + + /** TODO: 準備中 */ + public static final int SJCSIZ = 2; + + /** TODO: 準備中 */ + public static final byte[] ZENZERO = SJZERO; + + /** TODO: 準備中 */ + public static final byte[] ZENSPC = SJSPC; + + /** TODO: 準備中 */ + public static final byte[] ZENBLK = SJBLK; + + /** TODO: 準備中 */ + public static final byte[] ZENQUOT = SJQUOT; + + /** TODO: 準備中 */ + public static final byte[] ZENSLAS = SJSLAS; + + /** TODO: 準備中 */ + public static final int ZENCSIZ = SJCSIZ; + + /** TODO: 準備中 */ + public static final AbstractCobolField zero = CobolFieldFactory.makeCobolField(1, "0", allAttr); + + /** TODO: 準備中 */ + public static final AbstractCobolField space = + CobolFieldFactory.makeCobolField(1, " ", allAttr); + + /** TODO: 準備中 */ + public static final AbstractCobolField blank = + CobolFieldFactory.makeCobolField(1, " ", allAttr); + + /** TODO: 準備中 */ + public static final AbstractCobolField high = + CobolFieldFactory.makeCobolField(1, CobolConstant.get0xFFStorage(), allAttr); + + /** TODO: 準備中 */ + public static final AbstractCobolField low = CobolFieldFactory.makeCobolField(1, "\0", allAttr); + + /** TODO: 準備中 */ + public static final AbstractCobolField quote = + CobolFieldFactory.makeCobolField(1, "\"", allAttr); + + /** TODO: 準備中 */ + public static final AbstractCobolField one = CobolFieldFactory.makeCobolField(1, "1", oneAttr); + + /** TODO: 準備中 */ + public static final AbstractCobolField zenZero = + CobolFieldFactory.makeCobolField(ZENCSIZ, new CobolDataStorage(ZENZERO), allAttr); + + /** TODO: 準備中 */ + public static final AbstractCobolField zenSpace = + CobolFieldFactory.makeCobolField(ZENCSIZ, new CobolDataStorage(ZENSPC), allAttr); + + /** TODO: 準備中 */ + public static final AbstractCobolField zenBlank = + CobolFieldFactory.makeCobolField(ZENCSIZ, new CobolDataStorage(ZENBLK), allAttr); + + /** TODO: 準備中 */ + public static final AbstractCobolField zenQuote = + CobolFieldFactory.makeCobolField(ZENCSIZ, new CobolDataStorage(ZENQUOT), allAttr); + + private static CobolDataStorage get0xFFStorage() { + byte[] bytes = new byte[1]; + bytes[0] = (byte) 0xff; + return new CobolDataStorage(bytes); + } + + /** TODO: 準備中 */ + public static final long[] exp10LL = { + 1L, + 10L, + 100L, + 1000L, + 10000L, + 100000L, + 1000000L, + 10000000L, + 100000000L, + 1000000000L, + 10000000000L, + 100000000000L, + 1000000000000L, + 10000000000000L, + 100000000000000L, + 1000000000000000L, + 10000000000000000L, + 100000000000000000L, + 1000000000000000000L + }; + + /** TODO: 準備中 */ + static final int COB_MINI_BUFF = 256; + + /** TODO: 準備中 */ + static final int COB_SMALL_BUFF = 1024; + + /** TODO: 準備中 */ + static final int COB_NORMAL_BUFF = 2048; + + /** TODO: 準備中 */ + static final int COB_MEDIUM_BUFF = 8192; + + /** TODO: 準備中 */ + static final int COB_LARGE_BUFF = 16384; + + /** TODO: 準備中 */ + static final int COB_MINI_MAX = COB_MINI_BUFF - 1; + + /** TODO: 準備中 */ + static final int COB_SMALL_MAX = COB_SMALL_BUFF - 1; + + /** TODO: 準備中 */ + static final int COB_NORMAL_MAX = COB_NORMAL_BUFF - 1; + + /** TODO: 準備中 */ + static final int COB_MEDIUM_MAX = COB_MEDIUM_BUFF - 1; + + /** TODO: 準備中 */ + static final int COB_LARGE_MAX = COB_LARGE_BUFF - 1; + + /** TODO: 準備中 */ + static final int COB_MAX_FIELD_PARAMS = 64; + + /** TODO: 準備中 */ + static final int COB_FERROR_INITIALIZED = 0; + + /** TODO: 準備中 */ + static final String COB_SOURCE_FILE = null; + + /** TODO: 準備中 */ + static final int COB_PACKAGE_VERSION = 0; + + /** TODO: 準備中 */ + static final int COB_PATCH_LEVEL = 0; + + // TODO 標準パスの設定 + /** TODO: 準備中 */ + public static final String COB_LIBRARY_PATH = ""; +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolControl.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolControl.java index a222e4b8..bfd06754 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolControl.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolControl.java @@ -25,119 +25,120 @@ /** TODO: 準備中 */ public abstract class CobolControl { - /** TODO: 準備中 */ - public enum LabelType { /** TODO: 準備中 */ - label, - /** TODO: 準備中 */ - section, - } + public enum LabelType { + /** TODO: 準備中 */ + label, + /** TODO: 準備中 */ + section, + } - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - * @throws CobolRuntimeException TODO: 準備中 - * @throws CobolGoBackException TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public abstract Optional run() - throws CobolRuntimeException, CobolGoBackException, CobolStopRunException; + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + * @throws CobolRuntimeException TODO: 準備中 + * @throws CobolGoBackException TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public abstract Optional run() + throws CobolRuntimeException, CobolGoBackException, CobolStopRunException; - /** TODO: 準備中 */ - public int contId = -1; - /** TODO: 準備中 */ - public LabelType type = LabelType.label; + /** TODO: 準備中 */ + public int contId = -1; - /** TODO: 準備中 */ - public CobolControl() { - this.contId = -1; - this.type = LabelType.label; - } + /** TODO: 準備中 */ + public LabelType type = LabelType.label; + + /** TODO: 準備中 */ + public CobolControl() { + this.contId = -1; + this.type = LabelType.label; + } - /** - * TODO: 準備中 - * - * @param contId TODO: 準備中 - * @param type TODO: 準備中 - */ - public CobolControl(int contId, LabelType type) { - this.contId = contId; - this.type = type; - } + /** + * TODO: 準備中 + * + * @param contId TODO: 準備中 + * @param type TODO: 準備中 + */ + public CobolControl(int contId, LabelType type) { + this.contId = contId; + this.type = type; + } - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public static CobolControl pure() { - return new CobolControl() { - @Override - public Optional run() - throws CobolRuntimeException, CobolGoBackException, CobolStopRunException { - return Optional.empty(); - } - }; - } + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public static CobolControl pure() { + return new CobolControl() { + @Override + public Optional run() + throws CobolRuntimeException, CobolGoBackException, CobolStopRunException { + return Optional.empty(); + } + }; + } - /** - * TODO: 準備中 - * - * @param cont TODO: 準備中 - * @return TODO: 準備中 - */ - public static CobolControl goTo(CobolControl cont) { - return new CobolControl() { - @Override - public Optional run() - throws CobolRuntimeException, CobolGoBackException, CobolStopRunException { - return cont.run(); - } - }; - } + /** + * TODO: 準備中 + * + * @param cont TODO: 準備中 + * @return TODO: 準備中 + */ + public static CobolControl goTo(CobolControl cont) { + return new CobolControl() { + @Override + public Optional run() + throws CobolRuntimeException, CobolGoBackException, CobolStopRunException { + return cont.run(); + } + }; + } - /** - * TODO: 準備中 - * - * @param contList TODO: 準備中 - * @param begin TODO: 準備中 - * @param end TODO: 準備中 - * @return TODO: 準備中 - */ - public static CobolControl performThrough(CobolControl[] contList, int begin, int end) { - return new CobolControl() { - @Override - public Optional run() - throws CobolRuntimeException, CobolGoBackException, CobolStopRunException { - Optional nextCont = Optional.of(contList[begin]); - LabelType endType = contList[end].type; - int executedProgramId; - do { - CobolControl cont = nextCont.get(); - executedProgramId = cont.contId; - nextCont = cont.run(); - } while (nextCont.isPresent() && executedProgramId != end); + /** + * TODO: 準備中 + * + * @param contList TODO: 準備中 + * @param begin TODO: 準備中 + * @param end TODO: 準備中 + * @return TODO: 準備中 + */ + public static CobolControl performThrough(CobolControl[] contList, int begin, int end) { + return new CobolControl() { + @Override + public Optional run() + throws CobolRuntimeException, CobolGoBackException, CobolStopRunException { + Optional nextCont = Optional.of(contList[begin]); + LabelType endType = contList[end].type; + int executedProgramId; + do { + CobolControl cont = nextCont.get(); + executedProgramId = cont.contId; + nextCont = cont.run(); + } while (nextCont.isPresent() && executedProgramId != end); - if (endType == LabelType.section) { - while (nextCont.isPresent() && nextCont.get().type == LabelType.label) { - CobolControl cont = nextCont.get(); - nextCont = cont.run(); - } - } - return Optional.of(CobolControl.pure()); - } - }; - } + if (endType == LabelType.section) { + while (nextCont.isPresent() && nextCont.get().type == LabelType.label) { + CobolControl cont = nextCont.get(); + nextCont = cont.run(); + } + } + return Optional.of(CobolControl.pure()); + } + }; + } - /** - * TODO: 準備中 - * - * @param contList TODO: 準備中 - * @param labelId TODO: 準備中 - * @return TODO: 準備中 - */ - public static CobolControl perform(CobolControl[] contList, int labelId) { - return CobolControl.performThrough(contList, labelId, labelId); - } + /** + * TODO: 準備中 + * + * @param contList TODO: 準備中 + * @param labelId TODO: 準備中 + * @return TODO: 準備中 + */ + public static CobolControl perform(CobolControl[] contList, int labelId) { + return CobolControl.performThrough(contList, labelId, labelId); + } } diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolEncoding.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolEncoding.java new file mode 100644 index 00000000..3db3ded2 --- /dev/null +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolEncoding.java @@ -0,0 +1,15 @@ +package jp.osscons.opensourcecobol.libcobj.common; + +/** + * 文字コードを表す列挙型 + */ +public enum CobolEncoding { + /** + * UTF-8を表す + */ + UTF8, + /** + * Shift_JISを表す + */ + SHIFT_JIS, +}; diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolExternal.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolExternal.java index c7803529..38829c84 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolExternal.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolExternal.java @@ -1,77 +1,77 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.common; - -import java.util.AbstractMap; -import java.util.HashMap; -import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; -import jp.osscons.opensourcecobol.libcobj.file.CobolFile; - -/** TODO: 準備中 */ -public final class CobolExternal { - - private CobolFile extAllocFile; - private CobolDataStorage extAllocStorage; - - private static AbstractMap externalMap = - new HashMap(); - - private CobolExternal(CobolFile file) { - this.extAllocFile = file; - } - - private CobolExternal(CobolDataStorage storage, int size) { - this.extAllocStorage = storage; - } - - /** - * TODO: 準備中 - * - * @param name TODO: 準備中 - * @return TODO: 準備中 - */ - public static CobolFile getFileAddress(String name) { - if (externalMap.containsKey(name)) { - return externalMap.get(name).extAllocFile; - } else { - CobolFile ret = new CobolFile(); - CobolExternal ext = new CobolExternal(ret); - externalMap.put(name, ext); - return ret; - } - } - - /** - * TODO: 準備中 - * - * @param name TODO: 準備中 - * @param size TODO: 準備中 - * @return TODO: 準備中 - */ - public static CobolDataStorage getStorageAddress(String name, int size) { - if (externalMap.containsKey(name)) { - return externalMap.get(name).extAllocStorage; - } else { - CobolDataStorage ret = new CobolDataStorage(size); - CobolExternal ext = new CobolExternal(ret, size); - externalMap.put(name, ext); - return ret; - } - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.common; + +import java.util.AbstractMap; +import java.util.HashMap; +import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; +import jp.osscons.opensourcecobol.libcobj.file.CobolFile; + +/** TODO: 準備中 */ +public final class CobolExternal { + + private CobolFile extAllocFile; + private CobolDataStorage extAllocStorage; + + private static AbstractMap externalMap = + new HashMap(); + + private CobolExternal(CobolFile file) { + this.extAllocFile = file; + } + + private CobolExternal(CobolDataStorage storage, int size) { + this.extAllocStorage = storage; + } + + /** + * TODO: 準備中 + * + * @param name TODO: 準備中 + * @return TODO: 準備中 + */ + public static CobolFile getFileAddress(String name) { + if (externalMap.containsKey(name)) { + return externalMap.get(name).extAllocFile; + } else { + CobolFile ret = new CobolFile(); + CobolExternal ext = new CobolExternal(ret); + externalMap.put(name, ext); + return ret; + } + } + + /** + * TODO: 準備中 + * + * @param name TODO: 準備中 + * @param size TODO: 準備中 + * @return TODO: 準備中 + */ + public static CobolDataStorage getStorageAddress(String name, int size) { + if (externalMap.containsKey(name)) { + return externalMap.get(name).extAllocStorage; + } else { + CobolDataStorage ret = new CobolDataStorage(size); + CobolExternal ext = new CobolExternal(ret, size); + externalMap.put(name, ext); + return ret; + } + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolInspect.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolInspect.java index 2f44a492..d540d9f3 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolInspect.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolInspect.java @@ -1,411 +1,420 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.common; - -import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; -import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; -import jp.osscons.opensourcecobol.libcobj.data.CobolFieldAttribute; -import jp.osscons.opensourcecobol.libcobj.data.CobolFieldFactory; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionId; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; - -/** TODO: 準備中 */ -public class CobolInspect { - private static final int INSPECT_ALL = 0; - private static final int INSPECT_LEADING = 1; - private static final int INSPECT_FIRST = 2; - private static final int INSPECT_TRAILING = 3; - - private static AbstractCobolField inspectVar; - private static CobolDataStorage inspectData; - private static int inspectStart; - private static int inspectEnd; - private static int[] inspectMark = null; - private static int lastsize = 0; - private static int inspectSize; - private static int inspectReplacing; - private static int inspectSign; - private static AbstractCobolField inspectVarCopy; - - private static AbstractCobolField figurative(AbstractCobolField f1, AbstractCobolField f2) { - int size1 = 0; - int size2 = f2.getSize(); - byte[] figptr = new byte[size2]; - int s = 0; - for (int n = 0; n < size2; n++, s++) { - figptr[s] = f1.getDataStorage().getByte(size1); - size1++; - if (size1 >= f1.getSize()) { - size1 = 0; - } - } - return CobolFieldFactory.makeCobolField( - size2, - new CobolDataStorage(figptr), - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null)); - } - - private static void common(AbstractCobolField f1, AbstractCobolField f2, int type) - throws CobolStopRunException { - if (f1 == null) { - f1 = CobolConstant.low; - } - if (f2 == null) { - f2 = CobolConstant.low; - } - - int type1 = f1.getAttribute().getType(); - int type2 = f2.getAttribute().getType(); - - if (type2 == CobolFieldAttribute.COB_TYPE_NATIONAL - || type2 == CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED) { - if (f1 == CobolConstant.quote) { - f1 = CobolConstant.zenQuote; - } else if (f1 == CobolConstant.space) { - f1 = CobolConstant.zenSpace; - } else if (f1 == CobolConstant.zero) { - f1 = CobolConstant.zenZero; - } - } - if (type1 == CobolFieldAttribute.COB_TYPE_NATIONAL - || type1 == CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED) { - if (f2 == CobolConstant.quote) { - f2 = CobolConstant.zenQuote; - } else if (f2 == CobolConstant.space) { - f2 = CobolConstant.zenSpace; - } else if (f2 == CobolConstant.zero) { - f2 = CobolConstant.zenZero; - } - } - if (inspectReplacing != 0 && f1.getSize() != f2.getSize()) { - if (type1 == CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_ALL) { - f1 = figurative(f1, f2); - } else { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_RANGE_INSPECT_SIZE); - return; - } - } - - int mark = inspectStart; - int len = inspectEnd - inspectStart; - int n = 0; - if (type == INSPECT_TRAILING) { - for (int i = len - f2.getSize(); i >= 0; i--) { - if (inspectData.memcmp(inspectStart + i, f2.getDataStorage(), f2.getSize()) == 0) { - int j; - for (j = 0; j < f2.getSize(); ++j) { - if (inspectMark[mark + i + j] != -1) { - break; - } - } - if (j == f2.getSize()) { - CobolDataStorage f1Storage = f1.getDataStorage(); - for (j = 0; j < f2.getSize(); ++j) { - inspectMark[mark + i + j] = inspectReplacing != 0 ? f1Storage.getByte(j) : 1; - } - i -= f2.getSize() - 1; - n++; - } - } else { - break; - } - } - } else { - for (int i = 0; i < (len - f2.getSize() + 1); ++i) { - if (inspectData.memcmp(inspectStart + i, f2.getDataStorage(), f2.getSize()) == 0) { - int j; - for (j = 0; j < f2.getSize(); ++j) { - if (inspectMark[mark + i + j] != -1) { - break; - } - } - if (j == f2.getSize()) { - CobolDataStorage f1Storage = f1.getDataStorage(); - for (j = 0; j < f2.getSize(); ++j) { - inspectMark[mark + i + j] = inspectReplacing != 0 ? f1Storage.getByte(j) : 1; - } - i += f2.getSize() - 1; - n++; - if (type == INSPECT_FIRST) { - break; - } - } - } else if (type == INSPECT_LEADING) { - break; - } - } - } - - if (n > 0 && inspectReplacing == 0) { - f1.addInt(n); - } - } - - /** - * libcob/strings.cのcob_inspect_initの実装。詳しい説明はTODO: 準備中。 - * - * @param var TODO: 準備中 - * @param replacing TODO: 準備中 - */ - public static void init(AbstractCobolField var, int replacing) { - CobolInspect.inspectVarCopy = var; - CobolInspect.inspectVar = CobolInspect.inspectVarCopy; - if (inspectVar.getAttribute().isTypeNumericDisplay()) { - inspectVar.putSign(1); - } - CobolInspect.inspectReplacing = replacing; - CobolInspect.inspectSign = var.getSign(); - CobolInspect.inspectSize = var.getFieldSize(); - CobolInspect.inspectData = var.getDataStorage(); - CobolInspect.inspectStart = -1; - CobolInspect.inspectEnd = -1; - if (inspectSize > lastsize) { - inspectMark = new int[inspectSize]; - lastsize = inspectSize; - } - for (int i = 0; i < inspectSize; ++i) { - inspectMark[i] = -1; - } - CobolRuntimeException.setException(0); - } - - /** libcob/strings.cのcob_inspect_startの実装 */ - public static void start() { - inspectStart = 0; - inspectEnd = inspectSize; - } - - /** - * libcob/strings.cのcob_inspect_beforeの実装。詳しい説明はTODO: 準備中。 - * - * @param str TODO: 準備中 - */ - public static void before(AbstractCobolField str) { - CobolDataStorage p2 = null; - int fig = 0; - - switch (str.getAttribute().getType()) { - case CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY: - CobolDataStorage data = str.getDataStorage(); - int firstIndex = str.getFirstDataIndex(); - int size = str.getFieldSize(); - int n = 0; - int i = 0; - while (size > 1 - && (data.getByte(firstIndex + i) == (byte) '0' - || data.getByte(firstIndex + i) == (byte) 0x70)) { - size--; - i++; - } - while (size-- > 0) { - int b = data.getByte(firstIndex + i++); - n = n * 10 + (b >= 0x70 ? b - 0x70 : b - 0x30); - fig++; - } - p2 = new CobolDataStorage(String.format("%d", n).getBytes()); - break; - default: - fig = str.getSize(); - p2 = str.getDataStorage(); - break; - } - - for (int p = inspectStart; p < inspectEnd - fig + 1; ++p) { - if (inspectData.getSubDataStorage(p).memcmp(p2, fig) == 0) { - inspectEnd = p; - break; - } - } - } - - /** - * libcob/strings.cのcob_inspect_afterの実装。詳しい説明はTODO: 準備中。 - * - * @param str TODO: 準備中 - */ - public static void after(AbstractCobolField str) { - CobolDataStorage data = str.getDataStorage(); - int size = str.getSize(); - for (int p = inspectStart; p < inspectEnd - str.getSize() + 1; ++p) { - if (inspectData.getSubDataStorage(p).memcmp(data, size) == 0) { - inspectStart = p + size; - return; - } - } - inspectStart = inspectEnd; - } - - /** - * libcob/strings.cのcob_inspect_charactersの実装。詳しい説明はTODO: 準備中。 - * - * @param f1 TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void characters(AbstractCobolField f1) throws CobolStopRunException { - int mark = inspectStart; - int len = inspectEnd - inspectStart; - if (inspectReplacing != 0) { - for (int i = 0; i < len; ++i) { - if (inspectMark[mark + i] == -1) { - CobolDataStorage data = f1.getDataStorage(); - for (int j = 0; j < f1.getSize(); ++j) { - inspectMark[mark + i + j] = data.getByte(j); - } - i += f1.getSize() - 1; - } - } - } else { - int n = 0; - for (int i = 0; i < len; ++i) { - if (inspectMark[mark + i] == -1) { - inspectMark[mark + i] = 1; - n++; - } - } - if (n > 0) { - int type = inspectVar.getAttribute().getType(); - if (type == CobolFieldAttribute.COB_TYPE_NATIONAL - || type == CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED) { - n = n / 2; - } - f1.addInt(n); - } - } - } - - /** - * libcob/strings.cのcob_inspect_allの実装。詳しい説明はTODO: 準備中。 - * - * @param f1 TODO: 準備中 - * @param f2 TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void all(AbstractCobolField f1, AbstractCobolField f2) - throws CobolStopRunException { - common(f1, f2, INSPECT_ALL); - } - - /** - * libcob/strings.cのcob_inspect_leadingの実装。詳しい説明はTODO: 準備中。 - * - * @param f1 TODO: 準備中 - * @param f2 TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void leading(AbstractCobolField f1, AbstractCobolField f2) - throws CobolStopRunException { - common(f1, f2, INSPECT_LEADING); - } - - /** - * libcob/strings.cのcob_inspect_firstの実装。詳しい説明はTODO: 準備中。 - * - * @param f1 TODO: 準備中 - * @param f2 TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void first(AbstractCobolField f1, AbstractCobolField f2) - throws CobolStopRunException { - common(f1, f2, INSPECT_FIRST); - } - - /** - * libcob/strings.cのcob_inspect_trailingの実装。詳しい説明はTODO: 準備中。 - * - * @param f1 TODO: 準備中 - * @param f2 TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void trailing(AbstractCobolField f1, AbstractCobolField f2) - throws CobolStopRunException { - common(f1, f2, INSPECT_TRAILING); - } - - /** - * libcob/strings.cのcob_inspect_convertingの実装。詳しい説明はTODO: 準備中。 - * - * @param f1 TODO: 準備中 - * @param f2 TODO: 準備中 - */ - public static void converting(AbstractCobolField f1, AbstractCobolField f2) { - int type1 = f1.getAttribute().getType(); - int len = inspectEnd - inspectStart; - CobolDataStorage data = f2.getDataStorage(); - if (type1 == CobolFieldAttribute.COB_TYPE_NATIONAL - || type1 == CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED) { - if (f2 == CobolConstant.quote) { - f2 = CobolConstant.zenQuote; - } else if (f2 == CobolConstant.space) { - f2 = CobolConstant.zenSpace; - } else if (f2 == CobolConstant.zero) { - f2 = CobolConstant.zenZero; - } - for (int j = 0; j < f1.getSize(); j += 2) { - for (int i = 0; i < len; i += 2) { - if (inspectMark[i] == -1 - && inspectMark[i + 1] == -1 - && f1.getDataStorage() - .getSubDataStorage(j) - .memcmp(inspectData.getSubDataStorage(inspectStart + i), 2) - == 0) { - inspectData.setByte(inspectStart + i, data.getByte(0)); - inspectData.setByte(inspectStart + i + 1, data.getByte(1)); - } - inspectMark[i] = 1; - inspectMark[i + 1] = 1; - } - } - } else { - for (int j = 0; j < f1.getSize(); ++j) { - for (int i = 0; i < len; ++i) { - if (inspectMark[i] == -1 - && inspectData.getByte(inspectStart + i) == f1.getDataStorage().getByte(j)) { - if (f2 == CobolConstant.quote - || f2 == CobolConstant.space - || f2 == CobolConstant.zero) { - inspectData.setByte(inspectStart + i, data.getByte(0)); - } else { - inspectData.setByte(inspectStart + i, data.getByte(j)); - } - inspectMark[i] = 1; - } - } - } - } - } - - /** libcob/strings.cのcob_inspect_finishの実装。詳しい説明はTODO: 準備中。 */ - public static void finish() { - if (inspectReplacing != 0) { - for (int i = 0; i < inspectSize; ++i) { - if (inspectMark[i] != -1) { - inspectData.setByte(i, (byte) inspectMark[i]); - } - } - } - inspectVar.putSign(inspectSign); - } - - /** TODO: 準備中 */ - public static void initString() { - CobolInspect.inspectMark = new int[CobolConstant.COB_MEDIUM_BUFF]; - lastsize = CobolConstant.COB_MEDIUM_BUFF; - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.common; + +import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; +import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; +import jp.osscons.opensourcecobol.libcobj.data.CobolFieldAttribute; +import jp.osscons.opensourcecobol.libcobj.data.CobolFieldFactory; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionId; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; + +/** TODO: 準備中 */ +public class CobolInspect { + private static final int INSPECT_ALL = 0; + private static final int INSPECT_LEADING = 1; + private static final int INSPECT_FIRST = 2; + private static final int INSPECT_TRAILING = 3; + + private static AbstractCobolField inspectVar; + private static CobolDataStorage inspectData; + private static int inspectStart; + private static int inspectEnd; + private static int[] inspectMark = null; + private static int lastsize = 0; + private static int inspectSize; + private static int inspectReplacing; + private static int inspectSign; + private static AbstractCobolField inspectVarCopy; + + private static AbstractCobolField figurative(AbstractCobolField f1, AbstractCobolField f2) { + int size1 = 0; + int size2 = f2.getSize(); + byte[] figptr = new byte[size2]; + int s = 0; + for (int n = 0; n < size2; n++, s++) { + figptr[s] = f1.getDataStorage().getByte(size1); + size1++; + if (size1 >= f1.getSize()) { + size1 = 0; + } + } + return CobolFieldFactory.makeCobolField( + size2, + new CobolDataStorage(figptr), + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null)); + } + + private static void common(AbstractCobolField f1, AbstractCobolField f2, int type) + throws CobolStopRunException { + if (f1 == null) { + f1 = CobolConstant.low; + } + if (f2 == null) { + f2 = CobolConstant.low; + } + + int type1 = f1.getAttribute().getType(); + int type2 = f2.getAttribute().getType(); + + if (type2 == CobolFieldAttribute.COB_TYPE_NATIONAL + || type2 == CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED) { + if (f1 == CobolConstant.quote) { + f1 = CobolConstant.zenQuote; + } else if (f1 == CobolConstant.space) { + f1 = CobolConstant.zenSpace; + } else if (f1 == CobolConstant.zero) { + f1 = CobolConstant.zenZero; + } + } + if (type1 == CobolFieldAttribute.COB_TYPE_NATIONAL + || type1 == CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED) { + if (f2 == CobolConstant.quote) { + f2 = CobolConstant.zenQuote; + } else if (f2 == CobolConstant.space) { + f2 = CobolConstant.zenSpace; + } else if (f2 == CobolConstant.zero) { + f2 = CobolConstant.zenZero; + } + } + if (inspectReplacing != 0 && f1.getSize() != f2.getSize()) { + if (type1 == CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_ALL) { + f1 = figurative(f1, f2); + } else { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_RANGE_INSPECT_SIZE); + return; + } + } + + int mark = inspectStart; + int len = inspectEnd - inspectStart; + int n = 0; + if (type == INSPECT_TRAILING) { + for (int i = len - f2.getSize(); i >= 0; i--) { + if (inspectData.memcmp(inspectStart + i, f2.getDataStorage(), f2.getSize()) == 0) { + int j; + for (j = 0; j < f2.getSize(); ++j) { + if (inspectMark[mark + i + j] != -1) { + break; + } + } + if (j == f2.getSize()) { + CobolDataStorage f1Storage = f1.getDataStorage(); + for (j = 0; j < f2.getSize(); ++j) { + inspectMark[mark + i + j] = + inspectReplacing != 0 ? f1Storage.getByte(j) : 1; + } + i -= f2.getSize() - 1; + n++; + } + } else { + break; + } + } + } else { + for (int i = 0; i < (len - f2.getSize() + 1); ++i) { + if (inspectData.memcmp(inspectStart + i, f2.getDataStorage(), f2.getSize()) == 0) { + int j; + for (j = 0; j < f2.getSize(); ++j) { + if (inspectMark[mark + i + j] != -1) { + break; + } + } + if (j == f2.getSize()) { + CobolDataStorage f1Storage = f1.getDataStorage(); + for (j = 0; j < f2.getSize(); ++j) { + inspectMark[mark + i + j] = + inspectReplacing != 0 ? f1Storage.getByte(j) : 1; + } + i += f2.getSize() - 1; + n++; + if (type == INSPECT_FIRST) { + break; + } + } + } else if (type == INSPECT_LEADING) { + break; + } + } + } + + if (n > 0 && inspectReplacing == 0) { + f1.addInt(n); + } + } + + /** + * libcob/strings.cのcob_inspect_initの実装。詳しい説明はTODO: 準備中。 + * + * @param var TODO: 準備中 + * @param replacing TODO: 準備中 + */ + public static void init(AbstractCobolField var, int replacing) { + CobolInspect.inspectVarCopy = var; + CobolInspect.inspectVar = CobolInspect.inspectVarCopy; + CobolInspect.inspectSign = var.getSign(); + + if (var.getAttribute().isTypeNumericDisplay()) { + inspectVar.putSign(1); + } + + CobolInspect.inspectReplacing = replacing; + CobolInspect.inspectSize = var.getFieldSize(); + CobolInspect.inspectData = var.getDataStorage(); + CobolInspect.inspectStart = -1; + CobolInspect.inspectEnd = -1; + if (inspectSize > lastsize) { + inspectMark = new int[inspectSize]; + lastsize = inspectSize; + } + for (int i = 0; i < inspectSize; ++i) { + inspectMark[i] = -1; + } + CobolRuntimeException.setException(0); + } + + /** libcob/strings.cのcob_inspect_startの実装 */ + public static void start() { + inspectStart = 0; + inspectEnd = inspectSize; + } + + /** + * libcob/strings.cのcob_inspect_beforeの実装。詳しい説明はTODO: 準備中。 + * + * @param str TODO: 準備中 + */ + public static void before(AbstractCobolField str) { + CobolDataStorage p2 = null; + int fig = 0; + + switch (str.getAttribute().getType()) { + case CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY: + CobolDataStorage data = str.getDataStorage(); + int firstIndex = str.getFirstDataIndex(); + int size = str.getFieldSize(); + int n = 0; + int i = 0; + while (size > 1 + && (data.getByte(firstIndex + i) == (byte) '0' + || data.getByte(firstIndex + i) == (byte) 0x70)) { + size--; + i++; + } + while (size-- > 0) { + int b = data.getByte(firstIndex + i++); + n = n * 10 + (b >= 0x70 ? b - 0x70 : b - 0x30); + fig++; + } + p2 = + new CobolDataStorage( + String.format("%d", n).getBytes(AbstractCobolField.charSetSJIS)); + break; + default: + fig = str.getSize(); + p2 = str.getDataStorage(); + break; + } + + for (int p = inspectStart; p < inspectEnd - fig + 1; ++p) { + if (inspectData.getSubDataStorage(p).memcmp(p2, fig) == 0) { + inspectEnd = p; + break; + } + } + } + + /** + * libcob/strings.cのcob_inspect_afterの実装。詳しい説明はTODO: 準備中。 + * + * @param str TODO: 準備中 + */ + public static void after(AbstractCobolField str) { + CobolDataStorage data = str.getDataStorage(); + int size = str.getSize(); + for (int p = inspectStart; p < inspectEnd - str.getSize() + 1; ++p) { + if (inspectData.getSubDataStorage(p).memcmp(data, size) == 0) { + inspectStart = p + size; + return; + } + } + inspectStart = inspectEnd; + } + + /** + * libcob/strings.cのcob_inspect_charactersの実装。詳しい説明はTODO: 準備中。 + * + * @param f1 TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void characters(AbstractCobolField f1) throws CobolStopRunException { + int mark = inspectStart; + int len = inspectEnd - inspectStart; + if (inspectReplacing != 0) { + for (int i = 0; i < len; ++i) { + if (inspectMark[mark + i] == -1) { + CobolDataStorage data = f1.getDataStorage(); + for (int j = 0; j < f1.getSize(); ++j) { + inspectMark[mark + i + j] = data.getByte(j); + } + i += f1.getSize() - 1; + } + } + } else { + int n = 0; + for (int i = 0; i < len; ++i) { + if (inspectMark[mark + i] == -1) { + inspectMark[mark + i] = 1; + n++; + } + } + if (n > 0) { + int type = inspectVar.getAttribute().getType(); + if (type == CobolFieldAttribute.COB_TYPE_NATIONAL + || type == CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED) { + n = n / 2; + } + f1.addInt(n); + } + } + } + + /** + * libcob/strings.cのcob_inspect_allの実装。詳しい説明はTODO: 準備中。 + * + * @param f1 TODO: 準備中 + * @param f2 TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void all(AbstractCobolField f1, AbstractCobolField f2) + throws CobolStopRunException { + common(f1, f2, INSPECT_ALL); + } + + /** + * libcob/strings.cのcob_inspect_leadingの実装。詳しい説明はTODO: 準備中。 + * + * @param f1 TODO: 準備中 + * @param f2 TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void leading(AbstractCobolField f1, AbstractCobolField f2) + throws CobolStopRunException { + common(f1, f2, INSPECT_LEADING); + } + + /** + * libcob/strings.cのcob_inspect_firstの実装。詳しい説明はTODO: 準備中。 + * + * @param f1 TODO: 準備中 + * @param f2 TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void first(AbstractCobolField f1, AbstractCobolField f2) + throws CobolStopRunException { + common(f1, f2, INSPECT_FIRST); + } + + /** + * libcob/strings.cのcob_inspect_trailingの実装。詳しい説明はTODO: 準備中。 + * + * @param f1 TODO: 準備中 + * @param f2 TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void trailing(AbstractCobolField f1, AbstractCobolField f2) + throws CobolStopRunException { + common(f1, f2, INSPECT_TRAILING); + } + + /** + * libcob/strings.cのcob_inspect_convertingの実装。詳しい説明はTODO: 準備中。 + * + * @param f1 TODO: 準備中 + * @param f2 TODO: 準備中 + */ + public static void converting(AbstractCobolField f1, AbstractCobolField f2) { + int type1 = f1.getAttribute().getType(); + int len = inspectEnd - inspectStart; + CobolDataStorage data = f2.getDataStorage(); + if (type1 == CobolFieldAttribute.COB_TYPE_NATIONAL + || type1 == CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED) { + if (f2 == CobolConstant.quote) { + f2 = CobolConstant.zenQuote; + } else if (f2 == CobolConstant.space) { + f2 = CobolConstant.zenSpace; + } else if (f2 == CobolConstant.zero) { + f2 = CobolConstant.zenZero; + } + for (int j = 0; j < f1.getSize(); j += 2) { + for (int i = 0; i < len; i += 2) { + if (inspectMark[i] == -1 + && inspectMark[i + 1] == -1 + && f1.getDataStorage() + .getSubDataStorage(j) + .memcmp( + inspectData.getSubDataStorage(inspectStart + i), + 2) + == 0) { + inspectData.setByte(inspectStart + i, data.getByte(0)); + inspectData.setByte(inspectStart + i + 1, data.getByte(1)); + } + inspectMark[i] = 1; + inspectMark[i + 1] = 1; + } + } + } else { + for (int j = 0; j < f1.getSize(); ++j) { + for (int i = 0; i < len; ++i) { + if (inspectMark[i] == -1 + && inspectData.getByte(inspectStart + i) + == f1.getDataStorage().getByte(j)) { + if (f2 == CobolConstant.quote + || f2 == CobolConstant.space + || f2 == CobolConstant.zero) { + inspectData.setByte(inspectStart + i, data.getByte(0)); + } else { + inspectData.setByte(inspectStart + i, data.getByte(j)); + } + inspectMark[i] = 1; + } + } + } + } + } + + /** libcob/strings.cのcob_inspect_finishの実装。詳しい説明はTODO: 準備中。 */ + public static void finish() { + if (inspectReplacing != 0) { + for (int i = 0; i < inspectSize; ++i) { + if (inspectMark[i] != -1) { + inspectData.setByte(i, (byte) inspectMark[i]); + } + } + } + inspectVar.putSign(inspectSign); + } + + /** TODO: 準備中 */ + public static void initString() { + CobolInspect.inspectMark = new int[CobolConstant.COB_MEDIUM_BUFF]; + lastsize = CobolConstant.COB_MEDIUM_BUFF; + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolIntrinsic.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolIntrinsic.java index bd49eaf2..6fa42814 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolIntrinsic.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolIntrinsic.java @@ -1,2780 +1,2859 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.common; - -import java.math.BigDecimal; -import java.text.DateFormat; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.format.DateTimeFormatter; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Locale; -import java.util.Random; -import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; -import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; -import jp.osscons.opensourcecobol.libcobj.data.CobolDecimal; -import jp.osscons.opensourcecobol.libcobj.data.CobolFieldAttribute; -import jp.osscons.opensourcecobol.libcobj.data.CobolFieldFactory; -import jp.osscons.opensourcecobol.libcobj.data.CobolNationalField; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionId; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; -import jp.osscons.opensourcecobol.libcobj.file.CobolFile; - -/** TODO: 準備中 */ -public class CobolIntrinsic { - - private static int[] normalDays = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}; - private static int[] leapDays = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366}; - private static int[] normalMonthDays = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - private static int[] leapMonthDays = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - private static final int DEPTH_LEVEL = 8; - private static final int sizeOfDouble = 8; - private static int currEntry = 0; - private static AbstractCobolField currField = null; - private static AbstractCobolField[] calcField = new AbstractCobolField[DEPTH_LEVEL]; - private static Random random = new Random(); - private static byte[] localeBuff; - private static final byte[] byteArray00 = "00".getBytes(); - - /** libcob/intrinsicのmake_double_entryの実装 */ - private static void makeDoubleEntry() { - CobolDataStorage s = new CobolDataStorage(sizeOfDouble + 1); - - CobolFieldAttribute newAttr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE, - 18, - 9, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - AbstractCobolField newField = CobolFieldFactory.makeCobolField(sizeOfDouble, s, newAttr); - - calcField[currEntry] = newField; - currField = newField; - ++currEntry; - if (currEntry >= DEPTH_LEVEL) { - currEntry = 0; - } - } - - /** libcob/intrinsicのmake_field_entryの実装 */ - private static void makeFieldEntry(AbstractCobolField f) { - AbstractCobolField newField = - CobolFieldFactory.makeCobolField( - f.getSize(), new CobolDataStorage(f.getSize() + 1), f.getAttribute()); - calcField[currEntry] = newField; - currField = calcField[currEntry]; - - ++currEntry; - if (currEntry >= DEPTH_LEVEL) { - currEntry = 0; - } - } - - /** - * libcob/intrinsicのcob_intr_ordの実装 - * - * @param year TODO: 準備中 - * @return TODO: 準備中 - */ - private static boolean isLeapYear(int year) { - return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)); - } - - // libcob/intrinsicのcob_init_intrinsicの実装 - /** TODO: 準備中 */ - public static void init() { - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); - for (int i = 0; i < DEPTH_LEVEL; ++i) { - calcField[i] = CobolFieldFactory.makeCobolField(256, new CobolDataStorage(256), attr); - } - } - - // libcob/intrinsicのcob_intr_get_doubleの実装 - /** - * TODO: 準備中 - * - * @param d - * @return - */ - private static double intrGetDouble(CobolDecimal d) { - double v = d.getValue().doubleValue(); - int n = d.getScale(); - for (int i = 0; i < Math.abs(n); ++i) { - if (n > 0) { - v /= 10; - } else { - v *= 10; - } - } - return v; - } - - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - * @param offset TODO: 準備中 - * @param length TODO: 準備中 - */ - private static void calcRefMod(AbstractCobolField f, int offset, int length) { - if (offset <= f.getSize()) { - int calcoff = offset - 1; - int size = f.getSize() - calcoff; - if (length > 0 && length < size) { - size = length; - } - f.setSize(size); - if (calcoff > 0) { - CobolDataStorage tmp = new CobolDataStorage(size); - tmp.memcpy(f.getDataStorage().getSubDataStorage(calcoff), size); - f.getDataStorage().memcpy(tmp, size); - } - } - } - - /** - * TODO: 準備中 - * - * @param f1 TODO: 準備中 - * @param op TODO: 準備中 - * @param f2 TODO: 準備中 - * @return TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static AbstractCobolField intrBinop(AbstractCobolField f1, int op, AbstractCobolField f2) - throws CobolStopRunException { - CobolDecimal d1 = new CobolDecimal(); - CobolDecimal d2 = new CobolDecimal(); - d1.setField(f1); - d2.setField(f2); - - switch ((char) op) { - case '+': - d1.add(d2); - break; - case '-': - d1.sub(d2); - break; - case '*': - d1.mul(d2); - break; - case '/': - d1.div(d2); - break; - case '^': - d1.pow(d2); - break; - default: - break; - } - - int attrsign = 0; - if (d1.getValue().signum() < 0) { - attrsign = CobolFieldAttribute.COB_FLAG_HAVE_SIGN; - } else { - attrsign = 0; - } - - int size = sizeInBase10(d1.getValue()); - if (d1.getScale() > size) { - size = d1.getScale(); - } - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, size, d1.getScale(), attrsign, null); - AbstractCobolField field = - CobolFieldFactory.makeCobolField(size, (CobolDataStorage) null, attr); - makeFieldEntry(field); - d1.getDisplayField(currField, 0); - return currField; - } - - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcLength(AbstractCobolField srcfield) { - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 8, 0, 0, null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(4, (CobolDataStorage) null, attr); - makeFieldEntry(field); - currField.setInt(srcfield.getSize()); - return currField; - } - - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcInteger(AbstractCobolField srcfield) { - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, - 18, - 0, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); - makeFieldEntry(field); - - CobolDecimal d1 = new CobolDecimal(); - d1.setField(srcfield); - if (d1.getValue().signum() >= 0) { - try { - d1.getField(currField, 0); - } catch (CobolStopRunException e) { - return null; - } - return currField; - } - - boolean isScalePositive = d1.getScale() > 0; - BigDecimal val = d1.getValue(); - for (int i = 0; i < Math.abs(d1.getScale()); ++i) { - if (isScalePositive) { - val = val.divide(BigDecimal.TEN); - } else { - val = val.multiply(BigDecimal.TEN); - } - } - - // Rouding to negative infinity - BigDecimal[] vals = val.divideAndRemainder(BigDecimal.ONE); - if (vals[1].signum() != 0) { - vals[0] = vals[0].subtract(BigDecimal.ONE); - } - - try { - new CobolDecimal(vals[0], 0).getField(currField, 0); - } catch (CobolStopRunException e) { - return null; - } - return currField; - } - - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcIntegerPart(AbstractCobolField srcfield) { - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, - 18, - 0, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); - - makeFieldEntry(field); - currField.moveFrom(srcfield); - return currField; - } - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param length TODO: 準備中 - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcUpperCase( - int offset, int length, AbstractCobolField srcfield) { - makeFieldEntry(srcfield); - int size = srcfield.getSize(); - CobolDataStorage currStorage = currField.getDataStorage(); - CobolDataStorage srcStorage = srcfield.getDataStorage(); - for (int i = 0; i < size; ++i) { - currStorage.setByte(i, (byte) Character.toUpperCase(srcStorage.getByte(i))); - } - if (offset > 0) { - calcRefMod(currField, offset, length); - } - return currField; - } - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param length TODO: 準備中 - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcLowerCase( - int offset, int length, AbstractCobolField srcfield) { - makeFieldEntry(srcfield); - int size = srcfield.getSize(); - CobolDataStorage currStorage = currField.getDataStorage(); - CobolDataStorage srcStorage = srcfield.getDataStorage(); - for (int i = 0; i < size; ++i) { - currStorage.setByte(i, (byte) Character.toLowerCase(srcStorage.getByte(i))); - } - if (offset > 0) { - calcRefMod(currField, offset, length); - } - return currField; - } - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param length TODO: 準備中 - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcReverse( - int offset, int length, AbstractCobolField srcfield) { - makeFieldEntry(srcfield); - int size = srcfield.getSize(); - CobolDataStorage currStorage = currField.getDataStorage(); - CobolDataStorage srcStorage = srcfield.getDataStorage(); - for (int i = 0; i < size; ++i) { - currStorage.setByte(i, srcStorage.getByte(srcfield.getSize() - i - 1)); - } - if (offset > 0) { - calcRefMod(currField, offset, length); - } - return currField; - } - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param length TODO: 準備中 - * @param f TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcWhenCompiled(int offset, int length, AbstractCobolField f) { - makeFieldEntry(f); - currField.getDataStorage().memcpy(f.getDataStorage(), f.getSize()); - if (offset > 0) { - calcRefMod(currField, offset, length); - } - return currField; - } - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcCurrentDate(int offset, int length) { - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(21, (CobolDataStorage) null, attr); - makeFieldEntry(field); - // TODO Time Zoneを表示する機能を取り入れる - - String dateString = - String.format( - "%4d%02d%02d%02d%02d%02d%02d00000", - CobolUtil.cal.get(Calendar.YEAR), - CobolUtil.cal.get(Calendar.MONTH) + 1, - CobolUtil.cal.get(Calendar.DAY_OF_MONTH), - CobolUtil.cal.get(Calendar.HOUR_OF_DAY), - CobolUtil.cal.get(Calendar.MINUTE), - CobolUtil.cal.get(Calendar.SECOND), - CobolUtil.cal.get(Calendar.MILLISECOND) / 10); - currField.getDataStorage().memcpy(dateString.getBytes()); - - if (offset > 0) { - calcRefMod(currField, offset, length); - } - return currField; - } - - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcChar(AbstractCobolField srcfield) { - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(1, (CobolDataStorage) null, attr); - makeFieldEntry(field); - - int i = srcfield.getInt(); - if (i < 1 || i > 256) { - currField.getDataStorage().setByte(0, (byte) 0); - } else { - currField.getDataStorage().setByte(0, (byte) (i - 1)); - } - return currField; - } - - // libcob/intrinsicのcob_intr_ordの実装 - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcOrd(AbstractCobolField srcfield) { - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 8, 0, 0, null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(4, (CobolDataStorage) null, attr); - makeFieldEntry(field); - - currField.setInt(srcfield.getDataStorage().getByte(0) + 1); - return currField; - } - - // libcob/intrinsicのcob_intr_date_of_integerの実装 - /** - * TODO: 準備中 - * - * @param srcdays TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcDateOfInteger(AbstractCobolField srcdays) { - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, 8, 0, 0, null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); - makeFieldEntry(field); - - CobolRuntimeException.setException(0); - int days = srcdays.getInt(); - - if (days < 1 || days > 3067671) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); - currField.getDataStorage().memset((byte) '0', 8); - return currField; - } - - int leapyear = 365; - int baseyear = 1601; - while (days > leapyear) { - days -= leapyear; - ++baseyear; - if (isLeapYear(baseyear)) { - leapyear = 366; - } else { - leapyear = 365; - } - } - int i; - for (i = 0; i < 13; ++i) { - if (isLeapYear(baseyear)) { - if (days <= leapDays[i]) { - days -= leapDays[i - 1]; - break; - } - } else { - if (days <= normalDays[i]) { - days -= normalDays[i - 1]; - break; - } - } - } - String dateString = String.format("%04d%02d%02d", baseyear, i, days); - currField.getDataStorage().memcpy(dateString.getBytes()); - return currField; - } - - // libcob/intrinsicのcob_intr_day_of_integerの実装 - /** - * TODO: 準備中 - * - * @param srcdays TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcDayOfInteger(AbstractCobolField srcdays) { - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, 7, 0, 0, null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(7, (CobolDataStorage) null, attr); - makeFieldEntry(field); - - CobolRuntimeException.setException(0); - int days = srcdays.getInt(); - - if (days < 1 || days > 3067671) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); - currField.getDataStorage().memset((byte) '0', 8); - return currField; - } - - int leapyear = 365; - int baseyear = 1601; - while (days > leapyear) { - days -= leapyear; - ++baseyear; - if (isLeapYear((baseyear))) { - leapyear = 366; - } else { - leapyear = 365; - } - } - String dateString = String.format("%04d%03d", baseyear, days); - currField.getDataStorage().memcpy(dateString.getBytes()); - return currField; - } - - // libcob/intrinsicのcob_intr_integer_of_dateの実装 - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcIntegerOfDate(AbstractCobolField srcfield) { - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 8, 0, 0, null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(4, (CobolDataStorage) null, attr); - makeFieldEntry(field); - - CobolRuntimeException.setException(0); - int indate = srcfield.getInt(); - int year = indate / 10000; - if (year < 1601 || year > 9999) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); - currField.setInt(0); - return currField; - } - indate %= 10000; - int month = indate / 100; - if (month < 1 || month > 12) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); - currField.setInt(0); - return currField; - } - int days = indate % 100; - if (days < 1 || days > 31) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); - currField.setInt(0); - return currField; - } - if (isLeapYear(year)) { - if (days > leapMonthDays[month]) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); - currField.setInt(0); - return currField; - } - } else { - if (days > normalMonthDays[month]) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); - currField.setInt(0); - return currField; - } - } - - int totaldays = 0; - int baseyear = 1601; - while (baseyear != year) { - if (isLeapYear(baseyear)) { - totaldays += 366; - } else { - totaldays += 365; - } - ++baseyear; - } - - if (isLeapYear(baseyear)) { - totaldays += leapDays[month - 1]; - } else { - totaldays += normalDays[month - 1]; - } - - totaldays += days; - currField.setInt(totaldays); - return currField; - } - - // libcob/intrinsicのcob_intr_integer_of_dayの実装 - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcIntegerOfDay(AbstractCobolField srcfield) { - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 8, 0, 0, null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(4, (CobolDataStorage) null, attr); - makeFieldEntry(field); - - CobolRuntimeException.setException(0); - int indate = srcfield.getInt(); - int year = indate / 1000; - if (year < 1601 || year > 9999) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); - currField.setInt(0); - return currField; - } - int days = indate % 1000; - if (days < 1 || days > 365 + (isLeapYear(year) ? 1 : 0)) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); - currField.setInt(0); - return currField; - } - int totaldays = 0; - int baseyear = 1601; - while (baseyear != year) { - if (isLeapYear(baseyear)) { - totaldays += 366; - } else { - totaldays += 365; - } - ++baseyear; - } - totaldays += days; - currField.setInt(totaldays); - return currField; - } - - // libcob/intrinsicのcob_intr_integer_of_dayの実装 - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcFactorial(AbstractCobolField srcfield) { - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 18, 0, 0, null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); - makeFieldEntry(field); - - CobolRuntimeException.setException(0); - int srcval = srcfield.getInt(); - if (srcval < 0) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); - currField.setInt(0); - return currField; - } - BigDecimal d = BigDecimal.ONE; - for (int i = 2; i <= srcval; ++i) { - d = d.multiply(new BigDecimal(i)); - } - try { - new CobolDecimal(d, 0).getField(currField, 0); - } catch (CobolStopRunException e) { - return null; - } - return currField; - } - - private static CobolDecimal mathFunctionBefore1(AbstractCobolField srcfield) { - CobolDecimal d1 = new CobolDecimal(); - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, - 18, - 17, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); - d1.setField(srcfield); - makeFieldEntry(field); - return d1; - } - - private static CobolDecimal mathFunctionBefore2(AbstractCobolField srcfield) { - CobolDecimal d1 = new CobolDecimal(); - d1.setField(srcfield); - makeDoubleEntry(); - return d1; - } - - private static AbstractCobolField mathFunctionAfter1(double mathd2) { - if (Double.isNaN(mathd2) - || mathd2 == Double.POSITIVE_INFINITY - || mathd2 == Double.NEGATIVE_INFINITY) { - currField.setInt(0); - return currField; - } - long result = (long) mathd2; - mathd2 -= result; - for (int i = 0; i < 17; ++i) { - mathd2 *= 10; - int tempres = (int) mathd2; - result *= 10; - result += tempres; - mathd2 -= tempres; - } - currField.getDataStorage().set(result); - return currField; - } - - private static AbstractCobolField mathFunctionAfter2(double mathd2) { - if (Double.isNaN(mathd2) - || mathd2 == Double.POSITIVE_INFINITY - || mathd2 == Double.NEGATIVE_INFINITY) { - currField.setInt(0); - return currField; - } - currField.getDataStorage().set(mathd2); - return currField; - } - - // libcob/intrinsicのcob_intr_expの実装 - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcExp(AbstractCobolField srcfield) { - CobolDecimal d1 = mathFunctionBefore2(srcfield); - double mathd2 = Math.pow(2.7182818284590452354, intrGetDouble(d1)); - return mathFunctionAfter2(mathd2); - } - - // libcob/intrinsicのcob_intr_exp10の実装 - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcExp10(AbstractCobolField srcfield) { - CobolDecimal d1 = mathFunctionBefore2(srcfield); - double mathd2 = Math.pow(10, intrGetDouble(d1)); - return mathFunctionAfter2(mathd2); - } - - // libcob/intrinsicのcob_intr_absの実装 - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcAbs(AbstractCobolField srcfield) { - makeFieldEntry(srcfield); - CobolDecimal d1 = srcfield.getDecimal(); - d1.setValue(d1.getValue().abs()); - try { - d1.getField(currField, 0); - } catch (CobolStopRunException e) { - return null; - } - return currField; - } - - // libcob/intrinsicのcob_intr_acosの実装 - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcAcos(AbstractCobolField srcfield) { - CobolDecimal d1 = mathFunctionBefore1(srcfield); - double mathd2 = Math.acos(intrGetDouble(d1)); - return mathFunctionAfter1(mathd2); - } - - // libcob/intrinsicのcob_intr_asinの実装 - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcAsin(AbstractCobolField srcfield) { - CobolDecimal d1 = mathFunctionBefore1(srcfield); - double mathd2 = Math.asin(intrGetDouble(d1)); - return mathFunctionAfter1(mathd2); - } - - // libcob/intrinsicのcob_intr_atanの実装 - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcAtan(AbstractCobolField srcfield) { - CobolDecimal d1 = mathFunctionBefore1(srcfield); - double mathd2 = Math.atan(intrGetDouble(d1)); - return mathFunctionAfter1(mathd2); - } - - // libcob/intrinsicのcob_intr_cosの実装 - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcCos(AbstractCobolField srcfield) { - CobolDecimal d1 = mathFunctionBefore1(srcfield); - double mathd2 = Math.cos(intrGetDouble(d1)); - return mathFunctionAfter1(mathd2); - } - - // libcob/intrinsicのcob_intr_logの実装 - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcLog(AbstractCobolField srcfield) { - CobolDecimal d1 = mathFunctionBefore2(srcfield); - double mathd2 = Math.log(intrGetDouble(d1)); - return mathFunctionAfter2(mathd2); - } - - // libcob/intrinsicのcob_intr_log10の実装 - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcLog10(AbstractCobolField srcfield) { - CobolDecimal d1 = mathFunctionBefore2(srcfield); - double mathd2 = Math.log10(intrGetDouble(d1)); - return mathFunctionAfter2(mathd2); - } - - // libcob/intrinsicのcob_intr_sinの実装 - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcSin(AbstractCobolField srcfield) { - CobolDecimal d1 = mathFunctionBefore1(srcfield); - double mathd2 = Math.sin(intrGetDouble(d1)); - return mathFunctionAfter1(mathd2); - } - - // libcob/intrinsicのcob_intr_sqrtの実装 - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcSqrt(AbstractCobolField srcfield) { - CobolDecimal d1 = mathFunctionBefore2(srcfield); - double mathd2 = Math.sqrt(intrGetDouble(d1)); - return mathFunctionAfter2(mathd2); - } - - // libcob/intrinsicのcob_intr_tanの実装 - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcTan(AbstractCobolField srcfield) { - CobolDecimal d1 = mathFunctionBefore2(srcfield); - double mathd2 = Math.tan(intrGetDouble(d1)); - return mathFunctionAfter2(mathd2); - } - - // libcob/intrinsicのcob_intr_numvalの実装 - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcNumval(AbstractCobolField srcfield) { - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, - 18, - 0, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); - - CobolDataStorage s = srcfield.getDataStorage(); - boolean sign = false; - boolean decimalSeen = false; - long llval = 0; - int integerDigits = 0; - int decimalDigits = 0; - StringBuilder integerBuff = new StringBuilder(); - StringBuilder decimalBuff = new StringBuilder(); - for (int i = 0; i < srcfield.getSize(); ++i) { - if (i < srcfield.getSize() - 1) { - if ((Character.toUpperCase(s.getByte(i)) == 'C' - && Character.toUpperCase(s.getByte(i + 1)) == 'R') - || (Character.toUpperCase(s.getByte(i)) == 'D' - && Character.toUpperCase(s.getByte(i + 1)) == 'B')) { - sign = true; - break; - } - } - char c = (char) s.getByte(i); - if (c == ' ' || c == '+') { - continue; - } - if (c == '-') { - sign = true; - continue; - } - if (c == CobolModule.getCurrentModule().decimal_point) { - decimalSeen = true; - continue; - } - if (c >= '0' && c <= '9') { - llval *= 10; - llval += c - '0'; - if (decimalSeen) { - decimalBuff.append(c); - decimalDigits++; - } else { - integerBuff.append(c); - integerDigits++; - } - } - if (integerDigits + decimalDigits > 30) { - break; - } - } - if (integerDigits > 0) { - integerBuff.setCharAt(0, '0'); - } - if (decimalDigits > 0) { - decimalBuff.setCharAt(0, '0'); - } - if (sign) { - llval = -llval; - } - if (integerDigits + decimalDigits <= 18) { - attr.setScale(decimalDigits); - makeFieldEntry(field); - currField.getDataStorage().set(llval); - } else { - String dataString = - String.format("%s%s.%s", sign ? "-" : "", integerBuff.toString(), decimalBuff.toString()); - double val = Double.parseDouble(dataString); - makeDoubleEntry(); - currField.getDataStorage().set(val); - } - return currField; - } - - // libcob/intrinsicのcob_intr_numval_cの実装 - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @param currency TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcNumvalC( - AbstractCobolField srcfield, AbstractCobolField currency) { - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, - 18, - 0, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); - - boolean sign = false; - boolean decimalSeen = false; - long llval = 0; - int integerDigits = 0; - int decimalDigits = 0; - StringBuilder integerBuff = new StringBuilder(); - StringBuilder decimalBuff = new StringBuilder(); - - CobolDataStorage currencyData = null; - if (currency != null) { - if (currency.getSize() < srcfield.getSize()) { - currencyData = currency.getDataStorage(); - } - } - for (int i = 0; i < srcfield.getSize(); ++i) { - char c = (char) srcfield.getDataStorage().getByte(i); - if (i < srcfield.getSize() - 1) { - char cc = (char) srcfield.getDataStorage().getByte(i + 1); - if ((Character.toUpperCase(c) == 'C' && Character.toUpperCase(cc) == 'R') - || (Character.toUpperCase(c) == 'D' && Character.toUpperCase(cc) == 'B')) { - sign = true; - break; - } - } - if (currencyData != null) { - if (i < srcfield.getSize() - currency.getSize()) { - if (currencyData.memcmp( - srcfield.getDataStorage().getSubDataStorage(i), currency.getSize()) - == 0) { - i += (currency.getSize() - 1); - continue; - } - } - } - if (c == ' ' || c == '+') { - continue; - } - if (c == '-') { - sign = true; - continue; - } - if (c == CobolModule.getCurrentModule().decimal_point) { - decimalSeen = true; - continue; - } - if (c == CobolModule.getCurrentModule().currency_symbol) { - continue; - } - if (c >= '0' && c <= '9') { - llval *= 10; - llval += c - '0'; - if (decimalSeen) { - decimalBuff.append(c); - decimalDigits++; - } else { - integerBuff.append(c); - integerDigits++; - } - } - if (integerDigits + decimalDigits > 30) { - break; - } - } - if (integerDigits > 0) { - integerBuff.setCharAt(0, '0'); - } - if (decimalDigits > 0) { - decimalBuff.setCharAt(0, '0'); - } - if (sign) { - llval = -llval; - } - if (integerDigits + decimalDigits <= 18) { - attr.setScale(decimalDigits); - makeFieldEntry(field); - currField.getDataStorage().set(llval); - } else { - String dataString = - String.format("%s%s.%s", sign ? "-" : "", integerBuff.toString(), decimalBuff.toString()); - double val = Double.parseDouble(dataString); - makeDoubleEntry(); - currField.getDataStorage().set(val); - } - return currField; - } - - /** - * このメソッドは未実装 - * - * @param n このメソッドは未実装 - * @param currency このメソッドは未実装 - * @return null - */ - public static AbstractCobolField funcNumvalC(int n, AbstractCobolField currency) { - // TODO - return null; - } - - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcNumvalC(AbstractCobolField srcfield, int n) { - return funcNumvalC(srcfield, null); - } - - /** - * このメソッドは未実装 - * - * @param n このメソッドは未実装 - * @param m このメソッドは未実装 - * @return null - */ - public static AbstractCobolField funcNumvalC(int n, int m) { - // TODO - return null; - } - - // libcob/intrinsicのcob_intr_annuityの実装 - /** - * TODO: 準備中 - * - * @param srcfield1 TODO: 準備中 - * @param srcfield2 TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcAnnuity( - AbstractCobolField srcfield1, AbstractCobolField srcfield2) { - makeDoubleEntry(); - CobolDecimal d1 = new CobolDecimal(); - CobolDecimal d2 = new CobolDecimal(); - d1.setField(srcfield1); - d2.setField(srcfield2); - - double mathd1 = intrGetDouble(d1); - double mathd2 = intrGetDouble(d2); - if (mathd1 == 0) { - mathd1 = 1.0 / mathd2; - currField.getDataStorage().set(mathd1); - return currField; - } - - mathd1 /= (1.0 - Math.pow(mathd1 + 1.0, 0.0 - mathd2)); - currField.getDataStorage().set(mathd1); - return currField; - } - - private static int sizeInBase10(BigDecimal d1) { - String s = d1.toPlainString(); - int begin = s.charAt(0) == '-' ? 0 : -1; - int pointIndex = s.indexOf('.'); - int end = pointIndex < 0 ? s.length() : pointIndex; - return end - begin - 1; - } - - // libcob/intrinsicのcob_intr_sumの実装 - /** - * TODO: 準備中 - * - * @param params TODO: 準備中 - * @param fields TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcSum(int params, AbstractCobolField... fields) { - CobolDecimal d1 = new CobolDecimal(); - CobolDecimal d2 = new CobolDecimal(); - d1.setValue(BigDecimal.ZERO); - - int scale = 0; - for (AbstractCobolField f : fields) { - if (f.getAttribute().getScale() > scale) { - scale = f.getAttribute().getScale(); - } - d2.setField(f); - d1.add(d2); - } - - int size = sizeInBase10(d1.getValue()); - AbstractCobolField field; - if (size < 19) { - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, - 18, - scale, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - field = CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); - } else { - if (d1.getScale() > size) { - size = d1.getScale(); - } - if (scale > size) { - size = scale; - } - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, - size, - scale, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - field = CobolFieldFactory.makeCobolField(size, (CobolDataStorage) null, attr); - } - makeFieldEntry(field); - try { - d1.getField(currField, 0); - } catch (CobolStopRunException e) { - return null; - } - return currField; - } - - // libcob/intrinsicのcob_intr_ord_minの実装 - /** - * TODO: 準備中 - * - * @param params TODO: 準備中 - * @param fields TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcOrdMin(int params, AbstractCobolField... fields) { - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, 8, 0, 0, null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); - makeFieldEntry(field); - - if (fields.length <= 1) { - currField.setInt(0); - return currField; - } - - AbstractCobolField basef = fields[0]; - int ordmin = 0; - for (int i = 1; i < fields.length; ++i) { - AbstractCobolField f = fields[i]; - if (f.compareTo(basef) < 0) { - basef = f; - ordmin = i; - } - } - - currField.setLong((long) ordmin + 1); - return currField; - } - - // libcob/intrinsicのcob_intr_ord_maxの実装 - /** - * TODO: 準備中 - * - * @param params TODO: 準備中 - * @param fields TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcOrdMax(int params, AbstractCobolField... fields) { - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, 8, 0, 0, null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); - makeFieldEntry(field); - - if (fields.length <= 1) { - currField.setInt(0); - return currField; - } - - AbstractCobolField basef = fields[0]; - int ordmax = 0; - for (int i = 1; i < fields.length; ++i) { - AbstractCobolField f = fields[i]; - if (f.compareTo(basef) > 0) { - basef = f; - ordmax = i; - } - } - - currField.setLong((long) ordmax + 1); - return currField; - } - - // libcob/intrinsicのcob_intr_minの実装 - /** - * TODO: 準備中 - * - * @param params TODO: 準備中 - * @param fields TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcMin(int params, AbstractCobolField... fields) { - AbstractCobolField beasef = fields[0]; - for (int i = 1; i < fields.length; ++i) { - AbstractCobolField f = fields[i]; - if (f.compareTo(beasef) < 0) { - beasef = f; - } - } - - return beasef; - } - - // libcob/intrinsicのcob_intr_maxの実装 - /** - * TODO: 準備中 - * - * @param params TODO: 準備中 - * @param fields TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcMax(int params, AbstractCobolField... fields) { - AbstractCobolField beasef = fields[0]; - for (int i = 1; i < fields.length; ++i) { - AbstractCobolField f = fields[i]; - if (f.compareTo(beasef) > 0) { - beasef = f; - } - } - - return beasef; - } - - // libcob/intrinsicのcob_intr_midrangeの実装 - /** - * TODO: 準備中 - * - * @param params TODO: 準備中 - * @param fields TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcMidrange(int params, AbstractCobolField... fields) { - makeDoubleEntry(); - AbstractCobolField basemin = fields[0]; - AbstractCobolField basemax = fields[0]; - for (int i = 1; i < params; ++i) { - AbstractCobolField f = fields[i]; - if (f.compareTo(basemin) < 0) { - basemin = f; - } - if (f.compareTo(basemax) > 0) { - basemax = f; - } - } - - CobolDecimal d1 = new CobolDecimal(); - CobolDecimal d2 = new CobolDecimal(); - d1.setField(basemin); - d2.setField(basemax); - d1.add(d2); - d2 = new CobolDecimal(new BigDecimal(2), 0); - try { - d1.div(d2); - d1.getField(currField, 0); - } catch (CobolStopRunException e) { - return null; - } - return currField; - } - - // libcob/intrinsicのcob_intr_medianの実装 - /** - * TODO: 準備中 - * - * @param params TODO: 準備中 - * @param fields TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcMedian(int params, AbstractCobolField... fields) { - if (fields.length == 1) { - return fields[0]; - } - - AbstractCobolField[] fieldAlloc = new AbstractCobolField[fields.length]; - - for (int i = 0; i < params; ++i) { - fieldAlloc[i] = fields[i]; - } - - Arrays.sort(fieldAlloc, (a, b) -> a.compareTo(b)); - int i = params / 2; - if (params % 2 != 0) { - return fieldAlloc[i]; - } else { - makeDoubleEntry(); - CobolDecimal d1 = new CobolDecimal(); - CobolDecimal d2 = new CobolDecimal(); - d1.setField(fieldAlloc[i]); - d2.setField(fieldAlloc[i - 1]); - d1.add(d2); - d2 = new CobolDecimal(new BigDecimal(2), 0); - try { - d1.div(d2); - d1.getField(currField, 0); - } catch (CobolStopRunException e) { - return null; - } - return currField; - } - } - - // libcob/intrinsicのcob_intr_medianの実装 - /** - * TODO: 準備中 - * - * @param pramas TODO: 準備中 - * @param fields TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcMean(int pramas, AbstractCobolField... fields) { - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, - 18, - 0, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); - CobolDecimal d1 = new CobolDecimal(BigDecimal.ZERO); - CobolDecimal d2 = new CobolDecimal(); - - for (AbstractCobolField f : fields) { - d2.setField(f); - d1.add(d2); - } - - d2 = new CobolDecimal(new BigDecimal(fields.length), 0); - try { - d1.div(d2); - } catch (CobolStopRunException e) { - return null; - } - - CobolDataStorage storage = new CobolDataStorage(8); - field.setDataStorage(storage); - try { - d1.getField(field, 0); - } catch (CobolStopRunException e) { - return null; - } - long n = storage.longValue(); - int i = 0; - while (n != 0) { - n /= 10; - ++i; - } - field.setDataStorage(null); - if (i <= 18) { - attr.setScale(18 - i); - } - makeFieldEntry(field); - try { - d1.getField(currField, 0); - } catch (CobolStopRunException e) { - return null; - } - return currField; - } - - // libcob/intrinsicのcob_intr_modの実装 - /** - * TODO: 準備中 - * - * @param srcfield1 TODO: 準備中 - * @param srcfield2 TODO: 準備中 - * @return TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static AbstractCobolField funcMod( - AbstractCobolField srcfield1, AbstractCobolField srcfield2) throws CobolStopRunException { - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, - 18, - 0, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); - CobolDecimal d1 = new CobolDecimal(); - CobolDecimal d2 = new CobolDecimal(); - makeFieldEntry(field); - - AbstractCobolField f1 = funcInteger(intrBinop(srcfield1, '/', srcfield2)); - d1.setField(srcfield2); - d2.setField(f1); - d2.mul(d1); - d1.setField(srcfield1); - d1.sub(d2); - try { - d1.getField(currField, 0); - } catch (CobolStopRunException e) { - return null; - } - return currField; - } - - // libcob/intrinsicのcob_intr_rangeの実装 - /** - * TODO: 準備中 - * - * @param params TODO: 準備中 - * @param fields TODO: 準備中 - * @return TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static AbstractCobolField funcRange(int params, AbstractCobolField... fields) - throws CobolStopRunException { - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, - 18, - 0, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); - CobolDecimal d1 = new CobolDecimal(); - CobolDecimal d2 = new CobolDecimal(); - - AbstractCobolField basemin = fields[0]; - AbstractCobolField basemax = fields[0]; - for (int i = 1; i < fields.length; ++i) { - AbstractCobolField f = fields[i]; - if (f.compareTo(basemin) < 0) { - basemin = f; - } - if (f.compareTo(basemax) > 0) { - basemax = f; - } - } - - attr.setScale(basemin.getAttribute().getScale()); - if (basemax.getAttribute().getScale() > attr.getScale()) { - attr.setScale(basemax.getAttribute().getScale()); - } - makeFieldEntry(field); - d1.setField(basemax); - d2.setField(basemin); - d1.sub(d2); - d1.getField(currField, 0); - return currField; - } - - // libcob/intrinsicのcob_intr_remの実装 - /** - * TODO: 準備中 - * - * @param srcfield1 TODO: 準備中 - * @param srcfield2 TODO: 準備中 - * @return TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static AbstractCobolField funcRem( - AbstractCobolField srcfield1, AbstractCobolField srcfield2) throws CobolStopRunException { - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, - 18, - 0, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); - AbstractCobolField f1 = funcIntegerPart(intrBinop(srcfield1, '/', srcfield2)); - CobolDecimal d1 = new CobolDecimal(); - CobolDecimal d2 = new CobolDecimal(); - - d1.setField(srcfield2); - d2.setField(f1); - d2.mul(d1); - d1.setField(srcfield1); - d1.sub(d2); - - attr.setScale(srcfield1.getAttribute().getScale()); - if (srcfield2.getAttribute().getScale() > attr.getScale()) { - attr.setScale(srcfield2.getAttribute().getScale()); - } - makeFieldEntry(field); - d1.getField(currField, 0); - return currField; - } - - // libcob/intrinsicのcob_intr_randomの実装 - /** - * TODO: 準備中 - * - * @param prams TODO: 準備中 - * @param fields TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcRandom(int prams, AbstractCobolField... fields) { - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, - 18, - 0, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); - - if (fields.length > 0) { - AbstractCobolField f = fields[0]; - int seed = f.getInt(); - if (seed < 0) { - seed = 0; - } - random.setSeed(seed); - } - - int r = random.nextInt(1000000001); - - int exp10 = 1; - int i = 0; - for (i = 0; i < 10; ++i) { - if (r / exp10 == 0) { - break; - } - exp10 *= 10; - } - if (i == 0) { - i = 1; - } - attr.setScale(i); - makeFieldEntry(field); - currField.getDataStorage().set((long) r); - return currField; - } - - // libcob/intrinsicのcob_intr_varianceの実装 - /** - * TODO: 準備中 - * - * @param prams TODO: 準備中 - * @param fields TODO: 準備中 - * @return TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static AbstractCobolField funcVariance(int prams, AbstractCobolField... fields) - throws CobolStopRunException { - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, - 18, - 0, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); - - if (fields.length == 1) { - makeFieldEntry(field); - currField.setInt(0); - return currField; - } - - CobolDecimal d1 = new CobolDecimal(BigDecimal.ZERO, 0); - CobolDecimal d2 = new CobolDecimal(); - - for (AbstractCobolField f : fields) { - d2.setField(f); - d1.add(d2); - } - - d2.setValue(new BigDecimal(fields.length)); - d2.setScale(0); - try { - d1.div(d2); - } catch (CobolStopRunException e) { - return null; - } - - CobolDecimal d4 = new CobolDecimal(BigDecimal.ZERO, 0); - - for (AbstractCobolField f : fields) { - d2.setField(f); - d2.sub(d1); - d2.mul(d2); - d4.add(d2); - } - - CobolDecimal d3 = new CobolDecimal(new BigDecimal(fields.length), 0); - try { - d4.div(d3); - } catch (CobolStopRunException e) { - return null; - } - CobolDataStorage data = new CobolDataStorage(8); - field.setDataStorage(data); - d4.getField(field, 0); - long n = field.getLong(); - int i = 0; - while (n != 0) { - n /= 10; - ++i; - } - makeFieldEntry(field); - if (i <= 18) { - attr.setScale(18 - i); - } - d4.getField(currField, 0); - return currField; - } - - // libcob/intrinsicのcob_intr_standard_deviationの実装 - /** - * TODO: 準備中 - * - * @param prams TODO: 準備中 - * @param fields TODO: 準備中 - * @return TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static AbstractCobolField funcStandardDeviation(int prams, AbstractCobolField... fields) - throws CobolStopRunException { - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, - 18, - 0, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); - - makeDoubleEntry(); - - if (fields.length == 1) { - makeFieldEntry(field); - currField.setInt(0); - return currField; - } - - CobolDecimal d1 = new CobolDecimal(BigDecimal.ZERO, 0); - CobolDecimal d2 = new CobolDecimal(); - - for (AbstractCobolField f : fields) { - d2.setField(f); - d1.add(d2); - } - - d2.setValue(new BigDecimal(fields.length)); - d2.setScale(0); - try { - d1.div(d2); - } catch (CobolStopRunException e) { - return null; - } - - CobolDecimal d4 = new CobolDecimal(BigDecimal.ZERO, 0); - - for (AbstractCobolField f : fields) { - d2.setField(f); - d2.sub(d1); - d2.mul(d2); - d4.add(d2); - } - - CobolDecimal d3 = new CobolDecimal(new BigDecimal(fields.length), 0); - try { - d4.div(d3); - } catch (CobolStopRunException e) { - return null; - } - d4.getField(currField, 0); - return funcSqrt(currField); - } - - // libcob/intrinsicのcob_intr_present_valueの実装 - /** - * TODO: 準備中 - * - * @param prams TODO: 準備中 - * @param fields TODO: 準備中 - * @return TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static AbstractCobolField funcPresentValue(int prams, AbstractCobolField... fields) - throws CobolStopRunException { - makeDoubleEntry(); - if (fields.length < 2) { - System.err.println("Wrong number of parameters for FUNCTION PRESENT-VALUE"); - System.err.flush(); - currField.setInt(0); - return currField; - } - AbstractCobolField f = fields[0]; - CobolDecimal d1 = new CobolDecimal(); - d1.setField(f); - CobolDecimal d2 = new CobolDecimal(BigDecimal.ONE, 0); - d1.add(d2); - CobolDecimal d4 = new CobolDecimal(BigDecimal.ZERO, 0); - - for (int i = 1; i < fields.length; ++i) { - f = fields[i]; - d2.setField(f); - CobolDecimal d3 = new CobolDecimal(d1.getValue().add(BigDecimal.ZERO), d1.getScale()); - if (i > 1) { - CobolDecimal d5 = new CobolDecimal(new BigDecimal(i), 0); - d3.pow(d5); - } - d2.div(d3); - d4.add(d2); - } - - d4.getField(currField, 0); - return currField; - } - - // libcob/intrinsicのcob_intr_nationalの実装 - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcNational(AbstractCobolField srcfield) { - int size = srcfield.getSize(); - byte[] pdata = - CobolNationalField.han2zen(srcfield.getDataStorage().getByteBuffer(size).array(), size); - int ndata = CobolNationalField.workReturnSize; - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NATIONAL, 0, 0, 0, null); - AbstractCobolField field = - CobolFieldFactory.makeCobolField(ndata, (CobolDataStorage) null, attr); - makeFieldEntry(field); - currField.getDataStorage().memcpy(pdata, ndata); - return currField; - } - - // cob_intr_combined_datetimeの実装 - /** - * TODO: 準備中 - * - * @param srcdays TODO: 準備中 - * @param srctime TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcCombinedDatetime( - AbstractCobolField srcdays, AbstractCobolField srctime) { - int srdays; - int srtime; - String str; - - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, 12, 5, 0, null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(12, (CobolDataStorage) null, attr); - makeFieldEntry(field); - CobolRuntimeException.setException(0); - srdays = srcdays.getInt(); - if (srdays < 1 || srdays > 3067671) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); - currField.getDataStorage().memset(0, 12); - return currField; - } - srtime = srctime.getInt(); - if (srtime < 1 || srtime > 86400) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); - currField.getDataStorage().memset(0, 12); - return currField; - } - str = String.format("%7d%5d", srdays, srtime); - byte[] buff = str.getBytes(); - for (int i = 0; i < buff.length; i++) { - if (buff[i] == ' ') { - buff[i] = '0'; - } - } - currField.getDataStorage().memcpy(buff); - return currField; - } - - // cob_intr_concatenateの実装 - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param length TODO: 準備中 - * @param params TODO: 準備中 - * @param fields TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcConcatenate( - int offset, int length, int params, AbstractCobolField... fields) { - int calcsize = 0; - int i; - int index = 0; - int size; - byte[] data; - - for (i = 0; i < params; i++) { - calcsize += fields[i].getSize(); - } - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); - AbstractCobolField field = - CobolFieldFactory.makeCobolField(calcsize, (CobolDataStorage) null, attr); - makeFieldEntry(field); - data = new byte[calcsize]; - for (i = 0; i < params; i++) { - size = fields[i].getSize(); - System.arraycopy( - fields[i].getDataStorage().getByteBuffer(size).array(), 0, data, index, size); - index += size; - } - currField.setDataStorage(new CobolDataStorage(data)); - if (offset > 0) { - calcRefMod(currField, offset, length); - } - return currField; - } - - // cob_intr_date_to_yyyymmddの実装 - /** - * TODO: 準備中 - * - * @param params TODO: 準備中 - * @param fields TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcDateToYyyymmdd(int params, AbstractCobolField... fields) { - int year; - int mmdd; - int interval; - int xqtyear; - int maxyear; - LocalDateTime timeptr; - - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 8, 0, 0, null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(4, (CobolDataStorage) null, attr); - makeFieldEntry(field); - year = fields[0].getInt(); - mmdd = year % 10000; - year /= 10000; - if (params > 1) { - interval = fields[1].getInt(); - } else { - interval = 50; - } - if (params > 2) { - xqtyear = fields[2].getInt(); - } else { - timeptr = CobolUtil.localtime(); - xqtyear = 1900 + timeptr.getDayOfYear(); - } - if (year < 0 || year > 999999) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); - currField.setInt(0); - return currField; - } - if (xqtyear < 1601 || xqtyear > 9999) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); - currField.setInt(0); - return currField; - } - maxyear = xqtyear + interval; - if (maxyear < 1700 || maxyear > 9999) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); - currField.setInt(0); - return currField; - } - if (maxyear % 100 >= year) { - year += 100 * (maxyear / 100); - } else { - year += 100 * ((maxyear / 100) - 1); - } - year *= 10000; - year += mmdd; - currField.setInt(year); - return currField; - } - - // cob_intr_day_to_yyyydddの実装 - /** - * TODO: 準備中 - * - * @param params TODO: 準備中 - * @param fields TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcDayToYyyyddd(int params, AbstractCobolField... fields) { - int year; - int days; - int interval; - int xqtyear; - int maxyear; - LocalDateTime timeptr; - - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 8, 0, 0, null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(4, (CobolDataStorage) null, attr); - makeFieldEntry(field); - year = fields[0].getInt(); - days = year % 1000; - year /= 1000; - if (params > 1) { - interval = fields[1].getInt(); - } else { - interval = 50; - } - if (params > 2) { - xqtyear = fields[2].getInt(); - } else { - timeptr = CobolUtil.localtime(); - xqtyear = 1900 + timeptr.getDayOfYear(); - } - - if (year < 0 || year > 999999) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); - currField.setInt(0); - return currField; - } - if (xqtyear < 1601 || xqtyear > 9999) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); - currField.setInt(0); - return currField; - } - maxyear = xqtyear + interval; - if (maxyear < 1700 || maxyear > 9999) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); - currField.setInt(0); - return currField; - } - if (maxyear % 100 >= year) { - year += 100 * (maxyear / 100); - } else { - year += 100 * ((maxyear / 100) - 1); - } - year *= 1000; - year += days; - currField.setInt(year); - return currField; - } - - // cob_intr_exception_fileの実装 - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public static AbstractCobolField funcExceptionFile() { - int flen; - byte[] data; - - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(0, (CobolDataStorage) null, attr); - if (CobolRuntimeException.getException() == 0 - || (CobolRuntimeException.getExceptionCode() & 0x0500) != 0x0500) { - field.setSize(2); - makeFieldEntry(field); - currField.memcpy(byteArray00, 2); - } else { - flen = CobolFile.errorFile.getSelectName().length(); - field.setSize(flen + 2); - makeFieldEntry(field); - data = new byte[2 + flen]; - System.arraycopy(CobolFile.errorFile.getFileStatus(), 0, data, 0, 2); - System.arraycopy(CobolFile.errorFile.getSelectName().getBytes(), 0, data, 2, flen); - currField.setDataStorage(new CobolDataStorage(data)); - } - return currField; - } - - // cob_intr_exception_locationの実装 - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public static AbstractCobolField funcExceptionLocation() { - String buff; - - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(0, (CobolDataStorage) null, attr); - currField = field; - if (CobolRuntimeException.getException() != 1 - || CobolRuntimeException.getOrigProgramId() == null) { - field.setSize(1); - makeFieldEntry(field); - currField.getDataStorage().setByte(0, ' '); - return currField; - } - if (CobolRuntimeException.getOrigSection() != null - && CobolRuntimeException.getOrigParagragh() != null) { - buff = - String.format( - "%s; %s OF %s; %d", - CobolRuntimeException.getOrigProgramId(), - CobolRuntimeException.getOrigParagragh(), - CobolRuntimeException.getOrigSection(), - CobolRuntimeException.getOrigLine()); - } else if (CobolRuntimeException.getOrigSection() != null) { - buff = - String.format( - "%s; %s; %d", - CobolRuntimeException.getOrigProgramId(), - CobolRuntimeException.getOrigSection(), - CobolRuntimeException.getOrigLine()); - } else if (CobolRuntimeException.getOrigParagragh() != null) { - buff = - String.format( - "%s; %s; %d", - CobolRuntimeException.getOrigProgramId(), - CobolRuntimeException.getOrigParagragh(), - CobolRuntimeException.getOrigLine()); - } else { - buff = - String.format( - "%s; ; %d", - CobolRuntimeException.getOrigProgramId(), CobolRuntimeException.getOrigLine()); - } - localeBuff = buff.getBytes(); - field.setSize(localeBuff.length); - currField.setDataStorage(new CobolDataStorage(localeBuff)); - return currField; - } - - // cob_intr_exception_statementの実装 - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public static AbstractCobolField funcExceptionStatement() { - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(31, (CobolDataStorage) null, attr); - makeFieldEntry(field); - byte[] data; - if (CobolRuntimeException.getExceptionCode() != 0 - && CobolRuntimeException.getOrigStatement() != null) { - data = String.format("%-31s", CobolRuntimeException.getOrigStatement()).getBytes(); - } else { - data = String.format("%-31s", "").getBytes(); - } - currField.setDataStorage(new CobolDataStorage(data)); - return currField; - } - - private static final byte[] CONST_STRING_EXCEPTION_OBJECT = "EXCEPTION-OBJECT".getBytes(); - - // cob_intr_exception_statusの実装 - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public static AbstractCobolField funcExceptionStatus() { - byte[] exceptName; - - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(31, (CobolDataStorage) null, attr); - makeFieldEntry(field); - byte[] data = String.format("%-31s", "").getBytes(); - currField.setDataStorage(new CobolDataStorage(data)); - if (CobolRuntimeException.getExceptionCode() != 0) { - try { - exceptName = - CobolRuntimeException.getExceptionName(CobolRuntimeException.getExceptionCode()) - .getBytes(); - } catch (Exception e) { - exceptName = CONST_STRING_EXCEPTION_OBJECT; - } - currField.memcpy(exceptName, exceptName.length); - } - return currField; - } - - // cob_intr_fraction_partの実装 - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcFractionPart(AbstractCobolField srcfield) { - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, - 18, - 18, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); - makeFieldEntry(field); - - currField.moveFrom(srcfield); - return currField; - } - - // cob_intr_seconds_from_formatted_timeの実装 - /** - * TODO: 準備中 - * - * @param format TODO: 準備中 - * @param value TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcSecondsFromFormattedTime( - AbstractCobolField format, AbstractCobolField value) { - int n; - int seconds = 0; - int minutes = 0; - int hours = 0; - boolean secondsSeen = false; - boolean minutesSeen = false; - boolean hoursSeen = false; - String p1; - int p2; - - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 8, 0, 0, null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(4, (CobolDataStorage) null, attr); - makeFieldEntry(field); - - if (value.getSize() < format.getSize()) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); - currField.setInt(0); - return currField; - } - - CobolDataStorage formatData = format.getDataStorage(); - CobolDataStorage valueData = value.getDataStorage(); - - for (n = 0; n < format.getSize() - 1; n++) { - p1 = new String(formatData.getByteArray(n, 2)); - - if ("hh".equals(p1) && !hoursSeen) { - p2 = Integer.parseInt(new String(valueData.getByteArray(n, 2))); - hours = p2; - hoursSeen = true; - continue; - } - if ("mm".equals(p1) && !minutesSeen) { - p2 = Integer.parseInt(new String(valueData.getByteArray(n, 2))); - minutes = p2; - minutesSeen = true; - continue; - } - if ("ss".equals(p1) && !secondsSeen) { - p2 = Integer.parseInt(new String(valueData.getByteArray(n, 2))); - seconds = p2; - secondsSeen = true; - continue; - } - } - - if (hoursSeen && minutesSeen && secondsSeen) { - seconds += hours * 3600 + minutes * 60; - } else { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); - seconds = 0; - } - currField.setInt(seconds); - return currField; - } - - // cob_intr_seconds_past_midnightの実装 - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public static AbstractCobolField funcSecondsPastMidnight() { - int seconds; - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 8, 0, 0, null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(4, (CobolDataStorage) null, attr); - makeFieldEntry(field); - LocalDateTime currDate = LocalDateTime.now(); - seconds = currDate.getHour() * 3600 + currDate.getMinute() * 60 + currDate.getSecond(); - currField.setInt(seconds); - return currField; - } - - // cob_intr_signの実装 - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcSign(AbstractCobolField srcfield) { - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, - 8, - 0, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(4, (CobolDataStorage) null, attr); - makeFieldEntry(field); - - currField.setInt(0); - int n = srcfield.compareTo(currField); - if (n < 0) { - currField.setInt(-1); - } else if (n > 0) { - currField.setInt(1); - } - return currField; - } - - // cob_intr_stored_char_lengthの実装 - /** - * TODO: 準備中 - * - * @param srcfield TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcStoredCharLength(AbstractCobolField srcfield) { - int count; - - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 8, 0, 0, null); - AbstractCobolField field = CobolFieldFactory.makeCobolField(4, (CobolDataStorage) null, attr); - makeFieldEntry(field); - - CobolDataStorage storage = srcfield.getDataStorage(); - for (count = srcfield.getSize(); count > 0; count--) { - if (storage.getByte(count - 1) != ' ') { - break; - } - } - - currField.setInt(count); - return currField; - } - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param length TODO: 準備中 - * @param params TODO: 準備中 - * @param fields TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcSubstitute( - int offset, int length, int params, AbstractCobolField... fields) { - int i, j, k; - int numreps = params / 2; - AbstractCobolField[] f1 = new AbstractCobolField[numreps]; - AbstractCobolField[] f2 = new AbstractCobolField[numreps]; - CobolDataStorage src = fields[0].getDataStorage(); - CobolDataStorage fData1; - int srcSize = fields[0].getSize(); - int fSize1; - StringBuilder rtn = new StringBuilder(); - - for (i = 0; i < params - 1; i++) { - if ((i % 2) == 0) { - f1[i / 2] = fields[i + 1]; - } else { - f2[i / 2] = fields[i + 1]; - } - } - - for (i = 0; i < srcSize; ) { - for (j = 0; j < numreps; j++) { - fData1 = f1[j].getDataStorage(); - fSize1 = f1[j].getSize(); - for (k = fSize1 - 1; k >= 0; k--) { - if (i + k >= srcSize || src.getByte(i + k) != fData1.getByte(k)) { - break; - } - } - if (k < 0) { - rtn.append(f2[j].getString()); - i += fSize1; - break; - } - } - if (j == numreps) { - rtn.append((char) src.getByte(i)); - i++; - } - } - - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); - AbstractCobolField field = - CobolFieldFactory.makeCobolField(rtn.length(), (CobolDataStorage) null, attr); - makeFieldEntry(field); - currField.setDataStorage(new CobolDataStorage(rtn.toString())); - - if (offset > 0) { - calcRefMod(currField, offset, length); - } - return currField; - } - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param length TODO: 準備中 - * @param params TODO: 準備中 - * @param fields TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcSubstituteCase( - int offset, int length, int params, AbstractCobolField... fields) { - int i, j, k; - int numreps = params / 2; - AbstractCobolField[] f1 = new AbstractCobolField[numreps]; - AbstractCobolField[] f2 = new AbstractCobolField[numreps]; - CobolDataStorage src = fields[0].getDataStorage(); - CobolDataStorage fData1; - int srcSize = fields[0].getSize(); - int fSize1; - StringBuilder rtn = new StringBuilder(); - - for (i = 0; i < params - 1; i++) { - if (i % 2 == 0) { - f1[i / 2] = fields[i + 1]; - } else { - f2[i / 2] = fields[i + 1]; - } - } - - for (i = 0; i < srcSize; ) { - for (j = 0; j < numreps; j++) { - fData1 = f1[j].getDataStorage(); - fSize1 = f1[j].getSize(); - for (k = fSize1 - 1; k >= 0; k--) { - if (i + k >= srcSize - || Character.toLowerCase((char) fData1.getByte(k)) - != Character.toLowerCase((char) src.getByte(i + k))) { - break; - } - } - if (k < 0) { - rtn.append(f2[j].getString()); - i += fSize1; - break; - } - } - if (j == numreps) { - rtn.append((char) src.getByte(i)); - i++; - } - } - - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); - AbstractCobolField field = - CobolFieldFactory.makeCobolField(rtn.length(), (CobolDataStorage) null, attr); - makeFieldEntry(field); - - currField.setDataStorage(new CobolDataStorage(rtn.toString())); - if (offset > 0) { - calcRefMod(currField, offset, length); - } - return currField; - } - - // Equivalent to cob_intr_trim - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param length TODO: 準備中 - * @param srcField TODO: 準備中 - * @param direction TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcTrim( - int offset, int length, AbstractCobolField srcField, int direction) { - makeFieldEntry(srcField); - int i; - int srcFieldSize = srcField.getSize(); - CobolDataStorage srcStorage = srcField.getDataStorage(); - for (i = 0; i < srcFieldSize; ++i) { - if (srcStorage.getByte(i) != ' ') { - break; - } - } - if (i == srcFieldSize) { - currField.setSize(1); - currField.getDataStorage().setByte(0, (byte) ' '); - return currField; - } - int beginIndex = 0; - if (direction != 2) { - while (srcStorage.getByte(beginIndex) == ' ') { - ++beginIndex; - } - } - int endIndex = srcFieldSize - 1; - if (direction != 1) { - while (srcStorage.getByte(endIndex) == ' ') { - --endIndex; - } - } - CobolDataStorage currStorage = currField.getDataStorage(); - currField.setSize(endIndex - beginIndex + 1); - for (i = 0; i <= endIndex - beginIndex; ++i) { - currStorage.setByte(i, srcStorage.getByte(beginIndex + i)); - } - if (offset > 0) { - calcRefMod(currField, offset, length); - } - return currField; - } - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param length TODO: 準備中 - * @param srcField TODO: 準備中 - * @param localeField TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcLocaleDate( - int offset, int length, AbstractCobolField srcField, int localeField) { - return funcLocaleDate(offset, length, srcField, null); - } - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param length TODO: 準備中 - * @param srcField TODO: 準備中 - * @param localeField TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcLocaleDate( - int offset, int length, AbstractCobolField srcField, AbstractCobolField localeField) { - AbstractCobolField field = - CobolFieldFactory.makeCobolField( - 0, - (CobolDataStorage) null, - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 10, 0, 0, null)); - int inDate; - - // Convert the input field to an integer - if (srcField.getAttribute().isTypeNumeric()) { - inDate = srcField.getInt(); - } else { - if (srcField.getSize() < 8) { - return errorFuncLocaleDate(field); - } - int p = 0; - inDate = 0; - for (int len = 0; len < 8; ++len, ++p) { - char c = (char) srcField.getDataStorage().getByte(p); - if ('0' <= c && c <= '9') { - inDate = inDate * 10 + (c - '0'); - } else { - return errorFuncLocaleDate(field); - } - } - } - - // Calculate the year, month, and days - int year = inDate / 10000; - if (year < 1601 || year > 9999) { - return errorFuncLocaleDate(field); - } - inDate %= 10000; - - int month = inDate / 100; - if (month < 1 || month > 12) { - return errorFuncLocaleDate(field); - } - - int days = inDate % 100; - if (days < 1 || days > 31) { - return errorFuncLocaleDate(field); - } - - if (isLeapYear(year)) { - if (days > leapMonthDays[month]) { - return errorFuncLocaleDate(field); - } - } else { - if (days > normalMonthDays[month]) { - return errorFuncLocaleDate(field); - } - } - - // Create the date string - Calendar cal = Calendar.getInstance(); - cal.set(year, month - 1, days); - - DateFormat df; - if (localeField != null) { - Locale locale = new Locale(localeField.getString()); - df = DateFormat.getDateInstance(DateFormat.SHORT, locale); - } else { - df = DateFormat.getDateInstance(DateFormat.SHORT); - } - String dateString = df.format(cal.getTime()); - - // Return the result - field.setSize(dateString.length()); - makeFieldEntry(field); - currField.getDataStorage().memcpy(dateString.getBytes()); - if (offset > 0) { - calcRefMod(field, offset, length); - } - return currField; - } - - private static AbstractCobolField errorFuncLocaleDate(AbstractCobolField field) { - field.setSize(10); - makeFieldEntry(field); - currField.getDataStorage().memset((byte) '0', 10); - CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); - return currField; - } - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param length TODO: 準備中 - * @param srcField TODO: 準備中 - * @param localeField TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcLocaleTime( - int offset, int length, AbstractCobolField srcField, int localeField) { - return funcLocaleTime(offset, length, srcField, null); - } - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param length TODO: 準備中 - * @param srcField TODO: 準備中 - * @param localeField TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcLocaleTime( - int offset, int length, AbstractCobolField srcField, AbstractCobolField localeField) { - AbstractCobolField field = - CobolFieldFactory.makeCobolField( - 0, - (CobolDataStorage) null, - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 10, 0, 0, null)); - int inTime; - - // Convert the input field to an integer - if (srcField.getAttribute().isTypeNumeric()) { - inTime = srcField.getInt(); - } else { - if (srcField.getSize() < 6) { - return errorFuncLocaleDate(field); - } - int p = 0; - inTime = 0; - for (int len = 0; len < 6; ++len, ++p) { - char c = (char) srcField.getDataStorage().getByte(p); - if ('0' <= c && c <= '9') { - inTime = inTime * 10 + (c - '0'); - } else { - return errorFuncLocaleDate(field); - } - } - } - - // Calculate the hours, minutes, and seconds - int hours = inTime / 10000; - if (hours < 0 || hours > 24) { - return errorFuncLocaleDate(field); - } - inTime %= 10000; - - int minutes = inTime / 100; - if (minutes < 0 || minutes > 59) { - return errorFuncLocaleDate(field); - } - - int seconds = inTime % 100; - if (seconds < 0 || seconds > 59) { - return errorFuncLocaleDate(field); - } - - // Create the time string - LocalTime time = LocalTime.of(hours, minutes, seconds); - - DateTimeFormatter formatter; - String pattern = "HH:mm:ss"; - if (localeField != null) { - Locale locale = new Locale(localeField.getString()); - formatter = DateTimeFormatter.ofPattern(pattern, locale); - } else { - formatter = DateTimeFormatter.ofPattern(pattern); - } - String timeString = time.format(formatter); - - // Return the result - field.setSize(timeString.length()); - makeFieldEntry(field); - currField.getDataStorage().memcpy(timeString.getBytes()); - if (offset > 0) { - calcRefMod(field, offset, length); - } - return currField; - } - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param length TODO: 準備中 - * @param srcField TODO: 準備中 - * @param localeField TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcLocaleTimeFromSeconds( - int offset, int length, AbstractCobolField srcField, int localeField) { - return funcLocaleTime(offset, length, srcField, null); - } - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param length TODO: 準備中 - * @param srcField TODO: 準備中 - * @param localeField TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField funcLocaleTimeFromSeconds( - int offset, int length, AbstractCobolField srcField, AbstractCobolField localeField) { - AbstractCobolField field = - CobolFieldFactory.makeCobolField( - 0, - (CobolDataStorage) null, - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 10, 0, 0, null)); - int inTime; - - // Convert the input field to an integer - if (srcField.getAttribute().isTypeNumeric()) { - inTime = srcField.getInt(); - } else { - return errorFuncLocaleDate(field); - } - - // Calculate the hours, minutes, and seconds - int hours = inTime / 3600; - inTime %= 3600; - int minutes = inTime / 60; - int seconds = inTime % 60; - - // Create the time string - LocalTime time = LocalTime.of(hours, minutes, seconds); - - DateTimeFormatter formatter; - String pattern = "HH:mm:ss"; - if (localeField != null) { - Locale locale = new Locale(localeField.getString()); - formatter = DateTimeFormatter.ofPattern(pattern, locale); - } else { - formatter = DateTimeFormatter.ofPattern(pattern); - } - String timeString = time.format(formatter); - - // Return the result - field.setSize(timeString.length()); - makeFieldEntry(field); - currField.getDataStorage().memcpy(timeString.getBytes()); - if (offset > 0) { - calcRefMod(field, offset, length); - } - return currField; - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.common; + +import java.math.BigDecimal; +import java.text.DateFormat; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Locale; +import java.util.Random; +import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; +import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; +import jp.osscons.opensourcecobol.libcobj.data.CobolDecimal; +import jp.osscons.opensourcecobol.libcobj.data.CobolFieldAttribute; +import jp.osscons.opensourcecobol.libcobj.data.CobolFieldFactory; +import jp.osscons.opensourcecobol.libcobj.data.CobolNationalField; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionId; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; +import jp.osscons.opensourcecobol.libcobj.file.CobolFile; + +/** TODO: 準備中 */ +public class CobolIntrinsic { + + private static int[] normalDays = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}; + private static int[] leapDays = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366}; + private static int[] normalMonthDays = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + private static int[] leapMonthDays = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + private static final int DEPTH_LEVEL = 8; + private static final int sizeOfDouble = 8; + private static int currEntry = 0; + private static AbstractCobolField currField = null; + private static AbstractCobolField[] calcField = new AbstractCobolField[DEPTH_LEVEL]; + private static Random random = new Random(); + private static byte[] localeBuff; + private static final byte[] byteArray00 = "00".getBytes(AbstractCobolField.charSetSJIS); + + /** libcob/intrinsicのmake_double_entryの実装 */ + private static void makeDoubleEntry() { + CobolDataStorage s = new CobolDataStorage(sizeOfDouble + 1); + + CobolFieldAttribute newAttr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE, + 18, + 9, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + AbstractCobolField newField = CobolFieldFactory.makeCobolField(sizeOfDouble, s, newAttr); + + calcField[currEntry] = newField; + currField = newField; + ++currEntry; + if (currEntry >= DEPTH_LEVEL) { + currEntry = 0; + } + } + + /** libcob/intrinsicのmake_field_entryの実装 */ + private static void makeFieldEntry(AbstractCobolField f) { + AbstractCobolField newField = + CobolFieldFactory.makeCobolField( + f.getSize(), new CobolDataStorage(f.getSize() + 1), f.getAttribute()); + calcField[currEntry] = newField; + currField = calcField[currEntry]; + + ++currEntry; + if (currEntry >= DEPTH_LEVEL) { + currEntry = 0; + } + } + + /** + * libcob/intrinsicのcob_intr_ordの実装 + * + * @param year TODO: 準備中 + * @return TODO: 準備中 + */ + private static boolean isLeapYear(int year) { + return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)); + } + + // libcob/intrinsicのcob_init_intrinsicの実装 + /** TODO: 準備中 */ + public static void init() { + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); + for (int i = 0; i < DEPTH_LEVEL; ++i) { + calcField[i] = CobolFieldFactory.makeCobolField(256, new CobolDataStorage(256), attr); + } + } + + // libcob/intrinsicのcob_intr_get_doubleの実装 + /** + * TODO: 準備中 + * + * @param d + * @return + */ + private static double intrGetDouble(CobolDecimal d) { + double v = d.getValue().doubleValue(); + int n = d.getScale(); + for (int i = 0; i < Math.abs(n); ++i) { + if (n > 0) { + v /= 10; + } else { + v *= 10; + } + } + return v; + } + + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + * @param offset TODO: 準備中 + * @param length TODO: 準備中 + */ + private static void calcRefMod(AbstractCobolField f, int offset, int length) { + if (offset <= f.getSize()) { + int calcoff = offset - 1; + int size = f.getSize() - calcoff; + if (length > 0 && length < size) { + size = length; + } + f.setSize(size); + if (calcoff > 0) { + CobolDataStorage tmp = new CobolDataStorage(size); + tmp.memcpy(f.getDataStorage().getSubDataStorage(calcoff), size); + f.getDataStorage().memcpy(tmp, size); + } + } + } + + /** + * TODO: 準備中 + * + * @param f1 TODO: 準備中 + * @param op TODO: 準備中 + * @param f2 TODO: 準備中 + * @return TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static AbstractCobolField intrBinop(AbstractCobolField f1, int op, AbstractCobolField f2) + throws CobolStopRunException { + CobolDecimal d1 = new CobolDecimal(); + CobolDecimal d2 = new CobolDecimal(); + d1.setField(f1); + d2.setField(f2); + + switch ((char) op) { + case '+': + d1.add(d2); + break; + case '-': + d1.sub(d2); + break; + case '*': + d1.mul(d2); + break; + case '/': + d1.div(d2); + break; + case '^': + d1.pow(d2); + break; + default: + break; + } + + int attrsign = 0; + if (d1.getValue().signum() < 0) { + attrsign = CobolFieldAttribute.COB_FLAG_HAVE_SIGN; + } else { + attrsign = 0; + } + + int size = sizeInBase10(d1.getValue()); + if (d1.getScale() > size) { + size = d1.getScale(); + } + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, + size, + d1.getScale(), + attrsign, + null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(size, (CobolDataStorage) null, attr); + makeFieldEntry(field); + d1.getDisplayField(currField, 0); + return currField; + } + + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcLength(AbstractCobolField srcfield) { + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 8, 0, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(4, (CobolDataStorage) null, attr); + makeFieldEntry(field); + currField.setInt(srcfield.getSize()); + return currField; + } + + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcInteger(AbstractCobolField srcfield) { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, + 18, + 0, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); + makeFieldEntry(field); + + CobolDecimal d1 = new CobolDecimal(); + d1.setField(srcfield); + if (d1.getValue().signum() >= 0) { + try { + d1.getField(currField, 0); + } catch (CobolStopRunException e) { + return null; + } + return currField; + } + + boolean isScalePositive = d1.getScale() > 0; + BigDecimal val = d1.getValue(); + for (int i = 0; i < Math.abs(d1.getScale()); ++i) { + if (isScalePositive) { + val = val.divide(BigDecimal.TEN); + } else { + val = val.multiply(BigDecimal.TEN); + } + } + + // Rouding to negative infinity + BigDecimal[] vals = val.divideAndRemainder(BigDecimal.ONE); + if (vals[1].signum() != 0) { + vals[0] = vals[0].subtract(BigDecimal.ONE); + } + + try { + new CobolDecimal(vals[0], 0).getField(currField, 0); + } catch (CobolStopRunException e) { + return null; + } + return currField; + } + + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcIntegerPart(AbstractCobolField srcfield) { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, + 18, + 0, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); + + makeFieldEntry(field); + currField.moveFrom(srcfield); + return currField; + } + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param length TODO: 準備中 + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcUpperCase( + int offset, int length, AbstractCobolField srcfield) { + makeFieldEntry(srcfield); + int size = srcfield.getSize(); + CobolDataStorage currStorage = currField.getDataStorage(); + CobolDataStorage srcStorage = srcfield.getDataStorage(); + for (int i = 0; i < size; ++i) { + currStorage.setByte(i, (byte) Character.toUpperCase(srcStorage.getByte(i))); + } + if (offset > 0) { + calcRefMod(currField, offset, length); + } + return currField; + } + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param length TODO: 準備中 + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcLowerCase( + int offset, int length, AbstractCobolField srcfield) { + makeFieldEntry(srcfield); + int size = srcfield.getSize(); + CobolDataStorage currStorage = currField.getDataStorage(); + CobolDataStorage srcStorage = srcfield.getDataStorage(); + for (int i = 0; i < size; ++i) { + currStorage.setByte(i, (byte) Character.toLowerCase(srcStorage.getByte(i))); + } + if (offset > 0) { + calcRefMod(currField, offset, length); + } + return currField; + } + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param length TODO: 準備中 + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcReverse( + int offset, int length, AbstractCobolField srcfield) { + makeFieldEntry(srcfield); + int size = srcfield.getSize(); + CobolDataStorage currStorage = currField.getDataStorage(); + CobolDataStorage srcStorage = srcfield.getDataStorage(); + for (int i = 0; i < size; ++i) { + currStorage.setByte(i, srcStorage.getByte(srcfield.getSize() - i - 1)); + } + if (offset > 0) { + calcRefMod(currField, offset, length); + } + return currField; + } + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param length TODO: 準備中 + * @param f TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcWhenCompiled( + int offset, int length, AbstractCobolField f) { + makeFieldEntry(f); + currField.getDataStorage().memcpy(f.getDataStorage(), f.getSize()); + if (offset > 0) { + calcRefMod(currField, offset, length); + } + return currField; + } + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcCurrentDate(int offset, int length) { + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(21, (CobolDataStorage) null, attr); + makeFieldEntry(field); + // TODO Time Zoneを表示する機能を取り入れる + + String dateString = + String.format( + "%4d%02d%02d%02d%02d%02d%02d00000", + CobolUtil.cal.get(Calendar.YEAR), + CobolUtil.cal.get(Calendar.MONTH) + 1, + CobolUtil.cal.get(Calendar.DAY_OF_MONTH), + CobolUtil.cal.get(Calendar.HOUR_OF_DAY), + CobolUtil.cal.get(Calendar.MINUTE), + CobolUtil.cal.get(Calendar.SECOND), + CobolUtil.cal.get(Calendar.MILLISECOND) / 10); + currField.getDataStorage().memcpy(dateString.getBytes(AbstractCobolField.charSetSJIS)); + + if (offset > 0) { + calcRefMod(currField, offset, length); + } + return currField; + } + + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcChar(AbstractCobolField srcfield) { + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(1, (CobolDataStorage) null, attr); + makeFieldEntry(field); + + int i = srcfield.getInt(); + if (i < 1 || i > 256) { + currField.getDataStorage().setByte(0, (byte) 0); + } else { + currField.getDataStorage().setByte(0, (byte) (i - 1)); + } + return currField; + } + + // libcob/intrinsicのcob_intr_ordの実装 + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcOrd(AbstractCobolField srcfield) { + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 8, 0, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(4, (CobolDataStorage) null, attr); + makeFieldEntry(field); + + currField.setInt(srcfield.getDataStorage().getByte(0) + 1); + return currField; + } + + // libcob/intrinsicのcob_intr_date_of_integerの実装 + /** + * TODO: 準備中 + * + * @param srcdays TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcDateOfInteger(AbstractCobolField srcdays) { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, 8, 0, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); + makeFieldEntry(field); + + CobolRuntimeException.setException(0); + int days = srcdays.getInt(); + + if (days < 1 || days > 3067671) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); + currField.getDataStorage().memset((byte) '0', 8); + return currField; + } + + int leapyear = 365; + int baseyear = 1601; + while (days > leapyear) { + days -= leapyear; + ++baseyear; + if (isLeapYear(baseyear)) { + leapyear = 366; + } else { + leapyear = 365; + } + } + int i; + for (i = 0; i < 13; ++i) { + if (isLeapYear(baseyear)) { + if (days <= leapDays[i]) { + days -= leapDays[i - 1]; + break; + } + } else { + if (days <= normalDays[i]) { + days -= normalDays[i - 1]; + break; + } + } + } + String dateString = String.format("%04d%02d%02d", baseyear, i, days); + currField.getDataStorage().memcpy(dateString.getBytes(AbstractCobolField.charSetSJIS)); + return currField; + } + + // libcob/intrinsicのcob_intr_day_of_integerの実装 + /** + * TODO: 準備中 + * + * @param srcdays TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcDayOfInteger(AbstractCobolField srcdays) { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, 7, 0, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(7, (CobolDataStorage) null, attr); + makeFieldEntry(field); + + CobolRuntimeException.setException(0); + int days = srcdays.getInt(); + + if (days < 1 || days > 3067671) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); + currField.getDataStorage().memset((byte) '0', 8); + return currField; + } + + int leapyear = 365; + int baseyear = 1601; + while (days > leapyear) { + days -= leapyear; + ++baseyear; + if (isLeapYear((baseyear))) { + leapyear = 366; + } else { + leapyear = 365; + } + } + String dateString = String.format("%04d%03d", baseyear, days); + currField.getDataStorage().memcpy(dateString.getBytes(AbstractCobolField.charSetSJIS)); + return currField; + } + + // libcob/intrinsicのcob_intr_integer_of_dateの実装 + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcIntegerOfDate(AbstractCobolField srcfield) { + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 8, 0, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(4, (CobolDataStorage) null, attr); + makeFieldEntry(field); + + CobolRuntimeException.setException(0); + int indate = srcfield.getInt(); + int year = indate / 10000; + if (year < 1601 || year > 9999) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); + currField.setInt(0); + return currField; + } + indate %= 10000; + int month = indate / 100; + if (month < 1 || month > 12) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); + currField.setInt(0); + return currField; + } + int days = indate % 100; + if (days < 1 || days > 31) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); + currField.setInt(0); + return currField; + } + if (isLeapYear(year)) { + if (days > leapMonthDays[month]) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); + currField.setInt(0); + return currField; + } + } else { + if (days > normalMonthDays[month]) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); + currField.setInt(0); + return currField; + } + } + + int totaldays = 0; + int baseyear = 1601; + while (baseyear != year) { + if (isLeapYear(baseyear)) { + totaldays += 366; + } else { + totaldays += 365; + } + ++baseyear; + } + + if (isLeapYear(baseyear)) { + totaldays += leapDays[month - 1]; + } else { + totaldays += normalDays[month - 1]; + } + + totaldays += days; + currField.setInt(totaldays); + return currField; + } + + // libcob/intrinsicのcob_intr_integer_of_dayの実装 + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcIntegerOfDay(AbstractCobolField srcfield) { + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 8, 0, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(4, (CobolDataStorage) null, attr); + makeFieldEntry(field); + + CobolRuntimeException.setException(0); + int indate = srcfield.getInt(); + int year = indate / 1000; + if (year < 1601 || year > 9999) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); + currField.setInt(0); + return currField; + } + int days = indate % 1000; + if (days < 1 || days > 365 + (isLeapYear(year) ? 1 : 0)) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); + currField.setInt(0); + return currField; + } + int totaldays = 0; + int baseyear = 1601; + while (baseyear != year) { + if (isLeapYear(baseyear)) { + totaldays += 366; + } else { + totaldays += 365; + } + ++baseyear; + } + totaldays += days; + currField.setInt(totaldays); + return currField; + } + + // libcob/intrinsicのcob_intr_integer_of_dayの実装 + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcFactorial(AbstractCobolField srcfield) { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 18, 0, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); + makeFieldEntry(field); + + CobolRuntimeException.setException(0); + int srcval = srcfield.getInt(); + if (srcval < 0) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); + currField.setInt(0); + return currField; + } + BigDecimal d = BigDecimal.ONE; + for (int i = 2; i <= srcval; ++i) { + d = d.multiply(new BigDecimal(i)); + } + try { + new CobolDecimal(d, 0).getField(currField, 0); + } catch (CobolStopRunException e) { + return null; + } + return currField; + } + + private static CobolDecimal mathFunctionBefore1(AbstractCobolField srcfield) { + CobolDecimal d1 = new CobolDecimal(); + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, + 18, + 17, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); + d1.setField(srcfield); + makeFieldEntry(field); + return d1; + } + + private static CobolDecimal mathFunctionBefore2(AbstractCobolField srcfield) { + CobolDecimal d1 = new CobolDecimal(); + d1.setField(srcfield); + makeDoubleEntry(); + return d1; + } + + private static AbstractCobolField mathFunctionAfter1(double mathd2) { + if (Double.isNaN(mathd2) + || mathd2 == Double.POSITIVE_INFINITY + || mathd2 == Double.NEGATIVE_INFINITY) { + currField.setInt(0); + return currField; + } + long result = (long) mathd2; + mathd2 -= result; + for (int i = 0; i < 17; ++i) { + mathd2 *= 10; + int tempres = (int) mathd2; + result *= 10; + result += tempres; + mathd2 -= tempres; + } + currField.getDataStorage().set(result); + return currField; + } + + private static AbstractCobolField mathFunctionAfter2(double mathd2) { + if (Double.isNaN(mathd2) + || mathd2 == Double.POSITIVE_INFINITY + || mathd2 == Double.NEGATIVE_INFINITY) { + currField.setInt(0); + return currField; + } + currField.getDataStorage().set(mathd2); + return currField; + } + + // libcob/intrinsicのcob_intr_expの実装 + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcExp(AbstractCobolField srcfield) { + CobolDecimal d1 = mathFunctionBefore2(srcfield); + double mathd2 = Math.pow(2.7182818284590452354, intrGetDouble(d1)); + return mathFunctionAfter2(mathd2); + } + + // libcob/intrinsicのcob_intr_exp10の実装 + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcExp10(AbstractCobolField srcfield) { + CobolDecimal d1 = mathFunctionBefore2(srcfield); + double mathd2 = Math.pow(10, intrGetDouble(d1)); + return mathFunctionAfter2(mathd2); + } + + // libcob/intrinsicのcob_intr_absの実装 + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcAbs(AbstractCobolField srcfield) { + makeFieldEntry(srcfield); + CobolDecimal d1 = srcfield.getDecimal(); + d1.setValue(d1.getValue().abs()); + try { + d1.getField(currField, 0); + } catch (CobolStopRunException e) { + return null; + } + return currField; + } + + // libcob/intrinsicのcob_intr_acosの実装 + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcAcos(AbstractCobolField srcfield) { + CobolDecimal d1 = mathFunctionBefore1(srcfield); + double mathd2 = Math.acos(intrGetDouble(d1)); + return mathFunctionAfter1(mathd2); + } + + // libcob/intrinsicのcob_intr_asinの実装 + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcAsin(AbstractCobolField srcfield) { + CobolDecimal d1 = mathFunctionBefore1(srcfield); + double mathd2 = Math.asin(intrGetDouble(d1)); + return mathFunctionAfter1(mathd2); + } + + // libcob/intrinsicのcob_intr_atanの実装 + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcAtan(AbstractCobolField srcfield) { + CobolDecimal d1 = mathFunctionBefore1(srcfield); + double mathd2 = Math.atan(intrGetDouble(d1)); + return mathFunctionAfter1(mathd2); + } + + // libcob/intrinsicのcob_intr_cosの実装 + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcCos(AbstractCobolField srcfield) { + CobolDecimal d1 = mathFunctionBefore1(srcfield); + double mathd2 = Math.cos(intrGetDouble(d1)); + return mathFunctionAfter1(mathd2); + } + + // libcob/intrinsicのcob_intr_logの実装 + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcLog(AbstractCobolField srcfield) { + CobolDecimal d1 = mathFunctionBefore2(srcfield); + double mathd2 = Math.log(intrGetDouble(d1)); + return mathFunctionAfter2(mathd2); + } + + // libcob/intrinsicのcob_intr_log10の実装 + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcLog10(AbstractCobolField srcfield) { + CobolDecimal d1 = mathFunctionBefore2(srcfield); + double mathd2 = Math.log10(intrGetDouble(d1)); + return mathFunctionAfter2(mathd2); + } + + // libcob/intrinsicのcob_intr_sinの実装 + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcSin(AbstractCobolField srcfield) { + CobolDecimal d1 = mathFunctionBefore1(srcfield); + double mathd2 = Math.sin(intrGetDouble(d1)); + return mathFunctionAfter1(mathd2); + } + + // libcob/intrinsicのcob_intr_sqrtの実装 + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcSqrt(AbstractCobolField srcfield) { + CobolDecimal d1 = mathFunctionBefore2(srcfield); + double mathd2 = Math.sqrt(intrGetDouble(d1)); + return mathFunctionAfter2(mathd2); + } + + // libcob/intrinsicのcob_intr_tanの実装 + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcTan(AbstractCobolField srcfield) { + CobolDecimal d1 = mathFunctionBefore2(srcfield); + double mathd2 = Math.tan(intrGetDouble(d1)); + return mathFunctionAfter2(mathd2); + } + + // libcob/intrinsicのcob_intr_numvalの実装 + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcNumval(AbstractCobolField srcfield) { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, + 18, + 0, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); + + CobolDataStorage s = srcfield.getDataStorage(); + boolean sign = false; + boolean decimalSeen = false; + long llval = 0; + int integerDigits = 0; + int decimalDigits = 0; + StringBuilder integerBuff = new StringBuilder(); + StringBuilder decimalBuff = new StringBuilder(); + for (int i = 0; i < srcfield.getSize(); ++i) { + if (i < srcfield.getSize() - 1) { + if ((Character.toUpperCase(s.getByte(i)) == 'C' + && Character.toUpperCase(s.getByte(i + 1)) == 'R') + || (Character.toUpperCase(s.getByte(i)) == 'D' + && Character.toUpperCase(s.getByte(i + 1)) == 'B')) { + sign = true; + break; + } + } + char c = (char) s.getByte(i); + if (c == ' ' || c == '+') { + continue; + } + if (c == '-') { + sign = true; + continue; + } + if (c == CobolModule.getCurrentModule().decimal_point) { + decimalSeen = true; + continue; + } + if (c >= '0' && c <= '9') { + llval *= 10; + llval += c - '0'; + if (decimalSeen) { + decimalBuff.append(c); + decimalDigits++; + } else { + integerBuff.append(c); + integerDigits++; + } + } + if (integerDigits + decimalDigits > 30) { + break; + } + } + if (integerDigits > 0) { + integerBuff.setCharAt(0, '0'); + } + if (decimalDigits > 0) { + decimalBuff.setCharAt(0, '0'); + } + if (sign) { + llval = -llval; + } + if (integerDigits + decimalDigits <= 18) { + attr.setScale(decimalDigits); + makeFieldEntry(field); + currField.getDataStorage().set(llval); + } else { + String dataString = + String.format( + "%s%s.%s", + sign ? "-" : "", integerBuff.toString(), decimalBuff.toString()); + double val = Double.parseDouble(dataString); + makeDoubleEntry(); + currField.getDataStorage().set(val); + } + return currField; + } + + // libcob/intrinsicのcob_intr_numval_cの実装 + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @param currency TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcNumvalC( + AbstractCobolField srcfield, AbstractCobolField currency) { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, + 18, + 0, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); + + boolean sign = false; + boolean decimalSeen = false; + long llval = 0; + int integerDigits = 0; + int decimalDigits = 0; + StringBuilder integerBuff = new StringBuilder(); + StringBuilder decimalBuff = new StringBuilder(); + + CobolDataStorage currencyData = null; + if (currency != null) { + if (currency.getSize() < srcfield.getSize()) { + currencyData = currency.getDataStorage(); + } + } + for (int i = 0; i < srcfield.getSize(); ++i) { + char c = (char) srcfield.getDataStorage().getByte(i); + if (i < srcfield.getSize() - 1) { + char cc = (char) srcfield.getDataStorage().getByte(i + 1); + if ((Character.toUpperCase(c) == 'C' && Character.toUpperCase(cc) == 'R') + || (Character.toUpperCase(c) == 'D' && Character.toUpperCase(cc) == 'B')) { + sign = true; + break; + } + } + if (currencyData != null) { + if (i < srcfield.getSize() - currency.getSize()) { + if (currencyData.memcmp( + srcfield.getDataStorage().getSubDataStorage(i), + currency.getSize()) + == 0) { + i += (currency.getSize() - 1); + continue; + } + } + } + if (c == ' ' || c == '+') { + continue; + } + if (c == '-') { + sign = true; + continue; + } + if (c == CobolModule.getCurrentModule().decimal_point) { + decimalSeen = true; + continue; + } + if (c == CobolModule.getCurrentModule().currency_symbol) { + continue; + } + if (c >= '0' && c <= '9') { + llval *= 10; + llval += c - '0'; + if (decimalSeen) { + decimalBuff.append(c); + decimalDigits++; + } else { + integerBuff.append(c); + integerDigits++; + } + } + if (integerDigits + decimalDigits > 30) { + break; + } + } + if (integerDigits > 0) { + integerBuff.setCharAt(0, '0'); + } + if (decimalDigits > 0) { + decimalBuff.setCharAt(0, '0'); + } + if (sign) { + llval = -llval; + } + if (integerDigits + decimalDigits <= 18) { + attr.setScale(decimalDigits); + makeFieldEntry(field); + currField.getDataStorage().set(llval); + } else { + String dataString = + String.format( + "%s%s.%s", + sign ? "-" : "", integerBuff.toString(), decimalBuff.toString()); + double val = Double.parseDouble(dataString); + makeDoubleEntry(); + currField.getDataStorage().set(val); + } + return currField; + } + + /** + * このメソッドは未実装 + * + * @param n このメソッドは未実装 + * @param currency このメソッドは未実装 + * @return null + */ + public static AbstractCobolField funcNumvalC(int n, AbstractCobolField currency) { + // TODO + return null; + } + + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcNumvalC(AbstractCobolField srcfield, int n) { + return funcNumvalC(srcfield, null); + } + + /** + * このメソッドは未実装 + * + * @param n このメソッドは未実装 + * @param m このメソッドは未実装 + * @return null + */ + public static AbstractCobolField funcNumvalC(int n, int m) { + // TODO + return null; + } + + // libcob/intrinsicのcob_intr_annuityの実装 + /** + * TODO: 準備中 + * + * @param srcfield1 TODO: 準備中 + * @param srcfield2 TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcAnnuity( + AbstractCobolField srcfield1, AbstractCobolField srcfield2) { + makeDoubleEntry(); + CobolDecimal d1 = new CobolDecimal(); + CobolDecimal d2 = new CobolDecimal(); + d1.setField(srcfield1); + d2.setField(srcfield2); + + double mathd1 = intrGetDouble(d1); + double mathd2 = intrGetDouble(d2); + if (mathd1 == 0) { + mathd1 = 1.0 / mathd2; + currField.getDataStorage().set(mathd1); + return currField; + } + + mathd1 /= (1.0 - Math.pow(mathd1 + 1.0, 0.0 - mathd2)); + currField.getDataStorage().set(mathd1); + return currField; + } + + private static int sizeInBase10(BigDecimal d1) { + String s = d1.toPlainString(); + int begin = s.charAt(0) == '-' ? 0 : -1; + int pointIndex = s.indexOf('.'); + int end = pointIndex < 0 ? s.length() : pointIndex; + return end - begin - 1; + } + + // libcob/intrinsicのcob_intr_sumの実装 + /** + * TODO: 準備中 + * + * @param params TODO: 準備中 + * @param fields TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcSum(int params, AbstractCobolField... fields) { + CobolDecimal d1 = new CobolDecimal(); + CobolDecimal d2 = new CobolDecimal(); + d1.setValue(BigDecimal.ZERO); + + int scale = 0; + for (AbstractCobolField f : fields) { + if (f.getAttribute().getScale() > scale) { + scale = f.getAttribute().getScale(); + } + d2.setField(f); + d1.add(d2); + } + + int size = sizeInBase10(d1.getValue()); + AbstractCobolField field; + if (size < 19) { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, + 18, + scale, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + field = CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); + } else { + if (d1.getScale() > size) { + size = d1.getScale(); + } + if (scale > size) { + size = scale; + } + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, + size, + scale, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + field = CobolFieldFactory.makeCobolField(size, (CobolDataStorage) null, attr); + } + makeFieldEntry(field); + try { + d1.getField(currField, 0); + } catch (CobolStopRunException e) { + return null; + } + return currField; + } + + // libcob/intrinsicのcob_intr_ord_minの実装 + /** + * TODO: 準備中 + * + * @param params TODO: 準備中 + * @param fields TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcOrdMin(int params, AbstractCobolField... fields) { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, 8, 0, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); + makeFieldEntry(field); + + if (fields.length <= 1) { + currField.setInt(0); + return currField; + } + + AbstractCobolField basef = fields[0]; + int ordmin = 0; + for (int i = 1; i < fields.length; ++i) { + AbstractCobolField f = fields[i]; + if (f.compareTo(basef) < 0) { + basef = f; + ordmin = i; + } + } + + currField.setLong((long) ordmin + 1); + return currField; + } + + // libcob/intrinsicのcob_intr_ord_maxの実装 + /** + * TODO: 準備中 + * + * @param params TODO: 準備中 + * @param fields TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcOrdMax(int params, AbstractCobolField... fields) { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, 8, 0, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); + makeFieldEntry(field); + + if (fields.length <= 1) { + currField.setInt(0); + return currField; + } + + AbstractCobolField basef = fields[0]; + int ordmax = 0; + for (int i = 1; i < fields.length; ++i) { + AbstractCobolField f = fields[i]; + if (f.compareTo(basef) > 0) { + basef = f; + ordmax = i; + } + } + + currField.setLong((long) ordmax + 1); + return currField; + } + + // libcob/intrinsicのcob_intr_minの実装 + /** + * TODO: 準備中 + * + * @param params TODO: 準備中 + * @param fields TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcMin(int params, AbstractCobolField... fields) { + AbstractCobolField beasef = fields[0]; + for (int i = 1; i < fields.length; ++i) { + AbstractCobolField f = fields[i]; + if (f.compareTo(beasef) < 0) { + beasef = f; + } + } + + return beasef; + } + + // libcob/intrinsicのcob_intr_maxの実装 + /** + * TODO: 準備中 + * + * @param params TODO: 準備中 + * @param fields TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcMax(int params, AbstractCobolField... fields) { + AbstractCobolField beasef = fields[0]; + for (int i = 1; i < fields.length; ++i) { + AbstractCobolField f = fields[i]; + if (f.compareTo(beasef) > 0) { + beasef = f; + } + } + + return beasef; + } + + // libcob/intrinsicのcob_intr_midrangeの実装 + /** + * TODO: 準備中 + * + * @param params TODO: 準備中 + * @param fields TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcMidrange(int params, AbstractCobolField... fields) { + makeDoubleEntry(); + AbstractCobolField basemin = fields[0]; + AbstractCobolField basemax = fields[0]; + for (int i = 1; i < params; ++i) { + AbstractCobolField f = fields[i]; + if (f.compareTo(basemin) < 0) { + basemin = f; + } + if (f.compareTo(basemax) > 0) { + basemax = f; + } + } + + CobolDecimal d1 = new CobolDecimal(); + CobolDecimal d2 = new CobolDecimal(); + d1.setField(basemin); + d2.setField(basemax); + d1.add(d2); + d2 = new CobolDecimal(new BigDecimal(2), 0); + try { + d1.div(d2); + d1.getField(currField, 0); + } catch (CobolStopRunException e) { + return null; + } + return currField; + } + + // libcob/intrinsicのcob_intr_medianの実装 + /** + * TODO: 準備中 + * + * @param params TODO: 準備中 + * @param fields TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcMedian(int params, AbstractCobolField... fields) { + if (fields.length == 1) { + return fields[0]; + } + + AbstractCobolField[] fieldAlloc = new AbstractCobolField[fields.length]; + + for (int i = 0; i < params; ++i) { + fieldAlloc[i] = fields[i]; + } + + Arrays.sort(fieldAlloc, (a, b) -> a.compareTo(b)); + int i = params / 2; + if (params % 2 != 0) { + return fieldAlloc[i]; + } else { + makeDoubleEntry(); + CobolDecimal d1 = new CobolDecimal(); + CobolDecimal d2 = new CobolDecimal(); + d1.setField(fieldAlloc[i]); + d2.setField(fieldAlloc[i - 1]); + d1.add(d2); + d2 = new CobolDecimal(new BigDecimal(2), 0); + try { + d1.div(d2); + d1.getField(currField, 0); + } catch (CobolStopRunException e) { + return null; + } + return currField; + } + } + + // libcob/intrinsicのcob_intr_medianの実装 + /** + * TODO: 準備中 + * + * @param pramas TODO: 準備中 + * @param fields TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcMean(int pramas, AbstractCobolField... fields) { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, + 18, + 0, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); + CobolDecimal d1 = new CobolDecimal(BigDecimal.ZERO); + CobolDecimal d2 = new CobolDecimal(); + + for (AbstractCobolField f : fields) { + d2.setField(f); + d1.add(d2); + } + + d2 = new CobolDecimal(new BigDecimal(fields.length), 0); + try { + d1.div(d2); + } catch (CobolStopRunException e) { + return null; + } + + CobolDataStorage storage = new CobolDataStorage(8); + field.setDataStorage(storage); + try { + d1.getField(field, 0); + } catch (CobolStopRunException e) { + return null; + } + long n = storage.longValue(); + int i = 0; + while (n != 0) { + n /= 10; + ++i; + } + field.setDataStorage(null); + if (i <= 18) { + attr.setScale(18 - i); + } + makeFieldEntry(field); + try { + d1.getField(currField, 0); + } catch (CobolStopRunException e) { + return null; + } + return currField; + } + + // libcob/intrinsicのcob_intr_modの実装 + /** + * TODO: 準備中 + * + * @param srcfield1 TODO: 準備中 + * @param srcfield2 TODO: 準備中 + * @return TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static AbstractCobolField funcMod( + AbstractCobolField srcfield1, AbstractCobolField srcfield2) + throws CobolStopRunException { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, + 18, + 0, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); + CobolDecimal d1 = new CobolDecimal(); + CobolDecimal d2 = new CobolDecimal(); + makeFieldEntry(field); + + AbstractCobolField f1 = funcInteger(intrBinop(srcfield1, '/', srcfield2)); + d1.setField(srcfield2); + d2.setField(f1); + d2.mul(d1); + d1.setField(srcfield1); + d1.sub(d2); + try { + d1.getField(currField, 0); + } catch (CobolStopRunException e) { + return null; + } + return currField; + } + + // libcob/intrinsicのcob_intr_rangeの実装 + /** + * TODO: 準備中 + * + * @param params TODO: 準備中 + * @param fields TODO: 準備中 + * @return TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static AbstractCobolField funcRange(int params, AbstractCobolField... fields) + throws CobolStopRunException { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, + 18, + 0, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); + CobolDecimal d1 = new CobolDecimal(); + CobolDecimal d2 = new CobolDecimal(); + + AbstractCobolField basemin = fields[0]; + AbstractCobolField basemax = fields[0]; + for (int i = 1; i < fields.length; ++i) { + AbstractCobolField f = fields[i]; + if (f.compareTo(basemin) < 0) { + basemin = f; + } + if (f.compareTo(basemax) > 0) { + basemax = f; + } + } + + attr.setScale(basemin.getAttribute().getScale()); + if (basemax.getAttribute().getScale() > attr.getScale()) { + attr.setScale(basemax.getAttribute().getScale()); + } + makeFieldEntry(field); + d1.setField(basemax); + d2.setField(basemin); + d1.sub(d2); + d1.getField(currField, 0); + return currField; + } + + // libcob/intrinsicのcob_intr_remの実装 + /** + * TODO: 準備中 + * + * @param srcfield1 TODO: 準備中 + * @param srcfield2 TODO: 準備中 + * @return TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static AbstractCobolField funcRem( + AbstractCobolField srcfield1, AbstractCobolField srcfield2) + throws CobolStopRunException { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, + 18, + 0, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); + AbstractCobolField f1 = funcIntegerPart(intrBinop(srcfield1, '/', srcfield2)); + CobolDecimal d1 = new CobolDecimal(); + CobolDecimal d2 = new CobolDecimal(); + + d1.setField(srcfield2); + d2.setField(f1); + d2.mul(d1); + d1.setField(srcfield1); + d1.sub(d2); + + attr.setScale(srcfield1.getAttribute().getScale()); + if (srcfield2.getAttribute().getScale() > attr.getScale()) { + attr.setScale(srcfield2.getAttribute().getScale()); + } + makeFieldEntry(field); + d1.getField(currField, 0); + return currField; + } + + // libcob/intrinsicのcob_intr_randomの実装 + /** + * TODO: 準備中 + * + * @param prams TODO: 準備中 + * @param fields TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcRandom(int prams, AbstractCobolField... fields) { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, + 18, + 0, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); + + if (fields.length > 0) { + AbstractCobolField f = fields[0]; + int seed = f.getInt(); + if (seed < 0) { + seed = 0; + } + random.setSeed(seed); + } + + int r = random.nextInt(1000000001); + + int exp10 = 1; + int i = 0; + for (i = 0; i < 10; ++i) { + if (r / exp10 == 0) { + break; + } + exp10 *= 10; + } + if (i == 0) { + i = 1; + } + attr.setScale(i); + makeFieldEntry(field); + currField.getDataStorage().set((long) r); + return currField; + } + + // libcob/intrinsicのcob_intr_varianceの実装 + /** + * TODO: 準備中 + * + * @param prams TODO: 準備中 + * @param fields TODO: 準備中 + * @return TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static AbstractCobolField funcVariance(int prams, AbstractCobolField... fields) + throws CobolStopRunException { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, + 18, + 0, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); + + if (fields.length == 1) { + makeFieldEntry(field); + currField.setInt(0); + return currField; + } + + CobolDecimal d1 = new CobolDecimal(BigDecimal.ZERO, 0); + CobolDecimal d2 = new CobolDecimal(); + + for (AbstractCobolField f : fields) { + d2.setField(f); + d1.add(d2); + } + + d2.setValue(new BigDecimal(fields.length)); + d2.setScale(0); + try { + d1.div(d2); + } catch (CobolStopRunException e) { + return null; + } + + CobolDecimal d4 = new CobolDecimal(BigDecimal.ZERO, 0); + + for (AbstractCobolField f : fields) { + d2.setField(f); + d2.sub(d1); + d2.mul(d2); + d4.add(d2); + } + + CobolDecimal d3 = new CobolDecimal(new BigDecimal(fields.length), 0); + try { + d4.div(d3); + } catch (CobolStopRunException e) { + return null; + } + CobolDataStorage data = new CobolDataStorage(8); + field.setDataStorage(data); + d4.getField(field, 0); + long n = field.getLong(); + int i = 0; + while (n != 0) { + n /= 10; + ++i; + } + makeFieldEntry(field); + if (i <= 18) { + attr.setScale(18 - i); + } + d4.getField(currField, 0); + return currField; + } + + // libcob/intrinsicのcob_intr_standard_deviationの実装 + /** + * TODO: 準備中 + * + * @param prams TODO: 準備中 + * @param fields TODO: 準備中 + * @return TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static AbstractCobolField funcStandardDeviation(int prams, AbstractCobolField... fields) + throws CobolStopRunException { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, + 18, + 0, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); + + makeDoubleEntry(); + + if (fields.length == 1) { + makeFieldEntry(field); + currField.setInt(0); + return currField; + } + + CobolDecimal d1 = new CobolDecimal(BigDecimal.ZERO, 0); + CobolDecimal d2 = new CobolDecimal(); + + for (AbstractCobolField f : fields) { + d2.setField(f); + d1.add(d2); + } + + d2.setValue(new BigDecimal(fields.length)); + d2.setScale(0); + try { + d1.div(d2); + } catch (CobolStopRunException e) { + return null; + } + + CobolDecimal d4 = new CobolDecimal(BigDecimal.ZERO, 0); + + for (AbstractCobolField f : fields) { + d2.setField(f); + d2.sub(d1); + d2.mul(d2); + d4.add(d2); + } + + CobolDecimal d3 = new CobolDecimal(new BigDecimal(fields.length), 0); + try { + d4.div(d3); + } catch (CobolStopRunException e) { + return null; + } + d4.getField(currField, 0); + return funcSqrt(currField); + } + + // libcob/intrinsicのcob_intr_present_valueの実装 + /** + * TODO: 準備中 + * + * @param prams TODO: 準備中 + * @param fields TODO: 準備中 + * @return TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static AbstractCobolField funcPresentValue(int prams, AbstractCobolField... fields) + throws CobolStopRunException { + makeDoubleEntry(); + if (fields.length < 2) { + System.err.println("Wrong number of parameters for FUNCTION PRESENT-VALUE"); + System.err.flush(); + currField.setInt(0); + return currField; + } + AbstractCobolField f = fields[0]; + CobolDecimal d1 = new CobolDecimal(); + d1.setField(f); + CobolDecimal d2 = new CobolDecimal(BigDecimal.ONE, 0); + d1.add(d2); + CobolDecimal d4 = new CobolDecimal(BigDecimal.ZERO, 0); + + for (int i = 1; i < fields.length; ++i) { + f = fields[i]; + d2.setField(f); + CobolDecimal d3 = new CobolDecimal(d1.getValue().add(BigDecimal.ZERO), d1.getScale()); + if (i > 1) { + CobolDecimal d5 = new CobolDecimal(new BigDecimal(i), 0); + d3.pow(d5); + } + d2.div(d3); + d4.add(d2); + } + + d4.getField(currField, 0); + return currField; + } + + // libcob/intrinsicのcob_intr_nationalの実装 + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcNational(AbstractCobolField srcfield) { + int size = srcfield.getSize(); + byte[] pdata = + CobolNationalField.han2zen( + srcfield.getDataStorage().getByteBuffer(size).array(), size); + int ndata = CobolNationalField.workReturnSize; + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NATIONAL, 0, 0, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(ndata, (CobolDataStorage) null, attr); + makeFieldEntry(field); + currField.getDataStorage().memcpy(pdata, ndata); + return currField; + } + + // cob_intr_combined_datetimeの実装 + /** + * TODO: 準備中 + * + * @param srcdays TODO: 準備中 + * @param srctime TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcCombinedDatetime( + AbstractCobolField srcdays, AbstractCobolField srctime) { + int srdays; + int srtime; + String str; + + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, 12, 5, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(12, (CobolDataStorage) null, attr); + makeFieldEntry(field); + CobolRuntimeException.setException(0); + srdays = srcdays.getInt(); + if (srdays < 1 || srdays > 3067671) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); + currField.getDataStorage().memset(0, 12); + return currField; + } + srtime = srctime.getInt(); + if (srtime < 1 || srtime > 86400) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); + currField.getDataStorage().memset(0, 12); + return currField; + } + str = String.format("%7d%5d", srdays, srtime); + byte[] buff = str.getBytes(AbstractCobolField.charSetSJIS); + for (int i = 0; i < buff.length; i++) { + if (buff[i] == ' ') { + buff[i] = '0'; + } + } + currField.getDataStorage().memcpy(buff); + return currField; + } + + // cob_intr_concatenateの実装 + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param length TODO: 準備中 + * @param params TODO: 準備中 + * @param fields TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcConcatenate( + int offset, int length, int params, AbstractCobolField... fields) { + int calcsize = 0; + int i; + int index = 0; + int size; + byte[] data; + + for (i = 0; i < params; i++) { + calcsize += fields[i].getSize(); + } + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(calcsize, (CobolDataStorage) null, attr); + makeFieldEntry(field); + data = new byte[calcsize]; + for (i = 0; i < params; i++) { + size = fields[i].getSize(); + System.arraycopy( + fields[i].getDataStorage().getByteBuffer(size).array(), 0, data, index, size); + index += size; + } + currField.setDataStorage(new CobolDataStorage(data)); + if (offset > 0) { + calcRefMod(currField, offset, length); + } + return currField; + } + + // cob_intr_date_to_yyyymmddの実装 + /** + * TODO: 準備中 + * + * @param params TODO: 準備中 + * @param fields TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcDateToYyyymmdd(int params, AbstractCobolField... fields) { + int year; + int mmdd; + int interval; + int xqtyear; + int maxyear; + LocalDateTime timeptr; + + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 8, 0, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(4, (CobolDataStorage) null, attr); + makeFieldEntry(field); + year = fields[0].getInt(); + mmdd = year % 10000; + year /= 10000; + if (params > 1) { + interval = fields[1].getInt(); + } else { + interval = 50; + } + if (params > 2) { + xqtyear = fields[2].getInt(); + } else { + timeptr = CobolUtil.localtime(); + xqtyear = 1900 + timeptr.getDayOfYear(); + } + if (year < 0 || year > 999999) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); + currField.setInt(0); + return currField; + } + if (xqtyear < 1601 || xqtyear > 9999) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); + currField.setInt(0); + return currField; + } + maxyear = xqtyear + interval; + if (maxyear < 1700 || maxyear > 9999) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); + currField.setInt(0); + return currField; + } + if (maxyear % 100 >= year) { + year += 100 * (maxyear / 100); + } else { + year += 100 * ((maxyear / 100) - 1); + } + year *= 10000; + year += mmdd; + currField.setInt(year); + return currField; + } + + // cob_intr_day_to_yyyydddの実装 + /** + * TODO: 準備中 + * + * @param params TODO: 準備中 + * @param fields TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcDayToYyyyddd(int params, AbstractCobolField... fields) { + int year; + int days; + int interval; + int xqtyear; + int maxyear; + LocalDateTime timeptr; + + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 8, 0, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(4, (CobolDataStorage) null, attr); + makeFieldEntry(field); + year = fields[0].getInt(); + days = year % 1000; + year /= 1000; + if (params > 1) { + interval = fields[1].getInt(); + } else { + interval = 50; + } + if (params > 2) { + xqtyear = fields[2].getInt(); + } else { + timeptr = CobolUtil.localtime(); + xqtyear = 1900 + timeptr.getDayOfYear(); + } + + if (year < 0 || year > 999999) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); + currField.setInt(0); + return currField; + } + if (xqtyear < 1601 || xqtyear > 9999) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); + currField.setInt(0); + return currField; + } + maxyear = xqtyear + interval; + if (maxyear < 1700 || maxyear > 9999) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); + currField.setInt(0); + return currField; + } + if (maxyear % 100 >= year) { + year += 100 * (maxyear / 100); + } else { + year += 100 * ((maxyear / 100) - 1); + } + year *= 1000; + year += days; + currField.setInt(year); + return currField; + } + + // cob_intr_exception_fileの実装 + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public static AbstractCobolField funcExceptionFile() { + int flen; + byte[] data; + + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(0, (CobolDataStorage) null, attr); + if (CobolRuntimeException.getException() == 0 + || (CobolRuntimeException.getExceptionCode() & 0x0500) != 0x0500) { + field.setSize(2); + makeFieldEntry(field); + currField.memcpy(byteArray00, 2); + } else { + flen = CobolFile.errorFile.getSelectName().length(); + field.setSize(flen + 2); + makeFieldEntry(field); + data = new byte[2 + flen]; + System.arraycopy(CobolFile.errorFile.getFileStatus(), 0, data, 0, 2); + System.arraycopy( + CobolFile.errorFile.getSelectName().getBytes(AbstractCobolField.charSetSJIS), + 0, + data, + 2, + flen); + currField.setDataStorage(new CobolDataStorage(data)); + } + return currField; + } + + // cob_intr_exception_locationの実装 + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public static AbstractCobolField funcExceptionLocation() { + String buff; + + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(0, (CobolDataStorage) null, attr); + currField = field; + if (CobolRuntimeException.getException() != 1 + || CobolRuntimeException.getOrigProgramId() == null) { + field.setSize(1); + makeFieldEntry(field); + currField.getDataStorage().setByte(0, ' '); + return currField; + } + if (CobolRuntimeException.getOrigSection() != null + && CobolRuntimeException.getOrigParagragh() != null) { + buff = + String.format( + "%s; %s OF %s; %d", + CobolRuntimeException.getOrigProgramId(), + CobolRuntimeException.getOrigParagragh(), + CobolRuntimeException.getOrigSection(), + CobolRuntimeException.getOrigLine()); + } else if (CobolRuntimeException.getOrigSection() != null) { + buff = + String.format( + "%s; %s; %d", + CobolRuntimeException.getOrigProgramId(), + CobolRuntimeException.getOrigSection(), + CobolRuntimeException.getOrigLine()); + } else if (CobolRuntimeException.getOrigParagragh() != null) { + buff = + String.format( + "%s; %s; %d", + CobolRuntimeException.getOrigProgramId(), + CobolRuntimeException.getOrigParagragh(), + CobolRuntimeException.getOrigLine()); + } else { + buff = + String.format( + "%s; ; %d", + CobolRuntimeException.getOrigProgramId(), + CobolRuntimeException.getOrigLine()); + } + localeBuff = buff.getBytes(AbstractCobolField.charSetSJIS); + field.setSize(localeBuff.length); + currField.setDataStorage(new CobolDataStorage(localeBuff)); + return currField; + } + + // cob_intr_exception_statementの実装 + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public static AbstractCobolField funcExceptionStatement() { + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(31, (CobolDataStorage) null, attr); + makeFieldEntry(field); + byte[] data; + if (CobolRuntimeException.getExceptionCode() != 0 + && CobolRuntimeException.getOrigStatement() != null) { + data = + String.format("%-31s", CobolRuntimeException.getOrigStatement()) + .getBytes(AbstractCobolField.charSetSJIS); + } else { + data = String.format("%-31s", "").getBytes(AbstractCobolField.charSetSJIS); + } + currField.setDataStorage(new CobolDataStorage(data)); + return currField; + } + + private static final byte[] CONST_STRING_EXCEPTION_OBJECT = + "EXCEPTION-OBJECT".getBytes(AbstractCobolField.charSetSJIS); + + // cob_intr_exception_statusの実装 + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public static AbstractCobolField funcExceptionStatus() { + byte[] exceptName; + + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(31, (CobolDataStorage) null, attr); + makeFieldEntry(field); + byte[] data = String.format("%-31s", "").getBytes(AbstractCobolField.charSetSJIS); + currField.setDataStorage(new CobolDataStorage(data)); + if (CobolRuntimeException.getExceptionCode() != 0) { + try { + exceptName = + CobolRuntimeException.getExceptionName( + CobolRuntimeException.getExceptionCode()) + .getBytes(AbstractCobolField.charSetSJIS); + } catch (Exception e) { + exceptName = CONST_STRING_EXCEPTION_OBJECT; + } + currField.memcpy(exceptName, exceptName.length); + } + return currField; + } + + // cob_intr_fraction_partの実装 + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcFractionPart(AbstractCobolField srcfield) { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, + 18, + 18, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(8, (CobolDataStorage) null, attr); + makeFieldEntry(field); + + currField.moveFrom(srcfield); + return currField; + } + + // cob_intr_seconds_from_formatted_timeの実装 + /** + * TODO: 準備中 + * + * @param format TODO: 準備中 + * @param value TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcSecondsFromFormattedTime( + AbstractCobolField format, AbstractCobolField value) { + int n; + int seconds = 0; + int minutes = 0; + int hours = 0; + boolean secondsSeen = false; + boolean minutesSeen = false; + boolean hoursSeen = false; + String p1; + int p2; + + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 8, 0, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(4, (CobolDataStorage) null, attr); + makeFieldEntry(field); + + if (value.getSize() < format.getSize()) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); + currField.setInt(0); + return currField; + } + + CobolDataStorage formatData = format.getDataStorage(); + CobolDataStorage valueData = value.getDataStorage(); + + for (n = 0; n < format.getSize() - 1; n++) { + p1 = new String(formatData.getByteArray(n, 2), AbstractCobolField.charSetSJIS); + + if ("hh".equals(p1) && !hoursSeen) { + p2 = + Integer.parseInt( + new String( + valueData.getByteArray(n, 2), + AbstractCobolField.charSetSJIS)); + hours = p2; + hoursSeen = true; + continue; + } + if ("mm".equals(p1) && !minutesSeen) { + p2 = + Integer.parseInt( + new String( + valueData.getByteArray(n, 2), + AbstractCobolField.charSetSJIS)); + minutes = p2; + minutesSeen = true; + continue; + } + if ("ss".equals(p1) && !secondsSeen) { + p2 = + Integer.parseInt( + new String( + valueData.getByteArray(n, 2), + AbstractCobolField.charSetSJIS)); + seconds = p2; + secondsSeen = true; + continue; + } + } + + if (hoursSeen && minutesSeen && secondsSeen) { + seconds += hours * 3600 + minutes * 60; + } else { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); + seconds = 0; + } + currField.setInt(seconds); + return currField; + } + + // cob_intr_seconds_past_midnightの実装 + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public static AbstractCobolField funcSecondsPastMidnight() { + int seconds; + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 8, 0, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(4, (CobolDataStorage) null, attr); + makeFieldEntry(field); + LocalDateTime currDate = LocalDateTime.now(); + seconds = currDate.getHour() * 3600 + currDate.getMinute() * 60 + currDate.getSecond(); + currField.setInt(seconds); + return currField; + } + + // cob_intr_signの実装 + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcSign(AbstractCobolField srcfield) { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, + 8, + 0, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(4, (CobolDataStorage) null, attr); + makeFieldEntry(field); + + currField.setInt(0); + int n = srcfield.compareTo(currField); + if (n < 0) { + currField.setInt(-1); + } else if (n > 0) { + currField.setInt(1); + } + return currField; + } + + // cob_intr_stored_char_lengthの実装 + /** + * TODO: 準備中 + * + * @param srcfield TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcStoredCharLength(AbstractCobolField srcfield) { + int count; + + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 8, 0, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(4, (CobolDataStorage) null, attr); + makeFieldEntry(field); + + CobolDataStorage storage = srcfield.getDataStorage(); + for (count = srcfield.getSize(); count > 0; count--) { + if (storage.getByte(count - 1) != ' ') { + break; + } + } + + currField.setInt(count); + return currField; + } + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param length TODO: 準備中 + * @param params TODO: 準備中 + * @param fields TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcSubstitute( + int offset, int length, int params, AbstractCobolField... fields) { + int i, j, k; + int numreps = params / 2; + AbstractCobolField[] f1 = new AbstractCobolField[numreps]; + AbstractCobolField[] f2 = new AbstractCobolField[numreps]; + CobolDataStorage src = fields[0].getDataStorage(); + CobolDataStorage fData1; + int srcSize = fields[0].getSize(); + int fSize1; + StringBuilder rtn = new StringBuilder(); + + for (i = 0; i < params - 1; i++) { + if ((i % 2) == 0) { + f1[i / 2] = fields[i + 1]; + } else { + f2[i / 2] = fields[i + 1]; + } + } + + for (i = 0; i < srcSize; ) { + for (j = 0; j < numreps; j++) { + fData1 = f1[j].getDataStorage(); + fSize1 = f1[j].getSize(); + for (k = fSize1 - 1; k >= 0; k--) { + if (i + k >= srcSize || src.getByte(i + k) != fData1.getByte(k)) { + break; + } + } + if (k < 0) { + rtn.append(f2[j].getString()); + i += fSize1; + break; + } + } + if (j == numreps) { + rtn.append((char) src.getByte(i)); + i++; + } + } + + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(rtn.length(), (CobolDataStorage) null, attr); + makeFieldEntry(field); + currField.setDataStorage(new CobolDataStorage(rtn.toString())); + + if (offset > 0) { + calcRefMod(currField, offset, length); + } + return currField; + } + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param length TODO: 準備中 + * @param params TODO: 準備中 + * @param fields TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcSubstituteCase( + int offset, int length, int params, AbstractCobolField... fields) { + int i, j, k; + int numreps = params / 2; + AbstractCobolField[] f1 = new AbstractCobolField[numreps]; + AbstractCobolField[] f2 = new AbstractCobolField[numreps]; + CobolDataStorage src = fields[0].getDataStorage(); + CobolDataStorage fData1; + int srcSize = fields[0].getSize(); + int fSize1; + StringBuilder rtn = new StringBuilder(); + + for (i = 0; i < params - 1; i++) { + if (i % 2 == 0) { + f1[i / 2] = fields[i + 1]; + } else { + f2[i / 2] = fields[i + 1]; + } + } + + for (i = 0; i < srcSize; ) { + for (j = 0; j < numreps; j++) { + fData1 = f1[j].getDataStorage(); + fSize1 = f1[j].getSize(); + for (k = fSize1 - 1; k >= 0; k--) { + if (i + k >= srcSize + || Character.toLowerCase((char) fData1.getByte(k)) + != Character.toLowerCase((char) src.getByte(i + k))) { + break; + } + } + if (k < 0) { + rtn.append(f2[j].getString()); + i += fSize1; + break; + } + } + if (j == numreps) { + rtn.append((char) src.getByte(i)); + i++; + } + } + + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); + AbstractCobolField field = + CobolFieldFactory.makeCobolField(rtn.length(), (CobolDataStorage) null, attr); + makeFieldEntry(field); + + currField.setDataStorage(new CobolDataStorage(rtn.toString())); + if (offset > 0) { + calcRefMod(currField, offset, length); + } + return currField; + } + + // Equivalent to cob_intr_trim + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param length TODO: 準備中 + * @param srcField TODO: 準備中 + * @param direction TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcTrim( + int offset, int length, AbstractCobolField srcField, int direction) { + makeFieldEntry(srcField); + int i; + int srcFieldSize = srcField.getSize(); + CobolDataStorage srcStorage = srcField.getDataStorage(); + for (i = 0; i < srcFieldSize; ++i) { + if (srcStorage.getByte(i) != ' ') { + break; + } + } + if (i == srcFieldSize) { + currField.setSize(1); + currField.getDataStorage().setByte(0, (byte) ' '); + return currField; + } + int beginIndex = 0; + if (direction != 2) { + while (srcStorage.getByte(beginIndex) == ' ') { + ++beginIndex; + } + } + int endIndex = srcFieldSize - 1; + if (direction != 1) { + while (srcStorage.getByte(endIndex) == ' ') { + --endIndex; + } + } + CobolDataStorage currStorage = currField.getDataStorage(); + currField.setSize(endIndex - beginIndex + 1); + for (i = 0; i <= endIndex - beginIndex; ++i) { + currStorage.setByte(i, srcStorage.getByte(beginIndex + i)); + } + if (offset > 0) { + calcRefMod(currField, offset, length); + } + return currField; + } + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param length TODO: 準備中 + * @param srcField TODO: 準備中 + * @param localeField TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcLocaleDate( + int offset, int length, AbstractCobolField srcField, int localeField) { + return funcLocaleDate(offset, length, srcField, null); + } + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param length TODO: 準備中 + * @param srcField TODO: 準備中 + * @param localeField TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcLocaleDate( + int offset, int length, AbstractCobolField srcField, AbstractCobolField localeField) { + AbstractCobolField field = + CobolFieldFactory.makeCobolField( + 0, + (CobolDataStorage) null, + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 10, 0, 0, null)); + int inDate; + + // Convert the input field to an integer + if (srcField.getAttribute().isTypeNumeric()) { + inDate = srcField.getInt(); + } else { + if (srcField.getSize() < 8) { + return errorFuncLocaleDate(field); + } + int p = 0; + inDate = 0; + for (int len = 0; len < 8; ++len, ++p) { + char c = (char) srcField.getDataStorage().getByte(p); + if ('0' <= c && c <= '9') { + inDate = inDate * 10 + (c - '0'); + } else { + return errorFuncLocaleDate(field); + } + } + } + + // Calculate the year, month, and days + int year = inDate / 10000; + if (year < 1601 || year > 9999) { + return errorFuncLocaleDate(field); + } + inDate %= 10000; + + int month = inDate / 100; + if (month < 1 || month > 12) { + return errorFuncLocaleDate(field); + } + + int days = inDate % 100; + if (days < 1 || days > 31) { + return errorFuncLocaleDate(field); + } + + if (isLeapYear(year)) { + if (days > leapMonthDays[month]) { + return errorFuncLocaleDate(field); + } + } else { + if (days > normalMonthDays[month]) { + return errorFuncLocaleDate(field); + } + } + + // Create the date string + Calendar cal = Calendar.getInstance(); + cal.set(year, month - 1, days); + + DateFormat df; + if (localeField != null) { + Locale locale = new Locale(localeField.getString()); + df = DateFormat.getDateInstance(DateFormat.SHORT, locale); + } else { + df = DateFormat.getDateInstance(DateFormat.SHORT); + } + String dateString = df.format(cal.getTime()); + + // Return the result + field.setSize(dateString.length()); + makeFieldEntry(field); + currField.getDataStorage().memcpy(dateString.getBytes(AbstractCobolField.charSetSJIS)); + if (offset > 0) { + calcRefMod(field, offset, length); + } + return currField; + } + + private static AbstractCobolField errorFuncLocaleDate(AbstractCobolField field) { + field.setSize(10); + makeFieldEntry(field); + currField.getDataStorage().memset((byte) '0', 10); + CobolRuntimeException.setException(CobolExceptionId.COB_EC_ARGUMENT_FUNCTION); + return currField; + } + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param length TODO: 準備中 + * @param srcField TODO: 準備中 + * @param localeField TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcLocaleTime( + int offset, int length, AbstractCobolField srcField, int localeField) { + return funcLocaleTime(offset, length, srcField, null); + } + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param length TODO: 準備中 + * @param srcField TODO: 準備中 + * @param localeField TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcLocaleTime( + int offset, int length, AbstractCobolField srcField, AbstractCobolField localeField) { + AbstractCobolField field = + CobolFieldFactory.makeCobolField( + 0, + (CobolDataStorage) null, + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 10, 0, 0, null)); + int inTime; + + // Convert the input field to an integer + if (srcField.getAttribute().isTypeNumeric()) { + inTime = srcField.getInt(); + } else { + if (srcField.getSize() < 6) { + return errorFuncLocaleDate(field); + } + int p = 0; + inTime = 0; + for (int len = 0; len < 6; ++len, ++p) { + char c = (char) srcField.getDataStorage().getByte(p); + if ('0' <= c && c <= '9') { + inTime = inTime * 10 + (c - '0'); + } else { + return errorFuncLocaleDate(field); + } + } + } + + // Calculate the hours, minutes, and seconds + int hours = inTime / 10000; + if (hours < 0 || hours > 24) { + return errorFuncLocaleDate(field); + } + inTime %= 10000; + + int minutes = inTime / 100; + if (minutes < 0 || minutes > 59) { + return errorFuncLocaleDate(field); + } + + int seconds = inTime % 100; + if (seconds < 0 || seconds > 59) { + return errorFuncLocaleDate(field); + } + + // Create the time string + LocalTime time = LocalTime.of(hours, minutes, seconds); + + DateTimeFormatter formatter; + String pattern = "HH:mm:ss"; + if (localeField != null) { + Locale locale = new Locale(localeField.getString()); + formatter = DateTimeFormatter.ofPattern(pattern, locale); + } else { + formatter = DateTimeFormatter.ofPattern(pattern); + } + String timeString = time.format(formatter); + + // Return the result + field.setSize(timeString.length()); + makeFieldEntry(field); + currField.getDataStorage().memcpy(timeString.getBytes(AbstractCobolField.charSetSJIS)); + if (offset > 0) { + calcRefMod(field, offset, length); + } + return currField; + } + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param length TODO: 準備中 + * @param srcField TODO: 準備中 + * @param localeField TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcLocaleTimeFromSeconds( + int offset, int length, AbstractCobolField srcField, int localeField) { + return funcLocaleTime(offset, length, srcField, null); + } + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param length TODO: 準備中 + * @param srcField TODO: 準備中 + * @param localeField TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField funcLocaleTimeFromSeconds( + int offset, int length, AbstractCobolField srcField, AbstractCobolField localeField) { + AbstractCobolField field = + CobolFieldFactory.makeCobolField( + 0, + (CobolDataStorage) null, + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 10, 0, 0, null)); + int inTime; + + // Convert the input field to an integer + if (srcField.getAttribute().isTypeNumeric()) { + inTime = srcField.getInt(); + } else { + return errorFuncLocaleDate(field); + } + + // Calculate the hours, minutes, and seconds + int hours = inTime / 3600; + inTime %= 3600; + int minutes = inTime / 60; + int seconds = inTime % 60; + + // Create the time string + LocalTime time = LocalTime.of(hours, minutes, seconds); + + DateTimeFormatter formatter; + String pattern = "HH:mm:ss"; + if (localeField != null) { + Locale locale = new Locale(localeField.getString()); + formatter = DateTimeFormatter.ofPattern(pattern, locale); + } else { + formatter = DateTimeFormatter.ofPattern(pattern); + } + String timeString = time.format(formatter); + + // Return the result + field.setSize(timeString.length()); + makeFieldEntry(field); + currField.getDataStorage().memcpy(timeString.getBytes(AbstractCobolField.charSetSJIS)); + if (offset > 0) { + calcRefMod(field, offset, length); + } + return currField; + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolModule.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolModule.java index a9287f08..7df43c6f 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolModule.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolModule.java @@ -1,201 +1,209 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.common; - -import java.util.ArrayList; -import java.util.List; -import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; -import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; - -/** libcob/common.hのcob_moduleに対応するクラス */ -public class CobolModule { - - private static List moduleStack = new ArrayList(); - private static CobolModule currentModule; - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public static CobolModule getCurrentModule() { - return currentModule; - } - - /** - * モジュールスタックに追加する - * - * @param module キューに追加するモジュール - */ - public static void push(CobolModule module) { - currentModule = module; - moduleStack.add(module); - } - - /** モジュールスタックからモジュールを取り除く */ - public static void pop() { - currentModule = moduleStack.remove(moduleStack.size() - 1); - } - - /** - * TODO: 準備中 - * - * @param data TODO: 準備中 - * @return TODO: 準備中 - */ - public static int calledBy(CobolDataStorage data) { - AbstractCobolField param = CobolModule.getCurrentModule().cob_procedure_parameters.get(0); - if (param != null) { - if (moduleStack.size() >= 2) { - String calledProgramName = moduleStack.get(moduleStack.size() - 2).program_id; - if (calledProgramName == null) { - return -1; - } - int length = Math.min(param.getSize(), calledProgramName.length()); - param.getDataStorage().memcpy(calledProgramName, length); - } else { - param.getDataStorage().memset(' ', param.getSize()); - return 0; - } - } - return 1; - } - - /** - * モジュールキューが空かどうか - * - * @return TODO: 準備中 - */ - public static boolean isQueueEmpty() { - return moduleStack.isEmpty(); - } - - /** TODO: 準備中 */ - // private CobolModule next; - /** TODO: 準備中 */ - public CobolDataStorage collating_sequence; - /** TODO: 準備中 */ - // private AbstractCobolField cut_status; - /** TODO: 準備中 */ - // private AbstractCobolField cursor_pos; - /** TODO: 準備中 */ - public int display_sign; - /** TODO: 準備中 */ - public char decimal_point; - /** TODO: 準備中 */ - public char currency_symbol; - /** TODO: 準備中 */ - // private char numeric_separator; - /** TODO: 準備中 */ - public int flag_filename_mapping; - /** TODO: 準備中 */ - public int flag_binary_truncate; - /** TODO: 準備中 */ - public int flag_pretty_display; - /** TODO: 準備中 */ - // private int spare8; - /** TODO: 準備中 */ - private String program_id; - /** TODO: 準備中 */ - // private String packageName; - - /** TODO: 準備中 */ - public List cob_procedure_parameters; - - /** - * コンストラクタ - * - * @param next TODO: 準備中 - * @param collatingSequence TODO: 準備中 - * @param cutStatus TODO: 準備中 - * @param cursorPos TODO: 準備中 - * @param displaySign TODO: 準備中 - * @param decimalPoint TODO: 準備中 - * @param currencySymbol TODO: 準備中 - * @param numericSeparator TODO: 準備中 - * @param flagFilenameMapping TODO: 準備中 - * @param flagBinaryTruncate TODO: 準備中 - * @param flagPrettyDisplay TODO: 準備中 - * @param spare8 TODO: 準備中 - * @param programId TODO: 準備中 - */ - public CobolModule( - CobolModule next, - CobolDataStorage collatingSequence, - AbstractCobolField cutStatus, - AbstractCobolField cursorPos, - int displaySign, - char decimalPoint, - char currencySymbol, - char numericSeparator, - int flagFilenameMapping, - int flagBinaryTruncate, - int flagPrettyDisplay, - int spare8, - String programId) { - // this.next = next; - this.collating_sequence = collatingSequence; - // this.cut_status = cutStatus; - // this.cursor_pos = cursorPos; - this.display_sign = displaySign; - this.decimal_point = decimalPoint; - this.currency_symbol = currencySymbol; - // this.numeric_separator = numericSeparator; - this.flag_filename_mapping = flagFilenameMapping; - this.flag_binary_truncate = flagBinaryTruncate; - this.flag_pretty_display = flagPrettyDisplay; - // this.spare8 = spare8; - this.program_id = programId; - - this.cob_procedure_parameters = new ArrayList(); - } - - /** - * TODO 実装 - * - * @param programName TODO: 準備中 - */ - public void setProgramId(String programName) { - if (this.program_id != null) { - this.program_id = null; - } - this.program_id = programName; - } - - /** - * TODO: 準備中 - * - * @param field TODO: 準備中 - */ - public void setParameters(AbstractCobolField... field) { - cob_procedure_parameters.clear(); - for (AbstractCobolField f : field) { - cob_procedure_parameters.add(f); - } - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public static int getDecimalPoint() { - return currentModule.decimal_point; - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.common; + +import java.util.ArrayList; +import java.util.List; +import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; +import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; + +/** libcob/common.hのcob_moduleに対応するクラス */ +public class CobolModule { + + private static List moduleStack = new ArrayList(); + private static CobolModule currentModule; + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public static CobolModule getCurrentModule() { + return currentModule; + } + + /** + * モジュールスタックに追加する + * + * @param module キューに追加するモジュール + */ + public static void push(CobolModule module) { + currentModule = module; + moduleStack.add(module); + } + + /** モジュールスタックからモジュールを取り除く */ + public static void pop() { + currentModule = moduleStack.remove(moduleStack.size() - 1); + } + + /** + * TODO: 準備中 + * + * @param data TODO: 準備中 + * @return TODO: 準備中 + */ + public static int calledBy(CobolDataStorage data) { + AbstractCobolField param = CobolModule.getCurrentModule().cob_procedure_parameters.get(0); + if (param != null) { + if (moduleStack.size() >= 2) { + String calledProgramName = moduleStack.get(moduleStack.size() - 2).program_id; + if (calledProgramName == null) { + return -1; + } + int length = Math.min(param.getSize(), calledProgramName.length()); + param.getDataStorage().memcpy(calledProgramName, length); + } else { + param.getDataStorage().memset(' ', param.getSize()); + return 0; + } + } + return 1; + } + + /** + * モジュールキューが空かどうか + * + * @return TODO: 準備中 + */ + public static boolean isQueueEmpty() { + return moduleStack.isEmpty(); + } + + /** TODO: 準備中 */ + // private CobolModule next; + /** TODO: 準備中 */ + public CobolDataStorage collating_sequence; + + /** TODO: 準備中 */ + // private AbstractCobolField cut_status; + /** TODO: 準備中 */ + // private AbstractCobolField cursor_pos; + /** TODO: 準備中 */ + public int display_sign; + + /** TODO: 準備中 */ + public char decimal_point; + + /** TODO: 準備中 */ + public char currency_symbol; + + /** TODO: 準備中 */ + // private char numeric_separator; + /** TODO: 準備中 */ + public int flag_filename_mapping; + + /** TODO: 準備中 */ + public int flag_binary_truncate; + + /** TODO: 準備中 */ + public int flag_pretty_display; + + /** TODO: 準備中 */ + // private int spare8; + /** TODO: 準備中 */ + private String program_id; + + /** TODO: 準備中 */ + // private String packageName; + + /** TODO: 準備中 */ + public List cob_procedure_parameters; + + /** + * コンストラクタ + * + * @param next TODO: 準備中 + * @param collatingSequence TODO: 準備中 + * @param cutStatus TODO: 準備中 + * @param cursorPos TODO: 準備中 + * @param displaySign TODO: 準備中 + * @param decimalPoint TODO: 準備中 + * @param currencySymbol TODO: 準備中 + * @param numericSeparator TODO: 準備中 + * @param flagFilenameMapping TODO: 準備中 + * @param flagBinaryTruncate TODO: 準備中 + * @param flagPrettyDisplay TODO: 準備中 + * @param spare8 TODO: 準備中 + * @param programId TODO: 準備中 + */ + public CobolModule( + CobolModule next, + CobolDataStorage collatingSequence, + AbstractCobolField cutStatus, + AbstractCobolField cursorPos, + int displaySign, + char decimalPoint, + char currencySymbol, + char numericSeparator, + int flagFilenameMapping, + int flagBinaryTruncate, + int flagPrettyDisplay, + int spare8, + String programId) { + // this.next = next; + this.collating_sequence = collatingSequence; + // this.cut_status = cutStatus; + // this.cursor_pos = cursorPos; + this.display_sign = displaySign; + this.decimal_point = decimalPoint; + this.currency_symbol = currencySymbol; + // this.numeric_separator = numericSeparator; + this.flag_filename_mapping = flagFilenameMapping; + this.flag_binary_truncate = flagBinaryTruncate; + this.flag_pretty_display = flagPrettyDisplay; + // this.spare8 = spare8; + this.program_id = programId; + + this.cob_procedure_parameters = new ArrayList(); + } + + /** + * TODO 実装 + * + * @param programName TODO: 準備中 + */ + public void setProgramId(String programName) { + if (this.program_id != null) { + this.program_id = null; + } + this.program_id = programName; + } + + /** + * TODO: 準備中 + * + * @param field TODO: 準備中 + */ + public void setParameters(AbstractCobolField... field) { + cob_procedure_parameters.clear(); + for (AbstractCobolField f : field) { + cob_procedure_parameters.add(f); + } + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public static int getDecimalPoint() { + return currentModule.decimal_point; + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolString.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolString.java index 038dff26..074779ee 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolString.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolString.java @@ -1,588 +1,598 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.common; - -import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; -import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; -import jp.osscons.opensourcecobol.libcobj.data.CobolFieldAttribute; -import jp.osscons.opensourcecobol.libcobj.data.CobolFieldFactory; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionId; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionInfo; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; - -class Dlm { - public AbstractCobolField dlm; - public int all; -} - -/** TODO: 準備中 */ -public class CobolString { - private static final int DLM_DEFAULT_NUM = 8; - - private static int udlmCount = 0; - - private static AbstractCobolField stringDst; - private static AbstractCobolField stringPtr; - private static AbstractCobolField stringDlm; - private static AbstractCobolField stringDstCopy; - private static AbstractCobolField stringPtrCopy; - private static AbstractCobolField stringDlmCopy; - private static int stringOffset; - - private static Dlm[] dlmList; - private static AbstractCobolField unstringSrc; - private static AbstractCobolField unstringPtr; - private static AbstractCobolField unstringSrcCopy; - private static AbstractCobolField unstringPtrCopy; - private static int unstringOffset; - private static int unstringCount; - private static int unstringNdlms; - - /** - * TODO: 準備中 - * - * @param dst TODO: 準備中 - * @param ptr TODO: 準備中 - */ - public static void stringInit(int dst, AbstractCobolField ptr) { - stringInit(null, ptr); - } - - /** - * TODO: 準備中 - * - * @param dst TODO: 準備中 - * @param ptr TODO: 準備中 - */ - public static void stringInit(AbstractCobolField dst, int ptr) { - stringInit(dst, null); - } - - /** - * TODO: 準備中 - * - * @param dst TODO: 準備中 - * @param ptr TODO: 準備中 - */ - public static void stringInit(int dst, int ptr) { - stringInit(null, null); - } - - /** - * TODO: 準備中 - * - * @param dst TODO: 準備中 - * @param ptr TODO: 準備中 - */ - public static void stringInit(AbstractCobolField dst, AbstractCobolField ptr) { - stringDstCopy = dst; - stringDst = stringDstCopy; - stringPtr = null; - if (ptr != null) { - stringPtrCopy = ptr; - stringPtr = stringPtrCopy; - } - stringOffset = 0; - CobolRuntimeException.setException(0); - - if (stringPtr != null) { - stringOffset = stringPtr.getInt() - 1; - if (stringOffset < 0 || stringOffset >= stringDst.getSize()) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_OVERFLOW_STRING); - } - } - - switch (stringDst.getAttribute().getType()) { - case CobolFieldAttribute.COB_TYPE_NATIONAL: - case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: - stringOffset *= 2; - break; - default: - break; - } - } - - /** - * TODO: 準備中 - * - * @param dlm TODO: 準備中 - */ - public static void stringDelimited(int dlm) { - stringDelimited(null); - } - - /** - * TODO: 準備中 - * - * @param dlm TODO: 準備中 - */ - public static void stringDelimited(AbstractCobolField dlm) { - switch (stringDst.getAttribute().getType()) { - case CobolFieldAttribute.COB_TYPE_NATIONAL: - case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: - if (dlm == CobolConstant.quote) { - dlm = CobolConstant.zenQuote; - } else if (dlm == CobolConstant.space) { - dlm = CobolConstant.zenSpace; - } else if (dlm == CobolConstant.zero) { - dlm = CobolConstant.zenZero; - } - break; - default: - break; - } - stringDlm = null; - if (dlm != null) { - stringDlmCopy = dlm; - stringDlm = stringDlmCopy; - } - } - - /** - * TODO: 準備中 - * - * @param src TODO: 準備中 - */ - public static void stringAppend(int src) { - stringAppend(null); - } - - /** - * TODO: 準備中 - * - * @param src TODO: 準備中 - */ - public static void stringAppend(AbstractCobolField src) { - if (CobolRuntimeException.code != 0) { - return; - } - - int srcSize = src.getSize(); - if (stringDlm != null) { - int size = srcSize - stringDlm.getSize() + 1; - CobolDataStorage srcData = src.getDataStorage(); - CobolDataStorage dlmData = stringDlm.getDataStorage(); - int dlmSize = stringDlm.getSize(); - for (int i = 0; i < size; ++i) { - if (srcData.getSubDataStorage(i).memcmp(dlmData, dlmSize) == 0) { - srcSize = i; - break; - } - } - } - - if (srcSize <= stringDst.getSize() - stringOffset) { - stringDst - .getDataStorage() - .getSubDataStorage(stringOffset) - .memcpy(src.getDataStorage(), srcSize); - stringOffset += srcSize; - } else { - int size = stringDst.getSize() - stringOffset; - stringDst.getDataStorage().getSubDataStorage(stringOffset).memcpy(src.getDataStorage(), size); - stringOffset += size; - CobolRuntimeException.setException(CobolExceptionId.COB_EC_OVERFLOW_STRING); - } - } - - /** TODO: 準備中 */ - public static void stringFinish() { - int type = stringDst.getAttribute().getType(); - if (type == CobolFieldAttribute.COB_TYPE_NATIONAL - || type == CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED) { - - stringOffset /= 2; - } - if (stringPtr != null) { - stringPtr.setInt(stringOffset + 1); - } - } - - /** - * TODO: 準備中 - * - * @param src TODO: 準備中 - * @param ptr TODO: 準備中 - * @param numDlm TODO: 準備中 - */ - public static void unstringInit(int src, int ptr, int numDlm) { - unstringInit(null, null, numDlm); - } - - /** - * TODO: 準備中 - * - * @param src TODO: 準備中 - * @param ptr TODO: 準備中 - * @param numDlm TODO: 準備中 - */ - public static void unstringInit(AbstractCobolField src, int ptr, int numDlm) { - unstringInit(src, null, numDlm); - } - - /** - * TODO: 準備中 - * - * @param src TODO: 準備中 - * @param ptr TODO: 準備中 - * @param numDlm TODO: 準備中 - */ - public static void unstringInit(int src, AbstractCobolField ptr, int numDlm) { - unstringInit(null, ptr, numDlm); - } - - /** - * TODO: 準備中 - * - * @param src TODO: 準備中 - * @param ptr TODO: 準備中 - * @param numDlm TODO: 準備中 - */ - public static void unstringInit(AbstractCobolField src, AbstractCobolField ptr, int numDlm) { - unstringSrcCopy = src; - unstringSrc = unstringSrcCopy; - unstringPtr = null; - if (ptr != null) { - unstringPtrCopy = ptr; - unstringPtr = unstringPtrCopy; - } - - unstringOffset = 0; - unstringCount = 0; - unstringNdlms = 0; - CobolRuntimeException.setException(0); - - if (dlmList == null) { - if (numDlm <= DLM_DEFAULT_NUM) { - dlmList = new Dlm[DLM_DEFAULT_NUM]; - udlmCount = DLM_DEFAULT_NUM; - } else { - dlmList = new Dlm[numDlm]; - udlmCount = numDlm; - } - } else { - if (numDlm > udlmCount) { - dlmList = new Dlm[numDlm]; - udlmCount = numDlm; - } - } - - for (int i = 0; i < dlmList.length; ++i) { - dlmList[i] = new Dlm(); - } - - if (unstringPtr != null) { - unstringOffset = unstringPtr.getInt() - 1; - if (unstringOffset < 0 || unstringOffset >= unstringSrc.getSize()) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_OVERFLOW_UNSTRING); - } - } - - switch (unstringSrc.getAttribute().getType()) { - case CobolFieldAttribute.COB_TYPE_NATIONAL: - case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: - unstringOffset *= 2; - break; - default: - break; - } - } - - /** - * TODO: 準備中 - * - * @param dlm TODO: 準備中 - * @param all TODO: 準備中 - */ - public static void unstringDelimited(int dlm, int all) { - unstringDelimited(null, all); - } - - /** - * TODO: 準備中 - * - * @param dlm TODO: 準備中 - * @param all TODO: 準備中 - */ - public static void unstringDelimited(AbstractCobolField dlm, int all) { - AbstractCobolField addDlm = null; - - switch (unstringSrc.getAttribute().getType()) { - case CobolFieldAttribute.COB_TYPE_NATIONAL: - case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: - if (dlm == CobolConstant.quote) { - dlm = CobolConstant.zenQuote; - } else if (dlm == CobolConstant.space) { - dlm = CobolConstant.zenSpace; - addDlm = CobolConstant.zenBlank; - } else if (dlm == CobolConstant.zero) { - dlm = CobolConstant.zenZero; - } - break; - default: - break; - } - - dlmList[unstringNdlms].dlm = dlm; - dlmList[unstringNdlms].all = all; - unstringNdlms++; - - if (addDlm != null) { - dlmList[unstringNdlms].dlm = addDlm; - dlmList[unstringNdlms].all = all; - unstringNdlms++; - } - } - - /** - * TODO: 準備中 - * - * @param dst TODO: 準備中 - * @param dlm TODO: 準備中 - * @param cnt TODO: 準備中 - */ - public static void unstringInto(AbstractCobolField dst, AbstractCobolField dlm, int cnt) { - unstringInto(dst, dlm, null); - } - - /** - * TODO: 準備中 - * - * @param dst TODO: 準備中 - * @param dlm TODO: 準備中 - * @param cnt TODO: 準備中 - */ - public static void unstringInto(AbstractCobolField dst, int dlm, AbstractCobolField cnt) { - unstringInto(dst, null, cnt); - } - - /** - * TODO: 準備中 - * - * @param dst TODO: 準備中 - * @param dlm TODO: 準備中 - * @param cnt TODO: 準備中 - */ - public static void unstringInto(AbstractCobolField dst, int dlm, int cnt) { - unstringInto(dst, null, null); - } - - /** - * TODO: 準備中 - * - * @param dst TODO: 準備中 - * @param dlm TODO: 準備中 - * @param cnt TODO: 準備中 - */ - public static void unstringInto(int dst, int dlm, int cnt) { - unstringInto(null, null, null); - } - - /** - * TODO: 準備中 - * - * @param dst TODO: 準備中 - * @param dlm TODO: 準備中 - * @param cnt TODO: 準備中 - */ - public static void unstringInto(int dst, AbstractCobolField dlm, int cnt) { - unstringInto(null, dlm, null); - } - - /** - * TODO: 準備中 - * - * @param dst TODO: 準備中 - * @param dlm TODO: 準備中 - * @param cnt TODO: 準備中 - */ - public static void unstringInto(int dst, int dlm, AbstractCobolField cnt) { - unstringInto(null, null, cnt); - } - - /** - * TODO: 準備中 - * - * @param dst TODO: 準備中 - * @param dlm TODO: 準備中 - * @param cnt TODO: 準備中 - */ - public static void unstringInto(int dst, AbstractCobolField dlm, AbstractCobolField cnt) { - unstringInto(null, dlm, cnt); - } - - /** - * TODO: 準備中 - * - * @param dst TODO: 準備中 - * @param dlm TODO: 準備中 - * @param cnt TODO: 準備中 - */ - public static void unstringInto( - AbstractCobolField dst, AbstractCobolField dlm, AbstractCobolField cnt) { - if (CobolExceptionInfo.code != 0) { - return; - } - if (unstringOffset >= unstringSrc.getSize()) { - return; - } - - CobolDataStorage srcData = unstringSrc.getDataStorage(); - int start = unstringOffset; - int matchSize = 0; - int dlmSize = 0; - CobolDataStorage dlmData = null; - if (unstringNdlms == 0) { - matchSize = Math.min(dst.getFieldSize(), unstringSrc.getSize() - unstringOffset); - dst.moveFrom( - CobolFieldFactory.makeCobolField( - matchSize, - srcData.getSubDataStorage(unstringOffset), - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null))); - unstringOffset += matchSize; - } else { - int srSize = unstringSrc.getSize(); - int s = srSize; - boolean brkpt = false; - for (int p = start; p < s; ++p) { - for (int i = 0; i < unstringNdlms; ++i) { - int dlsize = dlmList[i].dlm.getSize(); - CobolDataStorage dp = dlmList[i].dlm.getDataStorage(); - if (p + dlsize > s) { - continue; - } - if (srcData.getSubDataStorage(p).memcmp(dp, dlsize) == 0) { - matchSize = (p - start); - dst.moveFrom( - CobolFieldFactory.makeCobolField( - matchSize, - srcData.getSubDataStorage(start), - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null))); - unstringOffset += matchSize + dlsize; - dlmData = dp; - dlmSize = dlsize; - if (dlmList[i].all != 0) { - for (p += dlsize; p < s; p += dlsize) { - if (p + dlsize > s) { - break; - } - if (srcData.getSubDataStorage(p).memcmp(dp, dlsize) != 0) { - break; - } - unstringOffset += dlsize; - } - } - brkpt = true; - break; - } - } - switch (unstringSrc.getAttribute().getType()) { - case CobolFieldAttribute.COB_TYPE_NATIONAL: - case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: - p++; - break; - default: - break; - } - - if (brkpt) { - break; - } - } - if (!brkpt) { - matchSize = unstringSrc.getSize() - unstringOffset; - dst.moveFrom( - CobolFieldFactory.makeCobolField( - matchSize, - srcData.getSubDataStorage(start), - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null))); - unstringOffset = unstringSrc.getSize(); - dlmData = null; - } - } - unstringCount++; - - if (dlm != null) { - if (dlmData != null) { - dlm.moveFrom( - CobolFieldFactory.makeCobolField( - dlmSize, - dlmData, - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null))); - } else if (dlm.getAttribute().isTypeNumeric()) { - dlm.moveFrom(CobolConstant.zero); - } else { - dlm.moveFrom(CobolConstant.space); - } - } - - switch (unstringSrc.getAttribute().getType()) { - case CobolFieldAttribute.COB_TYPE_NATIONAL: - case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: - matchSize /= 2; - break; - default: - break; - } - - if (cnt != null) { - cnt.setInt(matchSize); - } - } - - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void unstringTallying(int f) throws CobolStopRunException {} - - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void unstringTallying(AbstractCobolField f) throws CobolStopRunException { - f.addInt(unstringCount); - } - - /** TODO: 準備中 */ - public static void unstringFinish() { - if (unstringOffset < unstringSrc.getSize()) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_OVERFLOW_UNSTRING); - } - - switch (unstringSrc.getAttribute().getType()) { - case CobolFieldAttribute.COB_TYPE_NATIONAL: - case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: - unstringOffset /= 2; - break; - default: - break; - } - - if (unstringPtr != null) { - unstringPtr.setInt(unstringOffset + 1); - } - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.common; + +import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; +import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; +import jp.osscons.opensourcecobol.libcobj.data.CobolFieldAttribute; +import jp.osscons.opensourcecobol.libcobj.data.CobolFieldFactory; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionId; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionInfo; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; + +class Dlm { + public AbstractCobolField dlm; + public int all; +} + +/** TODO: 準備中 */ +public class CobolString { + private static final int DLM_DEFAULT_NUM = 8; + + private static int udlmCount = 0; + + private static AbstractCobolField stringDst; + private static AbstractCobolField stringPtr; + private static AbstractCobolField stringDlm; + private static AbstractCobolField stringDstCopy; + private static AbstractCobolField stringPtrCopy; + private static AbstractCobolField stringDlmCopy; + private static int stringOffset; + + private static Dlm[] dlmList; + private static AbstractCobolField unstringSrc; + private static AbstractCobolField unstringPtr; + private static AbstractCobolField unstringSrcCopy; + private static AbstractCobolField unstringPtrCopy; + private static int unstringOffset; + private static int unstringCount; + private static int unstringNdlms; + + /** + * TODO: 準備中 + * + * @param dst TODO: 準備中 + * @param ptr TODO: 準備中 + */ + public static void stringInit(int dst, AbstractCobolField ptr) { + stringInit(null, ptr); + } + + /** + * TODO: 準備中 + * + * @param dst TODO: 準備中 + * @param ptr TODO: 準備中 + */ + public static void stringInit(AbstractCobolField dst, int ptr) { + stringInit(dst, null); + } + + /** + * TODO: 準備中 + * + * @param dst TODO: 準備中 + * @param ptr TODO: 準備中 + */ + public static void stringInit(int dst, int ptr) { + stringInit(null, null); + } + + /** + * TODO: 準備中 + * + * @param dst TODO: 準備中 + * @param ptr TODO: 準備中 + */ + public static void stringInit(AbstractCobolField dst, AbstractCobolField ptr) { + stringDstCopy = dst; + stringDst = stringDstCopy; + stringPtr = null; + if (ptr != null) { + stringPtrCopy = ptr; + stringPtr = stringPtrCopy; + } + stringOffset = 0; + CobolRuntimeException.setException(0); + + if (stringPtr != null) { + stringOffset = stringPtr.getInt() - 1; + if (stringOffset < 0 || stringOffset >= stringDst.getSize()) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_OVERFLOW_STRING); + } + } + + switch (stringDst.getAttribute().getType()) { + case CobolFieldAttribute.COB_TYPE_NATIONAL: + case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: + stringOffset *= 2; + break; + default: + break; + } + } + + /** + * TODO: 準備中 + * + * @param dlm TODO: 準備中 + */ + public static void stringDelimited(int dlm) { + stringDelimited(null); + } + + /** + * TODO: 準備中 + * + * @param dlm TODO: 準備中 + */ + public static void stringDelimited(AbstractCobolField dlm) { + switch (stringDst.getAttribute().getType()) { + case CobolFieldAttribute.COB_TYPE_NATIONAL: + case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: + if (dlm == CobolConstant.quote) { + dlm = CobolConstant.zenQuote; + } else if (dlm == CobolConstant.space) { + dlm = CobolConstant.zenSpace; + } else if (dlm == CobolConstant.zero) { + dlm = CobolConstant.zenZero; + } + break; + default: + break; + } + stringDlm = null; + if (dlm != null) { + stringDlmCopy = dlm; + stringDlm = stringDlmCopy; + } + } + + /** + * TODO: 準備中 + * + * @param src TODO: 準備中 + */ + public static void stringAppend(int src) { + stringAppend(null); + } + + /** + * TODO: 準備中 + * + * @param src TODO: 準備中 + */ + public static void stringAppend(AbstractCobolField src) { + if (CobolRuntimeException.code != 0) { + return; + } + + int srcSize = src.getSize(); + if (stringDlm != null) { + int size = srcSize - stringDlm.getSize() + 1; + CobolDataStorage srcData = src.getDataStorage(); + CobolDataStorage dlmData = stringDlm.getDataStorage(); + int dlmSize = stringDlm.getSize(); + for (int i = 0; i < size; ++i) { + if (srcData.getSubDataStorage(i).memcmp(dlmData, dlmSize) == 0) { + srcSize = i; + break; + } + } + } + + if (srcSize <= stringDst.getSize() - stringOffset) { + stringDst + .getDataStorage() + .getSubDataStorage(stringOffset) + .memcpy(src.getDataStorage(), srcSize); + stringOffset += srcSize; + } else { + int size = stringDst.getSize() - stringOffset; + stringDst + .getDataStorage() + .getSubDataStorage(stringOffset) + .memcpy(src.getDataStorage(), size); + stringOffset += size; + CobolRuntimeException.setException(CobolExceptionId.COB_EC_OVERFLOW_STRING); + } + } + + /** TODO: 準備中 */ + public static void stringFinish() { + int type = stringDst.getAttribute().getType(); + if (type == CobolFieldAttribute.COB_TYPE_NATIONAL + || type == CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED) { + + stringOffset /= 2; + } + if (stringPtr != null) { + stringPtr.setInt(stringOffset + 1); + } + } + + /** + * TODO: 準備中 + * + * @param src TODO: 準備中 + * @param ptr TODO: 準備中 + * @param numDlm TODO: 準備中 + */ + public static void unstringInit(int src, int ptr, int numDlm) { + unstringInit(null, null, numDlm); + } + + /** + * TODO: 準備中 + * + * @param src TODO: 準備中 + * @param ptr TODO: 準備中 + * @param numDlm TODO: 準備中 + */ + public static void unstringInit(AbstractCobolField src, int ptr, int numDlm) { + unstringInit(src, null, numDlm); + } + + /** + * TODO: 準備中 + * + * @param src TODO: 準備中 + * @param ptr TODO: 準備中 + * @param numDlm TODO: 準備中 + */ + public static void unstringInit(int src, AbstractCobolField ptr, int numDlm) { + unstringInit(null, ptr, numDlm); + } + + /** + * TODO: 準備中 + * + * @param src TODO: 準備中 + * @param ptr TODO: 準備中 + * @param numDlm TODO: 準備中 + */ + public static void unstringInit(AbstractCobolField src, AbstractCobolField ptr, int numDlm) { + unstringSrcCopy = src; + unstringSrc = unstringSrcCopy; + unstringPtr = null; + if (ptr != null) { + unstringPtrCopy = ptr; + unstringPtr = unstringPtrCopy; + } + + unstringOffset = 0; + unstringCount = 0; + unstringNdlms = 0; + CobolRuntimeException.setException(0); + + if (dlmList == null) { + if (numDlm <= DLM_DEFAULT_NUM) { + dlmList = new Dlm[DLM_DEFAULT_NUM]; + udlmCount = DLM_DEFAULT_NUM; + } else { + dlmList = new Dlm[numDlm]; + udlmCount = numDlm; + } + } else { + if (numDlm > udlmCount) { + dlmList = new Dlm[numDlm]; + udlmCount = numDlm; + } + } + + for (int i = 0; i < dlmList.length; ++i) { + dlmList[i] = new Dlm(); + } + + if (unstringPtr != null) { + unstringOffset = unstringPtr.getInt() - 1; + if (unstringOffset < 0 || unstringOffset >= unstringSrc.getSize()) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_OVERFLOW_UNSTRING); + } + } + + switch (unstringSrc.getAttribute().getType()) { + case CobolFieldAttribute.COB_TYPE_NATIONAL: + case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: + unstringOffset *= 2; + break; + default: + break; + } + } + + /** + * TODO: 準備中 + * + * @param dlm TODO: 準備中 + * @param all TODO: 準備中 + */ + public static void unstringDelimited(int dlm, int all) { + unstringDelimited(null, all); + } + + /** + * TODO: 準備中 + * + * @param dlm TODO: 準備中 + * @param all TODO: 準備中 + */ + public static void unstringDelimited(AbstractCobolField dlm, int all) { + AbstractCobolField addDlm = null; + + switch (unstringSrc.getAttribute().getType()) { + case CobolFieldAttribute.COB_TYPE_NATIONAL: + case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: + if (dlm == CobolConstant.quote) { + dlm = CobolConstant.zenQuote; + } else if (dlm == CobolConstant.space) { + dlm = CobolConstant.zenSpace; + addDlm = CobolConstant.zenBlank; + } else if (dlm == CobolConstant.zero) { + dlm = CobolConstant.zenZero; + } + break; + default: + break; + } + + dlmList[unstringNdlms].dlm = dlm; + dlmList[unstringNdlms].all = all; + unstringNdlms++; + + if (addDlm != null) { + dlmList[unstringNdlms].dlm = addDlm; + dlmList[unstringNdlms].all = all; + unstringNdlms++; + } + } + + /** + * TODO: 準備中 + * + * @param dst TODO: 準備中 + * @param dlm TODO: 準備中 + * @param cnt TODO: 準備中 + */ + public static void unstringInto(AbstractCobolField dst, AbstractCobolField dlm, int cnt) { + unstringInto(dst, dlm, null); + } + + /** + * TODO: 準備中 + * + * @param dst TODO: 準備中 + * @param dlm TODO: 準備中 + * @param cnt TODO: 準備中 + */ + public static void unstringInto(AbstractCobolField dst, int dlm, AbstractCobolField cnt) { + unstringInto(dst, null, cnt); + } + + /** + * TODO: 準備中 + * + * @param dst TODO: 準備中 + * @param dlm TODO: 準備中 + * @param cnt TODO: 準備中 + */ + public static void unstringInto(AbstractCobolField dst, int dlm, int cnt) { + unstringInto(dst, null, null); + } + + /** + * TODO: 準備中 + * + * @param dst TODO: 準備中 + * @param dlm TODO: 準備中 + * @param cnt TODO: 準備中 + */ + public static void unstringInto(int dst, int dlm, int cnt) { + unstringInto(null, null, null); + } + + /** + * TODO: 準備中 + * + * @param dst TODO: 準備中 + * @param dlm TODO: 準備中 + * @param cnt TODO: 準備中 + */ + public static void unstringInto(int dst, AbstractCobolField dlm, int cnt) { + unstringInto(null, dlm, null); + } + + /** + * TODO: 準備中 + * + * @param dst TODO: 準備中 + * @param dlm TODO: 準備中 + * @param cnt TODO: 準備中 + */ + public static void unstringInto(int dst, int dlm, AbstractCobolField cnt) { + unstringInto(null, null, cnt); + } + + /** + * TODO: 準備中 + * + * @param dst TODO: 準備中 + * @param dlm TODO: 準備中 + * @param cnt TODO: 準備中 + */ + public static void unstringInto(int dst, AbstractCobolField dlm, AbstractCobolField cnt) { + unstringInto(null, dlm, cnt); + } + + /** + * TODO: 準備中 + * + * @param dst TODO: 準備中 + * @param dlm TODO: 準備中 + * @param cnt TODO: 準備中 + */ + public static void unstringInto( + AbstractCobolField dst, AbstractCobolField dlm, AbstractCobolField cnt) { + if (CobolExceptionInfo.code != 0) { + return; + } + if (unstringOffset >= unstringSrc.getSize()) { + return; + } + + CobolDataStorage srcData = unstringSrc.getDataStorage(); + int start = unstringOffset; + int matchSize = 0; + int dlmSize = 0; + CobolDataStorage dlmData = null; + if (unstringNdlms == 0) { + matchSize = Math.min(dst.getFieldSize(), unstringSrc.getSize() - unstringOffset); + dst.moveFrom( + CobolFieldFactory.makeCobolField( + matchSize, + srcData.getSubDataStorage(unstringOffset), + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null))); + unstringOffset += matchSize; + } else { + int srSize = unstringSrc.getSize(); + int s = srSize; + boolean brkpt = false; + for (int p = start; p < s; ++p) { + for (int i = 0; i < unstringNdlms; ++i) { + int dlsize = dlmList[i].dlm.getSize(); + CobolDataStorage dp = dlmList[i].dlm.getDataStorage(); + if (p + dlsize > s) { + continue; + } + if (srcData.getSubDataStorage(p).memcmp(dp, dlsize) == 0) { + matchSize = (p - start); + dst.moveFrom( + CobolFieldFactory.makeCobolField( + matchSize, + srcData.getSubDataStorage(start), + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, + 0, + 0, + 0, + null))); + unstringOffset += matchSize + dlsize; + dlmData = dp; + dlmSize = dlsize; + if (dlmList[i].all != 0) { + for (p += dlsize; p < s; p += dlsize) { + if (p + dlsize > s) { + break; + } + if (srcData.getSubDataStorage(p).memcmp(dp, dlsize) != 0) { + break; + } + unstringOffset += dlsize; + } + } + brkpt = true; + break; + } + } + switch (unstringSrc.getAttribute().getType()) { + case CobolFieldAttribute.COB_TYPE_NATIONAL: + case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: + p++; + break; + default: + break; + } + + if (brkpt) { + break; + } + } + if (!brkpt) { + matchSize = unstringSrc.getSize() - unstringOffset; + dst.moveFrom( + CobolFieldFactory.makeCobolField( + matchSize, + srcData.getSubDataStorage(start), + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null))); + unstringOffset = unstringSrc.getSize(); + dlmData = null; + } + } + unstringCount++; + + if (dlm != null) { + if (dlmData != null) { + dlm.moveFrom( + CobolFieldFactory.makeCobolField( + dlmSize, + dlmData, + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null))); + } else if (dlm.getAttribute().isTypeNumeric()) { + dlm.moveFrom(CobolConstant.zero); + } else { + dlm.moveFrom(CobolConstant.space); + } + } + + switch (unstringSrc.getAttribute().getType()) { + case CobolFieldAttribute.COB_TYPE_NATIONAL: + case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: + matchSize /= 2; + break; + default: + break; + } + + if (cnt != null) { + cnt.setInt(matchSize); + } + } + + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void unstringTallying(int f) throws CobolStopRunException {} + + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void unstringTallying(AbstractCobolField f) throws CobolStopRunException { + f.addInt(unstringCount); + } + + /** TODO: 準備中 */ + public static void unstringFinish() { + if (unstringOffset < unstringSrc.getSize()) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_OVERFLOW_UNSTRING); + } + + switch (unstringSrc.getAttribute().getType()) { + case CobolFieldAttribute.COB_TYPE_NATIONAL: + case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: + unstringOffset /= 2; + break; + default: + break; + } + + if (unstringPtr != null) { + unstringPtr.setInt(unstringOffset + 1); + } + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolUtil.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolUtil.java index 126fbbf7..8a9ea677 100755 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolUtil.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolUtil.java @@ -1,687 +1,705 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.common; - -import java.io.UnsupportedEncodingException; -import java.time.DateTimeException; -import java.time.LocalDateTime; -import java.util.Calendar; -import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; -import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionId; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionInfo; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; -import jp.osscons.opensourcecobol.libcobj.file.CobolFile; - -/** TDOD: 準備中 */ -public class CobolUtil { - private static boolean cob_io_assume_rewrite = false; - private static boolean cob_verbose = false; - private static HandlerList hdlrs = null; - private static String runtime_err_str = null; - - /** TDOD: 準備中 */ - public static LocalDateTime cobLocalTm = null; - /** TDOD: 準備中 */ - public static String cobLocalEnv = null; - - /** TDOD: 準備中 */ - public static String[] commandLineArgs = null; - /** TDOD: 準備中 */ - public static int currentArgIndex = 1; - - /** TDOD: 準備中 */ - public static boolean nibbleCForUnsigned = false; - - /** TDOD: 準備中 */ - public static boolean[] cobSwitch = new boolean[8]; - /** TDOD: 準備中 */ - public static int cobSaveCallParams = 0; - - /** TDOD: 準備中 */ - public static boolean verbose = false; - /** TDOD: 準備中 */ - public static boolean cobErrorOnExitFlag = false; - /** TDOD: 準備中 */ - public static Calendar cal; - - /** TDOD: 準備中 */ - public static int fileSeqWriteBufferSize = 10; - - private static boolean lineTrace = false; - - /** TDOD: 準備中 */ - private static String sourceFile; - /** TDOD: 準備中 */ - private static int sourceLine; - /** TDOD: 準備中 */ - private static String currProgramId; - /** TDOD: 準備中 */ - private static String currSection; - /** TDOD: 準備中 */ - private static String currParagraph; - /** TDOD: 準備中 */ - private static String sourceStatement; - - abstract static class HandlerList { - public HandlerList next = null; - - public abstract int proc(String s); - } - - /** TDOD: 準備中 */ - public static final int FERROR_INITIALIZED = 0; - /** TDOD: 準備中 */ - public static final int FERROR_CODEGEN = 1; - /** TDOD: 準備中 */ - public static final int FERROR_CHAINING = 2; - /** TDOD: 準備中 */ - public static final int FERROR_STACK = 3; - - private static Properties envVarTable = new Properties(); - - // libcob/common.cのcob_check_envの実装 - /** - * TODO: 準備中 - * - * @param name TODO: 準備中 - * @param value TODO: 準備中 - * @return TODO: 準備中 - */ - public static int checkEnv(String name, String value) { - if (name == null || value == null) { - return 0; - } - - String s = CobolUtil.getEnv(name); - if (s != null) { - if (s.contentEquals(value)) { - return 1; - } - } - return 0; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public static boolean cob_io_rewwrite_assumed() { - return cob_io_assume_rewrite; - } - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param length TODO: 準備中 - * @param size TODO: 準備中 - * @param name TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void cobCheckRefModNational(int offset, long length, int size, byte[] name) - throws CobolStopRunException { - CobolUtil.cobCheckRefMod((offset + 1) / 2, length / 2, size / 2, name); - } - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param length TODO: 準備中 - * @param size TODO: 準備中 - * @param name TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void cobCheckRefModNational(int offset, long length, int size, String name) - throws CobolStopRunException { - CobolUtil.cobCheckRefMod((offset + 1) / 2, length / 2, size / 2, name); - } - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param length TODO: 準備中 - * @param size TODO: 準備中 - * @param name TODO: 準備中 - * @param nameLen TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void cobCheckRefMod( - int offset, long length, int size, CobolDataStorage name, int nameLen) - throws CobolStopRunException { - cobCheckRefMod(offset, length, size, name.getByteArrayRef(0, nameLen)); - } - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param length TODO: 準備中 - * @param size TODO: 準備中 - * @param name TODO: 準備中 - * @param nameLen TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void cobCheckRefMod(int offset, long length, int size, byte[] name, int nameLen) - throws CobolStopRunException { - cobCheckRefMod(offset, length, size, name); - } - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param length TODO: 準備中 - * @param size TODO: 準備中 - * @param name TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void cobCheckRefMod(int offset, long length, int size, byte[] name) - throws CobolStopRunException { - try { - CobolUtil.cobCheckRefMod(offset, length, size, new String(name, "Shift_JIS")); - } catch (UnsupportedEncodingException e) { - CobolUtil.cobCheckRefMod(offset, length, size, ""); - } - } - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param length TODO: 準備中 - * @param size TODO: 準備中 - * @param name TODO: 準備中 - * @param nameLen TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void cobCheckRefMod(int offset, long length, int size, String name, int nameLen) - throws CobolStopRunException { - cobCheckRefMod(offset, length, size, name); - } - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param length TODO: 準備中 - * @param size TODO: 準備中 - * @param name TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void cobCheckRefMod(int offset, long length, int size, String name) - throws CobolStopRunException { - /* check the offset */ - if (offset < 1 || offset > size) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_BOUND_REF_MOD); - CobolUtil.runtimeError(String.format("Offset of '%s' out of bounds: %d", name, offset)); - CobolStopRunException.stopRunAndThrow(1); - } - - /* check the length */ - if (length < 1 || offset + length - 1 > size) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_BOUND_REF_MOD); - CobolUtil.runtimeError(String.format("Length of '%s' out of bounds: %d", name, length)); - CobolStopRunException.stopRunAndThrow(1); - } - } - - /** - * TODO: 準備中 - * - * @param x TODO: 準備中 - * @param name TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void cobCheckBased(CobolDataStorage x, byte[] name) throws CobolStopRunException { - if (x == null) { - CobolUtil.runtimeError(String.format("BASED/LINKAGE item '%s' has NULL address", name)); - CobolStopRunException.stopRunAndThrow(1); - } - } - - /** - * TODO: 準備中 - * - * @param argv TODO: 準備中 - * @param cobInitialized TODO: 準備中 - */ - public static void cob_init(String[] argv, boolean cobInitialized) { - // TODO 未完成 - if (!cobInitialized) { - CobolUtil.commandLineArgs = argv; - CobolInspect.initString(); - CobolFile.cob_init_fileio(); - CobolIntrinsic.init(); - CobolUtil.envVarTable = new Properties(); - - for (int i = 0; i < 8; ++i) { - String envVariableName = String.format("COB_SWITCH_%d", i + 1); - String envValue = CobolUtil.getEnv(envVariableName); - if (envValue == null) { - CobolUtil.cobSwitch[i] = false; - } else { - CobolUtil.cobSwitch[i] = "ON".equals(envValue); - } - } - } - - cal = Calendar.getInstance(); - String s = CobolUtil.getEnv("COB_DATE"); - if (s != null) { - Pattern p = Pattern.compile("([0-9]{4})/([0-9]{2})/([0-9]{2})"); - Matcher m = p.matcher(s); - if (m.matches()) { - date_time_block: - if (m.groupCount() != 3) { - System.err.println("Warning: COB_DATE format invalid, ignored."); - } else { - int year = Integer.parseInt(m.group(1)); - int month = Integer.parseInt(m.group(2)); - int dayOfMonth = Integer.parseInt(m.group(3)); - cal.set(Calendar.YEAR, year); - cal.set(Calendar.MONTH, month - 1); - cal.set(Calendar.DAY_OF_MONTH, dayOfMonth); - LocalDateTime tm; - try { - tm = LocalDateTime.of(year, month, dayOfMonth, 0, 0); - } catch (DateTimeException e) { - break date_time_block; - } - cobLocalTm = tm; - } - } else { - System.err.println("Warning: COB_DATE format invalid, ignored."); - } - } - - s = CobolUtil.getEnv("COB_VERBOSE"); - if (s != null && s.length() > 0 && (s.charAt(0) == 'y' || s.charAt(0) == 'Y')) { - CobolUtil.cob_verbose = true; - } - - s = CobolUtil.getEnv("COB_IO_ASSUME_REWRITE"); - if (s != null && s.length() > 0 && (s.charAt(0) == 'y' || s.charAt(0) == 'Y')) { - CobolUtil.cob_io_assume_rewrite = true; - } - - s = CobolUtil.getEnv("COB_NIBBLE_C_UNSIGNED"); - if (s != null && s.length() > 0 && (s.charAt(0) == 'y' || s.charAt(0) == 'Y')) { - CobolUtil.nibbleCForUnsigned = true; - } - - s = System.getenv("COB_FILE_SEQ_WRITE_BUFFER_SIZE"); - if (s != null) { - int size = Integer.parseInt(s); - if (size >= 0) { - CobolUtil.fileSeqWriteBufferSize = size; - } - } - } - - // libcob/common.cとcob_localtime - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public static LocalDateTime localtime() { - LocalDateTime rt = LocalDateTime.now(); - if (CobolUtil.cobLocalTm != null) { - CobolUtil.cobLocalTm = - CobolUtil.cobLocalTm - .withHour(rt.getHour()) - .withMinute(rt.getMinute()) - .withSecond(rt.getSecond()); - rt = CobolUtil.cobLocalTm; - } - return rt; - } - - // libcob/cob_verbose_outputの実装 - /** - * TODO: 準備中 - * - * @param s TODO cob_verboseの初期化 - */ - public static void verboseOutput(String s) { - if (cob_verbose) { - System.out.println("libcobj: " + s); - } - } - - // libcob/fileio.cのcob_rintime_errorの実装 - /** - * TODO: 準備中 - * - * @param s TODO: 準備中 - */ - public static void runtimeError(String s) { - if (hdlrs != null) { - HandlerList h = hdlrs; - if (runtime_err_str != null) { - if (sourceFile != null) { - runtime_err_str = String.format("%s:%d: ", sourceFile, sourceLine); - } - } - while (h != null) { - if (runtime_err_str != null) { - h.proc(runtime_err_str); - } else { - h.proc("Malloc error"); - } - h = h.next; - } - hdlrs = null; - } - - if (sourceFile != null) { - System.err.print(String.format("%s:%d: ", sourceFile, sourceLine)); - } - byte[] messageBytes = ("libcobj: " + s).getBytes(AbstractCobolField.charSetSJIS); - System.err.write(messageBytes, 0, messageBytes.length); - System.err.println(); - System.err.flush(); - } - - // libcob/common.c cob_get_environment - /** - * TODO: 準備中 - * - * @param envname TODO: 準備中 - * @param envval TODO: 準備中 - */ - public static void getEnvironment(AbstractCobolField envname, AbstractCobolField envval) { - String p = CobolUtil.getEnv(envname.fieldToString()); - if (p == null) { - CobolExceptionInfo.setException(CobolExceptionId.COB_EC_IMP_ACCEPT); - p = " "; - } - envval.memcpy(p); - } - - // libcob/common.cのCOB_CHK_PARMSの実装 - /** - * TODO: 準備中 - * - * @param funcName TODO: 準備中 - * @param numParams TODO: 準備中 - */ - public static void COB_CHK_PARMS(String funcName, int numParams) {} - - // libcob/common.cのcob_get_switchの実装 - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public static boolean getSwitch(int n) { - return CobolUtil.cobSwitch[n]; - } - - // libcob/common.cのcob_set_switchの実装 - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @param flag TODO: 準備中 - */ - public static void setSwitch(int n, int flag) { - if (flag == 0) { - CobolUtil.cobSwitch[n] = false; - } else if (flag == 1) { - CobolUtil.cobSwitch[n] = true; - } - } - - // libcob/common.cのalnum_cmpsの実装 - /** - * TODO: 準備中 - * - * @param s1 TODO: 準備中 - * @param s2 TODO: 準備中 - * @param size TODO: 準備中 - * @param col TODO: 準備中 - * @return TODO: 準備中 - */ - public static int alnumCmps( - CobolDataStorage s1, CobolDataStorage s2, int size, CobolDataStorage col) { - if (col != null) { - for (int i = 0; i < size; ++i) { - int ret = - col.getByte(Byte.toUnsignedInt(s1.getByte(i))) - - col.getByte(Byte.toUnsignedInt(s2.getByte(i))); - if (ret != 0) { - return ret; - } - } - } else { - for (int i = 0; i < size; ++i) { - int ret = Byte.toUnsignedInt(s1.getByte(i)) - Byte.toUnsignedInt(s2.getByte(i)); - if (ret != 0) { - return ret; - } - } - } - return 0; - } - - // libcob/common.cのnational_cmpsの実装 - /** - * TODO: 準備中 - * - * @param s1 TODO: 準備中 - * @param s2 TODO: 準備中 - * @param size TODO: 準備中 - * @param col TODO: 準備中 - * @return TODO: 準備中 - */ - public static int nationalCmps( - CobolDataStorage s1, CobolDataStorage s2, int size, CobolDataStorage col) { - int ret = 0; - for (int i = 0; i < size && ret == 0; i += 2) { - int b11 = Byte.toUnsignedInt(s1.getByte(i)); - int b12 = Byte.toUnsignedInt(s1.getByte(i + 1)); - int b21 = Byte.toUnsignedInt(s2.getByte(i)); - int b22 = Byte.toUnsignedInt(s2.getByte(i + 1)); - ret = ((b11 << 8) | b12) - ((b21 << 8) | b22); - } - return ret; - } - - /** TODO: 準備中 */ - public static void readyTrace() { - CobolUtil.lineTrace = true; - } - - /** TODO: 準備中 */ - public static void resetTrace() { - CobolUtil.lineTrace = false; - } - - /** - * TODO: 準備中 - * - * @param fatalError TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void fatalError(int fatalError) throws CobolStopRunException { - switch (fatalError) { - case CobolUtil.FERROR_INITIALIZED: - CobolUtil.runtimeError("cob_init() has not been called"); - break; - case CobolUtil.FERROR_CODEGEN: - CobolUtil.runtimeError("Codegen error - Please report this"); - break; - case CobolUtil.FERROR_CHAINING: - CobolUtil.runtimeError("ERROR - Recursive call of chained program"); - break; - case CobolUtil.FERROR_STACK: - CobolUtil.runtimeError("Stack overflow, possible PERFORM depth exceeded"); - break; - default: - CobolUtil.runtimeError(String.format("Unknown failure : %d", fatalError)); - break; - } - CobolStopRunException.stopRunAndThrow(1); - } - - /** - * TODO: 準備中 - * - * @param progId TODO: 準備中 - * @param sfile TODO: 準備中 - * @param sline TODO: 準備中 - * @param csect TODO: 準備中 - * @param cpara TODO: 準備中 - * @param cstatement TODO: 準備中 - */ - public static void setLocation( - String progId, String sfile, int sline, String csect, String cpara, String cstatement) { - CobolUtil.sourceFile = sfile; - CobolUtil.sourceLine = sline; - currProgramId = progId; - currSection = csect; - currParagraph = cpara; - sourceLine = sline; - if (cstatement != null) { - sourceStatement = cstatement; - } - if (CobolUtil.lineTrace) { - System.err.println( - String.format( - "PROGRAM-ID: %s \tLine: %d \tStatement: %s", - progId, sline, cstatement == null ? "Unknown" : cstatement)); - System.err.flush(); - } - } - - /** - * TODO: 準備中 - * - * @param envVarName TODO: 準備中 - * @return TODO: 準備中 - */ - public static String getEnv(String envVarName) { - String envVarInTable = CobolUtil.envVarTable.getProperty(envVarName); - if (envVarInTable != null) { - return envVarInTable; - } else { - return System.getenv(envVarName); - } - } - - /** - * get environemnt variable - * - * @param envVarName the name of an environment variable. - * @param envVarValue the value to be set to the environment variable. - */ - public static void setEnv(String envVarName, String envVarValue) { - CobolUtil.envVarTable.setProperty(envVarName, envVarValue); - } - - /** - * Set environemnt variable - * - * @param envVarName the name of an environment variable. The leading and trailing spaces are - * ignored. - * @param envVarValue the value of an environment variable to be set. - */ - public static void setEnv(AbstractCobolField envVarName, AbstractCobolField envVarValue) { - CobolUtil.envVarTable.setProperty(envVarName.getString().trim(), envVarValue.getString()); - } - - /** - * TODO: 準備中 - * - * @param s TODO: 準備中 - * @return TODO: 準備中 - */ - public static byte[] stringToBytes(String s) { - try { - return s.getBytes("Shift_JIS"); - } catch (UnsupportedEncodingException e) { - return null; - } - } - - /** - * TODO: 準備中 - * - * @param bytes TODO: 準備中 - * @return TODO: 準備中 - */ - public static byte[] toBytes(byte... bytes) { - return bytes; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public static String getCurrProgramId() { - return currProgramId; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public static String getCurrSection() { - return currSection; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public static String getCurrParagraph() { - return currParagraph; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public static int getSourceLine() { - return sourceLine; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public static String getSourceStatement() { - return sourceStatement; - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.common; + +import java.time.DateTimeException; +import java.time.LocalDateTime; +import java.util.Calendar; +import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; +import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionId; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionInfo; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; +import jp.osscons.opensourcecobol.libcobj.file.CobolFile; + +/** TDOD: 準備中 */ +public class CobolUtil { + private static boolean cob_io_assume_rewrite = false; + private static boolean cob_verbose = false; + private static HandlerList hdlrs = null; + private static String runtime_err_str = null; + + /** TDOD: 準備中 */ + public static LocalDateTime cobLocalTm = null; + + /** TDOD: 準備中 */ + public static String cobLocalEnv = null; + + /** TDOD: 準備中 */ + public static String[] commandLineArgs = null; + + /** TDOD: 準備中 */ + public static int currentArgIndex = 1; + + /** TDOD: 準備中 */ + public static boolean nibbleCForUnsigned = false; + + /** TDOD: 準備中 */ + public static boolean[] cobSwitch = new boolean[8]; + + /** TDOD: 準備中 */ + public static int cobSaveCallParams = 0; + + /** TDOD: 準備中 */ + public static boolean verbose = false; + + /** TDOD: 準備中 */ + public static boolean cobErrorOnExitFlag = false; + + /** TDOD: 準備中 */ + public static Calendar cal; + + /** TDOD: 準備中 */ + public static int fileSeqWriteBufferSize = 10; + + /** DISPLAY/ACCEPT文によるデータ出力時のエンコーディング */ + public static CobolEncoding terminalEncoding = CobolEncoding.SHIFT_JIS; + + private static boolean lineTrace = false; + + /** TDOD: 準備中 */ + private static String sourceFile; + + /** TDOD: 準備中 */ + private static int sourceLine; + + /** TDOD: 準備中 */ + private static String currProgramId; + + /** TDOD: 準備中 */ + private static String currSection; + + /** TDOD: 準備中 */ + private static String currParagraph; + + /** TDOD: 準備中 */ + private static String sourceStatement; + + abstract static class HandlerList { + public HandlerList next = null; + + public abstract int proc(String s); + } + + /** TDOD: 準備中 */ + public static final int FERROR_INITIALIZED = 0; + + /** TDOD: 準備中 */ + public static final int FERROR_CODEGEN = 1; + + /** TDOD: 準備中 */ + public static final int FERROR_CHAINING = 2; + + /** TDOD: 準備中 */ + public static final int FERROR_STACK = 3; + + private static Properties envVarTable = new Properties(); + + // libcob/common.cのcob_check_envの実装 + /** + * TODO: 準備中 + * + * @param name TODO: 準備中 + * @param value TODO: 準備中 + * @return TODO: 準備中 + */ + public static int checkEnv(String name, String value) { + if (name == null || value == null) { + return 0; + } + + String s = CobolUtil.getEnv(name); + if (s != null) { + if (s.contentEquals(value)) { + return 1; + } + } + return 0; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public static boolean cob_io_rewwrite_assumed() { + return cob_io_assume_rewrite; + } + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param length TODO: 準備中 + * @param size TODO: 準備中 + * @param name TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void cobCheckRefModNational(int offset, long length, int size, byte[] name) + throws CobolStopRunException { + CobolUtil.cobCheckRefMod((offset + 1) / 2, length / 2, size / 2, name); + } + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param length TODO: 準備中 + * @param size TODO: 準備中 + * @param name TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void cobCheckRefModNational(int offset, long length, int size, String name) + throws CobolStopRunException { + CobolUtil.cobCheckRefMod((offset + 1) / 2, length / 2, size / 2, name); + } + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param length TODO: 準備中 + * @param size TODO: 準備中 + * @param name TODO: 準備中 + * @param nameLen TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void cobCheckRefMod( + int offset, long length, int size, CobolDataStorage name, int nameLen) + throws CobolStopRunException { + cobCheckRefMod(offset, length, size, name.getByteArrayRef(0, nameLen)); + } + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param length TODO: 準備中 + * @param size TODO: 準備中 + * @param name TODO: 準備中 + * @param nameLen TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void cobCheckRefMod(int offset, long length, int size, byte[] name, int nameLen) + throws CobolStopRunException { + cobCheckRefMod(offset, length, size, name); + } + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param length TODO: 準備中 + * @param size TODO: 準備中 + * @param name TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void cobCheckRefMod(int offset, long length, int size, byte[] name) + throws CobolStopRunException { + CobolUtil.cobCheckRefMod( + offset, length, size, new String(name, AbstractCobolField.charSetSJIS)); + } + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param length TODO: 準備中 + * @param size TODO: 準備中 + * @param name TODO: 準備中 + * @param nameLen TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void cobCheckRefMod(int offset, long length, int size, String name, int nameLen) + throws CobolStopRunException { + cobCheckRefMod(offset, length, size, name); + } + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param length TODO: 準備中 + * @param size TODO: 準備中 + * @param name TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void cobCheckRefMod(int offset, long length, int size, String name) + throws CobolStopRunException { + /* check the offset */ + if (offset < 1 || offset > size) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_BOUND_REF_MOD); + CobolUtil.runtimeError(String.format("Offset of '%s' out of bounds: %d", name, offset)); + CobolStopRunException.stopRunAndThrow(1); + } + + /* check the length */ + if (length < 1 || offset + length - 1 > size) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_BOUND_REF_MOD); + CobolUtil.runtimeError(String.format("Length of '%s' out of bounds: %d", name, length)); + CobolStopRunException.stopRunAndThrow(1); + } + } + + /** + * TODO: 準備中 + * + * @param x TODO: 準備中 + * @param name TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void cobCheckBased(CobolDataStorage x, byte[] name) throws CobolStopRunException { + if (x == null) { + CobolUtil.runtimeError(String.format("BASED/LINKAGE item '%s' has NULL address", name)); + CobolStopRunException.stopRunAndThrow(1); + } + } + + /** + * TODO: 準備中 + * + * @param argv TODO: 準備中 + * @param cobInitialized TODO: 準備中 + */ + public static void cob_init(String[] argv, boolean cobInitialized) { + // TODO 未完成 + if (!cobInitialized) { + CobolUtil.commandLineArgs = argv; + CobolInspect.initString(); + CobolFile.cob_init_fileio(); + CobolIntrinsic.init(); + CobolUtil.envVarTable = new Properties(); + + for (int i = 0; i < 8; ++i) { + String envVariableName = String.format("COB_SWITCH_%d", i + 1); + String envValue = CobolUtil.getEnv(envVariableName); + if (envValue == null) { + CobolUtil.cobSwitch[i] = false; + } else { + CobolUtil.cobSwitch[i] = "ON".equals(envValue); + } + } + } + + cal = Calendar.getInstance(); + String s = CobolUtil.getEnv("COB_DATE"); + if (s != null) { + Pattern p = Pattern.compile("([0-9]{4})/([0-9]{2})/([0-9]{2})"); + Matcher m = p.matcher(s); + if (m.matches()) { + date_time_block: + if (m.groupCount() != 3) { + System.err.println("Warning: COB_DATE format invalid, ignored."); + } else { + int year = Integer.parseInt(m.group(1)); + int month = Integer.parseInt(m.group(2)); + int dayOfMonth = Integer.parseInt(m.group(3)); + cal.set(Calendar.YEAR, year); + cal.set(Calendar.MONTH, month - 1); + cal.set(Calendar.DAY_OF_MONTH, dayOfMonth); + LocalDateTime tm; + try { + tm = LocalDateTime.of(year, month, dayOfMonth, 0, 0); + } catch (DateTimeException e) { + break date_time_block; + } + cobLocalTm = tm; + } + } else { + System.err.println("Warning: COB_DATE format invalid, ignored."); + } + } + + s = CobolUtil.getEnv("COB_VERBOSE"); + if (s != null && s.length() > 0 && (s.charAt(0) == 'y' || s.charAt(0) == 'Y')) { + CobolUtil.cob_verbose = true; + } + + s = CobolUtil.getEnv("COB_IO_ASSUME_REWRITE"); + if (s != null && s.length() > 0 && (s.charAt(0) == 'y' || s.charAt(0) == 'Y')) { + CobolUtil.cob_io_assume_rewrite = true; + } + + s = CobolUtil.getEnv("COB_NIBBLE_C_UNSIGNED"); + if (s != null && s.length() > 0 && (s.charAt(0) == 'y' || s.charAt(0) == 'Y')) { + CobolUtil.nibbleCForUnsigned = true; + } + + s = System.getenv("COB_FILE_SEQ_WRITE_BUFFER_SIZE"); + if (s != null) { + int size = Integer.parseInt(s); + if (size >= 0) { + CobolUtil.fileSeqWriteBufferSize = size; + } + } + + s = System.getenv("COB_TERMINAL_ENCODING"); + CobolUtil.terminalEncoding = CobolEncoding.SHIFT_JIS; + if (s != null) { + Pattern p = Pattern.compile("[uU][tT][fF][_-]?8"); + Matcher m = p.matcher(s); + if (m.matches()) { + CobolUtil.terminalEncoding = CobolEncoding.UTF8; + } + } + } + + // libcob/common.cとcob_localtime + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public static LocalDateTime localtime() { + LocalDateTime rt = LocalDateTime.now(); + if (CobolUtil.cobLocalTm != null) { + CobolUtil.cobLocalTm = + CobolUtil.cobLocalTm + .withHour(rt.getHour()) + .withMinute(rt.getMinute()) + .withSecond(rt.getSecond()); + rt = CobolUtil.cobLocalTm; + } + return rt; + } + + // libcob/cob_verbose_outputの実装 + /** + * TODO: 準備中 + * + * @param s TODO cob_verboseの初期化 + */ + public static void verboseOutput(String s) { + if (cob_verbose) { + System.out.println("libcobj: " + s); + } + } + + // libcob/fileio.cのcob_rintime_errorの実装 + /** + * TODO: 準備中 + * + * @param s TODO: 準備中 + */ + public static void runtimeError(String s) { + if (hdlrs != null) { + HandlerList h = hdlrs; + if (runtime_err_str != null) { + if (sourceFile != null) { + runtime_err_str = String.format("%s:%d: ", sourceFile, sourceLine); + } + } + while (h != null) { + if (runtime_err_str != null) { + h.proc(runtime_err_str); + } else { + h.proc("Malloc error"); + } + h = h.next; + } + hdlrs = null; + } + + if (sourceFile != null) { + System.err.print(String.format("%s:%d: ", sourceFile, sourceLine)); + } + byte[] messageBytes = ("libcobj: " + s).getBytes(AbstractCobolField.charSetSJIS); + System.err.write(messageBytes, 0, messageBytes.length); + System.err.println(); + System.err.flush(); + } + + // libcob/common.c cob_get_environment + /** + * TODO: 準備中 + * + * @param envname TODO: 準備中 + * @param envval TODO: 準備中 + */ + public static void getEnvironment(AbstractCobolField envname, AbstractCobolField envval) { + String p = CobolUtil.getEnv(envname.fieldToString()); + if (p == null) { + CobolExceptionInfo.setException(CobolExceptionId.COB_EC_IMP_ACCEPT); + p = " "; + } + envval.memcpy(p); + } + + // libcob/common.cのCOB_CHK_PARMSの実装 + /** + * TODO: 準備中 + * + * @param funcName TODO: 準備中 + * @param numParams TODO: 準備中 + */ + public static void COB_CHK_PARMS(String funcName, int numParams) {} + + // libcob/common.cのcob_get_switchの実装 + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public static boolean getSwitch(int n) { + return CobolUtil.cobSwitch[n]; + } + + // libcob/common.cのcob_set_switchの実装 + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @param flag TODO: 準備中 + */ + public static void setSwitch(int n, int flag) { + if (flag == 0) { + CobolUtil.cobSwitch[n] = false; + } else if (flag == 1) { + CobolUtil.cobSwitch[n] = true; + } + } + + // libcob/common.cのalnum_cmpsの実装 + /** + * TODO: 準備中 + * + * @param s1 TODO: 準備中 + * @param s2 TODO: 準備中 + * @param size TODO: 準備中 + * @param col TODO: 準備中 + * @return TODO: 準備中 + */ + public static int alnumCmps( + CobolDataStorage s1, CobolDataStorage s2, int size, CobolDataStorage col) { + if (col != null) { + for (int i = 0; i < size; ++i) { + int ret = + col.getByte(Byte.toUnsignedInt(s1.getByte(i))) + - col.getByte(Byte.toUnsignedInt(s2.getByte(i))); + if (ret != 0) { + return ret; + } + } + } else { + for (int i = 0; i < size; ++i) { + int ret = Byte.toUnsignedInt(s1.getByte(i)) - Byte.toUnsignedInt(s2.getByte(i)); + if (ret != 0) { + return ret; + } + } + } + return 0; + } + + // libcob/common.cのnational_cmpsの実装 + /** + * TODO: 準備中 + * + * @param s1 TODO: 準備中 + * @param s2 TODO: 準備中 + * @param size TODO: 準備中 + * @param col TODO: 準備中 + * @return TODO: 準備中 + */ + public static int nationalCmps( + CobolDataStorage s1, CobolDataStorage s2, int size, CobolDataStorage col) { + int ret = 0; + for (int i = 0; i < size && ret == 0; i += 2) { + int b11 = Byte.toUnsignedInt(s1.getByte(i)); + int b12 = Byte.toUnsignedInt(s1.getByte(i + 1)); + int b21 = Byte.toUnsignedInt(s2.getByte(i)); + int b22 = Byte.toUnsignedInt(s2.getByte(i + 1)); + ret = ((b11 << 8) | b12) - ((b21 << 8) | b22); + } + return ret; + } + + /** TODO: 準備中 */ + public static void readyTrace() { + CobolUtil.lineTrace = true; + } + + /** TODO: 準備中 */ + public static void resetTrace() { + CobolUtil.lineTrace = false; + } + + /** + * TODO: 準備中 + * + * @param fatalError TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void fatalError(int fatalError) throws CobolStopRunException { + switch (fatalError) { + case CobolUtil.FERROR_INITIALIZED: + CobolUtil.runtimeError("cob_init() has not been called"); + break; + case CobolUtil.FERROR_CODEGEN: + CobolUtil.runtimeError("Codegen error - Please report this"); + break; + case CobolUtil.FERROR_CHAINING: + CobolUtil.runtimeError("ERROR - Recursive call of chained program"); + break; + case CobolUtil.FERROR_STACK: + CobolUtil.runtimeError("Stack overflow, possible PERFORM depth exceeded"); + break; + default: + CobolUtil.runtimeError(String.format("Unknown failure : %d", fatalError)); + break; + } + CobolStopRunException.stopRunAndThrow(1); + } + + /** + * TODO: 準備中 + * + * @param progId TODO: 準備中 + * @param sfile TODO: 準備中 + * @param sline TODO: 準備中 + * @param csect TODO: 準備中 + * @param cpara TODO: 準備中 + * @param cstatement TODO: 準備中 + */ + public static void setLocation( + String progId, String sfile, int sline, String csect, String cpara, String cstatement) { + CobolUtil.sourceFile = sfile; + CobolUtil.sourceLine = sline; + currProgramId = progId; + currSection = csect; + currParagraph = cpara; + sourceLine = sline; + if (cstatement != null) { + sourceStatement = cstatement; + } + if (CobolUtil.lineTrace) { + System.err.println( + String.format( + "PROGRAM-ID: %s \tLine: %d \tStatement: %s", + progId, sline, cstatement == null ? "Unknown" : cstatement)); + System.err.flush(); + } + } + + /** + * TODO: 準備中 + * + * @param envVarName TODO: 準備中 + * @return TODO: 準備中 + */ + public static String getEnv(String envVarName) { + String envVarInTable = CobolUtil.envVarTable.getProperty(envVarName); + if (envVarInTable != null) { + return envVarInTable; + } else { + return System.getenv(envVarName); + } + } + + /** + * get environemnt variable + * + * @param envVarName the name of an environment variable. + * @param envVarValue the value to be set to the environment variable. + */ + public static void setEnv(String envVarName, String envVarValue) { + CobolUtil.envVarTable.setProperty(envVarName, envVarValue); + } + + /** + * Set environemnt variable + * + * @param envVarName the name of an environment variable. The leading and trailing spaces are + * ignored. + * @param envVarValue the value of an environment variable to be set. + */ + public static void setEnv(AbstractCobolField envVarName, AbstractCobolField envVarValue) { + CobolUtil.envVarTable.setProperty(envVarName.getString().trim(), envVarValue.getString()); + } + + /** + * TODO: 準備中 + * + * @param s TODO: 準備中 + * @return TODO: 準備中 + */ + public static byte[] stringToBytes(String s) { + return s.getBytes(AbstractCobolField.charSetSJIS); + } + + /** + * TODO: 準備中 + * + * @param bytes TODO: 準備中 + * @return TODO: 準備中 + */ + public static byte[] toBytes(byte... bytes) { + return bytes; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public static String getCurrProgramId() { + return currProgramId; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public static String getCurrSection() { + return currSection; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public static String getCurrParagraph() { + return currParagraph; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public static int getSourceLine() { + return sourceLine; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public static String getSourceStatement() { + return sourceStatement; + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/GetAbstractCobolField.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/GetAbstractCobolField.java index 2467bc18..e0884f72 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/GetAbstractCobolField.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/GetAbstractCobolField.java @@ -1,33 +1,33 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.common; - -import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; - -/** TODO: 準備中 */ -public interface GetAbstractCobolField { - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - AbstractCobolField run() throws CobolStopRunException; -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.common; + +import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; + +/** TODO: 準備中 */ +public interface GetAbstractCobolField { + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + AbstractCobolField run() throws CobolStopRunException; +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/GetInt.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/GetInt.java index bfd08fe8..3dd2ffcb 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/GetInt.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/GetInt.java @@ -1,29 +1,32 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.common; - -/** TODO: 準備中 */ -public interface GetInt { - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - int run(); -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.common; + +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; + +/** TODO: 準備中 */ +public interface GetInt { + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + int run() throws CobolStopRunException; +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/AbstractCobolField.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/AbstractCobolField.java index 0be6e2bd..251a7356 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/AbstractCobolField.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/AbstractCobolField.java @@ -1,1737 +1,1775 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.data; - -import java.math.BigDecimal; -import java.nio.ByteBuffer; -import java.nio.charset.Charset; -import jp.osscons.opensourcecobol.libcobj.common.CobolConstant; -import jp.osscons.opensourcecobol.libcobj.common.CobolModule; -import jp.osscons.opensourcecobol.libcobj.common.CobolUtil; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; - -/** COBOLで使用する変数を表現するクラス。 */ -public abstract class AbstractCobolField { - /** データを格納に使用するバイト配列の長さ */ - protected int size; - - /** データを格納するバイト配列を扱うオブジェクト */ - protected CobolDataStorage dataStorage; - - /** 変数に関する様々な情報を保持するオブジェクト(符号付か,COMP-3指定かなど) */ - protected CobolFieldAttribute attribute; - - static int lastsize = 0; - static CobolDataStorage lastdata = null; - /** TODO: 準備中 */ - public static Charset charSetSJIS = Charset.forName("SHIFT-JIS"); - - static final int[] cobExp10 = { - 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 - }; - - /** - * コンストラクタ - * - * @param size データを格納するバイト配列の長さ - * @param dataStorage データを格納するバイト配列を扱うオブジェクト - * @param attribute 変数に関する様々な情報を保持するオブジェクト(符号付か,COMP-3指定かなど) - */ - public AbstractCobolField(int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { - this.size = size; - this.dataStorage = dataStorage; - this.attribute = attribute; - } - - /** - * メンバ変数dataStorageのgetter - * - * @return this.dataStorage - */ - public CobolDataStorage getDataStorage() { - return dataStorage; - } - - /** - * メンバ変数dataStorageのsetter - * - * @param dataStorage TODO: 準備中 - */ - public void setDataStorage(CobolDataStorage dataStorage) { - this.dataStorage = dataStorage; - } - - /** - * メンバ変数attributeのsetter - * - * @param attribute TODO: 準備中 - */ - public void setAttribute(CobolFieldAttribute attribute) { - this.attribute = attribute; - } - - /** - * メンバ変数attributeのgetter - * - * @return this.attribute - */ - public CobolFieldAttribute getAttribute() { - return attribute; - } - - /** - * メンバ変数sizeのsetter - * - * @param size TODO: 準備中 - */ - public void setSize(int size) { - this.size = size; - } - - /** - * メンバ変数sizeのgetter - * - * @return this.size - */ - public int getSize() { - return size; - } - - /** - * 符号部分を除いた数値部分の長さを返す - * - * @return 符号付で符号が分離している場合はthis.size-1,そうでなければthis.size - */ - public int getFieldSize() { - return this.size - (this.attribute.isFlagSignSeparate() ? 1 : 0); - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public CobolDataStorage getFieldData() { - if (this.attribute.isFlagSignSeparate() && this.attribute.isFlagSignLeading()) { - return new CobolDataStorage(this.dataStorage.getRefOfData(), this.dataStorage.getIndex() + 1); - } else { - return this.dataStorage; - } - } - - /** - * バイト配列の中で(符号データではなく)数値データの格納されている最小の添え字を返す - * - * @return SIGN LEADINGかつSIGN SEPARATEな変数なら1,それ以外は0 - */ - public int getFirstDataIndex() { - return (this.attribute.isFlagSignSeparate() && this.attribute.isFlagSignLeading()) ? 1 : 0; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public byte[] getBytes() { - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, - 9, - 0, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - CobolDataStorage n = new CobolDataStorage(new byte[4], 0); - AbstractCobolField temp = CobolFieldFactory.makeCobolField(4, n, attr); - temp.moveFrom(this); - return ByteBuffer.wrap(n.getByteArray(0, 4)).array(); - } - - /** - * thisの文字列表現をかえす. - * - * @return thisの文字列表現 - */ - public abstract String getString(); - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public int getInt() { - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, - 9, - 0, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - CobolDataStorage n = new CobolDataStorage(new byte[4], 0); - AbstractCobolField temp = CobolFieldFactory.makeCobolField(4, n, attr); - temp.moveFrom(this); - return ByteBuffer.wrap(n.getByteArray(0, 4)).getInt(); - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public double getDouble() { - try { - return Double.parseDouble(this.getString()); - } catch (Exception e) { - return 0; - } - } - - /** - * 数値を表すデータが実装すべきメソッド. 保持する数値データをCobolDecimal型に変換する. - * - * @return 保持する数値データをCobolDecimal型に変換した値 - */ - public CobolDecimal getDecimal() { - CobolDataStorage data = this.getDataStorage(); - int firstDataIndex = this.getFirstDataIndex(); - int size = this.getFieldSize(); - - if (Byte.toUnsignedInt(data.getByte(firstDataIndex)) == 0xFF) { - CobolDecimal decimal = new CobolDecimal(BigDecimal.TEN.pow(size)); - decimal.setScale(this.getAttribute().getScale()); - return decimal; - } - - if (data.getByte(firstDataIndex) == 0) { - CobolDecimal decimal = new CobolDecimal(BigDecimal.TEN.pow(size).negate()); - decimal.setScale(this.getAttribute().getScale()); - return decimal; - } - - char[] buf = new char[size]; - for (int i = 0; i < size; ++i) { - byte val = data.getByte(firstDataIndex + i); - if (val >= 0x70) { - buf[i] = (char) (val - 0x40); - } else { - buf[i] = (char) val; - } - } - - CobolFieldAttribute attr = this.getAttribute(); - int sign = 1; - if (attr.isFlagHaveSign()) { - if (attr.isFlagSignSeparate()) { - int signIndex = attr.isFlagSignLeading() ? 0 : this.getSize() - 1; - if (data.getByte(signIndex) == '-') { - sign = -1; - } - } else { - int signIndex = attr.isFlagSignLeading() ? 0 : this.getSize() - 1; - if (data.getByte(signIndex) >= 0x70) { - sign = -1; - } - } - } - - BigDecimal decimal = new BigDecimal(buf); - if (sign < 0) { - decimal = decimal.negate(); - } - CobolDecimal ret = new CobolDecimal(decimal); - ret.setScale(this.getAttribute().getScale()); - return ret; - } - - /** - * TODO: 準備中 - * - * @param decimal TODO: 準備中 - */ - public abstract void setDecimal(BigDecimal decimal); - - /** - * thisの保持する数値データをint型で返す - * - * @param size TODO: 準備中 - * @return thisの保持する数値データをintに変換した値 - */ - public int getInt(int size) { - int retval = 0; - int p = 0; - CobolDataStorage data = this.getDataStorage(); - for (int n = 0; n < size; ++n, ++p) { - retval *= 10; - if (data.getByte(p) > (byte) '9') { - retval += 10; - } else { - retval += data.getByte(p) - (byte) '0'; - } - } - return retval; - } - - /** thisの保持する数値データを0に設定するメソッド. */ - public void setZero() { - throw new CobolRuntimeException(0, "未実装"); - } - - /** - * thisの保持する数値データに,引数で与えられたフィールドの保持する数値データを加算する - * - * @param field 加算する数値を保持するフィールド - * @param opt 加算に関するオプション.詳しくはTODO: 準備中 - * @return 加算後のthisの保持する数値データ - * @throws CobolStopRunException TODO: 準備中 - */ - public int add(AbstractCobolField field, int opt) throws CobolStopRunException { - CobolDecimal d1 = this.getDecimal(); - CobolDecimal d2 = field.getDecimal(); - d1.add(d2); - return d1.getField(this, opt); - } - - /** - * thisの保持する数値データに,引数で与えられたフィールドの保持する数値データを減算する - * - * @param field 減算する数値を保持するフィールド - * @param opt 減算に関するオプション.詳しくはTODO: 準備中 - * @return 減算後のthisの保持する数値データ - * @throws CobolStopRunException TODO: 準備中 - */ - public int sub(AbstractCobolField field, int opt) throws CobolStopRunException { - CobolDecimal d1 = this.getDecimal(); - CobolDecimal d2 = field.getDecimal(); - d1.sub(d2); - return d1.getField(this, opt); - } - - /** - * 保持する数値データに指定された値を加算する - * - * @param n thisの保持する数値データから加算する数値 - * @return 基本的に0が返される.詳しくは詳しくはTODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public int addInt(int n) throws CobolStopRunException { - if (n == 0) { - return 0; - } - CobolDecimal d1 = this.getDecimal(); - CobolDecimal d2 = new CobolDecimal(n); - d2.setScale(0); - if (d1.getScale() != 0) { - BigDecimal cobMexp = BigDecimal.TEN.pow(d1.getScale()); - d2.setValue(d2.getValue().multiply(cobMexp)); - d2.setScale(d1.getScale()); - } - d1.setValue(d1.getValue().add(d2.getValue())); - return d1.getField(this, 0); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public abstract int addPackedInt(int n); - - /** - * thisの保持する数値データに指定された値を減算する - * - * @param n thisの保持する数値データから減算する数値 - * @return 基本的に0が返される.詳しくはTODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public int subInt(int n) throws CobolStopRunException { - return n == 0 ? 0 : this.addInt(-n); - } - - /** - * TODO: 準備中 - * - * @param divisor TODO: 準備中 - * @param quotient TODO: 準備中 - * @param opt TODO: 準備中 - * @return TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public int divQuotient(AbstractCobolField divisor, AbstractCobolField quotient, int opt) - throws CobolStopRunException { - AbstractCobolField dividend = this; - CobolDecimal d1 = dividend.getDecimal(); - CobolDecimal d2 = divisor.getDecimal(); - CobolDecimal.cobD3.set(d1); - - d1.div(d2); - if (d1.getScale() == CobolDecimal.DECIMAL_NAN) { - CobolDecimal.cobD3.setScale(CobolDecimal.DECIMAL_NAN); - // TODO 例外を投げるべきか? - return 0; - } - CobolDecimal d4 = new CobolDecimal(); - d4.set(d1); - int ret = d1.getField(quotient, opt); - - d4.shiftDecimal(quotient.getAttribute().getScale() - d4.getScale()); - - d4.mul(d2); - CobolDecimal.cobD3.sub(d4); - - return ret; - } - - /** - * TODO: 準備中 - * - * @param opt TODO: 準備中 - * @return TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public int divRemainder(int opt) throws CobolStopRunException { - return CobolDecimal.cobD3.getField(this, opt); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpInt(int n) { - CobolDecimal d1 = this.getDecimal(); - CobolDecimal d2 = new CobolDecimal(n); - d2.setScale(0); - return d1.compareTo(d2); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpInt(long n) { - return this.cmpInt((int) n); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpUint(int n) { - return this.cmpInt(n); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpUint(long n) { - return this.cmpUint((int) n); - } - - /** - * TODO: 準備中 - * - * @param field TODO: 準備中 - * @return TODO: 準備中 - */ - public int numericCompareTo(AbstractCobolField field) { - CobolDecimal d1 = this.getDecimal(); - CobolDecimal d2 = field.getDecimal(); - return d1.compareTo(d2); - } - - /** - * thisの保持する数値データの符号を返す - * - * @return thisの保持する数値データが負ならば負数,0なら0,正なら正数を返す - */ - public int getSign() { - return this.getAttribute().isFlagHaveSign() ? this.realGetSign() : 0; - } - - /** - * thisの保持する数値データの符号を設定する - * - * @param sign 正符号を設定するときは正数,負符号を設定するときは負数,それ以外は0 - */ - public void putSign(int sign) { - if (this.getAttribute().isFlagHaveSign()) { - this.realPutSign(sign); - } - } - - /** - * TODO: 準備中 - * - * @param src TODO: 準備中 - * @return TODO: 準備中 - */ - protected AbstractCobolField preprocessOfMoving(AbstractCobolField src) { - AbstractCobolField src1 = src; - - if (src1.getAttribute().isTypeAlphanumAll() || src1.getAttribute().isTypeNationalAll()) { - this.moveFromAll(src); - return null; - } - - if (this.getSize() == 0) { - return null; - } - - CobolFieldAttribute srcAttr = src1.getAttribute(); - CobolFieldAttribute dstAttr = this.getAttribute(); - if (!srcAttr.isTypeGroup()) { - if ((srcAttr.isTypeNumeric() || srcAttr.isTypeAlphanum() || srcAttr.isTypeAlphanumEdited()) - && (dstAttr.isTypeNational() || dstAttr.isTypeNationalEdited())) { - byte[] pTmp = null; - int size = 0; - if (srcAttr.isTypeNumericDisplay() - || srcAttr.isTypeAlphanum() - || srcAttr.isTypeAlphanumEdited()) { - pTmp = CobolNationalField.judge_hankakujpn_exist(src1); - size = CobolNationalField.workReturnSize; - } - if (pTmp != null) { - src1.setDataStorage(new CobolDataStorage(pTmp)); - src1.setSize(size); - } - if (src1.size == 0) { - return src1; - } - } - } - - if (src1.getSize() == 0) { - return src1; - } - - return src; - } - - /** - * TODO: 準備中 - * - * @param src TODO: 準備中 - */ - protected void moveFromAll(AbstractCobolField src) { - int size = 0; - CobolDataStorage tmpSrcStorage = null; - int tmpSrcSize = 0; - boolean xToN = false; - CobolFieldAttribute attr; - int digcount; - - if (!(src.getAttribute().isTypeNational() || src.getAttribute().isTypeNationalEdited()) - && (this.attribute.isTypeNational() || this.attribute.isTypeNationalEdited())) { - CobolDataStorage pTmp; - byte[] pBytes = CobolNationalField.judge_hankakujpn_exist(src); - pTmp = new CobolDataStorage(pBytes); - size = CobolNationalField.workReturnSize; - tmpSrcStorage = pTmp; - tmpSrcSize = size; - xToN = true; - } - - if (xToN) { - attr = new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NATIONAL, 0, 0, 0, null); - } else { - attr = new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); - } - if (this.attribute.isTypeNumeric()) { - digcount = 18; - attr.setType(CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY); - attr.setDigits(18); - } else { - digcount = this.size; - } - if (digcount > AbstractCobolField.lastsize) { - AbstractCobolField.lastdata = new CobolDataStorage(digcount); - AbstractCobolField.lastsize = digcount; - } - - AbstractCobolField temp = CobolFieldFactory.makeCobolField(digcount, lastdata, attr); - - if (xToN && tmpSrcSize > 1) { - for (int i = 0; i < digcount; ++i) { - lastdata.setByte(i, tmpSrcStorage.getByte(i % tmpSrcSize)); - } - } else { - if (src.getSize() == 1) { - lastdata.memset(src.getDataStorage().getByte(0), digcount); - } else { - int i; - for (i = 0; i < digcount; ++i) { - lastdata.setByte(i, src.getDataStorage().getByte(i % src.getSize())); - } - - int b = Byte.toUnsignedInt(lastdata.getByte(i - 1)); - if ((0x81 <= b && b <= 0x9F) || (0xE0 <= b && b <= 0xFC)) { - lastdata.setByte(i - 1, (byte) ' '); - } - } - } - this.moveFrom(temp); - } - - /** - * 引数で与えらえられたデータからthisへの代入を行う - * - * @param field 代入元のデータ - */ - public abstract void moveFrom(AbstractCobolField field); - - /** - * 引数で与えらえられたデータからthisへの代入を行う - * - * @param dataStorage 代入元のデータ - */ - public abstract void moveFrom(CobolDataStorage dataStorage); - - /** - * 引数で与えらえられたデータからthisへの代入を行う - * - * @param bytes 代入元のデータ - */ - public abstract void moveFrom(byte[] bytes); - - /** - * 引数で与えらえられたデータからthisへの代入を行う - * - * @param s 代入元のデータ - */ - public void moveFrom(String s) { - // The maximum number of digits of int type in decimal is 10 - - byte[] bytes = s.getBytes(charSetSJIS); - - CobolDataStorage storage = new CobolDataStorage(bytes.length); - storage.memcpy(bytes); - - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, - bytes.length, - 0, - 0, - String.format("X(%d)", bytes.length)); - - AbstractCobolField tmp = CobolFieldFactory.makeCobolField(bytes.length, storage, attr); - this.moveFrom(tmp); - } - - /** - * 引数で与えらえられたデータからthisへの代入を行う - * - * @param number 代入元のデータ - */ - public void moveFrom(int number) { - // The maximum number of digits of int type in decimal is 10 - final int length = 10; - - CobolDataStorage storage = new CobolDataStorage(length); - String formattedNumberString = String.format("%10d", Math.abs(number)); - storage.memcpy(formattedNumberString, length); - if (number < 0) { - storage.setByte(length - 1, (byte) (storage.getByte(length - 1) + 0x40)); - } - - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, - length, - 0, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - "S9(10)"); - - AbstractCobolField tmp = CobolFieldFactory.makeCobolField(length, storage, attr); - this.moveFrom(tmp); - } - - /** - * 引数で与えらえられたデータからthisへの代入を行う - * - * @param number 代入元のデータ - */ - public void moveFrom(double number) { - String s = Double.toString(Math.abs(number)); - String ss; - int scale; - ss = s.replace("+", "").replace("-", ""); - int pointIndex = ss.indexOf('.'); - if (pointIndex < 0) { - scale = 0; - } else { - scale = ss.length() - 1 - pointIndex; - ss = ss.replace(".", ""); - } - - CobolDataStorage storage = new CobolDataStorage(ss.length()); - storage.memcpy(ss, ss.length()); - - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, - ss.length(), - scale, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - ""); - - AbstractCobolField tmp = CobolFieldFactory.makeCobolField(ss.length(), storage, attr); - if (number < 0) { - tmp.putSign(-1); - } - this.moveFrom(tmp); - } - - /** - * 引数で与えらえられたデータからthisへの代入を行う - * - * @param number 代入元のデータ - */ - public abstract void moveFrom(BigDecimal number); - - /** - * TODO: 準備中 - * - * @param s TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public void checkNumeric(byte[] s) throws CobolStopRunException { - if (!this.isNumeric()) { - byte[] buff = this.getDataStorage().getByteArrayRef(0, this.getSize()); - String name = new String(s, charSetSJIS); - String content = new String(buff, charSetSJIS); - CobolUtil.runtimeError("'" + name + "' not numeric: '" + content + "'"); - CobolStopRunException.stopRunAndThrow(1); - } - } - - // TODO abstract指定 - /** - * thisと引数で与えられたデータとの数値比較を行う - * - * @param other thisと比較するfield - * @return 保持する数値データの比較を行い,this<fieldなら負の値,this==fieldなら0,this>fieldなら正の値 - */ - public int compareTo(AbstractCobolField other) { - AbstractCobolField f1 = this; - AbstractCobolField f2 = other; - CobolFieldAttribute attr1 = f1.getAttribute(); - CobolFieldAttribute attr2 = f2.getAttribute(); - - if (attr1.isTypeNational() || attr1.isTypeNationalAll() || attr1.isTypeNationalEdited()) { - if (f2 == CobolConstant.quote) { - f2 = CobolConstant.zenQuote; - } else if (f2 == CobolConstant.space) { - f2 = CobolConstant.zenSpace; - } else if (f2 == CobolConstant.zero) { - f2 = CobolConstant.zenZero; - } - } - - if (attr2.isTypeNational() || attr2.isTypeNationalAll() || attr2.isTypeNationalEdited()) { - if (f1 == CobolConstant.quote) { - f1 = CobolConstant.zenQuote; - } else if (f1 == CobolConstant.space) { - f1 = CobolConstant.zenSpace; - } else if (f1 == CobolConstant.zero) { - f1 = CobolConstant.zenZero; - } - } - - attr1 = f1.getAttribute(); - attr2 = f2.getAttribute(); - - if (attr1.isTypeNumeric() && attr2.isTypeNumeric()) { - return f1.numericCompareTo(f2); - } - if (attr2.isTypeAlphanumAll()) { - if (f2 == CobolConstant.zero && attr1.isTypeNumeric()) { - return f1.cmpInt(0); - } else if (f2.getSize() == 1) { - return f1.cmpChar(f2.getDataStorage().getByte(0)); - } else { - return f1.cmpAll(f2); - } - } else if (attr1.isTypeAlphanumAll()) { - if (f1 == CobolConstant.zero && attr2.isTypeNumeric()) { - return -f2.cmpInt(0); - } else if (f1.getSize() == 1) { - return -f2.cmpChar(f1.getDataStorage().getByte(0)); - } else { - return -f2.cmpAll(f1); - } - } else if (attr2.isTypeNationalAll()) { - if (f2 == CobolConstant.zero && attr1.isTypeNumeric()) { - return f1.cmpInt(0); - } else if (f2.getSize() == 1) { - return f1.cmpChar(f2.getDataStorage().getByte(0)); - } else { - return f1.cmpAll(f2); - } - } else if (attr1.isTypeNationalAll()) { - if (f1 == CobolConstant.zero && attr2.isTypeNumeric()) { - return -f2.cmpInt(0); - } else if (f1.getSize() == 1) { - return -f2.cmpChar(f1.getDataStorage().getByte(0)); - } else { - return -f2.cmpAll(f1); - } - } else if (attr1.isTypeGroup() || attr2.isTypeGroup()) { - return f1.cmpSimpleStr(f2); - } else { - if (attr1.isTypeNumeric()) { - if (attr1.getType() != CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY) { - int tmpSize = attr1.getDigits(); - CobolDataStorage tmpBuff = new CobolDataStorage(48); - CobolFieldAttribute tmpAttr = new CobolFieldAttribute(attr1); - tmpAttr.setType(CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY); - tmpAttr.setFlags(tmpAttr.getFlags() & ~CobolFieldAttribute.COB_FLAG_HAVE_SIGN); - AbstractCobolField tmpField = CobolFieldFactory.makeCobolField(tmpSize, tmpBuff, tmpAttr); - tmpField.moveFrom(f1); - f1 = tmpField; - } else if (attr1.isFlagSignSeparate()) { - int tmpSize = attr1.getDigits(); - CobolDataStorage tmpBuff = new CobolDataStorage(48); - CobolFieldAttribute tmpAttr = new CobolFieldAttribute(attr1); - tmpAttr.setType(CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY); - tmpAttr.setFlags(CobolFieldAttribute.COB_FLAG_HAVE_SIGN); - AbstractCobolField tmpField = CobolFieldFactory.makeCobolField(tmpSize, tmpBuff, tmpAttr); - tmpField.moveFrom(f1); - f1 = tmpField; - } - } - if (attr2.isTypeNumeric()) { - if (attr2.getType() != CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY) { - int tmpSize = attr2.getDigits(); - CobolDataStorage tmpBuff = new CobolDataStorage(48); - CobolFieldAttribute tmpAttr = new CobolFieldAttribute(attr2); - tmpAttr.setType(CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY); - tmpAttr.setFlags(tmpAttr.getFlags() & ~CobolFieldAttribute.COB_FLAG_HAVE_SIGN); - AbstractCobolField tmpField = CobolFieldFactory.makeCobolField(tmpSize, tmpBuff, tmpAttr); - tmpField.moveFrom(f2); - f2 = tmpField; - } else if (attr2.isFlagSignSeparate()) { - int tmpSize = attr2.getDigits(); - CobolDataStorage tmpBuff = new CobolDataStorage(48); - CobolFieldAttribute tmpAttr = new CobolFieldAttribute(attr2); - tmpAttr.setType(CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY); - tmpAttr.setFlags(CobolFieldAttribute.COB_FLAG_HAVE_SIGN); - AbstractCobolField tmpField = CobolFieldFactory.makeCobolField(tmpSize, tmpBuff, tmpAttr); - tmpField.moveFrom(f2); - f2 = tmpField; - } - } - } - return f1.cmpAlnum(f2); - } - - /** - * TODO: 準備中 - * - * @param field thisと比較するフィールド - * @return TODO: 準備中 - */ - protected int compareAll(AbstractCobolField field) { - int size = this.getSize(); - CobolDataStorage data = this.getDataStorage(); - int sign = this.getSign(); - int ret = 0; - int p = 0; - outer: - { - while (size >= field.getSize()) { - // TODO moduleを参照するコードにする - ret = alnumCmps(data, p, field.getDataStorage(), 0, this.getSize(), null); - if (ret != 0) { - break outer; - } - size -= field.getSize(); - p += field.getSize(); - } - if (size > 0) { - // TODO moduleを参照するコードにする - ret = alnumCmps(data, 0, field.getDataStorage(), 0, this.getSize(), null); - } - } - this.putSign(sign); - return ret; - } - - /** - * TODO: 準備中 - * - * @param s1 TODO: 準備中 - * @param s1Start s1のバイトデータにアクセスるするときの最初の添え字の相対位置 - * @param s2 TODO: 準備中 - * @param s2Start s2のバイトデータにアクセスるするときの最初の添え字の相対位置 - * @param size TODO: 準備中 - * @param col TODO: 準備中 - * @return TODO: 準備中 - */ - protected int alnumCmps( - CobolDataStorage s1, - int s1Start, - CobolDataStorage s2, - int s2Start, - int size, - CobolDataStorage col) { - int ret; - if (col != null) { - // TODO 実装 - throw new CobolRuntimeException(0, "未実装"); - } else { - for (int i = 0; i < size; ++i) { - ret = s1.getByte(i + s1Start) - s2.getByte(i + s2Start); - if (ret != 0) { - return ret; - } - } - } - return 0; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public BigDecimal getBigDecimal() { - return BigDecimal.ZERO; - } - - /** - * TODO: 準備中 - * - * @return thisからCobolNumericField型へ変換した値 - */ - public CobolNumericField getNumericField() { - return new CobolNumericField(this.getSize(), this.getDataStorage(), this.getAttribute()); - } - - /** - * TODO: 準備中 - * - * @param field TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public void checkMoveStrNum(AbstractCobolField field) throws CobolStopRunException { - switch (this.getAttribute().getType()) { - case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC: - case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_ALL: - case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_EDITED: - switch (field.getAttribute().getType()) { - case CobolFieldAttribute.COB_TYPE_NUMERIC: - /* case COB_TYPE_NUMERIC_DISPLAY: */ - case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: - case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: - case CobolFieldAttribute.COB_TYPE_NUMERIC_FLOAT: - case CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE: - case CobolFieldAttribute.COB_TYPE_NUMERIC_EDITED: - CobolDataStorage data = this.getDataStorage(); - int firstIndex = this.getFirstDataIndex(); - for (int i = 0; i < this.getSize(); i++) { - byte val = data.getByte(firstIndex + i); - if (val < 0x30 || 0x39 < val) { - CobolUtil.runtimeError("Numeric value is expected"); - CobolStopRunException.stopRunAndThrow(1); - } - } - break; - default: - break; - } - break; - default: - break; - } - } - - /** - * TODO: 準備中 - * - * @param s1 TODO: 準備中 - * @param s1StartIndex s1のバイトデータにアクセスるするときの最初の添え字の相対位置 - * @param s2 TODO: 準備中 - * @param s2StartIndex s2のバイトデータにアクセスるするときの最初の添え字の相対位置 - * @param size TODO: 準備中 - */ - protected void ownByteMemcpy( - CobolDataStorage s1, int s1StartIndex, CobolDataStorage s2, int s2StartIndex, int size) { - int i = 0; - do { - s1.setByte(s1StartIndex + i, s2.getByte(s2StartIndex + i)); - i++; - } while (--size > 0); - } - - @Override - public String toString() { - return this.getString(); - } - - /** - * TODO: 準備中 - * - * @return this.dataの保持するデータを文字列にして返す. - */ - public String fieldToString() { - CobolDataStorage data = this.getDataStorage(); - int i; - for (i = this.getSize() - 1; i >= 0; --i) { - if (data.getByte(i) != ' ' && data.getByte(i) != 0) { - break; - } - } - return new String(data.getByteArray(0, i + 1)); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void setInt(int n) { - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, - 9, - 0, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - CobolDataStorage data = new CobolDataStorage(ByteBuffer.allocate(4).putInt(n).array()); - AbstractCobolField temp = CobolFieldFactory.makeCobolField(4, data, attr); - this.moveFrom(temp); - } - - /** - * TODO: 準備中 - * - * @param data TODO: 準備中 - */ - public void setInt(CobolDataStorage data) { - this.setInt((int) data.intValue()); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void setLong(Long n) { - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, - 9, - 0, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - CobolDataStorage data = new CobolDataStorage(ByteBuffer.allocate(8).putLong(n).array()); - AbstractCobolField temp = CobolFieldFactory.makeCobolField(8, data, attr); - this.moveFrom(temp); - } - - /** - * TODO: 準備中 - * - * @param src TODO: 準備中 - * @param size TODO: 準備中 - */ - public void memcpy(byte[] src, int size) { - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); - AbstractCobolField temp = - CobolFieldFactory.makeCobolField(size, new CobolDataStorage(src), attr); - this.moveFrom(temp); - } - - /** - * TODO: 準備中 - * - * @param src TODO: 準備中 - */ - public void memcpy(byte[] src) { - this.memcpy(src, src.length); - } - - /** - * TODO: 準備中 - * - * @param src TODO: 準備中 - * @param size TODO: 準備中 - */ - public void memcpy(String src, int size) { - byte[] bytes = src.getBytes(); - this.memcpy(bytes, size); - } - - /** - * TODO: 準備中 - * - * @param src TODO: 準備中 - */ - public void memcpy(String src) { - this.memcpy(src.getBytes()); - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isOmitted() { - return this.dataStorage == null; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isNumeric() { - int i; - char c = 0; - int sign = 0; - switch (this.getAttribute().getType()) { - case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: - case CobolFieldAttribute.COB_TYPE_NUMERIC_FLOAT: - case CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE: - return true; - case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: - byte b = 0; - for (i = 0; i < this.size - 1; ++i) { - b = this.getDataStorage().getByte(i); - if ((b & 0xF0) > 0x90 || (b & 0x0f) > 0x09) { - return false; - } - } - b = this.getDataStorage().getByte(i); - if ((b & 0xf0) > 0x90) { - return false; - } - sign = b & 0x0f; - if (sign == 0x0f) { - return true; - } - if (this.getAttribute().isFlagHaveSign()) { - if (sign == 0x0c || sign == 0x0d) { - return true; - } - } else if (CobolUtil.nibbleCForUnsigned) { - if (sign == 0x0c) { - return true; - } - } - return false; - case CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY: - int size = this.getFieldSize(); - int firstIndex = this.getFirstDataIndex(); - sign = this.getSign(); - this.putSign(1); - for (i = 0; i < size; ++i) { - c = (char) this.getDataStorage().getByte(i + firstIndex); - if (!Character.isDigit(c)) { - this.putSign(sign); - return false; - } - } - this.putSign(sign); - return true; - default: - for (i = 0; i < this.size; ++i) { - c = (char) this.getDataStorage().getByte(i); - if (!Character.isDigit(c)) { - return false; - } - } - return true; - } - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isAlpha() { - for (int i = 0; i < this.size; ++i) { - char c = (char) this.getDataStorage().getByte(i); - if (!Character.isWhitespace(c) && !Character.isAlphabetic(c)) { - return false; - } - } - return true; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isUpper() { - for (int i = 0; i < this.size; ++i) { - char c = (char) this.getDataStorage().getByte(i); - if (!Character.isWhitespace(c) && !Character.isUpperCase(c)) { - return false; - } - } - return true; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isLower() { - for (int i = 0; i < this.size; ++i) { - char c = (char) this.getDataStorage().getByte(i); - if (!Character.isWhitespace(c) && !Character.isLowerCase(c)) { - return false; - } - } - return true; - } - - /** - * TODO: 準備中 - * - * @param c TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpChar(byte c) { - int sign = this.getSign(); - int ret = AbstractCobolField.commonCmpc(this.getDataStorage(), c, this.getSize()); - if (this.getAttribute().getType() != CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED) { - this.putSign(sign); - } - return ret; - } - - private interface DataComparator { - int compare(CobolDataStorage s1, CobolDataStorage s2, int size, CobolDataStorage col); - } - - private static DataComparator getComparator(AbstractCobolField f) { - if (f.getAttribute().isTypeNational()) { - return new DataComparator() { - @Override - public int compare( - CobolDataStorage s1, CobolDataStorage s2, int size, CobolDataStorage col) { - return CobolUtil.nationalCmps(s1, s2, size, col); - } - }; - } else { - return new DataComparator() { - @Override - public int compare( - CobolDataStorage s1, CobolDataStorage s2, int size, CobolDataStorage col) { - return CobolUtil.alnumCmps(s1, s2, size, col); - } - }; - } - } - - /** - * TODO: 準備中 - * - * @param other TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpAll(AbstractCobolField other) { - int ret = 0; - DataComparator comparator = getComparator(this); - int sign = 0; - - if ((this.getAttribute().getType() == CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_ALL - || this.getAttribute().getType() == CobolFieldAttribute.COB_TYPE_NATIONAL_ALL) - && this.getSize() < other.getSize()) { - int size = other.getSize(); - CobolDataStorage data = other.getDataStorage(); - sign = other.getSign(); - CobolDataStorage s = CobolModule.getCurrentModule().collating_sequence; - OUTSIDE: - do { - while (size >= this.getSize()) { - ret = comparator.compare(this.getDataStorage(), data, this.getSize(), s); - if (ret != 0) { - break OUTSIDE; - } - size -= this.getSize(); - data = data.getSubDataStorage(this.getSize()); - } - if (size > 0) { - ret = comparator.compare(this.getDataStorage(), data, size, s); - } - } while (false); - } else { - int size = this.getSize(); - CobolDataStorage data = this.getDataStorage(); - sign = this.getSign(); - CobolDataStorage s = CobolModule.getCurrentModule().collating_sequence; - OUTSIDE: - do { - while (size >= other.getSize()) { - ret = comparator.compare(data, other.getDataStorage(), other.getSize(), s); - if (ret != 0) { - break OUTSIDE; - } - size -= other.getSize(); - data = data.getSubDataStorage(other.getSize()); - } - if (size > 0) { - ret = comparator.compare(data, other.getDataStorage(), size, s); - } - } while (false); - } - - if (this.getAttribute().getType() != CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED) { - this.putSign(sign); - } - return ret; - } - - /** - * TODO: 準備中 - * - * @param other TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSimpleStr(AbstractCobolField other) { - AbstractCobolField lf, sf; - DataComparator comparator = getComparator(this); - if (this.getSize() < other.getSize()) { - lf = other; - sf = this; - } else { - lf = this; - sf = other; - } - CobolDataStorage s = CobolModule.getCurrentModule().collating_sequence; - int ret = comparator.compare(this.getDataStorage(), other.getDataStorage(), sf.getSize(), s); - if (ret == 0) { - if (lf.getSize() > sf.getSize()) { - if ((lf.getAttribute().getType() & CobolFieldAttribute.COB_TYPE_NATIONAL) != 0) { - int cmpResult = - AbstractCobolField.isNationalPadding( - sf.getSize(), lf.getDataStorage(), lf.getSize() - sf.getSize()); - return cmpResult == 0 ? 1 : 0; - } else { - ret = - AbstractCobolField.commonCmpc( - lf.getDataStorage().getSubDataStorage(sf.getSize()), - (byte) ' ', - lf.getSize() - sf.getSize()); - } - if (this.getSize() < other.getSize()) { - ret = -ret; - } - } - } - return ret; - } - - /** - * TODO: 準備中 - * - * @param other TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpAlnum(AbstractCobolField other) { - int sign1 = this.getSign(); - int sign2 = other.getSign(); - - if (this.getAttribute().isTypeNumericDisplay()) { - this.putSign(1); - } - if (other.getAttribute().isTypeNumericDisplay()) { - other.putSign(1); - } - - int ret = this.cmpSimpleStr(other); - - if (this.getAttribute().getType() != CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED) { - this.putSign(sign1); - } - if (other.getAttribute().getType() != CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED) { - other.putSign(sign2); - } - return ret; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public int realGetSign() { - CobolDataStorage p; - CobolFieldAttribute attr = this.getAttribute(); - byte b; - - switch (this.getAttribute().getType()) { - case CobolFieldAttribute.COB_TYPE_NUMERIC: - if (attr.isFlagSignLeading()) { - p = this.getDataStorage(); - } else { - p = this.getDataStorage().getSubDataStorage(this.getSize() - 1); - } - - b = p.getByte(0); - if (attr.isFlagSignSeparate()) { - return b == '+' ? 1 : -1; - } else { - if ('0' <= b && b <= '9') { - return 1; - } - if (b == ' ') { - p.setByte(0, (byte) '0'); - return 1; - } - if (CobolModule.getCurrentModule().display_sign != 0) { - return AbstractCobolField.getSignEbcdic(p); - } else { - // TODO マクロの分岐に関して調査 - // #ifdef COB_EBCDIC_MACHINE - // CobolUtil.getSignAscii(p); - // #else - p.setByte(0, (byte) (b - 0x40)); - // #endif - return -1; - } - } - case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: - p = this.getDataStorage().getSubDataStorage(this.size - 1); - return ((p.getByte(0) & 0x0f) == 0x0d) ? -1 : 1; - default: - return 0; - } - } - - /** - * TODO: 準備中 - * - * @param sign TODO: 準備中 - */ - public void realPutSign(int sign) { - CobolDataStorage p; - CobolFieldAttribute attr = this.getAttribute(); - byte b; - - switch (this.getAttribute().getType()) { - case CobolFieldAttribute.COB_TYPE_NUMERIC: - if (attr.isFlagSignLeading()) { - p = this.getDataStorage(); - } else { - p = this.getDataStorage().getSubDataStorage(this.getSize() - 1); - } - - b = p.getByte(0); - if (attr.isFlagSignSeparate()) { - char c = (sign < 0) ? '-' : '+'; - if (b != c) { - p.setByte(0, (byte) c); - } - } else if (CobolModule.getCurrentModule().display_sign != 0) { - AbstractCobolField.putSignEbcdic(p, sign); - } else if (sign < 0) { - p.setByte(0, (byte) (b + 0x40)); - } - return; - case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: - p = this.getDataStorage().getSubDataStorage(this.size - 1); - if (sign < 0) { - p.setByte(0, (byte) ((p.getByte(0) & 0xf0) | 0x0d)); - } else { - p.setByte(0, (byte) ((p.getByte(0) & 0xf0) | 0x0c)); - } - return; - default: - return; - } - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public long getLong() { - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, - 18, - 0, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - byte[] data = new byte[8]; - CobolDataStorage storage = new CobolDataStorage(data); - AbstractCobolField field = CobolFieldFactory.makeCobolField(8, storage, attr); - field.moveFrom(this); - return ByteBuffer.wrap(data).getLong(); - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public long getLongValue() { - return 0; - } - - /** - * TODO: 準備中 - * - * @param src TODO: 準備中 - */ - public void hankakuMoveFrom(AbstractCobolField src) { - // TODO 暫定実装 - this.moveFrom(src); - } - - // libcob/common.cのcob_get_sign_ebcdicの実装 - /** - * TODO: 準備中 - * - * @param p TODO: 準備中 - * @return TODO: 準備中 - */ - private static int getSignEbcdic(CobolDataStorage p) { - switch (p.getByte(0)) { - case '{': - p.setByte(0, (byte) '0'); - return 1; - case 'A': - p.setByte(0, (byte) '1'); - return 1; - case 'B': - p.setByte(0, (byte) '2'); - return 1; - case 'C': - p.setByte(0, (byte) '3'); - return 1; - case 'D': - p.setByte(0, (byte) '4'); - return 1; - case 'E': - p.setByte(0, (byte) '5'); - return 1; - case 'F': - p.setByte(0, (byte) '6'); - return 1; - case 'G': - p.setByte(0, (byte) '7'); - return 1; - case 'H': - p.setByte(0, (byte) '8'); - return 1; - case 'I': - p.setByte(0, (byte) '9'); - return 1; - case '}': - p.setByte(0, (byte) '0'); - return -1; - case 'J': - p.setByte(0, (byte) '1'); - return -1; - case 'K': - p.setByte(0, (byte) '2'); - return -1; - case 'L': - p.setByte(0, (byte) '3'); - return -1; - case 'M': - p.setByte(0, (byte) '4'); - return -1; - case 'N': - p.setByte(0, (byte) '5'); - return -1; - case 'O': - p.setByte(0, (byte) '6'); - return -1; - case 'P': - p.setByte(0, (byte) '7'); - return -1; - case 'Q': - p.setByte(0, (byte) '8'); - return -1; - case 'R': - p.setByte(0, (byte) '9'); - return -1; - default: - /* What to do here */ - p.setByte(0, (byte) '0'); - return 1; - } - } - - // libcob/common.cのcob_put_sign_ebcdicの実装 - /** - * TODO: 準備中 - * - * @param p TODO: 準備中 - * @param sign TODO: 準備中 - */ - private static void putSignEbcdic(CobolDataStorage p, int sign) { - if (sign < 0) { - switch (p.getByte(0)) { - case '0': - p.setByte(0, (byte) '}'); - return; - case '1': - p.setByte(0, (byte) 'J'); - return; - case '2': - p.setByte(0, (byte) 'K'); - return; - case '3': - p.setByte(0, (byte) 'L'); - return; - case '4': - p.setByte(0, (byte) 'M'); - return; - case '5': - p.setByte(0, (byte) 'N'); - return; - case '6': - p.setByte(0, (byte) 'O'); - return; - case '7': - p.setByte(0, (byte) 'P'); - return; - case '8': - p.setByte(0, (byte) 'Q'); - return; - case '9': - p.setByte(0, (byte) 'R'); - return; - default: - /* What to do here */ - p.setByte(0, (byte) '}'); - return; - } - } - switch (p.getByte(0)) { - case '0': - p.setByte(0, (byte) '{'); - return; - case '1': - p.setByte(0, (byte) 'A'); - return; - case '2': - p.setByte(0, (byte) 'B'); - return; - case '3': - p.setByte(0, (byte) 'C'); - return; - case '4': - p.setByte(0, (byte) 'D'); - return; - case '5': - p.setByte(0, (byte) 'E'); - return; - case '6': - p.setByte(0, (byte) 'F'); - return; - case '7': - p.setByte(0, (byte) 'G'); - return; - case '8': - p.setByte(0, (byte) 'H'); - return; - case '9': - p.setByte(0, (byte) 'I'); - return; - default: - /* What to do here */ - p.setByte(0, (byte) '{'); - return; - } - } - - // libcob/common.cのcommon_compcの実装 - /** - * TODO: 準備中 - * - * @param s1 TODO: 準備中 - * @param c TODO: 準備中 - * @param size TODO: 準備中 - * @return TODO: 準備中 - */ - private static int commonCmpc(CobolDataStorage s1, byte c, int size) { - CobolDataStorage s = CobolModule.getCurrentModule().collating_sequence; - int uc = c & 0xFF; - if (s != null) { - for (int i = 0; i < size; ++i) { - // int ret = s.getByte((s1.getByte(i) & 0xFF) - (s.getByte(uc) & 0xFF)); - int ret = (s.getByte(s1.getByte(i) & 0xFF) & 0xFF) - (s.getByte(uc) & 0xFF); - if (ret != 0) { - return ret; - } - } - } else { - for (int i = 0; i < size; ++i) { - int ret = (s1.getByte(i) & 0xFF) - uc; - if (ret != 0) { - return ret; - } - } - } - return 0; - } - - // libcob/common.cのis_national_paddingの実装 - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param s TODO: 準備中 - * @param size TODO: 準備中 - * @return TODO: 準備中 - */ - private static int isNationalPadding(int offset, CobolDataStorage s, int size) { - int ret = 1; - int i = 0; - while (i < size && ret != 0) { - if (s.getByte(offset + i) == ' ') { - i++; - } else if (size - i >= CobolConstant.ZENCSIZ) { - for (int j = 0; j < CobolConstant.ZENCSIZ; ++j) { - if (s.getByte(offset + i + j) != CobolConstant.ZENSPC[j]) { - return 0; - } - } - i += CobolConstant.ZENCSIZ; - } else { - ret = 0; - } - } - return ret; - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.data; + +import java.math.BigDecimal; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import jp.osscons.opensourcecobol.libcobj.common.CobolConstant; +import jp.osscons.opensourcecobol.libcobj.common.CobolModule; +import jp.osscons.opensourcecobol.libcobj.common.CobolUtil; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; + +/** COBOLで使用する変数を表現するクラス。 */ +public abstract class AbstractCobolField { + /** データを格納に使用するバイト配列の長さ */ + protected int size; + + /** データを格納するバイト配列を扱うオブジェクト */ + protected CobolDataStorage dataStorage; + + /** 変数に関する様々な情報を保持するオブジェクト(符号付か,COMP-3指定かなど) */ + protected CobolFieldAttribute attribute; + + static int lastsize = 0; + static CobolDataStorage lastdata = null; + + /** TODO: 準備中 */ + public static Charset charSetSJIS = Charset.forName("SHIFT-JIS"); + + static final int[] cobExp10 = { + 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 + }; + + /** + * コンストラクタ + * + * @param size データを格納するバイト配列の長さ + * @param dataStorage データを格納するバイト配列を扱うオブジェクト + * @param attribute 変数に関する様々な情報を保持するオブジェクト(符号付か,COMP-3指定かなど) + */ + public AbstractCobolField( + int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { + this.size = size; + this.dataStorage = dataStorage; + this.attribute = attribute; + } + + /** + * メンバ変数dataStorageのgetter + * + * @return this.dataStorage + */ + public CobolDataStorage getDataStorage() { + return dataStorage; + } + + /** + * メンバ変数dataStorageのsetter + * + * @param dataStorage TODO: 準備中 + */ + public void setDataStorage(CobolDataStorage dataStorage) { + this.dataStorage = dataStorage; + } + + /** + * メンバ変数attributeのsetter + * + * @param attribute TODO: 準備中 + */ + public void setAttribute(CobolFieldAttribute attribute) { + this.attribute = attribute; + } + + /** + * メンバ変数attributeのgetter + * + * @return this.attribute + */ + public CobolFieldAttribute getAttribute() { + return attribute; + } + + /** + * メンバ変数sizeのsetter + * + * @param size TODO: 準備中 + */ + public void setSize(int size) { + this.size = size; + } + + /** + * メンバ変数sizeのgetter + * + * @return this.size + */ + public int getSize() { + return size; + } + + /** + * 符号部分を除いた数値部分の長さを返す + * + * @return 符号付で符号が分離している場合はthis.size-1,そうでなければthis.size + */ + public int getFieldSize() { + return this.size - (this.attribute.isFlagSignSeparate() ? 1 : 0); + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public CobolDataStorage getFieldData() { + if (this.attribute.isFlagSignSeparate() && this.attribute.isFlagSignLeading()) { + return new CobolDataStorage( + this.dataStorage.getRefOfData(), this.dataStorage.getIndex() + 1); + } else { + return this.dataStorage; + } + } + + /** + * バイト配列の中で(符号データではなく)数値データの格納されている最小の添え字を返す + * + * @return SIGN LEADINGかつSIGN SEPARATEな変数なら1,それ以外は0 + */ + public int getFirstDataIndex() { + return (this.attribute.isFlagSignSeparate() && this.attribute.isFlagSignLeading()) ? 1 : 0; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public byte[] getBytes() { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, + 9, + 0, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + CobolDataStorage n = new CobolDataStorage(new byte[4], 0); + AbstractCobolField temp = CobolFieldFactory.makeCobolField(4, n, attr); + temp.moveFrom(this); + return ByteBuffer.wrap(n.getByteArray(0, 4)).array(); + } + + /** + * thisの文字列表現をかえす. + * + * @return thisの文字列表現 + */ + public abstract String getString(); + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public int getInt() { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, + 9, + 0, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + CobolDataStorage n = new CobolDataStorage(new byte[4], 0); + AbstractCobolField temp = CobolFieldFactory.makeCobolField(4, n, attr); + temp.moveFrom(this); + return ByteBuffer.wrap(n.getByteArray(0, 4)).getInt(); + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public double getDouble() { + try { + return Double.parseDouble(this.getString()); + } catch (Exception e) { + return 0; + } + } + + /** + * 数値を表すデータが実装すべきメソッド. 保持する数値データをCobolDecimal型に変換する. + * + * @return 保持する数値データをCobolDecimal型に変換した値 + */ + public CobolDecimal getDecimal() { + CobolDataStorage data = this.getDataStorage(); + int firstDataIndex = this.getFirstDataIndex(); + int size = this.getFieldSize(); + + if (Byte.toUnsignedInt(data.getByte(firstDataIndex)) == 0xFF) { + CobolDecimal decimal = new CobolDecimal(BigDecimal.TEN.pow(size)); + decimal.setScale(this.getAttribute().getScale()); + return decimal; + } + + if (data.getByte(firstDataIndex) == 0) { + CobolDecimal decimal = new CobolDecimal(BigDecimal.TEN.pow(size).negate()); + decimal.setScale(this.getAttribute().getScale()); + return decimal; + } + + char[] buf = new char[size]; + for (int i = 0; i < size; ++i) { + byte val = data.getByte(firstDataIndex + i); + if (val >= 0x70) { + buf[i] = (char) (val - 0x40); + } else { + buf[i] = (char) val; + } + } + + CobolFieldAttribute attr = this.getAttribute(); + int sign = 1; + if (attr.isFlagHaveSign()) { + if (attr.isFlagSignSeparate()) { + int signIndex = attr.isFlagSignLeading() ? 0 : this.getSize() - 1; + if (data.getByte(signIndex) == '-') { + sign = -1; + } + } else { + int signIndex = attr.isFlagSignLeading() ? 0 : this.getSize() - 1; + if (data.getByte(signIndex) >= 0x70) { + sign = -1; + } + } + } + + BigDecimal decimal = new BigDecimal(buf); + if (sign < 0) { + decimal = decimal.negate(); + } + CobolDecimal ret = new CobolDecimal(decimal); + ret.setScale(this.getAttribute().getScale()); + return ret; + } + + /** + * TODO: 準備中 + * + * @param decimal TODO: 準備中 + */ + public abstract void setDecimal(BigDecimal decimal); + + /** + * thisの保持する数値データをint型で返す + * + * @param size TODO: 準備中 + * @return thisの保持する数値データをintに変換した値 + */ + public int getInt(int size) { + int retval = 0; + int p = 0; + CobolDataStorage data = this.getDataStorage(); + for (int n = 0; n < size; ++n, ++p) { + retval *= 10; + if (data.getByte(p) > (byte) '9') { + retval += 10; + } else { + retval += data.getByte(p) - (byte) '0'; + } + } + return retval; + } + + /** thisの保持する数値データを0に設定するメソッド. */ + public void setZero() { + throw new CobolRuntimeException(0, "未実装"); + } + + /** + * thisの保持する数値データに,引数で与えられたフィールドの保持する数値データを加算する + * + * @param field 加算する数値を保持するフィールド + * @param opt 加算に関するオプション.詳しくはTODO: 準備中 + * @return 加算後のthisの保持する数値データ + * @throws CobolStopRunException TODO: 準備中 + */ + public int add(AbstractCobolField field, int opt) throws CobolStopRunException { + CobolDecimal d1 = this.getDecimal(); + CobolDecimal d2 = field.getDecimal(); + d1.add(d2); + return d1.getField(this, opt); + } + + /** + * thisの保持する数値データに,引数で与えられたフィールドの保持する数値データを減算する + * + * @param field 減算する数値を保持するフィールド + * @param opt 減算に関するオプション.詳しくはTODO: 準備中 + * @return 減算後のthisの保持する数値データ + * @throws CobolStopRunException TODO: 準備中 + */ + public int sub(AbstractCobolField field, int opt) throws CobolStopRunException { + CobolDecimal d1 = this.getDecimal(); + CobolDecimal d2 = field.getDecimal(); + d1.sub(d2); + return d1.getField(this, opt); + } + + /** + * 保持する数値データに指定された値を加算する + * + * @param n thisの保持する数値データから加算する数値 + * @return 基本的に0が返される.詳しくは詳しくはTODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public int addInt(int n) throws CobolStopRunException { + if (n == 0) { + return 0; + } + CobolDecimal d1 = this.getDecimal(); + CobolDecimal d2 = new CobolDecimal(n); + d2.setScale(0); + if (d1.getScale() != 0) { + BigDecimal cobMexp = BigDecimal.TEN.pow(d1.getScale()); + d2.setValue(d2.getValue().multiply(cobMexp)); + d2.setScale(d1.getScale()); + } + d1.setValue(d1.getValue().add(d2.getValue())); + return d1.getField(this, 0); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public abstract int addPackedInt(int n); + + /** + * thisの保持する数値データに指定された値を減算する + * + * @param n thisの保持する数値データから減算する数値 + * @return 基本的に0が返される.詳しくはTODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public int subInt(int n) throws CobolStopRunException { + return n == 0 ? 0 : this.addInt(-n); + } + + /** + * TODO: 準備中 + * + * @param divisor TODO: 準備中 + * @param quotient TODO: 準備中 + * @param opt TODO: 準備中 + * @return TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public int divQuotient(AbstractCobolField divisor, AbstractCobolField quotient, int opt) + throws CobolStopRunException { + AbstractCobolField dividend = this; + CobolDecimal d1 = dividend.getDecimal(); + CobolDecimal d2 = divisor.getDecimal(); + CobolDecimal.cobD3.set(d1); + + d1.div(d2); + if (d1.getScale() == CobolDecimal.DECIMAL_NAN) { + CobolDecimal.cobD3.setScale(CobolDecimal.DECIMAL_NAN); + // TODO 例外を投げるべきか? + return 0; + } + CobolDecimal d4 = new CobolDecimal(); + d4.set(d1); + int ret = d1.getField(quotient, opt); + + d4.shiftDecimal(quotient.getAttribute().getScale() - d4.getScale()); + + d4.mul(d2); + CobolDecimal.cobD3.sub(d4); + + return ret; + } + + /** + * TODO: 準備中 + * + * @param opt TODO: 準備中 + * @return TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public int divRemainder(int opt) throws CobolStopRunException { + return CobolDecimal.cobD3.getField(this, opt); + } + + /** + * 整数値との比較を行う + * @deprecated 代わりにcmpIntegerを使用してください + * @param n 比較対象の整数値 + * @return 保持する数値データの比較を行い,this<nなら負の値,this==nなら0,this>nなら正の値 + */ + public int cmpInt(int n) { + CobolDecimal d1 = this.getDecimal(); + CobolDecimal d2 = new CobolDecimal(n); + d2.setScale(0); + return d1.compareTo(d2); + } + + /** + * 整数値との比較を行う + * @deprecated 代わりにcmpIntegerを使用してください + * @param n 比較対象の整数値 + * @return 保持する数値データの比較を行い,this<nなら負の値,this==nなら0,this>nなら正の値 + */ + public int cmpInt(long n) { + return this.cmpInt((int) n); + } + + /** + * 整数値との比較を行う + * @param n 比較対象の整数値 + * @return 保持する数値データの比較を行い,this<nなら負の値,this==nなら0,this>nなら正の値 + */ + public int cmpInteger(long n) { + CobolDecimal d1 = this.getDecimal(); + CobolDecimal d2 = new CobolDecimal(n); + d2.setScale(0); + return d1.compareTo(d2); + } + + /** + * 整数値との比較を行う + * @param n 比較対象の整数値 + * @return 保持する数値データの比較を行い,this<nなら負の値,this==nなら0,this>nなら正の値 + */ + public int cmpInteger(int n) { + return this.cmpInteger((long) n); + } + + /** + * 整数値との比較を行う + * @deprecated 代わりにcmpIntegerを使用してください + * @param n 比較対象の整数値 + * @return 保持する数値データの比較を行い,this<nなら負の値,this==nなら0,this>nなら正の値 + */ + public int cmpUint(int n) { + return this.cmpInt(n); + } + + /** + * 整数値との比較を行う + * @deprecated 代わりにcmpIntegerを使用してください + * @param n 比較対象の整数値 + * @return 保持する数値データの比較を行い,this<nなら負の値,this==nなら0,this>nなら正の値 + */ + public int cmpUint(long n) { + return this.cmpUint((int) n); + } + + /** + * TODO: 準備中 + * + * @param field TODO: 準備中 + * @return TODO: 準備中 + */ + public int numericCompareTo(AbstractCobolField field) { + CobolDecimal d1 = this.getDecimal(); + CobolDecimal d2 = field.getDecimal(); + return d1.compareTo(d2); + } + + /** + * thisの保持する数値データの符号を返す + * + * @return thisの保持する数値データが負ならば負数,0なら0,正なら正数を返す + */ + public int getSign() { + return this.getAttribute().isFlagHaveSign() ? this.realGetSign() : 0; + } + + /** + * thisの保持する数値データの符号を設定する + * + * @param sign 正符号を設定するときは正数,負符号を設定するときは負数,それ以外は0 + */ + public void putSign(int sign) { + if (this.getAttribute().isFlagHaveSign()) { + this.realPutSign(sign); + } + } + + /** + * TODO: 準備中 + * + * @param src TODO: 準備中 + * @return TODO: 準備中 + */ + protected AbstractCobolField preprocessOfMoving(AbstractCobolField src) { + AbstractCobolField src1 = src; + + if (src1.getAttribute().isTypeAlphanumAll() || src1.getAttribute().isTypeNationalAll()) { + this.moveFromAll(src); + return null; + } + + if (this.getSize() == 0) { + return null; + } + + CobolFieldAttribute srcAttr = src1.getAttribute(); + CobolFieldAttribute dstAttr = this.getAttribute(); + if (!srcAttr.isTypeGroup()) { + if ((srcAttr.isTypeNumeric() + || srcAttr.isTypeAlphanum() + || srcAttr.isTypeAlphanumEdited()) + && (dstAttr.isTypeNational() || dstAttr.isTypeNationalEdited())) { + byte[] pTmp = null; + int size = 0; + if (srcAttr.isTypeNumericDisplay() + || srcAttr.isTypeAlphanum() + || srcAttr.isTypeAlphanumEdited()) { + pTmp = CobolNationalField.judge_hankakujpn_exist(src1); + size = CobolNationalField.workReturnSize; + } + if (pTmp != null) { + src1.setDataStorage(new CobolDataStorage(pTmp)); + src1.setSize(size); + } + if (src1.size == 0) { + return src1; + } + } + } + + if (src1.getSize() == 0) { + return src1; + } + + return src; + } + + /** + * TODO: 準備中 + * + * @param src TODO: 準備中 + */ + protected void moveFromAll(AbstractCobolField src) { + int size = 0; + CobolDataStorage tmpSrcStorage = null; + int tmpSrcSize = 0; + boolean xToN = false; + CobolFieldAttribute attr; + int digcount; + + if (!(src.getAttribute().isTypeNational() || src.getAttribute().isTypeNationalEdited()) + && (this.attribute.isTypeNational() || this.attribute.isTypeNationalEdited())) { + CobolDataStorage pTmp; + byte[] pBytes = CobolNationalField.judge_hankakujpn_exist(src); + pTmp = new CobolDataStorage(pBytes); + size = CobolNationalField.workReturnSize; + tmpSrcStorage = pTmp; + tmpSrcSize = size; + xToN = true; + } + + if (xToN) { + attr = new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NATIONAL, 0, 0, 0, null); + } else { + attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); + } + if (this.attribute.isTypeNumeric()) { + digcount = 18; + attr.setType(CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY); + attr.setDigits(18); + } else { + digcount = this.size; + } + if (digcount > AbstractCobolField.lastsize) { + AbstractCobolField.lastdata = new CobolDataStorage(digcount); + AbstractCobolField.lastsize = digcount; + } + + AbstractCobolField temp = CobolFieldFactory.makeCobolField(digcount, lastdata, attr); + + if (xToN && tmpSrcSize > 1) { + for (int i = 0; i < digcount; ++i) { + lastdata.setByte(i, tmpSrcStorage.getByte(i % tmpSrcSize)); + } + } else { + if (src.getSize() == 1) { + lastdata.memset(src.getDataStorage().getByte(0), digcount); + } else { + int i; + for (i = 0; i < digcount; ++i) { + lastdata.setByte(i, src.getDataStorage().getByte(i % src.getSize())); + } + + int b = Byte.toUnsignedInt(lastdata.getByte(i - 1)); + if ((0x81 <= b && b <= 0x9F) || (0xE0 <= b && b <= 0xFC)) { + lastdata.setByte(i - 1, (byte) ' '); + } + } + } + this.moveFrom(temp); + } + + /** + * 引数で与えらえられたデータからthisへの代入を行う + * + * @param field 代入元のデータ + */ + public abstract void moveFrom(AbstractCobolField field); + + /** + * 引数で与えらえられたデータからthisへの代入を行う + * + * @param dataStorage 代入元のデータ + */ + public abstract void moveFrom(CobolDataStorage dataStorage); + + /** + * 引数で与えらえられたデータからthisへの代入を行う + * + * @param bytes 代入元のデータ + */ + public abstract void moveFrom(byte[] bytes); + + /** + * 引数で与えらえられたデータからthisへの代入を行う + * + * @param s 代入元のデータ + */ + public void moveFrom(String s) { + // The maximum number of digits of int type in decimal is 10 + + byte[] bytes = s.getBytes(charSetSJIS); + + CobolDataStorage storage = new CobolDataStorage(bytes.length); + storage.memcpy(bytes); + + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, + bytes.length, + 0, + 0, + String.format("X(%d)", bytes.length)); + + AbstractCobolField tmp = CobolFieldFactory.makeCobolField(bytes.length, storage, attr); + this.moveFrom(tmp); + } + + /** + * 引数で与えらえられたデータからthisへの代入を行う + * + * @param number 代入元のデータ + */ + public void moveFrom(int number) { + // The maximum number of digits of int type in decimal is 10 + final int length = 10; + + CobolDataStorage storage = new CobolDataStorage(length); + String formattedNumberString = String.format("%10d", Math.abs(number)); + storage.memcpy(formattedNumberString, length); + if (number < 0) { + storage.setByte(length - 1, (byte) (storage.getByte(length - 1) + 0x40)); + } + + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, + length, + 0, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + "S9(10)"); + + AbstractCobolField tmp = CobolFieldFactory.makeCobolField(length, storage, attr); + this.moveFrom(tmp); + } + + /** + * 引数で与えらえられたデータからthisへの代入を行う + * + * @param number 代入元のデータ + */ + public void moveFrom(double number) { + String s = Double.toString(Math.abs(number)); + String ss; + int scale; + ss = s.replace("+", "").replace("-", ""); + int pointIndex = ss.indexOf('.'); + if (pointIndex < 0) { + scale = 0; + } else { + scale = ss.length() - 1 - pointIndex; + ss = ss.replace(".", ""); + } + + CobolDataStorage storage = new CobolDataStorage(ss.length()); + storage.memcpy(ss, ss.length()); + + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, + ss.length(), + scale, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + ""); + + AbstractCobolField tmp = CobolFieldFactory.makeCobolField(ss.length(), storage, attr); + if (number < 0) { + tmp.putSign(-1); + } + this.moveFrom(tmp); + } + + /** + * 引数で与えらえられたデータからthisへの代入を行う + * + * @param number 代入元のデータ + */ + public abstract void moveFrom(BigDecimal number); + + /** + * TODO: 準備中 + * + * @param s TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public void checkNumeric(byte[] s) throws CobolStopRunException { + if (!this.isNumeric()) { + byte[] buff = this.getDataStorage().getByteArrayRef(0, this.getSize()); + String name = new String(s, charSetSJIS); + String content = new String(buff, charSetSJIS); + CobolUtil.runtimeError("'" + name + "' not numeric: '" + content + "'"); + CobolStopRunException.stopRunAndThrow(1); + } + } + + // TODO abstract指定 + /** + * thisと引数で与えられたデータとの数値比較を行う + * + * @param other thisと比較するfield + * @return 保持する数値データの比較を行い,this<fieldなら負の値,this==fieldなら0,this>fieldなら正の値 + */ + public int compareTo(AbstractCobolField other) { + AbstractCobolField f1 = this; + AbstractCobolField f2 = other; + CobolFieldAttribute attr1 = f1.getAttribute(); + CobolFieldAttribute attr2 = f2.getAttribute(); + + if (attr1.isTypeNational() || attr1.isTypeNationalAll() || attr1.isTypeNationalEdited()) { + if (f2 == CobolConstant.quote) { + f2 = CobolConstant.zenQuote; + } else if (f2 == CobolConstant.space) { + f2 = CobolConstant.zenSpace; + } else if (f2 == CobolConstant.zero) { + f2 = CobolConstant.zenZero; + } + } + + if (attr2.isTypeNational() || attr2.isTypeNationalAll() || attr2.isTypeNationalEdited()) { + if (f1 == CobolConstant.quote) { + f1 = CobolConstant.zenQuote; + } else if (f1 == CobolConstant.space) { + f1 = CobolConstant.zenSpace; + } else if (f1 == CobolConstant.zero) { + f1 = CobolConstant.zenZero; + } + } + + attr1 = f1.getAttribute(); + attr2 = f2.getAttribute(); + + if (attr1.isTypeNumeric() && attr2.isTypeNumeric()) { + return f1.numericCompareTo(f2); + } + if (attr2.isTypeAlphanumAll()) { + if (f2 == CobolConstant.zero && attr1.isTypeNumeric()) { + return f1.cmpInt(0); + } else if (f2.getSize() == 1) { + return f1.cmpChar(f2.getDataStorage().getByte(0)); + } else { + return f1.cmpAll(f2); + } + } else if (attr1.isTypeAlphanumAll()) { + if (f1 == CobolConstant.zero && attr2.isTypeNumeric()) { + return -f2.cmpInt(0); + } else if (f1.getSize() == 1) { + return -f2.cmpChar(f1.getDataStorage().getByte(0)); + } else { + return -f2.cmpAll(f1); + } + } else if (attr2.isTypeNationalAll()) { + if (f2 == CobolConstant.zero && attr1.isTypeNumeric()) { + return f1.cmpInt(0); + } else if (f2.getSize() == 1) { + return f1.cmpChar(f2.getDataStorage().getByte(0)); + } else { + return f1.cmpAll(f2); + } + } else if (attr1.isTypeNationalAll()) { + if (f1 == CobolConstant.zero && attr2.isTypeNumeric()) { + return -f2.cmpInt(0); + } else if (f1.getSize() == 1) { + return -f2.cmpChar(f1.getDataStorage().getByte(0)); + } else { + return -f2.cmpAll(f1); + } + } else if (attr1.isTypeGroup() || attr2.isTypeGroup()) { + return f1.cmpSimpleStr(f2); + } else { + if (attr1.isTypeNumeric()) { + if (attr1.getType() != CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY) { + int tmpSize = attr1.getDigits(); + CobolDataStorage tmpBuff = new CobolDataStorage(48); + CobolFieldAttribute tmpAttr = new CobolFieldAttribute(attr1); + tmpAttr.setType(CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY); + tmpAttr.setFlags(tmpAttr.getFlags() & ~CobolFieldAttribute.COB_FLAG_HAVE_SIGN); + AbstractCobolField tmpField = + CobolFieldFactory.makeCobolField(tmpSize, tmpBuff, tmpAttr); + tmpField.moveFrom(f1); + f1 = tmpField; + } else if (attr1.isFlagSignSeparate()) { + int tmpSize = attr1.getDigits(); + CobolDataStorage tmpBuff = new CobolDataStorage(48); + CobolFieldAttribute tmpAttr = new CobolFieldAttribute(attr1); + tmpAttr.setType(CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY); + tmpAttr.setFlags(CobolFieldAttribute.COB_FLAG_HAVE_SIGN); + AbstractCobolField tmpField = + CobolFieldFactory.makeCobolField(tmpSize, tmpBuff, tmpAttr); + tmpField.moveFrom(f1); + f1 = tmpField; + } + } + if (attr2.isTypeNumeric()) { + if (attr2.getType() != CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY) { + int tmpSize = attr2.getDigits(); + CobolDataStorage tmpBuff = new CobolDataStorage(48); + CobolFieldAttribute tmpAttr = new CobolFieldAttribute(attr2); + tmpAttr.setType(CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY); + tmpAttr.setFlags(tmpAttr.getFlags() & ~CobolFieldAttribute.COB_FLAG_HAVE_SIGN); + AbstractCobolField tmpField = + CobolFieldFactory.makeCobolField(tmpSize, tmpBuff, tmpAttr); + tmpField.moveFrom(f2); + f2 = tmpField; + } else if (attr2.isFlagSignSeparate()) { + int tmpSize = attr2.getDigits(); + CobolDataStorage tmpBuff = new CobolDataStorage(48); + CobolFieldAttribute tmpAttr = new CobolFieldAttribute(attr2); + tmpAttr.setType(CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY); + tmpAttr.setFlags(CobolFieldAttribute.COB_FLAG_HAVE_SIGN); + AbstractCobolField tmpField = + CobolFieldFactory.makeCobolField(tmpSize, tmpBuff, tmpAttr); + tmpField.moveFrom(f2); + f2 = tmpField; + } + } + } + return f1.cmpAlnum(f2); + } + + /** + * TODO: 準備中 + * + * @param field thisと比較するフィールド + * @return TODO: 準備中 + */ + protected int compareAll(AbstractCobolField field) { + int size = this.getSize(); + CobolDataStorage data = this.getDataStorage(); + int sign = this.getSign(); + int ret = 0; + int p = 0; + outer: + { + while (size >= field.getSize()) { + // TODO moduleを参照するコードにする + ret = alnumCmps(data, p, field.getDataStorage(), 0, this.getSize(), null); + if (ret != 0) { + break outer; + } + size -= field.getSize(); + p += field.getSize(); + } + if (size > 0) { + // TODO moduleを参照するコードにする + ret = alnumCmps(data, 0, field.getDataStorage(), 0, this.getSize(), null); + } + } + this.putSign(sign); + return ret; + } + + /** + * TODO: 準備中 + * + * @param s1 TODO: 準備中 + * @param s1Start s1のバイトデータにアクセスるするときの最初の添え字の相対位置 + * @param s2 TODO: 準備中 + * @param s2Start s2のバイトデータにアクセスるするときの最初の添え字の相対位置 + * @param size TODO: 準備中 + * @param col TODO: 準備中 + * @return TODO: 準備中 + */ + protected int alnumCmps( + CobolDataStorage s1, + int s1Start, + CobolDataStorage s2, + int s2Start, + int size, + CobolDataStorage col) { + int ret; + if (col != null) { + // TODO 実装 + throw new CobolRuntimeException(0, "未実装"); + } else { + for (int i = 0; i < size; ++i) { + ret = s1.getByte(i + s1Start) - s2.getByte(i + s2Start); + if (ret != 0) { + return ret; + } + } + } + return 0; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public BigDecimal getBigDecimal() { + return BigDecimal.ZERO; + } + + /** + * TODO: 準備中 + * + * @return thisからCobolNumericField型へ変換した値 + */ + public CobolNumericField getNumericField() { + return new CobolNumericField(this.getSize(), this.getDataStorage(), this.getAttribute()); + } + + /** + * TODO: 準備中 + * + * @param field TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public void checkMoveStrNum(AbstractCobolField field) throws CobolStopRunException { + switch (this.getAttribute().getType()) { + case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC: + case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_ALL: + case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_EDITED: + switch (field.getAttribute().getType()) { + case CobolFieldAttribute.COB_TYPE_NUMERIC: + /* case COB_TYPE_NUMERIC_DISPLAY: */ + case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: + case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: + case CobolFieldAttribute.COB_TYPE_NUMERIC_FLOAT: + case CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE: + case CobolFieldAttribute.COB_TYPE_NUMERIC_EDITED: + CobolDataStorage data = this.getDataStorage(); + int firstIndex = this.getFirstDataIndex(); + for (int i = 0; i < this.getSize(); i++) { + byte val = data.getByte(firstIndex + i); + if (val < 0x30 || 0x39 < val) { + CobolUtil.runtimeError("Numeric value is expected"); + CobolStopRunException.stopRunAndThrow(1); + } + } + break; + default: + break; + } + break; + default: + break; + } + } + + /** + * TODO: 準備中 + * + * @param s1 TODO: 準備中 + * @param s1StartIndex s1のバイトデータにアクセスるするときの最初の添え字の相対位置 + * @param s2 TODO: 準備中 + * @param s2StartIndex s2のバイトデータにアクセスるするときの最初の添え字の相対位置 + * @param size TODO: 準備中 + */ + protected void ownByteMemcpy( + CobolDataStorage s1, + int s1StartIndex, + CobolDataStorage s2, + int s2StartIndex, + int size) { + int i = 0; + do { + s1.setByte(s1StartIndex + i, s2.getByte(s2StartIndex + i)); + i++; + } while (--size > 0); + } + + @Override + public String toString() { + return this.getString(); + } + + /** + * TODO: 準備中 + * + * @return this.dataの保持するデータを文字列にして返す. + */ + public String fieldToString() { + CobolDataStorage data = this.getDataStorage(); + int i; + for (i = this.getSize() - 1; i >= 0; --i) { + if (data.getByte(i) != ' ' && data.getByte(i) != 0) { + break; + } + } + return new String(data.getByteArray(0, i + 1)); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void setInt(int n) { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, + 9, + 0, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + CobolDataStorage data = new CobolDataStorage(ByteBuffer.allocate(4).putInt(n).array()); + AbstractCobolField temp = CobolFieldFactory.makeCobolField(4, data, attr); + this.moveFrom(temp); + } + + /** + * TODO: 準備中 + * + * @param data TODO: 準備中 + */ + public void setInt(CobolDataStorage data) { + this.setInt((int) data.intValue()); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void setLong(Long n) { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, + 9, + 0, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + CobolDataStorage data = new CobolDataStorage(ByteBuffer.allocate(8).putLong(n).array()); + AbstractCobolField temp = CobolFieldFactory.makeCobolField(8, data, attr); + this.moveFrom(temp); + } + + /** + * TODO: 準備中 + * + * @param src TODO: 準備中 + * @param size TODO: 準備中 + */ + public void memcpy(byte[] src, int size) { + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); + AbstractCobolField temp = + CobolFieldFactory.makeCobolField(size, new CobolDataStorage(src), attr); + this.moveFrom(temp); + } + + /** + * TODO: 準備中 + * + * @param src TODO: 準備中 + */ + public void memcpy(byte[] src) { + this.memcpy(src, src.length); + } + + /** + * TODO: 準備中 + * + * @param src TODO: 準備中 + * @param size TODO: 準備中 + */ + public void memcpy(String src, int size) { + byte[] bytes = src.getBytes(AbstractCobolField.charSetSJIS); + this.memcpy(bytes, size); + } + + /** + * TODO: 準備中 + * + * @param src TODO: 準備中 + */ + public void memcpy(String src) { + this.memcpy(src.getBytes(AbstractCobolField.charSetSJIS)); + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isOmitted() { + return this.dataStorage == null; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isNumeric() { + int i; + char c = 0; + int sign = 0; + switch (this.getAttribute().getType()) { + case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: + case CobolFieldAttribute.COB_TYPE_NUMERIC_FLOAT: + case CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE: + return true; + case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: + byte b = 0; + for (i = 0; i < this.size - 1; ++i) { + b = this.getDataStorage().getByte(i); + if ((b & 0xF0) > 0x90 || (b & 0x0f) > 0x09) { + return false; + } + } + b = this.getDataStorage().getByte(i); + if ((b & 0xf0) > 0x90) { + return false; + } + sign = b & 0x0f; + if (sign == 0x0f) { + return true; + } + if (this.getAttribute().isFlagHaveSign()) { + if (sign == 0x0c || sign == 0x0d) { + return true; + } + } else if (CobolUtil.nibbleCForUnsigned) { + if (sign == 0x0c) { + return true; + } + } + return false; + case CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY: + int size = this.getFieldSize(); + int firstIndex = this.getFirstDataIndex(); + sign = this.getSign(); + this.putSign(1); + for (i = 0; i < size; ++i) { + c = (char) this.getDataStorage().getByte(i + firstIndex); + if (!Character.isDigit(c)) { + this.putSign(sign); + return false; + } + } + this.putSign(sign); + return true; + default: + for (i = 0; i < this.size; ++i) { + c = (char) this.getDataStorage().getByte(i); + if (!Character.isDigit(c)) { + return false; + } + } + return true; + } + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isAlpha() { + for (int i = 0; i < this.size; ++i) { + char c = (char) this.getDataStorage().getByte(i); + if (!Character.isWhitespace(c) && !Character.isAlphabetic(c)) { + return false; + } + } + return true; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isUpper() { + for (int i = 0; i < this.size; ++i) { + char c = (char) this.getDataStorage().getByte(i); + if (!Character.isWhitespace(c) && !Character.isUpperCase(c)) { + return false; + } + } + return true; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isLower() { + for (int i = 0; i < this.size; ++i) { + char c = (char) this.getDataStorage().getByte(i); + if (!Character.isWhitespace(c) && !Character.isLowerCase(c)) { + return false; + } + } + return true; + } + + /** + * TODO: 準備中 + * + * @param c TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpChar(byte c) { + int sign = this.getSign(); + int ret = AbstractCobolField.commonCmpc(this.getDataStorage(), c, this.getSize()); + if (this.getAttribute().getType() != CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED) { + this.putSign(sign); + } + return ret; + } + + private interface DataComparator { + int compare(CobolDataStorage s1, CobolDataStorage s2, int size, CobolDataStorage col); + } + + private static DataComparator getComparator(AbstractCobolField f) { + if (f.getAttribute().isTypeNational()) { + return new DataComparator() { + @Override + public int compare( + CobolDataStorage s1, CobolDataStorage s2, int size, CobolDataStorage col) { + return CobolUtil.nationalCmps(s1, s2, size, col); + } + }; + } else { + return new DataComparator() { + @Override + public int compare( + CobolDataStorage s1, CobolDataStorage s2, int size, CobolDataStorage col) { + return CobolUtil.alnumCmps(s1, s2, size, col); + } + }; + } + } + + /** + * TODO: 準備中 + * + * @param other TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpAll(AbstractCobolField other) { + int ret = 0; + DataComparator comparator = getComparator(this); + int sign = 0; + + if ((this.getAttribute().getType() == CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_ALL + || this.getAttribute().getType() + == CobolFieldAttribute.COB_TYPE_NATIONAL_ALL) + && this.getSize() < other.getSize()) { + int size = other.getSize(); + CobolDataStorage data = other.getDataStorage(); + sign = other.getSign(); + CobolDataStorage s = CobolModule.getCurrentModule().collating_sequence; + OUTSIDE: + do { + while (size >= this.getSize()) { + ret = comparator.compare(this.getDataStorage(), data, this.getSize(), s); + if (ret != 0) { + break OUTSIDE; + } + size -= this.getSize(); + data = data.getSubDataStorage(this.getSize()); + } + if (size > 0) { + ret = comparator.compare(this.getDataStorage(), data, size, s); + } + } while (false); + } else { + int size = this.getSize(); + CobolDataStorage data = this.getDataStorage(); + sign = this.getSign(); + CobolDataStorage s = CobolModule.getCurrentModule().collating_sequence; + OUTSIDE: + do { + while (size >= other.getSize()) { + ret = comparator.compare(data, other.getDataStorage(), other.getSize(), s); + if (ret != 0) { + break OUTSIDE; + } + size -= other.getSize(); + data = data.getSubDataStorage(other.getSize()); + } + if (size > 0) { + ret = comparator.compare(data, other.getDataStorage(), size, s); + } + } while (false); + } + + if (this.getAttribute().getType() != CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED) { + this.putSign(sign); + } + return ret; + } + + /** + * TODO: 準備中 + * + * @param other TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSimpleStr(AbstractCobolField other) { + AbstractCobolField lf, sf; + DataComparator comparator = getComparator(this); + if (this.getSize() < other.getSize()) { + lf = other; + sf = this; + } else { + lf = this; + sf = other; + } + CobolDataStorage s = CobolModule.getCurrentModule().collating_sequence; + int ret = + comparator.compare(this.getDataStorage(), other.getDataStorage(), sf.getSize(), s); + if (ret == 0) { + if (lf.getSize() > sf.getSize()) { + if ((lf.getAttribute().getType() & CobolFieldAttribute.COB_TYPE_NATIONAL) != 0) { + int cmpResult = + AbstractCobolField.isNationalPadding( + sf.getSize(), lf.getDataStorage(), lf.getSize() - sf.getSize()); + return cmpResult == 0 ? 1 : 0; + } else { + ret = + AbstractCobolField.commonCmpc( + lf.getDataStorage().getSubDataStorage(sf.getSize()), + (byte) ' ', + lf.getSize() - sf.getSize()); + } + if (this.getSize() < other.getSize()) { + ret = -ret; + } + } + } + return ret; + } + + /** + * TODO: 準備中 + * + * @param other TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpAlnum(AbstractCobolField other) { + int sign1 = this.getSign(); + int sign2 = other.getSign(); + + if (this.getAttribute().isTypeNumericDisplay()) { + this.putSign(1); + } + if (other.getAttribute().isTypeNumericDisplay()) { + other.putSign(1); + } + + int ret = this.cmpSimpleStr(other); + + if (this.getAttribute().getType() != CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED) { + this.putSign(sign1); + } + if (other.getAttribute().getType() != CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED) { + other.putSign(sign2); + } + return ret; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public int realGetSign() { + CobolDataStorage p; + CobolFieldAttribute attr = this.getAttribute(); + byte b; + + switch (this.getAttribute().getType()) { + case CobolFieldAttribute.COB_TYPE_NUMERIC: + if (attr.isFlagSignLeading()) { + p = this.getDataStorage(); + } else { + p = this.getDataStorage().getSubDataStorage(this.getSize() - 1); + } + + b = p.getByte(0); + if (attr.isFlagSignSeparate()) { + return b == '+' ? 1 : -1; + } else { + if ('0' <= b && b <= '9') { + return 1; + } + if (b == ' ') { + p.setByte(0, (byte) '0'); + return 1; + } + if (CobolModule.getCurrentModule().display_sign != 0) { + return AbstractCobolField.getSignEbcdic(p); + } else { + // TODO マクロの分岐に関して調査 + // #ifdef COB_EBCDIC_MACHINE + // CobolUtil.getSignAscii(p); + // #else + p.setByte(0, (byte) (b - 0x40)); + // #endif + return -1; + } + } + case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: + p = this.getDataStorage().getSubDataStorage(this.size - 1); + return ((p.getByte(0) & 0x0f) == 0x0d) ? -1 : 1; + default: + return 0; + } + } + + /** + * TODO: 準備中 + * + * @param sign TODO: 準備中 + */ + public void realPutSign(int sign) { + CobolDataStorage p; + CobolFieldAttribute attr = this.getAttribute(); + byte b; + + switch (this.getAttribute().getType()) { + case CobolFieldAttribute.COB_TYPE_NUMERIC: + if (attr.isFlagSignLeading()) { + p = this.getDataStorage(); + } else { + p = this.getDataStorage().getSubDataStorage(this.getSize() - 1); + } + + b = p.getByte(0); + if (attr.isFlagSignSeparate()) { + char c = (sign < 0) ? '-' : '+'; + if (b != c) { + p.setByte(0, (byte) c); + } + } else if (CobolModule.getCurrentModule().display_sign != 0) { + AbstractCobolField.putSignEbcdic(p, sign); + } else if (sign < 0) { + p.setByte(0, (byte) (b + 0x40)); + } + return; + case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: + p = this.getDataStorage().getSubDataStorage(this.size - 1); + if (sign < 0) { + p.setByte(0, (byte) ((p.getByte(0) & 0xf0) | 0x0d)); + } else { + p.setByte(0, (byte) ((p.getByte(0) & 0xf0) | 0x0c)); + } + return; + default: + return; + } + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public long getLong() { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, + 18, + 0, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + byte[] data = new byte[8]; + CobolDataStorage storage = new CobolDataStorage(data); + AbstractCobolField field = CobolFieldFactory.makeCobolField(8, storage, attr); + field.moveFrom(this); + return ByteBuffer.wrap(data).getLong(); + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public long getLongValue() { + return 0; + } + + /** + * TODO: 準備中 + * + * @param src TODO: 準備中 + */ + public void hankakuMoveFrom(AbstractCobolField src) { + // TODO 暫定実装 + this.moveFrom(src); + } + + // libcob/common.cのcob_get_sign_ebcdicの実装 + /** + * TODO: 準備中 + * + * @param p TODO: 準備中 + * @return TODO: 準備中 + */ + private static int getSignEbcdic(CobolDataStorage p) { + switch (p.getByte(0)) { + case '{': + p.setByte(0, (byte) '0'); + return 1; + case 'A': + p.setByte(0, (byte) '1'); + return 1; + case 'B': + p.setByte(0, (byte) '2'); + return 1; + case 'C': + p.setByte(0, (byte) '3'); + return 1; + case 'D': + p.setByte(0, (byte) '4'); + return 1; + case 'E': + p.setByte(0, (byte) '5'); + return 1; + case 'F': + p.setByte(0, (byte) '6'); + return 1; + case 'G': + p.setByte(0, (byte) '7'); + return 1; + case 'H': + p.setByte(0, (byte) '8'); + return 1; + case 'I': + p.setByte(0, (byte) '9'); + return 1; + case '}': + p.setByte(0, (byte) '0'); + return -1; + case 'J': + p.setByte(0, (byte) '1'); + return -1; + case 'K': + p.setByte(0, (byte) '2'); + return -1; + case 'L': + p.setByte(0, (byte) '3'); + return -1; + case 'M': + p.setByte(0, (byte) '4'); + return -1; + case 'N': + p.setByte(0, (byte) '5'); + return -1; + case 'O': + p.setByte(0, (byte) '6'); + return -1; + case 'P': + p.setByte(0, (byte) '7'); + return -1; + case 'Q': + p.setByte(0, (byte) '8'); + return -1; + case 'R': + p.setByte(0, (byte) '9'); + return -1; + default: + /* What to do here */ + p.setByte(0, (byte) '0'); + return 1; + } + } + + // libcob/common.cのcob_put_sign_ebcdicの実装 + /** + * TODO: 準備中 + * + * @param p TODO: 準備中 + * @param sign TODO: 準備中 + */ + private static void putSignEbcdic(CobolDataStorage p, int sign) { + if (sign < 0) { + switch (p.getByte(0)) { + case '0': + p.setByte(0, (byte) '}'); + return; + case '1': + p.setByte(0, (byte) 'J'); + return; + case '2': + p.setByte(0, (byte) 'K'); + return; + case '3': + p.setByte(0, (byte) 'L'); + return; + case '4': + p.setByte(0, (byte) 'M'); + return; + case '5': + p.setByte(0, (byte) 'N'); + return; + case '6': + p.setByte(0, (byte) 'O'); + return; + case '7': + p.setByte(0, (byte) 'P'); + return; + case '8': + p.setByte(0, (byte) 'Q'); + return; + case '9': + p.setByte(0, (byte) 'R'); + return; + default: + /* What to do here */ + p.setByte(0, (byte) '}'); + return; + } + } + switch (p.getByte(0)) { + case '0': + p.setByte(0, (byte) '{'); + return; + case '1': + p.setByte(0, (byte) 'A'); + return; + case '2': + p.setByte(0, (byte) 'B'); + return; + case '3': + p.setByte(0, (byte) 'C'); + return; + case '4': + p.setByte(0, (byte) 'D'); + return; + case '5': + p.setByte(0, (byte) 'E'); + return; + case '6': + p.setByte(0, (byte) 'F'); + return; + case '7': + p.setByte(0, (byte) 'G'); + return; + case '8': + p.setByte(0, (byte) 'H'); + return; + case '9': + p.setByte(0, (byte) 'I'); + return; + default: + /* What to do here */ + p.setByte(0, (byte) '{'); + return; + } + } + + // libcob/common.cのcommon_compcの実装 + /** + * TODO: 準備中 + * + * @param s1 TODO: 準備中 + * @param c TODO: 準備中 + * @param size TODO: 準備中 + * @return TODO: 準備中 + */ + private static int commonCmpc(CobolDataStorage s1, byte c, int size) { + CobolDataStorage s = CobolModule.getCurrentModule().collating_sequence; + int uc = c & 0xFF; + if (s != null) { + for (int i = 0; i < size; ++i) { + // int ret = s.getByte((s1.getByte(i) & 0xFF) - (s.getByte(uc) & 0xFF)); + int ret = (s.getByte(s1.getByte(i) & 0xFF) & 0xFF) - (s.getByte(uc) & 0xFF); + if (ret != 0) { + return ret; + } + } + } else { + for (int i = 0; i < size; ++i) { + int ret = (s1.getByte(i) & 0xFF) - uc; + if (ret != 0) { + return ret; + } + } + } + return 0; + } + + // libcob/common.cのis_national_paddingの実装 + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param s TODO: 準備中 + * @param size TODO: 準備中 + * @return TODO: 準備中 + */ + private static int isNationalPadding(int offset, CobolDataStorage s, int size) { + int ret = 1; + int i = 0; + while (i < size && ret != 0) { + if (s.getByte(offset + i) == ' ') { + i++; + } else if (size - i >= CobolConstant.ZENCSIZ) { + for (int j = 0; j < CobolConstant.ZENCSIZ; ++j) { + if (s.getByte(offset + i + j) != CobolConstant.ZENSPC[j]) { + return 0; + } + } + i += CobolConstant.ZENCSIZ; + } else { + ret = 0; + } + } + return ret; + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolAlphanumericAllField.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolAlphanumericAllField.java index 107f8303..c667a3ed 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolAlphanumericAllField.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolAlphanumericAllField.java @@ -1,34 +1,34 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.data; - -/** TODO: 準備中 */ -public class CobolAlphanumericAllField extends CobolAlphanumericField { - /** - * コンストラクタ - * - * @param size データを格納するバイト配列の長さ - * @param dataStorage データを格納するバイト配列を扱うオブジェクト - * @param attribute 変数に関する様々な情報を保持するオブジェクト - */ - public CobolAlphanumericAllField( - int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { - super(size, dataStorage, attribute); - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.data; + +/** TODO: 準備中 */ +public class CobolAlphanumericAllField extends CobolAlphanumericField { + /** + * コンストラクタ + * + * @param size データを格納するバイト配列の長さ + * @param dataStorage データを格納するバイト配列を扱うオブジェクト + * @param attribute 変数に関する様々な情報を保持するオブジェクト + */ + public CobolAlphanumericAllField( + int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { + super(size, dataStorage, attribute); + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolAlphanumericEditedField.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolAlphanumericEditedField.java index da5d28c5..92bf3c7d 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolAlphanumericEditedField.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolAlphanumericEditedField.java @@ -1,187 +1,192 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.data; - -import java.math.BigDecimal; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -/** TODO: 準備中 */ -public class CobolAlphanumericEditedField extends AbstractCobolField { - /** - * コンストラクタ - * - * @param size データを格納するバイト配列の長さ - * @param dataStorage データを格納するバイト配列を扱うオブジェクト - * @param attribute 変数に関する様々な情報を保持するオブジェクト - */ - public CobolAlphanumericEditedField( - int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { - super(size, dataStorage, attribute); - } - - @Override - public byte[] getBytes() { - // TODO Auto-generated method stub - return new byte[0]; - } - - @Override - public String getString() { - // TODO Auto-generated method stub - return null; - } - - @Override - public CobolDecimal getDecimal() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void setDecimal(BigDecimal decimal) { - // TODO Auto-generated method stub - - } - - @Override - public int addPackedInt(int n) { - // TODO Auto-generated method stub - return 0; - } - - @Override - public void moveFrom(AbstractCobolField src) { - AbstractCobolField src1 = this.preprocessOfMoving(src); - if (src1 == null) { - return; - } - - switch (src1.getAttribute().getType()) { - case CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY: - CobolFieldAttribute attr = src1.getAttribute(); - int scale = src1.getAttribute().getScale(); - int digits = src1.getAttribute().getDigits(); - if (scale < 0 || scale > digits) { - CobolFieldAttribute newAttr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, attr.getDigits(), 0, 0, null); - int newSize = scale < 0 ? digits - scale : scale; - AbstractCobolField newSrc = - CobolFieldFactory.makeCobolField(newSize, new CobolDataStorage(newSize), newAttr); - newSrc.moveFrom(src1); - this.moveFrom(newSrc); - } else { - CobolAlphanumericEditedField.moveAlphanumToEdited(this, src1); - } - break; - case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: - case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: - case CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE: - case CobolFieldAttribute.COB_TYPE_NUMERIC_FLOAT: - this.moveFrom(src1.getNumericField()); - break; - case CobolFieldAttribute.COB_TYPE_GROUP: - CobolAlphanumericField.moveAlphanumToAlphanum(this, src1); - break; - default: - CobolAlphanumericEditedField.moveAlphanumToEdited(this, src1); - break; - } - } - - /** - * TODO: 準備中 - * - * @param dst TODO: 準備中 - * @param src TODO: 準備中 - */ - public static void moveAlphanumToEdited(AbstractCobolField dst, AbstractCobolField src) { - CobolDataStorage srcd = src.getDataStorage(); - CobolDataStorage dstd = dst.getDataStorage(); - int sign = src.getSign(); - int max = src.getFieldSize(); - int srcp = src.getFirstDataIndex(); - int dstp = 0; - byte[] picBytes = dst.getAttribute().getPic().getBytes(); - final int sizeOfInt = 4; - - for (int p = 0; p < picBytes.length; ) { - byte c = picBytes[p++]; - ByteBuffer buf = ByteBuffer.wrap(picBytes, p, sizeOfInt); - buf.order(ByteOrder.LITTLE_ENDIAN); - int n = buf.getInt(); - p += sizeOfInt; - - for (; n > 0; --n) { - switch (c) { - case 'A': - case 'X': - case '9': - dstd.setByte(dstp++, (srcp < max) ? srcd.getByte(srcp++) : (byte) ' '); - break; - case '0': - case '/': - dstd.setByte(dstp++, c); - break; - case 'B': - dstd.setByte(dstp++, (byte) ' '); - break; - default: - dstd.setByte(dstp++, (byte) '?'); /* invalid PIC */ - break; - } - } - } - src.putSign(sign); - } - - @Override - public void moveFrom(CobolDataStorage dataStrage) { - // TODO Auto-generated method stub - - } - - @Override - public void moveFrom(byte[] bytes) { - // TODO Auto-generated method stub - - } - - @Override - public void moveFrom(String string) { - // TODO Auto-generated method stub - } - - @Override - public void moveFrom(int number) { - // TODO Auto-generated method stub - } - - @Override - public void moveFrom(double number) { - // TODO Auto-generated method stub - - } - - @Override - public void moveFrom(BigDecimal number) { - // TODO Auto-generated method stub - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.data; + +import java.math.BigDecimal; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +/** TODO: 準備中 */ +public class CobolAlphanumericEditedField extends AbstractCobolField { + /** + * コンストラクタ + * + * @param size データを格納するバイト配列の長さ + * @param dataStorage データを格納するバイト配列を扱うオブジェクト + * @param attribute 変数に関する様々な情報を保持するオブジェクト + */ + public CobolAlphanumericEditedField( + int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { + super(size, dataStorage, attribute); + } + + @Override + public byte[] getBytes() { + // TODO Auto-generated method stub + return new byte[0]; + } + + @Override + public String getString() { + // TODO Auto-generated method stub + return null; + } + + @Override + public CobolDecimal getDecimal() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setDecimal(BigDecimal decimal) { + // TODO Auto-generated method stub + + } + + @Override + public int addPackedInt(int n) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void moveFrom(AbstractCobolField src) { + AbstractCobolField src1 = this.preprocessOfMoving(src); + if (src1 == null) { + return; + } + + switch (src1.getAttribute().getType()) { + case CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY: + CobolFieldAttribute attr = src1.getAttribute(); + int scale = src1.getAttribute().getScale(); + int digits = src1.getAttribute().getDigits(); + if (scale < 0 || scale > digits) { + CobolFieldAttribute newAttr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, + attr.getDigits(), + 0, + 0, + null); + int newSize = scale < 0 ? digits - scale : scale; + AbstractCobolField newSrc = + CobolFieldFactory.makeCobolField( + newSize, new CobolDataStorage(newSize), newAttr); + newSrc.moveFrom(src1); + this.moveFrom(newSrc); + } else { + CobolAlphanumericEditedField.moveAlphanumToEdited(this, src1); + } + break; + case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: + case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: + case CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE: + case CobolFieldAttribute.COB_TYPE_NUMERIC_FLOAT: + this.moveFrom(src1.getNumericField()); + break; + case CobolFieldAttribute.COB_TYPE_GROUP: + CobolAlphanumericField.moveAlphanumToAlphanum(this, src1); + break; + default: + CobolAlphanumericEditedField.moveAlphanumToEdited(this, src1); + break; + } + } + + /** + * TODO: 準備中 + * + * @param dst TODO: 準備中 + * @param src TODO: 準備中 + */ + public static void moveAlphanumToEdited(AbstractCobolField dst, AbstractCobolField src) { + CobolDataStorage srcd = src.getDataStorage(); + CobolDataStorage dstd = dst.getDataStorage(); + int sign = src.getSign(); + int max = src.getFieldSize(); + int srcp = src.getFirstDataIndex(); + int dstp = 0; + byte[] picBytes = dst.getAttribute().getPic().getBytes(AbstractCobolField.charSetSJIS); + final int sizeOfInt = 4; + + for (int p = 0; p < picBytes.length; ) { + byte c = picBytes[p++]; + ByteBuffer buf = ByteBuffer.wrap(picBytes, p, sizeOfInt); + buf.order(ByteOrder.LITTLE_ENDIAN); + int n = buf.getInt(); + p += sizeOfInt; + + for (; n > 0; --n) { + switch (c) { + case 'A': + case 'X': + case '9': + dstd.setByte(dstp++, (srcp < max) ? srcd.getByte(srcp++) : (byte) ' '); + break; + case '0': + case '/': + dstd.setByte(dstp++, c); + break; + case 'B': + dstd.setByte(dstp++, (byte) ' '); + break; + default: + dstd.setByte(dstp++, (byte) '?'); /* invalid PIC */ + break; + } + } + } + src.putSign(sign); + } + + @Override + public void moveFrom(CobolDataStorage dataStrage) { + // TODO Auto-generated method stub + + } + + @Override + public void moveFrom(byte[] bytes) { + // TODO Auto-generated method stub + + } + + @Override + public void moveFrom(String string) { + // TODO Auto-generated method stub + } + + @Override + public void moveFrom(int number) { + // TODO Auto-generated method stub + } + + @Override + public void moveFrom(double number) { + // TODO Auto-generated method stub + + } + + @Override + public void moveFrom(BigDecimal number) { + // TODO Auto-generated method stub + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolAlphanumericField.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolAlphanumericField.java index e95d38f2..c678ef52 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolAlphanumericField.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolAlphanumericField.java @@ -1,246 +1,238 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.data; - -import java.io.UnsupportedEncodingException; -import java.math.BigDecimal; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; - -/** PIC 文字列がX(5)やX(9)の変数を表現するクラス. */ -public class CobolAlphanumericField extends AbstractCobolField { - - /** - * コンストラクタ - * - * @param size データを格納するバイト配列の長さ - * @param dataStorage データを格納するバイト配列を扱うオブジェクト - * @param attribute 変数に関する様々な情報を保持するオブジェクト - */ - public CobolAlphanumericField( - int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { - super(size, dataStorage, attribute); - } - - @Override - public byte[] getBytes() { - return dataStorage.getData(); - } - - @Override - public String getString() { - try { - return new String(dataStorage.getByteArray(0, this.getSize()), "SJIS"); - } catch (UnsupportedEncodingException e) { - return ""; - } - } - - @Override - public void setDecimal(BigDecimal decimal) { - // TODO 自動生成されたメソッド・スタブ - - } - - @Override - public void moveFrom(AbstractCobolField src) { - AbstractCobolField src1 = this.preprocessOfMoving(src); - if (src1 == null) { - return; - } - - switch (src1.getAttribute().getType()) { - case CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY: - this.moveDisplayToAlnum(src1); - return; - case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: - case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: - case CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE: - case CobolFieldAttribute.COB_TYPE_NUMERIC_FLOAT: - this.moveFrom(src1.getNumericField()); - return; - case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC: - case CobolFieldAttribute.COB_TYPE_NATIONAL: - case CobolFieldAttribute.COB_TYPE_NUMERIC_EDITED: - case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_EDITED: - case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: - case CobolFieldAttribute.COB_TYPE_GROUP: - this.moveAlphanumToAlphanum(src1); - return; - default: - throw new CobolRuntimeException(0, "未実装"); - } - } - - /** - * CobolNumericDisplayからCobolAlphanumericFieldへのMOVEの処理 - * - * @param field 転記元のCobolNumericDisplay型のフィールド - */ - public void moveDisplayToAlnum(AbstractCobolField field) { - CobolDataStorage data1 = field.getDataStorage(); - int data1FirstIndex = field.getFirstDataIndex(); - int size1 = field.getFieldSize(); - int sign = field.getSign(); - CobolDataStorage data2 = this.getDataStorage(); - int size2 = this.getSize(); - - if (size1 >= size2) { - for (int i = 0; i < size2 && data1FirstIndex + i < size1; ++i) { - byte val = data1.getByte(data1FirstIndex + i); - data2.setByte(i, (byte) (val >= 0x70 ? val - 0x40 : val)); - } - } else { - int diff = size2 - size1; - int zeroSize = 0; - int i = 0; - for (; i < size1; ++i) { - byte val = data1.getByte(data1FirstIndex + i); - data2.setByte(i, (byte) (val >= 0x70 ? val - 0x40 : val)); - } - if (field.getAttribute().getScale() < 0) { - for (; i < field.getAttribute().getDigits(); ++i) { - data2.setByte(i, (byte) '0'); - } - } - if (diff - zeroSize > 0) { - for (; i < size2; ++i) { - data2.setByte(i, (byte) ' '); - } - } - } - field.putSign(sign); - } - - /** - * CobolNumericDisplayからCobolAlphanumericFieldへのMOVEの処理 - * - * @param field 転記元のCobolNumericDisplay型のフィールド - */ - public void moveAlphanumToAlphanum(AbstractCobolField field) { - CobolAlphanumericField.moveAlphanumToAlphanum(this, field); - } - - /** - * TODO: 準備中 - * - * @param dst TODO: 準備中 - * @param src TODO: 準備中 - */ - public static void moveAlphanumToAlphanum(AbstractCobolField dst, AbstractCobolField src) { - CobolDataStorage data1 = src.getDataStorage(); - int size1 = src.getSize(); - CobolDataStorage data2 = dst.getDataStorage(); - int size2 = dst.getSize(); - if (size1 >= size2) { - if (dst.getAttribute().isFlagJustified()) { - for (int i = 0; i < size2; ++i) { - data2.setByte(i, data1.getByte(size1 - size2 + i)); - } - } else { - for (int i = 0; i < size2; ++i) { - data2.setByte(i, data1.getByte(i)); - } - } - } else { - if (dst.getAttribute().isFlagJustified()) { - for (int i = 0; i < size2 - size1; ++i) { - data2.setByte(i, (byte) 0x20); - } - for (int i = 0; i < size1; ++i) { - data2.setByte(size2 - size1 + i, data1.getByte(i)); - } - } else { - for (int i = 0; i < size1; ++i) { - data2.setByte(i, data1.getByte(i)); - } - for (int i = 0; i < size2 - size1; ++i) { - data2.setByte(size1 + i, (byte) 0x20); - } - } - } - } - - @Override - public void moveFrom(byte[] bytes) { - this.dataStorage.setData(bytes); - } - - @Override - public void moveFrom(String string) { - try { - byte[] bytes = string.getBytes("SJIS"); - int length = Math.min(bytes.length, this.getSize()); - CobolDataStorage data = this.getDataStorage(); - // ' '埋め - for (int i = 0; i < this.getSize(); ++i) { - data.setByte(i, (byte) 0x20); - } - for (int i = 0; i < length; ++i) { - data.setByte(i, bytes[i]); - } - } catch (UnsupportedEncodingException e) { - return; - } - } - - @Override - public CobolNumericField getNumericField() { - int size = 36; - int scale = 18; - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, - size, - scale, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - CobolDataStorage data = new CobolDataStorage(64); - CobolNumericField field = new CobolNumericField(size, data, attr); - field.moveFrom(this); - return field; - } - - @Override - public void moveFrom(int number) { - // TODO 自動生成されたメソッド・スタブ - } - - @Override - public void moveFrom(double number) { - // TODO 自動生成されたメソッド・スタブ - this.moveFrom((int) number); - } - - @Override - public void moveFrom(BigDecimal number) { - // TODO 自動生成されたメソッド・スタブ - - } - - @Override - public void moveFrom(CobolDataStorage dataStorage) { - // TODO 自動生成されたメソッド・スタブ - - } - - @Override - public int addPackedInt(int n) { - throw new CobolRuntimeException(0, "実装しないコード"); - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.data; + +import java.math.BigDecimal; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; + +/** PIC 文字列がX(5)やX(9)の変数を表現するクラス. */ +public class CobolAlphanumericField extends AbstractCobolField { + + /** + * コンストラクタ + * + * @param size データを格納するバイト配列の長さ + * @param dataStorage データを格納するバイト配列を扱うオブジェクト + * @param attribute 変数に関する様々な情報を保持するオブジェクト + */ + public CobolAlphanumericField( + int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { + super(size, dataStorage, attribute); + } + + @Override + public byte[] getBytes() { + return dataStorage.getData(); + } + + @Override + public String getString() { + return new String( + dataStorage.getByteArray(0, this.getSize()), AbstractCobolField.charSetSJIS); + } + + @Override + public void setDecimal(BigDecimal decimal) { + // TODO 自動生成されたメソッド・スタブ + + } + + @Override + public void moveFrom(AbstractCobolField src) { + AbstractCobolField src1 = this.preprocessOfMoving(src); + if (src1 == null) { + return; + } + + switch (src1.getAttribute().getType()) { + case CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY: + this.moveDisplayToAlnum(src1); + return; + case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: + case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: + case CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE: + case CobolFieldAttribute.COB_TYPE_NUMERIC_FLOAT: + this.moveFrom(src1.getNumericField()); + return; + case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC: + case CobolFieldAttribute.COB_TYPE_NATIONAL: + case CobolFieldAttribute.COB_TYPE_NUMERIC_EDITED: + case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_EDITED: + case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: + case CobolFieldAttribute.COB_TYPE_GROUP: + this.moveAlphanumToAlphanum(src1); + return; + default: + throw new CobolRuntimeException(0, "未実装"); + } + } + + /** + * CobolNumericDisplayからCobolAlphanumericFieldへのMOVEの処理 + * + * @param field 転記元のCobolNumericDisplay型のフィールド + */ + public void moveDisplayToAlnum(AbstractCobolField field) { + CobolDataStorage data1 = field.getDataStorage(); + int data1FirstIndex = field.getFirstDataIndex(); + int size1 = field.getFieldSize(); + int sign = field.getSign(); + CobolDataStorage data2 = this.getDataStorage(); + int size2 = this.getSize(); + + if (size1 >= size2) { + for (int i = 0; i < size2 && data1FirstIndex + i < size1; ++i) { + byte val = data1.getByte(data1FirstIndex + i); + data2.setByte(i, (byte) (val >= 0x70 ? val - 0x40 : val)); + } + } else { + int diff = size2 - size1; + int zeroSize = 0; + int i = 0; + for (; i < size1; ++i) { + byte val = data1.getByte(data1FirstIndex + i); + data2.setByte(i, (byte) (val >= 0x70 ? val - 0x40 : val)); + } + if (field.getAttribute().getScale() < 0) { + for (; i < field.getAttribute().getDigits(); ++i) { + data2.setByte(i, (byte) '0'); + } + } + if (diff - zeroSize > 0) { + for (; i < size2; ++i) { + data2.setByte(i, (byte) ' '); + } + } + } + field.putSign(sign); + } + + /** + * CobolNumericDisplayからCobolAlphanumericFieldへのMOVEの処理 + * + * @param field 転記元のCobolNumericDisplay型のフィールド + */ + public void moveAlphanumToAlphanum(AbstractCobolField field) { + CobolAlphanumericField.moveAlphanumToAlphanum(this, field); + } + + /** + * TODO: 準備中 + * + * @param dst TODO: 準備中 + * @param src TODO: 準備中 + */ + public static void moveAlphanumToAlphanum(AbstractCobolField dst, AbstractCobolField src) { + CobolDataStorage data1 = src.getDataStorage(); + int size1 = src.getSize(); + CobolDataStorage data2 = dst.getDataStorage(); + int size2 = dst.getSize(); + if (size1 >= size2) { + if (dst.getAttribute().isFlagJustified()) { + for (int i = 0; i < size2; ++i) { + data2.setByte(i, data1.getByte(size1 - size2 + i)); + } + } else { + for (int i = 0; i < size2; ++i) { + data2.setByte(i, data1.getByte(i)); + } + } + } else { + if (dst.getAttribute().isFlagJustified()) { + for (int i = 0; i < size2 - size1; ++i) { + data2.setByte(i, (byte) 0x20); + } + for (int i = 0; i < size1; ++i) { + data2.setByte(size2 - size1 + i, data1.getByte(i)); + } + } else { + for (int i = 0; i < size1; ++i) { + data2.setByte(i, data1.getByte(i)); + } + for (int i = 0; i < size2 - size1; ++i) { + data2.setByte(size1 + i, (byte) 0x20); + } + } + } + } + + @Override + public void moveFrom(byte[] bytes) { + this.dataStorage.setData(bytes); + } + + @Override + public void moveFrom(String string) { + byte[] bytes = string.getBytes(AbstractCobolField.charSetSJIS); + int length = Math.min(bytes.length, this.getSize()); + CobolDataStorage data = this.getDataStorage(); + // ' '埋め + for (int i = 0; i < this.getSize(); ++i) { + data.setByte(i, (byte) 0x20); + } + for (int i = 0; i < length; ++i) { + data.setByte(i, bytes[i]); + } + } + + @Override + public CobolNumericField getNumericField() { + int size = 36; + int scale = 18; + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, + size, + scale, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + CobolDataStorage data = new CobolDataStorage(64); + CobolNumericField field = new CobolNumericField(size, data, attr); + field.moveFrom(this); + return field; + } + + @Override + public void moveFrom(int number) { + // TODO 自動生成されたメソッド・スタブ + } + + @Override + public void moveFrom(double number) { + // TODO 自動生成されたメソッド・スタブ + this.moveFrom((int) number); + } + + @Override + public void moveFrom(BigDecimal number) { + // TODO 自動生成されたメソッド・スタブ + + } + + @Override + public void moveFrom(CobolDataStorage dataStorage) { + // TODO 自動生成されたメソッド・スタブ + + } + + @Override + public int addPackedInt(int n) { + throw new CobolRuntimeException(0, "実装しないコード"); + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolDataStorage.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolDataStorage.java index 49c2f811..dff54357 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolDataStorage.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolDataStorage.java @@ -1,2588 +1,2696 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.data; - -import java.io.UnsupportedEncodingException; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import jp.osscons.opensourcecobol.libcobj.common.CobolModule; - -/** - * COBOL変数のデータを保存するバイト配列を扱うクラス
- * byte[]型のデータと、その配列中での相対位置を保持し、データの読み書きを行う - */ -public class CobolDataStorage { - - /** データを保存するバイト配列 */ - private byte[] data; - - /** このクラスの扱うデータが保存する領域のバイト配列中での相対位置 */ - private int index; - - /** - * 引数で指定された長さ分のバイト配列を確保する.相対位置は0にする. - * - * @param size バイト配列の長さ - */ - public CobolDataStorage(int size) { - this.data = new byte[size]; - this.index = 0; - } - - /** - * バイト配列と相対位置を指定する - * - * @param data データを保存するバイト配列 - * @param index バイト配列中の相対位置 - */ - public CobolDataStorage(byte[] data, int index) { - this.data = data; - this.index = index; - } - - /** - * データを保存するバイト配列を引数で指定する.相対位置は0にする. - * - * @param data データを保存するバイト配列 - */ - public CobolDataStorage(byte[] data) { - this(data, 0); - } - - /** - * TODO: 準備中 - * - * @param bytes TODO: 準備中 - * @return TODO: 準備中 - */ - public static CobolDataStorage makeCobolDataStorage(byte... bytes) { - return new CobolDataStorage(bytes); - } - - /** TODO: 準備中 */ - public CobolDataStorage() { - this.index = 0; - this.data = null; - } - - /** - * TODO: 準備中 - * - * @param data TODO: 準備中 - * @param index TODO: 準備中 - */ - public void setDataRefAndIndex(CobolDataStorage data, int index) { - this.data = data.data; - this.index = index; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public int getIndex() { - return this.index; - } - - /** - * TODO: 準備中 - * - * @param index TODO: 準備中 - */ - public void setIndex(int index) { - this.index = index; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public byte[] getRefOfData() { - return this.data; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public CobolDataStorage copy() { - CobolDataStorage ret = new CobolDataStorage(); - ret.index = this.index; - ret.data = this.data; - return ret; - } - - /** - * TODO: 準備中 - * - * @param size TODO: 準備中 - * @return TODO: 準備中 - */ - public ByteBuffer getByteBuffer(int size) { - return ByteBuffer.wrap(this.data, this.index, size); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addIndex(int n) { - this.index += n; - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public static CobolDataStorage primitiveToDataStorage(int n) { - byte[] bytes = new byte[4]; - ByteBuffer buffer = ByteBuffer.wrap(bytes); - buffer.putInt(n); - return new CobolDataStorage(bytes); - } - - /** - * TODO: 準備中 - * - * @param s TODO: 準備中 - * @return TODO: 準備中 - */ - public static CobolDataStorage primitiveToDataStorage(String s) { - return new CobolDataStorage(s); - } - - /** - * TODO: 準備中 - * - * @param str TODO: 準備中 - */ - public CobolDataStorage(String str) { - try { - byte[] bytes = str.getBytes("SHIFT-JIS"); - this.data = bytes; - this.index = 0; - } catch (Exception e) { - e.printStackTrace(); - this.data = new byte[0]; - this.index = 0; - } - } - - /** - * 保持するバイト配列のコピーを返す - * - * @return TODO: 準備中 - */ - public byte[] getData() { - return this.getData(0); - } - - /** - * 引数で指定した開始位置から末尾までをコピーした配列を返す。 - * - * @param index このオブジェクトの保持する相対位置を基準とした、コピーの開始位置 - * @return 開始位置から末尾までのデータをコピーしたバイト配列 - */ - public byte[] getData(int index) { - byte[] result = new byte[this.data.length - this.index - index]; - - System.arraycopy(this.data, this.index + index, result, 0, result.length); - - return result; - } - - /** - * 引数で指定した相対位置から指定した長さをコピーした配列を返す。 - * - * @param index このオブジェクトの保持する相対位置を基準とした、コピーの開始位置 - * @param length コピーする長さ(バイト数) - * @return 開始位置からlengthバイト分の配列 - */ - public byte[] getByteArray(int index, int length) { - byte[] result = new byte[length]; - System.arraycopy(this.data, this.index + index, result, 0, length); - return result; - } - - /** - * TODO: 準備中 - * - * @param index TODO: 準備中 - * @param length TODO: 準備中 - * @return TODO: 準備中 - */ - public byte[] getByteArrayRef(int index, int length) { - ByteBuffer buffer = ByteBuffer.wrap(this.data, this.index + index, length); - return buffer.array(); - } - - /** - * C言語のmemcpyに相当するメソッド - * - * @param buf TODO: 準備中 - * @param size TODO: 準備中 - */ - public void memcpy(CobolDataStorage buf, int size) { - for (int i = 0; i < size; ++i) { - this.setByte(i, buf.getByte(i)); - } - } - - /** - * C言語のmemcpyに相当するメソッド - * - * @param buf TODO: 準備中 - * @param size TODO: 準備中 - */ - public void memcpy(byte[] buf, int size) { - for (int i = 0; i < size; ++i) { - this.setByte(i, buf[i]); - } - } - - /** - * C言語のmemcpyに相当するメソッド - * - * @param str TODO: 準備中 - * @param size TODO: 準備中 - */ - public void memcpy(String str, int size) { - try { - this.memcpy(str.getBytes("SJIS"), size); - } catch (UnsupportedEncodingException e) { - this.memcpy(str.getBytes(), size); - } - } - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param buf TODO: 準備中 - * @param size TODO: 準備中 - */ - public void memcpy(int offset, byte[] buf, int size) { - for (int i = 0; i < size; ++i) { - this.setByte(offset + i, buf[i]); - } - } - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param buf TODO: 準備中 - * @param size TODO: 準備中 - */ - public void memcpy(int offset, CobolDataStorage buf, int size) { - for (int i = 0; i < size; ++i) { - this.setByte(offset + i, buf.getByte(i)); - } - } - - /** - * TODO: 準備中 - * - * @param buf TODO: 準備中 - * @param offset TODO: 準備中 - * @param size TODO: 準備中 - */ - public void memcpy(byte[] buf, int offset, int size) { - System.arraycopy(buf, offset, this.data, this.index, size); - } - - /** - * TODO: 準備中 - * - * @param buf TODO: 準備中 - */ - public void memcpy(byte[] buf) { - this.memcpy(buf, buf.length); - } - - /** - * C言語のmemsetに相当するメソッド - * - * @param ch TODO: 準備中 - * @param size TODO: 準備中 - */ - public void memset(byte ch, int size) { - for (int i = 0; i < size; ++i) { - this.setByte(i, ch); - } - } - - /** - * C言語のmemsetに相当するメソッド - * - * @param ch TODO: 準備中 - * @param size TODO: 準備中 - */ - public void memset(int ch, int size) { - this.memset((byte) ch, size); - } - - /** - * C言語のmemsetに相当するメソッド - * - * @param offset TODO: 準備中 - * @param ch TODO: 準備中 - * @param size TODO: 準備中 - */ - public void memset(int offset, byte ch, int size) { - for (int i = 0; i < size; ++i) { - this.setByte(offset + i, ch); - } - } - - /** - * C言語のmemsetに相当するメソッド - * - * @param offset TODO: 準備中 - * @param ch TODO: 準備中 - * @param size TODO: 準備中 - */ - public void memset(int offset, int ch, int size) { - this.memset(offset, (byte) ch, size); - } - - /** - * C言語のmemcmpに相当するメソッド - * - * @param buf TODO: 準備中 - * @param size TODO: 準備中 - * @return TODO: 準備中 - */ - public int memcmp(byte[] buf, int size) { - for (int i = 0; i < size; ++i) { - if (this.getByte(i) != buf[i]) { - int x = Byte.toUnsignedInt(this.getByte(i)); - int y = Byte.toUnsignedInt(buf[i]); - return x - y; - } - } - return 0; - } - - /** - * C言語のmemcmpに相当するメソッド - * - * @param buf TODO: 準備中 - * @param size TODO: 準備中 - * @return TODO: 準備中 - */ - public int memcmp(String buf, int size) { - return this.memcmp(buf.getBytes(), size); - } - - /** - * C言語のmemcmpに相当するメソッド - * - * @param buf TODO: 準備中 - * @param size TODO: 準備中 - * @return TODO: 準備中 - */ - public int memcmp(CobolDataStorage buf, int size) { - for (int i = 0; i < size; ++i) { - if (this.getByte(i) != buf.getByte(i)) { - int x = Byte.toUnsignedInt(this.getByte(i)); - int y = Byte.toUnsignedInt(buf.getByte(i)); - return x - y; - } - } - return 0; - } - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param buf TODO: 準備中 - * @param size TODO: 準備中 - * @return TODO: 準備中 - */ - public int memcmp(int offset, CobolDataStorage buf, int size) { - for (int i = 0; i < size; ++i) { - byte x = this.getByte(offset + i); - byte y = buf.getByte(i); - if (x != y) { - return Byte.toUnsignedInt(x) - Byte.toUnsignedInt(y); - } - } - return 0; - } - - /** - * 引数で与えられたバイト配列に保持したデータをこのオブジェクトに書き込む - * - * @param data TODO: 準備中 - */ - public void setData(byte[] data) { - setData(data, 0); - } - - /** - * 引数で与えられたバイト配列に保持したデータをこのオブジェクトに書き込む - * - * @param data コピー元のバイト配列 - * @param index コピー先のバイト配列中での開始位置 - */ - public void setData(byte[] data, int index) { - int length = - (data.length <= this.data.length - this.index - index) - ? data.length - : this.data.length - this.index - index; - - System.arraycopy(data, 0, this.data, this.index + index, length); - } - - /** - * 引数で指定された分だけ相対位置を変位させたCobolDataStorageクラスのインスタンスを作成する - * - * @param index 変位させるバイト数 - * @return 新たに作成したCobolDataStorageクラスのインスタンス - */ - public CobolDataStorage getDataStorage(int index) { - return new CobolDataStorage(this.data, this.index + index); - } - - /** - * 指定のバイト配列中での位置に指定の値を代入する - * - * @param index 代入先のバイト配列中の位置 - * @param value 代入する値 - */ - public void setByte(int index, byte value) { - this.data[this.index + index] = value; - } - - /** - * 指定のバイト配列中での位置に指定の値を代入する - * - * @param index 代入先のバイト配列中の位置 - * @param value 代入する値 - */ - public void setByte(int index, int value) { - this.setByte(index, (byte) value); - } - - /** - * 指定のバイト配列中での位置に指定の値を代入する - * - * @param index 代入先のバイト配列中の位置. - * @param value 代入する値 - */ - public void setByte(int index, char value) { - this.setByte(index, (byte) value); - } - - /** - * TODO: 準備中 - * - * @param value TODO: 準備中 - */ - public void setByte(byte value) { - this.setByte(0, value); - } - - /** - * TODO: 準備中 - * - * @param value TODO: 準備中 - */ - public void setByte(int value) { - this.setByte((byte) value); - } - - /** - * TODO: 準備中 - * - * @param value TODO: 準備中 - */ - public void setByte(char value) { - this.setByte((byte) value); - } - - /** - * 指定のバイト配列中での位置に格納された値を返す - * - * @param index バイト配列中での位置. - * @return 指定のバイト配列中での位置に格納された値 - */ - public byte getByte(int index) { - return this.data[this.index + index]; - } - - /** - * バイト配列のthis.indexバイト目からsizeバイトの範囲にvalueを代入する - * - * @param value 代入する値 - * @param size 代入先のバイト数 - */ - public void fillBytes(byte value, int size) { - fillBytes(0, value, size); - } - - /** - * バイト配列のthis.indexバイト目からsizeバイトの範囲にvalueを代入する - * - * @param value 代入する値 - * @param size 代入先のバイト数 - */ - public void fillBytes(int value, int size) { - fillBytes(0, value, size); - } - - /** - * バイト配列のthis.indexバイト目からsizeバイトの範囲にvalueを代入する - * - * @param value 代入する値 - * @param size 代入先のバイト数 - */ - public void fillBytes(char value, int size) { - fillBytes(0, value, size); - } - - /** - * バイト配列の0バイト目からsizeバイトの範囲にvalueを代入する - * - * @param index コピーの開始位置 - * @param value 代入する値 - * @param size 代入先のバイト数 - */ - public void fillBytes(int index, byte value, int size) { - for (int i = 0; i < size; ++i) { - this.setByte(i + index, value); - } - } - - /** - * バイト配列の0バイト目からsizeバイトの範囲にvalueを代入する - * - * @param index コピーの開始位置 - * @param value 代入する値 - * @param size 代入先のバイト数 - */ - public void fillBytes(int index, int value, int size) { - this.fillBytes(index, (byte) value, size); - } - - /** - * バイト配列の0バイト目からsizeバイトの範囲にvalueを代入する - * - * @param index コピーの開始位置 - * @param value 代入する値 - * @param size 代入先のバイト数 - */ - public void fillBytes(int index, char value, int size) { - this.fillBytes(index, (byte) value, size); - } - - /** - * TODO: 準備中 - * - * @param bytes コピー元のバイト配列 - */ - public void setBytes(byte[] bytes) { - for (int i = 0; i < bytes.length; ++i) { - this.setByte(i, bytes[i]); - } - } - - /** - * TODO: 準備中 - * - * @param bytes コピー元の配列 - * @param length コピーするバイト数 - */ - public void setBytes(byte[] bytes, int length) { - for (int i = 0; i < length; ++i) { - this.setByte(i, bytes[i]); - } - } - - /** - * 指定のバイト配列に格納された値を this.dataのthis.indexバイト目以降へlengthバイトだけコピーする. - * - * @param index コピー先のthis.indexからの相対位置 - * @param bytes コピー元の配列 - * @param length コピーするバイト数 - */ - public void setBytes(int index, byte[] bytes, int length) { - for (int i = 0; i < length; ++i) { - this.setByte(i + index, bytes[i]); - } - } - - /** - * 指定した文字列をバイト配列にコピーする - * - * @param str コピー元の文字列 - * @param length コピーするバイト数 - */ - public void setBytes(String str, int length) { - try { - this.setBytes(str.getBytes("SHIFT-JIS"), length); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * 指定されたCobolDataStorageのインスタンスから,lengthバイトだけデータをコピーする - * - * @param data コピー元のCobolDataStorage - * @param length コピーするバイト数 - */ - public void setBytes(CobolDataStorage data, int length) { - this.setBytes(data, length, 0, 0); - } - - /** - * 指定されたCobolDataStorageのインスタンスから,lengthバイトだけデータをコピーする - * - * @param data コピー元のCobolDataStorage - * @param length コピーするバイト数 - * @param dstIndex コピー先のthis.indexからの相対位置 - */ - public void setBytes(CobolDataStorage data, int length, int dstIndex) { - this.setBytes(data, length, dstIndex, 0); - } - - /** - * 指定されたCobolDataStorageのインスタンスから,lengthバイトだけデータをコピーする - * - * @param data コピー元のCobolDataStorage - * @param length コピーするバイト数 - * @param dstIndex TODO: 準備中 - * @param srcIndex コピー元バイト配列中の相対位置 - */ - public void setBytes(CobolDataStorage data, int length, int dstIndex, int srcIndex) { - for (int i = 0; i < length; ++i) { - this.setByte(i + dstIndex, data.getByte(i + srcIndex)); - } - } - - /** - * TODO 暫定的な実装 - * - * @param str TODO: 準備中 - */ - public void setString(String str) { - this.fillBytes((byte) 0x20, this.data.length); - try { - this.setBytes(str.getBytes("SHIFT-JIS")); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * TODO 暫定的な実装(対応未定) - * - * @param pointer TODO: 準備中 - */ - public void setPointer(int pointer) { - System.err.println("setPointer is not implemented"); - } - - /** - * TODO: 準備中 - * - * @param bytes 書き込むバイト配列 - */ - public void set(byte[] bytes) { - for (int i = 0; i < bytes.length && this.index + i < this.data.length; ++i) { - this.setByte(i, bytes[i]); - } - } - - /** - * TODO: 準備中 - * - * @param value TODO: 準備中 - */ - public void set(byte value) { - this.setByte(0, value); - } - - /** - * 2バイト整数値をこのオブジェクト時書き込む - * - * @param value 書き込む値 - */ - public void set(short value) { - ByteBuffer.wrap(this.data, this.index, 2).putShort(value); - } - - /** - * 4バイト整数値をこのオブジェクト時書き込む - * - * @param value 書き込む値 - */ - public void set(int value) { - ByteBuffer.wrap(this.data, this.index, 4).putInt(value); - } - - /** - * 8バイト整数値をこのオブジェクト時書き込む - * - * @param value 書き込む値 - */ - public void set(long value) { - ByteBuffer.wrap(this.data, this.index, 8).putLong(value); - } - - /** - * double型の値をこのオブジェクト時書き込む - * - * @param value 書き込む値 - */ - public void set(double value) { - ByteBuffer.wrap(this.data, this.index, 8).putDouble(value); - } - - /** - * TODO: 準備中 - * - * @param other TODO: 準備中 - */ - public void set(CobolDataStorage other) { - this.set(other.intValue()); - } - - /** - * コピーの開始位置を指定して、4バイト整数値を書き込む - * - * @param value TODO: 準備中 - * @param index TODO: 準備中 - */ - public void set(int value, int index) { - ByteBuffer buffer = ByteBuffer.wrap(this.data, this.index + index, 4); - buffer.putInt(value); - } - - /** - * TODO: 準備中 - * - * @param other TODO: 準備中 - * @return TODO: 準備中 - */ - public boolean isSame(CobolDataStorage other) { - return this.data == other.data && this.index == other.index; - } - - /** - * このオブジェクトの保持するバイト配列の先頭2バイトを読み込んでshort型として返す - * - * @return 読み込んだ2バイト整数値 - */ - public short shortValue() { - return ByteBuffer.wrap(this.data, this.index, Short.BYTES).getShort(); - } - - /** - * このオブジェクトの保持するバイト配列の先頭4バイトを読み込んでint型として返す - * - * @return 読み込んだ4バイト整数値 - */ - public int intValue() { - return ByteBuffer.wrap(this.data, this.index, Integer.BYTES).getInt(); - } - - /** - * このオブジェクトの保持するバイト配列の先頭4バイトを読み込んでlong型として返す - * - * @return 読み込んだ8バイト整数値 - */ - public long longValue() { - return ByteBuffer.wrap(this.data, this.index, Long.BYTES).getLong(); - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public double doubleValue() { - return ByteBuffer.wrap(this.data, this.index, Double.BYTES).getDouble(); - } - - /** - * 相対位置を加算したCobolDataStorageのインスタンスを返す - * - * @param index 相対位置に加算する値 - * @return 相対位置を加算したCobolDataStorageのインスタンス - */ - public CobolDataStorage getSubDataStorage(int index) { - return new CobolDataStorage(this.data, this.index + index); - } - - /** - * TODO: 準備中 - * - * @param index TODO: 準備中 - * @return TODO: 準備中 - */ - public CobolDataStorage getSubDataStorage(long index) { - return this.getDataStorage((int) index); - } - - private long toLong(int numOfBytes, boolean signed, boolean isBigEndian) { - ByteBuffer buffer = ByteBuffer.wrap(this.data); - buffer.order(isBigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN); - if (numOfBytes == 1) { - return buffer.get(this.index); - } else if (numOfBytes == 2) { - return buffer.getShort(this.index); - } else if (numOfBytes == 4) { - return buffer.getInt(this.index); - } else { - return buffer.getLong(this.index); - } - } - - private interface Cmpr { - int run(long a, long b); - } - - private static final Cmpr compareS = - new Cmpr() { - @Override - public int run(long a, long b) { - if (a < b) { - return -1; - } else if (a > b) { - return 1; - } else { - return 0; - } - } - }; - - private static final Cmpr compareU = - new Cmpr() { - @Override - public int run(long a, long b) { - return Long.compareUnsigned(a, b); - } - }; - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @param numOfBytes TODO: 準備中 - * @param signed TODO: 準備中 - * @param isBigEndian TODO: 準備中 - * @return TODO: 準備中 - */ - public int compareToBinary(long n, int numOfBytes, boolean signed, boolean isBigEndian) { - long val = this.toLong(numOfBytes, signed, isBigEndian); - Cmpr comparator = signed ? compareS : compareU; - return comparator.run(val, n); - } - - private void fromLong(int numOfBytes, boolean isBigEndian, long n) { - ByteBuffer buffer = ByteBuffer.wrap(this.data); - buffer.order(isBigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN); - if (numOfBytes <= 1) { - buffer.put(this.index, (byte) n); - } else if (numOfBytes <= 2) { - buffer.putShort(this.index, (short) n); - } else if (numOfBytes <= 4) { - buffer.putInt(this.index, (int) n); - } else if (numOfBytes <= 8) { - buffer.putLong(this.index, n); - } - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @param numOfBytes TODO: 準備中 - * @param signed TODO: 準備中 - * @param isBigEndian TODO: 準備中 - */ - public void addBinary(long n, int numOfBytes, boolean signed, boolean isBigEndian) { - long x = this.toLong(numOfBytes, signed, isBigEndian); - x += n; - this.fromLong(numOfBytes, isBigEndian, x); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @param numOfBytes TODO: 準備中 - * @param signed TODO: 準備中 - * @param isBigEndian TODO: 準備中 - */ - public void subBinary(long n, int numOfBytes, boolean signed, boolean isBigEndian) { - long x = this.toLong(numOfBytes, signed, isBigEndian); - x -= n; - this.fromLong(numOfBytes, isBigEndian, x); - } - - // n numofBytes signed isBigEndian - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpU8Binary(long n) { - return compareToBinary(n, 1, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpS8Binary(long n) { - return compareToBinary(n, 1, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpU16Binary(long n) { - return compareToBinary(n, 2, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpS16Binary(long n) { - return compareToBinary(n, 2, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpU24Binary(long n) { - return compareToBinary(n, 3, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpS24Binary(long n) { - return compareToBinary(n, 3, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpU32Binary(long n) { - return compareToBinary(n, 4, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpS32Binary(long n) { - return compareToBinary(n, 4, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpU40Binary(long n) { - return compareToBinary(n, 5, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpS40Binary(long n) { - return compareToBinary(n, 5, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpU48Binary(long n) { - return compareToBinary(n, 6, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpS48Binary(long n) { - return compareToBinary(n, 6, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpU56Binary(long n) { - return compareToBinary(n, 7, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpS56Binary(long n) { - return compareToBinary(n, 7, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpU64Binary(long n) { - return compareToBinary(n, 8, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpS64Binary(long n) { - return compareToBinary(n, 8, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpAlignU8Binary(long n) { - return compareToBinary(n, 1, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpAlignS8Binary(long n) { - return compareToBinary(n, 1, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpAlignU16Binary(long n) { - return compareToBinary(n, 2, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpAlignS16Binary(long n) { - return compareToBinary(n, 2, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpAlignU32Binary(long n) { - return compareToBinary(n, 4, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpAlignS32Binary(long n) { - return compareToBinary(n, 4, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpAlignU64Binary(long n) { - return compareToBinary(n, 8, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpAlignS64Binary(long n) { - return compareToBinary(n, 8, true, true); - } - - // n numofBytes signed isBigEndian - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addU8Binary(long n) { - addBinary(n, 1, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addS8Binary(long n) { - addBinary(n, 1, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addU16Binary(long n) { - addBinary(n, 2, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addS16Binary(long n) { - addBinary(n, 2, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addU24Binary(long n) { - addBinary(n, 3, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addS24Binary(long n) { - addBinary(n, 3, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addU32Binary(long n) { - addBinary(n, 4, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addS32Binary(long n) { - addBinary(n, 4, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addU40Binary(long n) { - addBinary(n, 5, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addS40Binary(long n) { - addBinary(n, 5, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addU48Binary(long n) { - addBinary(n, 6, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addS48Binary(long n) { - addBinary(n, 6, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addU56Binary(long n) { - addBinary(n, 7, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addS56Binary(long n) { - addBinary(n, 7, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addU64Binary(long n) { - addBinary(n, 8, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addS64Binary(long n) { - addBinary(n, 8, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addAlignU8Binary(long n) { - addBinary(n, 1, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addAlignS8Binary(long n) { - addBinary(n, 1, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addAlignU16Binary(long n) { - addBinary(n, 2, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addAlignS16Binary(long n) { - addBinary(n, 2, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addAlignU32Binary(long n) { - addBinary(n, 4, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addAlignS32Binary(long n) { - addBinary(n, 4, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addAlignU64Binary(long n) { - addBinary(n, 8, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addAlignS64Binary(long n) { - addBinary(n, 8, true, true); - } - - // n numofBytes signed isBigEndian - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subU8Binary(long n) { - subBinary(n, 1, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subS8Binary(long n) { - subBinary(n, 1, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subU16Binary(long n) { - subBinary(n, 2, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subS16Binary(long n) { - subBinary(n, 2, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subU24Binary(long n) { - subBinary(n, 3, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subS24Binary(long n) { - subBinary(n, 3, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subU32Binary(long n) { - subBinary(n, 4, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subS32Binary(long n) { - subBinary(n, 4, true, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subU40Binary(long n) { - subBinary(n, 5, false, true); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subS40Binary(long n) { - subBinary(n, 5, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subU48Binary(long n) { - subBinary(n, 6, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subS48Binary(long n) { - subBinary(n, 6, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subU56Binary(long n) { - subBinary(n, 7, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subS56Binary(long n) { - subBinary(n, 7, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subU64Binary(long n) { - subBinary(n, 8, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subS64Binary(long n) { - subBinary(n, 8, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subAlignU8Binary(long n) { - subBinary(n, 1, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subAlignS8Binary(long n) { - subBinary(n, 1, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subAlignU16Binary(long n) { - subBinary(n, 2, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subAlignS16Binary(long n) { - subBinary(n, 2, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subAlignU32Binary(long n) { - subBinary(n, 4, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subAlignS32Binary(long n) { - subBinary(n, 4, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subAlignU64Binary(long n) { - subBinary(n, 8, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subAlignS64Binary(long n) { - subBinary(n, 8, true, true); - } - - // n numofBytes signed isBigEndian - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSwpU8Binary(long n) { - return compareToBinary(n, 1, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSwpS8Binary(long n) { - return compareToBinary(n, 1, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSwpU16Binary(long n) { - return compareToBinary(n, 2, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSwpS16Binary(long n) { - return compareToBinary(n, 2, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSwpU24Binary(long n) { - return compareToBinary(n, 3, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSwpS24Binary(long n) { - return compareToBinary(n, 3, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSwpU32Binary(long n) { - return compareToBinary(n, 4, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSwpS32Binary(long n) { - return compareToBinary(n, 4, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSwpU40Binary(long n) { - return compareToBinary(n, 5, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSwpS40Binary(long n) { - return compareToBinary(n, 5, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSwpU48Binary(long n) { - return compareToBinary(n, 6, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSwpS48Binary(long n) { - return compareToBinary(n, 6, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSwpU56Binary(long n) { - return compareToBinary(n, 7, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSwpS56Binary(long n) { - return compareToBinary(n, 7, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSwpU64Binary(long n) { - return compareToBinary(n, 8, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSwpS64Binary(long n) { - return compareToBinary(n, 8, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSwpAlignU8Binary(long n) { - return compareToBinary(n, 1, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSwpAlignS8Binary(long n) { - return compareToBinary(n, 1, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSwpAlignU16Binary(long n) { - return compareToBinary(n, 2, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSwpAlignS16Binary(long n) { - return compareToBinary(n, 2, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSwpAlignU32Binary(long n) { - return compareToBinary(n, 4, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSwpAlignS32Binary(long n) { - return compareToBinary(n, 4, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSwpAlignU64Binary(long n) { - return compareToBinary(n, 8, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSwpAlignS64Binary(long n) { - return compareToBinary(n, 8, true, true); - } - - // n numofBytes signed isBigEndian - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addSwpU8Binary(long n) { - addBinary(n, 1, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addSwpS8Binary(long n) { - addBinary(n, 1, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addSwpU16Binary(long n) { - addBinary(n, 2, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addSwpS16Binary(long n) { - addBinary(n, 2, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addSwpU24Binary(long n) { - addBinary(n, 3, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addSwpS24Binary(long n) { - addBinary(n, 3, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addSwpU32Binary(long n) { - addBinary(n, 4, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addSwpS32Binary(long n) { - addBinary(n, 4, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addSwpU40Binary(long n) { - addBinary(n, 5, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addSwpS40Binary(long n) { - addBinary(n, 5, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addSwpU48Binary(long n) { - addBinary(n, 6, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addSwpS48Binary(long n) { - addBinary(n, 6, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addSwpU56Binary(long n) { - addBinary(n, 7, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addSwpS56Binary(long n) { - addBinary(n, 7, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addSwpU64Binary(long n) { - addBinary(n, 8, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addSwpS64Binary(long n) { - addBinary(n, 8, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addSwpAlignU8Binary(long n) { - addBinary(n, 1, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addSwpAlignS8Binary(long n) { - addBinary(n, 1, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addSwpAlignU16Binary(long n) { - addBinary(n, 2, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addSwpAlignS16Binary(long n) { - addBinary(n, 2, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addSwpAlignU32Binary(long n) { - addBinary(n, 4, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addSwpAlignS32Binary(long n) { - addBinary(n, 4, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addSwpAlignU64Binary(long n) { - addBinary(n, 8, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void addSwpAlignS64Binary(long n) { - addBinary(n, 8, true, true); - } - - // n numofBytes signed isBigEndian - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subSwpU8Binary(int n) { - subBinary(n, 1, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subSwpS8Binary(int n) { - subBinary(n, 1, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subSwpU16Binary(int n) { - subBinary(n, 2, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subSwpS16Binary(int n) { - subBinary(n, 2, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subSwpU24Binary(int n) { - subBinary(n, 3, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subSwpS24Binary(int n) { - subBinary(n, 3, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subSwpU32Binary(int n) { - subBinary(n, 4, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subSwpS32Binary(int n) { - subBinary(n, 4, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subSwpU40Binary(int n) { - subBinary(n, 5, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subSwpS40Binary(int n) { - subBinary(n, 5, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subSwpU48Binary(int n) { - subBinary(n, 6, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subSwpS48Binary(int n) { - subBinary(n, 6, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subSwpU56Binary(int n) { - subBinary(n, 7, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subSwpS56Binary(int n) { - subBinary(n, 7, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subSwpU64Binary(int n) { - subBinary(n, 8, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subSwpS64Binary(int n) { - subBinary(n, 8, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subSwpAlignU8Binary(int n) { - subBinary(n, 1, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subSwpAlignS8Binary(int n) { - subBinary(n, 1, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subSwpAlignU16Binary(int n) { - subBinary(n, 2, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subSwpAlignS16Binary(int n) { - subBinary(n, 2, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subSwpAlignU32Binary(int n) { - subBinary(n, 4, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subSwpAlignS32Binary(int n) { - subBinary(n, 4, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subSwpAlignU64Binary(int n) { - subBinary(n, 8, false, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void subSwpAlignS64Binary(int n) { - subBinary(n, 8, true, true); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void setSwpU16Binary(int n) { - this.fromLong(2, true, n); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void setSwpS16Binary(int n) { - this.fromLong(2, true, n); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void setSwpU24Binary(int n) { - this.fromLong(3, true, n); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void setSwpS24Binary(int n) { - this.fromLong(3, true, n); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void setSwpU32Binary(int n) { - this.fromLong(4, true, n); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void setSwpS32Binary(int n) { - this.fromLong(4, true, n); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void setSwpU40Binary(int n) { - this.fromLong(5, true, n); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void setSwpS40Binary(int n) { - this.fromLong(5, true, n); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void setSwpU48Binary(int n) { - this.fromLong(6, true, n); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void setSwpS48Binary(int n) { - this.fromLong(6, true, n); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void setSwpU56Binary(int n) { - this.fromLong(7, true, n); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void setSwpS56Binary(int n) { - this.fromLong(7, true, n); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void setSwpU64Binary(int n) { - this.fromLong(8, true, n); - } - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void setSwpS64Binary(int n) { - this.fromLong(8, true, n); - } - - // libcob/numeric.cのcob_cmp_numdispの実装 - /** - * TODO: 準備中 - * - * @param size TODO: 準備中 - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpNumdisp(int size, long n) { - int p = 0; - int val = 0; - for (int inc = 0; inc < size; ++inc, ++p) { - val = (val * 10) + (this.getByte(p) - '0'); - } - return (val < n) ? -1 : (val > n) ? 1 : 0; - } - - // libcob/numeric.cのcob_cmp_long_numdispの実装 - /** - * TODO: 準備中 - * - * @param size TODO: 準備中 - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpLongNumdisp(int size, long n) { - return this.cmpNumdisp(size, n); - } - - /** - * TODO: 準備中 - * - * @param size TODO: 準備中 - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpSignNumdisp(int size, long n) { - int p = 0; - int val = 0; - for (int inc = 0; inc < size - 1; ++inc, ++p) { - val = (val * 10) + (this.getByte(p) - '0'); - } - val *= 10; - if (this.getByte(p) >= '0' && this.getByte(p) <= '9') { - val += (this.getByte(p) - '0'); - } else { - if (CobolModule.getCurrentModule().display_sign != 0) { - PairInt pair = this.getLongEbcdicSign(p, val); - val = pair.first; - if (pair.last != 0) { - val = -val; - } - } else { - val += (this.getByte(p) - 'p'); - val = -val; - } - } - return (val < n) ? -1 : (val > n) ? 1 : 0; - } - - /** - * TODO: 準備中 - * - * @param size TODO: 準備中 - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - public int cmpLongSignNumdisp(int size, long n) { - int p = 0; - int val = 0; - for (int inc = 0; inc < size - 1; ++inc, ++p) { - val = (val * 10) + (this.getByte(p) - '0'); - } - val *= 10; - if (this.getByte(p) >= '0' && this.getByte(p) <= '9') { - val += (this.getByte(p) - '0'); - } else { - if (CobolModule.getCurrentModule().display_sign != 0) { - PairInt pair = this.getLongEbcdicSign(p, val); - val = pair.first; - if (pair.last != 0) { - val = -val; - } - } else { - val += (this.getByte(p) - ('0' + 0x40)); - val = -val; - } - } - return (val < n) ? -1 : (val > n) ? 1 : 0; - } - - /** - * TODO: 準備中 - * - * @param size TODO: 準備中 - * @return TODO: 準備中 - */ - public int getNumdisp(int size) { - int retval = 0; - for (int n = 0; n < size; ++n) { - retval *= 10; - byte b = this.getByte(n); - if (b > '9') { - retval += 10; - } else { - retval += b - '0'; - } - } - return retval; - } - - private static class PairInt { - public int first; - public int last; - - public PairInt(int a, int b) { - first = a; - last = b; - } - } - - /** - * TODO: 準備中 - * - * @param p TODO: 準備中 - * @param val TODO: 準備中 - * @return TODO: 準備中 - */ - public PairInt getEbcdicSign(int p, int val) { - switch (this.getByte(p)) { - case '{': - return new PairInt(val, 0); - case 'A': - return new PairInt(val + 1, 0); - case 'B': - return new PairInt(val + 2, 0); - case 'C': - return new PairInt(val + 3, 0); - case 'D': - return new PairInt(val + 4, 0); - case 'E': - return new PairInt(val + 5, 0); - case 'F': - return new PairInt(val + 6, 0); - case 'G': - return new PairInt(val + 7, 0); - case 'H': - return new PairInt(val + 8, 0); - case 'I': - return new PairInt(val + 9, 0); - case '}': - return new PairInt(val, 1); - case 'J': - return new PairInt(val + 1, 1); - case 'K': - return new PairInt(val + 2, 1); - case 'L': - return new PairInt(val + 3, 1); - case 'M': - return new PairInt(val + 4, 1); - case 'N': - return new PairInt(val + 5, 1); - case 'O': - return new PairInt(val + 6, 1); - case 'P': - return new PairInt(val + 7, 1); - case 'Q': - return new PairInt(val + 8, 1); - case 'R': - return new PairInt(val + 9, 1); - default: - return new PairInt(val, 0); - } - } - - /** - * TODO: 準備中 - * - * @param p TODO: 準備中 - * @param val TODO: 準備中 - * @return TODO: 準備中 - */ - public PairInt getLongEbcdicSign(int p, int val) { - switch (this.getByte(p)) { - case '{': - return new PairInt(val, 0); - case 'A': - return new PairInt(val + 1, 0); - case 'B': - return new PairInt(val + 2, 0); - case 'C': - return new PairInt(val + 3, 0); - case 'D': - return new PairInt(val + 4, 0); - case 'E': - return new PairInt(val + 5, 0); - case 'F': - return new PairInt(val + 6, 0); - case 'G': - return new PairInt(val + 7, 0); - case 'H': - return new PairInt(val + 8, 0); - case 'I': - return new PairInt(val + 9, 0); - case '}': - return new PairInt(val, 1); - case 'J': - return new PairInt(val + 1, 1); - case 'K': - return new PairInt(val + 2, 1); - case 'L': - return new PairInt(val + 3, 1); - case 'M': - return new PairInt(val + 4, 1); - case 'N': - return new PairInt(val + 5, 1); - case 'O': - return new PairInt(val + 6, 1); - case 'P': - return new PairInt(val + 7, 1); - case 'Q': - return new PairInt(val + 8, 1); - case 'R': - return new PairInt(val + 9, 1); - default: - return new PairInt(val, 0); - } - } - - // TODO 修正 - // opensource COBOLにはない実装 COB_BSWAP_32などの代替 - // 本家opensource COBOLのcobc/codegen.cの894行目付近を参照 - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public long bswap_16() { - return this.toLong(2, true, true); - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public long bswap_32() { - return this.toLong(4, true, true); - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public long bswap_64() { - return this.toLong(8, true, true); - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.data; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import jp.osscons.opensourcecobol.libcobj.common.CobolModule; + +/** + * COBOL変数のデータを保存するバイト配列を扱うクラス
+ * byte[]型のデータと、その配列中での相対位置を保持し、データの読み書きを行う + */ +public class CobolDataStorage { + + /** データを保存するバイト配列 */ + private byte[] data; + + /** このクラスの扱うデータが保存する領域のバイト配列中での相対位置 */ + private int index; + + /** + * 引数で指定された長さ分のバイト配列を確保する.相対位置は0にする. + * + * @param size バイト配列の長さ + */ + public CobolDataStorage(int size) { + this.data = new byte[size]; + this.index = 0; + } + + /** + * バイト配列と相対位置を指定する + * + * @param data データを保存するバイト配列 + * @param index バイト配列中の相対位置 + */ + public CobolDataStorage(byte[] data, int index) { + this.data = data; + this.index = index; + } + + /** + * データを保存するバイト配列を引数で指定する.相対位置は0にする. + * + * @param data データを保存するバイト配列 + */ + public CobolDataStorage(byte[] data) { + this(data, 0); + } + + /** + * TODO: 準備中 + * + * @param bytes TODO: 準備中 + * @return TODO: 準備中 + */ + public static CobolDataStorage makeCobolDataStorage(byte... bytes) { + return new CobolDataStorage(bytes); + } + + /** TODO: 準備中 */ + public CobolDataStorage() { + this.index = 0; + this.data = null; + } + + /** + * TODO: 準備中 + * + * @param data TODO: 準備中 + * @param index TODO: 準備中 + */ + public void setDataRefAndIndex(CobolDataStorage data, int index) { + this.data = data.data; + this.index = index; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public int getIndex() { + return this.index; + } + + /** + * TODO: 準備中 + * + * @param index TODO: 準備中 + */ + public void setIndex(int index) { + this.index = index; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public byte[] getRefOfData() { + return this.data; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public CobolDataStorage copy() { + CobolDataStorage ret = new CobolDataStorage(); + ret.index = this.index; + ret.data = this.data; + return ret; + } + + /** + * TODO: 準備中 + * + * @param size TODO: 準備中 + * @return TODO: 準備中 + */ + public ByteBuffer getByteBuffer(int size) { + return ByteBuffer.wrap(this.data, this.index, size); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addIndex(int n) { + this.index += n; + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public static CobolDataStorage primitiveToDataStorage(int n) { + byte[] bytes = new byte[4]; + ByteBuffer buffer = ByteBuffer.wrap(bytes); + buffer.putInt(n); + return new CobolDataStorage(bytes); + } + + /** + * TODO: 準備中 + * + * @param s TODO: 準備中 + * @return TODO: 準備中 + */ + public static CobolDataStorage primitiveToDataStorage(String s) { + return new CobolDataStorage(s); + } + + /** + * TODO: 準備中 + * + * @param str TODO: 準備中 + */ + public CobolDataStorage(String str) { + try { + byte[] bytes = str.getBytes(AbstractCobolField.charSetSJIS); + this.data = bytes; + this.index = 0; + } catch (Exception e) { + e.printStackTrace(); + this.data = new byte[0]; + this.index = 0; + } + } + + /** + * 保持するバイト配列のコピーを返す + * + * @return TODO: 準備中 + */ + public byte[] getData() { + return this.getData(0); + } + + /** + * 引数で指定した開始位置から末尾までをコピーした配列を返す。 + * + * @param index このオブジェクトの保持する相対位置を基準とした、コピーの開始位置 + * @return 開始位置から末尾までのデータをコピーしたバイト配列 + */ + public byte[] getData(int index) { + byte[] result = new byte[this.data.length - this.index - index]; + + System.arraycopy(this.data, this.index + index, result, 0, result.length); + + return result; + } + + /** + * 引数で指定した相対位置から指定した長さをコピーした配列を返す。 + * + * @param index このオブジェクトの保持する相対位置を基準とした、コピーの開始位置 + * @param length コピーする長さ(バイト数) + * @return 開始位置からlengthバイト分の配列 + */ + public byte[] getByteArray(int index, int length) { + byte[] result = new byte[length]; + System.arraycopy(this.data, this.index + index, result, 0, length); + return result; + } + + /** + * TODO: 準備中 + * + * @param index TODO: 準備中 + * @param length TODO: 準備中 + * @return TODO: 準備中 + */ + public byte[] getByteArrayRef(int index, int length) { + ByteBuffer buffer = ByteBuffer.wrap(this.data, this.index + index, length); + return buffer.array(); + } + + /** + * C言語のmemcpyに相当するメソッド + * + * @param buf TODO: 準備中 + * @param size TODO: 準備中 + */ + public void memcpy(CobolDataStorage buf, int size) { + for (int i = 0; i < size; ++i) { + this.setByte(i, buf.getByte(i)); + } + } + + /** + * C言語のmemcpyに相当するメソッド + * + * @param buf TODO: 準備中 + * @param size TODO: 準備中 + */ + public void memcpy(byte[] buf, int size) { + for (int i = 0; i < size; ++i) { + this.setByte(i, buf[i]); + } + } + + /** + * C言語のmemcpyに相当するメソッド + * + * @param str TODO: 準備中 + * @param size TODO: 準備中 + */ + public void memcpy(String str, int size) { + this.memcpy(str.getBytes(AbstractCobolField.charSetSJIS), size); + } + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param buf TODO: 準備中 + * @param size TODO: 準備中 + */ + public void memcpy(int offset, byte[] buf, int size) { + for (int i = 0; i < size; ++i) { + this.setByte(offset + i, buf[i]); + } + } + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param buf TODO: 準備中 + * @param size TODO: 準備中 + */ + public void memcpy(int offset, CobolDataStorage buf, int size) { + for (int i = 0; i < size; ++i) { + this.setByte(offset + i, buf.getByte(i)); + } + } + + /** + * TODO: 準備中 + * + * @param buf TODO: 準備中 + * @param offset TODO: 準備中 + * @param size TODO: 準備中 + */ + public void memcpy(byte[] buf, int offset, int size) { + System.arraycopy(buf, offset, this.data, this.index, size); + } + + /** + * TODO: 準備中 + * + * @param buf TODO: 準備中 + */ + public void memcpy(byte[] buf) { + this.memcpy(buf, buf.length); + } + + /** + * C言語のmemsetに相当するメソッド + * + * @param ch TODO: 準備中 + * @param size TODO: 準備中 + */ + public void memset(byte ch, int size) { + for (int i = 0; i < size; ++i) { + this.setByte(i, ch); + } + } + + /** + * C言語のmemsetに相当するメソッド + * + * @param ch TODO: 準備中 + * @param size TODO: 準備中 + */ + public void memset(int ch, int size) { + this.memset((byte) ch, size); + } + + /** + * C言語のmemsetに相当するメソッド + * + * @param offset TODO: 準備中 + * @param ch TODO: 準備中 + * @param size TODO: 準備中 + */ + public void memset(int offset, byte ch, int size) { + for (int i = 0; i < size; ++i) { + this.setByte(offset + i, ch); + } + } + + /** + * C言語のmemsetに相当するメソッド + * + * @param offset TODO: 準備中 + * @param ch TODO: 準備中 + * @param size TODO: 準備中 + */ + public void memset(int offset, int ch, int size) { + this.memset(offset, (byte) ch, size); + } + + /** + * C言語のmemcmpに相当するメソッド + * + * @param buf TODO: 準備中 + * @param size TODO: 準備中 + * @return TODO: 準備中 + */ + public int memcmp(byte[] buf, int size) { + for (int i = 0; i < size; ++i) { + if (this.getByte(i) != buf[i]) { + int x = Byte.toUnsignedInt(this.getByte(i)); + int y = Byte.toUnsignedInt(buf[i]); + return x - y; + } + } + return 0; + } + + /** + * C言語のmemcmpに相当するメソッド + * + * @param buf TODO: 準備中 + * @param size TODO: 準備中 + * @return TODO: 準備中 + */ + public int memcmp(String buf, int size) { + return this.memcmp(buf.getBytes(AbstractCobolField.charSetSJIS), size); + } + + /** + * C言語のmemcmpに相当するメソッド + * + * @param buf TODO: 準備中 + * @param size TODO: 準備中 + * @return TODO: 準備中 + */ + public int memcmp(CobolDataStorage buf, int size) { + for (int i = 0; i < size; ++i) { + if (this.getByte(i) != buf.getByte(i)) { + int x = Byte.toUnsignedInt(this.getByte(i)); + int y = Byte.toUnsignedInt(buf.getByte(i)); + return x - y; + } + } + return 0; + } + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param buf TODO: 準備中 + * @param size TODO: 準備中 + * @return TODO: 準備中 + */ + public int memcmp(int offset, CobolDataStorage buf, int size) { + for (int i = 0; i < size; ++i) { + byte x = this.getByte(offset + i); + byte y = buf.getByte(i); + if (x != y) { + return Byte.toUnsignedInt(x) - Byte.toUnsignedInt(y); + } + } + return 0; + } + + /** + * 引数で与えられたバイト配列に保持したデータをこのオブジェクトに書き込む + * + * @param data TODO: 準備中 + */ + public void setData(byte[] data) { + setData(data, 0); + } + + /** + * 引数で与えられたバイト配列に保持したデータをこのオブジェクトに書き込む + * + * @param data コピー元のバイト配列 + * @param index コピー先のバイト配列中での開始位置 + */ + public void setData(byte[] data, int index) { + int length = + (data.length <= this.data.length - this.index - index) + ? data.length + : this.data.length - this.index - index; + + System.arraycopy(data, 0, this.data, this.index + index, length); + } + + /** + * 引数で指定された分だけ相対位置を変位させたCobolDataStorageクラスのインスタンスを作成する + * + * @param index 変位させるバイト数 + * @return 新たに作成したCobolDataStorageクラスのインスタンス + */ + public CobolDataStorage getDataStorage(int index) { + return new CobolDataStorage(this.data, this.index + index); + } + + /** + * 指定のバイト配列中での位置に指定の値を代入する + * + * @param index 代入先のバイト配列中の位置 + * @param value 代入する値 + */ + public void setByte(int index, byte value) { + this.data[this.index + index] = value; + } + + /** + * 指定のバイト配列中での位置に指定の値を代入する + * + * @param index 代入先のバイト配列中の位置 + * @param value 代入する値 + */ + public void setByte(int index, int value) { + this.setByte(index, (byte) value); + } + + /** + * 指定のバイト配列中での位置に指定の値を代入する + * + * @param index 代入先のバイト配列中の位置. + * @param value 代入する値 + */ + public void setByte(int index, char value) { + this.setByte(index, (byte) value); + } + + /** + * TODO: 準備中 + * + * @param value TODO: 準備中 + */ + public void setByte(byte value) { + this.setByte(0, value); + } + + /** + * TODO: 準備中 + * + * @param value TODO: 準備中 + */ + public void setByte(int value) { + this.setByte((byte) value); + } + + /** + * TODO: 準備中 + * + * @param value TODO: 準備中 + */ + public void setByte(char value) { + this.setByte((byte) value); + } + + /** + * 指定のバイト配列中での位置に格納された値を返す + * + * @param index バイト配列中での位置. + * @return 指定のバイト配列中での位置に格納された値 + */ + public byte getByte(int index) { + return this.data[this.index + index]; + } + + /** + * バイト配列のthis.indexバイト目からsizeバイトの範囲にvalueを代入する + * + * @param value 代入する値 + * @param size 代入先のバイト数 + */ + public void fillBytes(byte value, int size) { + fillBytes(0, value, size); + } + + /** + * バイト配列のthis.indexバイト目からsizeバイトの範囲にvalueを代入する + * + * @param value 代入する値 + * @param size 代入先のバイト数 + */ + public void fillBytes(int value, int size) { + fillBytes(0, value, size); + } + + /** + * バイト配列のthis.indexバイト目からsizeバイトの範囲にvalueを代入する + * + * @param value 代入する値 + * @param size 代入先のバイト数 + */ + public void fillBytes(char value, int size) { + fillBytes(0, value, size); + } + + /** + * バイト配列の0バイト目からsizeバイトの範囲にvalueを代入する + * + * @param index コピーの開始位置 + * @param value 代入する値 + * @param size 代入先のバイト数 + */ + public void fillBytes(int index, byte value, int size) { + for (int i = 0; i < size; ++i) { + this.setByte(i + index, value); + } + } + + /** + * バイト配列の0バイト目からsizeバイトの範囲にvalueを代入する + * + * @param index コピーの開始位置 + * @param value 代入する値 + * @param size 代入先のバイト数 + */ + public void fillBytes(int index, int value, int size) { + this.fillBytes(index, (byte) value, size); + } + + /** + * バイト配列の0バイト目からsizeバイトの範囲にvalueを代入する + * + * @param index コピーの開始位置 + * @param value 代入する値 + * @param size 代入先のバイト数 + */ + public void fillBytes(int index, char value, int size) { + this.fillBytes(index, (byte) value, size); + } + + /** + * TODO: 準備中 + * + * @param bytes コピー元のバイト配列 + */ + public void setBytes(byte[] bytes) { + for (int i = 0; i < bytes.length; ++i) { + this.setByte(i, bytes[i]); + } + } + + /** + * TODO: 準備中 + * + * @param bytes コピー元のバイト配列 + * @param length コピーする最大バイト数 + */ + public void setByByteArrayAndPaddingSpaces(byte[] bytes, int length) { + int copyLength = Math.min(bytes.length, length); + int i; + for (i = 0; i < copyLength; ++i) { + this.setByte(i, bytes[i]); + } + for (; i < length; ++i) { + this.setByte(i, (byte) ' '); + } + } + + /** + * TODO: 準備中 + * + * @param bytes コピー元の配列 + * @param length コピーするバイト数 + */ + public void setBytes(byte[] bytes, int length) { + for (int i = 0; i < length; ++i) { + this.setByte(i, bytes[i]); + } + } + + /** + * 指定のバイト配列に格納された値を this.dataのthis.indexバイト目以降へlengthバイトだけコピーする. + * + * @param index コピー先のthis.indexからの相対位置 + * @param bytes コピー元の配列 + * @param length コピーするバイト数 + */ + public void setBytes(int index, byte[] bytes, int length) { + for (int i = 0; i < length; ++i) { + this.setByte(i + index, bytes[i]); + } + } + + /** + * 指定した文字列をバイト配列にコピーする + * + * @param str コピー元の文字列 + * @param length コピーするバイト数 + */ + public void setBytes(String str, int length) { + try { + this.setBytes(str.getBytes(AbstractCobolField.charSetSJIS), length); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 指定されたCobolDataStorageのインスタンスから,lengthバイトだけデータをコピーする + * + * @param data コピー元のCobolDataStorage + * @param length コピーするバイト数 + */ + public void setBytes(CobolDataStorage data, int length) { + this.setBytes(data, length, 0, 0); + } + + /** + * 指定されたCobolDataStorageのインスタンスから,lengthバイトだけデータをコピーする + * + * @param data コピー元のCobolDataStorage + * @param length コピーするバイト数 + * @param dstIndex コピー先のthis.indexからの相対位置 + */ + public void setBytes(CobolDataStorage data, int length, int dstIndex) { + this.setBytes(data, length, dstIndex, 0); + } + + /** + * 指定されたCobolDataStorageのインスタンスから,lengthバイトだけデータをコピーする + * + * @param data コピー元のCobolDataStorage + * @param length コピーするバイト数 + * @param dstIndex TODO: 準備中 + * @param srcIndex コピー元バイト配列中の相対位置 + */ + public void setBytes(CobolDataStorage data, int length, int dstIndex, int srcIndex) { + for (int i = 0; i < length; ++i) { + this.setByte(i + dstIndex, data.getByte(i + srcIndex)); + } + } + + /** + * TODO 暫定的な実装 + * + * @param str TODO: 準備中 + */ + public void setString(String str) { + this.fillBytes((byte) 0x20, this.data.length); + try { + this.setBytes(str.getBytes(AbstractCobolField.charSetSJIS)); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * TODO 暫定的な実装(対応未定) + * + * @param pointer TODO: 準備中 + */ + public void setPointer(int pointer) { + System.err.println("setPointer is not implemented"); + } + + /** + * TODO: 準備中 + * + * @param bytes 書き込むバイト配列 + */ + public void set(byte[] bytes) { + for (int i = 0; i < bytes.length && this.index + i < this.data.length; ++i) { + this.setByte(i, bytes[i]); + } + } + + /** + * TODO: 準備中 + * + * @param value TODO: 準備中 + */ + public void set(byte value) { + this.setByte(0, value); + } + + /** + * 2バイト整数値をこのオブジェクト時書き込む + * + * @param value 書き込む値 + */ + public void set(short value) { + ByteBuffer.wrap(this.data, this.index, 2).putShort(value); + } + + /** + * 4バイト整数値をこのオブジェクト時書き込む + * + * @param value 書き込む値 + */ + public void set(int value) { + ByteBuffer.wrap(this.data, this.index, 4).putInt(value); + } + + /** + * 8バイト整数値をこのオブジェクト時書き込む + * + * @param value 書き込む値 + */ + public void set(long value) { + ByteBuffer.wrap(this.data, this.index, 8).putLong(value); + } + + /** + * double型の値をこのオブジェクト時書き込む + * + * @param value 書き込む値 + */ + public void set(double value) { + ByteBuffer.wrap(this.data, this.index, 8).putDouble(value); + } + + /** + * TODO: 準備中 + * + * @param other TODO: 準備中 + */ + public void set(CobolDataStorage other) { + this.set(other.intValue()); + } + + /** + * コピーの開始位置を指定して、4バイト整数値を書き込む + * + * @param value TODO: 準備中 + * @param index TODO: 準備中 + */ + public void set(int value, int index) { + ByteBuffer buffer = ByteBuffer.wrap(this.data, this.index + index, 4); + buffer.putInt(value); + } + + /** + * TODO: 準備中 + * + * @param other TODO: 準備中 + * @return TODO: 準備中 + */ + public boolean isSame(CobolDataStorage other) { + return this.data == other.data && this.index == other.index; + } + + /** + * このオブジェクトの保持するバイト配列の先頭2バイトを読み込んでshort型として返す + * + * @return 読み込んだ2バイト整数値 + */ + public short shortValue() { + return ByteBuffer.wrap(this.data, this.index, Short.BYTES).getShort(); + } + + /** + * このオブジェクトの保持するバイト配列の先頭4バイトを読み込んでint型として返す + * + * @return 読み込んだ4バイト整数値 + */ + public int intValue() { + return ByteBuffer.wrap(this.data, this.index, Integer.BYTES).getInt(); + } + + /** + * このオブジェクトの保持するバイト配列の先頭4バイトを読み込んでlong型として返す + * + * @return 読み込んだ8バイト整数値 + */ + public long longValue() { + return ByteBuffer.wrap(this.data, this.index, Long.BYTES).getLong(); + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public double doubleValue() { + return ByteBuffer.wrap(this.data, this.index, Double.BYTES).getDouble(); + } + + /** + * 相対位置を加算したCobolDataStorageのインスタンスを返す + * + * @param index 相対位置に加算する値 + * @return 相対位置を加算したCobolDataStorageのインスタンス + */ + public CobolDataStorage getSubDataStorage(int index) { + return new CobolDataStorage(this.data, this.index + index); + } + + /** + * TODO: 準備中 + * + * @param index TODO: 準備中 + * @return TODO: 準備中 + */ + public CobolDataStorage getSubDataStorage(long index) { + return this.getDataStorage((int) index); + } + + private long toLong(int numOfBytes, boolean signed, boolean isBigEndian) { + ByteBuffer buffer = ByteBuffer.wrap(this.data); + buffer.order(isBigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN); + if (numOfBytes == 1) { + return buffer.get(this.index); + } else if (numOfBytes == 2) { + return buffer.getShort(this.index); + } else if (numOfBytes == 4) { + return buffer.getInt(this.index); + } else { + return buffer.getLong(this.index); + } + } + + private interface Cmpr { + int run(long a, long b); + } + + private static final Cmpr compareS = + new Cmpr() { + @Override + public int run(long a, long b) { + if (a < b) { + return -1; + } else if (a > b) { + return 1; + } else { + return 0; + } + } + }; + + private static final Cmpr compareU = + new Cmpr() { + @Override + public int run(long a, long b) { + return Long.compareUnsigned(a, b); + } + }; + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @param numOfBytes TODO: 準備中 + * @param signed TODO: 準備中 + * @param isBigEndian TODO: 準備中 + * @return TODO: 準備中 + */ + public int compareToBinary(long n, int numOfBytes, boolean signed, boolean isBigEndian) { + long val = this.toLong(numOfBytes, signed, isBigEndian); + Cmpr comparator = signed ? compareS : compareU; + return comparator.run(val, n); + } + + private void fromLong(int numOfBytes, boolean isBigEndian, long n) { + ByteBuffer buffer = ByteBuffer.wrap(this.data); + buffer.order(isBigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN); + if (numOfBytes <= 1) { + buffer.put(this.index, (byte) n); + } else if (numOfBytes <= 2) { + buffer.putShort(this.index, (short) n); + } else if (numOfBytes <= 4) { + buffer.putInt(this.index, (int) n); + } else if (numOfBytes <= 8) { + buffer.putLong(this.index, n); + } + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @param numOfBytes TODO: 準備中 + * @param signed TODO: 準備中 + * @param isBigEndian TODO: 準備中 + */ + public void addBinary(long n, int numOfBytes, boolean signed, boolean isBigEndian) { + long x = this.toLong(numOfBytes, signed, isBigEndian); + x += n; + this.fromLong(numOfBytes, isBigEndian, x); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @param numOfBytes TODO: 準備中 + * @param signed TODO: 準備中 + * @param isBigEndian TODO: 準備中 + */ + public void subBinary(long n, int numOfBytes, boolean signed, boolean isBigEndian) { + long x = this.toLong(numOfBytes, signed, isBigEndian); + x -= n; + this.fromLong(numOfBytes, isBigEndian, x); + } + + // n numofBytes signed isBigEndian + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpU8Binary(long n) { + return compareToBinary(n, 1, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpS8Binary(long n) { + return compareToBinary(n, 1, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpU16Binary(long n) { + return compareToBinary(n, 2, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpS16Binary(long n) { + return compareToBinary(n, 2, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpU24Binary(long n) { + return compareToBinary(n, 3, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpS24Binary(long n) { + return compareToBinary(n, 3, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpU32Binary(long n) { + return compareToBinary(n, 4, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpS32Binary(long n) { + return compareToBinary(n, 4, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpU40Binary(long n) { + return compareToBinary(n, 5, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpS40Binary(long n) { + return compareToBinary(n, 5, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpU48Binary(long n) { + return compareToBinary(n, 6, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpS48Binary(long n) { + return compareToBinary(n, 6, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpU56Binary(long n) { + return compareToBinary(n, 7, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpS56Binary(long n) { + return compareToBinary(n, 7, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpU64Binary(long n) { + return compareToBinary(n, 8, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpS64Binary(long n) { + return compareToBinary(n, 8, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpAlignU8Binary(long n) { + return compareToBinary(n, 1, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpAlignS8Binary(long n) { + return compareToBinary(n, 1, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpAlignU16Binary(long n) { + return compareToBinary(n, 2, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpAlignS16Binary(long n) { + return compareToBinary(n, 2, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpAlignU32Binary(long n) { + return compareToBinary(n, 4, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpAlignS32Binary(long n) { + return compareToBinary(n, 4, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpAlignU64Binary(long n) { + return compareToBinary(n, 8, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpAlignS64Binary(long n) { + return compareToBinary(n, 8, true, true); + } + + // n numofBytes signed isBigEndian + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addU8Binary(long n) { + addBinary(n, 1, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addS8Binary(long n) { + addBinary(n, 1, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addU16Binary(long n) { + addBinary(n, 2, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addS16Binary(long n) { + addBinary(n, 2, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addU24Binary(long n) { + addBinary(n, 3, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addS24Binary(long n) { + addBinary(n, 3, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addU32Binary(long n) { + addBinary(n, 4, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addS32Binary(long n) { + addBinary(n, 4, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addU40Binary(long n) { + addBinary(n, 5, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addS40Binary(long n) { + addBinary(n, 5, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addU48Binary(long n) { + addBinary(n, 6, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addS48Binary(long n) { + addBinary(n, 6, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addU56Binary(long n) { + addBinary(n, 7, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addS56Binary(long n) { + addBinary(n, 7, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addU64Binary(long n) { + addBinary(n, 8, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addS64Binary(long n) { + addBinary(n, 8, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addAlignU8Binary(long n) { + addBinary(n, 1, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addAlignS8Binary(long n) { + addBinary(n, 1, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addAlignU16Binary(long n) { + addBinary(n, 2, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addAlignS16Binary(long n) { + addBinary(n, 2, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addAlignU32Binary(long n) { + addBinary(n, 4, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addAlignS32Binary(long n) { + addBinary(n, 4, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addAlignU64Binary(long n) { + addBinary(n, 8, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addAlignS64Binary(long n) { + addBinary(n, 8, true, true); + } + + // n numofBytes signed isBigEndian + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subU8Binary(long n) { + subBinary(n, 1, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subS8Binary(long n) { + subBinary(n, 1, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subU16Binary(long n) { + subBinary(n, 2, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subS16Binary(long n) { + subBinary(n, 2, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subU24Binary(long n) { + subBinary(n, 3, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subS24Binary(long n) { + subBinary(n, 3, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subU32Binary(long n) { + subBinary(n, 4, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subS32Binary(long n) { + subBinary(n, 4, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subU40Binary(long n) { + subBinary(n, 5, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subS40Binary(long n) { + subBinary(n, 5, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subU48Binary(long n) { + subBinary(n, 6, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subS48Binary(long n) { + subBinary(n, 6, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subU56Binary(long n) { + subBinary(n, 7, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subS56Binary(long n) { + subBinary(n, 7, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subU64Binary(long n) { + subBinary(n, 8, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subS64Binary(long n) { + subBinary(n, 8, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subAlignU8Binary(long n) { + subBinary(n, 1, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subAlignS8Binary(long n) { + subBinary(n, 1, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subAlignU16Binary(long n) { + subBinary(n, 2, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subAlignS16Binary(long n) { + subBinary(n, 2, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subAlignU32Binary(long n) { + subBinary(n, 4, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subAlignS32Binary(long n) { + subBinary(n, 4, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subAlignU64Binary(long n) { + subBinary(n, 8, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subAlignS64Binary(long n) { + subBinary(n, 8, true, true); + } + + // n numofBytes signed isBigEndian + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSwpU8Binary(long n) { + return compareToBinary(n, 1, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSwpS8Binary(long n) { + return compareToBinary(n, 1, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSwpU16Binary(long n) { + return compareToBinary(n, 2, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSwpS16Binary(long n) { + return compareToBinary(n, 2, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSwpU24Binary(long n) { + return compareToBinary(n, 3, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSwpS24Binary(long n) { + return compareToBinary(n, 3, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSwpU32Binary(long n) { + return compareToBinary(n, 4, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSwpS32Binary(long n) { + return compareToBinary(n, 4, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSwpU40Binary(long n) { + return compareToBinary(n, 5, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSwpS40Binary(long n) { + return compareToBinary(n, 5, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSwpU48Binary(long n) { + return compareToBinary(n, 6, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSwpS48Binary(long n) { + return compareToBinary(n, 6, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSwpU56Binary(long n) { + return compareToBinary(n, 7, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSwpS56Binary(long n) { + return compareToBinary(n, 7, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSwpU64Binary(long n) { + return compareToBinary(n, 8, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSwpS64Binary(long n) { + return compareToBinary(n, 8, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSwpAlignU8Binary(long n) { + return compareToBinary(n, 1, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSwpAlignS8Binary(long n) { + return compareToBinary(n, 1, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSwpAlignU16Binary(long n) { + return compareToBinary(n, 2, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSwpAlignS16Binary(long n) { + return compareToBinary(n, 2, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSwpAlignU32Binary(long n) { + return compareToBinary(n, 4, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSwpAlignS32Binary(long n) { + return compareToBinary(n, 4, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSwpAlignU64Binary(long n) { + return compareToBinary(n, 8, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSwpAlignS64Binary(long n) { + return compareToBinary(n, 8, true, true); + } + + // n numofBytes signed isBigEndian + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addSwpU8Binary(long n) { + addBinary(n, 1, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addSwpS8Binary(long n) { + addBinary(n, 1, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addSwpU16Binary(long n) { + addBinary(n, 2, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addSwpS16Binary(long n) { + addBinary(n, 2, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addSwpU24Binary(long n) { + addBinary(n, 3, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addSwpS24Binary(long n) { + addBinary(n, 3, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addSwpU32Binary(long n) { + addBinary(n, 4, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addSwpS32Binary(long n) { + addBinary(n, 4, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addSwpU40Binary(long n) { + addBinary(n, 5, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addSwpS40Binary(long n) { + addBinary(n, 5, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addSwpU48Binary(long n) { + addBinary(n, 6, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addSwpS48Binary(long n) { + addBinary(n, 6, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addSwpU56Binary(long n) { + addBinary(n, 7, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addSwpS56Binary(long n) { + addBinary(n, 7, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addSwpU64Binary(long n) { + addBinary(n, 8, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addSwpS64Binary(long n) { + addBinary(n, 8, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addSwpAlignU8Binary(long n) { + addBinary(n, 1, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addSwpAlignS8Binary(long n) { + addBinary(n, 1, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addSwpAlignU16Binary(long n) { + addBinary(n, 2, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addSwpAlignS16Binary(long n) { + addBinary(n, 2, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addSwpAlignU32Binary(long n) { + addBinary(n, 4, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addSwpAlignS32Binary(long n) { + addBinary(n, 4, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addSwpAlignU64Binary(long n) { + addBinary(n, 8, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void addSwpAlignS64Binary(long n) { + addBinary(n, 8, true, true); + } + + // n numofBytes signed isBigEndian + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subSwpU8Binary(int n) { + subBinary(n, 1, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subSwpS8Binary(int n) { + subBinary(n, 1, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subSwpU16Binary(int n) { + subBinary(n, 2, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subSwpS16Binary(int n) { + subBinary(n, 2, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subSwpU24Binary(int n) { + subBinary(n, 3, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subSwpS24Binary(int n) { + subBinary(n, 3, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subSwpU32Binary(int n) { + subBinary(n, 4, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subSwpS32Binary(int n) { + subBinary(n, 4, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subSwpU40Binary(int n) { + subBinary(n, 5, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subSwpS40Binary(int n) { + subBinary(n, 5, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subSwpU48Binary(int n) { + subBinary(n, 6, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subSwpS48Binary(int n) { + subBinary(n, 6, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subSwpU56Binary(int n) { + subBinary(n, 7, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subSwpS56Binary(int n) { + subBinary(n, 7, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subSwpU64Binary(int n) { + subBinary(n, 8, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subSwpS64Binary(int n) { + subBinary(n, 8, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subSwpAlignU8Binary(int n) { + subBinary(n, 1, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subSwpAlignS8Binary(int n) { + subBinary(n, 1, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subSwpAlignU16Binary(int n) { + subBinary(n, 2, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subSwpAlignS16Binary(int n) { + subBinary(n, 2, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subSwpAlignU32Binary(int n) { + subBinary(n, 4, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subSwpAlignS32Binary(int n) { + subBinary(n, 4, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subSwpAlignU64Binary(int n) { + subBinary(n, 8, false, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void subSwpAlignS64Binary(int n) { + subBinary(n, 8, true, true); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void setSwpU16Binary(int n) { + this.fromLong(2, true, n); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void setSwpS16Binary(int n) { + this.fromLong(2, true, n); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void setSwpU24Binary(int n) { + this.fromLong(3, true, n); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void setSwpS24Binary(int n) { + this.fromLong(3, true, n); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void setSwpU32Binary(int n) { + this.fromLong(4, true, n); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void setSwpS32Binary(int n) { + this.fromLong(4, true, n); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void setSwpU40Binary(int n) { + this.fromLong(5, true, n); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void setSwpS40Binary(int n) { + this.fromLong(5, true, n); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void setSwpU48Binary(int n) { + this.fromLong(6, true, n); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void setSwpS48Binary(int n) { + this.fromLong(6, true, n); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void setSwpU56Binary(int n) { + this.fromLong(7, true, n); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void setSwpS56Binary(int n) { + this.fromLong(7, true, n); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void setSwpU64Binary(int n) { + this.fromLong(8, true, n); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void setSwpS64Binary(int n) { + this.fromLong(8, true, n); + } + + // libcob/numeric.cのcob_cmp_numdispの実装 + /** + * TODO: 準備中 + * + * @param size TODO: 準備中 + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpNumdisp(int size, long n) { + int p = 0; + int val = 0; + for (int inc = 0; inc < size; ++inc, ++p) { + val = (val * 10) + (this.getByte(p) - '0'); + } + return (val < n) ? -1 : (val > n) ? 1 : 0; + } + + // libcob/numeric.cのcob_cmp_long_numdispの実装 + /** + * TODO: 準備中 + * + * @param size TODO: 準備中 + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpLongNumdisp(int size, long n) { + return this.cmpNumdisp(size, n); + } + + /** + * TODO: 準備中 + * + * @param size TODO: 準備中 + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpSignNumdisp(int size, long n) { + int p = 0; + int val = 0; + for (int inc = 0; inc < size - 1; ++inc, ++p) { + val = (val * 10) + (this.getByte(p) - '0'); + } + val *= 10; + if (this.getByte(p) >= '0' && this.getByte(p) <= '9') { + val += (this.getByte(p) - '0'); + } else { + if (CobolModule.getCurrentModule().display_sign != 0) { + PairInt pair = this.getLongEbcdicSign(p, val); + val = pair.first; + if (pair.last != 0) { + val = -val; + } + } else { + val += (this.getByte(p) - 'p'); + val = -val; + } + } + return (val < n) ? -1 : (val > n) ? 1 : 0; + } + + /** + * TODO: 準備中 + * + * @param size TODO: 準備中 + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + public int cmpLongSignNumdisp(int size, long n) { + int p = 0; + int val = 0; + for (int inc = 0; inc < size - 1; ++inc, ++p) { + val = (val * 10) + (this.getByte(p) - '0'); + } + val *= 10; + if (this.getByte(p) >= '0' && this.getByte(p) <= '9') { + val += (this.getByte(p) - '0'); + } else { + if (CobolModule.getCurrentModule().display_sign != 0) { + PairInt pair = this.getLongEbcdicSign(p, val); + val = pair.first; + if (pair.last != 0) { + val = -val; + } + } else { + val += (this.getByte(p) - ('0' + 0x40)); + val = -val; + } + } + return (val < n) ? -1 : (val > n) ? 1 : 0; + } + + /** + * TODO: 準備中 + * + * @param size TODO: 準備中 + * @return TODO: 準備中 + */ + public int getNumdisp(int size) { + int retval = 0; + for (int n = 0; n < size; ++n) { + retval *= 10; + byte b = this.getByte(n); + if (b > '9') { + retval += 10; + } else { + retval += b - '0'; + } + } + return retval; + } + + private static class PairInt { + public int first; + public int last; + + public PairInt(int a, int b) { + first = a; + last = b; + } + } + + /** + * TODO: 準備中 + * + * @param p TODO: 準備中 + * @param val TODO: 準備中 + * @return TODO: 準備中 + */ + public PairInt getEbcdicSign(int p, int val) { + switch (this.getByte(p)) { + case '{': + return new PairInt(val, 0); + case 'A': + return new PairInt(val + 1, 0); + case 'B': + return new PairInt(val + 2, 0); + case 'C': + return new PairInt(val + 3, 0); + case 'D': + return new PairInt(val + 4, 0); + case 'E': + return new PairInt(val + 5, 0); + case 'F': + return new PairInt(val + 6, 0); + case 'G': + return new PairInt(val + 7, 0); + case 'H': + return new PairInt(val + 8, 0); + case 'I': + return new PairInt(val + 9, 0); + case '}': + return new PairInt(val, 1); + case 'J': + return new PairInt(val + 1, 1); + case 'K': + return new PairInt(val + 2, 1); + case 'L': + return new PairInt(val + 3, 1); + case 'M': + return new PairInt(val + 4, 1); + case 'N': + return new PairInt(val + 5, 1); + case 'O': + return new PairInt(val + 6, 1); + case 'P': + return new PairInt(val + 7, 1); + case 'Q': + return new PairInt(val + 8, 1); + case 'R': + return new PairInt(val + 9, 1); + default: + return new PairInt(val, 0); + } + } + + /** + * TODO: 準備中 + * + * @param p TODO: 準備中 + * @param val TODO: 準備中 + * @return TODO: 準備中 + */ + public PairInt getLongEbcdicSign(int p, int val) { + switch (this.getByte(p)) { + case '{': + return new PairInt(val, 0); + case 'A': + return new PairInt(val + 1, 0); + case 'B': + return new PairInt(val + 2, 0); + case 'C': + return new PairInt(val + 3, 0); + case 'D': + return new PairInt(val + 4, 0); + case 'E': + return new PairInt(val + 5, 0); + case 'F': + return new PairInt(val + 6, 0); + case 'G': + return new PairInt(val + 7, 0); + case 'H': + return new PairInt(val + 8, 0); + case 'I': + return new PairInt(val + 9, 0); + case '}': + return new PairInt(val, 1); + case 'J': + return new PairInt(val + 1, 1); + case 'K': + return new PairInt(val + 2, 1); + case 'L': + return new PairInt(val + 3, 1); + case 'M': + return new PairInt(val + 4, 1); + case 'N': + return new PairInt(val + 5, 1); + case 'O': + return new PairInt(val + 6, 1); + case 'P': + return new PairInt(val + 7, 1); + case 'Q': + return new PairInt(val + 8, 1); + case 'R': + return new PairInt(val + 9, 1); + default: + return new PairInt(val, 0); + } + } + + // TODO 修正 + // opensource COBOLにはない実装 COB_BSWAP_32などの代替 + // 本家opensource COBOLのcobc/codegen.cの894行目付近を参照 + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public long bswap_16() { + return this.toLong(2, true, true); + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public long bswap_32() { + return this.toLong(4, true, true); + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public long bswap_64() { + return this.toLong(8, true, true); + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolDecimal.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolDecimal.java index 4504e00f..95e4be1d 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolDecimal.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolDecimal.java @@ -1,747 +1,767 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.data; - -import java.math.BigDecimal; -import java.math.RoundingMode; -import jp.osscons.opensourcecobol.libcobj.common.CobolModule; -import jp.osscons.opensourcecobol.libcobj.common.CobolUtil; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionId; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionInfo; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; - -/** - * BigDecimalを扱うクラス
- * COMPUTE等で計算をするときに使用する - */ -public class CobolDecimal { - /** TODO: 準備中 */ - public static final int DECIMAL_NAN = -128; - /** TODO: 準備中 */ - public static final int COB_STORE_ROUND = 0x01; - /** TODO: 準備中 */ - public static final int COB_STORE_KEEP_ON_OVERFLOW = 0x02; - /** TODO: 準備中 */ - public static final int COB_STORE_TRUNC_ON_OVERFLOW = 0x04; - - /** TODO: 準備中 */ - public static final int COB_MAX_BINARY = 36; - - private static BigDecimal cobMexp = BigDecimal.ZERO; - /** TODO: 準備中 */ - static CobolDecimal cobD1 = new CobolDecimal(); - /** TODO: 準備中 */ - static CobolDecimal cobD2 = new CobolDecimal(); - /** TODO: 準備中 */ - static CobolDecimal cobD3 = new CobolDecimal(); - /** TODO: 準備中 */ - static CobolDecimal cobD4 = new CobolDecimal(); - /** TODO: 準備中 */ - private static BigDecimal[] cobMpze10 = new BigDecimal[COB_MAX_BINARY]; - /** TODO: 準備中 */ - static byte[] packedValue = new byte[20]; - /** TODO: 準備中 */ - static int packedValueInt = 0; - - /** TODO: 準備中 */ - public static void cobInitNumeric() { - cobD1 = new CobolDecimal(); - cobD2 = new CobolDecimal(); - cobD3 = new CobolDecimal(); - cobD4 = new CobolDecimal(); - cobMexp = BigDecimal.ZERO; - for (int i = 0; i < COB_MAX_BINARY; ++i) { - cobMpze10[i] = BigDecimal.ZERO; - cobMpze10[i] = BigDecimal.TEN.pow(i); - } - for (int i = 0; i < packedValue.length; ++i) { - packedValue[i] = 0; - } - packedValueInt = 0; - } - - // TODO cob_init_numeric周辺の初期化処理を正しく実装出来たら消す。 - static { - for (int i = 0; i < COB_MAX_BINARY; ++i) { - cobMpze10[i] = BigDecimal.ZERO; - cobMpze10[i] = BigDecimal.TEN.pow(i); - } - for (int i = 0; i < packedValue.length; ++i) { - packedValue[i] = 0; - } - packedValueInt = 0; - } - - /** 保持する数値データ */ - BigDecimal value; - - /** TODO: 準備中 */ - int scale; - - /** 値とスケールは0に設定する */ - public CobolDecimal() { - this.value = BigDecimal.ZERO; - this.setScale(0); - } - - /** - * 値はvalueを指定し,スケールは0に設定する - * - * @param value 設定する値 - */ - public CobolDecimal(BigDecimal value) { - this.setValue(value); - this.setScale(0); - } - - /** - * 値とスケールを指定する - * - * @param value 設定する値 - * @param scale 設定するスケール - */ - public CobolDecimal(BigDecimal value, int scale) { - this(value); - this.setScale(scale); - } - - /** - * 値を指定し,スケールは0に設定する - * - * @param n TODO: 準備中 - */ - public CobolDecimal(long n) { - if (n == 0L) { - this.setValue(BigDecimal.ZERO); - } else if (n == 1L) { - this.setValue(BigDecimal.ONE); - } else if (n == 10L) { - this.setValue(BigDecimal.TEN); - } else { - this.setValue(new BigDecimal(n)); - } - this.setScale(0); - } - - /** - * 値を設定し,スケールは0に設定する - * - * @param n TODO: 準備中 - */ - public CobolDecimal(int n) { - if (n == 0) { - this.setValue(BigDecimal.ZERO); - } else if (n == 1) { - this.setValue(BigDecimal.ONE); - } else if (n == 10) { - this.setValue(BigDecimal.TEN); - } else { - this.setValue(new BigDecimal(n)); - } - this.setScale(0); - } - - /** - * コピーコンストラクタ - * - * @param other TODO: 準備中 - */ - public CobolDecimal(CobolDecimal other) { - this.setValue(other.getValue()); - this.setScale(other.getScale()); - } - - /** - * このオブジェクトの値を取得する - * - * @return このオブジェクトの値 - */ - public BigDecimal getValue() { - return value; - } - - /** TODO: 準備中 */ - public void decimalInit() { - this.value = BigDecimal.ZERO; - } - - /** - * このオブジェクトの値を設定する - * - * @param value このオブジェクトに設定する値 - */ - public void setValue(BigDecimal value) { - this.value = value; - } - - /** this.valueの値を0にする */ - public void clear() { - this.value = BigDecimal.ZERO; - } - - /** - * このオブジェクトのスケールを設定する - * - * @param scale このオブジェクトに設定するスケール - */ - public void setScale(int scale) { - this.scale = scale; - } - - /** - * このオブジェクトのスケールを取得する - * - * @return このオブジェクトのスケール - */ - public int getScale() { - return this.scale; - } - - /** - * このオブジェクトの値を設定し、スケールは0に設定する - * - * @param n このオブジェクトに設定する値 - */ - public void set(int n) { - this.value = new BigDecimal(n); - this.scale = 0; - } - - /** - * このオブジェクトの値を設定し、スケールは0に設定する - * - * @param n このオブジェクトに設定する値 - */ - public void set(long n) { - this.value = new BigDecimal(n); - this.scale = 0; - } - - /** - * TODO: 準備中 - * - * @param decimal TODO: 準備中 - */ - public void set(CobolDecimal decimal) { - // TODO よりよいコピーの方法を考える - this.value = decimal.value.add(BigDecimal.ZERO); - this.setScale(decimal.getScale()); - } - - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - */ - public void setField(AbstractCobolField f) { - CobolDecimal decimal = f.getDecimal(); - this.setValue(decimal.getValue()); - this.setScale(decimal.getScale()); - } - - /** - * TODO: 準備中 - * - * @param d1 TODO: 準備中 - * @param d2 TODO: 準備中 - */ - private static boolean DECIMAL_CHECK(CobolDecimal d1, CobolDecimal d2) { - if (d1.getScale() == DECIMAL_NAN || d2.getScale() == DECIMAL_NAN) { - d1.setScale(DECIMAL_NAN); - return true; - } - return false; - } - - /** - * このオブジェクトの示す数値に対して加算を行う - * - * @param n このオブジェクトに加算する値 - */ - public void add(int n) { - this.value = this.value.add(new BigDecimal(n)); - } - - /** - * このオブジェクトの示す数値に対して加算を行う - * - * @param decimal このオブジェクトに加算する値 - */ - public void add(CobolDecimal decimal) { - if (DECIMAL_CHECK(this, decimal)) { - return; - } - alignDecimal(this, decimal); - this.setValue(this.getValue().add(decimal.getValue())); - } - - /** - * このオブジェクトの示す数値に対して減算を行う - * - * @param decimal このオブジェクトの示す数値から減算する値 - */ - public void sub(CobolDecimal decimal) { - if (DECIMAL_CHECK(this, decimal)) { - return; - } - alignDecimal(this, decimal); - this.setValue(this.getValue().subtract(decimal.getValue())); - } - - /** - * このオブジェクトの示す数値に対して減算を行う - * - * @param n このオブジェクトの示す数値から減算する値 - */ - public void sub(int n) { - this.value = this.value.subtract(new BigDecimal(n)); - } - - /** - * このオブジェクトの示す数値に対して乗算を行う - * - * @param decimal このオブジェクトの示す数値に乗算する値 - */ - public void mul(CobolDecimal decimal) { - if (DECIMAL_CHECK(this, decimal)) { - return; - } - this.setScale(this.getScale() + decimal.getScale()); - this.setValue(this.getValue().multiply(decimal.getValue())); - } - - /** - * このオブジェクトの示す数値に対して乗算を行う - * - * @param n このオブジェクトの示す数値に乗算する値 - */ - public void mul(int n) { - this.value = this.value.multiply(new BigDecimal(n)); - } - - /** - * このオブジェクトの示す数値に対してmod演算を行う - * - * @param decimal このオブジェクトの示す数値にmod演算する値 - * @throws CobolStopRunException TODO: 準備中 - */ - public void div(CobolDecimal decimal) throws CobolStopRunException { - if (DECIMAL_CHECK(this, decimal)) { - return; - } - if (decimal.getValue().signum() == 0) { - this.setScale(DECIMAL_NAN); - if (CobolUtil.cobErrorOnExitFlag) { - CobolUtil.runtimeError("Detected division by zero."); - CobolStopRunException.stopRunAndThrow(1); - ; - } - return; - } - if (this.getValue().signum() == 0) { - this.setScale(0); - return; - } - this.setScale(this.getScale() - decimal.getScale()); - int shift = 37 + ((this.getScale() < 0) ? -this.getScale() : 0); - this.shiftDecimal(shift); - this.setValue(this.getValue().divide(decimal.getValue(), RoundingMode.DOWN)); - } - - /** - * このオブジェクトの示す数値に対して除算を行う - * - * @param n このオブジェクトの示す数値を除算する値 - */ - public void div(int n) { - this.value = this.value.divide(new BigDecimal(n), RoundingMode.DOWN); - } - - /** - * このオブジェクトの示す数値に対して累乗を行う - * - * @param decimal このオブジェクトの示す数値を累乗する値 - */ - // TODO 残りの実装 - public void pow(CobolDecimal decimal) { - if (DECIMAL_CHECK(this, decimal)) { - return; - } - - if (decimal.getScale() == 0 && decimal.getValue().compareTo(new BigDecimal(2147483647)) <= 0) { - int n = decimal.getValue().intValue(); - this.value = this.value.pow(n); - this.setScale(this.getScale() * n); - } else { - this.decimalSetDouble(Math.pow(this.decimalGetDouble(), decimal.decimalGetDouble())); - } - } - - /** - * TODO: 準備中 - * - * @param v TODO: 準備中 - */ - private void decimalSetDouble(double v) { - this.setValue(new BigDecimal(v * 1.0e9)); - this.setScale(9); - } - - private double decimalGetDouble() { - double v = this.getValue().doubleValue(); - int n = this.getScale(); - for (; n > 0; n--) { - v /= 10; - } - for (; n < 0; n++) { - v *= 10; - } - return v; - } - - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - * @param opt TODO: 準備中 - * @return TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public int getField(AbstractCobolField f, int opt) throws CobolStopRunException { - if (this.getScale() == CobolDecimal.DECIMAL_NAN) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_SIZE_OVERFLOW); - return CobolRuntimeException.code; - } - - CobolDecimal d = new CobolDecimal(this); - - /* rounding */ - if ((opt & CobolDecimal.COB_STORE_ROUND) != 0) { - if (f.getAttribute().getScale() < d.getScale()) { - int sign = d.value.signum(); - if (sign != 0) { - d.shiftDecimal(f.getAttribute().getScale() - d.getScale() + 1); - if (sign > 0) { - d.add(5); - } else { - d.sub(5); - } - } - } - } - - d.shiftDecimal(f.getAttribute().getScale() - d.getScale()); - - // TODO 残りのパターンも実装 - switch (f.getAttribute().getType()) { - case CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY: - return d.getDisplayField(f, opt); - case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: - return d.getPackedField(f, opt); - case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: - return d.getBinaryField(f, opt); - case CobolFieldAttribute.COB_TYPE_NUMERIC_FLOAT: - System.out.println("getField: Float not implemented"); - throw new CobolRuntimeException(0, "getField: Float not implemented"); - case CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE: - return d.getDoubleField(f, opt); - default: - int digits = f.getAttribute().getDigits(); - CobolFieldAttribute attr = f.getAttribute(); - CobolFieldAttribute newAttr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, - digits, - attr.getScale(), - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - AbstractCobolField displayField = - CobolFieldFactory.makeCobolField(digits, new CobolDataStorage(digits), newAttr); - if (d.getField(displayField, opt) == 0) { - f.moveFrom(displayField); - } - return CobolExceptionInfo.code; - } - } - - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - * @param opt TODO: 準備中 - * @return TODO: 準備中 - */ - public int getDoubleField(AbstractCobolField f, int opt) { - CobolDataStorage storage = new CobolDataStorage(8); - double val = this.value.doubleValue(); - int scale = this.scale; - for (int i = 0; i < Math.abs(scale); ++i) { - if (scale > 0) { - val /= 10; - } else { - val *= 10; - } - } - storage.set(val); - f.setDataStorage(storage); - return 0; - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void shiftDecimal(int n) { - if (n == 0) { - return; - } - if (n > 0) { - cobMexp = BigDecimal.TEN.pow(n); - this.value = this.value.multiply(cobMexp); - } else { - cobMexp = BigDecimal.TEN.pow(-n); - this.value = this.value.divide(cobMexp, RoundingMode.DOWN); - } - this.setScale(this.getScale() + n); - } - - // libcob/numeric.cのalign_decimalの実装 - /** - * TODO: 準備中 - * - * @param d1 TODO: 準備中 - * @param d2 TODO: 準備中 - */ - public void alignDecimal(CobolDecimal d1, CobolDecimal d2) { - if (d1.getScale() < d2.getScale()) { - d1.shiftDecimal(d2.getScale() - d1.getScale()); - } else if (d1.getScale() > d2.getScale()) { - d2.shiftDecimal(d1.getScale() - d2.getScale()); - } - } - - // libcob/numeric.cのcob_decimal_cmpの実装 引数で与えられたCobolDecimal型のインスタンスとの比較をする. - /** - * TODO: 準備中 - * - * @param decimal TODO: 準備中 - * @return TODO: 準備中 - */ - public int compareTo(CobolDecimal decimal) { - alignDecimal(this, decimal); - BigDecimal v1 = this.getValue().movePointLeft(this.getScale()); - BigDecimal v2 = decimal.getValue().movePointLeft(decimal.getScale()); - return v1.compareTo(v2); - } - - // libcob/numeric.cのcob_decimal_get_displayの実装 - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - * @param opt TODO: 準備中 - * @return TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public int getDisplayField(AbstractCobolField f, int opt) throws CobolStopRunException { - int sign = this.value.signum(); - this.value = this.value.abs(); - String numString = this.value.toPlainString(); - int dPointIndex = numString.indexOf('.'); - numString = numString.replace(".", ""); - byte[] numBuffPtr = numString.getBytes(); - if (dPointIndex < 0) { - dPointIndex = numBuffPtr.length; - } - dPointIndex -= this.scale; - int size = numBuffPtr.length; - - CobolDataStorage data = f.getDataStorage(); - int diff = f.getFieldSize() - size; - - if (diff < 0) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_SIZE_OVERFLOW); - if ((opt & CobolDecimal.COB_STORE_KEEP_ON_OVERFLOW) > 0) { - return CobolRuntimeException.code; - } - } - - int fFirstIndex = f.getFirstDataIndex(); - int fFieldSize = f.getFieldSize(); - int fPointIndex = fFieldSize - f.getAttribute().getScale(); - for (int i = 0; i < fFieldSize; i++) { - int fIndex = fFirstIndex + i; - int dIndex = i + dPointIndex - fPointIndex; - if (0 <= dIndex && dIndex < numBuffPtr.length) { - data.setByte(fIndex, numBuffPtr[dIndex]); - } else { - data.setByte(fIndex, (byte) '0'); - } - } - f.putSign(sign); - return 0; - } - - // libcob/numeric.cのcob_decimal_get_packedの実装 - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - * @param opt TODO: 準備中 - * @return TODO: 準備中 - */ - public int getPackedField(AbstractCobolField f, int opt) { - int sign = this.value.signum(); - this.value = this.value.abs(); - String numString = this.value.toPlainString(); - int dPointIndex = numString.indexOf('.'); - numString = numString.replace(".", ""); - byte[] numBuffPtr = numString.getBytes(); - if (dPointIndex < 0) { - dPointIndex = numBuffPtr.length; - } - dPointIndex -= this.scale; - int size = numBuffPtr.length; - int fPointIndex = f.getAttribute().getDigits() - f.getAttribute().getScale(); - - CobolDataStorage data = f.getDataStorage(); - int digits = f.getAttribute().getDigits(); - int diff = digits - size; - if (diff < 0) { - CobolRuntimeException.setException(CobolExceptionId.COB_EC_SIZE_OVERFLOW); - if ((opt & CobolDecimal.COB_STORE_KEEP_ON_OVERFLOW) > 0) { - return CobolRuntimeException.code; - } - } - data.fillBytes(0, f.getSize()); - for (int i = 0; i < digits; ++i) { - int j = i - fPointIndex + dPointIndex; - if (j < 0 || numBuffPtr.length <= j) { - continue; - } - byte val = (byte) ((int) numBuffPtr[j] - '0'); - int index; - if (digits % 2 == 0) { - index = (i + 1) / 2; - } else { - index = i / 2; - } - byte b = data.getByte(index); - if ((digits + i) % 2 == 0) { - data.setByte(index, (b & 0xF0) | val); - } else { - data.setByte(index, (val << 4) | (b & 0x0F)); - } - } - - int p = f.getSize() - 1; - byte x = data.getByte(p); - if (!f.getAttribute().isFlagHaveSign()) { - data.setByte(p, (byte) ((x & 0xF0) | 0x0F)); - } else if (sign < 0) { - data.setByte(p, (byte) ((x & 0xF0) | 0x0D)); - } else { - data.setByte(p, (byte) ((x & 0xF0) | 0x0C)); - } - - return 0; - } - - // libcob/numeric.cのcob_decimal_get_binaryの実装 - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - * @param opt TODO: 準備中 - * @return TODO: 準備中 - */ - private int getBinaryField(AbstractCobolField f, int opt) { - CobolDataStorage data = f.getDataStorage(); - CobolFieldAttribute attr = f.getAttribute(); - if (this.getValue().signum() == 0) { - data.fillBytes(0, f.getSize()); - return 0; - } - int overflow = 0; - int digits = attr.getDigits(); - int sign; - if (attr.isFlagHaveSign()) { - sign = 1; - } else { - sign = 0; - if (this.value.signum() < 0) { - this.value = this.value.abs(); - } - } - int bitnum = f.getSize() * 8 - sign; - outer: - { - if (this.getValue().compareTo(new BigDecimal(2).pow(bitnum).subtract(BigDecimal.ONE)) > 0) { - if ((opt & COB_STORE_KEEP_ON_OVERFLOW) != 0) { - break outer; - } - overflow = 1; - if ((opt & COB_STORE_TRUNC_ON_OVERFLOW) != 0) { - this.setValue(this.getValue().remainder(cobMpze10[digits])); - } else { - this.setValue(this.getValue().remainder(new BigDecimal(2).pow(f.getSize() * 8))); - } - } else if ((opt != 0) && CobolModule.getCurrentModule().flag_binary_truncate != 0) { - if (this.getValue().abs().compareTo(cobMpze10[digits].abs()) >= 0) { - if ((opt & COB_STORE_KEEP_ON_OVERFLOW) != 0) { - break outer; - } - overflow = 1; - if ((opt & COB_STORE_TRUNC_ON_OVERFLOW) != 0) { - this.setValue(this.getValue().remainder(cobMpze10[digits])); - } else { - this.setValue(this.getValue().remainder(new BigDecimal(2).pow(f.getFieldSize() * 8))); - } - } - } - ((CobolNumericBinaryField) f).setLongValue(this.getValue().longValue()); - if (overflow == 0) { - return 0; - } - } - CobolRuntimeException.setException(CobolExceptionId.COB_EC_SIZE_OVERFLOW); - return CobolExceptionInfo.code; - } - - // libcob/numeric.cのnum_byte_memcpyの実装 - /** - * TODO: 準備中 - * - * @param s1 TODO: 準備中 - * @param s1StartIndex TODO: 準備中 - * @param s2 TODO: 準備中 - * @param s2StartIndex TODO: 準備中 - * @param size TODO: 準備中 - */ - public static void numByteMemcpy( - CobolDataStorage s1, int s1StartIndex, CobolDataStorage s2, int s2StartIndex, int size) { - int i1 = s1StartIndex; - int i2 = s2StartIndex; - do { - s1.setByte(i1++, s2.getByte(i2++)); - } while (--size != 0); - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.data; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import jp.osscons.opensourcecobol.libcobj.common.CobolModule; +import jp.osscons.opensourcecobol.libcobj.common.CobolUtil; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionId; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionInfo; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; + +/** + * BigDecimalを扱うクラス
+ * COMPUTE等で計算をするときに使用する + */ +public class CobolDecimal { + /** TODO: 準備中 */ + public static final int DECIMAL_NAN = -128; + + /** TODO: 準備中 */ + public static final int COB_STORE_ROUND = 0x01; + + /** TODO: 準備中 */ + public static final int COB_STORE_KEEP_ON_OVERFLOW = 0x02; + + /** TODO: 準備中 */ + public static final int COB_STORE_TRUNC_ON_OVERFLOW = 0x04; + + /** TODO: 準備中 */ + public static final int COB_MAX_BINARY = 36; + + private static BigDecimal cobMexp = BigDecimal.ZERO; + + /** TODO: 準備中 */ + static CobolDecimal cobD1 = new CobolDecimal(); + + /** TODO: 準備中 */ + static CobolDecimal cobD2 = new CobolDecimal(); + + /** TODO: 準備中 */ + static CobolDecimal cobD3 = new CobolDecimal(); + + /** TODO: 準備中 */ + static CobolDecimal cobD4 = new CobolDecimal(); + + /** TODO: 準備中 */ + private static BigDecimal[] cobMpze10 = new BigDecimal[COB_MAX_BINARY]; + + /** TODO: 準備中 */ + static byte[] packedValue = new byte[20]; + + /** TODO: 準備中 */ + static int packedValueInt = 0; + + /** TODO: 準備中 */ + public static void cobInitNumeric() { + cobD1 = new CobolDecimal(); + cobD2 = new CobolDecimal(); + cobD3 = new CobolDecimal(); + cobD4 = new CobolDecimal(); + cobMexp = BigDecimal.ZERO; + for (int i = 0; i < COB_MAX_BINARY; ++i) { + cobMpze10[i] = BigDecimal.ZERO; + cobMpze10[i] = BigDecimal.TEN.pow(i); + } + for (int i = 0; i < packedValue.length; ++i) { + packedValue[i] = 0; + } + packedValueInt = 0; + } + + // TODO cob_init_numeric周辺の初期化処理を正しく実装出来たら消す。 + static { + for (int i = 0; i < COB_MAX_BINARY; ++i) { + cobMpze10[i] = BigDecimal.ZERO; + cobMpze10[i] = BigDecimal.TEN.pow(i); + } + for (int i = 0; i < packedValue.length; ++i) { + packedValue[i] = 0; + } + packedValueInt = 0; + } + + /** 保持する数値データ */ + BigDecimal value; + + /** TODO: 準備中 */ + int scale; + + /** 値とスケールは0に設定する */ + public CobolDecimal() { + this.value = BigDecimal.ZERO; + this.setScale(0); + } + + /** + * 値はvalueを指定し,スケールは0に設定する + * + * @param value 設定する値 + */ + public CobolDecimal(BigDecimal value) { + this.setValue(value); + this.setScale(0); + } + + /** + * 値とスケールを指定する + * + * @param value 設定する値 + * @param scale 設定するスケール + */ + public CobolDecimal(BigDecimal value, int scale) { + this(value); + this.setScale(scale); + } + + /** + * 値を指定し,スケールは0に設定する + * + * @param n TODO: 準備中 + */ + public CobolDecimal(long n) { + if (n == 0L) { + this.setValue(BigDecimal.ZERO); + } else if (n == 1L) { + this.setValue(BigDecimal.ONE); + } else if (n == 10L) { + this.setValue(BigDecimal.TEN); + } else { + this.setValue(new BigDecimal(n)); + } + this.setScale(0); + } + + /** + * 値を設定し,スケールは0に設定する + * + * @param n TODO: 準備中 + */ + public CobolDecimal(int n) { + if (n == 0) { + this.setValue(BigDecimal.ZERO); + } else if (n == 1) { + this.setValue(BigDecimal.ONE); + } else if (n == 10) { + this.setValue(BigDecimal.TEN); + } else { + this.setValue(new BigDecimal(n)); + } + this.setScale(0); + } + + /** + * コピーコンストラクタ + * + * @param other TODO: 準備中 + */ + public CobolDecimal(CobolDecimal other) { + this.setValue(other.getValue()); + this.setScale(other.getScale()); + } + + /** + * このオブジェクトの値を取得する + * + * @return このオブジェクトの値 + */ + public BigDecimal getValue() { + return value; + } + + /** TODO: 準備中 */ + public void decimalInit() { + this.value = BigDecimal.ZERO; + } + + /** + * このオブジェクトの値を設定する + * + * @param value このオブジェクトに設定する値 + */ + public void setValue(BigDecimal value) { + this.value = value; + } + + /** this.valueの値を0にする */ + public void clear() { + this.value = BigDecimal.ZERO; + } + + /** + * このオブジェクトのスケールを設定する + * + * @param scale このオブジェクトに設定するスケール + */ + public void setScale(int scale) { + this.scale = scale; + } + + /** + * このオブジェクトのスケールを取得する + * + * @return このオブジェクトのスケール + */ + public int getScale() { + return this.scale; + } + + /** + * このオブジェクトの値を設定し、スケールは0に設定する + * + * @param n このオブジェクトに設定する値 + */ + public void set(int n) { + this.value = new BigDecimal(n); + this.scale = 0; + } + + /** + * このオブジェクトの値を設定し、スケールは0に設定する + * + * @param n このオブジェクトに設定する値 + */ + public void set(long n) { + this.value = new BigDecimal(n); + this.scale = 0; + } + + /** + * TODO: 準備中 + * + * @param decimal TODO: 準備中 + */ + public void set(CobolDecimal decimal) { + // TODO よりよいコピーの方法を考える + this.value = decimal.value.add(BigDecimal.ZERO); + this.setScale(decimal.getScale()); + } + + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + */ + public void setField(AbstractCobolField f) { + CobolDecimal decimal = f.getDecimal(); + this.setValue(decimal.getValue()); + this.setScale(decimal.getScale()); + } + + /** + * TODO: 準備中 + * + * @param d1 TODO: 準備中 + * @param d2 TODO: 準備中 + */ + private static boolean DECIMAL_CHECK(CobolDecimal d1, CobolDecimal d2) { + if (d1.getScale() == DECIMAL_NAN || d2.getScale() == DECIMAL_NAN) { + d1.setScale(DECIMAL_NAN); + return true; + } + return false; + } + + /** + * このオブジェクトの示す数値に対して加算を行う + * + * @param n このオブジェクトに加算する値 + */ + public void add(int n) { + this.value = this.value.add(new BigDecimal(n)); + } + + /** + * このオブジェクトの示す数値に対して加算を行う + * + * @param decimal このオブジェクトに加算する値 + */ + public void add(CobolDecimal decimal) { + if (DECIMAL_CHECK(this, decimal)) { + return; + } + alignDecimal(this, decimal); + this.setValue(this.getValue().add(decimal.getValue())); + } + + /** + * このオブジェクトの示す数値に対して減算を行う + * + * @param decimal このオブジェクトの示す数値から減算する値 + */ + public void sub(CobolDecimal decimal) { + if (DECIMAL_CHECK(this, decimal)) { + return; + } + alignDecimal(this, decimal); + this.setValue(this.getValue().subtract(decimal.getValue())); + } + + /** + * このオブジェクトの示す数値に対して減算を行う + * + * @param n このオブジェクトの示す数値から減算する値 + */ + public void sub(int n) { + this.value = this.value.subtract(new BigDecimal(n)); + } + + /** + * このオブジェクトの示す数値に対して乗算を行う + * + * @param decimal このオブジェクトの示す数値に乗算する値 + */ + public void mul(CobolDecimal decimal) { + if (DECIMAL_CHECK(this, decimal)) { + return; + } + this.setScale(this.getScale() + decimal.getScale()); + this.setValue(this.getValue().multiply(decimal.getValue())); + } + + /** + * このオブジェクトの示す数値に対して乗算を行う + * + * @param n このオブジェクトの示す数値に乗算する値 + */ + public void mul(int n) { + this.value = this.value.multiply(new BigDecimal(n)); + } + + /** + * このオブジェクトの示す数値に対してmod演算を行う + * + * @param decimal このオブジェクトの示す数値にmod演算する値 + * @throws CobolStopRunException TODO: 準備中 + */ + public void div(CobolDecimal decimal) throws CobolStopRunException { + if (DECIMAL_CHECK(this, decimal)) { + return; + } + if (decimal.getValue().signum() == 0) { + this.setScale(DECIMAL_NAN); + if (CobolUtil.cobErrorOnExitFlag) { + CobolUtil.runtimeError("Detected division by zero."); + CobolStopRunException.stopRunAndThrow(1); + ; + } + return; + } + if (this.getValue().signum() == 0) { + this.setScale(0); + return; + } + this.setScale(this.getScale() - decimal.getScale()); + int shift = 37 + ((this.getScale() < 0) ? -this.getScale() : 0); + this.shiftDecimal(shift); + this.setValue(this.getValue().divide(decimal.getValue(), RoundingMode.DOWN)); + } + + /** + * このオブジェクトの示す数値に対して除算を行う + * + * @param n このオブジェクトの示す数値を除算する値 + */ + public void div(int n) { + this.value = this.value.divide(new BigDecimal(n), RoundingMode.DOWN); + } + + /** + * このオブジェクトの示す数値に対して累乗を行う + * + * @param decimal このオブジェクトの示す数値を累乗する値 + */ + // TODO 残りの実装 + public void pow(CobolDecimal decimal) { + if (DECIMAL_CHECK(this, decimal)) { + return; + } + + if (decimal.getScale() == 0 + && decimal.getValue().compareTo(new BigDecimal(2147483647)) <= 0) { + int n = decimal.getValue().intValue(); + this.value = this.value.pow(n); + this.setScale(this.getScale() * n); + } else { + this.decimalSetDouble(Math.pow(this.decimalGetDouble(), decimal.decimalGetDouble())); + } + } + + /** + * TODO: 準備中 + * + * @param v TODO: 準備中 + */ + private void decimalSetDouble(double v) { + this.setValue(new BigDecimal(v * 1.0e9)); + this.setScale(9); + } + + private double decimalGetDouble() { + double v = this.getValue().doubleValue(); + int n = this.getScale(); + for (; n > 0; n--) { + v /= 10; + } + for (; n < 0; n++) { + v *= 10; + } + return v; + } + + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + * @param opt TODO: 準備中 + * @return TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public int getField(AbstractCobolField f, int opt) throws CobolStopRunException { + if (this.getScale() == CobolDecimal.DECIMAL_NAN) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_SIZE_OVERFLOW); + return CobolRuntimeException.code; + } + + CobolDecimal d = new CobolDecimal(this); + + /* rounding */ + if ((opt & CobolDecimal.COB_STORE_ROUND) != 0) { + if (f.getAttribute().getScale() < d.getScale()) { + int sign = d.value.signum(); + if (sign != 0) { + d.shiftDecimal(f.getAttribute().getScale() - d.getScale() + 1); + if (sign > 0) { + d.add(5); + } else { + d.sub(5); + } + } + } + } + + d.shiftDecimal(f.getAttribute().getScale() - d.getScale()); + + // TODO 残りのパターンも実装 + switch (f.getAttribute().getType()) { + case CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY: + return d.getDisplayField(f, opt); + case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: + return d.getPackedField(f, opt); + case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: + return d.getBinaryField(f, opt); + case CobolFieldAttribute.COB_TYPE_NUMERIC_FLOAT: + System.out.println("getField: Float not implemented"); + throw new CobolRuntimeException(0, "getField: Float not implemented"); + case CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE: + return d.getDoubleField(f, opt); + default: + int digits = f.getAttribute().getDigits(); + CobolFieldAttribute attr = f.getAttribute(); + CobolFieldAttribute newAttr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, + digits, + attr.getScale(), + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + AbstractCobolField displayField = + CobolFieldFactory.makeCobolField( + digits, new CobolDataStorage(digits), newAttr); + if (d.getField(displayField, opt) == 0) { + f.moveFrom(displayField); + } + return CobolExceptionInfo.code; + } + } + + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + * @param opt TODO: 準備中 + * @return TODO: 準備中 + */ + public int getDoubleField(AbstractCobolField f, int opt) { + CobolDataStorage storage = new CobolDataStorage(8); + double val = this.value.doubleValue(); + int scale = this.scale; + for (int i = 0; i < Math.abs(scale); ++i) { + if (scale > 0) { + val /= 10; + } else { + val *= 10; + } + } + storage.set(val); + f.setDataStorage(storage); + return 0; + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void shiftDecimal(int n) { + if (n == 0) { + return; + } + if (n > 0) { + cobMexp = BigDecimal.TEN.pow(n); + this.value = this.value.multiply(cobMexp); + } else { + cobMexp = BigDecimal.TEN.pow(-n); + this.value = this.value.divide(cobMexp, RoundingMode.DOWN); + } + this.setScale(this.getScale() + n); + } + + // libcob/numeric.cのalign_decimalの実装 + /** + * TODO: 準備中 + * + * @param d1 TODO: 準備中 + * @param d2 TODO: 準備中 + */ + public void alignDecimal(CobolDecimal d1, CobolDecimal d2) { + if (d1.getScale() < d2.getScale()) { + d1.shiftDecimal(d2.getScale() - d1.getScale()); + } else if (d1.getScale() > d2.getScale()) { + d2.shiftDecimal(d1.getScale() - d2.getScale()); + } + } + + // libcob/numeric.cのcob_decimal_cmpの実装 引数で与えられたCobolDecimal型のインスタンスとの比較をする. + /** + * TODO: 準備中 + * + * @param decimal TODO: 準備中 + * @return TODO: 準備中 + */ + public int compareTo(CobolDecimal decimal) { + alignDecimal(this, decimal); + BigDecimal v1 = this.getValue().movePointLeft(this.getScale()); + BigDecimal v2 = decimal.getValue().movePointLeft(decimal.getScale()); + return v1.compareTo(v2); + } + + // libcob/numeric.cのcob_decimal_get_displayの実装 + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + * @param opt TODO: 準備中 + * @return TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public int getDisplayField(AbstractCobolField f, int opt) throws CobolStopRunException { + int sign = this.value.signum(); + this.value = this.value.abs(); + String numString = this.value.toPlainString(); + int dPointIndex = numString.indexOf('.'); + numString = numString.replace(".", ""); + byte[] numBuffPtr = numString.getBytes(AbstractCobolField.charSetSJIS); + if (dPointIndex < 0) { + dPointIndex = numBuffPtr.length; + } + dPointIndex -= this.scale; + int size = numBuffPtr.length; + + CobolDataStorage data = f.getDataStorage(); + int diff = f.getFieldSize() - size; + + if (diff < 0) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_SIZE_OVERFLOW); + if ((opt & CobolDecimal.COB_STORE_KEEP_ON_OVERFLOW) > 0) { + return CobolRuntimeException.code; + } + } + + int fFirstIndex = f.getFirstDataIndex(); + int fFieldSize = f.getFieldSize(); + int fPointIndex = fFieldSize - f.getAttribute().getScale(); + for (int i = 0; i < fFieldSize; i++) { + int fIndex = fFirstIndex + i; + int dIndex = i + dPointIndex - fPointIndex; + if (0 <= dIndex && dIndex < numBuffPtr.length) { + data.setByte(fIndex, numBuffPtr[dIndex]); + } else { + data.setByte(fIndex, (byte) '0'); + } + } + f.putSign(sign); + return 0; + } + + // libcob/numeric.cのcob_decimal_get_packedの実装 + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + * @param opt TODO: 準備中 + * @return TODO: 準備中 + */ + public int getPackedField(AbstractCobolField f, int opt) { + int sign = this.value.signum(); + this.value = this.value.abs(); + String numString = this.value.toPlainString(); + int dPointIndex = numString.indexOf('.'); + numString = numString.replace(".", ""); + byte[] numBuffPtr = numString.getBytes(AbstractCobolField.charSetSJIS); + if (dPointIndex < 0) { + dPointIndex = numBuffPtr.length; + } + dPointIndex -= this.scale; + int size = numBuffPtr.length; + int fPointIndex = f.getAttribute().getDigits() - f.getAttribute().getScale(); + + CobolDataStorage data = f.getDataStorage(); + int digits = f.getAttribute().getDigits(); + int diff = digits - size; + if (diff < 0) { + CobolRuntimeException.setException(CobolExceptionId.COB_EC_SIZE_OVERFLOW); + if ((opt & CobolDecimal.COB_STORE_KEEP_ON_OVERFLOW) > 0) { + return CobolRuntimeException.code; + } + } + data.fillBytes(0, f.getSize()); + for (int i = 0; i < digits; ++i) { + int j = i - fPointIndex + dPointIndex; + if (j < 0 || numBuffPtr.length <= j) { + continue; + } + byte val = (byte) ((int) numBuffPtr[j] - '0'); + int index; + if (digits % 2 == 0) { + index = (i + 1) / 2; + } else { + index = i / 2; + } + byte b = data.getByte(index); + if ((digits + i) % 2 == 0) { + data.setByte(index, (b & 0xF0) | val); + } else { + data.setByte(index, (val << 4) | (b & 0x0F)); + } + } + + int p = f.getSize() - 1; + byte x = data.getByte(p); + if (!f.getAttribute().isFlagHaveSign()) { + data.setByte(p, (byte) ((x & 0xF0) | 0x0F)); + } else if (sign < 0) { + data.setByte(p, (byte) ((x & 0xF0) | 0x0D)); + } else { + data.setByte(p, (byte) ((x & 0xF0) | 0x0C)); + } + + return 0; + } + + // libcob/numeric.cのcob_decimal_get_binaryの実装 + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + * @param opt TODO: 準備中 + * @return TODO: 準備中 + */ + private int getBinaryField(AbstractCobolField f, int opt) { + CobolDataStorage data = f.getDataStorage(); + CobolFieldAttribute attr = f.getAttribute(); + if (this.getValue().signum() == 0) { + data.fillBytes(0, f.getSize()); + return 0; + } + int overflow = 0; + int digits = attr.getDigits(); + int sign; + if (attr.isFlagHaveSign()) { + sign = 1; + } else { + sign = 0; + if (this.value.signum() < 0) { + this.value = this.value.abs(); + } + } + int bitnum = f.getSize() * 8 - sign; + outer: + { + if (this.getValue().compareTo(new BigDecimal(2).pow(bitnum).subtract(BigDecimal.ONE)) + > 0) { + if ((opt & COB_STORE_KEEP_ON_OVERFLOW) != 0) { + break outer; + } + overflow = 1; + if ((opt & COB_STORE_TRUNC_ON_OVERFLOW) != 0) { + this.setValue(this.getValue().remainder(cobMpze10[digits])); + } else { + this.setValue( + this.getValue().remainder(new BigDecimal(2).pow(f.getSize() * 8))); + } + } else if ((opt != 0) && CobolModule.getCurrentModule().flag_binary_truncate != 0) { + if (this.getValue().abs().compareTo(cobMpze10[digits].abs()) >= 0) { + if ((opt & COB_STORE_KEEP_ON_OVERFLOW) != 0) { + break outer; + } + overflow = 1; + if ((opt & COB_STORE_TRUNC_ON_OVERFLOW) != 0) { + this.setValue(this.getValue().remainder(cobMpze10[digits])); + } else { + this.setValue( + this.getValue() + .remainder(new BigDecimal(2).pow(f.getFieldSize() * 8))); + } + } + } + ((CobolNumericBinaryField) f).setLongValue(this.getValue().longValue()); + if (overflow == 0) { + return 0; + } + } + CobolRuntimeException.setException(CobolExceptionId.COB_EC_SIZE_OVERFLOW); + return CobolExceptionInfo.code; + } + + // libcob/numeric.cのnum_byte_memcpyの実装 + /** + * TODO: 準備中 + * + * @param s1 TODO: 準備中 + * @param s1StartIndex TODO: 準備中 + * @param s2 TODO: 準備中 + * @param s2StartIndex TODO: 準備中 + * @param size TODO: 準備中 + */ + public static void numByteMemcpy( + CobolDataStorage s1, + int s1StartIndex, + CobolDataStorage s2, + int s2StartIndex, + int size) { + int i1 = s1StartIndex; + int i2 = s2StartIndex; + do { + s1.setByte(i1++, s2.getByte(i2++)); + } while (--size != 0); + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolFieldAttribute.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolFieldAttribute.java index 24a81f64..72dcb386 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolFieldAttribute.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolFieldAttribute.java @@ -1,431 +1,450 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.data; - -/** TODO: 準備中 */ -public class CobolFieldAttribute { - - /* field types */ - - /** TODO: 準備中 */ - public static final int COB_TYPE_UNKNOWN = 0x00; - /** TODO: 準備中 */ - public static final int COB_TYPE_GROUP = 0x01; - /** TODO: 準備中 */ - public static final int COB_TYPE_BOOLEAN = 0x02; - - /** TODO: 準備中 */ - public static final int COB_TYPE_NUMERIC = 0x10; - /** TODO: 準備中 */ - public static final int COB_TYPE_NUMERIC_DISPLAY = 0x10; - /** TODO: 準備中 */ - public static final int COB_TYPE_NUMERIC_BINARY = 0x11; - /** TODO: 準備中 */ - public static final int COB_TYPE_NUMERIC_PACKED = 0x12; - /** TODO: 準備中 */ - public static final int COB_TYPE_NUMERIC_FLOAT = 0x13; - /** TODO: 準備中 */ - public static final int COB_TYPE_NUMERIC_DOUBLE = 0x14; - /** TODO: 準備中 */ - public static final int COB_TYPE_NUMERIC_EDITED = 0x24; - - /** TODO: 準備中 */ - public static final int COB_TYPE_ALPHANUMERIC = 0x21; - /** TODO: 準備中 */ - public static final int COB_TYPE_ALPHANUMERIC_ALL = 0x22; - /** TODO: 準備中 */ - public static final int COB_TYPE_ALPHANUMERIC_EDITED = 0x23; - - /** TODO: 準備中 */ - public static final int COB_TYPE_NATIONAL = 0x40; - /** TODO: 準備中 */ - public static final int COB_TYPE_NATIONAL_EDITED = 0x41; - /** TODO: 準備中 */ - public static final int COB_TYPE_NATIONAL_ALL = 0x42; - - /* field flags */ - - /** TODO: 準備中 */ - public static final int COB_FLAG_HAVE_SIGN = 0x01; - /** TODO: 準備中 */ - public static final int COB_FLAG_SIGN_SEPARATE = 0x02; - /** TODO: 準備中 */ - public static final int COB_FLAG_SIGN_LEADING = 0x04; - /** TODO: 準備中 */ - public static final int COB_FLAG_BLANK_ZERO = 0x08; - /** TODO: 準備中 */ - public static final int COB_FLAG_JUSTIFIED = 0x10; - /** TODO: 準備中 */ - public static final int COB_FLAG_BINARY_SWAP = 0x20; - /** TODO: 準備中 */ - public static final int COB_FLAG_REAL_BINARY = 0x40; - /** TODO: 準備中 */ - public static final int COB_FLAG_IS_POINTER = 0x80; - - /** 変数種別 */ - private int type; - - /** 数値の時,桁数を示す */ - private int digits; - - /** 数値の時,スケールを示す */ - private int scale; - - /** 様々なフラグ */ - private int flags; - - /** PICTURE句の文字列 */ - private String pic; - - /** - * コンストラクタ - * - * @param type フィールドの種別 - * @param digits 数値型のとき,桁数を表す - * @param scale 数値型の時,スケールを表す - * @param flags 各種フラグ - * @param pic PIC文字列 - */ - public CobolFieldAttribute(int type, int digits, int scale, int flags, String pic) { - this.type = type; - this.digits = digits; - this.scale = scale; - this.flags = flags; - this.pic = pic; - } - - /** - * TODO: 準備中 - * - * @param other TODO: 準備中 - */ - public CobolFieldAttribute(CobolFieldAttribute other) { - this.type = other.type; - this.digits = other.digits; - this.scale = other.scale; - this.flags = other.flags; - this.pic = other.pic; - } - - /** - * 変数種別を取得する - * - * @return このオブジェクトの変数種別 - */ - public int getType() { - return type; - } - - /** - * 変数種別を取得する - * - * @param type このオブジェクトに設定する変数種別 - */ - public void setType(int type) { - this.type = type; - } - - /** - * 桁数を取得する - * - * @return このオブジェクトの桁数 - */ - public int getDigits() { - return digits; - } - - /** - * 桁数を設定する - * - * @param digits このオブジェクトに設定する桁数 - */ - public void setDigits(int digits) { - this.digits = digits; - } - - /** - * このオブジェクトのスケールを取得する - * - * @return このオブジェクトのスケール - */ - public int getScale() { - return scale; - } - - /** - * このオブジェクトのスケールを設定する - * - * @param scale このオブジェクトに設定するスケール - */ - public void setScale(int scale) { - this.scale = scale; - } - - /** - * このオブジェクトのフラグを設定する - * - * @return このオブジェクトのフラグ - */ - public int getFlags() { - return this.flags; - } - - /** - * このオブジェクトのフラグを設定する - * - * @param flags このオブジェクトに設定するフラグ - */ - public void setFlags(int flags) { - this.flags = flags; - } - - /** - * このオブジェクトのPICTURE文字列を取得する - * - * @return このオブジェクトのPICTURE文字列 - */ - public String getPic() { - return pic; - } - - /** - * このオブジェクトのPICTURE文字列を設定する - * - * @param pic このオブジェクトに設定するPICTURE文字列 - */ - public void setPic(String pic) { - this.pic = pic; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isTypeUnknown() { - return type == COB_TYPE_UNKNOWN; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isTypeGroup() { - return type == COB_TYPE_GROUP; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isTypeBoolean() { - return type == COB_TYPE_BOOLEAN; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isTypeNumeric() { - return (type & COB_TYPE_NUMERIC) > 0; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isTypeNumericDisplay() { - return type == COB_TYPE_NUMERIC_DISPLAY; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isTypeNumericBinary() { - return type == COB_TYPE_NUMERIC_BINARY; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isTypeNumericPacked() { - return type == COB_TYPE_NUMERIC_PACKED; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isTypeNumericFloat() { - return type == COB_TYPE_NUMERIC_FLOAT; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isTypeNumericDouble() { - return type == COB_TYPE_NUMERIC_DOUBLE; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isTypeNumericEdited() { - return type == COB_TYPE_NUMERIC_EDITED; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isTypeAlphanum() { - return type == COB_TYPE_ALPHANUMERIC; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isTypeAlphanumAll() { - return type == COB_TYPE_ALPHANUMERIC_ALL; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isTypeAlphanumEdited() { - return type == COB_TYPE_ALPHANUMERIC_EDITED; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isTypeNational() { - return type == COB_TYPE_NATIONAL; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isTypeNationalEdited() { - return type == COB_TYPE_NATIONAL_EDITED; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isTypeNationalAll() { - return type == COB_TYPE_NATIONAL_ALL; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isFlagHaveSign() { - return (flags & COB_FLAG_HAVE_SIGN) != 0; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isFlagSignSeparate() { - return (flags & COB_FLAG_SIGN_SEPARATE) != 0; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isFlagSignLeading() { - return (flags & COB_FLAG_SIGN_LEADING) != 0; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isFlagBlankZero() { - return (flags & COB_FLAG_BLANK_ZERO) != 0; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isFlagJustified() { - return (flags & COB_FLAG_JUSTIFIED) != 0; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isFlagBinarySwap() { - return (flags & COB_FLAG_BINARY_SWAP) != 0; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isFlagRealBinary() { - return (flags & COB_FLAG_REAL_BINARY) != 0; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public boolean isFlagIsPointer() { - return (flags & COB_FLAG_IS_POINTER) != 0; - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.data; + +/** TODO: 準備中 */ +public class CobolFieldAttribute { + + /* field types */ + + /** TODO: 準備中 */ + public static final int COB_TYPE_UNKNOWN = 0x00; + + /** TODO: 準備中 */ + public static final int COB_TYPE_GROUP = 0x01; + + /** TODO: 準備中 */ + public static final int COB_TYPE_BOOLEAN = 0x02; + + /** TODO: 準備中 */ + public static final int COB_TYPE_NUMERIC = 0x10; + + /** TODO: 準備中 */ + public static final int COB_TYPE_NUMERIC_DISPLAY = 0x10; + + /** TODO: 準備中 */ + public static final int COB_TYPE_NUMERIC_BINARY = 0x11; + + /** TODO: 準備中 */ + public static final int COB_TYPE_NUMERIC_PACKED = 0x12; + + /** TODO: 準備中 */ + public static final int COB_TYPE_NUMERIC_FLOAT = 0x13; + + /** TODO: 準備中 */ + public static final int COB_TYPE_NUMERIC_DOUBLE = 0x14; + + /** TODO: 準備中 */ + public static final int COB_TYPE_NUMERIC_EDITED = 0x24; + + /** TODO: 準備中 */ + public static final int COB_TYPE_ALPHANUMERIC = 0x21; + + /** TODO: 準備中 */ + public static final int COB_TYPE_ALPHANUMERIC_ALL = 0x22; + + /** TODO: 準備中 */ + public static final int COB_TYPE_ALPHANUMERIC_EDITED = 0x23; + + /** TODO: 準備中 */ + public static final int COB_TYPE_NATIONAL = 0x40; + + /** TODO: 準備中 */ + public static final int COB_TYPE_NATIONAL_EDITED = 0x41; + + /** TODO: 準備中 */ + public static final int COB_TYPE_NATIONAL_ALL = 0x42; + + /* field flags */ + + /** TODO: 準備中 */ + public static final int COB_FLAG_HAVE_SIGN = 0x01; + + /** TODO: 準備中 */ + public static final int COB_FLAG_SIGN_SEPARATE = 0x02; + + /** TODO: 準備中 */ + public static final int COB_FLAG_SIGN_LEADING = 0x04; + + /** TODO: 準備中 */ + public static final int COB_FLAG_BLANK_ZERO = 0x08; + + /** TODO: 準備中 */ + public static final int COB_FLAG_JUSTIFIED = 0x10; + + /** TODO: 準備中 */ + public static final int COB_FLAG_BINARY_SWAP = 0x20; + + /** TODO: 準備中 */ + public static final int COB_FLAG_REAL_BINARY = 0x40; + + /** TODO: 準備中 */ + public static final int COB_FLAG_IS_POINTER = 0x80; + + /** 変数種別 */ + private int type; + + /** 数値の時,桁数を示す */ + private int digits; + + /** 数値の時,スケールを示す */ + private int scale; + + /** 様々なフラグ */ + private int flags; + + /** PICTURE句の文字列 */ + private String pic; + + /** + * コンストラクタ + * + * @param type フィールドの種別 + * @param digits 数値型のとき,桁数を表す + * @param scale 数値型の時,スケールを表す + * @param flags 各種フラグ + * @param pic PIC文字列 + */ + public CobolFieldAttribute(int type, int digits, int scale, int flags, String pic) { + this.type = type; + this.digits = digits; + this.scale = scale; + this.flags = flags; + this.pic = pic; + } + + /** + * TODO: 準備中 + * + * @param other TODO: 準備中 + */ + public CobolFieldAttribute(CobolFieldAttribute other) { + this.type = other.type; + this.digits = other.digits; + this.scale = other.scale; + this.flags = other.flags; + this.pic = other.pic; + } + + /** + * 変数種別を取得する + * + * @return このオブジェクトの変数種別 + */ + public int getType() { + return type; + } + + /** + * 変数種別を取得する + * + * @param type このオブジェクトに設定する変数種別 + */ + public void setType(int type) { + this.type = type; + } + + /** + * 桁数を取得する + * + * @return このオブジェクトの桁数 + */ + public int getDigits() { + return digits; + } + + /** + * 桁数を設定する + * + * @param digits このオブジェクトに設定する桁数 + */ + public void setDigits(int digits) { + this.digits = digits; + } + + /** + * このオブジェクトのスケールを取得する + * + * @return このオブジェクトのスケール + */ + public int getScale() { + return scale; + } + + /** + * このオブジェクトのスケールを設定する + * + * @param scale このオブジェクトに設定するスケール + */ + public void setScale(int scale) { + this.scale = scale; + } + + /** + * このオブジェクトのフラグを設定する + * + * @return このオブジェクトのフラグ + */ + public int getFlags() { + return this.flags; + } + + /** + * このオブジェクトのフラグを設定する + * + * @param flags このオブジェクトに設定するフラグ + */ + public void setFlags(int flags) { + this.flags = flags; + } + + /** + * このオブジェクトのPICTURE文字列を取得する + * + * @return このオブジェクトのPICTURE文字列 + */ + public String getPic() { + return pic; + } + + /** + * このオブジェクトのPICTURE文字列を設定する + * + * @param pic このオブジェクトに設定するPICTURE文字列 + */ + public void setPic(String pic) { + this.pic = pic; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isTypeUnknown() { + return type == COB_TYPE_UNKNOWN; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isTypeGroup() { + return type == COB_TYPE_GROUP; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isTypeBoolean() { + return type == COB_TYPE_BOOLEAN; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isTypeNumeric() { + return (type & COB_TYPE_NUMERIC) > 0; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isTypeNumericDisplay() { + return type == COB_TYPE_NUMERIC_DISPLAY; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isTypeNumericBinary() { + return type == COB_TYPE_NUMERIC_BINARY; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isTypeNumericPacked() { + return type == COB_TYPE_NUMERIC_PACKED; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isTypeNumericFloat() { + return type == COB_TYPE_NUMERIC_FLOAT; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isTypeNumericDouble() { + return type == COB_TYPE_NUMERIC_DOUBLE; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isTypeNumericEdited() { + return type == COB_TYPE_NUMERIC_EDITED; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isTypeAlphanum() { + return type == COB_TYPE_ALPHANUMERIC; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isTypeAlphanumAll() { + return type == COB_TYPE_ALPHANUMERIC_ALL; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isTypeAlphanumEdited() { + return type == COB_TYPE_ALPHANUMERIC_EDITED; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isTypeNational() { + return type == COB_TYPE_NATIONAL; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isTypeNationalEdited() { + return type == COB_TYPE_NATIONAL_EDITED; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isTypeNationalAll() { + return type == COB_TYPE_NATIONAL_ALL; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isFlagHaveSign() { + return (flags & COB_FLAG_HAVE_SIGN) != 0; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isFlagSignSeparate() { + return (flags & COB_FLAG_SIGN_SEPARATE) != 0; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isFlagSignLeading() { + return (flags & COB_FLAG_SIGN_LEADING) != 0; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isFlagBlankZero() { + return (flags & COB_FLAG_BLANK_ZERO) != 0; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isFlagJustified() { + return (flags & COB_FLAG_JUSTIFIED) != 0; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isFlagBinarySwap() { + return (flags & COB_FLAG_BINARY_SWAP) != 0; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isFlagRealBinary() { + return (flags & COB_FLAG_REAL_BINARY) != 0; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public boolean isFlagIsPointer() { + return (flags & COB_FLAG_IS_POINTER) != 0; + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolFieldFactory.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolFieldFactory.java index 4621be0a..9b6de1f6 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolFieldFactory.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolFieldFactory.java @@ -1,140 +1,147 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.data; - -import java.io.UnsupportedEncodingException; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; - -/** AbstractCobolFieldのサブクラスを生成するためのメソッドを定義するクラス */ -public class CobolFieldFactory { - - /** - * 引数に応じて適切なAbstractCobolFieldクラスのサブクラスを生成する。 - * 特にattrに設定された値に応じて適切なAbstractCobolFieldのサブクラスのインスタンスを生成する。 - * - * @param size データを保存するバイト領域の大きさ - * @param str データを保存する領域に書き込まれる初期データ - * @param attr 変数の様々な情報を格納するインスタンス - * @return attrの値に応じてインスタンス化されたAbstractCobolField型のデータ - */ - public static AbstractCobolField makeCobolField(int size, String str, CobolFieldAttribute attr) { - return CobolFieldFactory.makeCobolField(size, new CobolDataStorage(str), attr); - } - - /** - * TODO: 準備中 - * - * @param size TODO: 準備中 - * @param bytes TODO: 準備中 - * @param attr TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField makeCobolField( - int size, byte[] bytes, CobolFieldAttribute attr) { - return CobolFieldFactory.makeCobolField(size, new CobolDataStorage(bytes), attr); - } - - /** - * 引数に応じて適切なAbstractCobolFieldクラスのサブクラスを生成する。 - * 特にattrに設定された値に応じて適切なAbstractCobolFieldのサブクラスのインスタンスを生成する。 - * - * @param size データを保存するバイト領域の大きさ - * @param data データを保存する領域 - * @param attr 変数の様々な情報を格納するインスタンス - * @return attrの値に応じてインスタンス化されたAbstractCobolField型のデータ - */ - public static AbstractCobolField makeCobolField( - int size, CobolDataStorage data, CobolFieldAttribute attr) { - switch (attr.getType()) { - case CobolFieldAttribute.COB_TYPE_NUMERIC: - return new CobolNumericField(size, data, attr); - case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC: - return new CobolAlphanumericField(size, data, attr); - case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: - return new CobolNumericPackedField(size, data, attr); - case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: - return new CobolNumericBinaryField(size, data, attr); - case CobolFieldAttribute.COB_TYPE_NATIONAL: - return new CobolNationalField(size, data, attr); - case CobolFieldAttribute.COB_TYPE_GROUP: - return new CobolGroupField(size, data, attr); - case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_EDITED: - return new CobolAlphanumericEditedField(size, data, attr); - case CobolFieldAttribute.COB_TYPE_NUMERIC_EDITED: - return new CobolNumericEditedField(size, data, attr); - case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: - return new CobolNationalEditedField(size, data, attr); - case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_ALL: - return new CobolAlphanumericAllField(size, data, attr); - case CobolFieldAttribute.COB_TYPE_NATIONAL_ALL: - return new CobolNationalAllField(size, data, attr); - case CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE: - return new CobolNumericDoubleField(size, data, attr); - default: - throw new CobolRuntimeException(0, "This data type is not implemented."); - } - } - - /** - * TODO: 準備中 - * - * @param size TODO: 準備中 - * @param data TODO: 準備中 - * @param attr TODO: 準備中 - * @return TODO: 準備中 - */ - public static AbstractCobolField makeCobolField( - long size, CobolDataStorage data, CobolFieldAttribute attr) { - return CobolFieldFactory.makeCobolField((int) size, data, attr); - } - - /** - * AbstractCobolFieldのインスタンスを生成する - * - * @param str 文字列データ - * @return strの値を保持するCobolAlphanumericFieldのインスタンス - */ - public static AbstractCobolField makeCobolField(String str) { - byte[] bytes; - try { - bytes = str.getBytes("SJIS"); - } catch (UnsupportedEncodingException e) { - return null; - } - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); - return new CobolAlphanumericField(bytes.length, new CobolDataStorage(bytes), attr); - } - - /** - * CobolNumericFieldのインスタンスを生成する - * - * @param n int型整数値 - * @return nの値を保持するCobolNumericFieldのインスタンス - */ - public static AbstractCobolField makeCobolField(int n) { - int size = (int) (Math.log10(n) + 1); - byte[] bytes = new byte[size]; - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC, size, 0, 0, null); - AbstractCobolField field = new CobolNumericField(size, new CobolDataStorage(bytes), attr); - field.setInt(n); - return field; - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.data; + +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; + +/** AbstractCobolFieldのサブクラスを生成するためのメソッドを定義するクラス */ +public class CobolFieldFactory { + + /** + * 引数に応じて適切なAbstractCobolFieldクラスのサブクラスを生成する。 + * 特にattrに設定された値に応じて適切なAbstractCobolFieldのサブクラスのインスタンスを生成する。 + * + * @param size データを保存するバイト領域の大きさ + * @param str データを保存する領域に書き込まれる初期データ + * @param attr 変数の様々な情報を格納するインスタンス + * @return attrの値に応じてインスタンス化されたAbstractCobolField型のデータ + */ + public static AbstractCobolField makeCobolField( + int size, String str, CobolFieldAttribute attr) { + return CobolFieldFactory.makeCobolField(size, new CobolDataStorage(str), attr); + } + + /** + * TODO: 準備中 + * + * @param size TODO: 準備中 + * @param bytes TODO: 準備中 + * @param attr TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField makeCobolField( + int size, byte[] bytes, CobolFieldAttribute attr) { + return CobolFieldFactory.makeCobolField(size, new CobolDataStorage(bytes), attr); + } + + /** + * TODO: 準備中 + * + * @param bytes TODO: 準備中 + * @param attr TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField makeCobolField(byte[] bytes, CobolFieldAttribute attr) { + return CobolFieldFactory.makeCobolField(bytes.length, new CobolDataStorage(bytes), attr); + } + + /** + * 引数に応じて適切なAbstractCobolFieldクラスのサブクラスを生成する。 + * 特にattrに設定された値に応じて適切なAbstractCobolFieldのサブクラスのインスタンスを生成する。 + * + * @param size データを保存するバイト領域の大きさ + * @param data データを保存する領域 + * @param attr 変数の様々な情報を格納するインスタンス + * @return attrの値に応じてインスタンス化されたAbstractCobolField型のデータ + */ + public static AbstractCobolField makeCobolField( + int size, CobolDataStorage data, CobolFieldAttribute attr) { + switch (attr.getType()) { + case CobolFieldAttribute.COB_TYPE_NUMERIC: + return new CobolNumericField(size, data, attr); + case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC: + return new CobolAlphanumericField(size, data, attr); + case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: + return new CobolNumericPackedField(size, data, attr); + case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: + return new CobolNumericBinaryField(size, data, attr); + case CobolFieldAttribute.COB_TYPE_NATIONAL: + return new CobolNationalField(size, data, attr); + case CobolFieldAttribute.COB_TYPE_GROUP: + return new CobolGroupField(size, data, attr); + case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_EDITED: + return new CobolAlphanumericEditedField(size, data, attr); + case CobolFieldAttribute.COB_TYPE_NUMERIC_EDITED: + return new CobolNumericEditedField(size, data, attr); + case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: + return new CobolNationalEditedField(size, data, attr); + case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_ALL: + return new CobolAlphanumericAllField(size, data, attr); + case CobolFieldAttribute.COB_TYPE_NATIONAL_ALL: + return new CobolNationalAllField(size, data, attr); + case CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE: + return new CobolNumericDoubleField(size, data, attr); + default: + throw new CobolRuntimeException(0, "This data type is not implemented."); + } + } + + /** + * TODO: 準備中 + * + * @param size TODO: 準備中 + * @param data TODO: 準備中 + * @param attr TODO: 準備中 + * @return TODO: 準備中 + */ + public static AbstractCobolField makeCobolField( + long size, CobolDataStorage data, CobolFieldAttribute attr) { + return CobolFieldFactory.makeCobolField((int) size, data, attr); + } + + /** + * AbstractCobolFieldのインスタンスを生成する + * + * @param str 文字列データ + * @return strの値を保持するCobolAlphanumericFieldのインスタンス + */ + public static AbstractCobolField makeCobolField(String str) { + byte[] bytes; + bytes = str.getBytes(AbstractCobolField.charSetSJIS); + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); + return new CobolAlphanumericField(bytes.length, new CobolDataStorage(bytes), attr); + } + + /** + * CobolNumericFieldのインスタンスを生成する + * + * @param n int型整数値 + * @return nの値を保持するCobolNumericFieldのインスタンス + */ + public static AbstractCobolField makeCobolField(int n) { + int size = (int) (Math.log10(n) + 1); + byte[] bytes = new byte[size]; + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC, size, 0, 0, null); + AbstractCobolField field = new CobolNumericField(size, new CobolDataStorage(bytes), attr); + field.setInt(n); + return field; + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolGroupField.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolGroupField.java index 95a60337..a9172d10 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolGroupField.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolGroupField.java @@ -18,97 +18,88 @@ */ package jp.osscons.opensourcecobol.libcobj.data; -import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; /** 集団項目を扱う */ public class CobolGroupField extends AbstractCobolField { - /** - * コンストラクタ - * - * @param size データを格納するバイト配列の長さ - * @param dataStorage データを格納するバイト配列を扱うオブジェクト - * @param attribute 変数に関する様々な情報を保持するオブジェクト - */ - public CobolGroupField(int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { - super(size, dataStorage, attribute); - } - - @Override - public byte[] getBytes() { - return dataStorage.getData(size); - } - - @Override - public String getString() { - try { - return new String(dataStorage.getData(), "SJIS"); - } catch (UnsupportedEncodingException e) { - return ""; + /** + * コンストラクタ + * + * @param size データを格納するバイト配列の長さ + * @param dataStorage データを格納するバイト配列を扱うオブジェクト + * @param attribute 変数に関する様々な情報を保持するオブジェクト + */ + public CobolGroupField(int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { + super(size, dataStorage, attribute); } - } - - @Override - public int getInt() { - return 0; - } - - @Override - public CobolDecimal getDecimal() { - return null; - } - - @Override - public void setDecimal(BigDecimal decimal) {} - - @Override - public void moveFrom(AbstractCobolField src) { - AbstractCobolField src1 = this.preprocessOfMoving(src); - if (src1 == null) { - return; + + @Override + public byte[] getBytes() { + return dataStorage.getData(size); } - CobolAlphanumericField.moveAlphanumToAlphanum(this, src1); - } + @Override + public String getString() { + return new String(dataStorage.getData(), AbstractCobolField.charSetSJIS); + } - @Override - public void moveFrom(CobolDataStorage dataStorage) {} + @Override + public int getInt() { + return 0; + } - @Override - public void moveFrom(byte[] bytes) { - if (bytes.length >= this.size) { - this.dataStorage.setBytes(bytes, this.size); - } else { - this.dataStorage.setBytes(bytes, bytes.length); - this.dataStorage.fillBytes(bytes.length, (byte) 0x20, this.size); + @Override + public CobolDecimal getDecimal() { + return null; } - } - - @Override - public void moveFrom(String string) { - byte[] bytes; - try { - bytes = string.getBytes("SJIS"); - } catch (UnsupportedEncodingException e) { - return; + + @Override + public void setDecimal(BigDecimal decimal) {} + + @Override + public void moveFrom(AbstractCobolField src) { + AbstractCobolField src1 = this.preprocessOfMoving(src); + if (src1 == null) { + return; + } + + CobolAlphanumericField.moveAlphanumToAlphanum(this, src1); } - this.moveFrom(bytes); - } + @Override + public void moveFrom(CobolDataStorage dataStorage) {} + + @Override + public void moveFrom(byte[] bytes) { + if (bytes.length >= this.size) { + this.dataStorage.setBytes(bytes, this.size); + } else { + this.dataStorage.setBytes(bytes, bytes.length); + this.dataStorage.fillBytes(bytes.length, (byte) 0x20, this.size); + } + } + + @Override + public void moveFrom(String string) { + byte[] bytes; + bytes = string.getBytes(AbstractCobolField.charSetSJIS); - @Override - public void moveFrom(int number) {} + this.moveFrom(bytes); + } - @Override - public void moveFrom(double number) {} + @Override + public void moveFrom(int number) {} - @Override - public void moveFrom(BigDecimal number) {} + @Override + public void moveFrom(double number) {} - @Override - public int addPackedInt(int n) { - throw new CobolRuntimeException(0, "実装しないコード"); - } + @Override + public void moveFrom(BigDecimal number) {} + + @Override + public int addPackedInt(int n) { + throw new CobolRuntimeException(0, "実装しないコード"); + } } diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNationalAllField.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNationalAllField.java index 9315470e..c2cab3f1 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNationalAllField.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNationalAllField.java @@ -1,34 +1,34 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.data; - -/** TODO: 準備中 */ -public class CobolNationalAllField extends CobolNationalField { - /** - * コンストラクタ - * - * @param size データを格納するバイト配列の長さ - * @param dataStorage データを格納するバイト配列を扱うオブジェクト - * @param attribute 変数に関する様々な情報を保持するオブジェクト - */ - public CobolNationalAllField( - int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { - super(size, dataStorage, attribute); - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.data; + +/** TODO: 準備中 */ +public class CobolNationalAllField extends CobolNationalField { + /** + * コンストラクタ + * + * @param size データを格納するバイト配列の長さ + * @param dataStorage データを格納するバイト配列を扱うオブジェクト + * @param attribute 変数に関する様々な情報を保持するオブジェクト + */ + public CobolNationalAllField( + int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { + super(size, dataStorage, attribute); + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNationalEditedField.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNationalEditedField.java index b2cb726c..d832f73c 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNationalEditedField.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNationalEditedField.java @@ -1,151 +1,151 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.data; - -import java.math.BigDecimal; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import jp.osscons.opensourcecobol.libcobj.common.CobolConstant; - -/** TODO: 準備中 */ -public class CobolNationalEditedField extends AbstractCobolField { - /** - * コンストラクタ - * - * @param size データを格納するバイト配列の長さ - * @param dataStorage データを格納するバイト配列を扱うオブジェクト - * @param attribute 変数に関する様々な情報を保持するオブジェクト - */ - public CobolNationalEditedField( - int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { - super(size, dataStorage, attribute); - } - - @Override - public byte[] getBytes() { - return new byte[0]; - } - - @Override - public String getString() { - return null; - } - - @Override - public CobolDecimal getDecimal() { - return null; - } - - @Override - public void setDecimal(BigDecimal decimal) {} - - @Override - public int addPackedInt(int n) { - return 0; - } - - @Override - public void moveFrom(AbstractCobolField src) { - AbstractCobolField src1 = this.preprocessOfMoving(src); - if (src1 == null) { - return; - } - - switch (src1.getAttribute().getType()) { - case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: - case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: - case CobolFieldAttribute.COB_TYPE_NUMERIC_FLOAT: - case CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE: - this.moveFrom(src1.getNumericField()); - break; - case CobolFieldAttribute.COB_TYPE_GROUP: - CobolAlphanumericField.moveAlphanumToAlphanum(this, src1); - break; - default: - this.moveAlphanumToNationalEdited(src1); - break; - } - } - - private void moveAlphanumToNationalEdited(AbstractCobolField src) { - CobolDataStorage srcd = src.getDataStorage(); - CobolDataStorage dstd = this.getDataStorage(); - int srcp = src.getFirstDataIndex(); - int dstp = 0; - int max = src.getFieldSize(); - dstd.memset((byte) ' ', this.getSize()); - - final int sizeOfInt = 4; - - byte[] picBytes = this.getAttribute().getPic().getBytes(); - for (int p = 0; p < picBytes.length; ) { - byte c = picBytes[p++]; - ByteBuffer buf = ByteBuffer.wrap(picBytes, p, sizeOfInt); - buf.order(ByteOrder.LITTLE_ENDIAN); - int n = buf.getInt(); - p += sizeOfInt; - for (; n > 0; --n) { - switch (c) { - case 'N': - if (srcp < max) { - dstd.setByte(dstp++, srcd.getByte(srcp++)); - dstd.setByte(dstp++, srcd.getByte(srcp++)); - } else { - dstd.memcpy(dstp, CobolConstant.ZENBLK, CobolConstant.ZENCSIZ); - dstp += CobolConstant.ZENCSIZ; - } - break; - case '/': - dstd.memcpy(dstp, CobolConstant.ZENSLAS, CobolConstant.ZENCSIZ); - dstp += CobolConstant.ZENCSIZ; - break; - case 'B': - dstd.memcpy(dstp, CobolConstant.ZENSPC, CobolConstant.ZENCSIZ); - dstp += CobolConstant.ZENCSIZ; - break; - case '0': - dstd.memcpy(dstp, CobolConstant.ZENZERO, CobolConstant.ZENCSIZ); - dstp += CobolConstant.ZENCSIZ; - break; - default: - dstd.setByte(dstp++, (byte) '?'); - break; - } - } - } - } - - @Override - public void moveFrom(CobolDataStorage dataStrage) {} - - @Override - public void moveFrom(byte[] bytes) {} - - @Override - public void moveFrom(String string) {} - - @Override - public void moveFrom(int number) {} - - @Override - public void moveFrom(double number) {} - - @Override - public void moveFrom(BigDecimal number) {} -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.data; + +import java.math.BigDecimal; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import jp.osscons.opensourcecobol.libcobj.common.CobolConstant; + +/** TODO: 準備中 */ +public class CobolNationalEditedField extends AbstractCobolField { + /** + * コンストラクタ + * + * @param size データを格納するバイト配列の長さ + * @param dataStorage データを格納するバイト配列を扱うオブジェクト + * @param attribute 変数に関する様々な情報を保持するオブジェクト + */ + public CobolNationalEditedField( + int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { + super(size, dataStorage, attribute); + } + + @Override + public byte[] getBytes() { + return new byte[0]; + } + + @Override + public String getString() { + return null; + } + + @Override + public CobolDecimal getDecimal() { + return null; + } + + @Override + public void setDecimal(BigDecimal decimal) {} + + @Override + public int addPackedInt(int n) { + return 0; + } + + @Override + public void moveFrom(AbstractCobolField src) { + AbstractCobolField src1 = this.preprocessOfMoving(src); + if (src1 == null) { + return; + } + + switch (src1.getAttribute().getType()) { + case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: + case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: + case CobolFieldAttribute.COB_TYPE_NUMERIC_FLOAT: + case CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE: + this.moveFrom(src1.getNumericField()); + break; + case CobolFieldAttribute.COB_TYPE_GROUP: + CobolAlphanumericField.moveAlphanumToAlphanum(this, src1); + break; + default: + this.moveAlphanumToNationalEdited(src1); + break; + } + } + + private void moveAlphanumToNationalEdited(AbstractCobolField src) { + CobolDataStorage srcd = src.getDataStorage(); + CobolDataStorage dstd = this.getDataStorage(); + int srcp = src.getFirstDataIndex(); + int dstp = 0; + int max = src.getFieldSize(); + dstd.memset((byte) ' ', this.getSize()); + + final int sizeOfInt = 4; + + byte[] picBytes = this.getAttribute().getPic().getBytes(AbstractCobolField.charSetSJIS); + for (int p = 0; p < picBytes.length; ) { + byte c = picBytes[p++]; + ByteBuffer buf = ByteBuffer.wrap(picBytes, p, sizeOfInt); + buf.order(ByteOrder.LITTLE_ENDIAN); + int n = buf.getInt(); + p += sizeOfInt; + for (; n > 0; --n) { + switch (c) { + case 'N': + if (srcp < max) { + dstd.setByte(dstp++, srcd.getByte(srcp++)); + dstd.setByte(dstp++, srcd.getByte(srcp++)); + } else { + dstd.memcpy(dstp, CobolConstant.ZENBLK, CobolConstant.ZENCSIZ); + dstp += CobolConstant.ZENCSIZ; + } + break; + case '/': + dstd.memcpy(dstp, CobolConstant.ZENSLAS, CobolConstant.ZENCSIZ); + dstp += CobolConstant.ZENCSIZ; + break; + case 'B': + dstd.memcpy(dstp, CobolConstant.ZENSPC, CobolConstant.ZENCSIZ); + dstp += CobolConstant.ZENCSIZ; + break; + case '0': + dstd.memcpy(dstp, CobolConstant.ZENZERO, CobolConstant.ZENCSIZ); + dstp += CobolConstant.ZENCSIZ; + break; + default: + dstd.setByte(dstp++, (byte) '?'); + break; + } + } + } + } + + @Override + public void moveFrom(CobolDataStorage dataStrage) {} + + @Override + public void moveFrom(byte[] bytes) {} + + @Override + public void moveFrom(String string) {} + + @Override + public void moveFrom(int number) {} + + @Override + public void moveFrom(double number) {} + + @Override + public void moveFrom(BigDecimal number) {} +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNationalField.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNationalField.java index dff31984..95c8de22 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNationalField.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNationalField.java @@ -1,1086 +1,1079 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.data; - -import java.io.UnsupportedEncodingException; -import java.math.BigDecimal; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; - -/** PIC 文字列がN(5)やN(9)の変数を表現するクラス. */ -public class CobolNationalField extends AbstractCobolField { - - /** TODO: 準備中 */ - public static int workReturnSize; - - /** - * コンストラクタ - * - * @param size データを格納するバイト配列の長さ - * @param dataStorage データを格納するバイト配列を扱うオブジェクト - * @param attribute 変数に関する様々な情報を保持するオブジェクト - */ - public CobolNationalField(int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { - super(size, dataStorage, attribute); - } - - @Override - public byte[] getBytes() { - return dataStorage.getData(size); - } - - @Override - public String getString() { - try { - return new String(dataStorage.getData(), "SJIS"); - } catch (UnsupportedEncodingException e) { - return ""; - } - } - - @Override - public int getInt() { - return 0; - } - - @Override - public CobolDecimal getDecimal() { - return null; - } - - @Override - public int addPackedInt(int n) { - throw new CobolRuntimeException(0, "実装しないコード"); - } - - @Override - public void moveFrom(AbstractCobolField src) { - - byte[] pTmp; - int size; - AbstractCobolField src2; - - AbstractCobolField src1 = this.preprocessOfMoving(src); - if (src1 == null) { - return; - } - - // Convert Numeric - switch (src1.getAttribute().getType()) { - case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: - case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: - case CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE: - case CobolFieldAttribute.COB_TYPE_NUMERIC_FLOAT: - src1 = src1.getNumericField(); - break; - default: - break; - } - - // HANKAKU TO ZENKAKU - if (!src1.getAttribute().isTypeNational() && !src1.getAttribute().isTypeNationalEdited()) { - workReturnSize = 0; - pTmp = judge_hankakujpn_exist(src1); - size = workReturnSize; - CobolDataStorage pTmpStorage = new CobolDataStorage(size); - pTmpStorage.setBytes(pTmp, size); - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); - src2 = new CobolAlphanumericField(size, pTmpStorage, attr); - } else { - src2 = src1; - } - - cob_move_from_alphanum(src2); - } - - /** - * CobolAlphanumericFieldからthisへの代入を行う - * - * @param field 代入元のデータ(AbstractCobolField型) - */ - private void cob_move_from_alphanum(AbstractCobolField field) { - // TODO UTF8対応 - CobolDataStorage data1; - CobolDataStorage data2; - int size1; - int size2; - int len; - // TODO - final int cobZenCSiz = 2; - final byte[] cobZenBlk = {(byte) 0x81, (byte) 0x40}; - - data1 = field.getDataStorage(); - size1 = field.getSize(); - data2 = this.getDataStorage(); - size2 = this.getSize(); - - len = size2 - size1; - - if (size1 >= size2) { - /* move string with truncation */ - if (this.getAttribute().isFlagJustified()) { - data2.setBytes(data1, size2, 0, size1 - size2); - } else { - data2.setBytes(data1, size2); - } - } else { - data2.fillBytes((byte) 0x20, size2); - if (this.getAttribute().isFlagJustified()) { - for (int i = 0; i < len; i += cobZenCSiz) { - if (len - i >= cobZenCSiz) { - data2.setBytes(i, cobZenBlk, cobZenCSiz); - } - } - data2.getSubDataStorage(len).memcpy(data1, size1); - } else { - for (int i = 0; i < len; i += cobZenCSiz) { - if (len - i >= cobZenCSiz) { - data2.setBytes(i + size1, cobZenBlk, cobZenCSiz); - } - } - data2.setBytes(data1, size1); - } - } - } - - /** - * TODO: 準備中 - * - * @param src TODO: 準備中 - * @return TODO: 準備中 - */ - public static byte[] judge_hankakujpn_exist(AbstractCobolField src) { - byte[] tmpZenJpnWord = null; - - if (src.getSize() <= 0) { - return null; - } - // TODO データのStrlenの差し替え - if (src.getDataStorage().getByte(0) != 0) { - tmpZenJpnWord = han2zen(src.getDataStorage().getData(), src.getSize()); - } - return tmpZenJpnWord; - } - - /** - * TODO: 準備中 - * - * @param str TODO: 準備中 - * @param size TODO: 準備中 - * @return TODO: 準備中 - */ - public static byte[] han2zen(byte[] str, int size) { - byte[] buf; - - int c; - int d = (byte) 0x00; - int i, buIndex; - - buf = new byte[size * 2 + 1]; - - for (i = 0, buIndex = 0; i < size; i++) { - c = Byte.toUnsignedInt(str[i]); - switch (c) { - case 0x20: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x40; - buIndex += 2; - break; - case 0x21: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x49; - buIndex += 2; - break; - case 0x22: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x68; - buIndex += 2; - break; - case 0x23: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x94; - buIndex += 2; - break; - case 0x24: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x90; - buIndex += 2; - break; - case 0x25: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x93; - buIndex += 2; - break; - case 0x26: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x95; - buIndex += 2; - break; - case 0x27: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x66; - buIndex += 2; - break; - case 0x28: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x69; - buIndex += 2; - break; - case 0x29: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x6A; - buIndex += 2; - break; - case 0x2A: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x96; - buIndex += 2; - break; - case 0x2B: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x7B; - buIndex += 2; - break; - case 0x2C: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x43; - buIndex += 2; - break; - case 0x2D: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x7C; - buIndex += 2; - break; - case 0x2E: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x44; - buIndex += 2; - break; - case 0x2F: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x5E; - buIndex += 2; - break; - case 0x30: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x4F; - buIndex += 2; - break; - case 0x31: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x50; - buIndex += 2; - break; - case 0x32: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x51; - buIndex += 2; - break; - case 0x33: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x52; - buIndex += 2; - break; - case 0x34: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x53; - buIndex += 2; - break; - case 0x35: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x54; - buIndex += 2; - break; - case 0x36: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x55; - buIndex += 2; - break; - case 0x37: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x56; - buIndex += 2; - break; - case 0x38: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x57; - buIndex += 2; - break; - case 0x39: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x58; - buIndex += 2; - break; - case 0x3A: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x46; - buIndex += 2; - break; - case 0x3B: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x47; - buIndex += 2; - break; - case 0x3C: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x83; - buIndex += 2; - break; - case 0x3D: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x81; - buIndex += 2; - break; - case 0x3E: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x84; - buIndex += 2; - break; - case 0x3F: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x48; - buIndex += 2; - break; - case 0x40: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x97; - buIndex += 2; - break; - case 0x41: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x60; - buIndex += 2; - break; - case 0x42: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x61; - buIndex += 2; - break; - case 0x43: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x62; - buIndex += 2; - break; - case 0x44: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x63; - buIndex += 2; - break; - case 0x45: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x64; - buIndex += 2; - break; - case 0x46: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x65; - buIndex += 2; - break; - case 0x47: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x66; - buIndex += 2; - break; - case 0x48: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x67; - buIndex += 2; - break; - case 0x49: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x68; - buIndex += 2; - break; - case 0x4A: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x69; - buIndex += 2; - break; - case 0x4B: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x6A; - buIndex += 2; - break; - case 0x4C: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x6B; - buIndex += 2; - break; - case 0x4D: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x6C; - buIndex += 2; - break; - case 0x4E: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x6D; - buIndex += 2; - break; - case 0x4F: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x6E; - buIndex += 2; - break; - case 0x50: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x6F; - buIndex += 2; - break; - case 0x51: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x70; - buIndex += 2; - break; - case 0x52: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x71; - buIndex += 2; - break; - case 0x53: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x72; - buIndex += 2; - break; - case 0x54: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x73; - buIndex += 2; - break; - case 0x55: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x74; - buIndex += 2; - break; - case 0x56: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x75; - buIndex += 2; - break; - case 0x57: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x76; - buIndex += 2; - break; - case 0x58: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x77; - buIndex += 2; - break; - case 0x59: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x78; - buIndex += 2; - break; - case 0x5A: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x79; - buIndex += 2; - break; - case 0x5B: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x6D; - buIndex += 2; - break; - case 0x5C: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x8F; - buIndex += 2; - break; - case 0x5D: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x6E; - buIndex += 2; - break; - case 0x5E: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x4F; - buIndex += 2; - break; - case 0x5F: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x51; - buIndex += 2; - break; - case 0x60: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x65; - buIndex += 2; - break; - case 0x61: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x81; - buIndex += 2; - break; - case 0x62: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x82; - buIndex += 2; - break; - case 0x63: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x83; - buIndex += 2; - break; - case 0x64: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x84; - buIndex += 2; - break; - case 0x65: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x85; - buIndex += 2; - break; - case 0x66: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x86; - buIndex += 2; - break; - case 0x67: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x87; - buIndex += 2; - break; - case 0x68: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x88; - buIndex += 2; - break; - case 0x69: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x89; - buIndex += 2; - break; - case 0x6A: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x8A; - buIndex += 2; - break; - case 0x6B: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x8B; - buIndex += 2; - break; - case 0x6C: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x8C; - buIndex += 2; - break; - case 0x6D: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x8D; - buIndex += 2; - break; - case 0x6E: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x8E; - buIndex += 2; - break; - case 0x6F: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x8F; - buIndex += 2; - break; - case 0x70: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x90; - buIndex += 2; - break; - case 0x71: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x91; - buIndex += 2; - break; - case 0x72: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x92; - buIndex += 2; - break; - case 0x73: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x93; - buIndex += 2; - break; - case 0x74: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x94; - buIndex += 2; - break; - case 0x75: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x95; - buIndex += 2; - break; - case 0x76: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x96; - buIndex += 2; - break; - case 0x77: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x97; - buIndex += 2; - break; - case 0x78: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x98; - buIndex += 2; - break; - case 0x79: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x99; - buIndex += 2; - break; - case 0x7A: - buf[buIndex] = (byte) 0x82; - buf[buIndex + 1] = (byte) 0x9A; - buIndex += 2; - break; - case 0x7B: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x6F; - buIndex += 2; - break; - case 0x7C: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x62; - buIndex += 2; - break; - case 0x7D: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x70; - buIndex += 2; - break; - case 0x7E: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x60; - buIndex += 2; - break; - case 0xA1: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x42; - buIndex += 2; - break; - case 0xA2: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x75; - buIndex += 2; - break; - case 0xA3: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x76; - buIndex += 2; - break; - case 0xA4: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x41; - buIndex += 2; - break; - case 0xA5: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x45; - buIndex += 2; - break; - case 0xA6: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x92; - buIndex += 2; - break; - case 0xA7: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x40; - buIndex += 2; - break; - case 0xA8: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x42; - buIndex += 2; - break; - case 0xA9: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x44; - buIndex += 2; - break; - case 0xAA: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x46; - buIndex += 2; - break; - case 0xAB: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x48; - buIndex += 2; - break; - case 0xAC: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x83; - buIndex += 2; - break; - case 0xAD: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x85; - buIndex += 2; - break; - case 0xAE: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x87; - buIndex += 2; - break; - case 0xAF: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x62; - buIndex += 2; - break; - case 0xB0: - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x5B; - buIndex += 2; - break; - case 0xB1: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x41; - buIndex += 2; - break; - case 0xB2: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x43; - buIndex += 2; - break; - case 0xB3: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x45; - buIndex += 2; - break; - case 0xB4: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x47; - buIndex += 2; - break; - case 0xB5: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x49; - buIndex += 2; - break; - case 0xB6: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x4A; - buIndex += 2; - break; - case 0xB7: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x4C; - buIndex += 2; - break; - case 0xB8: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x4E; - buIndex += 2; - break; - case 0xB9: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x50; - buIndex += 2; - break; - case 0xBA: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x52; - buIndex += 2; - break; - case 0xBB: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x54; - buIndex += 2; - break; - case 0xBC: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x56; - buIndex += 2; - break; - case 0xBD: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x58; - buIndex += 2; - break; - case 0xBE: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x5A; - buIndex += 2; - break; - case 0xBF: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x5C; - buIndex += 2; - break; - case 0xC0: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x5E; - buIndex += 2; - break; - case 0xC1: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x60; - buIndex += 2; - break; - case 0xC2: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x63; - buIndex += 2; - break; - case 0xC3: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x65; - buIndex += 2; - break; - case 0xC4: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x67; - buIndex += 2; - break; - case 0xC5: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x69; - buIndex += 2; - break; - case 0xC6: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x6A; - buIndex += 2; - break; - case 0xC7: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x6B; - buIndex += 2; - break; - case 0xC8: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x6C; - buIndex += 2; - break; - case 0xC9: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x6D; - buIndex += 2; - break; - case 0xCA: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x6E; - buIndex += 2; - break; - case 0xCB: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x71; - buIndex += 2; - break; - case 0xCC: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x74; - buIndex += 2; - break; - case 0xCD: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x77; - buIndex += 2; - break; - case 0xCE: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x7A; - buIndex += 2; - break; - case 0xCF: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x7D; - buIndex += 2; - break; - case 0xD0: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x7E; - buIndex += 2; - break; - case 0xD1: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x80; - buIndex += 2; - break; - case 0xD2: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x81; - buIndex += 2; - break; - case 0xD3: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x82; - buIndex += 2; - break; - case 0xD4: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x84; - buIndex += 2; - break; - case 0xD5: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x86; - buIndex += 2; - break; - case 0xD6: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x88; - buIndex += 2; - break; - case 0xD7: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x89; - buIndex += 2; - break; - case 0xD8: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x8A; - buIndex += 2; - break; - case 0xD9: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x8B; - buIndex += 2; - break; - case 0xDA: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x8C; - buIndex += 2; - break; - case 0xDB: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x8D; - buIndex += 2; - break; - case 0xDC: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x8F; - buIndex += 2; - break; - case 0xDD: - buf[buIndex] = (byte) 0x83; - buf[buIndex + 1] = (byte) 0x93; - buIndex += 2; - break; - case 0xDE: - /* Dakuten */ - if ((d >= 0xB6 && d <= 0xC4) || (d >= 0xCA && d <= 0xCE)) { - buf[buIndex - 1]++; - } else if (d == 0xB3) { - buf[buIndex - 1] = (byte) 0x94; - } else { - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x4A; - buIndex += 2; - } - break; - case 0xDF: - /* Han-dakuten */ - if (d >= 0xCA && d <= 0xCE) { - buf[buIndex - 1] += 2; - } else { - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x4B; - buIndex += 2; - } - break; - case 0: - case 255: - buf[buIndex] = (byte) c; - buIndex++; - buf[buIndex] = (byte) c; - buIndex++; - if (i + 1 < size) { - if (str[i + 1] == str[i]) { - i++; - } - } - break; - default: - if ((byte) 0 < c && c < (byte) 0x20) { - // #define COB_SJSPC "\x81\x40" - buf[buIndex] = (byte) 0x81; - buf[buIndex + 1] = (byte) 0x40; - buIndex += 2; - } else { - buf[buIndex] = str[i]; - buIndex++; - i++; - buf[buIndex] = str[i]; - buIndex++; - } - break; - } - d = c; - } - buf[buIndex] = (byte) 0x00; - workReturnSize = buIndex; - return buf; - } - - @Override - public void moveFrom(CobolDataStorage dataStorage) {} - - @Override - public void moveFrom(byte[] bytes) { - dataStorage.setBytes(bytes); - } - - @Override - public void moveFrom(String string) { - try { - byte[] bytes = string.getBytes("SJIS"); - CobolDataStorage data = new CobolDataStorage(bytes); - CobolFieldAttribute a = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); - CobolAlphanumericField f = new CobolAlphanumericField(bytes.length, data, a); - this.moveFrom(f); - } catch (UnsupportedEncodingException e) { - return; - } - } - - @Override - public void moveFrom(int number) {} - - @Override - public void moveFrom(double number) {} - - @Override - public void moveFrom(BigDecimal number) {} - - @Override - public void setDecimal(BigDecimal decimal) {} - - @Override - public CobolNumericField getNumericField() { - int size = this.getSize() / 2; - int scale = this.getAttribute().getScale(); - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, - size, - scale, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - CobolDataStorage data = new CobolDataStorage(size); - CobolNumericField field = new CobolNumericField(size, data, attr); - field.moveFrom(this); - return field; - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.data; + +import java.math.BigDecimal; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; + +/** PIC 文字列がN(5)やN(9)の変数を表現するクラス. */ +public class CobolNationalField extends AbstractCobolField { + + /** TODO: 準備中 */ + public static int workReturnSize; + + /** + * コンストラクタ + * + * @param size データを格納するバイト配列の長さ + * @param dataStorage データを格納するバイト配列を扱うオブジェクト + * @param attribute 変数に関する様々な情報を保持するオブジェクト + */ + public CobolNationalField( + int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { + super(size, dataStorage, attribute); + } + + @Override + public byte[] getBytes() { + return dataStorage.getData(size); + } + + @Override + public String getString() { + return new String(dataStorage.getData(), AbstractCobolField.charSetSJIS); + } + + @Override + public int getInt() { + return 0; + } + + @Override + public CobolDecimal getDecimal() { + return null; + } + + @Override + public int addPackedInt(int n) { + throw new CobolRuntimeException(0, "実装しないコード"); + } + + @Override + public void moveFrom(AbstractCobolField src) { + + byte[] pTmp; + int size; + AbstractCobolField src2; + + AbstractCobolField src1 = this.preprocessOfMoving(src); + if (src1 == null) { + return; + } + + // Convert Numeric + switch (src1.getAttribute().getType()) { + case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: + case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: + case CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE: + case CobolFieldAttribute.COB_TYPE_NUMERIC_FLOAT: + src1 = src1.getNumericField(); + break; + default: + break; + } + + // HANKAKU TO ZENKAKU + if (!src1.getAttribute().isTypeNational() && !src1.getAttribute().isTypeNationalEdited()) { + workReturnSize = 0; + pTmp = judge_hankakujpn_exist(src1); + size = workReturnSize; + CobolDataStorage pTmpStorage = new CobolDataStorage(size); + pTmpStorage.setBytes(pTmp, size); + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); + src2 = new CobolAlphanumericField(size, pTmpStorage, attr); + } else { + src2 = src1; + } + + cob_move_from_alphanum(src2); + } + + /** + * CobolAlphanumericFieldからthisへの代入を行う + * + * @param field 代入元のデータ(AbstractCobolField型) + */ + private void cob_move_from_alphanum(AbstractCobolField field) { + // TODO UTF8対応 + CobolDataStorage data1; + CobolDataStorage data2; + int size1; + int size2; + int len; + // TODO + final int cobZenCSiz = 2; + final byte[] cobZenBlk = {(byte) 0x81, (byte) 0x40}; + + data1 = field.getDataStorage(); + size1 = field.getSize(); + data2 = this.getDataStorage(); + size2 = this.getSize(); + + len = size2 - size1; + + if (size1 >= size2) { + /* move string with truncation */ + if (this.getAttribute().isFlagJustified()) { + data2.setBytes(data1, size2, 0, size1 - size2); + } else { + data2.setBytes(data1, size2); + } + } else { + data2.fillBytes((byte) 0x20, size2); + if (this.getAttribute().isFlagJustified()) { + for (int i = 0; i < len; i += cobZenCSiz) { + if (len - i >= cobZenCSiz) { + data2.setBytes(i, cobZenBlk, cobZenCSiz); + } + } + data2.getSubDataStorage(len).memcpy(data1, size1); + } else { + for (int i = 0; i < len; i += cobZenCSiz) { + if (len - i >= cobZenCSiz) { + data2.setBytes(i + size1, cobZenBlk, cobZenCSiz); + } + } + data2.setBytes(data1, size1); + } + } + } + + /** + * TODO: 準備中 + * + * @param src TODO: 準備中 + * @return TODO: 準備中 + */ + public static byte[] judge_hankakujpn_exist(AbstractCobolField src) { + byte[] tmpZenJpnWord = null; + + if (src.getSize() <= 0) { + return null; + } + // TODO データのStrlenの差し替え + if (src.getDataStorage().getByte(0) != 0) { + tmpZenJpnWord = han2zen(src.getDataStorage().getData(), src.getSize()); + } + return tmpZenJpnWord; + } + + /** + * TODO: 準備中 + * + * @param str TODO: 準備中 + * @param size TODO: 準備中 + * @return TODO: 準備中 + */ + public static byte[] han2zen(byte[] str, int size) { + byte[] buf; + + int c; + int d = (byte) 0x00; + int i, buIndex; + + buf = new byte[size * 2 + 1]; + + for (i = 0, buIndex = 0; i < size; i++) { + c = Byte.toUnsignedInt(str[i]); + switch (c) { + case 0x20: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x40; + buIndex += 2; + break; + case 0x21: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x49; + buIndex += 2; + break; + case 0x22: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x68; + buIndex += 2; + break; + case 0x23: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x94; + buIndex += 2; + break; + case 0x24: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x90; + buIndex += 2; + break; + case 0x25: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x93; + buIndex += 2; + break; + case 0x26: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x95; + buIndex += 2; + break; + case 0x27: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x66; + buIndex += 2; + break; + case 0x28: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x69; + buIndex += 2; + break; + case 0x29: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x6A; + buIndex += 2; + break; + case 0x2A: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x96; + buIndex += 2; + break; + case 0x2B: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x7B; + buIndex += 2; + break; + case 0x2C: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x43; + buIndex += 2; + break; + case 0x2D: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x7C; + buIndex += 2; + break; + case 0x2E: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x44; + buIndex += 2; + break; + case 0x2F: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x5E; + buIndex += 2; + break; + case 0x30: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x4F; + buIndex += 2; + break; + case 0x31: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x50; + buIndex += 2; + break; + case 0x32: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x51; + buIndex += 2; + break; + case 0x33: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x52; + buIndex += 2; + break; + case 0x34: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x53; + buIndex += 2; + break; + case 0x35: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x54; + buIndex += 2; + break; + case 0x36: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x55; + buIndex += 2; + break; + case 0x37: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x56; + buIndex += 2; + break; + case 0x38: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x57; + buIndex += 2; + break; + case 0x39: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x58; + buIndex += 2; + break; + case 0x3A: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x46; + buIndex += 2; + break; + case 0x3B: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x47; + buIndex += 2; + break; + case 0x3C: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x83; + buIndex += 2; + break; + case 0x3D: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x81; + buIndex += 2; + break; + case 0x3E: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x84; + buIndex += 2; + break; + case 0x3F: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x48; + buIndex += 2; + break; + case 0x40: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x97; + buIndex += 2; + break; + case 0x41: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x60; + buIndex += 2; + break; + case 0x42: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x61; + buIndex += 2; + break; + case 0x43: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x62; + buIndex += 2; + break; + case 0x44: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x63; + buIndex += 2; + break; + case 0x45: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x64; + buIndex += 2; + break; + case 0x46: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x65; + buIndex += 2; + break; + case 0x47: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x66; + buIndex += 2; + break; + case 0x48: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x67; + buIndex += 2; + break; + case 0x49: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x68; + buIndex += 2; + break; + case 0x4A: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x69; + buIndex += 2; + break; + case 0x4B: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x6A; + buIndex += 2; + break; + case 0x4C: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x6B; + buIndex += 2; + break; + case 0x4D: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x6C; + buIndex += 2; + break; + case 0x4E: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x6D; + buIndex += 2; + break; + case 0x4F: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x6E; + buIndex += 2; + break; + case 0x50: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x6F; + buIndex += 2; + break; + case 0x51: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x70; + buIndex += 2; + break; + case 0x52: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x71; + buIndex += 2; + break; + case 0x53: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x72; + buIndex += 2; + break; + case 0x54: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x73; + buIndex += 2; + break; + case 0x55: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x74; + buIndex += 2; + break; + case 0x56: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x75; + buIndex += 2; + break; + case 0x57: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x76; + buIndex += 2; + break; + case 0x58: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x77; + buIndex += 2; + break; + case 0x59: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x78; + buIndex += 2; + break; + case 0x5A: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x79; + buIndex += 2; + break; + case 0x5B: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x6D; + buIndex += 2; + break; + case 0x5C: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x8F; + buIndex += 2; + break; + case 0x5D: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x6E; + buIndex += 2; + break; + case 0x5E: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x4F; + buIndex += 2; + break; + case 0x5F: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x51; + buIndex += 2; + break; + case 0x60: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x65; + buIndex += 2; + break; + case 0x61: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x81; + buIndex += 2; + break; + case 0x62: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x82; + buIndex += 2; + break; + case 0x63: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x83; + buIndex += 2; + break; + case 0x64: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x84; + buIndex += 2; + break; + case 0x65: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x85; + buIndex += 2; + break; + case 0x66: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x86; + buIndex += 2; + break; + case 0x67: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x87; + buIndex += 2; + break; + case 0x68: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x88; + buIndex += 2; + break; + case 0x69: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x89; + buIndex += 2; + break; + case 0x6A: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x8A; + buIndex += 2; + break; + case 0x6B: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x8B; + buIndex += 2; + break; + case 0x6C: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x8C; + buIndex += 2; + break; + case 0x6D: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x8D; + buIndex += 2; + break; + case 0x6E: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x8E; + buIndex += 2; + break; + case 0x6F: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x8F; + buIndex += 2; + break; + case 0x70: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x90; + buIndex += 2; + break; + case 0x71: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x91; + buIndex += 2; + break; + case 0x72: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x92; + buIndex += 2; + break; + case 0x73: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x93; + buIndex += 2; + break; + case 0x74: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x94; + buIndex += 2; + break; + case 0x75: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x95; + buIndex += 2; + break; + case 0x76: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x96; + buIndex += 2; + break; + case 0x77: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x97; + buIndex += 2; + break; + case 0x78: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x98; + buIndex += 2; + break; + case 0x79: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x99; + buIndex += 2; + break; + case 0x7A: + buf[buIndex] = (byte) 0x82; + buf[buIndex + 1] = (byte) 0x9A; + buIndex += 2; + break; + case 0x7B: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x6F; + buIndex += 2; + break; + case 0x7C: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x62; + buIndex += 2; + break; + case 0x7D: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x70; + buIndex += 2; + break; + case 0x7E: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x60; + buIndex += 2; + break; + case 0xA1: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x42; + buIndex += 2; + break; + case 0xA2: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x75; + buIndex += 2; + break; + case 0xA3: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x76; + buIndex += 2; + break; + case 0xA4: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x41; + buIndex += 2; + break; + case 0xA5: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x45; + buIndex += 2; + break; + case 0xA6: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x92; + buIndex += 2; + break; + case 0xA7: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x40; + buIndex += 2; + break; + case 0xA8: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x42; + buIndex += 2; + break; + case 0xA9: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x44; + buIndex += 2; + break; + case 0xAA: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x46; + buIndex += 2; + break; + case 0xAB: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x48; + buIndex += 2; + break; + case 0xAC: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x83; + buIndex += 2; + break; + case 0xAD: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x85; + buIndex += 2; + break; + case 0xAE: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x87; + buIndex += 2; + break; + case 0xAF: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x62; + buIndex += 2; + break; + case 0xB0: + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x5B; + buIndex += 2; + break; + case 0xB1: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x41; + buIndex += 2; + break; + case 0xB2: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x43; + buIndex += 2; + break; + case 0xB3: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x45; + buIndex += 2; + break; + case 0xB4: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x47; + buIndex += 2; + break; + case 0xB5: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x49; + buIndex += 2; + break; + case 0xB6: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x4A; + buIndex += 2; + break; + case 0xB7: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x4C; + buIndex += 2; + break; + case 0xB8: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x4E; + buIndex += 2; + break; + case 0xB9: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x50; + buIndex += 2; + break; + case 0xBA: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x52; + buIndex += 2; + break; + case 0xBB: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x54; + buIndex += 2; + break; + case 0xBC: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x56; + buIndex += 2; + break; + case 0xBD: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x58; + buIndex += 2; + break; + case 0xBE: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x5A; + buIndex += 2; + break; + case 0xBF: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x5C; + buIndex += 2; + break; + case 0xC0: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x5E; + buIndex += 2; + break; + case 0xC1: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x60; + buIndex += 2; + break; + case 0xC2: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x63; + buIndex += 2; + break; + case 0xC3: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x65; + buIndex += 2; + break; + case 0xC4: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x67; + buIndex += 2; + break; + case 0xC5: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x69; + buIndex += 2; + break; + case 0xC6: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x6A; + buIndex += 2; + break; + case 0xC7: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x6B; + buIndex += 2; + break; + case 0xC8: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x6C; + buIndex += 2; + break; + case 0xC9: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x6D; + buIndex += 2; + break; + case 0xCA: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x6E; + buIndex += 2; + break; + case 0xCB: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x71; + buIndex += 2; + break; + case 0xCC: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x74; + buIndex += 2; + break; + case 0xCD: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x77; + buIndex += 2; + break; + case 0xCE: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x7A; + buIndex += 2; + break; + case 0xCF: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x7D; + buIndex += 2; + break; + case 0xD0: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x7E; + buIndex += 2; + break; + case 0xD1: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x80; + buIndex += 2; + break; + case 0xD2: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x81; + buIndex += 2; + break; + case 0xD3: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x82; + buIndex += 2; + break; + case 0xD4: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x84; + buIndex += 2; + break; + case 0xD5: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x86; + buIndex += 2; + break; + case 0xD6: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x88; + buIndex += 2; + break; + case 0xD7: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x89; + buIndex += 2; + break; + case 0xD8: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x8A; + buIndex += 2; + break; + case 0xD9: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x8B; + buIndex += 2; + break; + case 0xDA: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x8C; + buIndex += 2; + break; + case 0xDB: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x8D; + buIndex += 2; + break; + case 0xDC: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x8F; + buIndex += 2; + break; + case 0xDD: + buf[buIndex] = (byte) 0x83; + buf[buIndex + 1] = (byte) 0x93; + buIndex += 2; + break; + case 0xDE: + /* Dakuten */ + if ((d >= 0xB6 && d <= 0xC4) || (d >= 0xCA && d <= 0xCE)) { + buf[buIndex - 1]++; + } else if (d == 0xB3) { + buf[buIndex - 1] = (byte) 0x94; + } else { + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x4A; + buIndex += 2; + } + break; + case 0xDF: + /* Han-dakuten */ + if (d >= 0xCA && d <= 0xCE) { + buf[buIndex - 1] += 2; + } else { + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x4B; + buIndex += 2; + } + break; + case 0: + case 255: + buf[buIndex] = (byte) c; + buIndex++; + buf[buIndex] = (byte) c; + buIndex++; + if (i + 1 < size) { + if (str[i + 1] == str[i]) { + i++; + } + } + break; + default: + if ((byte) 0 < c && c < (byte) 0x20) { + // #define COB_SJSPC "\x81\x40" + buf[buIndex] = (byte) 0x81; + buf[buIndex + 1] = (byte) 0x40; + buIndex += 2; + } else { + buf[buIndex] = str[i]; + buIndex++; + i++; + buf[buIndex] = str[i]; + buIndex++; + } + break; + } + d = c; + } + buf[buIndex] = (byte) 0x00; + workReturnSize = buIndex; + return buf; + } + + @Override + public void moveFrom(CobolDataStorage dataStorage) {} + + @Override + public void moveFrom(byte[] bytes) { + dataStorage.setBytes(bytes); + } + + @Override + public void moveFrom(String string) { + byte[] bytes = string.getBytes(AbstractCobolField.charSetSJIS); + CobolDataStorage data = new CobolDataStorage(bytes); + CobolFieldAttribute a = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null); + CobolAlphanumericField f = new CobolAlphanumericField(bytes.length, data, a); + this.moveFrom(f); + } + + @Override + public void moveFrom(int number) {} + + @Override + public void moveFrom(double number) {} + + @Override + public void moveFrom(BigDecimal number) {} + + @Override + public void setDecimal(BigDecimal decimal) {} + + @Override + public CobolNumericField getNumericField() { + int size = this.getSize() / 2; + int scale = this.getAttribute().getScale(); + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, + size, + scale, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + CobolDataStorage data = new CobolDataStorage(size); + CobolNumericField field = new CobolNumericField(size, data, attr); + field.moveFrom(this); + return field; + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericBinaryField.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericBinaryField.java index a4e8c553..4038b79d 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericBinaryField.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericBinaryField.java @@ -1,271 +1,271 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.data; - -import java.math.BigDecimal; -import java.nio.ByteBuffer; -import jp.osscons.opensourcecobol.libcobj.common.CobolConstant; -import jp.osscons.opensourcecobol.libcobj.common.CobolModule; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; - -/** TODO: 準備中 */ -public class CobolNumericBinaryField extends AbstractCobolField { - - /** - * コンストラクタ - * - * @param size データを格納するバイト配列の長さ - * @param dataStorage データを格納するバイト配列を扱うオブジェクト - * @param attribute 変数に関する様々な情報を保持するオブジェクト - */ - public CobolNumericBinaryField( - int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { - super(size, dataStorage, attribute); - } - - @Override - public byte[] getBytes() { - return new byte[0]; - } - - @Override - public int addPackedInt(int n) { - throw new CobolRuntimeException(0, "実装しないコード"); - } - - private long getBinaryValue() { - CobolDataStorage storage = this.getDataStorage(); - if (this.size == 1) { - return storage.getByte(0); - } else if (this.size == 2) { - return storage.shortValue(); - } else if (this.size == 4) { - return storage.intValue(); - } else { - return storage.longValue(); - } - } - - private void setBinaryValue(long n) { - CobolDataStorage storage = this.getDataStorage(); - if (this.size == 1) { - storage.setByte(0, (byte) n); - } else if (this.size == 2) { - storage.set((short) n); - } else if (this.size == 4) { - storage.set((int) n); - } else { - storage.set((long) n); - } - } - - @Override - public long getLongValue() { - return this.getBinaryValue(); - } - - /** - * TODO: 準備中 - * - * @param n TODO: 準備中 - */ - public void setLongValue(long n) { - this.setBinaryValue(n); - } - - @Override - public String getString() { - CobolFieldAttribute thisAttr = this.getAttribute(); - int flag = thisAttr.isFlagHaveSign() ? CobolFieldAttribute.COB_FLAG_HAVE_SIGN : 0; - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC, - thisAttr.getDigits(), - thisAttr.getScale(), - flag, - thisAttr.getPic()); - CobolDataStorage storage = new CobolDataStorage(thisAttr.getDigits()); - CobolNumericField numericField = new CobolNumericField(thisAttr.getDigits(), storage, attr); - numericField.moveFrom(this); - return numericField.getString(); - } - - @Override - public int getSign() { - long n = this.getBinaryValue(); - - if (n < 0) { - return -1; - } else if (n > 0) { - return 1; - } else { - return 0; - } - } - - @Override - public void setDecimal(BigDecimal decimal) {} - - @Override - public void moveFrom(AbstractCobolField src) { - AbstractCobolField src1 = this.preprocessOfMoving(src); - if (src1 == null) { - return; - } - - switch (src1.getAttribute().getType()) { - case CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY: - this.moveDisplayToBinary(src1); - break; - case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: - case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC: - case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_EDITED: - case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: - case CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE: - case CobolFieldAttribute.COB_TYPE_NUMERIC_FLOAT: - case CobolFieldAttribute.COB_TYPE_NATIONAL: - case CobolFieldAttribute.COB_TYPE_NUMERIC_EDITED: - case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: - this.moveFrom(src1.getNumericField()); - break; - case CobolFieldAttribute.COB_TYPE_GROUP: - CobolAlphanumericField.moveAlphanumToAlphanum(this, src1); - break; - default: - throw new CobolRuntimeException(0, "未実装"); - } - } - - /** - * CobolNumericFieldからからthisへの代入 - * - * @param field 代入元のデータ(AbstractCobolField型) - */ - private void moveDisplayToBinary(AbstractCobolField field) { - int size1 = field.getFieldSize(); - int data1Index = field.getFirstDataIndex(); - int sign = field.getSign(); - - CobolDataStorage data1 = field.getDataStorage(); - CobolDataStorage data2 = this.getDataStorage(); - - boolean flagNull = true; - for (int i = 0; i < size1; ++i) { - if (data1.getByte(data1Index + i) != 0) { - flagNull = false; - } - } - if (flagNull) { - for (int i = 0; i < this.getSize(); ++i) { - data2.setByte(i, (byte) 0); - } - } - - int size = size1 - field.getAttribute().getScale() + this.getAttribute().getScale(); - long val = 0; - for (int i = 0; i < size; ++i) { - if (i < size1) { - byte x = data1.getByte(data1Index + i); - x = (byte) (x >= (byte) 0x70 ? x - (byte) 0x70 : x - (byte) 0x30); - val = val * 10 + x; - } else { - val = val * 10; - } - } - - if (sign < 0 && this.getAttribute().isFlagHaveSign()) { - val = -val; - } - - if (CobolModule.getCurrentModule().flag_binary_truncate != 0 - && !this.getAttribute().isFlagRealBinary()) { - val %= CobolConstant.exp10LL[this.getAttribute().getDigits()]; - } - - this.setBinaryValue(val); - field.putSign(sign); - } - - @Override - public void moveFrom(CobolDataStorage dataStorage) {} - - @Override - public void moveFrom(byte[] bytes) {} - - @Override - public void moveFrom(String string) {} - - @Override - public void moveFrom(int number) { - this.getDataStorage().setSwpU32Binary(number); - } - - @Override - public void moveFrom(double number) {} - - @Override - public void moveFrom(BigDecimal number) {} - - @Override - public CobolNumericField getNumericField() { - int size = this.getAttribute().getDigits(); - int scale = this.getAttribute().getScale(); - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, - size, - scale, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - CobolDataStorage data = new CobolDataStorage(this.getAttribute().getDigits()); - CobolNumericField field = new CobolNumericField(size, data, attr); - field.moveFrom(this); - return field; - } - - @Override - public CobolDecimal getDecimal() { - CobolDecimal decimal = new CobolDecimal(); - decimal.setValue(new BigDecimal(this.getBinaryValue())); - decimal.setScale(this.getAttribute().getScale()); - return decimal; - } - - // libcob/numeric.cのcob_binary_get_int64の実装 - private long binaryGetInt64() { - int fsiz = 8 - this.getSize(); - long n = 0; - byte[] nBytes = ByteBuffer.allocate(8).putLong(n).array(); - CobolDataStorage nStorage = new CobolDataStorage(nBytes); - if (this.getAttribute().isFlagHaveSign()) { - CobolDecimal.numByteMemcpy(nStorage, 0, this.getDataStorage(), 0, this.getSize()); - n = ByteBuffer.wrap(nStorage.getByteArray(0, 8)).getLong(); - n >>>= 8 * fsiz; - } else { - CobolDecimal.numByteMemcpy(nStorage, fsiz, this.getDataStorage(), 0, this.getSize()); - n = ByteBuffer.wrap(nStorage.getByteArray(0, 8)).getLong(); - } - return n; - } - - @Override - public long getLong() { - return this.binaryGetInt64(); - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.data; + +import java.math.BigDecimal; +import java.nio.ByteBuffer; +import jp.osscons.opensourcecobol.libcobj.common.CobolConstant; +import jp.osscons.opensourcecobol.libcobj.common.CobolModule; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; + +/** TODO: 準備中 */ +public class CobolNumericBinaryField extends AbstractCobolField { + + /** + * コンストラクタ + * + * @param size データを格納するバイト配列の長さ + * @param dataStorage データを格納するバイト配列を扱うオブジェクト + * @param attribute 変数に関する様々な情報を保持するオブジェクト + */ + public CobolNumericBinaryField( + int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { + super(size, dataStorage, attribute); + } + + @Override + public byte[] getBytes() { + return new byte[0]; + } + + @Override + public int addPackedInt(int n) { + throw new CobolRuntimeException(0, "実装しないコード"); + } + + private long getBinaryValue() { + CobolDataStorage storage = this.getDataStorage(); + if (this.size == 1) { + return storage.getByte(0); + } else if (this.size == 2) { + return storage.shortValue(); + } else if (this.size == 4) { + return storage.intValue(); + } else { + return storage.longValue(); + } + } + + private void setBinaryValue(long n) { + CobolDataStorage storage = this.getDataStorage(); + if (this.size == 1) { + storage.setByte(0, (byte) n); + } else if (this.size == 2) { + storage.set((short) n); + } else if (this.size == 4) { + storage.set((int) n); + } else { + storage.set((long) n); + } + } + + @Override + public long getLongValue() { + return this.getBinaryValue(); + } + + /** + * TODO: 準備中 + * + * @param n TODO: 準備中 + */ + public void setLongValue(long n) { + this.setBinaryValue(n); + } + + @Override + public String getString() { + CobolFieldAttribute thisAttr = this.getAttribute(); + int flag = thisAttr.isFlagHaveSign() ? CobolFieldAttribute.COB_FLAG_HAVE_SIGN : 0; + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC, + thisAttr.getDigits(), + thisAttr.getScale(), + flag, + thisAttr.getPic()); + CobolDataStorage storage = new CobolDataStorage(thisAttr.getDigits()); + CobolNumericField numericField = new CobolNumericField(thisAttr.getDigits(), storage, attr); + numericField.moveFrom(this); + return numericField.getString(); + } + + @Override + public int getSign() { + long n = this.getBinaryValue(); + + if (n < 0) { + return -1; + } else if (n > 0) { + return 1; + } else { + return 0; + } + } + + @Override + public void setDecimal(BigDecimal decimal) {} + + @Override + public void moveFrom(AbstractCobolField src) { + AbstractCobolField src1 = this.preprocessOfMoving(src); + if (src1 == null) { + return; + } + + switch (src1.getAttribute().getType()) { + case CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY: + this.moveDisplayToBinary(src1); + break; + case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: + case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC: + case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_EDITED: + case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: + case CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE: + case CobolFieldAttribute.COB_TYPE_NUMERIC_FLOAT: + case CobolFieldAttribute.COB_TYPE_NATIONAL: + case CobolFieldAttribute.COB_TYPE_NUMERIC_EDITED: + case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: + this.moveFrom(src1.getNumericField()); + break; + case CobolFieldAttribute.COB_TYPE_GROUP: + CobolAlphanumericField.moveAlphanumToAlphanum(this, src1); + break; + default: + throw new CobolRuntimeException(0, "未実装"); + } + } + + /** + * CobolNumericFieldからからthisへの代入 + * + * @param field 代入元のデータ(AbstractCobolField型) + */ + private void moveDisplayToBinary(AbstractCobolField field) { + int size1 = field.getFieldSize(); + int data1Index = field.getFirstDataIndex(); + int sign = field.getSign(); + + CobolDataStorage data1 = field.getDataStorage(); + CobolDataStorage data2 = this.getDataStorage(); + + boolean flagNull = true; + for (int i = 0; i < size1; ++i) { + if (data1.getByte(data1Index + i) != 0) { + flagNull = false; + } + } + if (flagNull) { + for (int i = 0; i < this.getSize(); ++i) { + data2.setByte(i, (byte) 0); + } + } + + int size = size1 - field.getAttribute().getScale() + this.getAttribute().getScale(); + long val = 0; + for (int i = 0; i < size; ++i) { + if (i < size1) { + byte x = data1.getByte(data1Index + i); + x = (byte) (x >= (byte) 0x70 ? x - (byte) 0x70 : x - (byte) 0x30); + val = val * 10 + x; + } else { + val = val * 10; + } + } + + if (sign < 0 && this.getAttribute().isFlagHaveSign()) { + val = -val; + } + + if (CobolModule.getCurrentModule().flag_binary_truncate != 0 + && !this.getAttribute().isFlagRealBinary()) { + val %= CobolConstant.exp10LL[this.getAttribute().getDigits()]; + } + + this.setBinaryValue(val); + field.putSign(sign); + } + + @Override + public void moveFrom(CobolDataStorage dataStorage) {} + + @Override + public void moveFrom(byte[] bytes) {} + + @Override + public void moveFrom(String string) {} + + @Override + public void moveFrom(int number) { + this.getDataStorage().setSwpU32Binary(number); + } + + @Override + public void moveFrom(double number) {} + + @Override + public void moveFrom(BigDecimal number) {} + + @Override + public CobolNumericField getNumericField() { + int size = this.getAttribute().getDigits(); + int scale = this.getAttribute().getScale(); + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, + size, + scale, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + CobolDataStorage data = new CobolDataStorage(this.getAttribute().getDigits()); + CobolNumericField field = new CobolNumericField(size, data, attr); + field.moveFrom(this); + return field; + } + + @Override + public CobolDecimal getDecimal() { + CobolDecimal decimal = new CobolDecimal(); + decimal.setValue(new BigDecimal(this.getBinaryValue())); + decimal.setScale(this.getAttribute().getScale()); + return decimal; + } + + // libcob/numeric.cのcob_binary_get_int64の実装 + private long binaryGetInt64() { + int fsiz = 8 - this.getSize(); + long n = 0; + byte[] nBytes = ByteBuffer.allocate(8).putLong(n).array(); + CobolDataStorage nStorage = new CobolDataStorage(nBytes); + if (this.getAttribute().isFlagHaveSign()) { + CobolDecimal.numByteMemcpy(nStorage, 0, this.getDataStorage(), 0, this.getSize()); + n = ByteBuffer.wrap(nStorage.getByteArray(0, 8)).getLong(); + n >>>= 8 * fsiz; + } else { + CobolDecimal.numByteMemcpy(nStorage, fsiz, this.getDataStorage(), 0, this.getSize()); + n = ByteBuffer.wrap(nStorage.getByteArray(0, 8)).getLong(); + } + return n; + } + + @Override + public long getLong() { + return this.binaryGetInt64(); + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericDoubleField.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericDoubleField.java index af26db19..31c57c10 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericDoubleField.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericDoubleField.java @@ -1,186 +1,186 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.data; - -import java.math.BigDecimal; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; - -/** TODO: 準備中 */ -public class CobolNumericDoubleField extends AbstractCobolField { - - /** - * TODO: 準備中 - * - * @param size TODO: 準備中 - * @param dataStorage TODO: 準備中 - * @param attribute TODO: 準備中 - */ - public CobolNumericDoubleField( - int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { - super(size, dataStorage, attribute); - } - - private double getBinaryValue() { - CobolDataStorage storage = this.getDataStorage(); - return storage.doubleValue(); - } - - @Override - public byte[] getBytes() { - return new byte[0]; - } - - @Override - public String getString() { - return String.format("%.18f", this.getDouble()); - } - - @Override - public int getSign() { - double n = this.getBinaryValue(); - - if (n < 0) { - return -1; - } else if (n > 0) { - return 1; - } else { - return 0; - } - } - - @Override - public double getDouble() { - return this.getBinaryValue(); - } - - @Override - public void setDecimal(BigDecimal decimal) { - // TODO Auto-generated method stub - } - - @Override - public int addPackedInt(int n) { - throw new CobolRuntimeException(0, "実装しないコード"); - } - - @Override - public void moveFrom(AbstractCobolField src) { - AbstractCobolField src1 = this.preprocessOfMoving(src); - if (src1 == null) { - return; - } - - switch (src1.getAttribute().getType()) { - case CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY: - this.moveDisplayToDouble(src1); - break; - case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: - case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC: - case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_EDITED: - case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: - case CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE: - case CobolFieldAttribute.COB_TYPE_NUMERIC_FLOAT: - case CobolFieldAttribute.COB_TYPE_NATIONAL: - case CobolFieldAttribute.COB_TYPE_NUMERIC_EDITED: - case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: - this.moveFrom(src1.getNumericField()); - break; - case CobolFieldAttribute.COB_TYPE_GROUP: - CobolAlphanumericField.moveAlphanumToAlphanum(this, src1); - break; - default: - throw new CobolRuntimeException(0, "未実装"); - } - } - - /** - * TODO: 準備中 - * - * @param src TODO: 準備中 - */ - public void moveDisplayToDouble(AbstractCobolField src) { - double dval = 0; - CobolDataStorage storage = src.getDataStorage(); - for (int i = 0; i < src.getSize(); ++i) { - byte c = storage.getByte(i); - if (c == (byte) '-' || c == (byte) '+') { - continue; - } - dval *= 10; - dval += c >= 0x70 ? c - 0x70 : c - 0x30; - } - int scale = src.getAttribute().getScale(); - for (int i = 0; i < Math.abs(scale); ++i) { - if (scale < 0) { - dval *= 10; - } else { - dval /= 10; - } - } - if (src.getSign() < 0) { - dval *= -1; - } - this.getDataStorage().set(dval); - } - - @Override - public CobolNumericField getNumericField() { - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, - 40, - 20, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - CobolDataStorage storage = new CobolDataStorage(40); - double dval = Math.abs(this.getBinaryValue()); - String dataString = String.format("%041.20f", dval).replace(".", ""); - storage.memcpy(dataString, 40); - AbstractCobolField field = CobolFieldFactory.makeCobolField(40, storage, attr); - if (this.getSign() >= 0) { - field.putSign(1); - } else { - field.putSign(-1); - } - return (CobolNumericField) field; - } - - @Override - public CobolDecimal getDecimal() { - return new CobolDecimal(BigDecimal.valueOf(this.getBinaryValue()), 0); - } - - @Override - public void moveFrom(byte[] bytes) {} - - @Override - public void moveFrom(String string) {} - - @Override - public void moveFrom(int number) {} - - @Override - public void moveFrom(double number) {} - - @Override - public void moveFrom(BigDecimal number) {} - - @Override - public void moveFrom(CobolDataStorage dataStrage) {} -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.data; + +import java.math.BigDecimal; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; + +/** TODO: 準備中 */ +public class CobolNumericDoubleField extends AbstractCobolField { + + /** + * TODO: 準備中 + * + * @param size TODO: 準備中 + * @param dataStorage TODO: 準備中 + * @param attribute TODO: 準備中 + */ + public CobolNumericDoubleField( + int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { + super(size, dataStorage, attribute); + } + + private double getBinaryValue() { + CobolDataStorage storage = this.getDataStorage(); + return storage.doubleValue(); + } + + @Override + public byte[] getBytes() { + return new byte[0]; + } + + @Override + public String getString() { + return String.format("%.18f", this.getDouble()); + } + + @Override + public int getSign() { + double n = this.getBinaryValue(); + + if (n < 0) { + return -1; + } else if (n > 0) { + return 1; + } else { + return 0; + } + } + + @Override + public double getDouble() { + return this.getBinaryValue(); + } + + @Override + public void setDecimal(BigDecimal decimal) { + // TODO Auto-generated method stub + } + + @Override + public int addPackedInt(int n) { + throw new CobolRuntimeException(0, "実装しないコード"); + } + + @Override + public void moveFrom(AbstractCobolField src) { + AbstractCobolField src1 = this.preprocessOfMoving(src); + if (src1 == null) { + return; + } + + switch (src1.getAttribute().getType()) { + case CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY: + this.moveDisplayToDouble(src1); + break; + case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: + case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC: + case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_EDITED: + case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: + case CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE: + case CobolFieldAttribute.COB_TYPE_NUMERIC_FLOAT: + case CobolFieldAttribute.COB_TYPE_NATIONAL: + case CobolFieldAttribute.COB_TYPE_NUMERIC_EDITED: + case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: + this.moveFrom(src1.getNumericField()); + break; + case CobolFieldAttribute.COB_TYPE_GROUP: + CobolAlphanumericField.moveAlphanumToAlphanum(this, src1); + break; + default: + throw new CobolRuntimeException(0, "未実装"); + } + } + + /** + * TODO: 準備中 + * + * @param src TODO: 準備中 + */ + public void moveDisplayToDouble(AbstractCobolField src) { + double dval = 0; + CobolDataStorage storage = src.getDataStorage(); + for (int i = 0; i < src.getSize(); ++i) { + byte c = storage.getByte(i); + if (c == (byte) '-' || c == (byte) '+') { + continue; + } + dval *= 10; + dval += c >= 0x70 ? c - 0x70 : c - 0x30; + } + int scale = src.getAttribute().getScale(); + for (int i = 0; i < Math.abs(scale); ++i) { + if (scale < 0) { + dval *= 10; + } else { + dval /= 10; + } + } + if (src.getSign() < 0) { + dval *= -1; + } + this.getDataStorage().set(dval); + } + + @Override + public CobolNumericField getNumericField() { + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, + 40, + 20, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + CobolDataStorage storage = new CobolDataStorage(40); + double dval = Math.abs(this.getBinaryValue()); + String dataString = String.format("%041.20f", dval).replace(".", ""); + storage.memcpy(dataString, 40); + AbstractCobolField field = CobolFieldFactory.makeCobolField(40, storage, attr); + if (this.getSign() >= 0) { + field.putSign(1); + } else { + field.putSign(-1); + } + return (CobolNumericField) field; + } + + @Override + public CobolDecimal getDecimal() { + return new CobolDecimal(BigDecimal.valueOf(this.getBinaryValue()), 0); + } + + @Override + public void moveFrom(byte[] bytes) {} + + @Override + public void moveFrom(String string) {} + + @Override + public void moveFrom(int number) {} + + @Override + public void moveFrom(double number) {} + + @Override + public void moveFrom(BigDecimal number) {} + + @Override + public void moveFrom(CobolDataStorage dataStrage) {} +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericEditedField.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericEditedField.java index 48e4a4c6..4e26f04c 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericEditedField.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericEditedField.java @@ -1,383 +1,385 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.data; - -import java.math.BigDecimal; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import jp.osscons.opensourcecobol.libcobj.common.CobolModule; - -/** TODO: 準備中 */ -public class CobolNumericEditedField extends AbstractCobolField { - /** - * コンストラクタ - * - * @param size データを格納するバイト配列の長さ - * @param dataStorage データを格納するバイト配列を扱うオブジェクト - * @param attribute 変数に関する様々な情報を保持するオブジェクト - */ - public CobolNumericEditedField( - int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { - super(size, dataStorage, attribute); - } - - @Override - public byte[] getBytes() { - return new byte[0]; - } - - @Override - public String getString() { - return null; - } - - @Override - public CobolDecimal getDecimal() { - return null; - } - - @Override - public void setDecimal(BigDecimal decimal) {} - - @Override - public int addPackedInt(int n) { - return 0; - } - - @Override - public void moveFrom(AbstractCobolField src) { - AbstractCobolField src1 = this.preprocessOfMoving(src); - if (src1 == null) { - return; - } - - switch (src1.getAttribute().getType()) { - case CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY: - CobolNumericEditedField.moveDisplayToEdited(this, src1); - break; - case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: - case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: - case CobolFieldAttribute.COB_TYPE_NUMERIC_EDITED: - case CobolFieldAttribute.COB_TYPE_NUMERIC_FLOAT: - case CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE: - this.moveFrom(src1.getNumericField()); - break; - case CobolFieldAttribute.COB_TYPE_GROUP: - CobolAlphanumericField.moveAlphanumToAlphanum(this, src1); - break; - default: - this.moveFrom(src1.getNumericField()); - break; - } - } - - private static void moveDisplayToEdited(AbstractCobolField dst, AbstractCobolField src) { - int decimalPoint = 0; - int sign = src.getSign(); - src.putSign(+1); - boolean neg = sign < 0; - byte[] picBytes = dst.getAttribute().getPic().getBytes(); - int count = 0; - int countSign = 1; - int countCurr = 1; - boolean pIsLeft = false; - - final int sizeOfInt = 4; - for (int p = 0; p < picBytes.length; p += 5) { - byte c = picBytes[p]; - ByteBuffer buf = ByteBuffer.wrap(picBytes, p + 1, sizeOfInt); - buf.order(ByteOrder.LITTLE_ENDIAN); - int repeat = buf.getInt(); - if (c == '9' || c == 'Z' || c == '*') { - count += repeat; - countSign = 0; - countCurr = 0; - } else if (countCurr != 0 && c == CobolModule.getCurrentModule().currency_symbol) { - count += repeat; - } else if (countSign != 0 && (c == '+' || c == '-')) { - count += repeat; - } else if (c == 'P') { - if (count == 0) { - pIsLeft = true; - break; - } else { - count += repeat; - countSign = 0; - countCurr = 0; - } - } else if (c == 'V' || c == CobolModule.getCurrentModule().decimal_point) { - break; - } - } - - // index - int min; - if (src.getAttribute().isFlagSignSeparate() && src.getAttribute().isFlagSignLeading()) { - min = src.getDataStorage().getIndex() + 1; - } else { - min = src.getDataStorage().getIndex(); - } - int max = min + src.getFieldSize(); - int srcp = max - src.getAttribute().getScale() - count; - - int dstp = dst.getDataStorage().getIndex(); - int end = dstp + dst.getSize(); - - int signFirst = 0; - - // byte array - byte[] srcBytes = src.getDataStorage().getRefOfData(); - byte[] dstBytes = dst.getDataStorage().getRefOfData(); - - // flag - boolean suppressZero = true; - boolean isZero = true; - boolean trailingSign = false; - boolean trailingCurr = false; - - // characters - byte pad = ' '; - byte x; - byte signSymbol = 0; - byte currSymbol = 0; - - for (int p = 0; p < picBytes.length; ) { - byte c = picBytes[p++]; - ByteBuffer buf = ByteBuffer.wrap(picBytes, p, sizeOfInt); - buf.order(ByteOrder.LITTLE_ENDIAN); - int n = buf.getInt(); - p += sizeOfInt; - for (; n > 0; n--, ++dstp) { - switch (c) { - case '0': - case '/': - dstBytes[dstp] = c; - break; - - case 'B': - dstBytes[dstp] = suppressZero ? pad : (byte) 'B'; - break; - - case 'P': - if (pIsLeft) { - ++srcp; - ++dstp; - } - break; - - case '9': - if (min <= srcp && srcp < max) { - byte val = srcBytes[srcp++]; - dstBytes[dstp] = (byte) (val >= 0x70 ? val - 0x40 : val); - } else { - srcp++; - dstBytes[dstp] = '0'; - } - if (dstBytes[dstp] != '0') { - isZero = suppressZero = false; - } - suppressZero = false; - trailingSign = true; - trailingCurr = true; - break; - - case 'V': - --dstp; - decimalPoint = dstp; - break; - - case '.': - case ',': - if (c == CobolModule.getCurrentModule().decimal_point) { - dstBytes[dstp] = (byte) CobolModule.getCurrentModule().decimal_point; - decimalPoint = dstp; - } else { - dstBytes[dstp] = suppressZero ? pad : c; - } - break; - - case 'C': - case 'D': - end = dstp; - if (neg) { - if (c == 'C') { - dstBytes[dstp] = 'C'; - dstBytes[dstp + 1] = 'R'; - } else { - dstBytes[dstp] = 'D'; - dstBytes[dstp + 1] = 'B'; - } - } else { - dstBytes[dstp] = ' '; - dstBytes[dstp + 1] = ' '; - } - dstp++; - break; - - case 'Z': - case '*': - x = (min <= srcp && srcp < max) ? srcBytes[srcp] : (byte) '0'; - srcp++; - if (x != '0') { - isZero = suppressZero = false; - } - pad = (byte) ((c == '*') ? '*' : ' '); - dstBytes[dstp] = suppressZero ? pad : x; - trailingSign = trailingCurr = true; - break; - - case '+': - case '-': - x = (min <= srcp && srcp < max) ? srcBytes[srcp] : (byte) '0'; - srcp++; - if (x != '0') { - isZero = suppressZero = false; - } - if (trailingSign) { - dstBytes[dstp] = (byte) (neg ? '-' : (c == '+') ? '+' : ' '); - --end; - } else if (dstp == dst.getDataStorage().getIndex() || suppressZero) { - dstBytes[dstp] = pad; - signSymbol = (byte) (neg ? '-' : (c == '+') ? '+' : ' '); - if (currSymbol != 0) { - ++signFirst; - } - } else { - dstBytes[dstp] = x; - } - break; - - default: - if (c == CobolModule.getCurrentModule().currency_symbol) { - x = (byte) ((min <= srcp && srcp < max) ? srcBytes[srcp] : '0'); - srcp++; - if (x != '0') { - isZero = suppressZero = false; - } - if (trailingCurr) { - dstBytes[dstp] = (byte) CobolModule.getCurrentModule().currency_symbol; - --end; - } else if (dstp == dst.getDataStorage().getIndex() || suppressZero) { - dstBytes[dstp] = pad; - currSymbol = (byte) CobolModule.getCurrentModule().currency_symbol; - } else { - dstBytes[dstp] = x; - } - break; - } - dstBytes[dstp] = '?'; - } - } - } - - if (suppressZero || (isZero && dst.getAttribute().isFlagBlankZero())) { - if (pad == ' ' || dst.getAttribute().isFlagBlankZero()) { - dst.getDataStorage().memset((byte) ' ', dst.getSize()); - } else { - int firstIndex = dst.getDataStorage().getIndex(); - for (dstp = firstIndex; dstp < firstIndex + dst.getSize(); ++dstp) { - if (dstBytes[dstp] != CobolModule.getCurrentModule().decimal_point) { - dstBytes[dstp] = pad; - } - } - } - } else { - if (decimalPoint != 0) { - for (dstp = decimalPoint + 1; dstp < end; ++dstp) { - if (!Character.isDigit(dstBytes[dstp]) && ",+/B".lastIndexOf(dstBytes[dstp]) < 0) { - dstBytes[dstp] = '0'; - } - } - } - - if (signSymbol != 0 || currSymbol != 0) { - for (dstp = end - 1; dstp > dst.getDataStorage().getIndex(); --dstp) { - if (dstBytes[dstp] == ' ') { - break; - } - } - if (signSymbol != 0 && currSymbol != 0) { - if (signFirst != 0) { - dstBytes[dstp] = currSymbol; - --dstp; - if (dstp >= dst.getDataStorage().getIndex()) { - dstBytes[dstp] = signSymbol; - } - } else { - dstBytes[dstp] = signSymbol; - --dstp; - if (dstp >= dst.getDataStorage().getIndex()) { - dstBytes[dstp] = currSymbol; - } - } - } else if (signSymbol > 0) { - dstBytes[dstp] = signSymbol; - } else { - dstBytes[dstp] = currSymbol; - } - } - - count = 0; - for (dstp = dst.getDataStorage().getIndex(); dstp < end; ++dstp) { - if (dstBytes[dstp] == 'B') { - dstBytes[dstp] = count == 0 ? pad : (byte) ' '; - } else { - ++count; - } - } - } - - src.putSign(sign); - } - - @Override - public void moveFrom(CobolDataStorage dataStrage) {} - - @Override - public void moveFrom(byte[] bytes) {} - - @Override - public void moveFrom(String string) {} - - @Override - public void moveFrom(int number) {} - - @Override - public void moveFrom(double number) {} - - @Override - public void moveFrom(BigDecimal number) {} - - @Override - public CobolNumericField getNumericField() { - int size = 36; - int scale = 18; - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, - size, - scale, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - CobolDataStorage data = new CobolDataStorage(64); - CobolNumericField field = new CobolNumericField(size, data, attr); - field.moveFrom(this); - return field; - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.data; + +import java.math.BigDecimal; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import jp.osscons.opensourcecobol.libcobj.common.CobolModule; + +/** TODO: 準備中 */ +public class CobolNumericEditedField extends AbstractCobolField { + /** + * コンストラクタ + * + * @param size データを格納するバイト配列の長さ + * @param dataStorage データを格納するバイト配列を扱うオブジェクト + * @param attribute 変数に関する様々な情報を保持するオブジェクト + */ + public CobolNumericEditedField( + int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { + super(size, dataStorage, attribute); + } + + @Override + public byte[] getBytes() { + return new byte[0]; + } + + @Override + public String getString() { + return null; + } + + @Override + public CobolDecimal getDecimal() { + return null; + } + + @Override + public void setDecimal(BigDecimal decimal) {} + + @Override + public int addPackedInt(int n) { + return 0; + } + + @Override + public void moveFrom(AbstractCobolField src) { + AbstractCobolField src1 = this.preprocessOfMoving(src); + if (src1 == null) { + return; + } + + switch (src1.getAttribute().getType()) { + case CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY: + CobolNumericEditedField.moveDisplayToEdited(this, src1); + break; + case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: + case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: + case CobolFieldAttribute.COB_TYPE_NUMERIC_EDITED: + case CobolFieldAttribute.COB_TYPE_NUMERIC_FLOAT: + case CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE: + this.moveFrom(src1.getNumericField()); + break; + case CobolFieldAttribute.COB_TYPE_GROUP: + CobolAlphanumericField.moveAlphanumToAlphanum(this, src1); + break; + default: + this.moveFrom(src1.getNumericField()); + break; + } + } + + private static void moveDisplayToEdited(AbstractCobolField dst, AbstractCobolField src) { + int decimalPoint = 0; + int sign = src.getSign(); + src.putSign(+1); + boolean neg = sign < 0; + byte[] picBytes = dst.getAttribute().getPic().getBytes(AbstractCobolField.charSetSJIS); + int count = 0; + int countSign = 1; + int countCurr = 1; + boolean pIsLeft = false; + + final int sizeOfInt = 4; + for (int p = 0; p < picBytes.length; p += 5) { + byte c = picBytes[p]; + ByteBuffer buf = ByteBuffer.wrap(picBytes, p + 1, sizeOfInt); + buf.order(ByteOrder.LITTLE_ENDIAN); + int repeat = buf.getInt(); + if (c == '9' || c == 'Z' || c == '*') { + count += repeat; + countSign = 0; + countCurr = 0; + } else if (countCurr != 0 && c == CobolModule.getCurrentModule().currency_symbol) { + count += repeat; + } else if (countSign != 0 && (c == '+' || c == '-')) { + count += repeat; + } else if (c == 'P') { + if (count == 0) { + pIsLeft = true; + break; + } else { + count += repeat; + countSign = 0; + countCurr = 0; + } + } else if (c == 'V' || c == CobolModule.getCurrentModule().decimal_point) { + break; + } + } + + // index + int min; + if (src.getAttribute().isFlagSignSeparate() && src.getAttribute().isFlagSignLeading()) { + min = src.getDataStorage().getIndex() + 1; + } else { + min = src.getDataStorage().getIndex(); + } + int max = min + src.getFieldSize(); + int srcp = max - src.getAttribute().getScale() - count; + + int dstp = dst.getDataStorage().getIndex(); + int end = dstp + dst.getSize(); + + int signFirst = 0; + + // byte array + byte[] srcBytes = src.getDataStorage().getRefOfData(); + byte[] dstBytes = dst.getDataStorage().getRefOfData(); + + // flag + boolean suppressZero = true; + boolean isZero = true; + boolean trailingSign = false; + boolean trailingCurr = false; + + // characters + byte pad = ' '; + byte x; + byte signSymbol = 0; + byte currSymbol = 0; + + for (int p = 0; p < picBytes.length; ) { + byte c = picBytes[p++]; + ByteBuffer buf = ByteBuffer.wrap(picBytes, p, sizeOfInt); + buf.order(ByteOrder.LITTLE_ENDIAN); + int n = buf.getInt(); + p += sizeOfInt; + for (; n > 0; n--, ++dstp) { + switch (c) { + case '0': + case '/': + dstBytes[dstp] = c; + break; + + case 'B': + dstBytes[dstp] = suppressZero ? pad : (byte) 'B'; + break; + + case 'P': + if (pIsLeft) { + ++srcp; + ++dstp; + } + break; + + case '9': + if (min <= srcp && srcp < max) { + byte val = srcBytes[srcp++]; + dstBytes[dstp] = (byte) (val >= 0x70 ? val - 0x40 : val); + } else { + srcp++; + dstBytes[dstp] = '0'; + } + if (dstBytes[dstp] != '0') { + isZero = suppressZero = false; + } + suppressZero = false; + trailingSign = true; + trailingCurr = true; + break; + + case 'V': + --dstp; + decimalPoint = dstp; + break; + + case '.': + case ',': + if (c == CobolModule.getCurrentModule().decimal_point) { + dstBytes[dstp] = (byte) CobolModule.getCurrentModule().decimal_point; + decimalPoint = dstp; + } else { + dstBytes[dstp] = suppressZero ? pad : c; + } + break; + + case 'C': + case 'D': + end = dstp; + if (neg) { + if (c == 'C') { + dstBytes[dstp] = 'C'; + dstBytes[dstp + 1] = 'R'; + } else { + dstBytes[dstp] = 'D'; + dstBytes[dstp + 1] = 'B'; + } + } else { + dstBytes[dstp] = ' '; + dstBytes[dstp + 1] = ' '; + } + dstp++; + break; + + case 'Z': + case '*': + x = (min <= srcp && srcp < max) ? srcBytes[srcp] : (byte) '0'; + srcp++; + if (x != '0') { + isZero = suppressZero = false; + } + pad = (byte) ((c == '*') ? '*' : ' '); + dstBytes[dstp] = suppressZero ? pad : x; + trailingSign = trailingCurr = true; + break; + + case '+': + case '-': + x = (min <= srcp && srcp < max) ? srcBytes[srcp] : (byte) '0'; + srcp++; + if (x != '0') { + isZero = suppressZero = false; + } + if (trailingSign) { + dstBytes[dstp] = (byte) (neg ? '-' : (c == '+') ? '+' : ' '); + --end; + } else if (dstp == dst.getDataStorage().getIndex() || suppressZero) { + dstBytes[dstp] = pad; + signSymbol = (byte) (neg ? '-' : (c == '+') ? '+' : ' '); + if (currSymbol != 0) { + ++signFirst; + } + } else { + dstBytes[dstp] = x; + } + break; + + default: + if (c == CobolModule.getCurrentModule().currency_symbol) { + x = (byte) ((min <= srcp && srcp < max) ? srcBytes[srcp] : '0'); + srcp++; + if (x != '0') { + isZero = suppressZero = false; + } + if (trailingCurr) { + dstBytes[dstp] = + (byte) CobolModule.getCurrentModule().currency_symbol; + --end; + } else if (dstp == dst.getDataStorage().getIndex() || suppressZero) { + dstBytes[dstp] = pad; + currSymbol = (byte) CobolModule.getCurrentModule().currency_symbol; + } else { + dstBytes[dstp] = x; + } + break; + } + dstBytes[dstp] = '?'; + } + } + } + + if (suppressZero || (isZero && dst.getAttribute().isFlagBlankZero())) { + if (pad == ' ' || dst.getAttribute().isFlagBlankZero()) { + dst.getDataStorage().memset((byte) ' ', dst.getSize()); + } else { + int firstIndex = dst.getDataStorage().getIndex(); + for (dstp = firstIndex; dstp < firstIndex + dst.getSize(); ++dstp) { + if (dstBytes[dstp] != CobolModule.getCurrentModule().decimal_point) { + dstBytes[dstp] = pad; + } + } + } + } else { + if (decimalPoint != 0) { + for (dstp = decimalPoint + 1; dstp < end; ++dstp) { + if (!Character.isDigit(dstBytes[dstp]) + && ",+/B".lastIndexOf(dstBytes[dstp]) < 0) { + dstBytes[dstp] = '0'; + } + } + } + + if (signSymbol != 0 || currSymbol != 0) { + for (dstp = end - 1; dstp > dst.getDataStorage().getIndex(); --dstp) { + if (dstBytes[dstp] == ' ') { + break; + } + } + if (signSymbol != 0 && currSymbol != 0) { + if (signFirst != 0) { + dstBytes[dstp] = currSymbol; + --dstp; + if (dstp >= dst.getDataStorage().getIndex()) { + dstBytes[dstp] = signSymbol; + } + } else { + dstBytes[dstp] = signSymbol; + --dstp; + if (dstp >= dst.getDataStorage().getIndex()) { + dstBytes[dstp] = currSymbol; + } + } + } else if (signSymbol > 0) { + dstBytes[dstp] = signSymbol; + } else { + dstBytes[dstp] = currSymbol; + } + } + + count = 0; + for (dstp = dst.getDataStorage().getIndex(); dstp < end; ++dstp) { + if (dstBytes[dstp] == 'B') { + dstBytes[dstp] = count == 0 ? pad : (byte) ' '; + } else { + ++count; + } + } + } + + src.putSign(sign); + } + + @Override + public void moveFrom(CobolDataStorage dataStrage) {} + + @Override + public void moveFrom(byte[] bytes) {} + + @Override + public void moveFrom(String string) {} + + @Override + public void moveFrom(int number) {} + + @Override + public void moveFrom(double number) {} + + @Override + public void moveFrom(BigDecimal number) {} + + @Override + public CobolNumericField getNumericField() { + int size = 36; + int scale = 18; + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, + size, + scale, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + CobolDataStorage data = new CobolDataStorage(64); + CobolNumericField field = new CobolNumericField(size, data, attr); + field.moveFrom(this); + return field; + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericField.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericField.java index 64edd2d4..3f2b37cb 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericField.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericField.java @@ -1,947 +1,994 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.data; - -import java.io.UnsupportedEncodingException; -import java.math.BigDecimal; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import jp.osscons.opensourcecobol.libcobj.common.CobolConstant; -import jp.osscons.opensourcecobol.libcobj.common.CobolModule; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionId; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; - -/** PIC 文字列が9(5)や9(9)の変数を表現するクラス. */ -public class CobolNumericField extends AbstractCobolField { - - /** - * コンストラクタ - * - * @param size データを格納するバイト配列の長さ - * @param dataStorage データを格納するバイト配列を扱うオブジェクト - * @param attribute 変数に関する様々な情報を保持するオブジェクト - */ - public CobolNumericField(int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { - super(size, dataStorage, attribute); - } - - /** - * TODO: 準備中 - * - * @param s TODO: 準備中 - */ - public void checkNumeric(String s) {} - - @Override - public byte[] getBytes() { - return dataStorage.getData(); - } - - @Override - public String getString() { - CobolDataStorage data = this.getDataStorage(); - CobolFieldAttribute attr = this.getAttribute(); - int digits = attr.getDigits(); - char decimalPoint = (char) CobolModule.getDecimalPoint(); - - StringBuilder sb = new StringBuilder(); - if (attr.isFlagHaveSign()) { - if (this.getSign() < 0) { - sb.append('-'); - } else { - sb.append('+'); - } - } - - int scale = attr.getScale(); - int fieldSize = this.getFieldSize(); - if (scale >= fieldSize) { - sb.append(decimalPoint); - for (int i = 0; i < scale - fieldSize; ++i) { - sb.append('0'); - } - int firstIndex = this.getFirstDataIndex(); - int signIndex = attr.isFlagSignLeading() ? 0 : this.getSize() - 1; - for (int i = 0; i < fieldSize; ++i) { - char c = (char) data.getByte(firstIndex + i); - if (firstIndex + i == signIndex && c >= 0x70) { - c -= 0x40; - } - sb.append(c); - } - return sb.toString(); - } - - int pointIndex = scale > 0 ? digits - scale - 1 : digits - 1; - - int signIndex = attr.isFlagSignLeading() ? 0 : this.getSize() - 1; - int i = 0; - int dataLastIndex = - attr.isFlagHaveSign() && !attr.isFlagSignLeading() && attr.isFlagSignSeparate() - ? this.getSize() - 2 - : this.getSize() - 1; - for (; i + getFirstDataIndex() <= dataLastIndex; ++i) { - if (scale > 0 && i - 1 == pointIndex) { - sb.append(decimalPoint); - } - char c = (char) data.getByte(this.getFirstDataIndex() + i); - if (attr.isFlagHaveSign() && !attr.isFlagSignSeparate() && i == signIndex && c >= 0x70) { - c -= 0x40; - } - sb.append(c); - } - for (; i < digits; ++i) { - if (scale > 0 && i - 1 == pointIndex) { - sb.append(decimalPoint); - } - sb.append('0'); - } - - return sb.toString(); - } - - @Override - public int getInt() { - int size = this.getFieldSize(); - CobolDataStorage data = this.getDataStorage(); - int firstDataIndex = this.getFirstDataIndex(); - int sign = this.getSign(); - - int i; - for (i = 0; i < size; ++i) { - if (data.getByte(firstDataIndex + i) - 0x30 != 0) { - break; - } - } - - int val = 0; - int scale = this.getAttribute().getScale(); - if (scale < 0) { - for (; i < size; ++i) { - byte x = data.getByte(firstDataIndex + i); - x -= (x >= 0x70) ? 0x70 : 0x30; - val = val * 10 + x; - } - val *= AbstractCobolField.cobExp10[-scale]; - } else { - size -= scale; - for (; i < size; ++i) { - byte x = data.getByte(firstDataIndex + i); - x -= (x >= 0x70) ? 0x70 : 0x30; - val = val * 10 + x; - } - } - - if (sign < 0) { - val = -val; - } - - this.putSign(sign); - return val; - } - - @Override - public void setDecimal(BigDecimal decimal) { - byte[] decimalBytes = decimal.toPlainString().getBytes(); - int length = Math.min(this.size, decimalBytes.length); - - for (int i = 0; i < length; ++i) { - this.dataStorage.setByte(this.size - 1 - i, decimalBytes[decimalBytes.length - 1 - i]); - } - } - - @Override - public void moveFrom(AbstractCobolField src) { - AbstractCobolField src1 = this.preprocessOfMoving(src); - if (src1 == null) { - return; - } - - switch (src1.getAttribute().getType()) { - case CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY: - this.moveDisplayToDisplay(src1); - break; - case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: - this.movePackedToDisplay(src1); - break; - case CobolFieldAttribute.COB_TYPE_NATIONAL: - case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC: - case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_EDITED: - case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: - this.moveAlphanumericToDisplay(src1); - break; - case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: - this.moveBinaryToDisplay(src1); - break; - case CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE: - case CobolFieldAttribute.COB_TYPE_NUMERIC_FLOAT: - this.moveDoubleToDisplay(src1); - break; - case CobolFieldAttribute.COB_TYPE_NUMERIC_EDITED: - this.moveEditedToDisplay(src1); - break; - case CobolFieldAttribute.COB_TYPE_GROUP: - CobolAlphanumericField.moveAlphanumToAlphanum(this, src1); - break; - default: - throw new CobolRuntimeException(0, "未実装"); - } - } - - /** - * CobolNumericDisplayからthisへの代入を行う - * - * @param field 代入元のデータ(AbstractCobolField型) - */ - private void moveDisplayToDisplay(AbstractCobolField field) { - int sign = field.getSign(); - field.putSign(1); - - this.storeCommonRegion( - this, - field.getDataStorage().getSubDataStorage(field.getFirstDataIndex()), - field.getFieldSize(), - field.getAttribute().getScale()); - - field.putSign(sign); - this.putSign(sign); - } - - /** - * CobolNumericPackedFieldからthisへの代入を行う - * - * @param field 代入元のデータ(AbstractCobolField型) - */ - private void movePackedToDisplay(AbstractCobolField field) { - int sign = field.getSign(); - int offset = 1 - (field.getAttribute().getDigits() % 2); - CobolDataStorage buff = new CobolDataStorage(64); - int packedDigits = field.getAttribute().getDigits(); - int packedScale = field.getAttribute().getScale(); - int end; - if (packedScale < 0) { - end = offset + packedDigits + packedScale; - } else { - end = offset + packedDigits; - } - - for (int i = offset; i < end; ++i) { - if (i % 2 == 0) { - buff.setByte( - i - offset, (byte) (((field.getDataStorage().getByte(i / 2) >> 4) & 0x0f) + 0x30)); - } else { - buff.setByte(i - offset, (byte) ((field.getDataStorage().getByte(i / 2) & 0x0f) + 0x30)); - } - } - this.storeCommonRegion( - this, buff, field.getAttribute().getDigits(), field.getAttribute().getScale()); - - this.putSign(sign); - } - - /** - * CobolAlphanumericFieldからthisへの代入を行う - * - * @param field 代入元のデータ(AbstractCobolField型) - */ - private void moveAlphanumericToDisplay(AbstractCobolField field) { - int s1 = 0; - int e1 = s1 + field.getSize(); - int s2 = this.getFirstDataIndex(); - int e2 = this.getFieldSize(); - - for (int i = 0; i < this.getSize(); ++i) { - this.getDataStorage().setByte(i, (byte) 0x30); - } - - /* skip white space */ - for (; s1 < e1; ++s1) { - char ch = (char) field.getDataStorage().getByte(s1); - if (!Character.isWhitespace(ch)) { - break; - } - } - - /* check for sign */ - int sign = 0; - if (s1 != e1) { - byte ch = field.getDataStorage().getByte(s1); - byte plus = 0x2b; - byte minus = 0x2d; - if (ch == plus || ch == minus) { - sign = (ch == plus) ? 1 : -1; - s1++; - } - } - - /* count the number of digits before decimal point */ - int count = 0; - // TODO Moduleの情報を参照するコードに編集する - for (int p = s1; p < e1 && field.getDataStorage().getByte(p) != '.'; ++p) { - if (Character.isDigit(field.getDataStorage().getByte(p))) { - ++count; - } - } - - /* find the start position */ - int size = this.getFieldSize() - this.getAttribute().getScale(); - if (count < size) { - s2 += size - count; - } else { - while (count-- > size) { - while (!Character.isDigit(field.getDataStorage().getByte(s1++))) { - ; - } - } - } - - /* move */ - count = 0; - outer: - { - for (; s1 < e1 && s2 < e2; ++s1) { - byte c = field.getDataStorage().getByte(s1); - if (Character.isDigit(c)) { - this.getDataStorage().setByte(s2++, c); - // TODO Moduleの情報を参照するコードに編集する - } else if (c == (byte) '.') { - ++count; - if (count > 1) { - break outer; - } - - // TODO Moduleの情報を参照するコードに編集する - } else if (!Character.isWhitespace(c) || c == ',') { - break outer; - } - } - this.putSign(sign); - return; - } - for (int i = 0; i < this.getSize(); ++i) { - this.getDataStorage().setByte(i, (byte) 0x30); - } - this.putSign(0); - } - - /** - * CobolNumericBinaryからthisへの代入を行う - * - * @param field 代入元のデータ(AbstractCobolField型) - */ - private void moveBinaryToDisplay(AbstractCobolField field) { - int sign = 1; - long val = field.getLongValue(); - - if (this.getAttribute().isFlagHaveSign() && val < 0) { - sign = -1; - val = -val; - } - - int i = 20; - byte[] buff = new byte[64]; - while (val > 0) { - buff[--i] = (byte) (val % 10 + 0x30); - val /= 10; - } - - this.storeCommonRegion( - this, new CobolDataStorage(buff, 0), i, (20 - i), field.getAttribute().getScale()); - this.putSign(sign); - } - - private void moveDoubleToDisplay(AbstractCobolField field) { - CobolFieldAttribute thisAttr = this.getAttribute(); - double val = Math.abs(field.getDouble()); - int startIndex = 0; - if (thisAttr.isFlagHaveSign() - && thisAttr.isFlagSignLeading() - && thisAttr.isFlagSignSeparate()) { - startIndex = 1; - } - CobolDataStorage dstStorage = this.getDataStorage().getSubDataStorage(startIndex); - dstStorage.memcpy(String.valueOf(val), thisAttr.getDigits()); - this.putSign(field.getSign() >= 0 ? 1 : -1); - } - - private void moveEditedToDisplay(AbstractCobolField field) { - byte[] buff = new byte[64]; - int p = 0; - boolean havePoint = false; - int scale = 0; - int sign = 0; - - for (int i = 0; i < field.getSize(); ++i) { - int cp = field.getDataStorage().getByte(i); - switch (cp) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - buff[p++] = (byte) cp; - if (havePoint) { - ++scale; - } - break; - case '.': - case ',': - if (cp == CobolModule.getCurrentModule().decimal_point) { - havePoint = true; - } - break; - case '-': - case 'C': - sign = -1; - break; - default: - break; - } - } - - byte[] picBytes = field.getAttribute().getPic().getBytes(); - int count = 0; - if (scale == 0) { - for (int p1 = 0; p1 < picBytes.length; p1 += 5) { - byte c = picBytes[p1]; - ByteBuffer buf = ByteBuffer.wrap(picBytes, p1 + 1, 4); - buf.order(ByteOrder.LITTLE_ENDIAN); - int n = buf.getInt(); - if (c == '9' || c == '0' || c == 'Z' || c == '*') { - if (havePoint) { - scale += n; - } else { - count += n; - } - } else if (c == 'P') { - if (count == 0) { - havePoint = true; - scale += n; - } else { - scale -= n; - } - } else if (c == 'V') { - havePoint = true; - } - } - } - - storeCommonRegion(this, new CobolDataStorage(buff), p, scale); - this.putSign(sign); - } - - @Override - public int getSign() { - CobolFieldAttribute attr = this.getAttribute(); - if (!attr.isFlagHaveSign()) { - return 0; - } - - int p; - if (attr.isFlagSignLeading()) { - p = 0; - } else { - p = this.getSize() - 1; - } - byte value = this.getDataStorage().getByte(p); - if (attr.isFlagSignSeparate()) { - return value == 0x2b ? 1 : -1; - } else { - if (0x30 <= value && value <= 0x39) { - return 1; - } - if (value == 0x20) { - this.getDataStorage().setByte(p, (byte) 0x30); - return 1; - } - - // TODO 以下のコメントアウトを外して,他の部分も修正してテストする - // if(CobolModule.getCurrentModule().display_sign != 0) { - // return 1; - // return getSignEbcdic(p); - // } else { - // return -1; - // } - - // this.getDataStorage().setByte(p, (byte) (this.getDataStorage().getByte(p) - - // 0x40)); - return -1; - } - } - - @Override - public void putSign(int sign) { - CobolFieldAttribute attr = this.getAttribute(); - int p; - - if (!attr.isFlagHaveSign()) { - return; - } - - if (attr.isFlagSignLeading()) { - p = 0; - } else { - p = this.getSize() - 1; - } - - byte value = this.getDataStorage().getByte(p); - if (attr.isFlagSignSeparate()) { - // 0x2dは'-', 0x2bは'+' - byte c = (byte) ((sign < 0) ? 0x2d : 0x2b); - if (value != c) { - this.getDataStorage().setByte(p, c); - } - // TODO 以下のコメントを外して他の部分も修正してテストする - } // else if (CobolModule.getCurrentModule().display_sign != 0) { - /// this.putSignEbcdic(p, sign); - // } - - else { - value = (byte) (value >= 0x70 ? value - 0x40 : value); - this.getDataStorage().setByte(p, (byte) (sign < 0 ? value + 0x40 : value)); - } - } - - /** - * libcob/move.cのstore_common_regionの実装 - * - * @param field TODO: 準備中 - * @param data TODO: 準備中 - * @param size TODO: 準備中 - * @param scale TODO: 準備中 - */ - private void storeCommonRegion( - AbstractCobolField field, CobolDataStorage data, int size, int scale) { - this.storeCommonRegion(field, data, 0, size, scale); - } - - /** - * libcob/move.cのstore_common_regionの実装 - * - * @param field TODO: 準備中 - * @param data TODO: 準備中 - * @param dataStartIndex TODO: 準備中 - * @param size TODO: 準備中 - * @param scale TODO: 準備中 - */ - private void storeCommonRegion( - AbstractCobolField field, CobolDataStorage data, int dataStartIndex, int size, int scale) { - int lf1 = -scale; - int lf2 = -field.getAttribute().getScale(); - int hf1 = size + lf1; - int hf2 = field.getFieldSize() + lf2; - - int lcf = Math.max(lf1, lf2); - int gcf = Math.min(hf1, hf2); - - for (int i = 0; i < field.getFieldSize(); ++i) { - field.getDataStorage().setByte(i + field.getFirstDataIndex(), (byte) 0x30); - } - - if (gcf > lcf) { - int csize = gcf - lcf; - int p = hf1 - gcf; - int q = field.getFirstDataIndex() + hf2 - gcf; - for (int cinc = 0; cinc < csize; ++cinc, ++p, ++q) { - if (data.getByte(dataStartIndex + p) == (byte) 0x20) { - field.getDataStorage().setByte(q, (byte) 0x30); - } else { - byte value = data.getByte(dataStartIndex + p); - field.getDataStorage().setByte(q, value); - } - } - } - } - - @Override - public void moveFrom(byte[] bytes) { - this.dataStorage.setData(bytes); - } - - @Override - public void moveFrom(String string) { - try { - this.dataStorage.setData(string.getBytes("SJIS")); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - } - - @Override - public void moveFrom(int number) { - int n = Math.abs(number); - for (int i = 0; i < this.size; ++i) { - this.dataStorage.setByte(i, (byte) 0x30); - } - - for (int i = this.size - 1; i >= 0; --i) { - this.dataStorage.setByte(i, (byte) (0x30 + n % 10)); - n /= 10; - } - - if (number < 0 && this.getAttribute().isFlagHaveSign()) { - this.putSign(-1); - } - } - - @Override - public int subInt(int in) { - return this.addInt(-in, CobolDecimal.COB_STORE_KEEP_ON_OVERFLOW); - } - - private int subInt(int in, int opt) { - return this.addInt(-in, opt); - } - - @Override - public int addInt(int in) { - return this.addInt(in, CobolDecimal.COB_STORE_KEEP_ON_OVERFLOW); - } - - private int addInt(int in, int opt) { - if (in == 0) { - return 0; - } - - int n = in; - CobolDataStorage data = this.getDataStorage(); - int firstDataIndex = this.getFirstDataIndex(); - int size = this.getFieldSize(); - int scale = this.getAttribute().getScale(); - int sign = this.getSign(); - int osize = size; - byte[] tfield = new byte[64]; - - for (int i = 0; i < osize; ++i) { - tfield[i] = data.getByte(firstDataIndex + i); - } - - if (sign < 0) { - n = -n; - } - while (scale > 0) { - --scale; - n *= 10; - } - - if (scale < 0) { - if (-scale < 10) { - while (scale != 0) { - ++scale; - n /= 10; - } - } else { - n = 0; - } - } else { - size -= scale; - } - - if (n > 0) { - if (displayAddInt(data, firstDataIndex, size, n) != 0) { - for (int i = 0; i < osize; ++i) { - data.setByte(firstDataIndex + i, tfield[i]); - } - CobolRuntimeException.setException(CobolExceptionId.COB_EC_SIZE_OVERFLOW); - if ((opt & CobolDecimal.COB_STORE_KEEP_ON_OVERFLOW) > 0) { - this.putSign(sign); - return CobolRuntimeException.code; - } - } - } else if (n < 0) { - if (displaySubInt(data, firstDataIndex, size, -n) != 0) { - for (int i = 0; i < size; ++i) { - byte val = data.getByte(firstDataIndex + i); - data.setByte(firstDataIndex + i, (byte) (9 - (val - 0x30) + 0x30)); - } - displayAddInt(data, firstDataIndex, size, 1); - sign = -sign; - } - } - - this.putSign(sign); - return 0; - } - - /** - * libcob/numeric.cのdisplay_add_intの実装 - * - * @param data TODO: 準備中 - * @param firstDataIndex dataにアクセスするときの開始位置 - * @param size TODO: 準備中 - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - private int displayAddInt(CobolDataStorage data, int firstDataIndex, int size, long n) { - int carry = 0; - int sp = firstDataIndex + size; - int i; - while (n > 0) { - i = (int) (n % 10L); - n /= 10; - - /* check for overflow */ - --sp; - if (sp < firstDataIndex) { - if (CobolModule.getCurrentModule().flag_binary_truncate == 0) { - return 0; - } - return 1; - } - - /* perform addtion */ - int is = (data.getByte(sp) & 0x0F) + i + carry; - if (is > 9) { - carry = 1; - data.setByte(sp, (byte) (0x30 + (is % 10))); - } else { - carry = 0; - data.setByte(sp, (byte) (0x30 + is)); - } - } - if (carry == 0) { - return 0; - } - - /* carry up */ - while (--sp >= firstDataIndex) { - byte val = data.getByte(sp); - data.setByte(sp, (byte) (val + 1)); - if (val + 1 <= '9') { - return 0; - } - data.setByte(sp, (byte) '0'); - } - - if (CobolModule.getCurrentModule().flag_binary_truncate == 0) { - return 0; - } - return 1; - } - - private static int displaySubInt(CobolDataStorage data, int firstDataIndex, int size, long n) { - int carry = 0; - int sp = firstDataIndex + size; - int i; - while (n > 0) { - i = (int) (n % 10L); - n /= 10; - - /* check for overflow */ - --sp; - if (sp < firstDataIndex) { - return 1; - } - - /* perform subtraction */ - byte val = data.getByte(sp); - data.setByte(sp, (byte) (val - (i + carry))); - if (val - (i + carry) < '0') { - carry = 1; - data.setByte(sp, (byte) (data.getByte(sp) + 10)); - } else { - carry = 0; - } - } - if (carry == 0) { - return 0; - } - - /* carry up */ - while (--sp >= firstDataIndex) { - byte val = data.getByte(sp); - data.setByte(sp, (byte) (val - 1)); - if (val - 1 >= '0') { - return 0; - } - data.setByte(sp, (byte) '9'); - } - return 1; - } - - @Override - public int add(AbstractCobolField field, int opt) throws CobolStopRunException { - CobolFieldAttribute attr = field.getAttribute(); - if (attr.isTypeNumeric() - && attr.getDigits() <= 9 - && attr.getScale() == 0 - && this.getAttribute().getScale() == 0) { - return this.addInt(field.getInt(), opt); - } else { - return super.add(field, opt); - } - } - - @Override - public int sub(AbstractCobolField field, int opt) throws CobolStopRunException { - CobolFieldAttribute attr = field.getAttribute(); - if (attr.isTypeNumeric() - && attr.getDigits() <= 9 - && attr.getScale() == 0 - && this.getAttribute().getScale() == 0) { - return this.subInt(field.getInt(), opt); - } else { - return super.sub(field, opt); - } - } - - @Override - public CobolNumericField getNumericField() { - return this; - } - - /* - * @Override - * public void moveFrom(double number) { - * this.moveFrom((int) number); - * } - */ - - @Override - public void moveFrom(BigDecimal number) {} - - @Override - public void moveFrom(CobolDataStorage dataStorage) {} - - @Override - public int addPackedInt(int n) { - throw new CobolRuntimeException(0, "実装しないコード"); - } - - @Override - public long getLong() { - int size = this.getSize(); - CobolDataStorage data = this.getDataStorage(); - int sign = this.getSign(); - int i = 0; - - for (i = 0; i < size; ++i) { - if (data.getByte(i) != '0') { - break; - } - } - - long val = 0; - int scale = this.getAttribute().getScale(); - if (scale < 0) { - for (; i < size; ++i) { - val = val * 10 + (data.getByte(i) - '0'); - } - val *= CobolConstant.exp10LL[-scale]; - } else { - size -= scale; - for (; i < size; ++i) { - val = val * 10 + (data.getByte(i) - '0'); - } - } - if (sign < 0) { - val = -val; - } - this.putSign(sign); - return val; - } - - @Override - public int numericCompareTo(AbstractCobolField field) { - CobolFieldAttribute attr1 = this.getAttribute(); - CobolFieldAttribute attr2 = field.getAttribute(); - if (attr2.isTypeNumericDisplay()) { - final int scale1 = attr1.getScale(); - final int scale2 = attr2.getScale(); - final int firstIndex1 = this.getFirstDataIndex(); - final int firstIndex2 = field.getFirstDataIndex(); - final int fieldSize1 = this.getFieldSize(); - final int fieldSize2 = field.getFieldSize(); - final int size1 = this.getSize(); - final int size2 = field.getSize(); - final int pointIndex1 = fieldSize1 - scale1; - final int pointIndex2 = fieldSize2 - scale2; - int sign1 = this.getSign(); - int sign2 = field.getSign(); - sign1 = sign1 > 0 ? 1 : sign1 < 0 ? -1 : 1; - sign2 = sign2 > 0 ? 1 : sign2 < 0 ? -1 : 1; - - final int signIndex1 = - attr1.isFlagHaveSign() && !attr1.isFlagSignLeading() ? size1 - 1 : firstIndex1; - final int signIndex2 = - attr2.isFlagHaveSign() && !attr2.isFlagSignLeading() ? size2 - 1 : firstIndex2; - final int l1 = -pointIndex1; - final int l2 = -pointIndex2; - final int r1 = fieldSize1 - pointIndex1; - final int r2 = fieldSize2 - pointIndex2; - final int left = Math.min(l1, l2); - final int right = Math.max(r1, r2); - final int lastIndex1; - if (attr1.isFlagHaveSign() && !attr1.isFlagSignLeading() && attr1.isFlagSignSeparate()) { - lastIndex1 = size1 - 2; - } else { - lastIndex1 = size1 - 1; - } - final int lastIndex2; - if (attr2.isFlagHaveSign() && !attr2.isFlagSignLeading() && attr2.isFlagSignSeparate()) { - lastIndex2 = size2 - 2; - } else { - lastIndex2 = size2 - 1; - } - CobolDataStorage d1 = this.getDataStorage(); - CobolDataStorage d2 = field.getDataStorage(); - for (int i = left; i < right; ++i) { - final int i1 = firstIndex1 + i + pointIndex1; - final int i2 = firstIndex2 + i + pointIndex2; - byte b1; - if (i1 < 0 || i1 > lastIndex1) { - b1 = (byte) '0'; - } else { - b1 = d1.getByte(i1); - if (i1 == signIndex1 && b1 >= 0x70) { - b1 -= 0x40; - } - } - byte b2; - if (i2 < 0 || i2 > lastIndex2) { - b2 = (byte) '0'; - } else { - b2 = d2.getByte(i2); - if (i2 == signIndex2 && b2 >= 0x70) { - b2 -= 0x40; - } - } - if (b1 != b2) { - return (sign1 * (int) b1) - (sign2 * (int) b2); - } - } - - if (sign1 * sign2 >= 0) { - return 0; - } else if (sign1 > 0) { - return 1; - } else { - return -1; - } - } else { - return super.numericCompareTo(field); - } - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.data; + +import java.math.BigDecimal; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import jp.osscons.opensourcecobol.libcobj.common.CobolConstant; +import jp.osscons.opensourcecobol.libcobj.common.CobolModule; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionId; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; + +/** PIC 文字列が9(5)や9(9)の変数を表現するクラス. */ +public class CobolNumericField extends AbstractCobolField { + + /** + * コンストラクタ + * + * @param size データを格納するバイト配列の長さ + * @param dataStorage データを格納するバイト配列を扱うオブジェクト + * @param attribute 変数に関する様々な情報を保持するオブジェクト + */ + public CobolNumericField( + int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { + super(size, dataStorage, attribute); + } + + /** + * TODO: 準備中 + * + * @param s TODO: 準備中 + */ + public void checkNumeric(String s) {} + + @Override + public byte[] getBytes() { + return dataStorage.getData(); + } + + @Override + public String getString() { + CobolDataStorage data = this.getDataStorage(); + CobolFieldAttribute attr = this.getAttribute(); + int digits = attr.getDigits(); + char decimalPoint = (char) CobolModule.getDecimalPoint(); + + StringBuilder sb = new StringBuilder(); + if (attr.isFlagHaveSign()) { + if (this.getSign() < 0) { + sb.append('-'); + } else { + sb.append('+'); + } + } + + int scale = attr.getScale(); + int fieldSize = this.getFieldSize(); + if (scale >= fieldSize) { + sb.append(decimalPoint); + for (int i = 0; i < scale - fieldSize; ++i) { + sb.append('0'); + } + int firstIndex = this.getFirstDataIndex(); + int signIndex = attr.isFlagSignLeading() ? 0 : this.getSize() - 1; + for (int i = 0; i < fieldSize; ++i) { + char c = (char) data.getByte(firstIndex + i); + if (firstIndex + i == signIndex && c >= 0x70) { + c -= 0x40; + } + sb.append(c); + } + return sb.toString(); + } + + int pointIndex = scale > 0 ? digits - scale - 1 : digits - 1; + + int signIndex = attr.isFlagSignLeading() ? 0 : this.getSize() - 1; + int i = 0; + int dataLastIndex = + attr.isFlagHaveSign() && !attr.isFlagSignLeading() && attr.isFlagSignSeparate() + ? this.getSize() - 2 + : this.getSize() - 1; + for (; i + getFirstDataIndex() <= dataLastIndex; ++i) { + if (scale > 0 && i - 1 == pointIndex) { + sb.append(decimalPoint); + } + char c = (char) data.getByte(this.getFirstDataIndex() + i); + if (attr.isFlagHaveSign() + && !attr.isFlagSignSeparate() + && i == signIndex + && c >= 0x70) { + c -= 0x40; + } + sb.append(c); + } + for (; i < digits; ++i) { + if (scale > 0 && i - 1 == pointIndex) { + sb.append(decimalPoint); + } + sb.append('0'); + } + + return sb.toString(); + } + + @Override + public int getInt() { + int size = this.getFieldSize(); + CobolDataStorage data = this.getDataStorage(); + int firstDataIndex = this.getFirstDataIndex(); + int sign = this.getSign(); + + int i; + for (i = 0; i < size; ++i) { + if (data.getByte(firstDataIndex + i) - 0x30 != 0) { + break; + } + } + + int val = 0; + int scale = this.getAttribute().getScale(); + if (scale < 0) { + for (; i < size; ++i) { + byte x = data.getByte(firstDataIndex + i); + x -= (x >= 0x70) ? 0x70 : 0x30; + val = val * 10 + x; + } + val *= AbstractCobolField.cobExp10[-scale]; + } else { + size -= scale; + for (; i < size; ++i) { + byte x = data.getByte(firstDataIndex + i); + x -= (x >= 0x70) ? 0x70 : 0x30; + val = val * 10 + x; + } + } + + if (sign < 0) { + val = -val; + } + + this.putSign(sign); + return val; + } + + @Override + public void setDecimal(BigDecimal decimal) { + byte[] decimalBytes = decimal.toPlainString().getBytes(AbstractCobolField.charSetSJIS); + int length = Math.min(this.size, decimalBytes.length); + + for (int i = 0; i < length; ++i) { + this.dataStorage.setByte(this.size - 1 - i, decimalBytes[decimalBytes.length - 1 - i]); + } + } + + @Override + public void moveFrom(AbstractCobolField src) { + AbstractCobolField src1 = this.preprocessOfMoving(src); + if (src1 == null) { + return; + } + + switch (src1.getAttribute().getType()) { + case CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY: + this.moveDisplayToDisplay(src1); + break; + case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: + this.movePackedToDisplay(src1); + break; + case CobolFieldAttribute.COB_TYPE_NATIONAL: + case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC: + case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_EDITED: + case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: + this.moveAlphanumericToDisplay(src1); + break; + case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: + this.moveBinaryToDisplay(src1); + break; + case CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE: + case CobolFieldAttribute.COB_TYPE_NUMERIC_FLOAT: + this.moveDoubleToDisplay(src1); + break; + case CobolFieldAttribute.COB_TYPE_NUMERIC_EDITED: + this.moveEditedToDisplay(src1); + break; + case CobolFieldAttribute.COB_TYPE_GROUP: + CobolAlphanumericField.moveAlphanumToAlphanum(this, src1); + break; + default: + throw new CobolRuntimeException(0, "未実装"); + } + } + + /** + * CobolNumericDisplayからthisへの代入を行う + * + * @param field 代入元のデータ(AbstractCobolField型) + */ + private void moveDisplayToDisplay(AbstractCobolField field) { + int sign = field.getSign(); + field.putSign(1); + + this.storeCommonRegion( + this, + field.getDataStorage().getSubDataStorage(field.getFirstDataIndex()), + field.getFieldSize(), + field.getAttribute().getScale()); + + field.putSign(sign); + this.putSign(sign); + } + + /** + * CobolNumericPackedFieldからthisへの代入を行う + * + * @param field 代入元のデータ(AbstractCobolField型) + */ + private void movePackedToDisplay(AbstractCobolField field) { + int sign = field.getSign(); + int offset = 1 - (field.getAttribute().getDigits() % 2); + CobolDataStorage buff = new CobolDataStorage(64); + int packedDigits = field.getAttribute().getDigits(); + int packedScale = field.getAttribute().getScale(); + int end; + if (packedScale < 0) { + end = offset + packedDigits + packedScale; + } else { + end = offset + packedDigits; + } + + for (int i = offset; i < end; ++i) { + if (i % 2 == 0) { + buff.setByte( + i - offset, + (byte) (((field.getDataStorage().getByte(i / 2) >> 4) & 0x0f) + 0x30)); + } else { + buff.setByte( + i - offset, (byte) ((field.getDataStorage().getByte(i / 2) & 0x0f) + 0x30)); + } + } + this.storeCommonRegion( + this, buff, field.getAttribute().getDigits(), field.getAttribute().getScale()); + + this.putSign(sign); + } + + /** + * CobolAlphanumericFieldからthisへの代入を行う + * + * @param field 代入元のデータ(AbstractCobolField型) + */ + private void moveAlphanumericToDisplay(AbstractCobolField field) { + int s1 = 0; + int e1 = s1 + field.getSize(); + int s2 = this.getFirstDataIndex(); + int e2 = this.getFieldSize(); + + for (int i = 0; i < this.getSize(); ++i) { + this.getDataStorage().setByte(i, (byte) 0x30); + } + + /* skip white space */ + for (; s1 < e1; ++s1) { + char ch = (char) field.getDataStorage().getByte(s1); + if (!Character.isWhitespace(ch)) { + break; + } + } + + /* check for sign */ + int sign = 0; + if (s1 != e1) { + byte ch = field.getDataStorage().getByte(s1); + byte plus = 0x2b; + byte minus = 0x2d; + if (ch == plus || ch == minus) { + sign = (ch == plus) ? 1 : -1; + s1++; + } + } + + /* count the number of digits before decimal point */ + int count = 0; + // TODO Moduleの情報を参照するコードに編集する + for (int p = s1; p < e1 && field.getDataStorage().getByte(p) != '.'; ++p) { + if (Character.isDigit(field.getDataStorage().getByte(p))) { + ++count; + } + } + + /* find the start position */ + int size = this.getFieldSize() - this.getAttribute().getScale(); + if (count < size) { + s2 += size - count; + } else { + while (count-- > size) { + while (!Character.isDigit(field.getDataStorage().getByte(s1++))) { + ; + } + } + } + + /* move */ + count = 0; + outer: + { + for (; s1 < e1 && s2 < e2; ++s1) { + byte c = field.getDataStorage().getByte(s1); + if (Character.isDigit(c)) { + this.getDataStorage().setByte(s2++, c); + // TODO Moduleの情報を参照するコードに編集する + } else if (c == (byte) '.') { + ++count; + if (count > 1) { + break outer; + } + + // TODO Moduleの情報を参照するコードに編集する + } else if (!Character.isWhitespace(c) || c == ',') { + break outer; + } + } + this.putSign(sign); + return; + } + for (int i = 0; i < this.getSize(); ++i) { + this.getDataStorage().setByte(i, (byte) 0x30); + } + this.putSign(0); + } + + /** + * CobolNumericBinaryからthisへの代入を行う + * + * @param field 代入元のデータ(AbstractCobolField型) + */ + private void moveBinaryToDisplay(AbstractCobolField field) { + int sign = 1; + long val = field.getLongValue(); + + if (this.getAttribute().isFlagHaveSign() && val < 0) { + sign = -1; + val = -val; + } + + int i = 20; + byte[] buff = new byte[64]; + while (val > 0) { + buff[--i] = (byte) (val % 10 + 0x30); + val /= 10; + } + + this.storeCommonRegion( + this, new CobolDataStorage(buff, 0), i, (20 - i), field.getAttribute().getScale()); + this.putSign(sign); + } + + private void moveDoubleToDisplay(AbstractCobolField field) { + CobolFieldAttribute thisAttr = this.getAttribute(); + double val = Math.abs(field.getDouble()); + int startIndex = 0; + if (thisAttr.isFlagHaveSign() + && thisAttr.isFlagSignLeading() + && thisAttr.isFlagSignSeparate()) { + startIndex = 1; + } + CobolDataStorage dstStorage = this.getDataStorage().getSubDataStorage(startIndex); + dstStorage.memcpy(String.valueOf(val), thisAttr.getDigits()); + this.putSign(field.getSign() >= 0 ? 1 : -1); + } + + private void moveEditedToDisplay(AbstractCobolField field) { + byte[] buff = new byte[64]; + int p = 0; + boolean havePoint = false; + int scale = 0; + int sign = 0; + + for (int i = 0; i < field.getSize(); ++i) { + int cp = field.getDataStorage().getByte(i); + switch (cp) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + buff[p++] = (byte) cp; + if (havePoint) { + ++scale; + } + break; + case '.': + case ',': + if (cp == CobolModule.getCurrentModule().decimal_point) { + havePoint = true; + } + break; + case '-': + case 'C': + sign = -1; + break; + default: + break; + } + } + + byte[] picBytes = field.getAttribute().getPic().getBytes(AbstractCobolField.charSetSJIS); + int count = 0; + if (scale == 0) { + for (int p1 = 0; p1 < picBytes.length; p1 += 5) { + byte c = picBytes[p1]; + ByteBuffer buf = ByteBuffer.wrap(picBytes, p1 + 1, 4); + buf.order(ByteOrder.LITTLE_ENDIAN); + int n = buf.getInt(); + if (c == '9' || c == '0' || c == 'Z' || c == '*') { + if (havePoint) { + scale += n; + } else { + count += n; + } + } else if (c == 'P') { + if (count == 0) { + havePoint = true; + scale += n; + } else { + scale -= n; + } + } else if (c == 'V') { + havePoint = true; + } + } + } + + storeCommonRegion(this, new CobolDataStorage(buff), p, scale); + this.putSign(sign); + } + + @Override + public int getSign() { + CobolFieldAttribute attr = this.getAttribute(); + if (!attr.isFlagHaveSign()) { + return 0; + } + + int p; + if (attr.isFlagSignLeading()) { + p = 0; + } else { + p = this.getSize() - 1; + } + byte value = this.getDataStorage().getByte(p); + if (attr.isFlagSignSeparate()) { + return value == 0x2b ? 1 : -1; + } else { + if (value == 0x20 || (0x30 <= value && value <= 0x39)) { + return 1; + } + + // TODO 以下のコメントアウトを外して,他の部分も修正してテストする + // if(CobolModule.getCurrentModule().display_sign != 0) { + // return 1; + // return getSignEbcdic(p); + // } else { + // return -1; + // } + + // this.getDataStorage().setByte(p, (byte) (this.getDataStorage().getByte(p) - + // 0x40)); + return -1; + } + } + + @Override + public void putSign(int sign) { + CobolFieldAttribute attr = this.getAttribute(); + int p; + + if (!attr.isFlagHaveSign()) { + return; + } + + if (attr.isFlagSignLeading()) { + p = 0; + } else { + p = this.getSize() - 1; + } + + byte value = this.getDataStorage().getByte(p); + if (attr.isFlagSignSeparate()) { + // 0x2dは'-', 0x2bは'+' + byte c = (byte) ((sign < 0) ? 0x2d : 0x2b); + if (value != c) { + this.getDataStorage().setByte(p, c); + } + // TODO 以下のコメントを外して他の部分も修正してテストする + } // else if (CobolModule.getCurrentModule().display_sign != 0) { + /// this.putSignEbcdic(p, sign); + // } + + else { + value = (byte) (value >= 0x70 ? value - 0x40 : value); + this.getDataStorage().setByte(p, (byte) (sign < 0 ? value + 0x40 : value)); + } + } + + /** + * libcob/move.cのstore_common_regionの実装 + * + * @param field TODO: 準備中 + * @param data TODO: 準備中 + * @param size TODO: 準備中 + * @param scale TODO: 準備中 + */ + private void storeCommonRegion( + AbstractCobolField field, CobolDataStorage data, int size, int scale) { + this.storeCommonRegion(field, data, 0, size, scale); + } + + /** + * libcob/move.cのstore_common_regionの実装 + * + * @param field TODO: 準備中 + * @param data TODO: 準備中 + * @param dataStartIndex TODO: 準備中 + * @param size TODO: 準備中 + * @param scale TODO: 準備中 + */ + private void storeCommonRegion( + AbstractCobolField field, + CobolDataStorage data, + int dataStartIndex, + int size, + int scale) { + int lf1 = -scale; + int lf2 = -field.getAttribute().getScale(); + int hf1 = size + lf1; + int hf2 = field.getFieldSize() + lf2; + + int lcf = Math.max(lf1, lf2); + int gcf = Math.min(hf1, hf2); + + for (int i = 0; i < field.getFieldSize(); ++i) { + field.getDataStorage().setByte(i + field.getFirstDataIndex(), (byte) 0x30); + } + + if (gcf > lcf) { + int csize = gcf - lcf; + int p = hf1 - gcf; + int q = field.getFirstDataIndex() + hf2 - gcf; + for (int cinc = 0; cinc < csize; ++cinc, ++p, ++q) { + if (data.getByte(dataStartIndex + p) == (byte) 0x20) { + field.getDataStorage().setByte(q, (byte) 0x30); + } else { + byte value = data.getByte(dataStartIndex + p); + field.getDataStorage().setByte(q, value); + } + } + } + } + + @Override + public void moveFrom(byte[] bytes) { + this.dataStorage.setData(bytes); + } + + @Override + public void moveFrom(String string) { + this.dataStorage.setData(string.getBytes(AbstractCobolField.charSetSJIS)); + } + + @Override + public void moveFrom(int number) { + int n = Math.abs(number); + for (int i = 0; i < this.size; ++i) { + this.dataStorage.setByte(i, (byte) 0x30); + } + + for (int i = this.size - 1; i >= 0; --i) { + this.dataStorage.setByte(i, (byte) (0x30 + n % 10)); + n /= 10; + } + + if (number < 0 && this.getAttribute().isFlagHaveSign()) { + this.putSign(-1); + } + } + + @Override + public int subInt(int in) { + return this.addInt(-in, CobolDecimal.COB_STORE_KEEP_ON_OVERFLOW); + } + + private int subInt(int in, int opt) { + return this.addInt(-in, opt); + } + + @Override + public int addInt(int in) { + return this.addInt(in, CobolDecimal.COB_STORE_KEEP_ON_OVERFLOW); + } + + private int addInt(int in, int opt) { + if (in == 0) { + return 0; + } + + int n = in; + CobolDataStorage data = this.getDataStorage(); + int firstDataIndex = this.getFirstDataIndex(); + int size = this.getFieldSize(); + int scale = this.getAttribute().getScale(); + int sign = this.getSign(); + int osize = size; + byte[] tfield = new byte[64]; + + for (int i = 0; i < osize; ++i) { + tfield[i] = data.getByte(firstDataIndex + i); + } + + if (sign < 0) { + n = -n; + } + while (scale > 0) { + --scale; + n *= 10; + } + + if (scale < 0) { + if (-scale < 10) { + while (scale != 0) { + ++scale; + n /= 10; + } + } else { + n = 0; + } + } else { + size -= scale; + } + + if (n > 0) { + if (displayAddInt(data, firstDataIndex, size, n) != 0) { + for (int i = 0; i < osize; ++i) { + data.setByte(firstDataIndex + i, tfield[i]); + } + CobolRuntimeException.setException(CobolExceptionId.COB_EC_SIZE_OVERFLOW); + if ((opt & CobolDecimal.COB_STORE_KEEP_ON_OVERFLOW) > 0) { + this.putSign(sign); + return CobolRuntimeException.code; + } + } + } else if (n < 0) { + if (displaySubInt(data, firstDataIndex, size, -n) != 0) { + for (int i = 0; i < size; ++i) { + byte val = data.getByte(firstDataIndex + i); + data.setByte(firstDataIndex + i, (byte) (9 - (val - 0x30) + 0x30)); + } + displayAddInt(data, firstDataIndex, size, 1); + sign = -sign; + } + } + + if (this.isPositiveZeroOrNegativeZero()) { + sign = 1; + } + + this.putSign(sign); + return 0; + } + + /** + * このフィールドが正のゼロまたは負のゼロであるかどうかを判定する + */ + private boolean isPositiveZeroOrNegativeZero() { + int signIndex; + CobolFieldAttribute attr = this.getAttribute(); + if (attr.isFlagHaveSign() && !attr.isFlagSignSeparate()) { + if (attr.isFlagSignLeading()) { + signIndex = 0; + } else { + signIndex = this.getSize() - 1; + } + } else { + signIndex = -1000; + } + + CobolDataStorage data = this.getDataStorage(); + int size = this.getFieldSize(); + int firstDataIndex = this.getFirstDataIndex(); + for (int i = 0; i < size; ++i) { + int index = firstDataIndex + i; + byte value = data.getByte(index); + if (index == signIndex) { + if (value != 0x30 && value != 0x70) { + return false; + } + } else { + if (value != 0x30) { + return false; + } + } + } + return true; + } + + /** + * libcob/numeric.cのdisplay_add_intの実装 + * + * @param data TODO: 準備中 + * @param firstDataIndex dataにアクセスするときの開始位置 + * @param size TODO: 準備中 + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + private int displayAddInt(CobolDataStorage data, int firstDataIndex, int size, long n) { + int carry = 0; + int sp = firstDataIndex + size; + int i; + while (n > 0) { + i = (int) (n % 10L); + n /= 10; + + /* check for overflow */ + --sp; + if (sp < firstDataIndex) { + if (CobolModule.getCurrentModule().flag_binary_truncate == 0) { + return 0; + } + return 1; + } + + /* perform addtion */ + int is = (data.getByte(sp) & 0x0F) + i + carry; + if (is > 9) { + carry = 1; + data.setByte(sp, (byte) (0x30 + (is % 10))); + } else { + carry = 0; + data.setByte(sp, (byte) (0x30 + is)); + } + } + if (carry == 0) { + return 0; + } + + /* carry up */ + while (--sp >= firstDataIndex) { + byte val = data.getByte(sp); + data.setByte(sp, (byte) (val + 1)); + if (val + 1 <= '9') { + return 0; + } + data.setByte(sp, (byte) '0'); + } + + if (CobolModule.getCurrentModule().flag_binary_truncate == 0) { + return 0; + } + return 1; + } + + private static int displaySubInt(CobolDataStorage data, int firstDataIndex, int size, long n) { + int carry = 0; + int sp = firstDataIndex + size; + int i; + while (n > 0) { + i = (int) (n % 10L); + n /= 10; + + /* check for overflow */ + --sp; + if (sp < firstDataIndex) { + return 1; + } + + /* perform subtraction */ + byte val = data.getByte(sp); + if (val >= 0x70) { + val -= 0x40; + } + data.setByte(sp, (byte) (val - (i + carry))); + if (val - (i + carry) < '0') { + carry = 1; + data.setByte(sp, (byte) (data.getByte(sp) + 10)); + } else { + carry = 0; + } + } + if (carry == 0) { + return 0; + } + + /* carry up */ + while (--sp >= firstDataIndex) { + byte val = data.getByte(sp); + data.setByte(sp, (byte) (val - 1)); + if (val - 1 >= '0') { + return 0; + } + data.setByte(sp, (byte) '9'); + } + return 1; + } + + @Override + public int add(AbstractCobolField field, int opt) throws CobolStopRunException { + CobolFieldAttribute attr = field.getAttribute(); + if (attr.isTypeNumeric() + && attr.getDigits() <= 9 + && attr.getScale() == 0 + && this.getAttribute().getScale() == 0) { + return this.addInt(field.getInt(), opt); + } else { + return super.add(field, opt); + } + } + + @Override + public int sub(AbstractCobolField field, int opt) throws CobolStopRunException { + CobolFieldAttribute attr = field.getAttribute(); + if (attr.isTypeNumeric() + && attr.getDigits() <= 9 + && attr.getScale() == 0 + && this.getAttribute().getScale() == 0) { + return this.subInt(field.getInt(), opt); + } else { + return super.sub(field, opt); + } + } + + @Override + public CobolNumericField getNumericField() { + return this; + } + + /* + * @Override + * public void moveFrom(double number) { + * this.moveFrom((int) number); + * } + */ + + @Override + public void moveFrom(BigDecimal number) {} + + @Override + public void moveFrom(CobolDataStorage dataStorage) {} + + @Override + public int addPackedInt(int n) { + throw new CobolRuntimeException(0, "実装しないコード"); + } + + @Override + public long getLong() { + int size = this.getSize(); + CobolDataStorage data = this.getDataStorage(); + int sign = this.getSign(); + int i = 0; + + for (i = 0; i < size; ++i) { + if (data.getByte(i) != '0') { + break; + } + } + + long val = 0; + int scale = this.getAttribute().getScale(); + if (scale < 0) { + for (; i < size; ++i) { + val = val * 10 + (data.getByte(i) - '0'); + } + val *= CobolConstant.exp10LL[-scale]; + } else { + size -= scale; + for (; i < size; ++i) { + val = val * 10 + (data.getByte(i) - '0'); + } + } + if (sign < 0) { + val = -val; + } + this.putSign(sign); + return val; + } + + @Override + public int numericCompareTo(AbstractCobolField field) { + CobolFieldAttribute attr1 = this.getAttribute(); + CobolFieldAttribute attr2 = field.getAttribute(); + if (attr2.isTypeNumericDisplay()) { + final int scale1 = attr1.getScale(); + final int scale2 = attr2.getScale(); + final int firstIndex1 = this.getFirstDataIndex(); + final int firstIndex2 = field.getFirstDataIndex(); + final int fieldSize1 = this.getFieldSize(); + final int fieldSize2 = field.getFieldSize(); + final int size1 = this.getSize(); + final int size2 = field.getSize(); + final int pointIndex1 = fieldSize1 - scale1; + final int pointIndex2 = fieldSize2 - scale2; + int sign1 = this.getSign(); + int sign2 = field.getSign(); + sign1 = sign1 > 0 ? 1 : sign1 < 0 ? -1 : 1; + sign2 = sign2 > 0 ? 1 : sign2 < 0 ? -1 : 1; + + final int signIndex1 = + attr1.isFlagHaveSign() && !attr1.isFlagSignLeading() ? size1 - 1 : firstIndex1; + final int signIndex2 = + attr2.isFlagHaveSign() && !attr2.isFlagSignLeading() ? size2 - 1 : firstIndex2; + final int l1 = -pointIndex1; + final int l2 = -pointIndex2; + final int r1 = fieldSize1 - pointIndex1; + final int r2 = fieldSize2 - pointIndex2; + final int left = Math.min(l1, l2); + final int right = Math.max(r1, r2); + final int lastIndex1; + if (attr1.isFlagHaveSign() + && !attr1.isFlagSignLeading() + && attr1.isFlagSignSeparate()) { + lastIndex1 = size1 - 2; + } else { + lastIndex1 = size1 - 1; + } + final int lastIndex2; + if (attr2.isFlagHaveSign() + && !attr2.isFlagSignLeading() + && attr2.isFlagSignSeparate()) { + lastIndex2 = size2 - 2; + } else { + lastIndex2 = size2 - 1; + } + CobolDataStorage d1 = this.getDataStorage(); + CobolDataStorage d2 = field.getDataStorage(); + for (int i = left; i < right; ++i) { + final int i1 = firstIndex1 + i + pointIndex1; + final int i2 = firstIndex2 + i + pointIndex2; + byte b1; + if (i1 < firstIndex1 || i1 > lastIndex1) { + b1 = (byte) '0'; + } else { + b1 = d1.getByte(i1); + if (i1 == signIndex1 && b1 >= 0x70) { + b1 -= 0x40; + } + } + byte b2; + if (i2 < firstIndex2 || i2 > lastIndex2) { + b2 = (byte) '0'; + } else { + b2 = d2.getByte(i2); + if (i2 == signIndex2 && b2 >= 0x70) { + b2 -= 0x40; + } + } + if (b1 != b2) { + return (sign1 * (int) b1) - (sign2 * (int) b2); + } + } + + if (sign1 * sign2 >= 0) { + return 0; + } else if (sign1 > 0) { + return 1; + } else { + return -1; + } + } else { + return super.numericCompareTo(field); + } + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericPackedField.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericPackedField.java index ea32e821..e55c62b2 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericPackedField.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolNumericPackedField.java @@ -1,876 +1,871 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.data; - -import java.io.UnsupportedEncodingException; -import java.math.BigDecimal; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; - -/** PIC 文字列が9(5) COMP-3などの変数を表現するクラス. */ -public class CobolNumericPackedField extends AbstractCobolField { - private static final byte[] packed_bytes = { - 0x00, - 0x01, - 0x02, - 0x03, - 0x04, - 0x05, - 0x06, - 0x07, - 0x08, - 0x09, - 0x10, - 0x11, - 0x12, - 0x13, - 0x14, - 0x15, - 0x16, - 0x17, - 0x18, - 0x19, - 0x20, - 0x21, - 0x22, - 0x23, - 0x24, - 0x25, - 0x26, - 0x27, - 0x28, - 0x29, - 0x30, - 0x31, - 0x32, - 0x33, - 0x34, - 0x35, - 0x36, - 0x37, - 0x38, - 0x39, - 0x40, - 0x41, - 0x42, - 0x43, - 0x44, - 0x45, - 0x46, - 0x47, - 0x48, - 0x49, - 0x50, - 0x51, - 0x52, - 0x53, - 0x54, - 0x55, - 0x56, - 0x57, - 0x58, - 0x59, - 0x60, - 0x61, - 0x62, - 0x63, - 0x64, - 0x65, - 0x66, - 0x67, - 0x68, - 0x69, - 0x70, - 0x71, - 0x72, - 0x73, - 0x74, - 0x75, - 0x76, - 0x77, - 0x78, - 0x79, - (byte) 0x80, - (byte) 0x81, - (byte) 0x82, - (byte) 0x83, - (byte) 0x84, - (byte) 0x85, - (byte) 0x86, - (byte) 0x87, - (byte) 0x88, - (byte) 0x89, - (byte) 0x90, - (byte) 0x91, - (byte) 0x92, - (byte) 0x93, - (byte) 0x94, - (byte) 0x95, - (byte) 0x96, - (byte) 0x97, - (byte) 0x98, - (byte) 0x99 - }; - - /** - * コンストラクタ - * - * @param size データを格納するバイト配列の長さ - * @param dataStorage データを格納するバイト配列を扱うオブジェクト - * @param attribute 変数に関する様々な情報を保持するオブジェクト(符号付か,COMP-3指定かなど) - */ - public CobolNumericPackedField( - int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { - super(size, dataStorage, attribute); - } - - /** - * TODO: 準備中 - * - * @param s TODO: 準備中 - */ - public void checkNumeric(String s) {} - - @Override - public byte[] getBytes() { - return dataStorage.getData(); - } - - @Override - public String getString() { - StringBuilder sb = new StringBuilder(); - int digits = this.getAttribute().getDigits(); - int scale = this.getAttribute().getScale(); - int counter = digits - scale; - int len; - if (scale < 0) { - len = digits + scale; - } else { - len = digits; - } - for (int i = 0; i < len; ++i, --counter) { - if (counter == 0) { - sb.append('.'); - } - sb.append((char) (this.getDigit(i) + 0x30)); - } - for (int i = 0; i < -scale; ++i) { - sb.append('0'); - } - - if (this.getAttribute().isFlagHaveSign()) { - if (this.getSign() < 0) { - return "-" + sb; - } else { - return "+" + sb; - } - } else { - return sb.toString(); - } - } - - @Override - public void setDecimal(BigDecimal decimal) { - byte[] decimalBytes = decimal.toPlainString().getBytes(); - int length = Math.min(this.size, decimalBytes.length); - - for (int i = 0; i < length; ++i) { - this.dataStorage.setByte(this.size - 1 - i, decimalBytes[decimalBytes.length - 1 - i]); - } - } - - @Override - public void moveFrom(AbstractCobolField src) { - AbstractCobolField src1 = this.preprocessOfMoving(src); - if (src1 == null) { - return; - } - - switch (src1.getAttribute().getType()) { - case CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY: - this.moveDisplayToPacked(src1); - break; - case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: - case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC: - case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: - case CobolFieldAttribute.COB_TYPE_NATIONAL: - case CobolFieldAttribute.COB_TYPE_NUMERIC_EDITED: - case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_EDITED: - case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: - this.moveFrom(src1.getNumericField()); - break; - case CobolFieldAttribute.COB_TYPE_GROUP: - CobolAlphanumericField.moveAlphanumToAlphanum(this, src1); - break; - default: - throw new CobolRuntimeException(0, "未実装"); - } - } - - /** - * CobolNumericFieldからthisへの代入を行う - * - * @param field 代入元のデータ(AbstractCobolField型) - */ - private void moveDisplayToPacked(AbstractCobolField field) { - int sign = field.getSign(); - CobolDataStorage data1 = field.getDataStorage(); - int data1FirstIndex = field.getFirstDataIndex(); - int digits1 = field.getAttribute().getDigits(); - int scale1 = field.getAttribute().getScale(); - CobolDataStorage data2 = this.getDataStorage(); - int digits2 = this.getAttribute().getDigits(); - int scale2 = this.getAttribute().getScale(); - int packedRealDigits; - if (scale2 < 0) { - packedRealDigits = digits2 + scale2; - } else { - packedRealDigits = digits2; - } - - /* null check */ - boolean flagNull = true; - for (int i = 0; i < digits1; ++i) { - if (field.getDataStorage().getByte(i) != 0) { - flagNull = false; - } - } - if (flagNull) { - this.getDataStorage().fillBytes((byte) 0, this.getSize()); - return; - } - - /* pack string */ - this.getDataStorage().fillBytes((byte) 0, this.getSize()); - int offset = 1 - (digits2 % 2); - int p; - if (scale2 < 0) { - p = (digits1 - scale1) - digits2; - } else { - p = (digits1 - scale1) - (digits2 - scale2); - } - - boolean isZero = true; - for (int i = offset; i < offset + packedRealDigits; ++i, ++p) { - byte n; - int index1 = data1FirstIndex + p; - if (index1 >= field.getSize() || index1 < data1FirstIndex) { - n = 0; - } else { - byte ch = data1.getByte(index1); - if (ch == (byte) 0x20) { - n = 0; - } else if (ch >= 0x70) { - n = (byte) (ch - 0x70); - } else { - n = (byte) (ch - 0x30); - } - } - isZero &= n == 0; - if (i % 2 == 0) { - data2.setByte(i / 2, (byte) (n << 4)); - } else { - byte value = data2.getByte(i / 2); - data2.setByte(i / 2, (byte) (value | n)); - } - } - - p = this.size - 1; - byte value = this.getDataStorage().getByte(p); - if ((this.getAttribute().getFlags() & CobolFieldAttribute.COB_FLAG_HAVE_SIGN) == 0) { - this.getDataStorage().setByte(p, (byte) ((value & 0xf0) | 0x0f)); - } else if (sign < 0 && !isZero) { - this.getDataStorage().setByte(p, (byte) ((value & 0xf0) | 0x0d)); - } else { - this.getDataStorage().setByte(p, (byte) ((value & 0xf0) | 0x0c)); - } - } - - @Override - public void moveFrom(byte[] bytes) { - this.dataStorage.setData(bytes); - } - - @Override - public void moveFrom(String string) { - try { - this.dataStorage.setData(string.getBytes("SJIS")); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - } - - @Override - public void moveFrom(int val) { - int n; - int sign = 0; - CobolDataStorage data = this.getDataStorage(); - - if (val == Integer.MIN_VALUE) { - // Integer.MIN_VALUE == -2147483647 - int[] bytes = {2, 1, 4, 7, 4, 8, 3, 6, 4, 8}; - int digits = this.getAttribute().getDigits(); - for (int i = 0; i < digits; ++i) { - if (i < bytes.length) { - this.setDigit(digits - 1 - i, bytes[bytes.length - 1 - i]); - } else { - this.setDigit(digits - 1 - i, 0); - } - } - this.putSign(-1); - return; - } else if (val < 0) { - n = -val; - sign = 1; - } else { - n = val; - } - this.getDataStorage().fillBytes(0, this.getSize()); - int p = this.getSize() - 1; - byte b = data.getByte(p); - b = (byte) ((n % 10) << 4); - if (!this.getAttribute().isFlagHaveSign()) { - b |= 0x0f; - } else if (sign != 0) { - b |= 0x0d; - } else { - b |= 0x0c; - } - data.setByte(p, b); - n /= 10; - p--; - - for (; n != 0 && p >= 0; n /= 100, p--) { - data.setByte(p, packed_bytes[n % 100]); - } - - /* Fixme */ - if (this.getAttribute().getDigits() % 2 == 0) { - data.setByte(0, (byte) (data.getByte(0) & 0x0F)); - } - } - - /** - * 指定の桁に指定の値を設定する - * - * @param index 桁の - * @param value 設定する値 - */ - private void setDigit(int index, int value) { - // 符号を格納 - byte lastByte = this.dataStorage.getByte(this.size - 1); - if (value < 0) { - this.dataStorage.setByte(this.size - 1, (byte) ((lastByte & 0xF0) | 0x0D)); - } else { - this.dataStorage.setByte(this.size - 1, (byte) ((lastByte & 0xF0) | 0x0C)); - } - - int i = this.getByteIndex(index); - - if ((this.getAttribute().getDigits() + index) % 2 == 0) { - byte x = this.dataStorage.getByte(i); - x = (byte) ((x & (0x0F << 4)) | value); - this.dataStorage.setByte(i, x); - } else { - byte x = this.dataStorage.getByte(i); - x = (byte) ((x & 0x0F) | (value << 4)); - this.dataStorage.setByte(i, x); - } - } - - /** - * 指定のけたの値を取得する - * - * @param index 桁 - * @return index桁目の値 - */ - private int getDigit(int index) { - int i = this.getByteIndex(index); - - if ((this.getAttribute().getDigits() + index) % 2 == 0) { - return (byte) (this.dataStorage.getByte(i) & 0x0F); - } else { - return (byte) ((this.dataStorage.getByte(i) >>> 4) & 0x0F); - } - } - - /** - * 指定した桁の値を取得する - * - * @param index 取得する桁の位置 - * @return index番目の桁の値 - */ - private int getByteIndex(int index) { - if (this.getAttribute().getDigits() % 2 == 0) { - return (index + 1) / 2; - } else { - return index / 2; - } - } - - @Override - public CobolNumericField getNumericField() { - int size = this.getAttribute().getDigits(); - int scale = this.getAttribute().getScale(); - CobolFieldAttribute attr = - new CobolFieldAttribute( - CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, - size, - scale, - CobolFieldAttribute.COB_FLAG_HAVE_SIGN, - null); - CobolDataStorage data = new CobolDataStorage(this.getAttribute().getDigits()); - CobolNumericField field = new CobolNumericField(size, data, attr); - field.moveFrom(this); - return field; - } - - @Override - public void moveFrom(BigDecimal number) { - // TODO 自動生成されたメソッド・スタブ - } - - @Override - public void moveFrom(CobolDataStorage dataStorage) { - // TODO 自動生成されたメソッド・スタブ - } - - @Override - public int getSign() { - if (!this.getAttribute().isFlagHaveSign()) { - return 0; - } - int index = this.size - 1; - return (this.dataStorage.getByte(index) & 0x0f) == 0x0d ? -1 : 1; - } - - @Override - public void putSign(int sign) { - int index = this.getSize() - 1; - byte value = this.dataStorage.getByte(index); - if (sign < 0) { - this.getDataStorage().setByte(index, (byte) ((value & 0xf0) | 0x0d)); - } else { - this.getDataStorage().setByte(index, (byte) ((value & 0xf0) | 0x0c)); - } - } - - @Override - public CobolDecimal getDecimal() { - CobolDataStorage data = this.getDataStorage(); - int p = 0; - int digits = this.getAttribute().getDigits(); - int sign = this.getSign(); - int val; - BigDecimal value; - - if (digits % 2 == 0) { - val = data.getByte(p) & 0x0F; - digits--; - p++; - } else { - val = 0; - } - - if (this.getAttribute().getDigits() < 10) { - while (digits > 1) { - if (val != 0) { - val *= 100; - } - if (data.getByte(p) != 0) { - val += (upper4bits(data.getByte(p)) * 10) + (data.getByte(p) & 0x0F); - } - digits -= 2; - p++; - } - if (val != 0) { - val *= 10; - } - val += upper4bits(data.getByte(p)); - value = new BigDecimal(val); - } else { - int valseen = 0; - value = new BigDecimal(val); - if (val != 0) { - valseen = 1; - } - while (digits > 1) { - if (valseen != 0) { - value = value.multiply(new BigDecimal(100)); - } - if (data.getByte(p) != 0) { - int n = (upper4bits(data.getByte(p))) * 10 + (data.getByte(p) & 0x0F); - value = value.add(new BigDecimal(n)); - valseen = 1; - } - digits -= 2; - p++; - } - if (valseen != 0) { - value = value.multiply(BigDecimal.TEN); - } - value = value.add(new BigDecimal(upper4bits(data.getByte(p)))); - } - - if (sign < 0) { - value = value.negate(); - } - return new CobolDecimal(value, this.getAttribute().getScale()); - } - - /** - * byte型データを右に4回シフトした値を返す CとJavaのビット演算の仕様に差異があるため実装した - * - * @param b TODO: 準備中 - * @return b>>4 - */ - private byte upper4bits(byte b) { - return (byte) ((b >>> 4) & 0x0F); - } - - @Override - public int getInt() { - int p = 0; - CobolDataStorage data = this.getDataStorage(); - int val = 0; - - for (int size = 0; size < this.getSize() - 1; ++size, ++p) { - val *= 10; - val += (data.getByte(p) >>> 4) & 0x0F; - val *= 10; - val += data.getByte(p) & 0x0F; - } - val *= 10; - val += (data.getByte(p) >>> 4) & 0x0F; - if ((data.getByte(p) & 0x0F) == 0x0d) { - val = -val; - } - return val; - } - - /** thisの保持する数値データを0に設定する */ - @Override - public void setZero() { - CobolDataStorage data = this.getDataStorage(); - int size = this.getSize(); - for (int i = 0; i < size; ++i) { - data.setByte(i, (byte) 0); - } - if (this.getAttribute().isFlagHaveSign()) { - data.setByte(size - 1, (byte) 0x0C); - } else { - data.setByte(size - 1, (byte) 0x0F); - } - } - - @Override - public int addPackedInt(int val) { - if (val == 0) { - return 0; - } - - int p = this.getSize() - 1; - CobolDataStorage data = this.getDataStorage(); - int n; - if ((data.getByte(p) & 0x0F) == 0x0d) { - if (val > 0) { - return this.addInt(val); - } - n = -val; - } else { - if (val < 0) { - return this.addInt(val); - } - n = val; - } - int inc = upper4bits(data.getByte(p)) + (n % 10); - n /= 10; - int carry = inc / 10; - data.setByte(p, (byte) (((inc % 10) << 4) | data.getByte(p) & 0x0F)); - p--; - - for (int size = 0; size < this.getSize() - 1; ++size, --p) { - if (carry == 0 && n == 0) { - break; - } - byte x = data.getByte(p); - inc = (upper4bits(x) * 10) + (x & 0x0F) + carry + (n % 100); - carry = inc / 100; - n /= 100; - inc %= 100; - data.setByte(p, (byte) (((inc / 10) << 4) | (inc % 10))); - } - return 0; - } - - @Override - public int addInt(int ival) { - if (ival == 0) { - return 0; - } - - long val = ival; - int ndigs = this.getAttribute().getScale(); - while (ndigs > 0) { - --ndigs; - val *= 10; - } - ndigs = this.getAttribute().getDigits(); - if (ndigs <= 0) { - return 0; - } - int sign = this.getSign(); - int msn = 1; - int emptydig = 1 - (this.getAttribute().getDigits() % 2); - int subtr = 0; - - if (sign < 0) { - val = -val; - } - if (val < 0) { - val = -val; - subtr = 1; - } - - int p = ((ndigs + emptydig) / 2) - (1 - msn); - CobolDataStorage data = this.getDataStorage(); - int origdigs = ndigs; - int carry = 0; - int zeroes = 0; - - while (ndigs-- != 0) { - int tval; - if (msn == 0) { - tval = data.getByte(p) & 0x0F; - } else { - tval = upper4bits((byte) (data.getByte(p) & 0xF0)); - } - if (val != 0) { - carry += (val % 10); - val /= 10; - } - if (subtr != 0) { - tval -= carry; - if (tval < 0) { - tval += 10; - carry = 1; - } else { - carry = 0; - } - } else { - tval += carry; - if (tval > 9) { - tval %= 10; - carry = 1; - } else { - carry = 0; - } - } - if (tval == 0) { - zeroes++; - } - if (msn == 0) { - data.setByte(p, (byte) ((data.getByte(p) & 0xF0) | tval)); - msn = 1; - } else { - data.setByte(p, (byte) ((data.getByte(p) & 0x0F) | (tval << 4))); - msn = 0; - p--; - } - } - - if (sign != 0) { - p = this.getSize() - 1; - byte x = data.getByte(p); - if (origdigs == zeroes) { - data.setByte(p, (byte) ((x & 0xF0) | 0x0C)); - } else if (subtr != 0 && carry != 0) { - complementPacked(); - sign = -sign; - if (sign < 0) { - data.setByte(p, (byte) ((x & 0xF0) | 0x0D)); - } else { - data.setByte(p, (byte) ((x & 0xF0) | 0x0C)); - } - } - } else if (subtr != 0 && carry != 0) { - complementPacked(); - } - return 0; - } - - /** libcob/numeric.cのcob_complement_packedの実装 */ - private void complementPacked() { - int ndigs = this.getAttribute().getDigits(); - int msn = 1; - int emptydig = 1 - (this.getAttribute().getDigits() % 2); - int p = ((ndigs + emptydig) / 2) - (1 - msn); - CobolDataStorage data = this.getDataStorage(); - int tval; - int carry = 0; - - while (ndigs-- != 0) { - if (msn == 0) { - tval = data.getByte(p) & 0x0F; - } else { - tval = upper4bits((byte) (data.getByte(p) & 0xF0)); - } - tval += carry; - if (tval > 0) { - carry = 1; - tval = 10 - tval; - } else { - carry = 0; - } - byte x = data.getByte(p); - if (msn == 0) { - data.setByte(p, (byte) (x & 0xF0 | tval)); - msn = 1; - } else { - data.setByte(p, (byte) (x & 0x0F | (tval << 4))); - msn = 0; - p--; - } - } - } - - @Override - public int cmpInt(int n) { - if (this.getAttribute().getDigits() < 10) { - return this.cmpPackedInt(n); - } else { - return this.cmpPacked(n); - } - } - - /** - * libcob/codegen.hのcob_cmp_packed_intの実装 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - private int cmpPackedInt(int n) { - CobolDataStorage data = this.getDataStorage(); - int val = 0; - int p = 0; - - for (int size = 0; size < this.getSize() - 1; ++size, ++p) { - val *= 10; - val += (data.getByte(p) >>> 4) & 0x0F; - val *= 10; - val += data.getByte(p) & 0x0F; - } - val *= 10; - val += (data.getByte(p) >> 4) & 0x0F; - if ((data.getByte(p) & 0x0F) == 0x0d) { - val = -val; - } - - return val < n ? -1 : val > n ? 1 : 0; - } - - /** - * libcob/numeric.cのcob_cmp_packedの実装 - * - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - private int cmpPacked(int n) { - int sign = this.getSign(); - if (sign >= 0 && n < 0) { - return 1; - } - if (sign < 0 && n >= 0) { - return -1; - } - - int p = 0; - CobolDataStorage data = this.getDataStorage(); - byte[] val1 = new byte[20]; - int inc = 0; - int size; - for (size = 0; size < 20; size++) { - if (size < 20 - this.getSize()) { - val1[size] = 0; - } else { - val1[size] = data.getByte(inc++); - } - } - val1[19] &= 0xF0; - if (this.getAttribute().getDigits() % 2 == 0) { - val1[20 - this.getSize()] &= 0x0F; - } - if (n != CobolDecimal.packedValueInt) { - CobolDecimal.packedValueInt = n; - if (n < 0) { - n = -n; - } - for (int i = 0; i < 6; ++i) { - CobolDecimal.packedValue[14 + i] = 0; - } - if (n != 0) { - p = 19; - CobolDecimal.packedValue[p] = (byte) ((n % 10) << 4); - p--; - n /= 10; - while (n != 0) { - size = n % 100; - CobolDecimal.packedValue[p] = (byte) ((size % 10) | ((size / 10) << 4)); - n /= 100; - p--; - } - } - } - for (size = 0; size < 20; size++) { - if (val1[size] != CobolDecimal.packedValue[size]) { - if (sign < 0) { - return Byte.toUnsignedInt(CobolDecimal.packedValue[size]) - - Byte.toUnsignedInt(val1[size]); - } else { - return Byte.toUnsignedInt(val1[size]) - - Byte.toUnsignedInt(CobolDecimal.packedValue[size]); - } - } - } - return 0; - } - - @Override - public long getLong() { - int digits = this.getAttribute().getDigits(); - int scale = this.getAttribute().getScale(); - CobolDataStorage data = this.getDataStorage(); - int sign = this.getSign(); - int offset = 1 - (this.getAttribute().getDigits() % 2); - int val = 0; - - for (int i = offset; i < digits - scale + offset; ++i) { - val *= 10; - if (i % 2 == 0) { - val += (0xFF & data.getByte(i / 2)) >> 4; - } else { - val += data.getByte(i / 2) & 0x0F; - } - } - - if (sign < 0) { - val = -val; - } - return val; - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.data; + +import java.math.BigDecimal; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; + +/** PIC 文字列が9(5) COMP-3などの変数を表現するクラス. */ +public class CobolNumericPackedField extends AbstractCobolField { + private static final byte[] packed_bytes = { + 0x00, + 0x01, + 0x02, + 0x03, + 0x04, + 0x05, + 0x06, + 0x07, + 0x08, + 0x09, + 0x10, + 0x11, + 0x12, + 0x13, + 0x14, + 0x15, + 0x16, + 0x17, + 0x18, + 0x19, + 0x20, + 0x21, + 0x22, + 0x23, + 0x24, + 0x25, + 0x26, + 0x27, + 0x28, + 0x29, + 0x30, + 0x31, + 0x32, + 0x33, + 0x34, + 0x35, + 0x36, + 0x37, + 0x38, + 0x39, + 0x40, + 0x41, + 0x42, + 0x43, + 0x44, + 0x45, + 0x46, + 0x47, + 0x48, + 0x49, + 0x50, + 0x51, + 0x52, + 0x53, + 0x54, + 0x55, + 0x56, + 0x57, + 0x58, + 0x59, + 0x60, + 0x61, + 0x62, + 0x63, + 0x64, + 0x65, + 0x66, + 0x67, + 0x68, + 0x69, + 0x70, + 0x71, + 0x72, + 0x73, + 0x74, + 0x75, + 0x76, + 0x77, + 0x78, + 0x79, + (byte) 0x80, + (byte) 0x81, + (byte) 0x82, + (byte) 0x83, + (byte) 0x84, + (byte) 0x85, + (byte) 0x86, + (byte) 0x87, + (byte) 0x88, + (byte) 0x89, + (byte) 0x90, + (byte) 0x91, + (byte) 0x92, + (byte) 0x93, + (byte) 0x94, + (byte) 0x95, + (byte) 0x96, + (byte) 0x97, + (byte) 0x98, + (byte) 0x99 + }; + + /** + * コンストラクタ + * + * @param size データを格納するバイト配列の長さ + * @param dataStorage データを格納するバイト配列を扱うオブジェクト + * @param attribute 変数に関する様々な情報を保持するオブジェクト(符号付か,COMP-3指定かなど) + */ + public CobolNumericPackedField( + int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) { + super(size, dataStorage, attribute); + } + + /** + * TODO: 準備中 + * + * @param s TODO: 準備中 + */ + public void checkNumeric(String s) {} + + @Override + public byte[] getBytes() { + return dataStorage.getData(); + } + + @Override + public String getString() { + StringBuilder sb = new StringBuilder(); + int digits = this.getAttribute().getDigits(); + int scale = this.getAttribute().getScale(); + int counter = digits - scale; + int len; + if (scale < 0) { + len = digits + scale; + } else { + len = digits; + } + for (int i = 0; i < len; ++i, --counter) { + if (counter == 0) { + sb.append('.'); + } + sb.append((char) (this.getDigit(i) + 0x30)); + } + for (int i = 0; i < -scale; ++i) { + sb.append('0'); + } + + if (this.getAttribute().isFlagHaveSign()) { + if (this.getSign() < 0) { + return "-" + sb; + } else { + return "+" + sb; + } + } else { + return sb.toString(); + } + } + + @Override + public void setDecimal(BigDecimal decimal) { + byte[] decimalBytes = decimal.toPlainString().getBytes(AbstractCobolField.charSetSJIS); + int length = Math.min(this.size, decimalBytes.length); + + for (int i = 0; i < length; ++i) { + this.dataStorage.setByte(this.size - 1 - i, decimalBytes[decimalBytes.length - 1 - i]); + } + } + + @Override + public void moveFrom(AbstractCobolField src) { + AbstractCobolField src1 = this.preprocessOfMoving(src); + if (src1 == null) { + return; + } + + switch (src1.getAttribute().getType()) { + case CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY: + this.moveDisplayToPacked(src1); + break; + case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED: + case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC: + case CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY: + case CobolFieldAttribute.COB_TYPE_NATIONAL: + case CobolFieldAttribute.COB_TYPE_NUMERIC_EDITED: + case CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_EDITED: + case CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED: + this.moveFrom(src1.getNumericField()); + break; + case CobolFieldAttribute.COB_TYPE_GROUP: + CobolAlphanumericField.moveAlphanumToAlphanum(this, src1); + break; + default: + throw new CobolRuntimeException(0, "未実装"); + } + } + + /** + * CobolNumericFieldからthisへの代入を行う + * + * @param field 代入元のデータ(AbstractCobolField型) + */ + private void moveDisplayToPacked(AbstractCobolField field) { + int sign = field.getSign(); + CobolDataStorage data1 = field.getDataStorage(); + int data1FirstIndex = field.getFirstDataIndex(); + int digits1 = field.getAttribute().getDigits(); + int scale1 = field.getAttribute().getScale(); + CobolDataStorage data2 = this.getDataStorage(); + int digits2 = this.getAttribute().getDigits(); + int scale2 = this.getAttribute().getScale(); + int packedRealDigits; + if (scale2 < 0) { + packedRealDigits = digits2 + scale2; + } else { + packedRealDigits = digits2; + } + + /* null check */ + boolean flagNull = true; + for (int i = 0; i < digits1; ++i) { + if (field.getDataStorage().getByte(i) != 0) { + flagNull = false; + } + } + if (flagNull) { + this.getDataStorage().fillBytes((byte) 0, this.getSize()); + return; + } + + /* pack string */ + this.getDataStorage().fillBytes((byte) 0, this.getSize()); + int offset = 1 - (digits2 % 2); + int p; + if (scale2 < 0) { + p = (digits1 - scale1) - digits2; + } else { + p = (digits1 - scale1) - (digits2 - scale2); + } + + boolean isZero = true; + for (int i = offset; i < offset + packedRealDigits; ++i, ++p) { + byte n; + int index1 = data1FirstIndex + p; + if (index1 >= field.getSize() || index1 < data1FirstIndex) { + n = 0; + } else { + byte ch = data1.getByte(index1); + if (ch == (byte) 0x20) { + n = 0; + } else if (ch >= 0x70) { + n = (byte) (ch - 0x70); + } else { + n = (byte) (ch - 0x30); + } + } + isZero &= n == 0; + if (i % 2 == 0) { + data2.setByte(i / 2, (byte) (n << 4)); + } else { + byte value = data2.getByte(i / 2); + data2.setByte(i / 2, (byte) (value | n)); + } + } + + p = this.size - 1; + byte value = this.getDataStorage().getByte(p); + if ((this.getAttribute().getFlags() & CobolFieldAttribute.COB_FLAG_HAVE_SIGN) == 0) { + this.getDataStorage().setByte(p, (byte) ((value & 0xf0) | 0x0f)); + } else if (sign < 0 && !isZero) { + this.getDataStorage().setByte(p, (byte) ((value & 0xf0) | 0x0d)); + } else { + this.getDataStorage().setByte(p, (byte) ((value & 0xf0) | 0x0c)); + } + } + + @Override + public void moveFrom(byte[] bytes) { + this.dataStorage.setData(bytes); + } + + @Override + public void moveFrom(String string) { + this.dataStorage.setData(string.getBytes(AbstractCobolField.charSetSJIS)); + } + + @Override + public void moveFrom(int val) { + int n; + int sign = 0; + CobolDataStorage data = this.getDataStorage(); + + if (val == Integer.MIN_VALUE) { + // Integer.MIN_VALUE == -2147483647 + int[] bytes = {2, 1, 4, 7, 4, 8, 3, 6, 4, 8}; + int digits = this.getAttribute().getDigits(); + for (int i = 0; i < digits; ++i) { + if (i < bytes.length) { + this.setDigit(digits - 1 - i, bytes[bytes.length - 1 - i]); + } else { + this.setDigit(digits - 1 - i, 0); + } + } + this.putSign(-1); + return; + } else if (val < 0) { + n = -val; + sign = 1; + } else { + n = val; + } + this.getDataStorage().fillBytes(0, this.getSize()); + int p = this.getSize() - 1; + byte b = data.getByte(p); + b = (byte) ((n % 10) << 4); + if (!this.getAttribute().isFlagHaveSign()) { + b |= 0x0f; + } else if (sign != 0) { + b |= 0x0d; + } else { + b |= 0x0c; + } + data.setByte(p, b); + n /= 10; + p--; + + for (; n != 0 && p >= 0; n /= 100, p--) { + data.setByte(p, packed_bytes[n % 100]); + } + + /* Fixme */ + if (this.getAttribute().getDigits() % 2 == 0) { + data.setByte(0, (byte) (data.getByte(0) & 0x0F)); + } + } + + /** + * 指定の桁に指定の値を設定する + * + * @param index 桁の + * @param value 設定する値 + */ + private void setDigit(int index, int value) { + // 符号を格納 + byte lastByte = this.dataStorage.getByte(this.size - 1); + if (value < 0) { + this.dataStorage.setByte(this.size - 1, (byte) ((lastByte & 0xF0) | 0x0D)); + } else { + this.dataStorage.setByte(this.size - 1, (byte) ((lastByte & 0xF0) | 0x0C)); + } + + int i = this.getByteIndex(index); + + if ((this.getAttribute().getDigits() + index) % 2 == 0) { + byte x = this.dataStorage.getByte(i); + x = (byte) ((x & (0x0F << 4)) | value); + this.dataStorage.setByte(i, x); + } else { + byte x = this.dataStorage.getByte(i); + x = (byte) ((x & 0x0F) | (value << 4)); + this.dataStorage.setByte(i, x); + } + } + + /** + * 指定のけたの値を取得する + * + * @param index 桁 + * @return index桁目の値 + */ + private int getDigit(int index) { + int i = this.getByteIndex(index); + + if ((this.getAttribute().getDigits() + index) % 2 == 0) { + return (byte) (this.dataStorage.getByte(i) & 0x0F); + } else { + return (byte) ((this.dataStorage.getByte(i) >>> 4) & 0x0F); + } + } + + /** + * 指定した桁の値を取得する + * + * @param index 取得する桁の位置 + * @return index番目の桁の値 + */ + private int getByteIndex(int index) { + if (this.getAttribute().getDigits() % 2 == 0) { + return (index + 1) / 2; + } else { + return index / 2; + } + } + + @Override + public CobolNumericField getNumericField() { + int size = this.getAttribute().getDigits(); + int scale = this.getAttribute().getScale(); + CobolFieldAttribute attr = + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY, + size, + scale, + CobolFieldAttribute.COB_FLAG_HAVE_SIGN, + null); + CobolDataStorage data = new CobolDataStorage(this.getAttribute().getDigits()); + CobolNumericField field = new CobolNumericField(size, data, attr); + field.moveFrom(this); + return field; + } + + @Override + public void moveFrom(BigDecimal number) { + // TODO 自動生成されたメソッド・スタブ + } + + @Override + public void moveFrom(CobolDataStorage dataStorage) { + // TODO 自動生成されたメソッド・スタブ + } + + @Override + public int getSign() { + if (!this.getAttribute().isFlagHaveSign()) { + return 0; + } + int index = this.size - 1; + return (this.dataStorage.getByte(index) & 0x0f) == 0x0d ? -1 : 1; + } + + @Override + public void putSign(int sign) { + int index = this.getSize() - 1; + byte value = this.dataStorage.getByte(index); + if (sign < 0) { + this.getDataStorage().setByte(index, (byte) ((value & 0xf0) | 0x0d)); + } else { + this.getDataStorage().setByte(index, (byte) ((value & 0xf0) | 0x0c)); + } + } + + @Override + public CobolDecimal getDecimal() { + CobolDataStorage data = this.getDataStorage(); + int p = 0; + int digits = this.getAttribute().getDigits(); + int sign = this.getSign(); + int val; + BigDecimal value; + + if (digits % 2 == 0) { + val = data.getByte(p) & 0x0F; + digits--; + p++; + } else { + val = 0; + } + + if (this.getAttribute().getDigits() < 10) { + while (digits > 1) { + if (val != 0) { + val *= 100; + } + if (data.getByte(p) != 0) { + val += (upper4bits(data.getByte(p)) * 10) + (data.getByte(p) & 0x0F); + } + digits -= 2; + p++; + } + if (val != 0) { + val *= 10; + } + val += upper4bits(data.getByte(p)); + value = new BigDecimal(val); + } else { + int valseen = 0; + value = new BigDecimal(val); + if (val != 0) { + valseen = 1; + } + while (digits > 1) { + if (valseen != 0) { + value = value.multiply(new BigDecimal(100)); + } + if (data.getByte(p) != 0) { + int n = (upper4bits(data.getByte(p))) * 10 + (data.getByte(p) & 0x0F); + value = value.add(new BigDecimal(n)); + valseen = 1; + } + digits -= 2; + p++; + } + if (valseen != 0) { + value = value.multiply(BigDecimal.TEN); + } + value = value.add(new BigDecimal(upper4bits(data.getByte(p)))); + } + + if (sign < 0) { + value = value.negate(); + } + return new CobolDecimal(value, this.getAttribute().getScale()); + } + + /** + * byte型データを右に4回シフトした値を返す CとJavaのビット演算の仕様に差異があるため実装した + * + * @param b TODO: 準備中 + * @return b>>4 + */ + private byte upper4bits(byte b) { + return (byte) ((b >>> 4) & 0x0F); + } + + @Override + public int getInt() { + int p = 0; + CobolDataStorage data = this.getDataStorage(); + int val = 0; + + for (int size = 0; size < this.getSize() - 1; ++size, ++p) { + val *= 10; + val += (data.getByte(p) >>> 4) & 0x0F; + val *= 10; + val += data.getByte(p) & 0x0F; + } + val *= 10; + val += (data.getByte(p) >>> 4) & 0x0F; + if ((data.getByte(p) & 0x0F) == 0x0d) { + val = -val; + } + return val; + } + + /** thisの保持する数値データを0に設定する */ + @Override + public void setZero() { + CobolDataStorage data = this.getDataStorage(); + int size = this.getSize(); + for (int i = 0; i < size; ++i) { + data.setByte(i, (byte) 0); + } + if (this.getAttribute().isFlagHaveSign()) { + data.setByte(size - 1, (byte) 0x0C); + } else { + data.setByte(size - 1, (byte) 0x0F); + } + } + + @Override + public int addPackedInt(int val) { + if (val == 0) { + return 0; + } + + int p = this.getSize() - 1; + CobolDataStorage data = this.getDataStorage(); + int n; + if ((data.getByte(p) & 0x0F) == 0x0d) { + if (val > 0) { + return this.addInt(val); + } + n = -val; + } else { + if (val < 0) { + return this.addInt(val); + } + n = val; + } + int inc = upper4bits(data.getByte(p)) + (n % 10); + n /= 10; + int carry = inc / 10; + data.setByte(p, (byte) (((inc % 10) << 4) | data.getByte(p) & 0x0F)); + p--; + + for (int size = 0; size < this.getSize() - 1; ++size, --p) { + if (carry == 0 && n == 0) { + break; + } + byte x = data.getByte(p); + inc = (upper4bits(x) * 10) + (x & 0x0F) + carry + (n % 100); + carry = inc / 100; + n /= 100; + inc %= 100; + data.setByte(p, (byte) (((inc / 10) << 4) | (inc % 10))); + } + return 0; + } + + @Override + public int addInt(int ival) { + if (ival == 0) { + return 0; + } + + long val = ival; + int ndigs = this.getAttribute().getScale(); + while (ndigs > 0) { + --ndigs; + val *= 10; + } + ndigs = this.getAttribute().getDigits(); + if (ndigs <= 0) { + return 0; + } + int sign = this.getSign(); + int msn = 1; + int emptydig = 1 - (this.getAttribute().getDigits() % 2); + int subtr = 0; + + if (sign < 0) { + val = -val; + } + if (val < 0) { + val = -val; + subtr = 1; + } + + int p = ((ndigs + emptydig) / 2) - (1 - msn); + CobolDataStorage data = this.getDataStorage(); + int origdigs = ndigs; + int carry = 0; + int zeroes = 0; + + while (ndigs-- != 0) { + int tval; + if (msn == 0) { + tval = data.getByte(p) & 0x0F; + } else { + tval = upper4bits((byte) (data.getByte(p) & 0xF0)); + } + if (val != 0) { + carry += (val % 10); + val /= 10; + } + if (subtr != 0) { + tval -= carry; + if (tval < 0) { + tval += 10; + carry = 1; + } else { + carry = 0; + } + } else { + tval += carry; + if (tval > 9) { + tval %= 10; + carry = 1; + } else { + carry = 0; + } + } + if (tval == 0) { + zeroes++; + } + if (msn == 0) { + data.setByte(p, (byte) ((data.getByte(p) & 0xF0) | tval)); + msn = 1; + } else { + data.setByte(p, (byte) ((data.getByte(p) & 0x0F) | (tval << 4))); + msn = 0; + p--; + } + } + + if (sign != 0) { + p = this.getSize() - 1; + byte x = data.getByte(p); + if (origdigs == zeroes) { + data.setByte(p, (byte) ((x & 0xF0) | 0x0C)); + } else if (subtr != 0 && carry != 0) { + complementPacked(); + sign = -sign; + if (sign < 0) { + data.setByte(p, (byte) ((x & 0xF0) | 0x0D)); + } else { + data.setByte(p, (byte) ((x & 0xF0) | 0x0C)); + } + } + } else if (subtr != 0 && carry != 0) { + complementPacked(); + } + return 0; + } + + /** libcob/numeric.cのcob_complement_packedの実装 */ + private void complementPacked() { + int ndigs = this.getAttribute().getDigits(); + int msn = 1; + int emptydig = 1 - (this.getAttribute().getDigits() % 2); + int p = ((ndigs + emptydig) / 2) - (1 - msn); + CobolDataStorage data = this.getDataStorage(); + int tval; + int carry = 0; + + while (ndigs-- != 0) { + if (msn == 0) { + tval = data.getByte(p) & 0x0F; + } else { + tval = upper4bits((byte) (data.getByte(p) & 0xF0)); + } + tval += carry; + if (tval > 0) { + carry = 1; + tval = 10 - tval; + } else { + carry = 0; + } + byte x = data.getByte(p); + if (msn == 0) { + data.setByte(p, (byte) (x & 0xF0 | tval)); + msn = 1; + } else { + data.setByte(p, (byte) (x & 0x0F | (tval << 4))); + msn = 0; + p--; + } + } + } + + @Override + public int cmpInt(int n) { + if (this.getAttribute().getDigits() < 10) { + return this.cmpPackedInt(n); + } else { + return this.cmpPacked(n); + } + } + + /** + * libcob/codegen.hのcob_cmp_packed_intの実装 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + private int cmpPackedInt(int n) { + CobolDataStorage data = this.getDataStorage(); + int val = 0; + int p = 0; + + for (int size = 0; size < this.getSize() - 1; ++size, ++p) { + val *= 10; + val += (data.getByte(p) >>> 4) & 0x0F; + val *= 10; + val += data.getByte(p) & 0x0F; + } + val *= 10; + val += (data.getByte(p) >> 4) & 0x0F; + if ((data.getByte(p) & 0x0F) == 0x0d) { + val = -val; + } + + return val < n ? -1 : val > n ? 1 : 0; + } + + /** + * libcob/numeric.cのcob_cmp_packedの実装 + * + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + private int cmpPacked(int n) { + int sign = this.getSign(); + if (sign >= 0 && n < 0) { + return 1; + } + if (sign < 0 && n >= 0) { + return -1; + } + + int p = 0; + CobolDataStorage data = this.getDataStorage(); + byte[] val1 = new byte[20]; + int inc = 0; + int size; + for (size = 0; size < 20; size++) { + if (size < 20 - this.getSize()) { + val1[size] = 0; + } else { + val1[size] = data.getByte(inc++); + } + } + val1[19] &= 0xF0; + if (this.getAttribute().getDigits() % 2 == 0) { + val1[20 - this.getSize()] &= 0x0F; + } + if (n != CobolDecimal.packedValueInt) { + CobolDecimal.packedValueInt = n; + if (n < 0) { + n = -n; + } + for (int i = 0; i < 6; ++i) { + CobolDecimal.packedValue[14 + i] = 0; + } + if (n != 0) { + p = 19; + CobolDecimal.packedValue[p] = (byte) ((n % 10) << 4); + p--; + n /= 10; + while (n != 0) { + size = n % 100; + CobolDecimal.packedValue[p] = (byte) ((size % 10) | ((size / 10) << 4)); + n /= 100; + p--; + } + } + } + for (size = 0; size < 20; size++) { + if (val1[size] != CobolDecimal.packedValue[size]) { + if (sign < 0) { + return Byte.toUnsignedInt(CobolDecimal.packedValue[size]) + - Byte.toUnsignedInt(val1[size]); + } else { + return Byte.toUnsignedInt(val1[size]) + - Byte.toUnsignedInt(CobolDecimal.packedValue[size]); + } + } + } + return 0; + } + + @Override + public long getLong() { + int digits = this.getAttribute().getDigits(); + int scale = this.getAttribute().getScale(); + CobolDataStorage data = this.getDataStorage(); + int sign = this.getSign(); + int offset = 1 - (this.getAttribute().getDigits() % 2); + int val = 0; + + for (int i = offset; i < digits - scale + offset; ++i) { + val *= 10; + if (i % 2 == 0) { + val += (0xFF & data.getByte(i / 2)) >> 4; + } else { + val += data.getByte(i / 2) & 0x0F; + } + } + + if (sign < 0) { + val = -val; + } + return val; + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/exceptions/CobolExceptionId.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/exceptions/CobolExceptionId.java index b1e89abe..a082a060 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/exceptions/CobolExceptionId.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/exceptions/CobolExceptionId.java @@ -1,319 +1,466 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.exceptions; - -/** 例外コードを定義するクラス */ -public class CobolExceptionId { - /** この例外コードは使用されない */ - public static final int COB_EC_ZERO = 0; - /** この例外コードは使用されない */ - public static final int COB_EC_ALL = 1; - /** TODO: 準備中 */ - public static final int COB_EC_ARGUMENT = 2; - /** TODO: 準備中 */ - public static final int COB_EC_ARGUMENT_FUNCTION = 3; - /** この例外コードは使用されない */ - public static final int COB_EC_ARGUMENT_IMP = 4; - /** この例外コードは使用されない */ - public static final int COB_EC_BOUND = 5; - /** この例外コードは使用されない */ - public static final int COB_EC_BOUND_IMP = 6; - /** この例外コードは使用されない */ - public static final int COB_EC_BOUND_ODO = 7; - /** この例外コードは使用されない */ - public static final int COB_EC_BOUND_OVERFLOW = 8; - /** TODO: 準備中 */ - public static final int COB_EC_BOUND_PTR = 9; - /** TODO: 準備中 */ - public static final int COB_EC_BOUND_REF_MOD = 10; - /** この例外コードは使用されない */ - public static final int COB_EC_BOUND_SET = 11; - /** TODO: 準備中 */ - public static final int COB_EC_BOUND_SUBSCRIPT = 12; - /** この例外コードは使用されない */ - public static final int COB_EC_BOUND_TABLE_LIMIT = 13; - /** この例外コードは使用されない */ - public static final int COB_EC_DATA = 14; - /** この例外コードは使用されない */ - public static final int COB_EC_DATA_CONVERSION = 15; - /** この例外コードは使用されない */ - public static final int COB_EC_DATA_IMP = 16; - /** この例外コードは使用されない */ - public static final int COB_EC_DATA_INCOMPATIBLE = 17; - /** この例外コードは使用されない */ - public static final int COB_EC_DATA_INTEGRITY = 18; - /** この例外コードは使用されない */ - public static final int COB_EC_DATA_PTR_NULL = 19; - /** この例外コードは使用されない */ - public static final int COB_EC_DATA_INFINITY = 20; - /** この例外コードは使用されない */ - public static final int COB_EC_DATA_NEGATIVE_INFINITY = 21; - /** この例外コードは使用されない */ - public static final int COB_EC_DATA_NOT_A_NUMBER = 22; - /** この例外コードは使用されない */ - public static final int COB_EC_FLOW = 23; - /** この例外コードは使用されない */ - public static final int COB_EC_FLOW_GLOBAL_EXIT = 24; - /** この例外コードは使用されない */ - public static final int COB_EC_FLOW_GLOBAL_GOBACK = 25; - /** この例外コードは使用されない */ - public static final int COB_EC_FLOW_IMP = 26; - /** この例外コードは使用されない */ - public static final int COB_EC_FLOW_RELEASE = 27; - /** この例外コードは使用されない */ - public static final int COB_EC_FLOW_REPORT = 28; - /** この例外コードは使用されない */ - public static final int COB_EC_FLOW_RETURN = 29; - /** この例外コードは使用されない */ - public static final int COB_EC_FLOW_SEARCH = 30; - /** この例外コードは使用されない */ - public static final int COB_EC_FLOW_USE = 31; - /** TODO: 準備中 */ - public static final int COB_EC_I_O = 32; - /** TODO: 準備中 */ - public static final int COB_EC_I_O_AT_END = 33; - /** TODO: 準備中 */ - public static final int COB_EC_I_O_EOP = 34; - /** TODO: 準備中 */ - public static final int COB_EC_I_O_EOP_OVERFLOW = 35; - /** TODO: 準備中 */ - public static final int COB_EC_I_O_FILE_SHARING = 36; - /** TODO: 準備中 */ - public static final int COB_EC_I_O_IMP = 37; - /** TODO: 準備中 */ - public static final int COB_EC_I_O_INVALID_KEY = 38; - /** TODO: 準備中 */ - public static final int COB_EC_I_O_LINAGE = 39; - /** TODO: 準備中 */ - public static final int COB_EC_I_O_LOGIC_ERROR = 40; - /** TODO: 準備中 */ - public static final int COB_EC_I_O_PERMANENT_ERROR = 41; - /** TODO: 準備中 */ - public static final int COB_EC_I_O_RECORD_OPERATION = 42; - /** TODO: 準備中 */ - public static final int COB_EC_IMP = 43; - /** TODO: 準備中 */ - public static final int COB_EC_IMP_ACCEPT = 44; - /** TODO: 準備中 */ - public static final int COB_EC_IMP_DISPLAY = 45; - /** この例外コードは使用されない */ - public static final int COB_EC_LOCALE = 46; - /** この例外コードは使用されない */ - public static final int COB_EC_LOCALE_IMP = 47; - /** この例外コードは使用されない */ - public static final int COB_EC_LOCALE_INCOMPATIBLE = 48; - /** この例外コードは使用されない */ - public static final int COB_EC_LOCALE_INVALID = 49; - /** この例外コードは使用されない */ - public static final int COB_EC_LOCALE_INVALID_PTR = 50; - /** この例外コードは使用されない */ - public static final int COB_EC_LOCALE_MISSING = 51; - /** この例外コードは使用されない */ - public static final int COB_EC_LOCALE_SIZE = 52; - /** この例外コードは使用されない */ - public static final int COB_EC_OO = 53; - /** この例外コードは使用されない */ - public static final int COB_EC_OO_CONFORMANCE = 54; - /** この例外コードは使用されない */ - public static final int COB_EC_OO_EXCEPTION = 55; - /** この例外コードは使用されない */ - public static final int COB_EC_OO_IMP = 56; - /** この例外コードは使用されない */ - public static final int COB_EC_OO_METHOD = 57; - /** この例外コードは使用されない */ - public static final int COB_EC_OO_NULL = 58; - /** この例外コードは使用されない */ - public static final int COB_EC_OO_RESOURCE = 59; - /** この例外コードは使用されない */ - public static final int COB_EC_OO_UNIVERSAL = 60; - /** この例外コードは使用されない */ - public static final int COB_EC_ORDER = 61; - /** この例外コードは使用されない */ - public static final int COB_EC_ORDER_IMP = 62; - /** この例外コードは使用されない */ - public static final int COB_EC_ORDER_NOT_SUPPORTED = 63; - /** TODO: 準備中 */ - public static final int COB_EC_OVERFLOW = 64; - /** TODO: 準備中 */ - public static final int COB_EC_OVERFLOW_IMP = 65; - /** TODO: 準備中 */ - public static final int COB_EC_OVERFLOW_STRING = 66; - /** TODO: 準備中 */ - public static final int COB_EC_OVERFLOW_UNSTRING = 67; - /** この例外コードは使用されない */ - public static final int COB_EC_PROGRAM = 68; - /** この例外コードは使用されない */ - public static final int COB_EC_PROGRAM_ARG_MISMATCH = 69; - /** この例外コードは使用されない */ - public static final int COB_EC_PROGRAM_ARG_OMITTED = 70; - /** この例外コードは使用されない */ - public static final int COB_EC_PROGRAM_CANCEL_ACTIVE = 71; - /** この例外コードは使用されない */ - public static final int COB_EC_PROGRAM_IMP = 72; - /** TODO: 準備中 */ - public static final int COB_EC_PROGRAM_NOT_FOUND = 73; - /** この例外コードは使用されない */ - public static final int COB_EC_PROGRAM_PTR_NULL = 74; - /** この例外コードは使用されない */ - public static final int COB_EC_PROGRAM_RECURSIVE_CALL = 75; - /** この例外コードは使用されない */ - public static final int COB_EC_PROGRAM_RESOURCES = 76; - /** この例外コードは使用されない */ - public static final int COB_EC_RAISING = 77; - /** この例外コードは使用されない */ - public static final int COB_EC_RAISING_IMP = 78; - /** この例外コードは使用されない */ - public static final int COB_EC_RAISING_NOT_SPECIFIED = 79; - /** この例外コードは使用されない */ - public static final int COB_EC_RANGE = 80; - /** この例外コードは使用されない */ - public static final int COB_EC_RANGE_IMP = 81; - /** この例外コードは使用されない */ - public static final int COB_EC_RANGE_INDEX = 82; - /** TODO: 準備中 */ - public static final int COB_EC_RANGE_INSPECT_SIZE = 83; - /** この例外コードは使用されない */ - public static final int COB_EC_RANGE_INVALID = 84; - /** この例外コードは使用されない */ - public static final int COB_EC_RANGE_PERFORM_VARYING = 85; - /** この例外コードは使用されない */ - public static final int COB_EC_RANGE_PTR = 86; - /** この例外コードは使用されない */ - public static final int COB_EC_RANGE_SEARCH_INDEX = 87; - /** この例外コードは使用されない */ - public static final int COB_EC_RANGE_SEARCH_NO_MATCH = 88; - /** この例外コードは使用されない */ - public static final int COB_EC_REPORT = 89; - /** この例外コードは使用されない */ - public static final int COB_EC_REPORT_ACTIVE = 90; - /** この例外コードは使用されない */ - public static final int COB_EC_REPORT_COLUMN_OVERLAP = 91; - /** この例外コードは使用されない */ - public static final int COB_EC_REPORT_FILE_MODE = 92; - /** この例外コードは使用されない */ - public static final int COB_EC_REPORT_IMP = 93; - /** この例外コードは使用されない */ - public static final int COB_EC_REPORT_INACTIVE = 94; - /** この例外コードは使用されない */ - public static final int COB_EC_REPORT_LINE_OVERLAP = 95; - /** この例外コードは使用されない */ - public static final int COB_EC_REPORT_NOT_TERMINATED = 96; - /** この例外コードは使用されない */ - public static final int COB_EC_REPORT_PAGE_LIMIT = 97; - /** この例外コードは使用されない */ - public static final int COB_EC_REPORT_PAGE_WIDTH = 98; - /** この例外コードは使用されない */ - public static final int COB_EC_REPORT_SUM_SIZE = 99; - /** この例外コードは使用されない */ - public static final int COB_EC_REPORT_VARYING = 100; - /** この例外コードは使用されない */ - public static final int COB_EC_SCREEN = 101; - /** この例外コードは使用されない */ - public static final int COB_EC_SCREEN_FIELD_OVERLAP = 102; - /** この例外コードは使用されない */ - public static final int COB_EC_SCREEN_IMP = 103; - /** この例外コードは使用されない */ - public static final int COB_EC_SCREEN_ITEM_TRUNCATED = 104; - /** この例外コードは使用されない */ - public static final int COB_EC_SCREEN_LINE_NUMBER = 105; - /** この例外コードは使用されない */ - public static final int COB_EC_SCREEN_STARTING_COLUMN = 106; - /** この例外コードは使用されない */ - public static final int COB_EC_SIZE = 107; - /** この例外コードは使用されない */ - public static final int COB_EC_SIZE_ADDRESS = 108; - /** この例外コードは使用されない */ - public static final int COB_EC_SIZE_EXPONENTIATION = 109; - /** この例外コードは使用されない */ - public static final int COB_EC_SIZE_IMP = 110; - /** TODO: 準備中 */ - public static final int COB_EC_SIZE_OVERFLOW = 111; - /** この例外コードは使用されない */ - public static final int COB_EC_SIZE_TRUNCATION = 112; - /** この例外コードは使用されない */ - public static final int COB_EC_SIZE_UNDERFLOW = 113; - /** この例外コードは使用されない */ - public static final int COB_EC_SIZE_ZERO_DIVIDE = 114; - /** この例外コードは使用されない */ - public static final int COB_EC_SORT_MERGE = 115; - /** この例外コードは使用されない */ - public static final int COB_EC_SORT_MERGE_ACTIVE = 116; - /** この例外コードは使用されない */ - public static final int COB_EC_SORT_MERGE_FILE_OPEN = 117; - /** この例外コードは使用されない */ - public static final int COB_EC_SORT_MERGE_IMP = 118; - /** この例外コードは使用されない */ - public static final int COB_EC_SORT_MERGE_RELEASE = 119; - /** この例外コードは使用されない */ - public static final int COB_EC_SORT_MERGE_RETURN = 120; - /** この例外コードは使用されない */ - public static final int COB_EC_SORT_MERGE_SEQUENCE = 121; - /** この例外コードは使用されない */ - public static final int COB_EC_STORAGE = 122; - /** この例外コードは使用されない */ - public static final int COB_EC_STORAGE_IMP = 123; - /** この例外コードは使用されない */ - public static final int COB_EC_STORAGE_NOT_ALLOC = 124; - /** この例外コードは使用されない */ - public static final int COB_EC_STORAGE_NOT_AVAIL = 125; - /** この例外コードは使用されない */ - public static final int COB_EC_USER = 126; - /** この例外コードは使用されない */ - public static final int COB_EC_VALIDATE = 127; - /** この例外コードは使用されない */ - public static final int COB_EC_VALIDATE_CONTENT = 128; - /** この例外コードは使用されない */ - public static final int COB_EC_VALIDATE_FORMAT = 129; - /** この例外コードは使用されない */ - public static final int COB_EC_VALIDATE_IMP = 130; - /** この例外コードは使用されない */ - public static final int COB_EC_VALIDATE_RELATION = 131; - /** この例外コードは使用されない */ - public static final int COB_EC_VALIDATE_VARYING = 132; - /** この例外コードは使用されない */ - public static final int COB_EC_FUNCTION = 133; - /** この例外コードは使用されない */ - public static final int COB_EC_FUNCTION_NOT_FOUND = 134; - /** この例外コードは使用されない */ - public static final int COB_EC_FUNCTION_PTR_INVALID = 135; - /** この例外コードは使用されない */ - public static final int COB_EC_FUNCTION_PTR_NULL = 136; - /** この例外コードは使用されない */ - public static final int COB_EC_XML = 137; - /** この例外コードは使用されない */ - public static final int COB_EC_XML_CODESET = 138; - /** この例外コードは使用されない */ - public static final int COB_EC_XML_CODESET_CONVERSION = 139; - /** この例外コードは使用されない */ - public static final int COB_EC_XML_COUNT = 140; - /** この例外コードは使用されない */ - public static final int COB_EC_XML_DOCUMENT_TYPE = 141; - /** この例外コードは使用されない */ - public static final int COB_EC_XML_IMPLICIT_CLOSE = 142; - /** この例外コードは使用されない */ - public static final int COB_EC_XML_INVALID = 143; - /** この例外コードは使用されない */ - public static final int COB_EC_XML_NAMESPACE = 144; - /** この例外コードは使用されない */ - public static final int COB_EC_XML_STACKED_OPEN = 145; - /** この例外コードは使用されない */ - public static final int COB_EC_XML_RANGE = 146; - /** この例外コードは使用されない */ - public static final int COB_EC_MAX = 147; -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.exceptions; + +/** 例外コードを定義するクラス */ +public class CobolExceptionId { + /** この例外コードは使用されない */ + public static final int COB_EC_ZERO = 0; + + /** この例外コードは使用されない */ + public static final int COB_EC_ALL = 1; + + /** TODO: 準備中 */ + public static final int COB_EC_ARGUMENT = 2; + + /** TODO: 準備中 */ + public static final int COB_EC_ARGUMENT_FUNCTION = 3; + + /** この例外コードは使用されない */ + public static final int COB_EC_ARGUMENT_IMP = 4; + + /** この例外コードは使用されない */ + public static final int COB_EC_BOUND = 5; + + /** この例外コードは使用されない */ + public static final int COB_EC_BOUND_IMP = 6; + + /** この例外コードは使用されない */ + public static final int COB_EC_BOUND_ODO = 7; + + /** この例外コードは使用されない */ + public static final int COB_EC_BOUND_OVERFLOW = 8; + + /** TODO: 準備中 */ + public static final int COB_EC_BOUND_PTR = 9; + + /** TODO: 準備中 */ + public static final int COB_EC_BOUND_REF_MOD = 10; + + /** この例外コードは使用されない */ + public static final int COB_EC_BOUND_SET = 11; + + /** TODO: 準備中 */ + public static final int COB_EC_BOUND_SUBSCRIPT = 12; + + /** この例外コードは使用されない */ + public static final int COB_EC_BOUND_TABLE_LIMIT = 13; + + /** この例外コードは使用されない */ + public static final int COB_EC_DATA = 14; + + /** この例外コードは使用されない */ + public static final int COB_EC_DATA_CONVERSION = 15; + + /** この例外コードは使用されない */ + public static final int COB_EC_DATA_IMP = 16; + + /** この例外コードは使用されない */ + public static final int COB_EC_DATA_INCOMPATIBLE = 17; + + /** この例外コードは使用されない */ + public static final int COB_EC_DATA_INTEGRITY = 18; + + /** この例外コードは使用されない */ + public static final int COB_EC_DATA_PTR_NULL = 19; + + /** この例外コードは使用されない */ + public static final int COB_EC_DATA_INFINITY = 20; + + /** この例外コードは使用されない */ + public static final int COB_EC_DATA_NEGATIVE_INFINITY = 21; + + /** この例外コードは使用されない */ + public static final int COB_EC_DATA_NOT_A_NUMBER = 22; + + /** この例外コードは使用されない */ + public static final int COB_EC_FLOW = 23; + + /** この例外コードは使用されない */ + public static final int COB_EC_FLOW_GLOBAL_EXIT = 24; + + /** この例外コードは使用されない */ + public static final int COB_EC_FLOW_GLOBAL_GOBACK = 25; + + /** この例外コードは使用されない */ + public static final int COB_EC_FLOW_IMP = 26; + + /** この例外コードは使用されない */ + public static final int COB_EC_FLOW_RELEASE = 27; + + /** この例外コードは使用されない */ + public static final int COB_EC_FLOW_REPORT = 28; + + /** この例外コードは使用されない */ + public static final int COB_EC_FLOW_RETURN = 29; + + /** この例外コードは使用されない */ + public static final int COB_EC_FLOW_SEARCH = 30; + + /** この例外コードは使用されない */ + public static final int COB_EC_FLOW_USE = 31; + + /** TODO: 準備中 */ + public static final int COB_EC_I_O = 32; + + /** TODO: 準備中 */ + public static final int COB_EC_I_O_AT_END = 33; + + /** TODO: 準備中 */ + public static final int COB_EC_I_O_EOP = 34; + + /** TODO: 準備中 */ + public static final int COB_EC_I_O_EOP_OVERFLOW = 35; + + /** TODO: 準備中 */ + public static final int COB_EC_I_O_FILE_SHARING = 36; + + /** TODO: 準備中 */ + public static final int COB_EC_I_O_IMP = 37; + + /** TODO: 準備中 */ + public static final int COB_EC_I_O_INVALID_KEY = 38; + + /** TODO: 準備中 */ + public static final int COB_EC_I_O_LINAGE = 39; + + /** TODO: 準備中 */ + public static final int COB_EC_I_O_LOGIC_ERROR = 40; + + /** TODO: 準備中 */ + public static final int COB_EC_I_O_PERMANENT_ERROR = 41; + + /** TODO: 準備中 */ + public static final int COB_EC_I_O_RECORD_OPERATION = 42; + + /** TODO: 準備中 */ + public static final int COB_EC_IMP = 43; + + /** TODO: 準備中 */ + public static final int COB_EC_IMP_ACCEPT = 44; + + /** TODO: 準備中 */ + public static final int COB_EC_IMP_DISPLAY = 45; + + /** この例外コードは使用されない */ + public static final int COB_EC_LOCALE = 46; + + /** この例外コードは使用されない */ + public static final int COB_EC_LOCALE_IMP = 47; + + /** この例外コードは使用されない */ + public static final int COB_EC_LOCALE_INCOMPATIBLE = 48; + + /** この例外コードは使用されない */ + public static final int COB_EC_LOCALE_INVALID = 49; + + /** この例外コードは使用されない */ + public static final int COB_EC_LOCALE_INVALID_PTR = 50; + + /** この例外コードは使用されない */ + public static final int COB_EC_LOCALE_MISSING = 51; + + /** この例外コードは使用されない */ + public static final int COB_EC_LOCALE_SIZE = 52; + + /** この例外コードは使用されない */ + public static final int COB_EC_OO = 53; + + /** この例外コードは使用されない */ + public static final int COB_EC_OO_CONFORMANCE = 54; + + /** この例外コードは使用されない */ + public static final int COB_EC_OO_EXCEPTION = 55; + + /** この例外コードは使用されない */ + public static final int COB_EC_OO_IMP = 56; + + /** この例外コードは使用されない */ + public static final int COB_EC_OO_METHOD = 57; + + /** この例外コードは使用されない */ + public static final int COB_EC_OO_NULL = 58; + + /** この例外コードは使用されない */ + public static final int COB_EC_OO_RESOURCE = 59; + + /** この例外コードは使用されない */ + public static final int COB_EC_OO_UNIVERSAL = 60; + + /** この例外コードは使用されない */ + public static final int COB_EC_ORDER = 61; + + /** この例外コードは使用されない */ + public static final int COB_EC_ORDER_IMP = 62; + + /** この例外コードは使用されない */ + public static final int COB_EC_ORDER_NOT_SUPPORTED = 63; + + /** TODO: 準備中 */ + public static final int COB_EC_OVERFLOW = 64; + + /** TODO: 準備中 */ + public static final int COB_EC_OVERFLOW_IMP = 65; + + /** TODO: 準備中 */ + public static final int COB_EC_OVERFLOW_STRING = 66; + + /** TODO: 準備中 */ + public static final int COB_EC_OVERFLOW_UNSTRING = 67; + + /** この例外コードは使用されない */ + public static final int COB_EC_PROGRAM = 68; + + /** この例外コードは使用されない */ + public static final int COB_EC_PROGRAM_ARG_MISMATCH = 69; + + /** この例外コードは使用されない */ + public static final int COB_EC_PROGRAM_ARG_OMITTED = 70; + + /** この例外コードは使用されない */ + public static final int COB_EC_PROGRAM_CANCEL_ACTIVE = 71; + + /** この例外コードは使用されない */ + public static final int COB_EC_PROGRAM_IMP = 72; + + /** TODO: 準備中 */ + public static final int COB_EC_PROGRAM_NOT_FOUND = 73; + + /** この例外コードは使用されない */ + public static final int COB_EC_PROGRAM_PTR_NULL = 74; + + /** この例外コードは使用されない */ + public static final int COB_EC_PROGRAM_RECURSIVE_CALL = 75; + + /** この例外コードは使用されない */ + public static final int COB_EC_PROGRAM_RESOURCES = 76; + + /** この例外コードは使用されない */ + public static final int COB_EC_RAISING = 77; + + /** この例外コードは使用されない */ + public static final int COB_EC_RAISING_IMP = 78; + + /** この例外コードは使用されない */ + public static final int COB_EC_RAISING_NOT_SPECIFIED = 79; + + /** この例外コードは使用されない */ + public static final int COB_EC_RANGE = 80; + + /** この例外コードは使用されない */ + public static final int COB_EC_RANGE_IMP = 81; + + /** この例外コードは使用されない */ + public static final int COB_EC_RANGE_INDEX = 82; + + /** TODO: 準備中 */ + public static final int COB_EC_RANGE_INSPECT_SIZE = 83; + + /** この例外コードは使用されない */ + public static final int COB_EC_RANGE_INVALID = 84; + + /** この例外コードは使用されない */ + public static final int COB_EC_RANGE_PERFORM_VARYING = 85; + + /** この例外コードは使用されない */ + public static final int COB_EC_RANGE_PTR = 86; + + /** この例外コードは使用されない */ + public static final int COB_EC_RANGE_SEARCH_INDEX = 87; + + /** この例外コードは使用されない */ + public static final int COB_EC_RANGE_SEARCH_NO_MATCH = 88; + + /** この例外コードは使用されない */ + public static final int COB_EC_REPORT = 89; + + /** この例外コードは使用されない */ + public static final int COB_EC_REPORT_ACTIVE = 90; + + /** この例外コードは使用されない */ + public static final int COB_EC_REPORT_COLUMN_OVERLAP = 91; + + /** この例外コードは使用されない */ + public static final int COB_EC_REPORT_FILE_MODE = 92; + + /** この例外コードは使用されない */ + public static final int COB_EC_REPORT_IMP = 93; + + /** この例外コードは使用されない */ + public static final int COB_EC_REPORT_INACTIVE = 94; + + /** この例外コードは使用されない */ + public static final int COB_EC_REPORT_LINE_OVERLAP = 95; + + /** この例外コードは使用されない */ + public static final int COB_EC_REPORT_NOT_TERMINATED = 96; + + /** この例外コードは使用されない */ + public static final int COB_EC_REPORT_PAGE_LIMIT = 97; + + /** この例外コードは使用されない */ + public static final int COB_EC_REPORT_PAGE_WIDTH = 98; + + /** この例外コードは使用されない */ + public static final int COB_EC_REPORT_SUM_SIZE = 99; + + /** この例外コードは使用されない */ + public static final int COB_EC_REPORT_VARYING = 100; + + /** この例外コードは使用されない */ + public static final int COB_EC_SCREEN = 101; + + /** この例外コードは使用されない */ + public static final int COB_EC_SCREEN_FIELD_OVERLAP = 102; + + /** この例外コードは使用されない */ + public static final int COB_EC_SCREEN_IMP = 103; + + /** この例外コードは使用されない */ + public static final int COB_EC_SCREEN_ITEM_TRUNCATED = 104; + + /** この例外コードは使用されない */ + public static final int COB_EC_SCREEN_LINE_NUMBER = 105; + + /** この例外コードは使用されない */ + public static final int COB_EC_SCREEN_STARTING_COLUMN = 106; + + /** この例外コードは使用されない */ + public static final int COB_EC_SIZE = 107; + + /** この例外コードは使用されない */ + public static final int COB_EC_SIZE_ADDRESS = 108; + + /** この例外コードは使用されない */ + public static final int COB_EC_SIZE_EXPONENTIATION = 109; + + /** この例外コードは使用されない */ + public static final int COB_EC_SIZE_IMP = 110; + + /** TODO: 準備中 */ + public static final int COB_EC_SIZE_OVERFLOW = 111; + + /** この例外コードは使用されない */ + public static final int COB_EC_SIZE_TRUNCATION = 112; + + /** この例外コードは使用されない */ + public static final int COB_EC_SIZE_UNDERFLOW = 113; + + /** この例外コードは使用されない */ + public static final int COB_EC_SIZE_ZERO_DIVIDE = 114; + + /** この例外コードは使用されない */ + public static final int COB_EC_SORT_MERGE = 115; + + /** この例外コードは使用されない */ + public static final int COB_EC_SORT_MERGE_ACTIVE = 116; + + /** この例外コードは使用されない */ + public static final int COB_EC_SORT_MERGE_FILE_OPEN = 117; + + /** この例外コードは使用されない */ + public static final int COB_EC_SORT_MERGE_IMP = 118; + + /** この例外コードは使用されない */ + public static final int COB_EC_SORT_MERGE_RELEASE = 119; + + /** この例外コードは使用されない */ + public static final int COB_EC_SORT_MERGE_RETURN = 120; + + /** この例外コードは使用されない */ + public static final int COB_EC_SORT_MERGE_SEQUENCE = 121; + + /** この例外コードは使用されない */ + public static final int COB_EC_STORAGE = 122; + + /** この例外コードは使用されない */ + public static final int COB_EC_STORAGE_IMP = 123; + + /** この例外コードは使用されない */ + public static final int COB_EC_STORAGE_NOT_ALLOC = 124; + + /** この例外コードは使用されない */ + public static final int COB_EC_STORAGE_NOT_AVAIL = 125; + + /** この例外コードは使用されない */ + public static final int COB_EC_USER = 126; + + /** この例外コードは使用されない */ + public static final int COB_EC_VALIDATE = 127; + + /** この例外コードは使用されない */ + public static final int COB_EC_VALIDATE_CONTENT = 128; + + /** この例外コードは使用されない */ + public static final int COB_EC_VALIDATE_FORMAT = 129; + + /** この例外コードは使用されない */ + public static final int COB_EC_VALIDATE_IMP = 130; + + /** この例外コードは使用されない */ + public static final int COB_EC_VALIDATE_RELATION = 131; + + /** この例外コードは使用されない */ + public static final int COB_EC_VALIDATE_VARYING = 132; + + /** この例外コードは使用されない */ + public static final int COB_EC_FUNCTION = 133; + + /** この例外コードは使用されない */ + public static final int COB_EC_FUNCTION_NOT_FOUND = 134; + + /** この例外コードは使用されない */ + public static final int COB_EC_FUNCTION_PTR_INVALID = 135; + + /** この例外コードは使用されない */ + public static final int COB_EC_FUNCTION_PTR_NULL = 136; + + /** この例外コードは使用されない */ + public static final int COB_EC_XML = 137; + + /** この例外コードは使用されない */ + public static final int COB_EC_XML_CODESET = 138; + + /** この例外コードは使用されない */ + public static final int COB_EC_XML_CODESET_CONVERSION = 139; + + /** この例外コードは使用されない */ + public static final int COB_EC_XML_COUNT = 140; + + /** この例外コードは使用されない */ + public static final int COB_EC_XML_DOCUMENT_TYPE = 141; + + /** この例外コードは使用されない */ + public static final int COB_EC_XML_IMPLICIT_CLOSE = 142; + + /** この例外コードは使用されない */ + public static final int COB_EC_XML_INVALID = 143; + + /** この例外コードは使用されない */ + public static final int COB_EC_XML_NAMESPACE = 144; + + /** この例外コードは使用されない */ + public static final int COB_EC_XML_STACKED_OPEN = 145; + + /** この例外コードは使用されない */ + public static final int COB_EC_XML_RANGE = 146; + + /** この例外コードは使用されない */ + public static final int COB_EC_MAX = 147; +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/exceptions/CobolExceptionInfo.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/exceptions/CobolExceptionInfo.java index 032a4c01..ac4262c7 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/exceptions/CobolExceptionInfo.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/exceptions/CobolExceptionInfo.java @@ -1,34 +1,34 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.exceptions; - -/** エラーコードを保持する。 */ -public class CobolExceptionInfo { - /** エラーコード。TODO: 準備中 */ - public static int code = 0; - - /** - * エラーコードを設定する。TODO: 準備中 - * - * @param id TODO: 準備中 - */ - public static void setException(int id) { - CobolExceptionInfo.code = CobolExceptionTabCode.code[id]; - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.exceptions; + +/** エラーコードを保持する。 */ +public class CobolExceptionInfo { + /** エラーコード。TODO: 準備中 */ + public static int code = 0; + + /** + * エラーコードを設定する。TODO: 準備中 + * + * @param id TODO: 準備中 + */ + public static void setException(int id) { + CobolExceptionInfo.code = CobolExceptionTabCode.code[id]; + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/exceptions/CobolExceptionTabCode.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/exceptions/CobolExceptionTabCode.java index 7080124e..d3556de8 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/exceptions/CobolExceptionTabCode.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/exceptions/CobolExceptionTabCode.java @@ -1,38 +1,49 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.exceptions; - -/** エラーコード関連の計算に用いる */ -public class CobolExceptionTabCode { - static int[] code = { - 0, 0xFFFF, 0x0100, 0x0101, 0x0102, 0x0200, 0x0201, 0x0202, 0x0203, 0x0204, 0x0205, 0x0206, - 0x0207, 0x0208, 0x0300, 0x0301, 0x0302, 0x0303, 0x0304, 0x0305, 0x0306, 0x0307, 0x0308, 0x0400, - 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407, 0x0408, 0x0500, 0x0501, 0x0502, 0x0503, - 0x0504, 0x0505, 0x0506, 0x0507, 0x0508, 0x0509, 0x050A, 0x0600, 0x0601, 0x0602, 0x0700, 0x0701, - 0x0702, 0x0703, 0x0704, 0x0705, 0x0706, 0x0800, 0x0801, 0x0802, 0x0803, 0x0804, 0x0805, 0x0806, - 0x0807, 0x0900, 0x0901, 0x0902, 0x0A00, 0x0A01, 0x0A02, 0x0A03, 0x0B00, 0x0B01, 0x0B02, 0x0B03, - 0x0B04, 0x0B05, 0x0B06, 0x0B07, 0x0B08, 0x0C00, 0x0C01, 0x0C02, 0x0D00, 0x0D01, 0x0D02, 0x0D03, - 0x0D04, 0x0D05, 0x0D06, 0x0D07, 0x0D08, 0x0E00, 0x0E01, 0x0E02, 0x0E03, 0x0E04, 0x0E05, 0x0E06, - 0x0E08, 0x0E09, 0x0E0A, 0x0E0B, 0x0E0C, 0x0F00, 0x0F01, 0x0F02, 0x0F03, 0x0F04, 0x0F05, 0x1000, - 0x1001, 0x1002, 0x1003, 0x1004, 0x1005, 0x1006, 0x1007, 0x1100, 0x1101, 0x1102, 0x1103, 0x1104, - 0x1105, 0x1106, 0x1200, 0x1201, 0x1202, 0x1203, 0x1300, 0x1400, 0x1401, 0x1402, 0x1403, 0x1404, - 0x1405, 0x1500, 0x1501, 0x1502, 0x1503, 0x1600, 0x1601, 0x1602, 0x1603, 0x1604, 0x1605, 0x1606, - 0x1607, 0x1608, 0x1609, 0 - }; -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.exceptions; + +/** エラーコード関連の計算に用いる */ +public class CobolExceptionTabCode { + static int[] code = { + 0, 0xFFFF, 0x0100, 0x0101, 0x0102, 0x0200, 0x0201, 0x0202, 0x0203, 0x0204, 0x0205, 0x0206, + 0x0207, 0x0208, 0x0300, 0x0301, 0x0302, 0x0303, 0x0304, 0x0305, 0x0306, 0x0307, 0x0308, + 0x0400, + 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407, 0x0408, 0x0500, 0x0501, 0x0502, + 0x0503, + 0x0504, 0x0505, 0x0506, 0x0507, 0x0508, 0x0509, 0x050A, 0x0600, 0x0601, 0x0602, 0x0700, + 0x0701, + 0x0702, 0x0703, 0x0704, 0x0705, 0x0706, 0x0800, 0x0801, 0x0802, 0x0803, 0x0804, 0x0805, + 0x0806, + 0x0807, 0x0900, 0x0901, 0x0902, 0x0A00, 0x0A01, 0x0A02, 0x0A03, 0x0B00, 0x0B01, 0x0B02, + 0x0B03, + 0x0B04, 0x0B05, 0x0B06, 0x0B07, 0x0B08, 0x0C00, 0x0C01, 0x0C02, 0x0D00, 0x0D01, 0x0D02, + 0x0D03, + 0x0D04, 0x0D05, 0x0D06, 0x0D07, 0x0D08, 0x0E00, 0x0E01, 0x0E02, 0x0E03, 0x0E04, 0x0E05, + 0x0E06, + 0x0E08, 0x0E09, 0x0E0A, 0x0E0B, 0x0E0C, 0x0F00, 0x0F01, 0x0F02, 0x0F03, 0x0F04, 0x0F05, + 0x1000, + 0x1001, 0x1002, 0x1003, 0x1004, 0x1005, 0x1006, 0x1007, 0x1100, 0x1101, 0x1102, 0x1103, + 0x1104, + 0x1105, 0x1106, 0x1200, 0x1201, 0x1202, 0x1203, 0x1300, 0x1400, 0x1401, 0x1402, 0x1403, + 0x1404, + 0x1405, 0x1500, 0x1501, 0x1502, 0x1503, 0x1600, 0x1601, 0x1602, 0x1603, 0x1604, 0x1605, + 0x1606, + 0x1607, 0x1608, 0x1609, 0 + }; +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/exceptions/CobolGoBackException.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/exceptions/CobolGoBackException.java index 34175070..7dbe82a7 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/exceptions/CobolGoBackException.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/exceptions/CobolGoBackException.java @@ -23,65 +23,65 @@ /** GOBACKの呼び出し時にスローされる例外。返り値を保持する */ public final class CobolGoBackException extends Exception { - /** 返り値 */ - private int returnCode; + /** 返り値 */ + private int returnCode; - /** - * コンストラクタ - * - * @param returnCode 返り値 - */ - private CobolGoBackException(int returnCode) { - this.returnCode = returnCode; - } + /** + * コンストラクタ + * + * @param returnCode 返り値 + */ + private CobolGoBackException(int returnCode) { + this.returnCode = returnCode; + } - /** - * コンストラクタ - * - * @param returnCode 返り値 - */ - private CobolGoBackException(CobolDataStorage storage) { - this(storage.intValue()); - } + /** + * コンストラクタ + * + * @param returnCode 返り値 + */ + private CobolGoBackException(CobolDataStorage storage) { + this(storage.intValue()); + } - /** - * このクラスが保持するGOBACKの返り値を取得する。 - * - * @return このクラスが保持するGOBACKの返り値 - */ - public int getReturnCode() { - return returnCode; - } + /** + * このクラスが保持するGOBACKの返り値を取得する。 + * + * @return このクラスが保持するGOBACKの返り値 + */ + public int getReturnCode() { + return returnCode; + } - /** - * CobolGoBackExceptionを例外として投げる。 - * - * @param returnCode GOBACKの返り値 - * @throws CobolGoBackException TODO: 準備中 - */ - public static void throwException(int returnCode) throws CobolGoBackException { - throw new CobolGoBackException(returnCode); - } + /** + * CobolGoBackExceptionを例外として投げる。 + * + * @param returnCode GOBACKの返り値 + * @throws CobolGoBackException TODO: 準備中 + */ + public static void throwException(int returnCode) throws CobolGoBackException { + throw new CobolGoBackException(returnCode); + } - /** - * CobolGoBackExceptionを例外として投げる。 - * - * @param storage GOBACKの返り値 - * @throws CobolGoBackException TODO: 準備中 - */ - public static void throwException(CobolDataStorage storage) throws CobolGoBackException { - throw new CobolGoBackException(storage); - } + /** + * CobolGoBackExceptionを例外として投げる。 + * + * @param storage GOBACKの返り値 + * @throws CobolGoBackException TODO: 準備中 + */ + public static void throwException(CobolDataStorage storage) throws CobolGoBackException { + throw new CobolGoBackException(storage); + } - /** - * javaコンパイラは、try節の中にthrowが発生しないと判断するとコンパイルエラーになる。 Javaコード生成時にこの問題を回避するため、このメソッドが挿入される。 throws - * CobolGoBackExceptionが指定されているが、このメソッドは決して例外をスローせず、その他の処理も実行しない。 - * - * @throws CobolGoBackException TODO: 準備中 - */ - public static void dummy() throws CobolGoBackException { - if (false) { - throw new CobolGoBackException(0); + /** + * javaコンパイラは、try節の中にthrowが発生しないと判断するとコンパイルエラーになる。 Javaコード生成時にこの問題を回避するため、このメソッドが挿入される。 throws + * CobolGoBackExceptionが指定されているが、このメソッドは決して例外をスローせず、その他の処理も実行しない。 + * + * @throws CobolGoBackException TODO: 準備中 + */ + public static void dummy() throws CobolGoBackException { + if (false) { + throw new CobolGoBackException(0); + } } - } } diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/exceptions/CobolRuntimeException.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/exceptions/CobolRuntimeException.java index e0984800..976f8adf 100755 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/exceptions/CobolRuntimeException.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/exceptions/CobolRuntimeException.java @@ -1,159 +1,159 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.exceptions; - -import jp.osscons.opensourcecobol.libcobj.call.CobolResolve; -import jp.osscons.opensourcecobol.libcobj.common.CobolUtil; - -/** 実行時エラーを示す例外。エラー番号とエラーメッセージを保持する */ -public class CobolRuntimeException extends RuntimeException { - /** TODO: 準備中 */ - public static int code; - - private static int cobException = 0; - private static String origProgramId; - private static String origSection; - private static String origParagraph; - private static int origLine = 0; - private static String origStatement; - - /** 重大なエラーを示すエラーコード */ - public static final int COBOL_FATAL_ERROR = 9000; - - /** エラー番号 */ - private int errorCode; - - /** エラーメッセージ */ - private String message; - - /** - * コンストラクタ - * - * @param errorCode エラーコード - * @param message エラーメッセージ - */ - public CobolRuntimeException(int errorCode, String message) { - super(); - this.errorCode = errorCode; - this.message = message; - } - - /** エラーメッセージの文字列表現を返す */ - @Override - public String getMessage() { - // TODO エラーメッセージの設計 - return errorCode + " : " + message; - } - - /** superのprintStackTraceの拡張 */ - @Override - public void printStackTrace() { - System.out.println(errorCode + " : " + message); - super.printStackTrace(); - } - - /** - * 実行時例外を設定する。 エラーIDをベースに、CobolExceptioTabCode.codeテーブルを参照して、対応するエラーコードが設定される。 - * また、エラー発生時のプログラムID、セクション名、パラグラフ名、行番号、ステートメントを取得し、このクラスの静的変数に保持する。 - * - * @param id エラーID - */ - public static void setException(int id) { - code = CobolExceptionTabCode.code[id]; - cobException = 1; - origLine = CobolUtil.getSourceLine(); - origProgramId = CobolUtil.getCurrProgramId(); - origSection = CobolUtil.getCurrSection(); - origParagraph = CobolUtil.getCurrParagraph(); - origStatement = CobolUtil.getSourceStatement(); - } - - /** - * エラーコード名を取得する - * - * @param exceptionCode エラーコード - * @return エラーコードに対応するエラーコード名 - */ - public static String getExceptionName(int exceptionCode) { - return CobolResolve.cobException.get(exceptionCode); - } - - /** - * エラーコードを取得する - * - * @return エラーコード - */ - public static int getExceptionCode() { - return code; - } - - /** - * 常に0を返す。TODO: 必要に応じてこのメソッドは削除ないし修正する。 - * - * @return 0 - */ - public static int getException() { - return cobException; - } - - /** - * エラー発生時のプログラムIDを取得する - * - * @return エラー発生時のプログラムID - */ - public static String getOrigProgramId() { - return origProgramId; - } - - /** - * エラー発生時のセクション名を取得する - * - * @return エラー発生時のセクション名 - */ - public static String getOrigSection() { - return origSection; - } - - /** - * エラー発生時のパラグラフ名を取得する - * - * @return エラー発生時のパラグラフ名 - */ - public static String getOrigParagragh() { - return origParagraph; - } - - /** - * エラー発生時の行番号を取得する - * - * @return エラー発生時の行番号 - */ - public static int getOrigLine() { - return origLine; - } - - /** - * エラー発生時のステートメントを取得する - * - * @return エラー発生時のステートメント - */ - public static String getOrigStatement() { - return origStatement; - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.exceptions; + +import jp.osscons.opensourcecobol.libcobj.call.CobolResolve; +import jp.osscons.opensourcecobol.libcobj.common.CobolUtil; + +/** 実行時エラーを示す例外。エラー番号とエラーメッセージを保持する */ +public class CobolRuntimeException extends RuntimeException { + /** TODO: 準備中 */ + public static int code; + + private static int cobException = 0; + private static String origProgramId; + private static String origSection; + private static String origParagraph; + private static int origLine = 0; + private static String origStatement; + + /** 重大なエラーを示すエラーコード */ + public static final int COBOL_FATAL_ERROR = 9000; + + /** エラー番号 */ + private int errorCode; + + /** エラーメッセージ */ + private String message; + + /** + * コンストラクタ + * + * @param errorCode エラーコード + * @param message エラーメッセージ + */ + public CobolRuntimeException(int errorCode, String message) { + super(); + this.errorCode = errorCode; + this.message = message; + } + + /** エラーメッセージの文字列表現を返す */ + @Override + public String getMessage() { + // TODO エラーメッセージの設計 + return errorCode + " : " + message; + } + + /** superのprintStackTraceの拡張 */ + @Override + public void printStackTrace() { + System.out.println(errorCode + " : " + message); + super.printStackTrace(); + } + + /** + * 実行時例外を設定する。 エラーIDをベースに、CobolExceptioTabCode.codeテーブルを参照して、対応するエラーコードが設定される。 + * また、エラー発生時のプログラムID、セクション名、パラグラフ名、行番号、ステートメントを取得し、このクラスの静的変数に保持する。 + * + * @param id エラーID + */ + public static void setException(int id) { + code = CobolExceptionTabCode.code[id]; + cobException = 1; + origLine = CobolUtil.getSourceLine(); + origProgramId = CobolUtil.getCurrProgramId(); + origSection = CobolUtil.getCurrSection(); + origParagraph = CobolUtil.getCurrParagraph(); + origStatement = CobolUtil.getSourceStatement(); + } + + /** + * エラーコード名を取得する + * + * @param exceptionCode エラーコード + * @return エラーコードに対応するエラーコード名 + */ + public static String getExceptionName(int exceptionCode) { + return CobolResolve.cobException.get(exceptionCode); + } + + /** + * エラーコードを取得する + * + * @return エラーコード + */ + public static int getExceptionCode() { + return code; + } + + /** + * 常に0を返す。TODO: 必要に応じてこのメソッドは削除ないし修正する。 + * + * @return 0 + */ + public static int getException() { + return cobException; + } + + /** + * エラー発生時のプログラムIDを取得する + * + * @return エラー発生時のプログラムID + */ + public static String getOrigProgramId() { + return origProgramId; + } + + /** + * エラー発生時のセクション名を取得する + * + * @return エラー発生時のセクション名 + */ + public static String getOrigSection() { + return origSection; + } + + /** + * エラー発生時のパラグラフ名を取得する + * + * @return エラー発生時のパラグラフ名 + */ + public static String getOrigParagragh() { + return origParagraph; + } + + /** + * エラー発生時の行番号を取得する + * + * @return エラー発生時の行番号 + */ + public static int getOrigLine() { + return origLine; + } + + /** + * エラー発生時のステートメントを取得する + * + * @return エラー発生時のステートメント + */ + public static String getOrigStatement() { + return origStatement; + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/exceptions/CobolStopRunException.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/exceptions/CobolStopRunException.java index 7dcaf734..3ead872b 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/exceptions/CobolStopRunException.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/exceptions/CobolStopRunException.java @@ -24,84 +24,84 @@ /** STOP RUNの呼び出し時にスローされる例外。返り値を保持する。 */ public final class CobolStopRunException extends Exception { - /** 返り値 */ - private int returnCode; + /** 返り値 */ + private int returnCode; - /** - * コンストラクタ - * - * @param returnCode 返り値 - */ - private CobolStopRunException(int returnCode) { - this.returnCode = returnCode; - } + /** + * コンストラクタ + * + * @param returnCode 返り値 + */ + private CobolStopRunException(int returnCode) { + this.returnCode = returnCode; + } - /** - * コンストラクタ - * - * @param storage 返り値を格納したCobolDataStorageのインスタンス - */ - private CobolStopRunException(CobolDataStorage storage) { - this(storage.intValue()); - } + /** + * コンストラクタ + * + * @param storage 返り値を格納したCobolDataStorageのインスタンス + */ + private CobolStopRunException(CobolDataStorage storage) { + this(storage.intValue()); + } - /** - * このクラスが保持するSTOP RUNの返り値を取得する。 - * - * @return このクラスが保持するSTOP RUNの返り値 - */ - public int getReturnCode() { - return returnCode; - } + /** + * このクラスが保持するSTOP RUNの返り値を取得する。 + * + * @return このクラスが保持するSTOP RUNの返り値 + */ + public int getReturnCode() { + return returnCode; + } - /** - * CobolStopRunExceptionを例外としてスローする。 COBOLプログラム終了時のデフォルトの終了処理は実行されない。 - * - * @param returnCode STOP RUNの返り値 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void throwException(int returnCode) throws CobolStopRunException { - throw new CobolStopRunException(returnCode); - } + /** + * CobolStopRunExceptionを例外としてスローする。 COBOLプログラム終了時のデフォルトの終了処理は実行されない。 + * + * @param returnCode STOP RUNの返り値 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void throwException(int returnCode) throws CobolStopRunException { + throw new CobolStopRunException(returnCode); + } - /** - * CobolStopRunExceptionを例外としてスローする。 COBOLプログラム終了時のデフォルトの終了処理は実行されない。 - * - * @param storage STOP RUNの返り値 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void throwException(CobolDataStorage storage) throws CobolStopRunException { - throw new CobolStopRunException(storage); - } + /** + * CobolStopRunExceptionを例外としてスローする。 COBOLプログラム終了時のデフォルトの終了処理は実行されない。 + * + * @param storage STOP RUNの返り値 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void throwException(CobolDataStorage storage) throws CobolStopRunException { + throw new CobolStopRunException(storage); + } - /** - * javaコンパイラは、try節の中にthrowが発生しないと判断するとコンパイルエラーになる。 Javaコード生成時にこの問題を回避するため、このメソッドが挿入される。 throws - * CobolRunExceptionが指定されているが、このメソッドは決して例外をスローせず、その他の処理も実行しない。 - * - * @throws CobolStopRunException TODO: 準備中 - */ - public static void dummy() throws CobolStopRunException { - if (false) { - throw new CobolStopRunException(0); + /** + * javaコンパイラは、try節の中にthrowが発生しないと判断するとコンパイルエラーになる。 Javaコード生成時にこの問題を回避するため、このメソッドが挿入される。 throws + * CobolRunExceptionが指定されているが、このメソッドは決して例外をスローせず、その他の処理も実行しない。 + * + * @throws CobolStopRunException TODO: 準備中 + */ + public static void dummy() throws CobolStopRunException { + if (false) { + throw new CobolStopRunException(0); + } } - } - /** - * デフォルトの終了処理を実行してから、CobolStopRunExceptionをスローする。 - * デフォルトの終了処理では、COBOLプログラムによってオープンされたファイルのクローズが行われる。 - * - * @param status STOP RUNの返り値 - * @throws CobolStopRunException このメソッドでは必ずCobolStopRunExceptionがスローされる。 - */ - public static void stopRunAndThrow(int status) throws CobolStopRunException { - stopRun(); - CobolStopRunException.throwException(status); - } + /** + * デフォルトの終了処理を実行してから、CobolStopRunExceptionをスローする。 + * デフォルトの終了処理では、COBOLプログラムによってオープンされたファイルのクローズが行われる。 + * + * @param status STOP RUNの返り値 + * @throws CobolStopRunException このメソッドでは必ずCobolStopRunExceptionがスローされる。 + */ + public static void stopRunAndThrow(int status) throws CobolStopRunException { + stopRun(); + CobolStopRunException.throwException(status); + } - /** デフォルトの終了処理を実行する。CobolStopRunExceptionをスローしない。 */ - public static void stopRun() { - // TODO screen実装時に追加 - // cob_screen_terminate(); - CobolFile.exitFileIO(); - } + /** デフォルトの終了処理を実行する。CobolStopRunExceptionをスローしない。 */ + public static void stopRun() { + // TODO screen実装時に追加 + // cob_screen_terminate(); + CobolFile.exitFileIO(); + } } diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java index 73ed2290..f3747fcf 100755 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java @@ -1,1985 +1,2188 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.file; - -import java.io.IOException; -import java.nio.channels.ClosedChannelException; -import java.nio.channels.FileChannel; -import java.nio.channels.FileLock; -import java.nio.channels.NonWritableChannelException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardOpenOption; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import jp.osscons.opensourcecobol.libcobj.common.CobolModule; -import jp.osscons.opensourcecobol.libcobj.common.CobolUtil; -import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; -import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionId; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; - -/** INDEXED, RELATIVE, SEQUENTIAL, LINE SEQUENTIAL等のCOBOLの ファイルを実装するための基底クラス */ -public class CobolFile { - /** TODO: 準備中 */ - protected static final int COB_ORG_SEQUENTIAL = 0; - /** TODO: 準備中 */ - protected static final int COB_ORG_LINE_SEQUENTIAL = 1; - /** TODO: 準備中 */ - protected static final int COB_ORG_RELATIVE = 2; - /** TODO: 準備中 */ - protected static final int COB_ORG_INDEXED = 3; - /** TODO: 準備中 */ - protected static final int COB_ORG_SORT = 4; - /** TODO: 準備中 */ - protected static final int COB_ORG_MAX = 5; - - /** TODO: 準備中 */ - protected static final int COB_ACCESS_SEQUENTIAL = 1; - /** TODO: 準備中 */ - protected static final int COB_ACCESS_DYNAMIC = 2; - /** TODO: 準備中 */ - protected static final int COB_ACCESS_RANDOM = 3; - - /** TODO: 準備中 */ - protected static final int COB_IO_OPEN = 0; - /** TODO: 準備中 */ - protected static final int COB_IO_READ = 1; - /** TODO: 準備中 */ - protected static final int COB_IO_WRITE = 2; - /** TODO: 準備中 */ - protected static final int COB_IO_CLOSE = 3; - /** TODO: 準備中 */ - protected static final int COB_IO_DELETE = 4; - /** TODO: 準備中 */ - protected static final int COB_IO_REWRITE = 5; - /** TODO: 準備中 */ - protected static final int COB_IO_START = 6; - /** TODO: 準備中 */ - protected static final int COB_IO_COMMIT = 7; - /** TODO: 準備中 */ - protected static final int COB_IO_ROLLBACK = 8; - /** TODO: 準備中 */ - protected static final int COB_IO_UNLOCK = 9; - /** TODO: 準備中 */ - protected static final int COB_IO_DELETE_FILE = 10; - - /** TODO: 準備中 */ - public static final int COB_OPEN_CLOSED = 0; - /** TODO: 準備中 */ - public static final int COB_OPEN_INPUT = 1; - /** TODO: 準備中 */ - public static final int COB_OPEN_OUTPUT = 2; - /** TODO: 準備中 */ - public static final int COB_OPEN_I_O = 3; - /** TODO: 準備中 */ - public static final int COB_OPEN_EXTEND = 4; - /** TODO: 準備中 */ - public static final int COB_OPEN_LOCKED = 5; - - /** TODO: 準備中 */ - public static final int COB_CLOSE_NORMAL = 0; - /** TODO: 準備中 */ - public static final int COB_CLOSE_LOCK = 1; - /** TODO: 準備中 */ - public static final int COB_CLOSE_NO_REWIND = 2; - /** TODO: 準備中 */ - public static final int COB_CLOSE_UNIT = 3; - /** TODO: 準備中 */ - public static final int COB_CLOSE_UNIT_REMOVAL = 4; - - /** TODO: 準備中 */ - public static final int COB_WRITE_MASK = 0x0000ffff; - /** TODO: 準備中 */ - public static final int COB_WRITE_LINES = 0x00010000; - /** TODO: 準備中 */ - public static final int COB_WRITE_PAGE = 0x00020000; - /** TODO: 準備中 */ - public static final int COB_WRITE_CHANNEL = 0x00040000; - /** TODO: 準備中 */ - public static final int COB_WRITE_AFTER = 0x00100000; - /** TODO: 準備中 */ - public static final int COB_WRITE_BEFORE = 0x00200000; - /** TODO: 準備中 */ - public static final int COB_WRITE_EOP = 0x00400000; - /** TODO: 準備中 */ - public static final int COB_WRITE_LOCK = 0x00800000; - - /** TODO: 準備中 */ - public static final int COB_READ_NEXT = 0x01; - /** TODO: 準備中 */ - public static final int COB_READ_PREVIOUS = 0x2; - /** TODO: 準備中 */ - public static final int COB_READ_FIRST = 0x04; - /** TODO: 準備中 */ - public static final int COB_READ_LAST = 0x08; - /** TODO: 準備中 */ - public static final int COB_READ_LOCK = 0x10; - /** TODO: 準備中 */ - public static final int COB_READ_NO_LOCK = 0x20; - /** TODO: 準備中 */ - public static final int COB_READ_KEPT_LOCK = 0x40; - /** TODO: 準備中 */ - public static final int COB_READ_WAIT_LOCK = 0x80; - /** TODO: 準備中 */ - public static final int COB_READ_IGNORE_LOCK = 0x100; - - /** TODO: 準備中 */ - protected static final String TIS_DEFINE_USERFH = "OC_USERFH"; - /** TODO: 準備中 */ - protected static final String COB_IO_CREATES = "OC_IO_CREATES"; - /** TODO: 準備中 */ - protected static final String COB_EXTEND_CREATES = "OC_EXTEND_CREATES"; - - /** TODO: 準備中 */ - protected static final int COB_STATUS_00_SUCCESS = 0; - /** TODO: 準備中 */ - protected static final int COB_STATUS_02_SUCCESS_DUPLICATE = 2; - /** TODO: 準備中 */ - protected static final int COB_STATUS_04_SUCCESS_INCOMPLETE = 4; - /** TODO: 準備中 */ - protected static final int COB_STATUS_05_SUCCESS_OPTIONAL = 5; - /** TODO: 準備中 */ - protected static final int COB_STATUS_07_SUCCESS_NO_UNIT = 7; - /** TODO: 準備中 */ - protected static final int COB_STATUS_10_END_OF_FILE = 10; - /** TODO: 準備中 */ - protected static final int COB_STATUS_14_OUT_OF_KEY_RANGE = 14; - /** TODO: 準備中 */ - protected static final int COB_STATUS_21_KEY_INVALID = 21; - /** TODO: 準備中 */ - protected static final int COB_STATUS_22_KEY_EXISTS = 22; - /** TODO: 準備中 */ - protected static final int COB_STATUS_23_KEY_NOT_EXISTS = 23; - /** TODO: 準備中 */ - protected static final int COB_STATUS_30_PERMANENT_ERROR = 30; - /** TODO: 準備中 */ - protected static final int COB_STATUS_31_INCONSISTENT_FILENAME = 31; - /** TODO: 準備中 */ - protected static final int COB_STATUS_34_BOUNDARY_VIOLATION = 34; - /** TODO: 準備中 */ - protected static final int COB_STATUS_35_NOT_EXISTS = 35; - /** TODO: 準備中 */ - protected static final int COB_STATUS_37_PERMISSION_DENIED = 37; - /** TODO: 準備中 */ - protected static final int COB_STATUS_38_CLOSED_WITH_LOCK = 38; - /** TODO: 準備中 */ - protected static final int COB_STATUS_39_CONFLICT_ATTRIBUTE = 39; - /** TODO: 準備中 */ - protected static final int COB_STATUS_41_ALREADY_OPEN = 41; - /** TODO: 準備中 */ - protected static final int COB_STATUS_42_NOT_OPEN = 42; - /** TODO: 準備中 */ - protected static final int COB_STATUS_43_READ_NOT_DONE = 43; - /** TODO: 準備中 */ - protected static final int COB_STATUS_44_RECORD_OVERFLOW = 44; - /** TODO: 準備中 */ - protected static final int COB_STATUS_46_READ_ERROR = 46; - /** TODO: 準備中 */ - protected static final int COB_STATUS_47_INPUT_DENIED = 47; - /** TODO: 準備中 */ - protected static final int COB_STATUS_48_OUTPUT_DENIED = 48; - /** TODO: 準備中 */ - protected static final int COB_STATUS_49_I_O_DENIED = 49; - /** TODO: 準備中 */ - protected static final int COB_STATUS_51_RECORD_LOCKED = 51; - /** TODO: 準備中 */ - protected static final int COB_STATUS_52_EOP = 52; - /** TODO: 準備中 */ - protected static final int COB_STATUS_57_I_O_LINAGE = 57; - /** TODO: 準備中 */ - protected static final int COB_STATUS_61_FILE_SHARING = 61; - /** TODO: 準備中 */ - protected static final int COB_STATUS_91_NOT_AVAILABLE = 91; - - /** TODO: 準備中 */ - protected static final int COB_LINAGE_INVALID = 16384; - /** TODO: 準備中 */ - protected static final int COB_NOT_CONFIGURED = 32768; - - /** TODO: 準備中 */ - public static final int COB_SELECT_FILE_STATUS = 0x01; - /** TODO: 準備中 */ - public static final int COB_SELECT_EXTERNAL = 0x02; - /** TODO: 準備中 */ - public static final int COB_SELECT_LINAGE = 0x04; - /** TODO: 準備中 */ - public static final int COB_SELECT_SPLITKEY = 0x08; - - /** TODO: 準備中 */ - protected static final int FNSTATUSSIZE = 3; - - /** TODO: 準備中 */ - protected static final int ENOENT = 2; - /** TODO: 準備中 */ - protected static final int EBADF = 9; - /** TODO: 準備中 */ - protected static final int EACCESS = 13; - /** TODO: 準備中 */ - protected static final int EISDIR = 21; - /** TODO: 準備中 */ - protected static final int EROFS = 30; - /** TODO: 準備中 */ - protected static final int EAGAIN = 11; - - /** TODO: 準備中 */ - public static CobolFile errorFile; - - /** TODO: 準備中 */ - protected static int COB_SMALL_BUFF = 1024; - /** TODO: 準備中 */ - protected static int COB_SMALL_MAX = COB_SMALL_BUFF - 1; - - /** TODO: 準備中 */ - protected static final int COB_LOCK_EXCLUSIVE = 1; - /** TODO: 準備中 */ - protected static final int COB_LOCK_MANUAL = 2; - /** TODO: 準備中 */ - protected static final int COB_LOCK_AUTOMATIC = 3; - /** TODO: 準備中 */ - protected static final int COB_LOCK_MULTIPLE = 1; - /** TODO: 準備中 */ - protected static final int COB_LOCK_MASK = 0x7; - - /** TODO: 準備中 */ - protected static String cob_file_path = null; - /** TODO: 準備中 */ - protected static String cob_ls_nulls = null; - /** TODO: 準備中 */ - protected static String cob_ls_fixed = null; - /** TODO: 準備中 */ - protected static byte[] file_open_env = new byte[1024]; - /** TODO: 準備中 */ - protected static String file_open_name; - /** TODO: 準備中 */ - protected static byte[] file_open_buff = new byte[1024]; - - /** TODO: 準備中 */ - protected static final String[] prefix = {"DD_", "dd_", ""}; - /** TODO: 準備中 */ - protected static final int NUM_PREFIX = prefix.length; - - /** TODO: 準備中 */ - protected static int eop_status = 0; - /** TODO: 準備中 */ - protected static int cob_do_sync = 0; - - private static List file_cache = new ArrayList(); - - /** TODO: 準備中 */ - protected static int[] status_exception = { - 0, - CobolExceptionId.COB_EC_I_O_AT_END, - CobolExceptionId.COB_EC_I_O_INVALID_KEY, - CobolExceptionId.COB_EC_I_O_PERMANENT_ERROR, - CobolExceptionId.COB_EC_I_O_LOGIC_ERROR, - CobolExceptionId.COB_EC_I_O_RECORD_OPERATION, - CobolExceptionId.COB_EC_I_O_FILE_SHARING, - CobolExceptionId.COB_EC_I_O, - CobolExceptionId.COB_EC_I_O, - CobolExceptionId.COB_EC_I_O_IMP - }; - /** TODO: 準備中 */ - public String select_name; - /** TODO: 準備中 */ - public byte[] file_status; - /** TODO: 準備中 */ - protected AbstractCobolField assign; - /** TODO: 準備中 */ - public AbstractCobolField record; - /** TODO: 準備中 */ - protected AbstractCobolField record_size; - /** TODO: 準備中 */ - protected CobolFileKey[] keys; - /** TODO: 準備中 */ - public FileIO file; - /** TODO: 準備中 */ - protected CobolSort filex; - /** TODO: 準備中 */ - protected IndexedFile filei; - /** TODO: 準備中 */ - protected Linage linorkeyptr; - /** TODO: 準備中 */ - protected CobolDataStorage sort_collating; - /** TODO: 準備中 */ - protected Object extfh_ptr; - /** TODO: 準備中 */ - protected int record_min; - /** TODO: 準備中 */ - public int record_max; - /** TODO: 準備中 */ - protected int nkeys; - - /** TODO: 準備中 */ - protected char organization; - /** TODO: 準備中 */ - protected char access_mode; - /** TODO: 準備中 */ - protected char lock_mode; - /** TODO: 準備中 */ - protected char open_mode; - /** TODO: 準備中 */ - protected boolean flag_optional; - /** TODO: 準備中 */ - public char last_open_mode; - /** TODO: 準備中 */ - protected char special; - /** TODO: 準備中 */ - protected boolean flag_nonexistent; - - /** TODO: 準備中 */ - protected boolean flag_end_of_file; - /** TODO: 準備中 */ - protected boolean flag_begin_of_file; - /** TODO: 準備中 */ - protected char flag_first_read; - /** TODO: 準備中 */ - protected boolean flag_read_done; - /** TODO: 準備中 */ - public char flag_select_features; - /** TODO: 準備中 */ - protected boolean flag_needs_nl; - /** TODO: 準備中 */ - protected boolean flag_needs_top; - /** TODO: 準備中 */ - protected char file_version; - - /** TODO: 準備中 */ - protected static String runtime_buffer; - /** TODO: 準備中 */ - protected static String name; - /** TODO: 準備中 */ - protected static byte[] status; - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public Linage getLinorkeyptr() { - return this.linorkeyptr; - } - - /** - * TODO: 準備中 - * - * @param ptr TODO: 準備中 - */ - public void setLinorkeyptr(Linage ptr) { - this.linorkeyptr = ptr; - } - - /** TODO: 準備中 */ - public CobolFile() {} - - /** - * TODO: 準備中 - * - * @param selectName TODO: 準備中 - * @param fileStatus TODO: 準備中 - * @param assign TODO: 準備中 - * @param record TODO: 準備中 - * @param recordSize TODO: 準備中 - * @param recordMin TODO: 準備中 - * @param recordMax TODO: 準備中 - * @param nkeys TODO: 準備中 - * @param keys TODO: 準備中 - * @param organization TODO: 準備中 - * @param accessMode TODO: 準備中 - * @param lockMode TODO: 準備中 - * @param openMode TODO: 準備中 - * @param flagOptional TODO: 準備中 - * @param lastOpenMode TODO: 準備中 - * @param special TODO: 準備中 - * @param flagNonexistent TODO: 準備中 - * @param flagEndOfFile TODO: 準備中 - * @param flagBeginOfFile TODO: 準備中 - * @param flagFirstRead TODO: 準備中 - * @param flagReadDone TODO: 準備中 - * @param flagSelectFeatures TODO: 準備中 - * @param flagNeedsNl TODO: 準備中 - * @param flagNeedsTop TODO: 準備中 - * @param fileVersion TODO: 準備中 - */ - public CobolFile( - String selectName, - byte[] fileStatus, - AbstractCobolField assign, - AbstractCobolField record, - AbstractCobolField recordSize, - int recordMin, - int recordMax, - int nkeys, - CobolFileKey[] keys, - char organization, - char accessMode, - char lockMode, - char openMode, - boolean flagOptional, - char lastOpenMode, - char special, - boolean flagNonexistent, - boolean flagEndOfFile, - boolean flagBeginOfFile, - char flagFirstRead, - boolean flagReadDone, - char flagSelectFeatures, - boolean flagNeedsNl, - boolean flagNeedsTop, - char fileVersion) { - - this.select_name = selectName; - this.file_status = fileStatus; - this.assign = assign; - this.record = record; - this.record_size = recordSize; - this.record_min = recordMin; - this.record_max = recordMax; - this.nkeys = nkeys; - this.keys = keys; - this.file = new FileIO(); - this.organization = organization; - this.access_mode = accessMode; - this.lock_mode = lockMode; - this.open_mode = openMode; - this.flag_optional = flagOptional; - this.special = special; - this.flag_nonexistent = flagNonexistent; - this.flag_end_of_file = flagEndOfFile; - this.flag_begin_of_file = flagBeginOfFile; - this.flag_first_read = flagFirstRead; - this.flag_read_done = flagReadDone; - this.flag_select_features = flagSelectFeatures; - this.flag_needs_nl = flagNeedsNl; - this.flag_needs_top = flagNeedsTop; - this.file_version = fileVersion; - } - - // libcob/fileio.cのsave_statusの実装 RETURN_STATUSマクロは実装できないため,本メソッドの呼び出し後の次の文はreturn;を書くこと. - /** - * TODO: 準備中 - * - * @param status TODO: 準備中 - * @param fnstatus TODO: 準備中 - */ - protected void saveStatus(int status, AbstractCobolField fnstatus) { - CobolFile.errorFile = this; - if (status == 0) { - this.file_status[0] = '0'; - this.file_status[1] = '0'; - if (fnstatus != null) { - fnstatus.getDataStorage().setByte(0, (byte) '0'); - fnstatus.getDataStorage().setByte(1, (byte) '0'); - } - CobolRuntimeException.code = 0; - return; - } - - if (status != COB_STATUS_52_EOP) { - CobolRuntimeException.setException(status_exception[status / 10]); - } - this.file_status[0] = (byte) (status / 10 + '0'); - this.file_status[1] = (byte) (status % 10 + '0'); - if (fnstatus != null) { - fnstatus.getDataStorage().setByte(0, this.file_status[0]); - fnstatus.getDataStorage().setByte(1, this.file_status[1]); - } - } - - // libcob/fileio.のcob_invoke_funの実装 - /** - * TODO: 準備中 - * - * @param operate TODO: 準備中 - * @param f TODO: 準備中 - * @param key TODO: 準備中 - * @param rec TODO: 準備中 - * @param fnstatus TODO: 準備中 - * @param openMode TODO: 準備中 - * @param startCond TODO: 準備中 - * @param readOpts TODO: 準備中 - * @return TODO: 準備中 - */ - public static int invokeFun( - int operate, - Object f, - AbstractCobolField key, - CobolDataStorage rec, - AbstractCobolField fnstatus, - String openMode, - String startCond, - String readOpts) { - return 0; - } - - // libcob/cob_cache_fileのj実装 - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - */ - protected static void cacheFile(CobolFile f) { - if (file_cache.contains(f)) { - return; - } - file_cache.add(f); - } - - // libcob/fileio.cのcob_file_linage_checkの実装 TODO 実装 - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - protected boolean file_linage_check() { - Linage lingptr = getLinorkeyptr(); - lingptr.setLinLines(lingptr.getLinage().getInt()); - - outer: - { - if (lingptr.getLinLines() < 1) { - break outer; - } - if (lingptr.getLatfoot() != null) { - lingptr.setLinFoot(lingptr.getLatfoot().getInt()); - if (lingptr.getLinFoot() < 1 || lingptr.getLinFoot() > lingptr.getLinLines()) { - break outer; - } - } else { - lingptr.setLinFoot(0); - } - if (lingptr.getLattop() != null) { - lingptr.setLinTop(lingptr.getLattop().getInt()); - if (lingptr.getLinTop() < 0) { - break outer; - } - } else { - lingptr.setLinTop(0); - } - if (lingptr.getLatbot() != null) { - lingptr.setLinBot(lingptr.getLatbot().getInt()); - if (lingptr.getLinBot() < 0) { - break outer; - } - } else { - lingptr.setLinBot(0); - } - return false; - } - - lingptr.getLinageCtr().setInt(0); - return true; - } - - // libcob/fileio.cのcob_linage_write_optの実装 TODO 実装 - /** - * TODO: 準備中 - * - * @param opt TODO: 準備中 - * @return TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - protected int linage_write_opt(int opt) throws CobolStopRunException { - int i, n; - Linage lingptr = this.getLinorkeyptr(); - - if ((opt & COB_WRITE_PAGE) != 0) { - i = lingptr.getLinageCtr().getInt(); - if (i == 0) { - return COB_STATUS_57_I_O_LINAGE; - } - n = lingptr.getLinLines(); - for (; i < n; ++i) { - this.file.putc((byte) '\n'); - } - for (i = 0; i < lingptr.getLinBot(); i++) { - this.file.putc((byte) '\n'); - } - if (this.file_linage_check()) { - return COB_STATUS_57_I_O_LINAGE; - } - for (i = 0; i < lingptr.getLinTop(); i++) { - this.file.putc((byte) '\n'); - } - lingptr.getLinageCtr().setInt(1); - } else if ((opt & COB_WRITE_LINES) != 0) { - n = lingptr.getLinageCtr().getInt(); - if (n == 0) { - return COB_STATUS_57_I_O_LINAGE; - } - lingptr.getLinageCtr().addInt(opt & COB_WRITE_MASK); - i = lingptr.getLinageCtr().getInt(); - if ((opt & COB_WRITE_EOP) != 0 && lingptr.getLinFoot() != 0) { - if (i >= lingptr.getLinFoot()) { - eop_status = 1; - } - } - if (i > lingptr.getLinLines()) { - if ((opt & COB_WRITE_EOP) != 0) { - eop_status = 1; - } - for (; n < lingptr.getLinLines(); n++) { - this.file.putc((byte) '\n'); - } - for (i = 0; i < lingptr.getLinBot(); i++) { - this.file.putc((byte) '\n'); - } - if (this.file_linage_check()) { - return COB_STATUS_57_I_O_LINAGE; - } - lingptr.getLinageCtr().setInt(1); - for (i = 0; i < lingptr.getLinTop(); i++) { - this.file.putc((byte) '\n'); - } - } else { - for (i = (opt & COB_WRITE_MASK) - 1; i > 0; i--) { - this.file.putc((byte) '\n'); - } - } - } - return 0; - } - - /** - * TODO: 準備中 - * - * @param name TODO: 準備中 - * @param jbuf TODO: 準備中 - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - protected byte[] cb_get_jisword_buff(byte[] name, byte[] jbuf, int n) { - int cs = 0; - int ce = name.length - 1; - int cp; - boolean flagQuoted = false; - int siz = 0; - byte[] rt = null; - int c; - int p = 0; - - if (name[cs] == '\'' && name[ce] == '\'') { - cs++; - --ce; - flagQuoted = true; - } - - if (ce - cs >= 5 - && !(name[cs] == '_' && name[cs + 1] == '_' && name[cs + 2] == '_') - && !(name[ce - 2] == '_' && name[ce - 1] == '_' && name[ce] == '_')) { - cs += 3; - ce -= 3; - if (!flagQuoted) { - siz = (ce - cs + 1) / 2 + 1; - } else { - siz = (ce - cs + 1) / 2 + 3; - } - if (jbuf != null) { - rt = new byte[siz]; - } else { - if (siz > n) { - c = siz - n; - siz -= c; - ce -= c * 2; - } - /* - * TODO fix - * for (int i = 0; i < n; ++i) { - * jbuf[i] = 0; - * } - */ - // TODO - rt = null; - } - if (flagQuoted && siz > 2) { - rt[0] = rt[siz - 2] = (byte) '\''; - p = 1; - } else { - p = 0; - } - for (c = 0, cp = cs; cp <= ce; cp++, p += (c == 0 ? 1 : 0)) { - if (name[cp] >= '0' && name[cp] <= '9') { - rt[p] |= (name[cp] - '0') << (c << 2); - } else if (name[cp] >= 'A' && name[cp] <= 'F') { - rt[p] |= (name[cp] - 'A' + 10) << (c << 2); - } else { - name[p] = '?'; - cp += c; - c = 0; - } - } - } else { - if (jbuf != null) { - rt = name.clone(); - } else { - /* - * TODO fix - * for (int i = 0; i < n; ++i) { - * jbuf[i] = 0; - * } - * for (int i = 0; i < n - 1; ++i) { - * jbuf[i] = name[i]; - * } - */ - // TODO fix - rt = null; - } - } - return rt; - } - - // assert 0 <= openMode < 10 - private static String openModeToString(int openMode) { - StringBuilder sb = new StringBuilder(); - return sb.append("0").append(openMode).toString(); - } - - private static String readOptsToString(int readOpts) { - StringBuilder sb = new StringBuilder(); - if (readOpts < 10) { - sb.append("0"); - } - return sb.append(readOpts).toString(); - } - - private static String concatString(String... strs) { - StringBuilder sb = new StringBuilder(); - for (String s : strs) { - sb.append(s); - } - return sb.toString(); - } - - /** - * TODO: 準備中 - * - * @param mode TODO: 準備中 - * @param sharing TODO: 準備中 - * @param fnstatus TODO: 準備中 - */ - public void open(int mode, int sharing, AbstractCobolField fnstatus) { - String openMode = openModeToString(mode); - if (invokeFun(COB_IO_OPEN, this, null, null, fnstatus, openMode, null, null) != 0) { - this.last_open_mode = (char) Integer.parseInt(openMode); - return; - } - this.last_open_mode = (char) Integer.parseInt(openMode); - - /* file was previously closed with lock */ - if (this.open_mode == COB_OPEN_LOCKED) { - saveStatus(COB_STATUS_38_CLOSED_WITH_LOCK, fnstatus); - return; - } - - /* file is already open */ - if (((int) this.open_mode) != COB_OPEN_CLOSED) { - saveStatus(COB_STATUS_41_ALREADY_OPEN, fnstatus); - return; - } - - this.last_open_mode = (char) mode; - this.flag_nonexistent = false; - this.flag_end_of_file = false; - this.flag_begin_of_file = false; - this.flag_first_read = 2; - - if (this.special != 0) { - if (this.special == 1) { - if (mode != COB_OPEN_INPUT) { - saveStatus(COB_STATUS_30_PERMANENT_ERROR, fnstatus); - return; - } - this.file.setIn(System.in); - this.open_mode = (char) mode; - this.saveStatus(COB_STATUS_00_SUCCESS, fnstatus); - return; - } else { - if (mode != COB_OPEN_OUTPUT) { - this.saveStatus(COB_STATUS_30_PERMANENT_ERROR, fnstatus); - return; - } - this.file.setOut(System.out); - this.open_mode = (char) mode; - saveStatus(COB_STATUS_00_SUCCESS, fnstatus); - return; - } - } - - /* obtain the file name */ - if (this.assign == null) { - file_open_name = this.select_name; - } else { - file_open_name = this.assign.fieldToString(); - } - - byte[] src; - byte[] dst; - boolean simple; - if (CobolModule.getCurrentModule().flag_filename_mapping != 0) { - src = file_open_name.getBytes(); - dst = file_open_buff; - simple = true; - int srcI = 0; - int dstI = 0; - while (srcI < src.length) { - char c = (char) src[srcI]; - if (!Character.isLetterOrDigit(c) && c != '_' && c != '-') { - simple = false; - } - if (c == '$') { - int i; - for (i = 1; srcI + i < src.length; i++) { - char d = (char) src[srcI + i]; - if (!Character.isLetterOrDigit(d) && d != '_' && c != '-') { - break; - } - } - for (int j = 0; j < i - 1; ++j) { - file_open_env[j] = src[srcI + 1 + j]; - } - file_open_env[i - 1] = 0; - String p = CobolUtil.getEnv(new String(Arrays.copyOfRange(file_open_env, 0, i - 1))); - if (p != null) { - byte[] pbytes = p.getBytes(); - for (int j = 0; j < pbytes.length; ++j) { - dst[dstI + j] = pbytes[j]; - } - dstI += pbytes.length; - } - srcI += i; - } else { - dst[dstI++] = src[srcI++]; - } - } - - file_open_name = new String(Arrays.copyOfRange(dst, 0, dstI)); - - byte[] fileOpenNameBytes = file_open_name.getBytes(); - cb_get_jisword_buff(file_open_buff, fileOpenNameBytes, COB_SMALL_BUFF); - - if (simple) { - int i; - for (i = 0; i < NUM_PREFIX; i++) { - byte[] fileOpenBuff = concatString(prefix[i], file_open_name).getBytes(); - String p = CobolUtil.getEnv(new String(fileOpenBuff)); - if (p != null) { - fileOpenNameBytes = p.getBytes(); - break; - } - } - - if (i == NUM_PREFIX && cob_file_path != null) { - byte[] fileOpenBuff = concatString(cob_file_path, "/", file_open_name).getBytes(); - fileOpenNameBytes = fileOpenBuff; - } - } - - file_open_name = new String(fileOpenNameBytes); - } - - boolean wasNotExist = false; - if (this.organization == COB_ORG_INDEXED) { - if (!Files.exists(Paths.get(file_open_name))) { - wasNotExist = true; - if (mode != COB_OPEN_OUTPUT - && !this.flag_optional - && (mode != COB_OPEN_I_O || !"yes".equals(CobolUtil.getEnv(COB_IO_CREATES))) - && (mode != COB_OPEN_EXTEND || !"yes".equals(CobolUtil.getEnv(COB_EXTEND_CREATES)))) { - saveStatus(COB_STATUS_35_NOT_EXISTS, fnstatus); - return; - } - } - } else if (Files.notExists(Paths.get(file_open_name))) { - wasNotExist = true; - if (mode != COB_OPEN_OUTPUT - && !this.flag_optional - && (mode != COB_OPEN_I_O || CobolUtil.checkEnv(COB_IO_CREATES, "yes") == 0) - && (mode != COB_OPEN_EXTEND || CobolUtil.checkEnv(COB_EXTEND_CREATES, "yes") == 0)) { - saveStatus(COB_STATUS_35_NOT_EXISTS, fnstatus); - return; - } - } - cacheFile(this); - - try { - switch (this.open_(file_open_name, mode, sharing)) { - case 0: - this.open_mode = (char) mode; - if (this.flag_optional && wasNotExist) { - saveStatus(COB_STATUS_05_SUCCESS_OPTIONAL, fnstatus); - return; - } else { - saveStatus(COB_STATUS_00_SUCCESS, fnstatus); - return; - } - case ENOENT: - if (mode == COB_OPEN_EXTEND || mode == COB_OPEN_OUTPUT) { - saveStatus(COB_STATUS_30_PERMANENT_ERROR, fnstatus); - return; - } - if (this.flag_optional) { - this.open_mode = (char) mode; - this.flag_nonexistent = true; - this.flag_end_of_file = true; - this.flag_begin_of_file = true; - saveStatus(COB_STATUS_05_SUCCESS_OPTIONAL, fnstatus); - return; - } else { - saveStatus(COB_STATUS_35_NOT_EXISTS, fnstatus); - return; - } - case EACCESS: - case EISDIR: - case EROFS: - saveStatus(COB_STATUS_37_PERMISSION_DENIED, fnstatus); - return; - case COB_STATUS_61_FILE_SHARING: - saveStatus(COB_STATUS_61_FILE_SHARING, fnstatus); - return; - case COB_STATUS_91_NOT_AVAILABLE: - saveStatus(COB_STATUS_91_NOT_AVAILABLE, fnstatus); - return; - case COB_LINAGE_INVALID: - saveStatus(COB_STATUS_57_I_O_LINAGE, fnstatus); - return; - default: - saveStatus(COB_STATUS_30_PERMANENT_ERROR, fnstatus); - return; - } - } catch (IOException e) { - saveStatus(COB_STATUS_30_PERMANENT_ERROR, fnstatus); - return; - } - } - - // protected long start; - // protected long end; - - /** - * TODO: 準備中 - * - * @param mode TODO: 準備中 - * @param sharing TODO: 準備中 - * @param fnstatus TODO: 準備中 - */ - public void openEx(int mode, int sharing, AbstractCobolField fnstatus) { - // this.open_("", mode, sharing); - } - - /** - * TODO: 準備中 - * - * @param filename TODO: 準備中 - * @param mode TODO: 準備中 - * @param sharing TODO: 準備中 - * @return TODO: 準備中 - * @throws IOException TODO: 準備中 - */ - public int open_(String filename, int mode, int sharing) throws IOException { - FileChannel fp = null; - try { - switch (mode) { - case COB_OPEN_INPUT: - fp = FileChannel.open(Paths.get(filename), StandardOpenOption.READ); - break; - case COB_OPEN_OUTPUT: - fp = - FileChannel.open( - Paths.get(filename), - StandardOpenOption.WRITE, - StandardOpenOption.CREATE, - StandardOpenOption.TRUNCATE_EXISTING); - break; - case COB_OPEN_I_O: - fp = - FileChannel.open( - Paths.get(filename), - StandardOpenOption.READ, - StandardOpenOption.WRITE, - StandardOpenOption.CREATE); - break; - case COB_OPEN_EXTEND: - fp = - FileChannel.open( - Paths.get(filename), StandardOpenOption.APPEND, StandardOpenOption.CREATE); - break; - default: - break; - } - } catch (IOException e) { - if (Files.notExists(Paths.get(filename))) { - return ENOENT; - } else { - return EACCESS; - } - } - - FileLock fl = null; - if (!filename.startsWith("/dev/")) { - try { - boolean lockFlag; - if (sharing != 0 || mode == COB_OPEN_OUTPUT) { - lockFlag = false; - } else { - lockFlag = true; - } - fl = fp.tryLock(0L, Long.MAX_VALUE, lockFlag); - } catch (NonWritableChannelException e) { - fp.close(); - return EBADF; - } catch (ClosedChannelException e) { - fp.close(); - return COB_STATUS_61_FILE_SHARING; - } - - this.file.setChannel(fp, fl); - if (fl == null || !fl.isValid()) { - fp.close(); - return COB_STATUS_61_FILE_SHARING; - } - } - - this.file.setChannel(fp, fl); - if ((this.flag_select_features & COB_SELECT_LINAGE) != 0) { - if (this.file_linage_check()) { - return COB_LINAGE_INVALID; - } - this.flag_needs_top = true; - Linage lingptr = this.getLinorkeyptr(); - lingptr.getLinageCtr().setInt(1); - } - if ((this.organization == COB_ORG_SEQUENTIAL || this.organization == COB_ORG_LINE_SEQUENTIAL) - && (mode == COB_OPEN_OUTPUT || mode == COB_OPEN_EXTEND) - && CobolUtil.fileSeqWriteBufferSize > 0) { - this.file.prepareWriteBuffer(CobolUtil.fileSeqWriteBufferSize * this.record_max); - } - return 0; - } - - /** - * TODO: 準備中 - * - * @param opt TODO: 準備中 - * @param fnstatus TODO: 準備中 - */ - public void close(int opt, AbstractCobolField fnstatus) { - String openMode = openModeToString(this.last_open_mode); - if (invokeFun(COB_IO_CLOSE, this, null, null, fnstatus, openMode, null, null) != 0) { - this.last_open_mode = (char) Integer.parseInt(openMode); - return; - } - - this.flag_read_done = false; - if (this.special != 0) { - this.open_mode = COB_OPEN_CLOSED; - saveStatus(COB_STATUS_00_SUCCESS, fnstatus); - return; - } - if (this.open_mode == COB_OPEN_CLOSED) { - saveStatus(COB_STATUS_42_NOT_OPEN, fnstatus); - return; - } - - int ret; - if (this.flag_nonexistent) { - ret = COB_STATUS_00_SUCCESS; - } else { - ret = this.close_(opt); - } - - if (ret == COB_STATUS_00_SUCCESS) { - switch (opt) { - case COB_CLOSE_LOCK: - this.open_mode = COB_OPEN_LOCKED; - break; - default: - this.open_mode = COB_OPEN_CLOSED; - break; - } - } - saveStatus(ret, fnstatus); - } - - // public void closeEx(int opt, AbstractCobolField fnstatus) { - // this.close_(opt); - // } - - /** - * TODO: 準備中 - * - * @param opt TODO: 準備中 - * @return TODO: 準備中 - */ - public int close_(int opt) { - switch (opt) { - case COB_CLOSE_NORMAL: - case COB_CLOSE_LOCK: - case COB_CLOSE_NO_REWIND: - if (this.organization == COB_ORG_LINE_SEQUENTIAL) { - if (this.flag_needs_nl && ((this.flag_select_features & COB_SELECT_LINAGE) == 0)) { - this.flag_needs_nl = false; - this.file.putc((byte) '\n'); - } - } - - this.file.releaseLock(); - this.file.close(); - - if (opt == COB_CLOSE_NO_REWIND) { - this.open_mode = COB_OPEN_CLOSED; - return COB_STATUS_07_SUCCESS_NO_UNIT; - } - return COB_STATUS_00_SUCCESS; - default: - this.file.flush(); - return COB_STATUS_07_SUCCESS_NO_UNIT; - } - } - - /** - * TODO: 準備中 - * - * @param cond TODO: 準備中 - * @param key TODO: 準備中 - * @param fnstatus TODO: 準備中 - */ - public void start(int cond, AbstractCobolField key, AbstractCobolField fnstatus) { - String openMode = openModeToString(this.last_open_mode); - String startCond = String.format("%01d", cond); - if (invokeFun(COB_IO_START, this, null, null, fnstatus, openMode, startCond, null) != 0) { - return; - } - - this.flag_read_done = false; - this.flag_first_read = 0; - - if (this.flag_nonexistent) { - saveStatus(COB_STATUS_23_KEY_NOT_EXISTS, fnstatus); - return; - } - - if (this.open_mode == COB_OPEN_CLOSED - || this.open_mode == COB_OPEN_OUTPUT - || this.open_mode == COB_OPEN_EXTEND - || this.access_mode == COB_ACCESS_RANDOM) { - saveStatus(COB_STATUS_47_INPUT_DENIED, fnstatus); - return; - } - - int ret = this.start_(cond, key); - if (ret == COB_STATUS_00_SUCCESS) { - this.flag_end_of_file = false; - this.flag_begin_of_file = false; - this.flag_first_read = 1; - } - - saveStatus(ret, fnstatus); - } - - /** - * TODO: 準備中 - * - * @param cond TODO: 準備中 - * @param key TODO: 準備中 - * @param fnstatus TODO: 準備中 - */ - public void startEx(int cond, AbstractCobolField key, AbstractCobolField fnstatus) { - this.start_(cond, key); - } - - /** - * TODO: 準備中 - * - * @param cond TODO: 準備中 - * @param key TODO: 準備中 - * @return TODO: 準備中 - */ - public int start_(int cond, AbstractCobolField key) { - System.out.println("super.start"); - return 0; - } - - /** - * TODO: 準備中 - * - * @param key TODO: 準備中 - * @param fnstatus TODO: 準備中 - * @param readOpts TODO: 準備中 - */ - public void read(AbstractCobolField key, AbstractCobolField fnstatus, int readOpts) { - byte[] sbuff = new byte[3]; - String openMode = openModeToString(this.last_open_mode); - String readOptStr = readOptsToString(readOpts); - if (invokeFun(COB_IO_READ, this, key, null, fnstatus, openMode, null, readOptStr) != 0) { - for (int i = 0; i < 3; ++i) { - sbuff[i] = 0; - } - - if (fnstatus == null) { - return; - } - - for (int i = 0; i < 2; ++i) { - sbuff[i] = fnstatus.getDataStorage().getByte(i); - } - int status = Integer.parseInt(new String(sbuff)); - saveStatus(status, fnstatus); - return; - } - - this.flag_read_done = false; - if (this.flag_nonexistent) { - if (this.flag_first_read == 0) { - saveStatus(COB_STATUS_23_KEY_NOT_EXISTS, fnstatus); - return; - } - this.flag_first_read = 0; - saveStatus(COB_STATUS_10_END_OF_FILE, fnstatus); - return; - } - - /* sequential read at the end of file is an error */ - if (key == null) { - if (this.flag_end_of_file && (readOpts & COB_READ_PREVIOUS) == 0) { - saveStatus(COB_STATUS_46_READ_ERROR, fnstatus); - return; - } - if (this.flag_begin_of_file && (readOpts & COB_READ_PREVIOUS) != 0) { - saveStatus(COB_STATUS_46_READ_ERROR, fnstatus); - return; - } - } - - if (this.open_mode == COB_OPEN_CLOSED - || this.open_mode == COB_OPEN_OUTPUT - || this.open_mode == COB_OPEN_EXTEND) { - saveStatus(COB_STATUS_47_INPUT_DENIED, fnstatus); - return; - } - - if (this.organization == COB_ORG_INDEXED) { - if (this.open_mode != COB_OPEN_I_O || (this.lock_mode & COB_LOCK_EXCLUSIVE) != 0) { - readOpts &= ~COB_READ_LOCK; - } else if ((this.lock_mode & COB_LOCK_AUTOMATIC) != 0 && (readOpts & COB_READ_NO_LOCK) == 0) { - readOpts |= COB_READ_LOCK; - } - } else { - readOpts &= ~COB_READ_LOCK; - } - - if (this.organization == COB_ORG_INDEXED /* && bdb_env != null */) { - if (this.open_mode != COB_OPEN_I_O || (this.lock_mode & COB_LOCK_EXCLUSIVE) != 0) { - readOpts &= ~COB_READ_LOCK; - } else if ((this.lock_mode & COB_LOCK_AUTOMATIC) != 0 && (readOpts & COB_READ_NO_LOCK) == 0) { - readOpts |= COB_READ_LOCK; - } - } else { - readOpts &= ~COB_READ_LOCK; - } - - int ret; - if (key != null) { - ret = this.read_(key, readOpts); - } else { - ret = this.readNext(readOpts); - } - - switch (ret) { - case COB_STATUS_00_SUCCESS: - this.flag_first_read = 0; - this.flag_read_done = true; - this.flag_end_of_file = false; - this.flag_begin_of_file = false; - if (this.record_size != null && this.organization != COB_ORG_LINE_SEQUENTIAL) { - this.record_size.setInt(record.getSize()); - } - break; - case COB_STATUS_10_END_OF_FILE: - if ((readOpts & COB_READ_PREVIOUS) != 0) { - this.flag_begin_of_file = true; - } else { - this.flag_end_of_file = true; - } - break; - default: - break; - } - - saveStatus(ret, fnstatus); - } - - /** - * TODO: 準備中 - * - * @param key TODO: 準備中 - * @param fnstatus TODO: 準備中 - * @param readOpts TODO: 準備中 - */ - public void read(int key, AbstractCobolField fnstatus, int readOpts) { - this.read(null, fnstatus, readOpts); - } - - /** - * TODO: 準備中 - * - * @param key TODO: 準備中 - * @param fnstatus TODO: 準備中 - * @param readOpts TODO: 準備中 - */ - public void readEx(AbstractCobolField key, AbstractCobolField fnstatus, int readOpts) { - this.read_(key, readOpts); - } - - /** - * TODO: 準備中 - * - * @param key TODO: 準備中 - * @param readOpts TODO: 準備中 - * @return TODO: 準備中 - */ - public int read_(AbstractCobolField key, int readOpts) { - System.out.println("super.read"); - return 0; - } - - /** - * TODO: 準備中 - * - * @param readOpts TODO: 準備中 - * @return TODO: 準備中 - */ - public int readNext(int readOpts) { - System.out.println("super.readNext"); - return 0; - } - - /** - * TODO: 準備中 - * - * @param rec TODO: 準備中 - * @param opt TODO: 準備中 - * @param fnstatus TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public void write(AbstractCobolField rec, int opt, AbstractCobolField fnstatus) - throws CobolStopRunException { - if (this.access_mode == COB_ACCESS_SEQUENTIAL - && this.last_open_mode == COB_OPEN_I_O - && CobolUtil.cob_io_rewwrite_assumed()) { - this.rewrite(rec, opt, fnstatus); - return; - } - - String openMode = openModeToString(this.last_open_mode); - if (invokeFun(COB_IO_WRITE, this, null, rec.getDataStorage(), fnstatus, openMode, null, null) - != 0) { - return; - } - - this.flag_read_done = false; - if (this.access_mode == COB_ACCESS_SEQUENTIAL) { - if (this.open_mode == COB_OPEN_CLOSED - || this.open_mode == COB_OPEN_INPUT - || this.open_mode == COB_OPEN_I_O) { - saveStatus(COB_STATUS_48_OUTPUT_DENIED, fnstatus); - return; - } - } else { - if (this.open_mode == COB_OPEN_CLOSED - || this.open_mode == COB_OPEN_INPUT - || this.open_mode == COB_OPEN_EXTEND) { - saveStatus(COB_STATUS_48_OUTPUT_DENIED, fnstatus); - return; - } - } - - int tmpsize = this.record.getSize(); - if (this.record_size != null) { - this.record.setSize(this.record_size.getInt()); - } else { - this.record.setSize(rec.getSize()); - } - - if (this.record.getSize() < this.record_min || this.record_max < this.record.getSize()) { - saveStatus(COB_STATUS_44_RECORD_OVERFLOW, fnstatus); - return; - } - - int ret = this.write_(opt); - - if (cob_do_sync != 0 && ret == 0) { - cob_sync(this, cob_do_sync); - } - - this.record.setSize(tmpsize); - saveStatus(ret, fnstatus); - } - - /** - * TODO: 準備中 - * - * @param rec TODO: 準備中 - * @param opt TODO: 準備中 - * @param fnstatus TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public void writeEx(AbstractCobolField rec, int opt, AbstractCobolField fnstatus) - throws CobolStopRunException { - this.write_(opt); - } - - /** - * TODO: 準備中 - * - * @param opt TODO: 準備中 - * @return TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public int write_(int opt) throws CobolStopRunException { - System.out.println("super.write"); - return 0; - } - - // libcob/fileio.cのcob_file_write_optの実装 - /** - * TODO: 準備中 - * - * @param opt TODO: 準備中 - * @return TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - protected int file_write_opt(int opt) throws CobolStopRunException { - if ((this.flag_select_features & COB_SELECT_LINAGE) != 0) { - return linage_write_opt(opt); - } - if ((opt & COB_WRITE_LINES) != 0) { - for (int i = opt & COB_WRITE_MASK; i > 0; i--) { - this.file.putc((byte) '\n'); - } - } else if ((opt & COB_WRITE_PAGE) != 0) { - this.file.putc((byte) '\f'); - } - return 0; - } - - /** - * TODO: 準備中 - * - * @param rec TODO: 準備中 - * @param opt TODO: 準備中 - * @param fnstatus TODO: 準備中 - */ - public void rewrite(AbstractCobolField rec, int opt, AbstractCobolField fnstatus) { - String openMode = openModeToString(this.last_open_mode); - if (invokeFun(COB_IO_REWRITE, this, null, null, fnstatus, openMode, null, null) != 0) { - this.last_open_mode = (char) Integer.parseInt(openMode); - return; - } - - boolean readDone = this.flag_read_done; - this.flag_read_done = false; - - if (this.open_mode == COB_OPEN_CLOSED || this.open_mode != COB_OPEN_I_O) { - saveStatus(COB_STATUS_49_I_O_DENIED, fnstatus); - return; - } - if (this.access_mode == COB_ACCESS_SEQUENTIAL && !readDone) { - saveStatus(COB_STATUS_43_READ_NOT_DONE, fnstatus); - return; - } - if (this.organization == COB_ORG_SEQUENTIAL) { - if (this.record.getSize() != rec.getSize()) { - saveStatus(COB_STATUS_44_RECORD_OVERFLOW, fnstatus); - return; - } - if (this.record_size != null) { - if (this.record.getSize() != this.record_size.getInt()) { - saveStatus(COB_STATUS_44_RECORD_OVERFLOW, fnstatus); - return; - } - } - } - int ret = this.rewrite_(opt); - if (cob_do_sync != 0 && ret == 0) { - cob_sync(this, cob_do_sync); - } - - saveStatus(ret, fnstatus); - } - - /** - * TODO: 準備中 - * - * @param rec TODO: 準備中 - * @param opt TODO: 準備中 - * @param fnstatus TODO: 準備中 - */ - public void rewriteEx(AbstractCobolField rec, int opt, AbstractCobolField fnstatus) { - this.rewrite_(opt); - } - - /** - * TODO: 準備中 - * - * @param opt TODO: 準備中 - * @return TODO: 準備中 - */ - public int rewrite_(int opt) { - System.out.println("super.rewrite"); - return 0; - } - - /** - * TODO: 準備中 - * - * @param fnstatus TODO: 準備中 - */ - public void delete(AbstractCobolField fnstatus) { - String openMode = openModeToString(this.last_open_mode); - if (invokeFun(COB_IO_DELETE, this, null, null, fnstatus, openMode, null, null) != 0) { - return; - } - - boolean readDone = this.flag_read_done; - this.flag_read_done = false; - - if (this.open_mode == COB_OPEN_CLOSED || this.open_mode != COB_OPEN_I_O) { - saveStatus(COB_STATUS_49_I_O_DENIED, fnstatus); - return; - } - - if (this.access_mode == COB_ACCESS_SEQUENTIAL && !readDone) { - saveStatus(COB_STATUS_43_READ_NOT_DONE, fnstatus); - return; - } - - int ret = this.delete_(); - - if (cob_do_sync != 0 && ret == 0) { - cob_sync(this, cob_do_sync); - } - saveStatus(ret, fnstatus); - } - - /** - * TODO: 準備中 - * - * @param fnstatus TODO: 準備中 - */ - public void deleteEx(AbstractCobolField fnstatus) { - this.delete_(); - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public int delete_() { - System.out.println("super.delete"); - return 0; - } - - /** - * TODO: 準備中 - * - * @param fnstatus TODO: 準備中 - */ - public void unlock(AbstractCobolField fnstatus) { - String openMode = openModeToString(this.last_open_mode); - if (invokeFun(COB_IO_UNLOCK, this, null, null, fnstatus, openMode, null, null) != 0) { - return; - } - this.unlock_(); - saveStatus(COB_STATUS_00_SUCCESS, fnstatus); - } - - /** TODO: 準備中 */ - public void unlock_() { - if (this.open_mode != COB_OPEN_CLOSED && this.open_mode != COB_OPEN_LOCKED) { - this.file.flush(); - } - } - - /** TODO: 準備中 */ - public static void commit() { - if (invokeFun(COB_IO_COMMIT, null, null, null, null, null, null, null) != 0) { - return; - } - for (CobolFile l : file_cache) { - l.unlock_(); - } - } - - /** TODO: 準備中 */ - public static void rollback() { - if (invokeFun(COB_IO_ROLLBACK, null, null, null, null, null, null, null) != 0) { - return; - } - for (CobolFile l : file_cache) { - l.unlock_(); - } - } - - /// libcob/fileio.cのcob_exit_fileioの実装 TODO 一部だけ実装したため残りを実装する - /** TODO: 準備中 */ - public static void exitFileIO() { - for (CobolFile f : file_cache) { - if (f.open_mode != COB_OPEN_CLOSED && f.open_mode != COB_OPEN_LOCKED) { - String filename = f.assign.fieldToString(); - System.err.print( - String.format( - "WARNING - Implicit CLOSE of %s (\"%s\") %c", f.select_name, filename, '\n')); - } - } - } - - // libcob/fileio.cのcob_syncの実装 - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - * @param mode TODO: 準備中 - */ - protected void cob_sync(CobolFile f, int mode) { - // TODO - // INDEXEDファイル実装時にやる - // if (f.organization == COB_ORG_INDEXED) { - // } - if (f.organization != COB_ORG_SORT) { - this.file.flush(); - if (mode == 2) { - this.file.flush(); - } - } - } - - // libcob/fileio.cのcob_init_fileioの実装 - /** TODO: 準備中 */ - public static void cob_init_fileio() { - String s = CobolUtil.getEnv("COB_SYNC"); - if (s != null) { - if (s.charAt(0) == 'Y' || s.charAt(0) == 'y') { - cob_do_sync = 1; - } - if (s.charAt(0) == 'P' || s.charAt(0) == 'p') { - cob_do_sync = 2; - } - } - - cob_file_path = CobolUtil.getEnv("COB_FILE_PATH"); - if (cob_file_path != null) { - if (cob_file_path.charAt(0) == '\0' || cob_file_path.charAt(0) == ' ') { - cob_file_path = null; - } - } - - cob_ls_nulls = CobolUtil.getEnv("COB_LS_NULLS"); - cob_ls_fixed = CobolUtil.getEnv("COB_LS_FIXED"); - - file_open_env = new byte[COB_SMALL_BUFF]; - // file_open_name = new byte[COB_SMALL_BUFF]; - file_open_buff = new byte[COB_SMALL_BUFF]; - } - - /** TODO: 準備中 */ - public static void defaultErrorHandle() { - byte[] fileStatus = CobolFile.errorFile.file_status; - int status = (fileStatus[0] - '0') * 10 + (fileStatus[1] - '0'); - String msg; - switch (status) { - case COB_STATUS_10_END_OF_FILE: - msg = "End of file"; - break; - case COB_STATUS_14_OUT_OF_KEY_RANGE: - msg = "Key out of range"; - break; - case COB_STATUS_21_KEY_INVALID: - msg = "Key order not ascending"; - break; - case COB_STATUS_22_KEY_EXISTS: - msg = "Record key already exists"; - break; - case COB_STATUS_23_KEY_NOT_EXISTS: - msg = "Record key does not exist"; - break; - case COB_STATUS_30_PERMANENT_ERROR: - msg = "Permanent file error"; - break; - case COB_STATUS_35_NOT_EXISTS: - msg = "File does not exist"; - break; - case COB_STATUS_37_PERMISSION_DENIED: - msg = "Permission denied"; - break; - case COB_STATUS_41_ALREADY_OPEN: - msg = "File already open"; - break; - case COB_STATUS_42_NOT_OPEN: - msg = "File not open"; - break; - case COB_STATUS_43_READ_NOT_DONE: - msg = "READ must be executed first"; - break; - case COB_STATUS_44_RECORD_OVERFLOW: - msg = "Record overflow"; - break; - case COB_STATUS_46_READ_ERROR: - msg = "Failed to read"; - break; - case COB_STATUS_47_INPUT_DENIED: - msg = "READ/START not allowed"; - break; - case COB_STATUS_48_OUTPUT_DENIED: - msg = "WRITE not allowed"; - break; - case COB_STATUS_49_I_O_DENIED: - msg = "DELETE/REWRITE not allowed"; - break; - case COB_STATUS_51_RECORD_LOCKED: - msg = "Record locked by another file connector"; - break; - case COB_STATUS_52_EOP: - msg = "A page overflow condition occurred"; - break; - case COB_STATUS_57_I_O_LINAGE: - msg = "LINAGE values invalid"; - break; - case COB_STATUS_61_FILE_SHARING: - msg = "File sharing conflict"; - break; - case COB_STATUS_91_NOT_AVAILABLE: - msg = "Runtime library is not configured for this operation"; - break; - default: - msg = "Unknown file error"; - break; - } - String filename = CobolFile.errorFile.assign.fieldToString(); - CobolUtil.runtimeError(String.format("%s (STATUS = %02d) File : '%s'", msg, status, filename)); - } - - /** - * TODO: 準備中 - * - * @param fnstatus TODO: 準備中 - */ - public void cob_delete_file(AbstractCobolField fnstatus) { - String openMode = openModeToString(this.last_open_mode); - if (invokeFun(COB_IO_DELETE_FILE, this, null, null, fnstatus, openMode, null, null) != 0) { - return; - } - - if (this.open_mode == COB_OPEN_LOCKED) { - saveStatus(COB_STATUS_38_CLOSED_WITH_LOCK, fnstatus); - return; - } - - /* file is already open */ - if (this.open_mode != COB_OPEN_CLOSED) { - saveStatus(COB_STATUS_41_ALREADY_OPEN, fnstatus); - return; - } - - if (this.special != 0) { - saveStatus(COB_STATUS_30_PERMANENT_ERROR, fnstatus); - return; - } - - if (this.assign == null) { - file_open_name = this.select_name; - } else { - file_open_name = this.assign.fieldToString(); - } - - byte[] src; - byte[] dst; - boolean simple; - if (CobolModule.getCurrentModule().flag_filename_mapping != 0) { - src = file_open_name.getBytes(); - dst = file_open_buff; - simple = true; - int srcI = 0; - int dstI = 0; - while (srcI < src.length) { - char c = (char) src[srcI]; - if (!Character.isLetterOrDigit(c) && c != '_' && c != '-') { - simple = false; - } - if (c == '$') { - int i; - for (i = 1; srcI + i < src.length; i++) { - char d = (char) src[srcI + i]; - if (!Character.isLetterOrDigit(d) && d != '_' && c != '-') { - break; - } - } - for (int j = 0; j < i - 1; ++j) { - file_open_env[j] = src[srcI + 1 + j]; - } - file_open_env[i - 1] = 0; - String p = CobolUtil.getEnv(new String(Arrays.copyOfRange(file_open_env, 0, i - 1))); - if (p != null) { - byte[] pbytes = p.getBytes(); - for (int j = 0; j < pbytes.length; ++j) { - dst[dstI + j] = pbytes[j]; - } - dstI += pbytes.length; - } - srcI += i; - } else { - dst[dstI++] = src[srcI++]; - } - } - - file_open_name = new String(Arrays.copyOfRange(dst, 0, dstI)); - - byte[] fileOpenNameBytes = file_open_name.getBytes(); - cb_get_jisword_buff(file_open_buff, fileOpenNameBytes, COB_SMALL_BUFF); - - if (simple) { - int i; - for (i = 0; i < NUM_PREFIX; i++) { - byte[] fileOpenBuff = concatString(prefix[i], file_open_name).getBytes(); - String p = CobolUtil.getEnv(new String(fileOpenBuff)); - if (p != null) { - fileOpenNameBytes = p.getBytes(); - break; - } - } - - if (i == NUM_PREFIX && cob_file_path != null) { - byte[] fileOpenBuff = concatString(cob_file_path, "/", file_open_name).getBytes(); - fileOpenNameBytes = fileOpenBuff; - } - } - - file_open_name = new String(fileOpenNameBytes); - } - - Path filePath; - if (this.assign == null) { - filePath = Paths.get(this.select_name); - } else { - filePath = Paths.get(this.assign.fieldToString()); - } - try { - saveStatus(COB_STATUS_00_SUCCESS, fnstatus); - Files.delete(filePath); - return; - } catch (IOException e) { - int mode = (int) this.last_open_mode; - try { - switch (this.open_(file_open_name, mode, 0)) { - case ENOENT: - saveStatus(COB_STATUS_35_NOT_EXISTS, fnstatus); - return; - case EACCESS: - case EISDIR: - case EROFS: - saveStatus(COB_STATUS_37_PERMISSION_DENIED, fnstatus); - return; - case EAGAIN: - case COB_STATUS_61_FILE_SHARING: - saveStatus(COB_STATUS_61_FILE_SHARING, fnstatus); - return; - case COB_STATUS_91_NOT_AVAILABLE: - saveStatus(COB_STATUS_91_NOT_AVAILABLE, fnstatus); - return; - case COB_LINAGE_INVALID: - saveStatus(COB_STATUS_57_I_O_LINAGE, fnstatus); - return; - default: - saveStatus(COB_STATUS_30_PERMANENT_ERROR, fnstatus); - return; - } - } catch (IOException e1) { - saveStatus(COB_STATUS_30_PERMANENT_ERROR, fnstatus); - return; - } - } - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public String getSelectName() { - // CobolFile cobolFile = new CobolFile(); - return this.select_name; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public byte[] getFileStatus() { - // CobolFile cobolFile = new CobolFile(); - return this.file_status; - } - - private static Map externalFileStatusTable = new HashMap(); - - /** - * TODO: 準備中 - * - * @param key TODO: 準備中 - * @return TODO: 準備中 - */ - public static byte[] getExternalFileStatus(String key) { - byte[] bytes = externalFileStatusTable.get(key); - if (bytes == null) { - bytes = new byte[2]; - bytes[0] = 0; - bytes[1] = 0; - externalFileStatusTable.put(key, bytes); - } - return bytes; - } - - private static Map externalFileTable = new HashMap(); - - /** - * TODO: 準備中 - * - * @param key TODO: 準備中 - * @return TODO: 準備中 - */ - public static CobolFile getExternalFile(String key) { - return externalFileTable.get(key); - } - - /** - * TODO: 準備中 - * - * @param key TODO: 準備中 - * @param value TODO: 準備中 - * @return TODO: 準備中 - */ - public static CobolFile putExternalFile(String key, CobolFile value) { - return externalFileTable.put(key, value); - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.file; + +import java.io.IOException; +import java.nio.channels.ClosedChannelException; +import java.nio.channels.FileChannel; +import java.nio.channels.FileLock; +import java.nio.channels.NonWritableChannelException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import jp.osscons.opensourcecobol.libcobj.common.CobolModule; +import jp.osscons.opensourcecobol.libcobj.common.CobolUtil; +import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; +import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionId; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; + +/** INDEXED, RELATIVE, SEQUENTIAL, LINE SEQUENTIAL等のCOBOLの ファイルを実装するための基底クラス */ +public class CobolFile { + /** TODO: 準備中 */ + protected static final int COB_ORG_SEQUENTIAL = 0; + + /** TODO: 準備中 */ + protected static final int COB_ORG_LINE_SEQUENTIAL = 1; + + /** TODO: 準備中 */ + protected static final int COB_ORG_RELATIVE = 2; + + /** TODO: 準備中 */ + protected static final int COB_ORG_INDEXED = 3; + + /** TODO: 準備中 */ + protected static final int COB_ORG_SORT = 4; + + /** TODO: 準備中 */ + protected static final int COB_ORG_MAX = 5; + + /** TODO: 準備中 */ + protected static final int COB_ACCESS_SEQUENTIAL = 1; + + /** TODO: 準備中 */ + protected static final int COB_ACCESS_DYNAMIC = 2; + + /** TODO: 準備中 */ + protected static final int COB_ACCESS_RANDOM = 3; + + /** TODO: 準備中 */ + protected static final int COB_IO_OPEN = 0; + + /** TODO: 準備中 */ + protected static final int COB_IO_READ = 1; + + /** TODO: 準備中 */ + protected static final int COB_IO_WRITE = 2; + + /** TODO: 準備中 */ + protected static final int COB_IO_CLOSE = 3; + + /** TODO: 準備中 */ + protected static final int COB_IO_DELETE = 4; + + /** TODO: 準備中 */ + protected static final int COB_IO_REWRITE = 5; + + /** TODO: 準備中 */ + protected static final int COB_IO_START = 6; + + /** TODO: 準備中 */ + protected static final int COB_IO_COMMIT = 7; + + /** TODO: 準備中 */ + protected static final int COB_IO_ROLLBACK = 8; + + /** TODO: 準備中 */ + protected static final int COB_IO_UNLOCK = 9; + + /** TODO: 準備中 */ + protected static final int COB_IO_DELETE_FILE = 10; + + /** TODO: 準備中 */ + public static final int COB_OPEN_CLOSED = 0; + + /** TODO: 準備中 */ + public static final int COB_OPEN_INPUT = 1; + + /** TODO: 準備中 */ + public static final int COB_OPEN_OUTPUT = 2; + + /** TODO: 準備中 */ + public static final int COB_OPEN_I_O = 3; + + /** TODO: 準備中 */ + public static final int COB_OPEN_EXTEND = 4; + + /** TODO: 準備中 */ + public static final int COB_OPEN_LOCKED = 5; + + /** TODO: 準備中 */ + public static final int COB_CLOSE_NORMAL = 0; + + /** TODO: 準備中 */ + public static final int COB_CLOSE_LOCK = 1; + + /** TODO: 準備中 */ + public static final int COB_CLOSE_NO_REWIND = 2; + + /** TODO: 準備中 */ + public static final int COB_CLOSE_UNIT = 3; + + /** TODO: 準備中 */ + public static final int COB_CLOSE_UNIT_REMOVAL = 4; + + /** TODO: 準備中 */ + public static final int COB_WRITE_MASK = 0x0000ffff; + + /** TODO: 準備中 */ + public static final int COB_WRITE_LINES = 0x00010000; + + /** TODO: 準備中 */ + public static final int COB_WRITE_PAGE = 0x00020000; + + /** TODO: 準備中 */ + public static final int COB_WRITE_CHANNEL = 0x00040000; + + /** TODO: 準備中 */ + public static final int COB_WRITE_AFTER = 0x00100000; + + /** TODO: 準備中 */ + public static final int COB_WRITE_BEFORE = 0x00200000; + + /** TODO: 準備中 */ + public static final int COB_WRITE_EOP = 0x00400000; + + /** TODO: 準備中 */ + public static final int COB_WRITE_LOCK = 0x00800000; + + /** TODO: 準備中 */ + public static final int COB_READ_NEXT = 0x01; + + /** TODO: 準備中 */ + public static final int COB_READ_PREVIOUS = 0x2; + + /** TODO: 準備中 */ + public static final int COB_READ_FIRST = 0x04; + + /** TODO: 準備中 */ + public static final int COB_READ_LAST = 0x08; + + /** TODO: 準備中 */ + public static final int COB_READ_LOCK = 0x10; + + /** TODO: 準備中 */ + public static final int COB_READ_NO_LOCK = 0x20; + + /** TODO: 準備中 */ + public static final int COB_READ_KEPT_LOCK = 0x40; + + /** TODO: 準備中 */ + public static final int COB_READ_WAIT_LOCK = 0x80; + + /** TODO: 準備中 */ + public static final int COB_READ_IGNORE_LOCK = 0x100; + + /** TODO: 準備中 */ + protected static final String TIS_DEFINE_USERFH = "OC_USERFH"; + + /** TODO: 準備中 */ + protected static final String COB_IO_CREATES = "OC_IO_CREATES"; + + /** TODO: 準備中 */ + protected static final String COB_EXTEND_CREATES = "OC_EXTEND_CREATES"; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_00_SUCCESS = 0; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_02_SUCCESS_DUPLICATE = 2; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_04_SUCCESS_INCOMPLETE = 4; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_05_SUCCESS_OPTIONAL = 5; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_07_SUCCESS_NO_UNIT = 7; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_10_END_OF_FILE = 10; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_14_OUT_OF_KEY_RANGE = 14; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_21_KEY_INVALID = 21; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_22_KEY_EXISTS = 22; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_23_KEY_NOT_EXISTS = 23; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_30_PERMANENT_ERROR = 30; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_31_INCONSISTENT_FILENAME = 31; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_34_BOUNDARY_VIOLATION = 34; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_35_NOT_EXISTS = 35; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_37_PERMISSION_DENIED = 37; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_38_CLOSED_WITH_LOCK = 38; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_39_CONFLICT_ATTRIBUTE = 39; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_41_ALREADY_OPEN = 41; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_42_NOT_OPEN = 42; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_43_READ_NOT_DONE = 43; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_44_RECORD_OVERFLOW = 44; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_46_READ_ERROR = 46; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_47_INPUT_DENIED = 47; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_48_OUTPUT_DENIED = 48; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_49_I_O_DENIED = 49; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_51_RECORD_LOCKED = 51; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_52_EOP = 52; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_57_I_O_LINAGE = 57; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_61_FILE_SHARING = 61; + + /** TODO: 準備中 */ + protected static final int COB_STATUS_91_NOT_AVAILABLE = 91; + + /** + * File status 92: Version incompatibility. + * Indicates that the file operation failed due to a version mismatch between the file and the program. + */ + protected static final int COB_STATUS_92_VERSION_INCOMPATIBLE = 92; + + // ============================================== + // The following constants must not be equal + // to any of the above constants `COB_STATUS_*` + + /** TODO: 準備中 */ + protected static final int ENOENT = 1002; + + /** TODO: 準備中 */ + protected static final int EBADF = 1009; + + /** TODO: 準備中 */ + protected static final int EACCESS = 1013; + + /** TODO: 準備中 */ + protected static final int EISDIR = 1021; + + /** TODO: 準備中 */ + protected static final int EROFS = 1030; + + /** TODO: 準備中 */ + protected static final int EAGAIN = 1011; + + // ============================================== + + /** TODO: 準備中 */ + protected static final int COB_LINAGE_INVALID = 16384; + + /** TODO: 準備中 */ + protected static final int COB_NOT_CONFIGURED = 32768; + + /** TODO: 準備中 */ + public static final int COB_SELECT_FILE_STATUS = 0x01; + + /** TODO: 準備中 */ + public static final int COB_SELECT_EXTERNAL = 0x02; + + /** TODO: 準備中 */ + public static final int COB_SELECT_LINAGE = 0x04; + + /** TODO: 準備中 */ + public static final int COB_SELECT_SPLITKEY = 0x08; + + /** TODO: 準備中 */ + protected static final int FNSTATUSSIZE = 3; + + /** TODO: 準備中 */ + public static CobolFile errorFile; + + /** TODO: 準備中 */ + protected static int COB_SMALL_BUFF = 1024; + + /** TODO: 準備中 */ + protected static int COB_SMALL_MAX = COB_SMALL_BUFF - 1; + + /** TODO: 準備中 */ + protected static final int COB_LOCK_EXCLUSIVE = 1; + + /** TODO: 準備中 */ + protected static final int COB_LOCK_MANUAL = 2; + + /** TODO: 準備中 */ + protected static final int COB_LOCK_AUTOMATIC = 4; + + /** TODO: 準備中 */ + protected static final int COB_LOCK_MULTIPLE = 8; + + /** TODO: 準備中 */ + protected static final int COB_LOCK_MASK = 0x7; + + /** TODO: 準備中 */ + protected static String cob_file_path = null; + + /** TODO: 準備中 */ + protected static String cob_ls_nulls = null; + + /** TODO: 準備中 */ + protected static String cob_ls_fixed = null; + + /** TODO: 準備中 */ + protected static byte[] file_open_env = new byte[1024]; + + /** TODO: 準備中 */ + protected static String file_open_name; + + /** TODO: 準備中 */ + protected static byte[] file_open_buff = new byte[1024]; + + /** TODO: 準備中 */ + protected static final String[] prefix = {"DD_", "dd_", ""}; + + /** TODO: 準備中 */ + protected static final int NUM_PREFIX = prefix.length; + + /** TODO: 準備中 */ + protected static int eop_status = 0; + + /** TODO: 準備中 */ + protected static int cob_do_sync = 0; + + private static List file_cache = new ArrayList(); + + /** TODO: 準備中 */ + protected static int[] status_exception = { + 0, + CobolExceptionId.COB_EC_I_O_AT_END, + CobolExceptionId.COB_EC_I_O_INVALID_KEY, + CobolExceptionId.COB_EC_I_O_PERMANENT_ERROR, + CobolExceptionId.COB_EC_I_O_LOGIC_ERROR, + CobolExceptionId.COB_EC_I_O_RECORD_OPERATION, + CobolExceptionId.COB_EC_I_O_FILE_SHARING, + CobolExceptionId.COB_EC_I_O, + CobolExceptionId.COB_EC_I_O, + CobolExceptionId.COB_EC_I_O_IMP + }; + + /** TODO: 準備中 */ + public String select_name; + + /** TODO: 準備中 */ + public byte[] file_status; + + /** TODO: 準備中 */ + protected AbstractCobolField assign; + + /** TODO: 準備中 */ + public AbstractCobolField record; + + /** TODO: 準備中 */ + protected AbstractCobolField record_size; + + /** TODO: 準備中 */ + protected CobolFileKey[] keys; + + /** TODO: 準備中 */ + public FileIO file; + + /** TODO: 準備中 */ + protected CobolSort filex; + + /** TODO: 準備中 */ + protected IndexedFile filei; + + /** TODO: 準備中 */ + protected Linage linorkeyptr; + + /** TODO: 準備中 */ + protected CobolDataStorage sort_collating; + + /** TODO: 準備中 */ + protected Object extfh_ptr; + + /** TODO: 準備中 */ + protected int record_min; + + /** TODO: 準備中 */ + public int record_max; + + /** TODO: 準備中 */ + protected int nkeys; + + /** TODO: 準備中 */ + protected char organization; + + /** TODO: 準備中 */ + protected char access_mode; + + /** TODO: 準備中 */ + protected char lock_mode; + + /** TODO: 準備中 */ + protected char open_mode; + + /** TODO: 準備中 */ + protected boolean flag_optional; + + /** TODO: 準備中 */ + public char last_open_mode; + + /** TODO: 準備中 */ + protected char special; + + /** TODO: 準備中 */ + protected boolean flag_nonexistent; + + /** TODO: 準備中 */ + protected boolean flag_end_of_file; + + /** TODO: 準備中 */ + protected boolean flag_begin_of_file; + + /** TODO: 準備中 */ + protected char flag_first_read; + + /** TODO: 準備中 */ + protected boolean flag_read_done; + + /** TODO: 準備中 */ + public char flag_select_features; + + /** TODO: 準備中 */ + protected boolean flag_needs_nl; + + /** TODO: 準備中 */ + protected boolean flag_needs_top; + + /** TODO: 準備中 */ + protected char file_version; + + /** TODO: 準備中 */ + protected static String runtime_buffer; + + /** TODO: 準備中 */ + protected static String name; + + /** TODO: 準備中 */ + protected static byte[] status; + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public Linage getLinorkeyptr() { + return this.linorkeyptr; + } + + /** + * TODO: 準備中 + * + * @param ptr TODO: 準備中 + */ + public void setLinorkeyptr(Linage ptr) { + this.linorkeyptr = ptr; + } + + /** TODO: 準備中 */ + public CobolFile() {} + + /** + * TODO: 準備中 + * + * @param selectName TODO: 準備中 + * @param fileStatus TODO: 準備中 + * @param assign TODO: 準備中 + * @param record TODO: 準備中 + * @param recordSize TODO: 準備中 + * @param recordMin TODO: 準備中 + * @param recordMax TODO: 準備中 + * @param nkeys TODO: 準備中 + * @param keys TODO: 準備中 + * @param organization TODO: 準備中 + * @param accessMode TODO: 準備中 + * @param lockMode TODO: 準備中 + * @param openMode TODO: 準備中 + * @param flagOptional TODO: 準備中 + * @param lastOpenMode TODO: 準備中 + * @param special TODO: 準備中 + * @param flagNonexistent TODO: 準備中 + * @param flagEndOfFile TODO: 準備中 + * @param flagBeginOfFile TODO: 準備中 + * @param flagFirstRead TODO: 準備中 + * @param flagReadDone TODO: 準備中 + * @param flagSelectFeatures TODO: 準備中 + * @param flagNeedsNl TODO: 準備中 + * @param flagNeedsTop TODO: 準備中 + * @param fileVersion TODO: 準備中 + */ + public CobolFile( + String selectName, + byte[] fileStatus, + AbstractCobolField assign, + AbstractCobolField record, + AbstractCobolField recordSize, + int recordMin, + int recordMax, + int nkeys, + CobolFileKey[] keys, + char organization, + char accessMode, + char lockMode, + char openMode, + boolean flagOptional, + char lastOpenMode, + char special, + boolean flagNonexistent, + boolean flagEndOfFile, + boolean flagBeginOfFile, + char flagFirstRead, + boolean flagReadDone, + char flagSelectFeatures, + boolean flagNeedsNl, + boolean flagNeedsTop, + char fileVersion) { + + this.select_name = selectName; + this.file_status = fileStatus; + this.assign = assign; + this.record = record; + this.record_size = recordSize; + this.record_min = recordMin; + this.record_max = recordMax; + this.nkeys = nkeys; + this.keys = keys; + this.file = new FileIO(); + this.organization = organization; + this.access_mode = accessMode; + this.lock_mode = lockMode; + this.open_mode = openMode; + this.flag_optional = flagOptional; + this.special = special; + this.flag_nonexistent = flagNonexistent; + this.flag_end_of_file = flagEndOfFile; + this.flag_begin_of_file = flagBeginOfFile; + this.flag_first_read = flagFirstRead; + this.flag_read_done = flagReadDone; + this.flag_select_features = flagSelectFeatures; + this.flag_needs_nl = flagNeedsNl; + this.flag_needs_top = flagNeedsTop; + this.file_version = fileVersion; + } + + // libcob/fileio.cのsave_statusの実装 RETURN_STATUSマクロは実装できないため,本メソッドの呼び出し後の次の文はreturn;を書くこと. + /** + * TODO: 準備中 + * + * @param status TODO: 準備中 + * @param fnstatus TODO: 準備中 + */ + protected void saveStatus(int status, AbstractCobolField fnstatus) { + CobolFile.errorFile = this; + if (status == 0) { + this.file_status[0] = '0'; + this.file_status[1] = '0'; + if (fnstatus != null) { + fnstatus.getDataStorage().setByte(0, (byte) '0'); + fnstatus.getDataStorage().setByte(1, (byte) '0'); + } + CobolRuntimeException.code = 0; + return; + } + + if (status != COB_STATUS_52_EOP) { + CobolRuntimeException.setException(status_exception[status / 10]); + } + this.file_status[0] = (byte) (status / 10 + '0'); + this.file_status[1] = (byte) (status % 10 + '0'); + if (fnstatus != null) { + fnstatus.getDataStorage().setByte(0, this.file_status[0]); + fnstatus.getDataStorage().setByte(1, this.file_status[1]); + } + } + + // libcob/fileio.のcob_invoke_funの実装 + /** + * TODO: 準備中 + * + * @param operate TODO: 準備中 + * @param f TODO: 準備中 + * @param key TODO: 準備中 + * @param rec TODO: 準備中 + * @param fnstatus TODO: 準備中 + * @param openMode TODO: 準備中 + * @param startCond TODO: 準備中 + * @param readOpts TODO: 準備中 + * @return TODO: 準備中 + */ + public static int invokeFun( + int operate, + Object f, + AbstractCobolField key, + CobolDataStorage rec, + AbstractCobolField fnstatus, + String openMode, + String startCond, + String readOpts) { + return 0; + } + + // libcob/cob_cache_fileのj実装 + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + */ + protected static void cacheFile(CobolFile f) { + if (file_cache.contains(f)) { + return; + } + file_cache.add(f); + } + + // libcob/fileio.cのcob_file_linage_checkの実装 TODO 実装 + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + protected boolean file_linage_check() { + Linage lingptr = getLinorkeyptr(); + lingptr.setLinLines(lingptr.getLinage().getInt()); + + outer: + { + if (lingptr.getLinLines() < 1) { + break outer; + } + if (lingptr.getLatfoot() != null) { + lingptr.setLinFoot(lingptr.getLatfoot().getInt()); + if (lingptr.getLinFoot() < 1 || lingptr.getLinFoot() > lingptr.getLinLines()) { + break outer; + } + } else { + lingptr.setLinFoot(0); + } + if (lingptr.getLattop() != null) { + lingptr.setLinTop(lingptr.getLattop().getInt()); + if (lingptr.getLinTop() < 0) { + break outer; + } + } else { + lingptr.setLinTop(0); + } + if (lingptr.getLatbot() != null) { + lingptr.setLinBot(lingptr.getLatbot().getInt()); + if (lingptr.getLinBot() < 0) { + break outer; + } + } else { + lingptr.setLinBot(0); + } + return false; + } + + lingptr.getLinageCtr().setInt(0); + return true; + } + + // libcob/fileio.cのcob_linage_write_optの実装 TODO 実装 + /** + * TODO: 準備中 + * + * @param opt TODO: 準備中 + * @return TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + protected int linage_write_opt(int opt) throws CobolStopRunException { + int i, n; + Linage lingptr = this.getLinorkeyptr(); + + if ((opt & COB_WRITE_PAGE) != 0) { + i = lingptr.getLinageCtr().getInt(); + if (i == 0) { + return COB_STATUS_57_I_O_LINAGE; + } + n = lingptr.getLinLines(); + for (; i < n; ++i) { + this.file.putc((byte) '\n'); + } + for (i = 0; i < lingptr.getLinBot(); i++) { + this.file.putc((byte) '\n'); + } + if (this.file_linage_check()) { + return COB_STATUS_57_I_O_LINAGE; + } + for (i = 0; i < lingptr.getLinTop(); i++) { + this.file.putc((byte) '\n'); + } + lingptr.getLinageCtr().setInt(1); + } else if ((opt & COB_WRITE_LINES) != 0) { + n = lingptr.getLinageCtr().getInt(); + if (n == 0) { + return COB_STATUS_57_I_O_LINAGE; + } + lingptr.getLinageCtr().addInt(opt & COB_WRITE_MASK); + i = lingptr.getLinageCtr().getInt(); + if ((opt & COB_WRITE_EOP) != 0 && lingptr.getLinFoot() != 0) { + if (i >= lingptr.getLinFoot()) { + eop_status = 1; + } + } + if (i > lingptr.getLinLines()) { + if ((opt & COB_WRITE_EOP) != 0) { + eop_status = 1; + } + for (; n < lingptr.getLinLines(); n++) { + this.file.putc((byte) '\n'); + } + for (i = 0; i < lingptr.getLinBot(); i++) { + this.file.putc((byte) '\n'); + } + if (this.file_linage_check()) { + return COB_STATUS_57_I_O_LINAGE; + } + lingptr.getLinageCtr().setInt(1); + for (i = 0; i < lingptr.getLinTop(); i++) { + this.file.putc((byte) '\n'); + } + } else { + for (i = (opt & COB_WRITE_MASK) - 1; i > 0; i--) { + this.file.putc((byte) '\n'); + } + } + } + return 0; + } + + /** + * TODO: 準備中 + * + * @param name TODO: 準備中 + * @param jbuf TODO: 準備中 + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + protected byte[] cb_get_jisword_buff(byte[] name, byte[] jbuf, int n) { + int cs = 0; + int ce = name.length - 1; + int cp; + boolean flagQuoted = false; + int siz = 0; + byte[] rt = null; + int c; + int p = 0; + + if (name[cs] == '\'' && name[ce] == '\'') { + cs++; + --ce; + flagQuoted = true; + } + + if (ce - cs >= 5 + && !(name[cs] == '_' && name[cs + 1] == '_' && name[cs + 2] == '_') + && !(name[ce - 2] == '_' && name[ce - 1] == '_' && name[ce] == '_')) { + cs += 3; + ce -= 3; + if (!flagQuoted) { + siz = (ce - cs + 1) / 2 + 1; + } else { + siz = (ce - cs + 1) / 2 + 3; + } + if (jbuf != null) { + rt = new byte[siz]; + } else { + if (siz > n) { + c = siz - n; + siz -= c; + ce -= c * 2; + } + /* + * TODO fix + * for (int i = 0; i < n; ++i) { + * jbuf[i] = 0; + * } + */ + // TODO + rt = null; + } + if (flagQuoted && siz > 2) { + rt[0] = rt[siz - 2] = (byte) '\''; + p = 1; + } else { + p = 0; + } + for (c = 0, cp = cs; cp <= ce; cp++, p += (c == 0 ? 1 : 0)) { + if (name[cp] >= '0' && name[cp] <= '9') { + rt[p] |= (name[cp] - '0') << (c << 2); + } else if (name[cp] >= 'A' && name[cp] <= 'F') { + rt[p] |= (name[cp] - 'A' + 10) << (c << 2); + } else { + name[p] = '?'; + cp += c; + c = 0; + } + } + } else { + if (jbuf != null) { + rt = name.clone(); + } else { + /* + * TODO fix + * for (int i = 0; i < n; ++i) { + * jbuf[i] = 0; + * } + * for (int i = 0; i < n - 1; ++i) { + * jbuf[i] = name[i]; + * } + */ + // TODO fix + rt = null; + } + } + return rt; + } + + // assert 0 <= openMode < 10 + private static String openModeToString(int openMode) { + StringBuilder sb = new StringBuilder(); + return sb.append("0").append(openMode).toString(); + } + + private static String readOptsToString(int readOpts) { + StringBuilder sb = new StringBuilder(); + if (readOpts < 10) { + sb.append("0"); + } + return sb.append(readOpts).toString(); + } + + private static String concatString(String... strs) { + StringBuilder sb = new StringBuilder(); + for (String s : strs) { + sb.append(s); + } + return sb.toString(); + } + + /** + * This method is mainly for unlocking the indexed files. + * + * @return true if post-processing is successful, false otherwise. + */ + protected boolean postProcess() { + return true; + } + + private void runPostProcess(AbstractCobolField fnstatus) { + postProcess(); + // TODO: Implement error handling + // boolean postProcessSucceeded = postProcess(); + // if(!postProcessSucceeded) { + // this.saveStatus(COB_STATUS_30_PERMANENT_ERROR, fnstatus); + // } + } + + /** + * TODO: 準備中 + * + * @param mode TODO: 準備中 + * @param sharing TODO: 準備中 + * @param fnstatus TODO: 準備中 + */ + public void open(int mode, int sharing, AbstractCobolField fnstatus) { + String openMode = openModeToString(mode); + if (invokeFun(COB_IO_OPEN, this, null, null, fnstatus, openMode, null, null) != 0) { + this.last_open_mode = (char) Integer.parseInt(openMode); + return; + } + this.last_open_mode = (char) Integer.parseInt(openMode); + + /* file was previously closed with lock */ + if (this.open_mode == COB_OPEN_LOCKED) { + saveStatus(COB_STATUS_38_CLOSED_WITH_LOCK, fnstatus); + return; + } + + /* file is already open */ + if (((int) this.open_mode) != COB_OPEN_CLOSED) { + saveStatus(COB_STATUS_41_ALREADY_OPEN, fnstatus); + return; + } + + this.last_open_mode = (char) mode; + this.flag_nonexistent = false; + this.flag_end_of_file = false; + this.flag_begin_of_file = false; + this.flag_first_read = 2; + + if (this.special != 0) { + if (this.special == 1) { + if (mode != COB_OPEN_INPUT) { + saveStatus(COB_STATUS_30_PERMANENT_ERROR, fnstatus); + return; + } + this.file.setIn(System.in); + this.open_mode = (char) mode; + this.saveStatus(COB_STATUS_00_SUCCESS, fnstatus); + return; + } else { + if (mode != COB_OPEN_OUTPUT) { + this.saveStatus(COB_STATUS_30_PERMANENT_ERROR, fnstatus); + return; + } + this.file.setOut(System.out); + this.open_mode = (char) mode; + saveStatus(COB_STATUS_00_SUCCESS, fnstatus); + return; + } + } + + /* obtain the file name */ + if (this.assign == null) { + file_open_name = this.select_name; + } else { + file_open_name = this.assign.fieldToString(); + } + + byte[] src; + byte[] dst; + boolean simple; + if (CobolModule.getCurrentModule().flag_filename_mapping != 0) { + src = file_open_name.getBytes(AbstractCobolField.charSetSJIS); + dst = file_open_buff; + simple = true; + int srcI = 0; + int dstI = 0; + while (srcI < src.length) { + char c = (char) src[srcI]; + if (!Character.isLetterOrDigit(c) && c != '_' && c != '-') { + simple = false; + } + if (c == '$') { + int i; + for (i = 1; srcI + i < src.length; i++) { + char d = (char) src[srcI + i]; + if (!Character.isLetterOrDigit(d) && d != '_' && c != '-') { + break; + } + } + for (int j = 0; j < i - 1; ++j) { + file_open_env[j] = src[srcI + 1 + j]; + } + file_open_env[i - 1] = 0; + String p = + CobolUtil.getEnv( + new String( + Arrays.copyOfRange(file_open_env, 0, i - 1), + AbstractCobolField.charSetSJIS)); + if (p != null) { + byte[] pbytes = p.getBytes(AbstractCobolField.charSetSJIS); + for (int j = 0; j < pbytes.length; ++j) { + dst[dstI + j] = pbytes[j]; + } + dstI += pbytes.length; + } + srcI += i; + } else { + dst[dstI++] = src[srcI++]; + } + } + + file_open_name = + new String(Arrays.copyOfRange(dst, 0, dstI), AbstractCobolField.charSetSJIS); + + byte[] fileOpenNameBytes = file_open_name.getBytes(AbstractCobolField.charSetSJIS); + cb_get_jisword_buff(file_open_buff, fileOpenNameBytes, COB_SMALL_BUFF); + + if (simple) { + int i; + for (i = 0; i < NUM_PREFIX; i++) { + byte[] fileOpenBuff = + concatString(prefix[i], file_open_name) + .getBytes(AbstractCobolField.charSetSJIS); + String p = + CobolUtil.getEnv( + new String(fileOpenBuff, AbstractCobolField.charSetSJIS)); + if (p != null) { + fileOpenNameBytes = p.getBytes(AbstractCobolField.charSetSJIS); + break; + } + } + + if (i == NUM_PREFIX && cob_file_path != null) { + byte[] fileOpenBuff = + concatString(cob_file_path, "/", file_open_name) + .getBytes(AbstractCobolField.charSetSJIS); + fileOpenNameBytes = fileOpenBuff; + } + } + + file_open_name = new String(fileOpenNameBytes, AbstractCobolField.charSetSJIS); + } + + boolean wasNotExist = false; + if (this.organization == COB_ORG_INDEXED) { + if (!Files.exists(Paths.get(file_open_name))) { + wasNotExist = true; + if (mode != COB_OPEN_OUTPUT + && !this.flag_optional + && (mode != COB_OPEN_I_O || !"yes".equals(CobolUtil.getEnv(COB_IO_CREATES))) + && (mode != COB_OPEN_EXTEND + || !"yes".equals(CobolUtil.getEnv(COB_EXTEND_CREATES)))) { + saveStatus(COB_STATUS_35_NOT_EXISTS, fnstatus); + return; + } + } + } else if (Files.notExists(Paths.get(file_open_name))) { + wasNotExist = true; + if (mode != COB_OPEN_OUTPUT + && !this.flag_optional + && (mode != COB_OPEN_I_O || CobolUtil.checkEnv(COB_IO_CREATES, "yes") == 0) + && (mode != COB_OPEN_EXTEND + || CobolUtil.checkEnv(COB_EXTEND_CREATES, "yes") == 0)) { + saveStatus(COB_STATUS_35_NOT_EXISTS, fnstatus); + return; + } + } + cacheFile(this); + + try { + switch (this.open_(file_open_name, mode, sharing)) { + case 0: + this.open_mode = (char) mode; + if (this.flag_optional && wasNotExist) { + saveStatus(COB_STATUS_05_SUCCESS_OPTIONAL, fnstatus); + return; + } else { + saveStatus(COB_STATUS_00_SUCCESS, fnstatus); + return; + } + case ENOENT: + if (mode == COB_OPEN_EXTEND || mode == COB_OPEN_OUTPUT) { + saveStatus(COB_STATUS_30_PERMANENT_ERROR, fnstatus); + return; + } + if (this.flag_optional) { + this.open_mode = (char) mode; + this.flag_nonexistent = true; + this.flag_end_of_file = true; + this.flag_begin_of_file = true; + saveStatus(COB_STATUS_05_SUCCESS_OPTIONAL, fnstatus); + return; + } else { + saveStatus(COB_STATUS_35_NOT_EXISTS, fnstatus); + return; + } + case EACCESS: + case EISDIR: + case EROFS: + saveStatus(COB_STATUS_37_PERMISSION_DENIED, fnstatus); + return; + case COB_STATUS_61_FILE_SHARING: + saveStatus(COB_STATUS_61_FILE_SHARING, fnstatus); + return; + case COB_STATUS_91_NOT_AVAILABLE: + saveStatus(COB_STATUS_91_NOT_AVAILABLE, fnstatus); + return; + case COB_STATUS_92_VERSION_INCOMPATIBLE: + saveStatus(COB_STATUS_92_VERSION_INCOMPATIBLE, fnstatus); + return; + case COB_LINAGE_INVALID: + saveStatus(COB_STATUS_57_I_O_LINAGE, fnstatus); + return; + default: + saveStatus(COB_STATUS_30_PERMANENT_ERROR, fnstatus); + return; + } + } catch (IOException e) { + saveStatus(COB_STATUS_30_PERMANENT_ERROR, fnstatus); + return; + } + } + + // protected long start; + // protected long end; + + /** + * TODO: 準備中 + * + * @param mode TODO: 準備中 + * @param sharing TODO: 準備中 + * @param fnstatus TODO: 準備中 + */ + public void openEx(int mode, int sharing, AbstractCobolField fnstatus) { + // this.open_("", mode, sharing); + } + + /** + * TODO: 準備中 + * + * @param filename TODO: 準備中 + * @param mode TODO: 準備中 + * @param sharing TODO: 準備中 + * @return TODO: 準備中 + * @throws IOException TODO: 準備中 + */ + public int open_(String filename, int mode, int sharing) throws IOException { + FileChannel fp = null; + try { + switch (mode) { + case COB_OPEN_INPUT: + fp = FileChannel.open(Paths.get(filename), StandardOpenOption.READ); + break; + case COB_OPEN_OUTPUT: + fp = + FileChannel.open( + Paths.get(filename), + StandardOpenOption.WRITE, + StandardOpenOption.CREATE, + StandardOpenOption.TRUNCATE_EXISTING); + break; + case COB_OPEN_I_O: + fp = + FileChannel.open( + Paths.get(filename), + StandardOpenOption.READ, + StandardOpenOption.WRITE, + StandardOpenOption.CREATE); + break; + case COB_OPEN_EXTEND: + fp = + FileChannel.open( + Paths.get(filename), + StandardOpenOption.APPEND, + StandardOpenOption.CREATE); + break; + default: + break; + } + } catch (IOException e) { + if (Files.notExists(Paths.get(filename))) { + return ENOENT; + } else { + return EACCESS; + } + } + + FileLock fl = null; + if (!filename.startsWith("/dev/")) { + try { + boolean isSharedLock; + if (sharing != 0 || mode == COB_OPEN_OUTPUT) { + isSharedLock = false; + } else { + isSharedLock = true; + } + fl = fp.tryLock(0L, Long.MAX_VALUE, isSharedLock); + } catch (NonWritableChannelException e) { + fp.close(); + return EBADF; + } catch (ClosedChannelException e) { + fp.close(); + return COB_STATUS_61_FILE_SHARING; + } + + this.file.setChannel(fp, fl); + if (fl == null || !fl.isValid()) { + fp.close(); + return COB_STATUS_61_FILE_SHARING; + } + } + + this.file.setChannel(fp, fl); + if ((this.flag_select_features & COB_SELECT_LINAGE) != 0) { + if (this.file_linage_check()) { + return COB_LINAGE_INVALID; + } + this.flag_needs_top = true; + Linage lingptr = this.getLinorkeyptr(); + lingptr.getLinageCtr().setInt(1); + } + if ((this.organization == COB_ORG_SEQUENTIAL + || this.organization == COB_ORG_LINE_SEQUENTIAL) + && (mode == COB_OPEN_OUTPUT || mode == COB_OPEN_EXTEND) + && CobolUtil.fileSeqWriteBufferSize > 0) { + this.file.prepareWriteBuffer(CobolUtil.fileSeqWriteBufferSize * this.record_max); + } + return 0; + } + + /** + * TODO: 準備中 + * + * @param opt TODO: 準備中 + * @param fnstatus TODO: 準備中 + */ + public void close(int opt, AbstractCobolField fnstatus) { + String openMode = openModeToString(this.last_open_mode); + if (invokeFun(COB_IO_CLOSE, this, null, null, fnstatus, openMode, null, null) != 0) { + this.last_open_mode = (char) Integer.parseInt(openMode); + return; + } + + this.flag_read_done = false; + if (this.special != 0) { + this.open_mode = COB_OPEN_CLOSED; + saveStatus(COB_STATUS_00_SUCCESS, fnstatus); + return; + } + if (this.open_mode == COB_OPEN_CLOSED) { + saveStatus(COB_STATUS_42_NOT_OPEN, fnstatus); + return; + } + + int ret; + if (this.flag_nonexistent) { + ret = COB_STATUS_00_SUCCESS; + } else { + ret = this.close_(opt); + } + + if (ret == COB_STATUS_00_SUCCESS) { + switch (opt) { + case COB_CLOSE_LOCK: + this.open_mode = COB_OPEN_LOCKED; + break; + default: + this.open_mode = COB_OPEN_CLOSED; + break; + } + } + saveStatus(ret, fnstatus); + } + + // public void closeEx(int opt, AbstractCobolField fnstatus) { + // this.close_(opt); + // } + + /** + * TODO: 準備中 + * + * @param opt TODO: 準備中 + * @return TODO: 準備中 + */ + public int close_(int opt) { + switch (opt) { + case COB_CLOSE_NORMAL: + case COB_CLOSE_LOCK: + case COB_CLOSE_NO_REWIND: + if (this.organization == COB_ORG_LINE_SEQUENTIAL) { + if (this.flag_needs_nl + && ((this.flag_select_features & COB_SELECT_LINAGE) == 0)) { + this.flag_needs_nl = false; + this.file.putc((byte) '\n'); + } + } + + this.file.releaseLock(); + this.file.close(); + + if (opt == COB_CLOSE_NO_REWIND) { + this.open_mode = COB_OPEN_CLOSED; + return COB_STATUS_07_SUCCESS_NO_UNIT; + } + return COB_STATUS_00_SUCCESS; + default: + this.file.flush(); + return COB_STATUS_07_SUCCESS_NO_UNIT; + } + } + + /** + * TODO: 準備中 + * + * @param cond TODO: 準備中 + * @param key TODO: 準備中 + * @param fnstatus TODO: 準備中 + */ + public void start(int cond, AbstractCobolField key, AbstractCobolField fnstatus) { + String openMode = openModeToString(this.last_open_mode); + String startCond = String.format("%01d", cond); + if (invokeFun(COB_IO_START, this, null, null, fnstatus, openMode, startCond, null) != 0) { + return; + } + + this.flag_read_done = false; + this.flag_first_read = 0; + + if (this.flag_nonexistent) { + saveStatus(COB_STATUS_23_KEY_NOT_EXISTS, fnstatus); + return; + } + + if (this.open_mode == COB_OPEN_CLOSED + || this.open_mode == COB_OPEN_OUTPUT + || this.open_mode == COB_OPEN_EXTEND + || this.access_mode == COB_ACCESS_RANDOM) { + saveStatus(COB_STATUS_47_INPUT_DENIED, fnstatus); + return; + } + + int ret = this.start_(cond, key); + if (ret == COB_STATUS_00_SUCCESS) { + this.flag_end_of_file = false; + this.flag_begin_of_file = false; + this.flag_first_read = 1; + } + + saveStatus(ret, fnstatus); + } + + /** + * TODO: 準備中 + * + * @param cond TODO: 準備中 + * @param key TODO: 準備中 + * @param fnstatus TODO: 準備中 + */ + public void startEx(int cond, AbstractCobolField key, AbstractCobolField fnstatus) { + this.start_(cond, key); + } + + /** + * TODO: 準備中 + * + * @param cond TODO: 準備中 + * @param key TODO: 準備中 + * @return TODO: 準備中 + */ + public int start_(int cond, AbstractCobolField key) { + System.out.println("super.start"); + return 0; + } + + /** + * TODO: 準備中 + * + * @param key TODO: 準備中 + * @param fnstatus TODO: 準備中 + * @param readOpts TODO: 準備中 + */ + public void read(AbstractCobolField key, AbstractCobolField fnstatus, int readOpts) { + byte[] sbuff = new byte[3]; + String openMode = openModeToString(this.last_open_mode); + String readOptStr = readOptsToString(readOpts); + if (invokeFun(COB_IO_READ, this, key, null, fnstatus, openMode, null, readOptStr) != 0) { + for (int i = 0; i < 3; ++i) { + sbuff[i] = 0; + } + + if (fnstatus == null) { + return; + } + + for (int i = 0; i < 2; ++i) { + sbuff[i] = fnstatus.getDataStorage().getByte(i); + } + int status = Integer.parseInt(new String(sbuff, AbstractCobolField.charSetSJIS)); + saveStatus(status, fnstatus); + return; + } + + this.flag_read_done = false; + if (this.flag_nonexistent) { + if (this.flag_first_read == 0) { + saveStatus(COB_STATUS_23_KEY_NOT_EXISTS, fnstatus); + runPostProcess(fnstatus); + return; + } + this.flag_first_read = 0; + saveStatus(COB_STATUS_10_END_OF_FILE, fnstatus); + runPostProcess(fnstatus); + return; + } + + /* sequential read at the end of file is an error */ + if (key == null) { + if (this.flag_end_of_file && (readOpts & COB_READ_PREVIOUS) == 0) { + saveStatus(COB_STATUS_46_READ_ERROR, fnstatus); + runPostProcess(fnstatus); + return; + } + if (this.flag_begin_of_file && (readOpts & COB_READ_PREVIOUS) != 0) { + saveStatus(COB_STATUS_46_READ_ERROR, fnstatus); + runPostProcess(fnstatus); + return; + } + } + + if (this.open_mode == COB_OPEN_CLOSED + || this.open_mode == COB_OPEN_OUTPUT + || this.open_mode == COB_OPEN_EXTEND) { + saveStatus(COB_STATUS_47_INPUT_DENIED, fnstatus); + runPostProcess(fnstatus); + return; + } + + if (this.organization == COB_ORG_INDEXED) { + if (this.open_mode != COB_OPEN_I_O || (this.lock_mode & COB_LOCK_EXCLUSIVE) != 0) { + readOpts &= ~COB_READ_LOCK; + } else if ((this.lock_mode & COB_LOCK_AUTOMATIC) != 0 + && (readOpts & COB_READ_NO_LOCK) == 0) { + readOpts |= COB_READ_LOCK; + } + } else { + readOpts &= ~COB_READ_LOCK; + } + + int ret; + if (key != null) { + ret = this.read_(key, readOpts); + } else { + ret = this.readNext(readOpts); + } + + switch (ret) { + case COB_STATUS_00_SUCCESS: + this.flag_first_read = 0; + this.flag_read_done = true; + this.flag_end_of_file = false; + this.flag_begin_of_file = false; + if (this.record_size != null && this.organization != COB_ORG_LINE_SEQUENTIAL) { + this.record_size.setInt(record.getSize()); + } + break; + case COB_STATUS_10_END_OF_FILE: + if ((readOpts & COB_READ_PREVIOUS) != 0) { + this.flag_begin_of_file = true; + } else { + this.flag_end_of_file = true; + } + break; + default: + break; + } + + saveStatus(ret, fnstatus); + } + + /** + * TODO: 準備中 + * + * @param key TODO: 準備中 + * @param fnstatus TODO: 準備中 + * @param readOpts TODO: 準備中 + */ + public void read(int key, AbstractCobolField fnstatus, int readOpts) { + this.read(null, fnstatus, readOpts); + } + + /** + * TODO: 準備中 + * + * @param key TODO: 準備中 + * @param fnstatus TODO: 準備中 + * @param readOpts TODO: 準備中 + */ + public void readEx(AbstractCobolField key, AbstractCobolField fnstatus, int readOpts) { + this.read_(key, readOpts); + } + + /** + * TODO: 準備中 + * + * @param key TODO: 準備中 + * @param readOpts TODO: 準備中 + * @return TODO: 準備中 + */ + public int read_(AbstractCobolField key, int readOpts) { + System.out.println("super.read"); + return 0; + } + + /** + * TODO: 準備中 + * + * @param readOpts TODO: 準備中 + * @return TODO: 準備中 + */ + public int readNext(int readOpts) { + System.out.println("super.readNext"); + return 0; + } + + /** + * TODO: 準備中 + * + * @param rec TODO: 準備中 + * @param opt TODO: 準備中 + * @param fnstatus TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public void write(AbstractCobolField rec, int opt, AbstractCobolField fnstatus) + throws CobolStopRunException { + if (this.access_mode == COB_ACCESS_SEQUENTIAL + && this.last_open_mode == COB_OPEN_I_O + && CobolUtil.cob_io_rewwrite_assumed()) { + this.rewrite(rec, opt, fnstatus); + return; + } + + String openMode = openModeToString(this.last_open_mode); + if (invokeFun( + COB_IO_WRITE, + this, + null, + rec.getDataStorage(), + fnstatus, + openMode, + null, + null) + != 0) { + return; + } + + this.flag_read_done = false; + if (this.access_mode == COB_ACCESS_SEQUENTIAL) { + if (this.open_mode == COB_OPEN_CLOSED + || this.open_mode == COB_OPEN_INPUT + || this.open_mode == COB_OPEN_I_O) { + saveStatus(COB_STATUS_48_OUTPUT_DENIED, fnstatus); + runPostProcess(fnstatus); + return; + } + } else { + if (this.open_mode == COB_OPEN_CLOSED + || this.open_mode == COB_OPEN_INPUT + || this.open_mode == COB_OPEN_EXTEND) { + saveStatus(COB_STATUS_48_OUTPUT_DENIED, fnstatus); + runPostProcess(fnstatus); + return; + } + } + + int tmpsize = this.record.getSize(); + if (this.record_size != null) { + this.record.setSize(this.record_size.getInt()); + } else { + this.record.setSize(rec.getSize()); + } + + if (this.record.getSize() < this.record_min || this.record_max < this.record.getSize()) { + saveStatus(COB_STATUS_44_RECORD_OVERFLOW, fnstatus); + runPostProcess(fnstatus); + return; + } + + int ret = this.write_(opt); + + if (cob_do_sync != 0 && ret == 0) { + cob_sync(this, cob_do_sync); + } + + this.record.setSize(tmpsize); + saveStatus(ret, fnstatus); + } + + /** + * TODO: 準備中 + * + * @param rec TODO: 準備中 + * @param opt TODO: 準備中 + * @param fnstatus TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public void writeEx(AbstractCobolField rec, int opt, AbstractCobolField fnstatus) + throws CobolStopRunException { + this.write_(opt); + } + + /** + * TODO: 準備中 + * + * @param opt TODO: 準備中 + * @return TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public int write_(int opt) throws CobolStopRunException { + System.out.println("super.write"); + return 0; + } + + // libcob/fileio.cのcob_file_write_optの実装 + /** + * TODO: 準備中 + * + * @param opt TODO: 準備中 + * @return TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + protected int file_write_opt(int opt) throws CobolStopRunException { + if ((this.flag_select_features & COB_SELECT_LINAGE) != 0) { + return linage_write_opt(opt); + } + if ((opt & COB_WRITE_LINES) != 0) { + for (int i = opt & COB_WRITE_MASK; i > 0; i--) { + this.file.putc((byte) '\n'); + } + } else if ((opt & COB_WRITE_PAGE) != 0) { + this.file.putc((byte) '\f'); + } + return 0; + } + + /** + * TODO: 準備中 + * + * @param rec TODO: 準備中 + * @param opt TODO: 準備中 + * @param fnstatus TODO: 準備中 + */ + public void rewrite(AbstractCobolField rec, int opt, AbstractCobolField fnstatus) { + String openMode = openModeToString(this.last_open_mode); + if (invokeFun(COB_IO_REWRITE, this, null, null, fnstatus, openMode, null, null) != 0) { + this.last_open_mode = (char) Integer.parseInt(openMode); + return; + } + + boolean readDone = this.flag_read_done; + this.flag_read_done = false; + + if (this.open_mode == COB_OPEN_CLOSED || this.open_mode != COB_OPEN_I_O) { + saveStatus(COB_STATUS_49_I_O_DENIED, fnstatus); + runPostProcess(fnstatus); + return; + } + if (this.access_mode == COB_ACCESS_SEQUENTIAL && !readDone) { + saveStatus(COB_STATUS_43_READ_NOT_DONE, fnstatus); + runPostProcess(fnstatus); + return; + } + if (this.organization == COB_ORG_SEQUENTIAL) { + if (this.record.getSize() != rec.getSize()) { + saveStatus(COB_STATUS_44_RECORD_OVERFLOW, fnstatus); + runPostProcess(fnstatus); + return; + } + if (this.record_size != null) { + if (this.record.getSize() != this.record_size.getInt()) { + saveStatus(COB_STATUS_44_RECORD_OVERFLOW, fnstatus); + runPostProcess(fnstatus); + return; + } + } + } + int ret = this.rewrite_(opt); + if (cob_do_sync != 0 && ret == 0) { + cob_sync(this, cob_do_sync); + } + + saveStatus(ret, fnstatus); + } + + /** + * TODO: 準備中 + * + * @param rec TODO: 準備中 + * @param opt TODO: 準備中 + * @param fnstatus TODO: 準備中 + */ + public void rewriteEx(AbstractCobolField rec, int opt, AbstractCobolField fnstatus) { + this.rewrite_(opt); + } + + /** + * TODO: 準備中 + * + * @param opt TODO: 準備中 + * @return TODO: 準備中 + */ + public int rewrite_(int opt) { + System.out.println("super.rewrite"); + return 0; + } + + /** + * TODO: 準備中 + * + * @param fnstatus TODO: 準備中 + */ + public void delete(AbstractCobolField fnstatus) { + String openMode = openModeToString(this.last_open_mode); + if (invokeFun(COB_IO_DELETE, this, null, null, fnstatus, openMode, null, null) != 0) { + return; + } + + boolean readDone = this.flag_read_done; + this.flag_read_done = false; + + if (this.open_mode == COB_OPEN_CLOSED || this.open_mode != COB_OPEN_I_O) { + saveStatus(COB_STATUS_49_I_O_DENIED, fnstatus); + runPostProcess(fnstatus); + return; + } + + if (this.access_mode == COB_ACCESS_SEQUENTIAL && !readDone) { + saveStatus(COB_STATUS_43_READ_NOT_DONE, fnstatus); + runPostProcess(fnstatus); + return; + } + + int ret = this.delete_(); + + if (cob_do_sync != 0 && ret == 0) { + cob_sync(this, cob_do_sync); + } + saveStatus(ret, fnstatus); + } + + /** + * TODO: 準備中 + * + * @param fnstatus TODO: 準備中 + */ + public void deleteEx(AbstractCobolField fnstatus) { + this.delete_(); + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public int delete_() { + System.out.println("super.delete"); + return 0; + } + + /** + * TODO: 準備中 + * + * @param fnstatus TODO: 準備中 + */ + public void unlock(AbstractCobolField fnstatus) { + String openMode = openModeToString(this.last_open_mode); + if (invokeFun(COB_IO_UNLOCK, this, null, null, fnstatus, openMode, null, null) != 0) { + return; + } + this.unlock_(); + saveStatus(COB_STATUS_00_SUCCESS, fnstatus); + } + + /** TODO: 準備中 */ + public void unlock_() { + if (this.open_mode != COB_OPEN_CLOSED && this.open_mode != COB_OPEN_LOCKED) { + this.file.flush(); + } + } + + /** TODO: 準備中 */ + public static void commit() { + if (invokeFun(COB_IO_COMMIT, null, null, null, null, null, null, null) != 0) { + return; + } + for (CobolFile l : file_cache) { + l.unlock_(); + } + } + + /** TODO: 準備中 */ + public static void rollback() { + if (invokeFun(COB_IO_ROLLBACK, null, null, null, null, null, null, null) != 0) { + return; + } + for (CobolFile l : file_cache) { + l.unlock_(); + } + } + + /// libcob/fileio.cのcob_exit_fileioの実装 TODO 一部だけ実装したため残りを実装する + /** TODO: 準備中 */ + public static void exitFileIO() { + for (CobolFile f : file_cache) { + if (f.open_mode != COB_OPEN_CLOSED && f.open_mode != COB_OPEN_LOCKED) { + String filename = f.assign.fieldToString(); + System.err.print( + String.format( + "WARNING - Implicit CLOSE of %s (\"%s\") %c", + f.select_name, filename, '\n')); + } + } + } + + // libcob/fileio.cのcob_syncの実装 + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + * @param mode TODO: 準備中 + */ + protected void cob_sync(CobolFile f, int mode) { + // TODO + // INDEXEDファイル実装時にやる + // if (f.organization == COB_ORG_INDEXED) { + // } + if (f.organization != COB_ORG_SORT) { + this.file.flush(); + if (mode == 2) { + this.file.flush(); + } + } + } + + // libcob/fileio.cのcob_init_fileioの実装 + /** TODO: 準備中 */ + public static void cob_init_fileio() { + String s = CobolUtil.getEnv("COB_SYNC"); + if (s != null) { + if (s.charAt(0) == 'Y' || s.charAt(0) == 'y') { + cob_do_sync = 1; + } + if (s.charAt(0) == 'P' || s.charAt(0) == 'p') { + cob_do_sync = 2; + } + } + + cob_file_path = CobolUtil.getEnv("COB_FILE_PATH"); + if (cob_file_path != null) { + if (cob_file_path.charAt(0) == '\0' || cob_file_path.charAt(0) == ' ') { + cob_file_path = null; + } + } + + cob_ls_nulls = CobolUtil.getEnv("COB_LS_NULLS"); + cob_ls_fixed = CobolUtil.getEnv("COB_LS_FIXED"); + + file_open_env = new byte[COB_SMALL_BUFF]; + // file_open_name = new byte[COB_SMALL_BUFF]; + file_open_buff = new byte[COB_SMALL_BUFF]; + } + + /** TODO: 準備中 */ + public static void defaultErrorHandle() { + byte[] fileStatus = CobolFile.errorFile.file_status; + int status = (fileStatus[0] - '0') * 10 + (fileStatus[1] - '0'); + String msg; + switch (status) { + case COB_STATUS_10_END_OF_FILE: + msg = "End of file"; + break; + case COB_STATUS_14_OUT_OF_KEY_RANGE: + msg = "Key out of range"; + break; + case COB_STATUS_21_KEY_INVALID: + msg = "Key order not ascending"; + break; + case COB_STATUS_22_KEY_EXISTS: + msg = "Record key already exists"; + break; + case COB_STATUS_23_KEY_NOT_EXISTS: + msg = "Record key does not exist"; + break; + case COB_STATUS_30_PERMANENT_ERROR: + msg = "Permanent file error"; + break; + case COB_STATUS_35_NOT_EXISTS: + msg = "File does not exist"; + break; + case COB_STATUS_37_PERMISSION_DENIED: + msg = "Permission denied"; + break; + case COB_STATUS_41_ALREADY_OPEN: + msg = "File already open"; + break; + case COB_STATUS_42_NOT_OPEN: + msg = "File not open"; + break; + case COB_STATUS_43_READ_NOT_DONE: + msg = "READ must be executed first"; + break; + case COB_STATUS_44_RECORD_OVERFLOW: + msg = "Record overflow"; + break; + case COB_STATUS_46_READ_ERROR: + msg = "Failed to read"; + break; + case COB_STATUS_47_INPUT_DENIED: + msg = "READ/START not allowed"; + break; + case COB_STATUS_48_OUTPUT_DENIED: + msg = "WRITE not allowed"; + break; + case COB_STATUS_49_I_O_DENIED: + msg = "DELETE/REWRITE not allowed"; + break; + case COB_STATUS_51_RECORD_LOCKED: + msg = "Record locked by another file connector"; + break; + case COB_STATUS_52_EOP: + msg = "A page overflow condition occurred"; + break; + case COB_STATUS_57_I_O_LINAGE: + msg = "LINAGE values invalid"; + break; + case COB_STATUS_61_FILE_SHARING: + msg = "File sharing conflict"; + break; + case COB_STATUS_91_NOT_AVAILABLE: + msg = "Runtime library is not configured for this operation"; + break; + default: + msg = "Unknown file error"; + break; + } + String filename = CobolFile.errorFile.assign.fieldToString(); + CobolUtil.runtimeError( + String.format("%s (STATUS = %02d) File : '%s'", msg, status, filename)); + } + + /** + * TODO: 準備中 + * + * @param fnstatus TODO: 準備中 + */ + public void cob_delete_file(AbstractCobolField fnstatus) { + String openMode = openModeToString(this.last_open_mode); + if (invokeFun(COB_IO_DELETE_FILE, this, null, null, fnstatus, openMode, null, null) != 0) { + return; + } + + if (this.open_mode == COB_OPEN_LOCKED) { + saveStatus(COB_STATUS_38_CLOSED_WITH_LOCK, fnstatus); + return; + } + + /* file is already open */ + if (this.open_mode != COB_OPEN_CLOSED) { + saveStatus(COB_STATUS_41_ALREADY_OPEN, fnstatus); + return; + } + + if (this.special != 0) { + saveStatus(COB_STATUS_30_PERMANENT_ERROR, fnstatus); + return; + } + + if (this.assign == null) { + file_open_name = this.select_name; + } else { + file_open_name = this.assign.fieldToString(); + } + + byte[] src; + byte[] dst; + boolean simple; + if (CobolModule.getCurrentModule().flag_filename_mapping != 0) { + src = file_open_name.getBytes(AbstractCobolField.charSetSJIS); + dst = file_open_buff; + simple = true; + int srcI = 0; + int dstI = 0; + while (srcI < src.length) { + char c = (char) src[srcI]; + if (!Character.isLetterOrDigit(c) && c != '_' && c != '-') { + simple = false; + } + if (c == '$') { + int i; + for (i = 1; srcI + i < src.length; i++) { + char d = (char) src[srcI + i]; + if (!Character.isLetterOrDigit(d) && d != '_' && c != '-') { + break; + } + } + for (int j = 0; j < i - 1; ++j) { + file_open_env[j] = src[srcI + 1 + j]; + } + file_open_env[i - 1] = 0; + String p = + CobolUtil.getEnv( + new String( + Arrays.copyOfRange(file_open_env, 0, i - 1), + AbstractCobolField.charSetSJIS)); + if (p != null) { + byte[] pbytes = p.getBytes(AbstractCobolField.charSetSJIS); + for (int j = 0; j < pbytes.length; ++j) { + dst[dstI + j] = pbytes[j]; + } + dstI += pbytes.length; + } + srcI += i; + } else { + dst[dstI++] = src[srcI++]; + } + } + + file_open_name = + new String(Arrays.copyOfRange(dst, 0, dstI), AbstractCobolField.charSetSJIS); + + byte[] fileOpenNameBytes = file_open_name.getBytes(AbstractCobolField.charSetSJIS); + cb_get_jisword_buff(file_open_buff, fileOpenNameBytes, COB_SMALL_BUFF); + + if (simple) { + int i; + for (i = 0; i < NUM_PREFIX; i++) { + byte[] fileOpenBuff = + concatString(prefix[i], file_open_name) + .getBytes(AbstractCobolField.charSetSJIS); + String p = + CobolUtil.getEnv( + new String(fileOpenBuff, AbstractCobolField.charSetSJIS)); + if (p != null) { + fileOpenNameBytes = p.getBytes(AbstractCobolField.charSetSJIS); + break; + } + } + + if (i == NUM_PREFIX && cob_file_path != null) { + byte[] fileOpenBuff = + concatString(cob_file_path, "/", file_open_name) + .getBytes(AbstractCobolField.charSetSJIS); + fileOpenNameBytes = fileOpenBuff; + } + } + + file_open_name = new String(fileOpenNameBytes, AbstractCobolField.charSetSJIS); + } + + Path filePath; + if (this.assign == null) { + filePath = Paths.get(this.select_name); + } else { + filePath = Paths.get(this.assign.fieldToString()); + } + try { + saveStatus(COB_STATUS_00_SUCCESS, fnstatus); + Files.delete(filePath); + return; + } catch (IOException e) { + int mode = (int) this.last_open_mode; + try { + switch (this.open_(file_open_name, mode, 0)) { + case ENOENT: + saveStatus(COB_STATUS_35_NOT_EXISTS, fnstatus); + return; + case EACCESS: + case EISDIR: + case EROFS: + saveStatus(COB_STATUS_37_PERMISSION_DENIED, fnstatus); + return; + case EAGAIN: + case COB_STATUS_61_FILE_SHARING: + saveStatus(COB_STATUS_61_FILE_SHARING, fnstatus); + return; + case COB_STATUS_91_NOT_AVAILABLE: + saveStatus(COB_STATUS_91_NOT_AVAILABLE, fnstatus); + return; + case COB_STATUS_92_VERSION_INCOMPATIBLE: + saveStatus(COB_STATUS_92_VERSION_INCOMPATIBLE, fnstatus); + return; + case COB_LINAGE_INVALID: + saveStatus(COB_STATUS_57_I_O_LINAGE, fnstatus); + return; + default: + saveStatus(COB_STATUS_30_PERMANENT_ERROR, fnstatus); + return; + } + } catch (IOException e1) { + saveStatus(COB_STATUS_30_PERMANENT_ERROR, fnstatus); + return; + } + } + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public String getSelectName() { + // CobolFile cobolFile = new CobolFile(); + return this.select_name; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public byte[] getFileStatus() { + // CobolFile cobolFile = new CobolFile(); + return this.file_status; + } + + private static Map externalFileStatusTable = new HashMap(); + + /** + * TODO: 準備中 + * + * @param key TODO: 準備中 + * @return TODO: 準備中 + */ + public static byte[] getExternalFileStatus(String key) { + byte[] bytes = externalFileStatusTable.get(key); + if (bytes == null) { + bytes = new byte[2]; + bytes[0] = 0; + bytes[1] = 0; + externalFileStatusTable.put(key, bytes); + } + return bytes; + } + + private static Map externalFileTable = new HashMap(); + + /** + * TODO: 準備中 + * + * @param key TODO: 準備中 + * @return TODO: 準備中 + */ + public static CobolFile getExternalFile(String key) { + return externalFileTable.get(key); + } + + /** + * TODO: 準備中 + * + * @param key TODO: 準備中 + * @param value TODO: 準備中 + * @return TODO: 準備中 + */ + public static CobolFile putExternalFile(String key, CobolFile value) { + return externalFileTable.put(key, value); + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolFileFactory.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolFileFactory.java index 4e7ad469..bbec6a1e 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolFileFactory.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolFileFactory.java @@ -1,220 +1,220 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.file; - -import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; - -/** TODO: 準備中 */ -public class CobolFileFactory { - - /** - * TODO: 準備中 - * - * @param selectName TODO: 準備中 - * @param fileStatus TODO: 準備中 - * @param assign TODO: 準備中 - * @param record TODO: 準備中 - * @param recordSize TODO: 準備中 - * @param recordMin TODO: 準備中 - * @param recordMax TODO: 準備中 - * @param nkeys TODO: 準備中 - * @param keys TODO: 準備中 - * @param organization TODO: 準備中 - * @param accessMode TODO: 準備中 - * @param lockMode TODO: 準備中 - * @param openMode TODO: 準備中 - * @param flagOptional TODO: 準備中 - * @param lastOpenMode TODO: 準備中 - * @param special TODO: 準備中 - * @param flagNonexistent TODO: 準備中 - * @param flagEndOfFile TODO: 準備中 - * @param flagBeginOfFile TODO: 準備中 - * @param flagFirstRead TODO: 準備中 - * @param flagReadDone TODO: 準備中 - * @param flagSelectFeatures TODO: 準備中 - * @param flagNeedsNl TODO: 準備中 - * @param flagNeedsTop TODO: 準備中 - * @param fileVersion TODO: 準備中 - * @return TODO: 準備中 - */ - public static CobolFile makeCobolFileInstance( - String selectName, - byte[] fileStatus, - AbstractCobolField assign, - AbstractCobolField record, - AbstractCobolField recordSize, - int recordMin, - int recordMax, - int nkeys, - CobolFileKey[] keys, - char organization, - char accessMode, - char lockMode, - char openMode, - boolean flagOptional, - char lastOpenMode, - char special, - boolean flagNonexistent, - boolean flagEndOfFile, - boolean flagBeginOfFile, - char flagFirstRead, - boolean flagReadDone, - char flagSelectFeatures, - boolean flagNeedsNl, - boolean flagNeedsTop, - char fileVersion) { - switch (organization) { - case CobolFile.COB_ORG_SEQUENTIAL: - return new CobolSequentialFile( - selectName, - fileStatus, - assign, - record, - recordSize, - recordMin, - recordMax, - nkeys, - keys, - organization, - accessMode, - lockMode, - openMode, - flagOptional, - lastOpenMode, - special, - flagNonexistent, - flagEndOfFile, - flagBeginOfFile, - flagFirstRead, - flagReadDone, - flagSelectFeatures, - flagNeedsNl, - flagNeedsTop, - fileVersion); - case CobolFile.COB_ORG_LINE_SEQUENTIAL: - return new CobolLineSequentialFile( - selectName, - fileStatus, - assign, - record, - recordSize, - recordMin, - recordMax, - nkeys, - keys, - organization, - accessMode, - lockMode, - openMode, - flagOptional, - lastOpenMode, - special, - flagNonexistent, - flagEndOfFile, - flagBeginOfFile, - flagFirstRead, - flagReadDone, - flagSelectFeatures, - flagNeedsNl, - flagNeedsTop, - fileVersion); - case CobolFile.COB_ORG_RELATIVE: - return new CobolRelativeFile( - selectName, - fileStatus, - assign, - record, - recordSize, - recordMin, - recordMax, - nkeys, - keys, - organization, - accessMode, - lockMode, - openMode, - flagOptional, - lastOpenMode, - special, - flagNonexistent, - flagEndOfFile, - flagBeginOfFile, - flagFirstRead, - flagReadDone, - flagSelectFeatures, - flagNeedsNl, - flagNeedsTop, - fileVersion); - case CobolFile.COB_ORG_INDEXED: - return new CobolIndexedFile( - selectName, - fileStatus, - assign, - record, - recordSize, - recordMin, - recordMax, - nkeys, - keys, - organization, - accessMode, - lockMode, - openMode, - flagOptional, - lastOpenMode, - special, - flagNonexistent, - flagEndOfFile, - flagBeginOfFile, - flagFirstRead, - flagReadDone, - flagSelectFeatures, - flagNeedsNl, - flagNeedsTop, - fileVersion); - default: - return new CobolFile( - selectName, - fileStatus, - assign, - record, - recordSize, - recordMin, - recordMax, - nkeys, - keys, - organization, - accessMode, - lockMode, - openMode, - flagOptional, - lastOpenMode, - special, - flagNonexistent, - flagEndOfFile, - flagBeginOfFile, - flagFirstRead, - flagReadDone, - flagSelectFeatures, - flagNeedsNl, - flagNeedsTop, - fileVersion); - } - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.file; + +import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; + +/** TODO: 準備中 */ +public class CobolFileFactory { + + /** + * TODO: 準備中 + * + * @param selectName TODO: 準備中 + * @param fileStatus TODO: 準備中 + * @param assign TODO: 準備中 + * @param record TODO: 準備中 + * @param recordSize TODO: 準備中 + * @param recordMin TODO: 準備中 + * @param recordMax TODO: 準備中 + * @param nkeys TODO: 準備中 + * @param keys TODO: 準備中 + * @param organization TODO: 準備中 + * @param accessMode TODO: 準備中 + * @param lockMode TODO: 準備中 + * @param openMode TODO: 準備中 + * @param flagOptional TODO: 準備中 + * @param lastOpenMode TODO: 準備中 + * @param special TODO: 準備中 + * @param flagNonexistent TODO: 準備中 + * @param flagEndOfFile TODO: 準備中 + * @param flagBeginOfFile TODO: 準備中 + * @param flagFirstRead TODO: 準備中 + * @param flagReadDone TODO: 準備中 + * @param flagSelectFeatures TODO: 準備中 + * @param flagNeedsNl TODO: 準備中 + * @param flagNeedsTop TODO: 準備中 + * @param fileVersion TODO: 準備中 + * @return TODO: 準備中 + */ + public static CobolFile makeCobolFileInstance( + String selectName, + byte[] fileStatus, + AbstractCobolField assign, + AbstractCobolField record, + AbstractCobolField recordSize, + int recordMin, + int recordMax, + int nkeys, + CobolFileKey[] keys, + char organization, + char accessMode, + char lockMode, + char openMode, + boolean flagOptional, + char lastOpenMode, + char special, + boolean flagNonexistent, + boolean flagEndOfFile, + boolean flagBeginOfFile, + char flagFirstRead, + boolean flagReadDone, + char flagSelectFeatures, + boolean flagNeedsNl, + boolean flagNeedsTop, + char fileVersion) { + switch (organization) { + case CobolFile.COB_ORG_SEQUENTIAL: + return new CobolSequentialFile( + selectName, + fileStatus, + assign, + record, + recordSize, + recordMin, + recordMax, + nkeys, + keys, + organization, + accessMode, + lockMode, + openMode, + flagOptional, + lastOpenMode, + special, + flagNonexistent, + flagEndOfFile, + flagBeginOfFile, + flagFirstRead, + flagReadDone, + flagSelectFeatures, + flagNeedsNl, + flagNeedsTop, + fileVersion); + case CobolFile.COB_ORG_LINE_SEQUENTIAL: + return new CobolLineSequentialFile( + selectName, + fileStatus, + assign, + record, + recordSize, + recordMin, + recordMax, + nkeys, + keys, + organization, + accessMode, + lockMode, + openMode, + flagOptional, + lastOpenMode, + special, + flagNonexistent, + flagEndOfFile, + flagBeginOfFile, + flagFirstRead, + flagReadDone, + flagSelectFeatures, + flagNeedsNl, + flagNeedsTop, + fileVersion); + case CobolFile.COB_ORG_RELATIVE: + return new CobolRelativeFile( + selectName, + fileStatus, + assign, + record, + recordSize, + recordMin, + recordMax, + nkeys, + keys, + organization, + accessMode, + lockMode, + openMode, + flagOptional, + lastOpenMode, + special, + flagNonexistent, + flagEndOfFile, + flagBeginOfFile, + flagFirstRead, + flagReadDone, + flagSelectFeatures, + flagNeedsNl, + flagNeedsTop, + fileVersion); + case CobolFile.COB_ORG_INDEXED: + return new CobolIndexedFile( + selectName, + fileStatus, + assign, + record, + recordSize, + recordMin, + recordMax, + nkeys, + keys, + organization, + accessMode, + lockMode, + openMode, + flagOptional, + lastOpenMode, + special, + flagNonexistent, + flagEndOfFile, + flagBeginOfFile, + flagFirstRead, + flagReadDone, + flagSelectFeatures, + flagNeedsNl, + flagNeedsTop, + fileVersion); + default: + return new CobolFile( + selectName, + fileStatus, + assign, + record, + recordSize, + recordMin, + recordMax, + nkeys, + keys, + organization, + accessMode, + lockMode, + openMode, + flagOptional, + lastOpenMode, + special, + flagNonexistent, + flagEndOfFile, + flagBeginOfFile, + flagFirstRead, + flagReadDone, + flagSelectFeatures, + flagNeedsNl, + flagNeedsTop, + fileVersion); + } + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolFileKey.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolFileKey.java index 2e2ec71e..e59edd4a 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolFileKey.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolFileKey.java @@ -1,132 +1,132 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.file; - -import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; - -/** TODO: 準備中 */ -public class CobolFileKey { - /** TODO: 準備中 */ - public static final int COB_MAX_KEY_COMPONENTS = 8; - - private AbstractCobolField field; - private int flag; - private int offset; - private int countComponents; - private KeyComponent[] component = new KeyComponent[COB_MAX_KEY_COMPONENTS]; - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public AbstractCobolField getField() { - return field; - } - - /** - * TODO: 準備中 - * - * @param field TODO: 準備中 - */ - public void setField(AbstractCobolField field) { - this.field = field; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public int getFlag() { - return flag; - } - - /** - * TODO: 準備中 - * - * @param flag TODO: 準備中 - */ - public void setFlag(int flag) { - this.flag = flag; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public int getOffset() { - return offset; - } - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - */ - public void setOffset(int offset) { - this.offset = offset; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public int getCountComponents() { - return countComponents; - } - - /** - * TODO: 準備中 - * - * @param countComponents TODO: 準備中 - */ - public void setCountComponents(int countComponents) { - this.countComponents = countComponents; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public KeyComponent[] getComponent() { - return component; - } - - /** - * TODO: 準備中 - * - * @param component TODO: 準備中 - */ - public void setComponent(KeyComponent[] component) { - this.component = component; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public static int getCobMaxKeyComponents() { - return COB_MAX_KEY_COMPONENTS; - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.file; + +import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; + +/** TODO: 準備中 */ +public class CobolFileKey { + /** TODO: 準備中 */ + public static final int COB_MAX_KEY_COMPONENTS = 8; + + private AbstractCobolField field; + private int flag; + private int offset; + private int countComponents; + private KeyComponent[] component = new KeyComponent[COB_MAX_KEY_COMPONENTS]; + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public AbstractCobolField getField() { + return field; + } + + /** + * TODO: 準備中 + * + * @param field TODO: 準備中 + */ + public void setField(AbstractCobolField field) { + this.field = field; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public int getFlag() { + return flag; + } + + /** + * TODO: 準備中 + * + * @param flag TODO: 準備中 + */ + public void setFlag(int flag) { + this.flag = flag; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public int getOffset() { + return offset; + } + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + */ + public void setOffset(int offset) { + this.offset = offset; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public int getCountComponents() { + return countComponents; + } + + /** + * TODO: 準備中 + * + * @param countComponents TODO: 準備中 + */ + public void setCountComponents(int countComponents) { + this.countComponents = countComponents; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public KeyComponent[] getComponent() { + return component; + } + + /** + * TODO: 準備中 + * + * @param component TODO: 準備中 + */ + public void setComponent(KeyComponent[] component) { + this.component = component; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public static int getCobMaxKeyComponents() { + return COB_MAX_KEY_COMPONENTS; + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolFileSort.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolFileSort.java index b019cfea..24a48249 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolFileSort.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolFileSort.java @@ -1,1140 +1,1166 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.file; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.nio.file.StandardOpenOption; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import jp.osscons.opensourcecobol.libcobj.common.CobolModule; -import jp.osscons.opensourcecobol.libcobj.common.CobolUtil; -import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; -import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; -import jp.osscons.opensourcecobol.libcobj.data.CobolFieldAttribute; -import jp.osscons.opensourcecobol.libcobj.data.CobolFieldFactory; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; - -/** TODO: 準備中 */ -public class CobolFileSort { - /** TODO: 準備中 */ - protected static final int COBSORTEND = 1; - /** TODO: 準備中 */ - protected static final int COBSORTABORT = 2; - /** TODO: 準備中 */ - protected static final int COBSORTFILEERR = 3; - /** TODO: 準備中 */ - protected static final int COBSORTNOTOPEN = 4; - - /** TODO: 準備中 */ - protected static final int COB_ASCENDING = 0; - /** TODO: 準備中 */ - protected static final int COB_DESCENDING = 1; - - private static String cob_process_id = ""; - private static int cob_iteration = 0; - - /** TODO: 準備中 */ - protected static int cob_sort_memory = 128 * 1024 * 1024; - - // Javaの標準ライブラリでソートするならtrue - private static boolean SORT_STD_LIB = true; - private static List dataList; - - /** - * libcob/fileio.cのsort_cmpsの実装 - * - * @param s1 TODO: 準備中 - * @param s2 TODO: 準備中 - * @param size TODO: 準備中 - * @param col TODO: 準備中 - * @return TODO: 準備中 - */ - private static int sortCmps( - CobolDataStorage s1, CobolDataStorage s2, int size, CobolDataStorage col) { - if (col != null) { - for (int i = 0; i < size; ++i) { - int ret = (col.getByte(s1.getByte(i)) & 0xff) - (col.getByte(s2.getByte(i)) & 0xff); - if (ret != 0) { - return ret; - } - } - } else { - for (int i = 0; i < size; ++i) { - int ret = (s1.getByte(i) & 0xff) - (s2.getByte(i) & 0xff); - if (ret != 0) { - return ret; - } - } - } - return 0; - } - - private static void uniqueCopy(CobolDataStorage s1, CobolDataStorage s2, int size) { - for (int i = 0; i < size; ++i) { - s1.setByte(s2.getByte(i)); - } - } - - /** - * libcob/fileio.cのcob_file_sort_compareの実装 - * - * @param k1 TODO: 準備中 - * @param k2 TODO: 準備中 - * @param pointer TODO: 準備中 - * @return TODO: 準備中 - */ - private static int sortCompare(CobolItem k1, CobolItem k2, CobolFile pointer) { - CobolFile f = pointer; - long u1; - long u2; - int cmp; - - for (int i = 0; i < f.nkeys; i++) { - AbstractCobolField src = f.keys[i].getField(); - - CobolDataStorage d1 = k1.getItem().copy(); - d1.addIndex(f.keys[i].getOffset()); - - CobolDataStorage d2 = k2.getItem().copy(); - d2.addIndex(f.keys[i].getOffset()); - - AbstractCobolField f1 = - CobolFieldFactory.makeCobolField(src.getSize(), d1, src.getAttribute()); - AbstractCobolField f2 = - CobolFieldFactory.makeCobolField(src.getSize(), d2, src.getAttribute()); - - if (f1.getAttribute().isTypeNumeric()) { - cmp = f1.numericCompareTo(f2); - } else { - cmp = sortCmps(f1.getDataStorage(), f2.getDataStorage(), f1.getSize(), f.sort_collating); - } - if (cmp != 0) { - return (f.keys[i].getFlag() == COB_ASCENDING) ? cmp : -cmp; - } - } - byte[] bu1 = new byte[8]; - byte[] bu2 = new byte[8]; - uniqueCopy(new CobolDataStorage(bu1), k1.getUnique(), 8); - uniqueCopy(new CobolDataStorage(bu2), k2.getUnique(), 8); - u1 = ByteBuffer.wrap(bu1).getLong(); - u2 = ByteBuffer.wrap(bu2).getLong(); - return u1 < u2 ? -1 : 1; - } - - /** - * libcob/fileio.cのcob_free_listの実装 - * - * @param q TODO: 準備中 - */ - private static void cob_free_list(CobolItem q) { - // nothing to do - } - - /** - * libcob/fileio.cのcob_new_itemの実装 - * - * @param hp TODO: 準備中 - * @return TODO: 準備中 - */ - private static CobolItem newItem(CobolSort hp) { - CobolItem q; - if (hp.getEmpty() != null) { - q = hp.getEmpty(); - hp.setEmpty(q.getNext()); - } else { - q = new CobolItem(); - } - return q; - } - - /** - * libcob/fileio.cのcob_tmpfileの実装 - * - * @return TODO: 準備中 - */ - private static FileIO tmpfile() { - FileIO fp = new FileIO(); - String s = CobolUtil.getEnv("TMPDIR"); - if (s == null) { - s = CobolUtil.getEnv("TMP"); - if (s == null) { - s = CobolUtil.getEnv("TEMP"); - if (s == null) { - s = "/tmp"; - } - } - } - if ("".equals(cob_process_id)) { - cob_process_id = - java.lang.management.ManagementFactory.getRuntimeMXBean().getName().split("@")[0]; - } - String filename = String.format("%s/cobsort_%s_%d", s, cob_process_id, cob_iteration); - cob_iteration++; - outer: - try { - Files.delete(Paths.get(filename)); - } catch (IOException e1) { - break outer; - } - FileChannel fc = null; - try { - fc = - FileChannel.open( - Paths.get(filename), - StandardOpenOption.READ, - StandardOpenOption.WRITE, - StandardOpenOption.CREATE, - StandardOpenOption.TRUNCATE_EXISTING); - } catch (IOException e) { - return null; - } - fp.setChannel(fc, null); - return fp; - } - - /** - * libcob/fileio.cのcob_get_temp_fileの実装 - * - * @param hp TODO: 準備中 - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - private static boolean getTempFile(CobolSort hp, int n) { - if (hp.getFile()[n].getFp() == null) { - hp.getFile()[n].setFp(tmpfile()); - if (hp.getFile()[n].getFp() == null) { - // TODO 暫定実装 - System.out.println("SORT is unable to auire temporary file"); - System.exit(0); - } - } else { - hp.getFile()[n].getFp().rewind(); - } - hp.getFile()[n].setCount(0); - return hp.getFile()[n].getFp() == null; - } - - /** - * libcob/fileio.cのcob_sort_queuesの実装 - * - * @param hp TODO: 準備中 - * @return TODO: 準備中 - */ - private static int sortQueues(CobolSort hp) { - CobolItem q; - int source = 0; - int destination; - int move; - int n; - int[] endOfBlock = new int[2]; - - while (hp.getQueue()[source + 1].getCount() != 0) { - destination = source ^ 2; - hp.getQueue()[destination].setCount(0); - hp.getQueue()[destination + 1].setCount(0); - hp.getQueue()[destination].setFirst(null); - hp.getQueue()[destination + 1].setFirst(null); - for (; ; ) { - endOfBlock[0] = hp.getQueue()[source].getCount() == 0 ? 1 : 0; - endOfBlock[1] = hp.getQueue()[source + 1].getCount() == 0 ? 1 : 0; - if (endOfBlock[0] != 0 && endOfBlock[1] != 0) { - break; - } - while (endOfBlock[0] == 0 || endOfBlock[1] == 0) { - if (endOfBlock[0] != 0) { - move = 1; - } else if (endOfBlock[1] != 0) { - move = 0; - } else { - n = - sortCompare( - hp.getQueue()[source].getFirst(), - hp.getQueue()[source + 1].getFirst(), - hp.getPointer()); - move = n < 0 ? 0 : 1; - } - q = hp.getQueue()[source + move].getFirst(); - if (q.getEndOfBlock() != 0) { - endOfBlock[move] = 1; - } - q = hp.getQueue()[source + move].getFirst(); - if (q.getEndOfBlock() != 0) { - endOfBlock[move] = 1; - } - hp.getQueue()[source + move].setFirst(q.getNext()); - if (hp.getQueue()[destination].getFirst() == null) { - hp.getQueue()[destination].setFirst(q); - } else { - hp.getQueue()[destination].getLast().setNext(q); - } - hp.getQueue()[destination].setLast(q); - hp.getQueue()[source + move].setCount(hp.getQueue()[source + move].getCount() - 1); - hp.getQueue()[destination].setCount(hp.getQueue()[destination].getCount() + 1); - q.setNext(null); - q.setEndOfBlock(0); - } - hp.getQueue()[destination].getLast().setEndOfBlock(1); - destination ^= 1; - } - source = destination & 2; - } - return source; - } - - /** - * libcob/fileio.cのcob_read_itemの実装 - * - * @param hp TODO: 準備中 - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - private static int readItem(CobolSort hp, int n) { - FileIO fp = hp.getFile()[n].getFp(); - if (fp.getc() != 0) { - hp.getQueue()[n].getFirst().setEndOfBlock(1); - } else { - hp.getQueue()[n].getFirst().setEndOfBlock(0); - try { - if (fp.read(hp.getQueue()[n].getFirst().getUnique(), 8) != 8) { - return 1; - } - if (fp.read(hp.getQueue()[n].getFirst().getItem(), hp.getSize()) != hp.getSize()) { - return 1; - } - } catch (IOException e) { - return 1; - } - } - return 0; - } - - /** - * writeBlock内で使う補助メソッド - * - * @param fp TODO: 準備中 - * @param q TODO: 準備中 - * @param hp TODO: 準備中 - * @return 書き込み失敗時true,それ以外はfalse - */ - private static boolean writeItem(FileIO fp, CobolItem q, CobolSort hp) { - byte[] blockByteData = new byte[1]; - blockByteData[0] = q.getBlockByte(); - if (!fp.write(blockByteData, 1)) { - return true; - } - if (!fp.write(q.getUnique(), 8)) { - return true; - } - return fp.write(q.getItem(), hp.getSize()); - } - - /** - * libcob/fileio.cのcob_write_blockの実装 - * - * @param hp TODO: 準備中 - * @param n TODO: 準備中 - * @return TODO: 準備中 - */ - private static int writeBlock(CobolSort hp, int n) { - FileIO fp = hp.getFile()[hp.getDestinationFile()].getFp(); - for (; ; ) { - CobolItem q = hp.getQueue()[n].getFirst(); - if (q == null) { - break; - } - if (writeItem(fp, q, hp)) { - return 1; - } - hp.getQueue()[n].setFirst(q.getNext()); - q.setNext(hp.getEmpty()); - hp.setEmpty(q); - } - hp.getQueue()[n].setCount(0); - hp.getFile()[hp.getDestinationFile()].setCount( - hp.getFile()[hp.getDestinationFile()].getCount() + 1); - if (fp.putc((byte) 1) != 1) { - return 1; - } - return 0; - } - - /** - * libcob/fileio.cのcob_copy_checkの実装 - * - * @param from TODO: 準備中 - */ - private static void copyCheck(CobolFile to, CobolFile from) { - CobolDataStorage toptr = to.record.getDataStorage(); - CobolDataStorage fromptr = from.record.getDataStorage(); - int tosize = to.record.getSize(); - int fromsize = from.record.getSize(); - if (tosize > fromsize) { - for (int i = 0; i < fromsize; ++i) { - toptr.setByte(i, fromptr.getByte(i)); - } - for (int i = 0; i < tosize - fromsize; ++i) { - toptr.setByte(fromsize + i, (byte) ' '); - } - } else { - for (int i = 0; i < tosize; ++i) { - toptr.setByte(i, fromptr.getByte(i)); - } - } - } - - /** - * libcob/fileio.cのcob_file_sort_processの実装 - * - * @param hp TODO: 準備中 - * @return TODO: 準備中 - */ - private static int sortProcess(CobolSort hp) { - hp.setRetrieving(1); - int n = sortQueues(hp); - if (hp.getFilesUsed() == 0) { - hp.setRetrievalQueue(n); - return 0; - } - if (writeBlock(hp, n) != 0) { - return COBSORTFILEERR; - } - for (int i = 0; i < 4; i++) { - hp.getQueue()[i].setFirst(hp.getEmpty()); - hp.setEmpty(hp.getEmpty().getNext()); - hp.getQueue()[i].getFirst().setNext(null); - } - hp.getFile()[0].getFp().rewind(); - hp.getFile()[1].getFp().rewind(); - if (getTempFile(hp, 2)) { - return COBSORTFILEERR; - } - if (getTempFile(hp, 3)) { - return COBSORTFILEERR; - } - int source = 0; - while (hp.getFile()[source].getCount() > 1) { - int destination = source ^ 2; - hp.getFile()[destination].setCount(0); - hp.getFile()[destination + 1].setCount(0); - while (hp.getFile()[source].getCount() > 0) { - if (readItem(hp, source) != 0) { - return COBSORTFILEERR; - } - if (hp.getFile()[source + 1].getCount() > 0) { - if (readItem(hp, source + 1) != 0) { - return COBSORTFILEERR; - } - } else { - hp.getQueue()[source + 1].getFirst().setEndOfBlock(1); - } - while (hp.getQueue()[source].getFirst().getEndOfBlock() == 0 - || hp.getQueue()[source + 1].getFirst().getEndOfBlock() == 0) { - int move; - if (hp.getQueue()[source].getFirst().getEndOfBlock() != 0) { - move = 1; - } else if (hp.getQueue()[source + 1].getFirst().getEndOfBlock() != 0) { - move = 0; - } else { - int res = - sortCompare( - hp.getQueue()[source].getFirst(), - hp.getQueue()[source + 1].getFirst(), - hp.getPointer()); - move = res < 0 ? 0 : 1; - } - if (writeItem( - hp.getFile()[destination].getFp(), hp.getQueue()[source + move].getFirst(), hp)) { - return COBSORTFILEERR; - } - if (readItem(hp, source + move) != 0) { - return COBSORTFILEERR; - } - } - hp.getFile()[destination].setCount(hp.getFile()[destination].getCount() + 1); - if (hp.getFile()[destination].getFp().putc((byte) 1) != 1) { - return COBSORTFILEERR; - } - hp.getFile()[source].setCount(hp.getFile()[source].getCount() - 1); - hp.getFile()[source + 1].setCount(hp.getFile()[source + 1].getCount() - 1); - destination ^= 1; - } - source = destination & 2; - for (int i = 0; i < 4; ++i) { - hp.getFile()[i].getFp().rewind(); - } - } - hp.setRetrievalQueue(source); - if (readItem(hp, source) != 0) { - return COBSORTFILEERR; - } - if (readItem(hp, source + 1) != 0) { - return COBSORTFILEERR; - } - return 0; - } - - /** - * libcob/fileio.cのcob_file_sort_submitの実装 - * - * @param p TODO: 準備中 - * @return TODO: 準備中 - */ - private static int sortSubmit(CobolFile f, CobolDataStorage p) { - - if (SORT_STD_LIB) { - dataList.add(new CobolDataStorage(p.getData())); - return 0; - } else { - CobolSort hp = f.filex; - if (hp == null) { - return COBSORTNOTOPEN; - } - if (hp.getRetrieving() != 0) { - return COBSORTABORT; - } - if (hp.getQueue()[0].getCount() + hp.getQueue()[1].getCount() >= hp.getMemory()) { - if (hp.getFilesUsed() == 0) { - if (getTempFile(hp, 0)) { - return COBSORTFILEERR; - } - if (getTempFile(hp, 1)) { - return COBSORTFILEERR; - } - hp.setFilesUsed(1); - hp.setDestinationFile(0); - } - int n = sortQueues(hp); - if (writeBlock(hp, n) != 0) { - return COBSORTFILEERR; - } - hp.setDestinationFile(hp.getDestinationFile() ^ 1); - } - - CobolItem q = newItem(hp); - if (f.record_size != null) { - q.setRecordSize(f.record_size.getInt()); - } else { - q.setRecordSize(hp.getSize()); - } - q.setEndOfBlock(1); - - { - byte[] bytes = new byte[8]; - ByteBuffer buf = ByteBuffer.wrap(bytes); - buf.putInt(hp.getUnique()); - uniqueCopy(q.getUnique(), new CobolDataStorage(bytes), 8); - } - - hp.setUnique(hp.getUnique() + 1); - - byte[] arr = p.getByteArray(0, hp.getSize()); - q.setItem(new CobolDataStorage(arr)); - - MemoryStruct z; - if (hp.getQueue()[0].getCount() <= hp.getQueue()[1].getCount()) { - z = hp.getQueue()[0]; - } else { - z = hp.getQueue()[1]; - } - q.setNext(z.getFirst()); - z.setFirst(q); - z.setCount(z.getCount() + 1); - return 0; - } - } - - /** - * libcob/fileio.cのcob_file_sort_retrieveの実装 - * - * @param p TODO: 準備中 - * @return TODO: 準備中 - */ - private static int sortRetrieve(CobolFile f, CobolDataStorage p) { - CobolSort hp = f.filex; - if (hp == null) { - return COBSORTNOTOPEN; - } - - if (SORT_STD_LIB) { - if (hp.getRetrieving() == 0) { - memorySort(f); - hp.setRetrieving(1); - } - if (dataList.isEmpty()) { - return COBSORTEND; - } - CobolDataStorage storage = dataList.remove(0); - p.setBytes(storage, hp.getSize()); - if (f.record_size != null) { - f.record_size.setInt(hp.getSize()); - } - return 0; - } - - if (hp.getRetrieving() == 0) { - int res = sortProcess(hp); - if (res != 0) { - return res; - } - } - - if (hp.getFilesUsed() != 0) { - int source = hp.getRetrievalQueue(); - int move; - if (hp.getQueue()[source].getFirst().getEndOfBlock() != 0) { - if (hp.getQueue()[source].getFirst().getEndOfBlock() != 0) { - return COBSORTEND; - } - move = 1; - } else if (hp.getQueue()[source].getFirst().getEndOfBlock() != 0) { - move = 0; - } else { - int res = - sortCompare( - hp.getQueue()[source].getFirst(), - hp.getQueue()[source + 1].getFirst(), - hp.getPointer()); - move = res < 0 ? 0 : 1; - } - for (int i = 0; i < hp.getSize(); ++i) { - p.setByte(i, hp.getQueue()[source + move].getFirst().getItem().getByte(i)); - } - if (readItem(hp, source + move) != 0) { - return COBSORTFILEERR; - } - } else { - MemoryStruct z = hp.getQueue()[hp.getRetrievalQueue()]; - if (z.getFirst() == null) { - return COBSORTEND; - } - for (int i = 0; i < hp.getSize(); ++i) { - p.setByte(i, z.getFirst().getItem().getByte(i)); - } - if (f.record_size != null) { - f.record_size.setInt(z.getFirst().getRecordSize()); - } - CobolItem next = z.getFirst().getNext(); - z.getFirst().setNext(hp.getEmpty()); - hp.setEmpty(z.getFirst()); - z.setFirst(next); - } - return 0; - } - - private static void memorySort(CobolFile f) { - dataList.sort( - new Comparator() { - @Override - public int compare(CobolDataStorage data1, CobolDataStorage data2) { - int cmp; - - for (int i = 0; i < f.nkeys; i++) { - AbstractCobolField src = f.keys[i].getField(); - - CobolDataStorage d1 = data1.copy(); - d1.addIndex(f.keys[i].getOffset()); - - CobolDataStorage d2 = data2.copy(); - d2.addIndex(f.keys[i].getOffset()); - - AbstractCobolField f1 = - CobolFieldFactory.makeCobolField(src.getSize(), d1, src.getAttribute()); - AbstractCobolField f2 = - CobolFieldFactory.makeCobolField(src.getSize(), d2, src.getAttribute()); - - if (f1.getAttribute().isTypeNumeric()) { - cmp = f1.numericCompareTo(f2); - } else { - cmp = - sortCmps( - f1.getDataStorage(), f2.getDataStorage(), f1.getSize(), f.sort_collating); - } - if (cmp != 0) { - return (f.keys[i].getFlag() == COB_ASCENDING) ? cmp : -cmp; - } - } - return 0; - } - }); - } - - // libcob/fileio.cのcob_file_sort_initの実装 - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - * @param nkeys TODO: 準備中 - * @param collatingSequence TODO: 準備中 - * @param sortReturn TODO: 準備中 - * @param fnstatus TODO: 準備中 - */ - public static void sortInit( - CobolFile f, - int nkeys, - CobolDataStorage collatingSequence, - CobolDataStorage sortReturn, - AbstractCobolField fnstatus) { - int sizeOfSizeT = 8; - CobolSort p = new CobolSort(); - p.setFnstatus(fnstatus); - p.setSize(f.record_max); - p.setrSize(f.record_max + sizeOfSizeT); - p.setwSize(f.record_max + sizeOfSizeT + 1); - p.setPointer(f); - p.setSortReturn(sortReturn); - sortReturn.set(0); - // opensource COBOLでsizeof(struct cobitem) == 32だっため,32を使用した - p.setMemory(cob_sort_memory / (p.getSize() + 32)); - dataList = new ArrayList(); - f.filex = p; - f.keys = new CobolFileKey[nkeys]; - for (int i = 0; i < nkeys; ++i) { - f.keys[i] = new CobolFileKey(); - } - f.nkeys = 0; - if (collatingSequence != null) { - f.sort_collating = collatingSequence; - } else { - f.sort_collating = CobolModule.getCurrentModule().collating_sequence; - } - f.saveStatus(CobolFile.COB_STATUS_00_SUCCESS, fnstatus); - } - - // libcob/fileio.cのcob_file_sort_initの実装 - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - * @param nkeys TODO: 準備中 - * @param collatingSequence TODO: 準備中 - * @param sortReturn TODO: 準備中 - * @param fnstatus TODO: 準備中 - */ - public static void sortInit( - CobolFile f, - int nkeys, - int collatingSequence, - CobolDataStorage sortReturn, - AbstractCobolField fnstatus) { - sortInit(f, nkeys, null, sortReturn, fnstatus); - } - - // libcob/fileio.cのcob_file_sort_init_keyの実装 - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - * @param flag TODO: 準備中 - * @param field TODO: 準備中 - * @param offset TODO: 準備中 - */ - public static void sortInitKey(CobolFile f, int flag, AbstractCobolField field, int offset) { - f.keys[f.nkeys].setFlag(flag); - f.keys[f.nkeys].setField(field); - f.keys[f.nkeys].setOffset(offset); - f.nkeys++; - } - - // libcob/fileio.cのcob_file_sort_usingの実装 - /** - * TODO: 準備中 - * - * @param sortFile TODO: 準備中 - * @param dataFile TODO: 準備中 - */ - public static void sortUsing(CobolFile sortFile, CobolFile dataFile) { - dataFile.open(CobolFile.COB_OPEN_INPUT, 0, null); - for (; ; ) { - dataFile.read(null, null, CobolFile.COB_READ_NEXT); - if (dataFile.file_status[0] != (byte) '0') { - break; - } - copyCheck(sortFile, dataFile); - int ret = sortSubmit(sortFile, sortFile.record.getDataStorage()); - if (ret != 0) { - break; - } - } - dataFile.close(CobolFile.COB_CLOSE_NORMAL, null); - } - - // libcob/fileio.cのcob_file_sort_givingの実装 - /** - * TODO: 準備中 - * - * @param sortFile TODO: 準備中 - * @param varcnt TODO: 準備中 - * @param fbase TODO: 準備中 - * @throws CobolStopRunException TODO: 準備中 - */ - public static void sortGiving(CobolFile sortFile, int varcnt, CobolFile... fbase) - throws CobolStopRunException { - if (SORT_STD_LIB) { - for (int i = 0; i < varcnt; i++) { - fbase[i].open(CobolFile.COB_OPEN_OUTPUT, 0, null); - } - - int cntRec = 0; - memorySort(sortFile); - for (CobolDataStorage d : dataList) { - for (int i = 0; i < varcnt; i++) { - int opt; - if (fbase[i].special != 0 || fbase[i].organization == CobolFile.COB_ORG_LINE_SEQUENTIAL) { - opt = CobolFile.COB_WRITE_BEFORE | CobolFile.COB_WRITE_LINES | 1; - } else { - opt = 0; - } - sortFile.record.getDataStorage().memcpy(d, sortFile.record.getSize()); - copyCheck(fbase[i], sortFile); - fbase[i].write(fbase[i].record, opt, null); - } - cntRec++; - } - sortFile.file_status[0] = '1'; - sortFile.file_status[1] = '0'; - - for (int i = 0; i < varcnt; i++) { - fbase[i].close(CobolFile.COB_CLOSE_NORMAL, null); - } - CobolUtil.verboseOutput(String.format("END OF SORT/MERGE, RECORD=%d.", cntRec)); - - } else { - - for (int i = 0; i < varcnt; i++) { - fbase[i].open(CobolFile.COB_OPEN_OUTPUT, 0, null); - } - int cntRec = 0; - for (; ; ) { - int ret = sortRetrieve(sortFile, sortFile.record.getDataStorage()); - if (ret != 0) { - if (ret == COBSORTEND) { - sortFile.file_status[0] = '1'; - sortFile.file_status[1] = '0'; - } else { - CobolSort hp = sortFile.filex; - hp.getSortReturn().set(16); - sortFile.file_status[0] = '3'; - sortFile.file_status[1] = '0'; - } - break; - } - for (int i = 0; i < varcnt; i++) { - int opt; - if (fbase[i].special != 0 || fbase[i].organization == CobolFile.COB_ORG_LINE_SEQUENTIAL) { - opt = CobolFile.COB_WRITE_BEFORE | CobolFile.COB_WRITE_LINES | 1; - } else { - opt = 0; - } - copyCheck(fbase[i], sortFile); - fbase[i].write(fbase[i].record, opt, null); - } - cntRec++; - } - for (int i = 0; i < varcnt; i++) { - fbase[i].close(CobolFile.COB_CLOSE_NORMAL, null); - } - CobolUtil.verboseOutput(String.format("END OF SORT/MERGE, RECORD=%d.", cntRec)); - } - } - - // libcob/fileio.cのcob_file_sort_closeの実装 - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - */ - public static void sortClose(CobolFile f) { - AbstractCobolField fnstatus = null; - CobolSort hp = f.filex; - - if (hp != null) { - fnstatus = hp.getFnstatus(); - cob_free_list(hp.getEmpty()); - for (int i = 0; i < 4; ++i) { - cob_free_list(hp.getQueue()[i].getFirst()); - if (hp.getFile()[i].getFp() != null) { - hp.getFile()[i].getFp().close(); - } - } - } - f.filex = null; - f.saveStatus(CobolFile.COB_STATUS_00_SUCCESS, fnstatus); - } - - // libcob/fileio.cのcob_file_releaseの実装 - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - */ - public static void performRelease(CobolFile f) { - AbstractCobolField fnstatus = null; - CobolSort hp = f.filex; - - if (hp != null) { - fnstatus = hp.getFnstatus(); - } - int ret = CobolFileSort.sortSubmit(f, f.record.getDataStorage()); - switch (ret) { - case 0: - f.saveStatus(CobolFile.COB_STATUS_00_SUCCESS, fnstatus); - return; - default: - if (hp != null) { - hp.getSortReturn().set(16); - } - f.saveStatus(CobolFile.COB_STATUS_30_PERMANENT_ERROR, fnstatus); - return; - } - } - - // libcob/fileio.cのcob_file_returnの実装 - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - */ - public static void performReturn(CobolFile f) { - AbstractCobolField fnstatus = null; - CobolSort hp = f.filex; - if (hp != null) { - fnstatus = hp.getFnstatus(); - } - - int ret = CobolFileSort.sortRetrieve(f, f.record.getDataStorage()); - switch (ret) { - case 0: - f.saveStatus(CobolFile.COB_STATUS_00_SUCCESS, fnstatus); - return; - case CobolFileSort.COBSORTEND: - f.saveStatus(CobolFile.COB_STATUS_10_END_OF_FILE, fnstatus); - return; - default: - if (hp != null) { - hp.getSortReturn().set(16); - } - f.saveStatus(CobolFile.COB_STATUS_30_PERMANENT_ERROR, fnstatus); - return; - } - } - - /* Table sort */ - private static int sortNKeys; - private static CobolFileKey[] sortKeys; - private static CobolDataStorage sortCollate; - private static CobolDataStorage pivotStorage = new CobolDataStorage(); - private static CobolDataStorage leftStorage = new CobolDataStorage(); - private static CobolDataStorage rightStorage = new CobolDataStorage(); - private static CobolDataStorage cmpStorage1 = new CobolDataStorage(); - private static CobolDataStorage cmpStorage2 = new CobolDataStorage(); - private static CobolDataStorage copyBuffer = null; - private static CobolDataStorage tmpRecord = new CobolDataStorage(); - private static int copyBufferSizeMax = 0; - private static int[] sortBuffer = null; - private static AbstractCobolField cmpField1 = - CobolFieldFactory.makeCobolField( - 0, - cmpStorage1, - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null)); - private static AbstractCobolField cmpField2 = - CobolFieldFactory.makeCobolField( - 0, - cmpStorage2, - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null)); - - /** - * TODO: 準備中 - * - * @param nkeys TODO: 準備中 - * @param collatingSequence TODO: 準備中 - */ - public static void sortTableInit(int nkeys, int collatingSequence) { - sortTableInit(nkeys, null); - } - - /** - * TODO: 準備中 - * - * @param nkeys TODO: 準備中 - * @param collatingSequence TODO: 準備中 - */ - public static void sortTableInit(int nkeys, CobolDataStorage collatingSequence) { - sortNKeys = 0; - if (sortKeys == null || sortKeys.length < nkeys) { - sortKeys = new CobolFileKey[nkeys]; - } - if (collatingSequence != null) { - sortCollate = collatingSequence; - } else { - sortCollate = CobolModule.getCurrentModule().collating_sequence; - } - } - - /** - * TODO: 準備中 - * - * @param flag TODO: 準備中 - * @param field TODO: 準備中 - * @param offset TODO: 準備中 - */ - public static void sortTableInitKey(int flag, AbstractCobolField field, int offset) { - if (sortKeys[sortNKeys] == null) { - sortKeys[sortNKeys] = new CobolFileKey(); - } - sortKeys[sortNKeys].setFlag(flag); - sortKeys[sortNKeys].setField( - CobolFieldFactory.makeCobolField( - field.getSize(), (CobolDataStorage) null, field.getAttribute())); - sortKeys[sortNKeys].setOffset(offset); - sortNKeys++; - } - - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - * @param n TODO: 準備中 - */ - public static void sortTable(AbstractCobolField f, int n) { - int recordSize = f.getSize(); - if (sortBuffer == null || sortBuffer.length < n) { - sortBuffer = new int[n]; - } - for (int i = 0; i < n; ++i) { - sortBuffer[i] = i; - } - CobolDataStorage baseStorage = f.getDataStorage(); - int baseStorageBaseIndex = baseStorage.getIndex(); - indexQuickSort(f.getDataStorage(), 0, n, recordSize); - - int copyBufferSize = n * f.getSize(); - if (copyBuffer == null || copyBufferSizeMax < copyBufferSize) { - copyBuffer = new CobolDataStorage(copyBufferSize); - copyBufferSizeMax = copyBufferSize; - } - - for (int i = 0; i < n; ++i, copyBuffer.addIndex(recordSize)) { - tmpRecord.setDataRefAndIndex(baseStorage, baseStorageBaseIndex + recordSize * sortBuffer[i]); - copyBuffer.memcpy(tmpRecord, recordSize); - } - copyBuffer.setIndex(0); - baseStorage.memcpy(copyBuffer, copyBufferSize); - } - - private static void indexQuickSort( - CobolDataStorage base, int mostLeft, int mostRight, int recordSize) { - - if (mostRight - mostLeft <= 1) { - return; - } - - int pivot = (mostRight + mostLeft) / 2; - int left = mostLeft, right = mostRight - 1; - - while (true) { - pivotStorage.setDataRefAndIndex(base, base.getIndex() + sortBuffer[pivot] * recordSize); - boolean elementBiggerThanPivot = false; - for (; left < pivot; ++left) { - leftStorage.setDataRefAndIndex(base, base.getIndex() + sortBuffer[left] * recordSize); - if (compareStorageForSort(leftStorage, pivotStorage) > 0) { - elementBiggerThanPivot = true; - break; - } - } - boolean elementSmallerThanPivot = false; - for (; right > pivot; --right) { - rightStorage.setDataRefAndIndex(base, base.getIndex() + sortBuffer[right] * recordSize); - if (compareStorageForSort(pivotStorage, rightStorage) > 0) { - elementSmallerThanPivot = true; - break; - } - } - if (elementBiggerThanPivot && elementSmallerThanPivot) { - swap2Indecies(left, right); - ++left; - --right; - } else if (elementBiggerThanPivot && !elementSmallerThanPivot) { - if (left + 1 == pivot) { - swap2Indecies(left, pivot); - } else { - rotate3Indecies(pivot, pivot - 1, left); - } - --pivot; - } else if (!elementBiggerThanPivot && elementSmallerThanPivot) { - if (right - 1 == pivot) { - swap2Indecies(pivot, right); - } else { - rotate3Indecies(pivot, pivot + 1, right); - } - ++pivot; - } else { - break; - } - } - indexQuickSort(base, mostLeft, pivot, recordSize); - indexQuickSort(base, pivot + 1, mostRight, recordSize); - } - - private static int compareStorageForSort(CobolDataStorage s1, CobolDataStorage s2) { - for (int i = 0; i < sortNKeys; ++i) { - - cmpStorage1.setDataRefAndIndex(s1, s1.getIndex() + sortKeys[i].getOffset()); - cmpStorage2.setDataRefAndIndex(s2, s2.getIndex() + sortKeys[i].getOffset()); - - int cmp; - CobolFieldAttribute attr = sortKeys[i].getField().getAttribute(); - int keySize = sortKeys[i].getField().getSize(); - if (attr.isTypeNumeric()) { - cmpField1.setSize(keySize); - cmpField2.setSize(keySize); - - cmpField1.setAttribute(attr); - cmpField2.setAttribute(attr); - - cmp = cmpField1.numericCompareTo(cmpField2); - } else if (attr.isTypeNational()) { - cmp = CobolUtil.nationalCmps(cmpStorage1, cmpStorage2, keySize, sortCollate); - } else { - cmp = CobolUtil.alnumCmps(cmpStorage1, cmpStorage2, keySize, sortCollate); - } - if (cmp != 0) { - return (sortKeys[i].getFlag() == COB_ASCENDING) ? cmp : -cmp; - } - } - return 0; - } - - private static void swap2Indecies(int a, int b) { - int tmp = sortBuffer[a]; - sortBuffer[a] = sortBuffer[b]; - sortBuffer[b] = tmp; - } - - private static void rotate3Indecies(int a, int b, int c) { - int tmp = sortBuffer[c]; - sortBuffer[c] = sortBuffer[b]; - sortBuffer[b] = sortBuffer[a]; - sortBuffer[a] = tmp; - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.file; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import jp.osscons.opensourcecobol.libcobj.common.CobolModule; +import jp.osscons.opensourcecobol.libcobj.common.CobolUtil; +import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; +import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; +import jp.osscons.opensourcecobol.libcobj.data.CobolFieldAttribute; +import jp.osscons.opensourcecobol.libcobj.data.CobolFieldFactory; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; + +/** TODO: 準備中 */ +public class CobolFileSort { + /** TODO: 準備中 */ + protected static final int COBSORTEND = 1; + + /** TODO: 準備中 */ + protected static final int COBSORTABORT = 2; + + /** TODO: 準備中 */ + protected static final int COBSORTFILEERR = 3; + + /** TODO: 準備中 */ + protected static final int COBSORTNOTOPEN = 4; + + /** TODO: 準備中 */ + protected static final int COB_ASCENDING = 0; + + /** TODO: 準備中 */ + protected static final int COB_DESCENDING = 1; + + private static String cob_process_id = ""; + private static int cob_iteration = 0; + + /** TODO: 準備中 */ + protected static int cob_sort_memory = 128 * 1024 * 1024; + + // Javaの標準ライブラリでソートするならtrue + private static boolean SORT_STD_LIB = true; + private static List dataList; + + /** + * libcob/fileio.cのsort_cmpsの実装 + * + * @param s1 TODO: 準備中 + * @param s2 TODO: 準備中 + * @param size TODO: 準備中 + * @param col TODO: 準備中 + * @return TODO: 準備中 + */ + private static int sortCmps( + CobolDataStorage s1, CobolDataStorage s2, int size, CobolDataStorage col) { + if (col != null) { + for (int i = 0; i < size; ++i) { + int ret = (col.getByte(s1.getByte(i)) & 0xff) - (col.getByte(s2.getByte(i)) & 0xff); + if (ret != 0) { + return ret; + } + } + } else { + for (int i = 0; i < size; ++i) { + int ret = (s1.getByte(i) & 0xff) - (s2.getByte(i) & 0xff); + if (ret != 0) { + return ret; + } + } + } + return 0; + } + + private static void uniqueCopy(CobolDataStorage s1, CobolDataStorage s2, int size) { + for (int i = 0; i < size; ++i) { + s1.setByte(s2.getByte(i)); + } + } + + /** + * libcob/fileio.cのcob_file_sort_compareの実装 + * + * @param k1 TODO: 準備中 + * @param k2 TODO: 準備中 + * @param pointer TODO: 準備中 + * @return TODO: 準備中 + */ + private static int sortCompare(CobolItem k1, CobolItem k2, CobolFile pointer) { + CobolFile f = pointer; + long u1; + long u2; + int cmp; + + for (int i = 0; i < f.nkeys; i++) { + AbstractCobolField src = f.keys[i].getField(); + + CobolDataStorage d1 = k1.getItem().copy(); + d1.addIndex(f.keys[i].getOffset()); + + CobolDataStorage d2 = k2.getItem().copy(); + d2.addIndex(f.keys[i].getOffset()); + + AbstractCobolField f1 = + CobolFieldFactory.makeCobolField(src.getSize(), d1, src.getAttribute()); + AbstractCobolField f2 = + CobolFieldFactory.makeCobolField(src.getSize(), d2, src.getAttribute()); + + if (f1.getAttribute().isTypeNumeric()) { + cmp = f1.numericCompareTo(f2); + } else { + cmp = + sortCmps( + f1.getDataStorage(), + f2.getDataStorage(), + f1.getSize(), + f.sort_collating); + } + if (cmp != 0) { + return (f.keys[i].getFlag() == COB_ASCENDING) ? cmp : -cmp; + } + } + byte[] bu1 = new byte[8]; + byte[] bu2 = new byte[8]; + uniqueCopy(new CobolDataStorage(bu1), k1.getUnique(), 8); + uniqueCopy(new CobolDataStorage(bu2), k2.getUnique(), 8); + u1 = ByteBuffer.wrap(bu1).getLong(); + u2 = ByteBuffer.wrap(bu2).getLong(); + return u1 < u2 ? -1 : 1; + } + + /** + * libcob/fileio.cのcob_free_listの実装 + * + * @param q TODO: 準備中 + */ + private static void cob_free_list(CobolItem q) { + // nothing to do + } + + /** + * libcob/fileio.cのcob_new_itemの実装 + * + * @param hp TODO: 準備中 + * @return TODO: 準備中 + */ + private static CobolItem newItem(CobolSort hp) { + CobolItem q; + if (hp.getEmpty() != null) { + q = hp.getEmpty(); + hp.setEmpty(q.getNext()); + } else { + q = new CobolItem(); + } + return q; + } + + /** + * libcob/fileio.cのcob_tmpfileの実装 + * + * @return TODO: 準備中 + */ + private static FileIO tmpfile() { + FileIO fp = new FileIO(); + String s = CobolUtil.getEnv("TMPDIR"); + if (s == null) { + s = CobolUtil.getEnv("TMP"); + if (s == null) { + s = CobolUtil.getEnv("TEMP"); + if (s == null) { + s = "/tmp"; + } + } + } + if ("".equals(cob_process_id)) { + cob_process_id = + java.lang.management.ManagementFactory.getRuntimeMXBean() + .getName() + .split("@")[0]; + } + String filename = String.format("%s/cobsort_%s_%d", s, cob_process_id, cob_iteration); + cob_iteration++; + outer: + try { + Files.delete(Paths.get(filename)); + } catch (IOException e1) { + break outer; + } + FileChannel fc = null; + try { + fc = + FileChannel.open( + Paths.get(filename), + StandardOpenOption.READ, + StandardOpenOption.WRITE, + StandardOpenOption.CREATE, + StandardOpenOption.TRUNCATE_EXISTING); + } catch (IOException e) { + return null; + } + fp.setChannel(fc, null); + return fp; + } + + /** + * libcob/fileio.cのcob_get_temp_fileの実装 + * + * @param hp TODO: 準備中 + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + private static boolean getTempFile(CobolSort hp, int n) { + if (hp.getFile()[n].getFp() == null) { + hp.getFile()[n].setFp(tmpfile()); + if (hp.getFile()[n].getFp() == null) { + // TODO 暫定実装 + System.out.println("SORT is unable to auire temporary file"); + System.exit(0); + } + } else { + hp.getFile()[n].getFp().rewind(); + } + hp.getFile()[n].setCount(0); + return hp.getFile()[n].getFp() == null; + } + + /** + * libcob/fileio.cのcob_sort_queuesの実装 + * + * @param hp TODO: 準備中 + * @return TODO: 準備中 + */ + private static int sortQueues(CobolSort hp) { + CobolItem q; + int source = 0; + int destination; + int move; + int n; + int[] endOfBlock = new int[2]; + + while (hp.getQueue()[source + 1].getCount() != 0) { + destination = source ^ 2; + hp.getQueue()[destination].setCount(0); + hp.getQueue()[destination + 1].setCount(0); + hp.getQueue()[destination].setFirst(null); + hp.getQueue()[destination + 1].setFirst(null); + for (; ; ) { + endOfBlock[0] = hp.getQueue()[source].getCount() == 0 ? 1 : 0; + endOfBlock[1] = hp.getQueue()[source + 1].getCount() == 0 ? 1 : 0; + if (endOfBlock[0] != 0 && endOfBlock[1] != 0) { + break; + } + while (endOfBlock[0] == 0 || endOfBlock[1] == 0) { + if (endOfBlock[0] != 0) { + move = 1; + } else if (endOfBlock[1] != 0) { + move = 0; + } else { + n = + sortCompare( + hp.getQueue()[source].getFirst(), + hp.getQueue()[source + 1].getFirst(), + hp.getPointer()); + move = n < 0 ? 0 : 1; + } + q = hp.getQueue()[source + move].getFirst(); + if (q.getEndOfBlock() != 0) { + endOfBlock[move] = 1; + } + q = hp.getQueue()[source + move].getFirst(); + if (q.getEndOfBlock() != 0) { + endOfBlock[move] = 1; + } + hp.getQueue()[source + move].setFirst(q.getNext()); + if (hp.getQueue()[destination].getFirst() == null) { + hp.getQueue()[destination].setFirst(q); + } else { + hp.getQueue()[destination].getLast().setNext(q); + } + hp.getQueue()[destination].setLast(q); + hp.getQueue()[source + move].setCount( + hp.getQueue()[source + move].getCount() - 1); + hp.getQueue()[destination].setCount(hp.getQueue()[destination].getCount() + 1); + q.setNext(null); + q.setEndOfBlock(0); + } + hp.getQueue()[destination].getLast().setEndOfBlock(1); + destination ^= 1; + } + source = destination & 2; + } + return source; + } + + /** + * libcob/fileio.cのcob_read_itemの実装 + * + * @param hp TODO: 準備中 + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + private static int readItem(CobolSort hp, int n) { + FileIO fp = hp.getFile()[n].getFp(); + if (fp.getc() != 0) { + hp.getQueue()[n].getFirst().setEndOfBlock(1); + } else { + hp.getQueue()[n].getFirst().setEndOfBlock(0); + try { + if (fp.read(hp.getQueue()[n].getFirst().getUnique(), 8) != 8) { + return 1; + } + if (fp.read(hp.getQueue()[n].getFirst().getItem(), hp.getSize()) != hp.getSize()) { + return 1; + } + } catch (IOException e) { + return 1; + } + } + return 0; + } + + /** + * writeBlock内で使う補助メソッド + * + * @param fp TODO: 準備中 + * @param q TODO: 準備中 + * @param hp TODO: 準備中 + * @return 書き込み失敗時true,それ以外はfalse + */ + private static boolean writeItem(FileIO fp, CobolItem q, CobolSort hp) { + byte[] blockByteData = new byte[1]; + blockByteData[0] = q.getBlockByte(); + if (!fp.write(blockByteData, 1)) { + return true; + } + if (!fp.write(q.getUnique(), 8)) { + return true; + } + return fp.write(q.getItem(), hp.getSize()); + } + + /** + * libcob/fileio.cのcob_write_blockの実装 + * + * @param hp TODO: 準備中 + * @param n TODO: 準備中 + * @return TODO: 準備中 + */ + private static int writeBlock(CobolSort hp, int n) { + FileIO fp = hp.getFile()[hp.getDestinationFile()].getFp(); + for (; ; ) { + CobolItem q = hp.getQueue()[n].getFirst(); + if (q == null) { + break; + } + if (writeItem(fp, q, hp)) { + return 1; + } + hp.getQueue()[n].setFirst(q.getNext()); + q.setNext(hp.getEmpty()); + hp.setEmpty(q); + } + hp.getQueue()[n].setCount(0); + hp.getFile()[hp.getDestinationFile()].setCount( + hp.getFile()[hp.getDestinationFile()].getCount() + 1); + if (fp.putc((byte) 1) != 1) { + return 1; + } + return 0; + } + + /** + * libcob/fileio.cのcob_copy_checkの実装 + * + * @param from TODO: 準備中 + */ + private static void copyCheck(CobolFile to, CobolFile from) { + CobolDataStorage toptr = to.record.getDataStorage(); + CobolDataStorage fromptr = from.record.getDataStorage(); + int tosize = to.record.getSize(); + int fromsize = from.record.getSize(); + if (tosize > fromsize) { + for (int i = 0; i < fromsize; ++i) { + toptr.setByte(i, fromptr.getByte(i)); + } + for (int i = 0; i < tosize - fromsize; ++i) { + toptr.setByte(fromsize + i, (byte) ' '); + } + } else { + for (int i = 0; i < tosize; ++i) { + toptr.setByte(i, fromptr.getByte(i)); + } + } + } + + /** + * libcob/fileio.cのcob_file_sort_processの実装 + * + * @param hp TODO: 準備中 + * @return TODO: 準備中 + */ + private static int sortProcess(CobolSort hp) { + hp.setRetrieving(1); + int n = sortQueues(hp); + if (hp.getFilesUsed() == 0) { + hp.setRetrievalQueue(n); + return 0; + } + if (writeBlock(hp, n) != 0) { + return COBSORTFILEERR; + } + for (int i = 0; i < 4; i++) { + hp.getQueue()[i].setFirst(hp.getEmpty()); + hp.setEmpty(hp.getEmpty().getNext()); + hp.getQueue()[i].getFirst().setNext(null); + } + hp.getFile()[0].getFp().rewind(); + hp.getFile()[1].getFp().rewind(); + if (getTempFile(hp, 2)) { + return COBSORTFILEERR; + } + if (getTempFile(hp, 3)) { + return COBSORTFILEERR; + } + int source = 0; + while (hp.getFile()[source].getCount() > 1) { + int destination = source ^ 2; + hp.getFile()[destination].setCount(0); + hp.getFile()[destination + 1].setCount(0); + while (hp.getFile()[source].getCount() > 0) { + if (readItem(hp, source) != 0) { + return COBSORTFILEERR; + } + if (hp.getFile()[source + 1].getCount() > 0) { + if (readItem(hp, source + 1) != 0) { + return COBSORTFILEERR; + } + } else { + hp.getQueue()[source + 1].getFirst().setEndOfBlock(1); + } + while (hp.getQueue()[source].getFirst().getEndOfBlock() == 0 + || hp.getQueue()[source + 1].getFirst().getEndOfBlock() == 0) { + int move; + if (hp.getQueue()[source].getFirst().getEndOfBlock() != 0) { + move = 1; + } else if (hp.getQueue()[source + 1].getFirst().getEndOfBlock() != 0) { + move = 0; + } else { + int res = + sortCompare( + hp.getQueue()[source].getFirst(), + hp.getQueue()[source + 1].getFirst(), + hp.getPointer()); + move = res < 0 ? 0 : 1; + } + if (writeItem( + hp.getFile()[destination].getFp(), + hp.getQueue()[source + move].getFirst(), + hp)) { + return COBSORTFILEERR; + } + if (readItem(hp, source + move) != 0) { + return COBSORTFILEERR; + } + } + hp.getFile()[destination].setCount(hp.getFile()[destination].getCount() + 1); + if (hp.getFile()[destination].getFp().putc((byte) 1) != 1) { + return COBSORTFILEERR; + } + hp.getFile()[source].setCount(hp.getFile()[source].getCount() - 1); + hp.getFile()[source + 1].setCount(hp.getFile()[source + 1].getCount() - 1); + destination ^= 1; + } + source = destination & 2; + for (int i = 0; i < 4; ++i) { + hp.getFile()[i].getFp().rewind(); + } + } + hp.setRetrievalQueue(source); + if (readItem(hp, source) != 0) { + return COBSORTFILEERR; + } + if (readItem(hp, source + 1) != 0) { + return COBSORTFILEERR; + } + return 0; + } + + /** + * libcob/fileio.cのcob_file_sort_submitの実装 + * + * @param p TODO: 準備中 + * @return TODO: 準備中 + */ + private static int sortSubmit(CobolFile f, CobolDataStorage p) { + + if (SORT_STD_LIB) { + dataList.add(new CobolDataStorage(p.getData())); + return 0; + } else { + CobolSort hp = f.filex; + if (hp == null) { + return COBSORTNOTOPEN; + } + if (hp.getRetrieving() != 0) { + return COBSORTABORT; + } + if (hp.getQueue()[0].getCount() + hp.getQueue()[1].getCount() >= hp.getMemory()) { + if (hp.getFilesUsed() == 0) { + if (getTempFile(hp, 0)) { + return COBSORTFILEERR; + } + if (getTempFile(hp, 1)) { + return COBSORTFILEERR; + } + hp.setFilesUsed(1); + hp.setDestinationFile(0); + } + int n = sortQueues(hp); + if (writeBlock(hp, n) != 0) { + return COBSORTFILEERR; + } + hp.setDestinationFile(hp.getDestinationFile() ^ 1); + } + + CobolItem q = newItem(hp); + if (f.record_size != null) { + q.setRecordSize(f.record_size.getInt()); + } else { + q.setRecordSize(hp.getSize()); + } + q.setEndOfBlock(1); + + { + byte[] bytes = new byte[8]; + ByteBuffer buf = ByteBuffer.wrap(bytes); + buf.putInt(hp.getUnique()); + uniqueCopy(q.getUnique(), new CobolDataStorage(bytes), 8); + } + + hp.setUnique(hp.getUnique() + 1); + + byte[] arr = p.getByteArray(0, hp.getSize()); + q.setItem(new CobolDataStorage(arr)); + + MemoryStruct z; + if (hp.getQueue()[0].getCount() <= hp.getQueue()[1].getCount()) { + z = hp.getQueue()[0]; + } else { + z = hp.getQueue()[1]; + } + q.setNext(z.getFirst()); + z.setFirst(q); + z.setCount(z.getCount() + 1); + return 0; + } + } + + /** + * libcob/fileio.cのcob_file_sort_retrieveの実装 + * + * @param p TODO: 準備中 + * @return TODO: 準備中 + */ + private static int sortRetrieve(CobolFile f, CobolDataStorage p) { + CobolSort hp = f.filex; + if (hp == null) { + return COBSORTNOTOPEN; + } + + if (SORT_STD_LIB) { + if (hp.getRetrieving() == 0) { + memorySort(f); + hp.setRetrieving(1); + } + if (dataList.isEmpty()) { + return COBSORTEND; + } + CobolDataStorage storage = dataList.remove(0); + p.setBytes(storage, hp.getSize()); + if (f.record_size != null) { + f.record_size.setInt(hp.getSize()); + } + return 0; + } + + if (hp.getRetrieving() == 0) { + int res = sortProcess(hp); + if (res != 0) { + return res; + } + } + + if (hp.getFilesUsed() != 0) { + int source = hp.getRetrievalQueue(); + int move; + if (hp.getQueue()[source].getFirst().getEndOfBlock() != 0) { + if (hp.getQueue()[source].getFirst().getEndOfBlock() != 0) { + return COBSORTEND; + } + move = 1; + } else if (hp.getQueue()[source].getFirst().getEndOfBlock() != 0) { + move = 0; + } else { + int res = + sortCompare( + hp.getQueue()[source].getFirst(), + hp.getQueue()[source + 1].getFirst(), + hp.getPointer()); + move = res < 0 ? 0 : 1; + } + for (int i = 0; i < hp.getSize(); ++i) { + p.setByte(i, hp.getQueue()[source + move].getFirst().getItem().getByte(i)); + } + if (readItem(hp, source + move) != 0) { + return COBSORTFILEERR; + } + } else { + MemoryStruct z = hp.getQueue()[hp.getRetrievalQueue()]; + if (z.getFirst() == null) { + return COBSORTEND; + } + for (int i = 0; i < hp.getSize(); ++i) { + p.setByte(i, z.getFirst().getItem().getByte(i)); + } + if (f.record_size != null) { + f.record_size.setInt(z.getFirst().getRecordSize()); + } + CobolItem next = z.getFirst().getNext(); + z.getFirst().setNext(hp.getEmpty()); + hp.setEmpty(z.getFirst()); + z.setFirst(next); + } + return 0; + } + + private static void memorySort(CobolFile f) { + dataList.sort( + new Comparator() { + @Override + public int compare(CobolDataStorage data1, CobolDataStorage data2) { + int cmp; + + for (int i = 0; i < f.nkeys; i++) { + AbstractCobolField src = f.keys[i].getField(); + + CobolDataStorage d1 = data1.copy(); + d1.addIndex(f.keys[i].getOffset()); + + CobolDataStorage d2 = data2.copy(); + d2.addIndex(f.keys[i].getOffset()); + + AbstractCobolField f1 = + CobolFieldFactory.makeCobolField( + src.getSize(), d1, src.getAttribute()); + AbstractCobolField f2 = + CobolFieldFactory.makeCobolField( + src.getSize(), d2, src.getAttribute()); + + if (f1.getAttribute().isTypeNumeric()) { + cmp = f1.numericCompareTo(f2); + } else { + cmp = + sortCmps( + f1.getDataStorage(), + f2.getDataStorage(), + f1.getSize(), + f.sort_collating); + } + if (cmp != 0) { + return (f.keys[i].getFlag() == COB_ASCENDING) ? cmp : -cmp; + } + } + return 0; + } + }); + } + + // libcob/fileio.cのcob_file_sort_initの実装 + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + * @param nkeys TODO: 準備中 + * @param collatingSequence TODO: 準備中 + * @param sortReturn TODO: 準備中 + * @param fnstatus TODO: 準備中 + */ + public static void sortInit( + CobolFile f, + int nkeys, + CobolDataStorage collatingSequence, + CobolDataStorage sortReturn, + AbstractCobolField fnstatus) { + int sizeOfSizeT = 8; + CobolSort p = new CobolSort(); + p.setFnstatus(fnstatus); + p.setSize(f.record_max); + p.setrSize(f.record_max + sizeOfSizeT); + p.setwSize(f.record_max + sizeOfSizeT + 1); + p.setPointer(f); + p.setSortReturn(sortReturn); + sortReturn.set(0); + // opensource COBOLでsizeof(struct cobitem) == 32だっため,32を使用した + p.setMemory(cob_sort_memory / (p.getSize() + 32)); + dataList = new ArrayList(); + f.filex = p; + f.keys = new CobolFileKey[nkeys]; + for (int i = 0; i < nkeys; ++i) { + f.keys[i] = new CobolFileKey(); + } + f.nkeys = 0; + if (collatingSequence != null) { + f.sort_collating = collatingSequence; + } else { + f.sort_collating = CobolModule.getCurrentModule().collating_sequence; + } + f.saveStatus(CobolFile.COB_STATUS_00_SUCCESS, fnstatus); + } + + // libcob/fileio.cのcob_file_sort_initの実装 + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + * @param nkeys TODO: 準備中 + * @param collatingSequence TODO: 準備中 + * @param sortReturn TODO: 準備中 + * @param fnstatus TODO: 準備中 + */ + public static void sortInit( + CobolFile f, + int nkeys, + int collatingSequence, + CobolDataStorage sortReturn, + AbstractCobolField fnstatus) { + sortInit(f, nkeys, null, sortReturn, fnstatus); + } + + // libcob/fileio.cのcob_file_sort_init_keyの実装 + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + * @param flag TODO: 準備中 + * @param field TODO: 準備中 + * @param offset TODO: 準備中 + */ + public static void sortInitKey(CobolFile f, int flag, AbstractCobolField field, int offset) { + f.keys[f.nkeys].setFlag(flag); + f.keys[f.nkeys].setField(field); + f.keys[f.nkeys].setOffset(offset); + f.nkeys++; + } + + // libcob/fileio.cのcob_file_sort_usingの実装 + /** + * TODO: 準備中 + * + * @param sortFile TODO: 準備中 + * @param dataFile TODO: 準備中 + */ + public static void sortUsing(CobolFile sortFile, CobolFile dataFile) { + dataFile.open(CobolFile.COB_OPEN_INPUT, 0, null); + for (; ; ) { + dataFile.read(null, null, CobolFile.COB_READ_NEXT); + if (dataFile.file_status[0] != (byte) '0') { + break; + } + copyCheck(sortFile, dataFile); + int ret = sortSubmit(sortFile, sortFile.record.getDataStorage()); + if (ret != 0) { + break; + } + } + dataFile.close(CobolFile.COB_CLOSE_NORMAL, null); + } + + // libcob/fileio.cのcob_file_sort_givingの実装 + /** + * TODO: 準備中 + * + * @param sortFile TODO: 準備中 + * @param varcnt TODO: 準備中 + * @param fbase TODO: 準備中 + * @throws CobolStopRunException TODO: 準備中 + */ + public static void sortGiving(CobolFile sortFile, int varcnt, CobolFile... fbase) + throws CobolStopRunException { + if (SORT_STD_LIB) { + for (int i = 0; i < varcnt; i++) { + fbase[i].open(CobolFile.COB_OPEN_OUTPUT, 0, null); + } + + int cntRec = 0; + memorySort(sortFile); + for (CobolDataStorage d : dataList) { + for (int i = 0; i < varcnt; i++) { + int opt; + if (fbase[i].special != 0 + || fbase[i].organization == CobolFile.COB_ORG_LINE_SEQUENTIAL) { + opt = CobolFile.COB_WRITE_BEFORE | CobolFile.COB_WRITE_LINES | 1; + } else { + opt = 0; + } + sortFile.record.getDataStorage().memcpy(d, sortFile.record.getSize()); + copyCheck(fbase[i], sortFile); + fbase[i].write(fbase[i].record, opt, null); + } + cntRec++; + } + sortFile.file_status[0] = '1'; + sortFile.file_status[1] = '0'; + + for (int i = 0; i < varcnt; i++) { + fbase[i].close(CobolFile.COB_CLOSE_NORMAL, null); + } + CobolUtil.verboseOutput(String.format("END OF SORT/MERGE, RECORD=%d.", cntRec)); + + } else { + + for (int i = 0; i < varcnt; i++) { + fbase[i].open(CobolFile.COB_OPEN_OUTPUT, 0, null); + } + int cntRec = 0; + for (; ; ) { + int ret = sortRetrieve(sortFile, sortFile.record.getDataStorage()); + if (ret != 0) { + if (ret == COBSORTEND) { + sortFile.file_status[0] = '1'; + sortFile.file_status[1] = '0'; + } else { + CobolSort hp = sortFile.filex; + hp.getSortReturn().set(16); + sortFile.file_status[0] = '3'; + sortFile.file_status[1] = '0'; + } + break; + } + for (int i = 0; i < varcnt; i++) { + int opt; + if (fbase[i].special != 0 + || fbase[i].organization == CobolFile.COB_ORG_LINE_SEQUENTIAL) { + opt = CobolFile.COB_WRITE_BEFORE | CobolFile.COB_WRITE_LINES | 1; + } else { + opt = 0; + } + copyCheck(fbase[i], sortFile); + fbase[i].write(fbase[i].record, opt, null); + } + cntRec++; + } + for (int i = 0; i < varcnt; i++) { + fbase[i].close(CobolFile.COB_CLOSE_NORMAL, null); + } + CobolUtil.verboseOutput(String.format("END OF SORT/MERGE, RECORD=%d.", cntRec)); + } + } + + // libcob/fileio.cのcob_file_sort_closeの実装 + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + */ + public static void sortClose(CobolFile f) { + AbstractCobolField fnstatus = null; + CobolSort hp = f.filex; + + if (hp != null) { + fnstatus = hp.getFnstatus(); + cob_free_list(hp.getEmpty()); + for (int i = 0; i < 4; ++i) { + cob_free_list(hp.getQueue()[i].getFirst()); + if (hp.getFile()[i].getFp() != null) { + hp.getFile()[i].getFp().close(); + } + } + } + f.filex = null; + f.saveStatus(CobolFile.COB_STATUS_00_SUCCESS, fnstatus); + } + + // libcob/fileio.cのcob_file_releaseの実装 + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + */ + public static void performRelease(CobolFile f) { + AbstractCobolField fnstatus = null; + CobolSort hp = f.filex; + + if (hp != null) { + fnstatus = hp.getFnstatus(); + } + int ret = CobolFileSort.sortSubmit(f, f.record.getDataStorage()); + switch (ret) { + case 0: + f.saveStatus(CobolFile.COB_STATUS_00_SUCCESS, fnstatus); + return; + default: + if (hp != null) { + hp.getSortReturn().set(16); + } + f.saveStatus(CobolFile.COB_STATUS_30_PERMANENT_ERROR, fnstatus); + return; + } + } + + // libcob/fileio.cのcob_file_returnの実装 + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + */ + public static void performReturn(CobolFile f) { + AbstractCobolField fnstatus = null; + CobolSort hp = f.filex; + if (hp != null) { + fnstatus = hp.getFnstatus(); + } + + int ret = CobolFileSort.sortRetrieve(f, f.record.getDataStorage()); + switch (ret) { + case 0: + f.saveStatus(CobolFile.COB_STATUS_00_SUCCESS, fnstatus); + return; + case CobolFileSort.COBSORTEND: + f.saveStatus(CobolFile.COB_STATUS_10_END_OF_FILE, fnstatus); + return; + default: + if (hp != null) { + hp.getSortReturn().set(16); + } + f.saveStatus(CobolFile.COB_STATUS_30_PERMANENT_ERROR, fnstatus); + return; + } + } + + /* Table sort */ + private static int sortNKeys; + private static CobolFileKey[] sortKeys; + private static CobolDataStorage sortCollate; + private static CobolDataStorage pivotStorage = new CobolDataStorage(); + private static CobolDataStorage leftStorage = new CobolDataStorage(); + private static CobolDataStorage rightStorage = new CobolDataStorage(); + private static CobolDataStorage cmpStorage1 = new CobolDataStorage(); + private static CobolDataStorage cmpStorage2 = new CobolDataStorage(); + private static CobolDataStorage copyBuffer = null; + private static CobolDataStorage tmpRecord = new CobolDataStorage(); + private static int copyBufferSizeMax = 0; + private static int[] sortBuffer = null; + private static AbstractCobolField cmpField1 = + CobolFieldFactory.makeCobolField( + 0, + cmpStorage1, + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null)); + private static AbstractCobolField cmpField2 = + CobolFieldFactory.makeCobolField( + 0, + cmpStorage2, + new CobolFieldAttribute( + CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null)); + + /** + * TODO: 準備中 + * + * @param nkeys TODO: 準備中 + * @param collatingSequence TODO: 準備中 + */ + public static void sortTableInit(int nkeys, int collatingSequence) { + sortTableInit(nkeys, null); + } + + /** + * TODO: 準備中 + * + * @param nkeys TODO: 準備中 + * @param collatingSequence TODO: 準備中 + */ + public static void sortTableInit(int nkeys, CobolDataStorage collatingSequence) { + sortNKeys = 0; + if (sortKeys == null || sortKeys.length < nkeys) { + sortKeys = new CobolFileKey[nkeys]; + } + if (collatingSequence != null) { + sortCollate = collatingSequence; + } else { + sortCollate = CobolModule.getCurrentModule().collating_sequence; + } + } + + /** + * TODO: 準備中 + * + * @param flag TODO: 準備中 + * @param field TODO: 準備中 + * @param offset TODO: 準備中 + */ + public static void sortTableInitKey(int flag, AbstractCobolField field, int offset) { + if (sortKeys[sortNKeys] == null) { + sortKeys[sortNKeys] = new CobolFileKey(); + } + sortKeys[sortNKeys].setFlag(flag); + sortKeys[sortNKeys].setField( + CobolFieldFactory.makeCobolField( + field.getSize(), (CobolDataStorage) null, field.getAttribute())); + sortKeys[sortNKeys].setOffset(offset); + sortNKeys++; + } + + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + * @param n TODO: 準備中 + */ + public static void sortTable(AbstractCobolField f, int n) { + int recordSize = f.getSize(); + if (sortBuffer == null || sortBuffer.length < n) { + sortBuffer = new int[n]; + } + for (int i = 0; i < n; ++i) { + sortBuffer[i] = i; + } + CobolDataStorage baseStorage = f.getDataStorage(); + int baseStorageBaseIndex = baseStorage.getIndex(); + indexQuickSort(f.getDataStorage(), 0, n, recordSize); + + int copyBufferSize = n * f.getSize(); + if (copyBuffer == null || copyBufferSizeMax < copyBufferSize) { + copyBuffer = new CobolDataStorage(copyBufferSize); + copyBufferSizeMax = copyBufferSize; + } + + for (int i = 0; i < n; ++i, copyBuffer.addIndex(recordSize)) { + tmpRecord.setDataRefAndIndex( + baseStorage, baseStorageBaseIndex + recordSize * sortBuffer[i]); + copyBuffer.memcpy(tmpRecord, recordSize); + } + copyBuffer.setIndex(0); + baseStorage.memcpy(copyBuffer, copyBufferSize); + } + + private static void indexQuickSort( + CobolDataStorage base, int mostLeft, int mostRight, int recordSize) { + + if (mostRight - mostLeft <= 1) { + return; + } + + int pivot = (mostRight + mostLeft) / 2; + int left = mostLeft, right = mostRight - 1; + + while (true) { + pivotStorage.setDataRefAndIndex(base, base.getIndex() + sortBuffer[pivot] * recordSize); + boolean elementBiggerThanPivot = false; + for (; left < pivot; ++left) { + leftStorage.setDataRefAndIndex( + base, base.getIndex() + sortBuffer[left] * recordSize); + if (compareStorageForSort(leftStorage, pivotStorage) > 0) { + elementBiggerThanPivot = true; + break; + } + } + boolean elementSmallerThanPivot = false; + for (; right > pivot; --right) { + rightStorage.setDataRefAndIndex( + base, base.getIndex() + sortBuffer[right] * recordSize); + if (compareStorageForSort(pivotStorage, rightStorage) > 0) { + elementSmallerThanPivot = true; + break; + } + } + if (elementBiggerThanPivot && elementSmallerThanPivot) { + swap2Indecies(left, right); + ++left; + --right; + } else if (elementBiggerThanPivot && !elementSmallerThanPivot) { + if (left + 1 == pivot) { + swap2Indecies(left, pivot); + } else { + rotate3Indecies(pivot, pivot - 1, left); + } + --pivot; + } else if (!elementBiggerThanPivot && elementSmallerThanPivot) { + if (right - 1 == pivot) { + swap2Indecies(pivot, right); + } else { + rotate3Indecies(pivot, pivot + 1, right); + } + ++pivot; + } else { + break; + } + } + indexQuickSort(base, mostLeft, pivot, recordSize); + indexQuickSort(base, pivot + 1, mostRight, recordSize); + } + + private static int compareStorageForSort(CobolDataStorage s1, CobolDataStorage s2) { + for (int i = 0; i < sortNKeys; ++i) { + + cmpStorage1.setDataRefAndIndex(s1, s1.getIndex() + sortKeys[i].getOffset()); + cmpStorage2.setDataRefAndIndex(s2, s2.getIndex() + sortKeys[i].getOffset()); + + int cmp; + CobolFieldAttribute attr = sortKeys[i].getField().getAttribute(); + int keySize = sortKeys[i].getField().getSize(); + if (attr.isTypeNumeric()) { + cmpField1.setSize(keySize); + cmpField2.setSize(keySize); + + cmpField1.setAttribute(attr); + cmpField2.setAttribute(attr); + + cmp = cmpField1.numericCompareTo(cmpField2); + } else if (attr.isTypeNational()) { + cmp = CobolUtil.nationalCmps(cmpStorage1, cmpStorage2, keySize, sortCollate); + } else { + cmp = CobolUtil.alnumCmps(cmpStorage1, cmpStorage2, keySize, sortCollate); + } + if (cmp != 0) { + return (sortKeys[i].getFlag() == COB_ASCENDING) ? cmp : -cmp; + } + } + return 0; + } + + private static void swap2Indecies(int a, int b) { + int tmp = sortBuffer[a]; + sortBuffer[a] = sortBuffer[b]; + sortBuffer[b] = tmp; + } + + private static void rotate3Indecies(int a, int b, int c) { + int tmp = sortBuffer[c]; + sortBuffer[c] = sortBuffer[b]; + sortBuffer[b] = sortBuffer[a]; + sortBuffer[a] = tmp; + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolIndexedFile.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolIndexedFile.java index 854d6d00..368dc37f 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolIndexedFile.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolIndexedFile.java @@ -1,777 +1,1396 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.file; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.Optional; -import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; -import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; -import org.sqlite.SQLiteConfig; -import org.sqlite.SQLiteErrorCode; - -/** TODO: 準備中 */ -public class CobolIndexedFile extends CobolFile { - private Optional cursor; - private boolean updateWhileReading = false; - private boolean indexedFirstRead = true; - private boolean callStart = false; - private boolean commitOnModification = true; - - /** TODO: 準備中 */ - public static final int COB_EQ = 1; - /** TODO: 準備中 */ - public static final int COB_LT = 2; - /** TODO: 準備中 */ - public static final int COB_LE = 3; - /** TODO: 準備中 */ - public static final int COB_GT = 4; - /** TODO: 準備中 */ - public static final int COB_GE = 5; - /** TODO: 準備中 */ - public static final int COB_NE = 6; - - /** - * TODO: 準備中 - * - * @param selectName TODO: 準備中 - * @param fileStatus TODO: 準備中 - * @param assign TODO: 準備中 - * @param record TODO: 準備中 - * @param recordSize TODO: 準備中 - * @param recordMin TODO: 準備中 - * @param recordMax TODO: 準備中 - * @param nkeys TODO: 準備中 - * @param keys TODO: 準備中 - * @param organization TODO: 準備中 - * @param accessMode TODO: 準備中 - * @param lockMode TODO: 準備中 - * @param openMode TODO: 準備中 - * @param flagOptional TODO: 準備中 - * @param lastOpenMode TODO: 準備中 - * @param special TODO: 準備中 - * @param flagNonexistent TODO: 準備中 - * @param flagEndOfFile TODO: 準備中 - * @param flagBeginOfFile TODO: 準備中 - * @param flagFirstRead TODO: 準備中 - * @param flagReadDone TODO: 準備中 - * @param flagSelectFeatures TODO: 準備中 - * @param flagNeedsNl TODO: 準備中 - * @param flagNeedsTop TODO: 準備中 - * @param fileVersion TODO: 準備中 - */ - public CobolIndexedFile( - String selectName, - byte[] fileStatus, - AbstractCobolField assign, - AbstractCobolField record, - AbstractCobolField recordSize, - int recordMin, - int recordMax, - int nkeys, - CobolFileKey[] keys, - char organization, - char accessMode, - char lockMode, - char openMode, - boolean flagOptional, - char lastOpenMode, - char special, - boolean flagNonexistent, - boolean flagEndOfFile, - boolean flagBeginOfFile, - char flagFirstRead, - boolean flagReadDone, - char flagSelectFeatures, - boolean flagNeedsNl, - boolean flagNeedsTop, - char fileVersion) { - super( - selectName, - fileStatus, - assign, - record, - recordSize, - recordMin, - recordMax, - nkeys, - keys, - organization, - accessMode, - lockMode, - openMode, - flagOptional, - lastOpenMode, - special, - flagNonexistent, - flagEndOfFile, - flagBeginOfFile, - flagFirstRead, - flagReadDone, - flagSelectFeatures, - flagNeedsNl, - flagNeedsTop, - fileVersion); - } - - private static String getIndexName(int index) { - return String.format("index%d", index); - } - - private static String getSubIndexName(int index) { - return String.format("subindex%d", index); - } - - /** - * TODO: 準備中 - * - * @param index TODO: 準備中 - * @return TODO: 準備中 - */ - public static String getTableName(int index) { - return String.format("table%d", index); - } - - /** - * TODO: 準備中 - * - * @param index TODO: 準備中 - * @return TODO: 準備中 - */ - public static String getCursorName(int index) { - return String.format("cursor%d", index); - } - - private static String getConstraintName(int index) { - return String.format("constraint%d", index); - } - - /** - * TODO: 準備中 - * - * @param commitOnModification TODO: 準備中 - */ - public void setCommitOnModification(boolean commitOnModification) { - this.commitOnModification = commitOnModification; - } - - /** Equivalent to DBT_SET in libcob/fileio.c */ - private byte[] DBT_SET(AbstractCobolField field) { - return field.getDataStorage().getByteArray(0, field.getSize()); - } - - @Override - public int open_(String filename, int mode, int sharing) { - IndexedFile p = new IndexedFile(); - - SQLiteConfig config = new SQLiteConfig(); - config.setReadOnly(mode == COB_OPEN_INPUT); - - if (mode == COB_OPEN_OUTPUT) { - Path path = Paths.get(filename); - try { - Files.deleteIfExists(path); - } catch (IOException e) { - return COB_STATUS_30_PERMANENT_ERROR; - } - } - - boolean fileExists = new java.io.File(filename).exists(); - - p.connection = null; - try { - p.connection = DriverManager.getConnection("jdbc:sqlite:" + filename, config.toProperties()); - p.connection.setAutoCommit(false); - } catch (SQLException e) { - int errorCode = e.getErrorCode(); - if (errorCode == SQLiteErrorCode.SQLITE_BUSY.code) { - return COB_STATUS_61_FILE_SHARING; - } else { - return ENOENT; - } - } catch (Exception e) { - return COB_STATUS_30_PERMANENT_ERROR; - } - - p.filenamelen = filename.length(); - p.last_dupno = new int[this.nkeys]; - p.rewrite_sec_key = new int[this.nkeys]; - - int maxsize = 0; - for (int i = 0; i < this.nkeys; ++i) { - if (this.keys[i].getField().getSize() > maxsize) { - maxsize = this.keys[i].getField().getSize(); - } - } - - if (mode == COB_OPEN_OUTPUT - || (!fileExists && (mode == COB_OPEN_EXTEND || mode == COB_OPEN_I_O))) { - try { - for (int i = 0; i < this.nkeys; ++i) { - String tableName = getTableName(i); - Statement statement = p.connection.createStatement(); - if (i == 0) { - statement.execute( - String.format( - "create table %s (key blob not null primary key, value blob not null)", - tableName)); - } else { - if (this.keys[i].getFlag() == 0) { - statement.execute( - String.format( - "create table %s (key blob not null primary key, value blob not null," - + " constraint %s foreign key (value) references %s (key))", - tableName, getConstraintName(i), getTableName(0))); - } else { - statement.execute( - String.format( - "create table %s (key blob not null, value blob not null, dupNo integer not" - + " null, constraint %s foreign key (value) references %s (key))", - tableName, getConstraintName(i), getTableName(0))); - } - statement.execute( - String.format("create index %s on %s(value)", getSubIndexName(i), tableName)); - } - statement.execute( - String.format("create index %s on %s(key)", getIndexName(i), tableName)); - statement.close(); - } - this.writeMetaData(p); - if (this.commitOnModification) { - p.connection.commit(); - } - } catch (SQLException e) { - return COB_STATUS_30_PERMANENT_ERROR; - } - } - - p.temp_key = new CobolDataStorage(maxsize + 4); - this.filei = p; - p.key_index = 0; - p.last_key = null; - - p.filename = filename; - p.write_cursor_open = false; - p.record_locked = false; - - p.key = DBT_SET(this.keys[0].getField()); - this.updateWhileReading = false; - this.indexedFirstRead = true; - this.callStart = false; - - return 0; - } - - // Write a metadata to the database - private void writeMetaData(IndexedFile p) throws SQLException { - Statement statement = p.connection.createStatement(); - // Create a table to store metadata - statement.execute( - "create table metadata_string_int (key text not null primary key, value integer not null)"); - statement.execute( - "create table metadata_key (idx integer not null primary key, offset integer not null, size integer not null, duplicate boolean)"); - statement.close(); - - // Store the size of a record - PreparedStatement recordSizePreparedStmt = - p.connection.prepareStatement("insert into metadata_string_int values ('record_size', ?)"); - recordSizePreparedStmt.setInt(1, this.record_max); - recordSizePreparedStmt.execute(); - recordSizePreparedStmt.close(); - - // Store information of all keys - PreparedStatement keyPreparedStmt = - p.connection.prepareStatement("insert into metadata_key values (?, ?, ?, ?)"); - for (int i = 0; i < this.nkeys; i++) { - keyPreparedStmt.setInt(1, i); - keyPreparedStmt.setInt( - 2, - this.keys[i].getField().getDataStorage().getIndex() - - this.record.getDataStorage().getIndex()); - keyPreparedStmt.setInt(3, this.keys[i].getField().getSize()); - keyPreparedStmt.setBoolean(4, this.keys[i].getFlag() != 0); - keyPreparedStmt.execute(); - } - keyPreparedStmt.close(); - } - - @Override - public int close_(int opt) { - IndexedFile p = this.filei; - - this.closeCursor(); - - try { - p.connection.close(); - } catch (SQLException e) { - return COB_STATUS_30_PERMANENT_ERROR; - } - return COB_STATUS_00_SUCCESS; - } - - // Equivalent to indexed_start_internal in libcob/fileio.c - /** - * TODO: 準備中 - * - * @param cond TODO: 準備中 - * @param key TODO: 準備中 - * @param readOpts TODO: 準備中 - * @param testLock TODO: 準備中 - * @return TODO: 準備中 - */ - public int indexed_start_internal( - int cond, AbstractCobolField key, int readOpts, boolean testLock) { - IndexedFile p = this.filei; - for (p.key_index = 0; p.key_index < this.nkeys; p.key_index++) { - if (this.keys[p.key_index].getField().getDataStorage().isSame(key.getDataStorage())) { - break; - } - } - - p.key = DBT_SET(key); - - boolean isDuplicate = this.keys[p.key_index].getFlag() != 0; - - this.cursor = IndexedCursor.createCursor(p.connection, p.key, p.key_index, isDuplicate, cond); - if (!this.cursor.isPresent()) { - return COB_STATUS_30_PERMANENT_ERROR; - } - - IndexedCursor cursor = this.cursor.get(); - Optional optionalResult = cursor.next(); - if (optionalResult.isPresent()) { - FetchResult result = optionalResult.get(); - p.key = result.key; - p.data = result.value; - this.indexedFirstRead = false; - return COB_STATUS_00_SUCCESS; - } else { - return COB_STATUS_23_KEY_NOT_EXISTS; - } - } - - @Override - public int start_(int cond, AbstractCobolField key) { - int ret = indexed_start_internal(cond, key, 0, false); - if (ret == COB_STATUS_00_SUCCESS) { - this.callStart = true; - } - return ret; - } - - @Override - public int read_(AbstractCobolField key, int readOpts) { - IndexedFile p = this.filei; - boolean testLock = false; - this.callStart = false; - int ret = this.indexed_start_internal(COB_EQ, key, readOpts, testLock); - if (ret != COB_STATUS_00_SUCCESS) { - return ret; - } - - this.record.setSize(p.data.length); - this.record.getDataStorage().memcpy(p.data, p.data.length); - - return COB_STATUS_00_SUCCESS; - } - - @Override - public int readNext(int readOpts) { - IndexedFile p = this.filei; - if (this.callStart) { - this.callStart = false; - this.indexedFirstRead = false; - this.record.setSize(p.data.length); - if (this.cursor.isPresent()) { - IndexedCursor cursor = this.cursor.get(); - if ((readOpts & CobolFile.COB_READ_PREVIOUS) != 0 - && cursor.getComparator() == COB_LE - && this.record.getDataStorage().memcmp(p.data, p.data.length) != 0) { - this.callStart = false; - return this.readNext(readOpts); - } - } - this.record.getDataStorage().memcpy(p.data, p.data.length); - return COB_STATUS_00_SUCCESS; - } - - boolean isDuplicate = this.keys[p.key_index].getFlag() != 0; - if (this.indexedFirstRead || this.flag_begin_of_file) { - this.cursor = - IndexedCursor.createCursor(p.connection, p.key, p.key_index, isDuplicate, COB_GE); - if (!this.cursor.isPresent()) { - return COB_STATUS_10_END_OF_FILE; - } - this.cursor.get().moveToFirst(); - } else if (this.flag_end_of_file) { - this.cursor = - IndexedCursor.createCursor(p.connection, p.key, p.key_index, isDuplicate, COB_LE); - if (!this.cursor.isPresent()) { - return COB_STATUS_30_PERMANENT_ERROR; - } - this.cursor.get().moveToLast(); - } else if (this.updateWhileReading) { - this.updateWhileReading = false; - if (!this.cursor.isPresent()) { - return COB_STATUS_30_PERMANENT_ERROR; - } - IndexedCursor oldCursor = this.cursor.get(); - Optional newCursor = oldCursor.reloadCursor(); - if (!newCursor.isPresent()) { - this.cursor = Optional.of(oldCursor); - } else { - oldCursor.close(); - this.cursor = newCursor; - } - } - - if (!this.cursor.isPresent()) { - return COB_STATUS_30_PERMANENT_ERROR; - } - - IndexedCursor cursor = this.cursor.get(); - - final CursorReadOption cursorOpt; - if ((readOpts & COB_READ_PREVIOUS) != 0) { - cursorOpt = CursorReadOption.PREV; - cursor.setComparator(COB_LE); - } else { - cursorOpt = CursorReadOption.NEXT; - cursor.setComparator(COB_GE); - } - - Optional optionalResult = cursor.read(cursorOpt); - - if (!optionalResult.isPresent()) { - this.indexedFirstRead = false; - return COB_STATUS_10_END_OF_FILE; - } - - FetchResult result = optionalResult.get(); - p.key = result.key; - p.data = result.value; - - this.record.setSize(p.data.length); - this.record.getDataStorage().memcpy(p.data, p.data.length); - - this.indexedFirstRead = false; - return COB_STATUS_00_SUCCESS; - } - - private void closeCursor() { - if (this.cursor != null) { - if (this.cursor.isPresent()) { - this.cursor.get().close(); - } - } - } - - private boolean keyExistsInTable(IndexedFile p, int index, byte[] key) { - String query = String.format("select * from %s where key = ?", getTableName(index)); - try (PreparedStatement selectStatement = p.connection.prepareStatement(query)) { - selectStatement.setBytes(1, key); - selectStatement.setFetchSize(0); - ResultSet rs = selectStatement.executeQuery(); - return rs.next(); - } catch (SQLException e) { - return false; - } - } - - private boolean isDuplicateColumn(int index) { - return this.keys[index].getFlag() != 0; - } - - private int getNextKeyDupNo(Connection conn, int index, byte[] key) { - try { - PreparedStatement selectStatement = - conn.prepareStatement( - String.format("select ifnull(max(dupNo), -1) from %s", getTableName(index))); - ResultSet rs = selectStatement.executeQuery(); - return rs.getInt(1) + 1; - } catch (SQLException e) { - return 0; - } - } - - private int returnWith(IndexedFile p, boolean closeCursor, int index, int returnCode) { - if (closeCursor) { - this.closeCursor(); - p.write_cursor_open = false; - } - return returnCode; - } - - /** Equivalent to indexed_write_internal in libcob/fileio.c */ - private int indexed_write_internal(boolean rewrite, int opt) { - IndexedFile p = this.filei; - - boolean closeCursor; - p.write_cursor_open = true; - closeCursor = true; - - if (this.nkeys > 1 && !rewrite) { - if (this.check_alt_keys(false)) { - return returnWith(p, closeCursor, 0, COB_STATUS_22_KEY_EXISTS); - } - p.key = DBT_SET(this.keys[0].getField()); - } - - if (keyExistsInTable(p, 0, p.key)) { - return COB_STATUS_22_KEY_EXISTS; - } - - // insert into the primary table - p.data = DBT_SET(this.record); - try (PreparedStatement insertStatement = - p.connection.prepareStatement( - String.format("insert into %s values (?, ?)", getTableName(0)))) { - insertStatement.setBytes(1, p.key); - insertStatement.setBytes(2, p.data); - insertStatement.execute(); - if (this.commitOnModification) { - p.connection.commit(); - } - } catch (SQLException e) { - return returnWith(p, closeCursor, 0, COB_STATUS_51_RECORD_LOCKED); - } - - p.data = p.key; - - // insert into sub tables - for (int i = 1; i < this.nkeys; i++) { - - p.key = DBT_SET(this.keys[i].getField()); - try { - if (!isDuplicateColumn(i) && keyExistsInTable(p, i, p.key)) { - return returnWith(p, closeCursor, 0, COB_STATUS_22_KEY_EXISTS); - } - - PreparedStatement insertStatement; - if (isDuplicateColumn(i)) { - int dupNo = getNextKeyDupNo(p.connection, i, p.key); - insertStatement = - p.connection.prepareStatement( - String.format("insert into %s values (?, ?, ?)", getTableName(i))); - insertStatement.setBytes(1, p.key); - insertStatement.setBytes(2, p.data); - insertStatement.setInt(3, dupNo); - } else { - insertStatement = - p.connection.prepareStatement( - String.format("insert into %s values (?, ?)", getTableName(i))); - insertStatement.setBytes(1, p.key); - insertStatement.setBytes(2, p.data); - } - insertStatement.execute(); - insertStatement.close(); - if (this.commitOnModification) { - p.connection.commit(); - } - } catch (SQLException e) { - return returnWith(p, closeCursor, 0, COB_STATUS_51_RECORD_LOCKED); - } - } - - this.updateWhileReading = true; - - return returnWith(p, closeCursor, 0, COB_STATUS_00_SUCCESS); - } - - @Override - public int write_(int opt) { - IndexedFile p = this.filei; - - p.key = DBT_SET(this.keys[0].getField()); - if (p.last_key == null) { - p.last_key = new CobolDataStorage(p.key.length); - - } else if (this.access_mode == COB_ACCESS_SEQUENTIAL) { - byte[] keyBytes = p.key; - if (p.last_key.memcmp(keyBytes, keyBytes.length) > 0) { - return COB_STATUS_21_KEY_INVALID; - } - } - - byte[] keyBytes = p.key; - p.last_key.memcpy(keyBytes, keyBytes.length); - - return indexed_write_internal(false, opt); - } - - /** Equivalent to check_alt_keys in libcob/fileio.c */ - private boolean check_alt_keys(boolean rewrite) { - IndexedFile p = this.filei; - - byte[] primaryKey = DBT_SET(this.keys[0].getField()); - for (int i = 1; i < this.nkeys; ++i) { - if (this.keys[i].getFlag() == 0) { - p.key = DBT_SET(this.keys[i].getField()); - if (rewrite) { - if (checkTable(p, i, p.key, primaryKey)) { - return true; - } - } else { - if (keyExistsInTable(p, i, p.key)) { - return true; - } - } - } - } - return false; - } - - private static boolean checkTable(IndexedFile p, int index, byte[] key, byte[] primaryKey) { - String query = - String.format("select key from %s " + "where key = ? and value = ?", getTableName(index)); - try (PreparedStatement selectStatement = p.connection.prepareStatement(query)) { - selectStatement.setBytes(1, key); - selectStatement.setBytes(2, primaryKey); - selectStatement.setFetchSize(0); - ResultSet rs = selectStatement.executeQuery(); - return rs.next(); - } catch (SQLException e) { - return false; - } - } - - @Override - /** Equivalent to indexed_rewrite in libcob/fileio.c */ - public int rewrite_(int opt) { - IndexedFile p = this.filei; - - p.write_cursor_open = true; - - if (this.access_mode == COB_ACCESS_SEQUENTIAL - && !IndexedCursor.matchKeyHead(p.key, DBT_SET(this.keys[0].getField()))) { - return COB_STATUS_21_KEY_INVALID; - } - - p.key = DBT_SET(this.keys[0].getField()); - - int ret = this.indexed_delete_internal(true); - - if (ret != COB_STATUS_00_SUCCESS) { - p.write_cursor_open = false; - return ret; - } - - return this.indexed_write_internal(true, opt); - } - - /** Equivalent to indexed_delete_internal in libcob/fileio.c */ - private int indexed_delete_internal(boolean rewrite) { - IndexedFile p = this.filei; - boolean closeCursor; - - p.write_cursor_open = true; - closeCursor = true; - - if (this.access_mode != COB_ACCESS_SEQUENTIAL) { - p.key = DBT_SET(this.keys[0].getField()); - } - - if (this.access_mode != COB_ACCESS_SEQUENTIAL && !keyExistsInTable(p, 0, p.key)) { - return returnWith(p, closeCursor, 0, COB_STATUS_23_KEY_NOT_EXISTS); - } - - // delete data from the primary table - String query = String.format("delete from %s where key = ?", getTableName(0)); - try (PreparedStatement statement = p.connection.prepareStatement(query)) { - statement.setBytes(1, p.key); - statement.execute(); - } catch (SQLException e) { - return returnWith(p, closeCursor, 0, COB_STATUS_30_PERMANENT_ERROR); - } - - // delete data from sub tables - for (int i = 1; i < this.nkeys; ++i) { - try (PreparedStatement statement = - p.connection.prepareStatement( - String.format("delete from %s where value = ?", getTableName(i)))) { - statement.setBytes(1, p.key); - statement.execute(); - } catch (SQLException e) { - return returnWith(p, closeCursor, 0, COB_STATUS_30_PERMANENT_ERROR); - } - } - - if (this.commitOnModification) { - try { - p.connection.commit(); - } catch (SQLException e) { - return returnWith(p, closeCursor, 0, COB_STATUS_30_PERMANENT_ERROR); - } - } - - this.updateWhileReading = true; - - return COB_STATUS_00_SUCCESS; - } - - @Override - public int delete_() { - return this.indexed_delete_internal(false); - } - - @Override - public void unlock_() { - System.err.println("Unlocking INDEXED file is not implemented"); - } - - /** TODO: 準備中 */ - public void commitJdbcTransaction() { - IndexedFile p = this.filei; - try { - p.connection.commit(); - } catch (SQLException e) { - System.err.println("Failed to commit a transaction"); - } - } - - /** - * Delete all records in the file - * - * @return true if all records are deleted successfully, otherwise false - */ - public boolean deleteAllRecords() { - IndexedFile p = this.filei; - try { - for (int i = this.nkeys - 1; i >= 0; --i) { - Statement statement = p.connection.createStatement(); - statement.execute("delete from " + getTableName(i)); - statement.close(); - } - if (this.commitOnModification) { - p.connection.commit(); - } - return true; - } catch (SQLException e) { - return false; - } - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.file; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Optional; +import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; +import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; +import org.sqlite.SQLiteConfig; +import org.sqlite.SQLiteErrorCode; + +/** TODO: 準備中 */ +public class CobolIndexedFile extends CobolFile { + private Optional cursor; + private boolean updateWhileReading = false; + private boolean indexedFirstRead = true; + private boolean callStart = false; + private boolean commitOnModification = true; + private int fetchKeyIndex = -1; + private byte[] previousLockedRecordKey = null; + + /** TODO: 準備中 */ + public static final int COB_EQ = 1; + + /** TODO: 準備中 */ + public static final int COB_LT = 2; + + /** TODO: 準備中 */ + public static final int COB_LE = 3; + + /** TODO: 準備中 */ + public static final int COB_GT = 4; + + /** TODO: 準備中 */ + public static final int COB_GE = 5; + + /** TODO: 準備中 */ + public static final int COB_NE = 6; + + private static String storedProcessUuid = null; + private static String storedProcessId = null; + + /** + * TODO: 準備中 + * + * @param selectName TODO: 準備中 + * @param fileStatus TODO: 準備中 + * @param assign TODO: 準備中 + * @param record TODO: 準備中 + * @param recordSize TODO: 準備中 + * @param recordMin TODO: 準備中 + * @param recordMax TODO: 準備中 + * @param nkeys TODO: 準備中 + * @param keys TODO: 準備中 + * @param organization TODO: 準備中 + * @param accessMode TODO: 準備中 + * @param lockMode TODO: 準備中 + * @param openMode TODO: 準備中 + * @param flagOptional TODO: 準備中 + * @param lastOpenMode TODO: 準備中 + * @param special TODO: 準備中 + * @param flagNonexistent TODO: 準備中 + * @param flagEndOfFile TODO: 準備中 + * @param flagBeginOfFile TODO: 準備中 + * @param flagFirstRead TODO: 準備中 + * @param flagReadDone TODO: 準備中 + * @param flagSelectFeatures TODO: 準備中 + * @param flagNeedsNl TODO: 準備中 + * @param flagNeedsTop TODO: 準備中 + * @param fileVersion TODO: 準備中 + */ + public CobolIndexedFile( + String selectName, + byte[] fileStatus, + AbstractCobolField assign, + AbstractCobolField record, + AbstractCobolField recordSize, + int recordMin, + int recordMax, + int nkeys, + CobolFileKey[] keys, + char organization, + char accessMode, + char lockMode, + char openMode, + boolean flagOptional, + char lastOpenMode, + char special, + boolean flagNonexistent, + boolean flagEndOfFile, + boolean flagBeginOfFile, + char flagFirstRead, + boolean flagReadDone, + char flagSelectFeatures, + boolean flagNeedsNl, + boolean flagNeedsTop, + char fileVersion) { + super( + selectName, + fileStatus, + assign, + record, + recordSize, + recordMin, + recordMax, + nkeys, + keys, + organization, + accessMode, + lockMode, + openMode, + flagOptional, + lastOpenMode, + special, + flagNonexistent, + flagEndOfFile, + flagBeginOfFile, + flagFirstRead, + flagReadDone, + flagSelectFeatures, + flagNeedsNl, + flagNeedsTop, + fileVersion); + } + + private static String getProcessUuid() { + if (CobolIndexedFile.storedProcessUuid == null) { + CobolIndexedFile.storedProcessUuid = java.util.UUID.randomUUID().toString(); + } + return CobolIndexedFile.storedProcessUuid; + } + + private static String getProcessId() { + if (CobolIndexedFile.storedProcessId == null) { + CobolIndexedFile.storedProcessId = + String.valueOf( + java.lang.management.ManagementFactory.getRuntimeMXBean() + .getName() + .split("@")[0]); + } + return CobolIndexedFile.storedProcessId; + } + + private static String getIndexName(int index) { + return String.format("index%d", index); + } + + private static String getSubIndexName(int index) { + return String.format("subindex%d", index); + } + + /** + * TODO: 準備中 + * + * @param index TODO: 準備中 + * @return TODO: 準備中 + */ + public static String getTableName(int index) { + return String.format("table%d", index); + } + + /** + * TODO: 準備中 + * + * @param index TODO: 準備中 + * @return TODO: 準備中 + */ + public static String getCursorName(int index) { + return String.format("cursor%d", index); + } + + private static String getConstraintName(int index) { + return String.format("constraint%d", index); + } + + /** + * TODO: 準備中 + * + * @param commitOnModification TODO: 準備中 + */ + public void setCommitOnModification(boolean commitOnModification) { + this.commitOnModification = commitOnModification; + } + + /** Equivalent to DBT_SET in libcob/fileio.c */ + private byte[] DBT_SET(AbstractCobolField field) { + return field.getDataStorage().getByteArray(0, field.getSize()); + } + + @Override + public int open_(String filename, int mode, int sharing) { + IndexedFile p = new IndexedFile(); + this.filei = p; + + // If the file does not exist and the mode is COB_OPEN_INPUT, return ENOENT + boolean fileExists = new java.io.File(filename).exists(); + if (mode == COB_OPEN_INPUT && !fileExists) { + return ENOENT; + } + + // Establish a connection to the database + int getConnectionStatus = this.getConnection(filename); + + // If the connection could not be established, return the error code + if (getConnectionStatus != COB_STATUS_00_SUCCESS) { + return getConnectionStatus; + } + + if (fileExists) { + int code = this.checkVersionOld(); + if (code != COB_STATUS_00_SUCCESS) { + return code; + } + } + + try { + // Acquire a file lock + boolean succeedToFileLock = this.acquireFileLock(filename, mode, fileExists); + if (succeedToFileLock) { + if (mode == COB_OPEN_OUTPUT) { + this.deleteAllTablesExceptForFileLockTable(); + } + this.createAllTablesIfNotExists(); + if (mode == COB_OPEN_OUTPUT) { + this.writeMetaData(p); + } + p.connection.commit(); + this.setInitialParameters(filename); + return COB_STATUS_00_SUCCESS; + } else { + try { + p.connection.close(); + } catch (SQLException closeEx) { + return COB_STATUS_30_PERMANENT_ERROR; + } + return COB_STATUS_61_FILE_SHARING; + } + } catch (SQLException e) { + try { + p.connection.close(); + } catch (SQLException closeEx) { + return COB_STATUS_30_PERMANENT_ERROR; + } + return COB_STATUS_30_PERMANENT_ERROR; + } + } + + private int getConnection(String filename) { + IndexedFile p = this.filei; + // Establishes a connection to the SQLite database using the provided filename. + SQLiteConfig config = new SQLiteConfig(); + config.setReadOnly(false); + + p.connection = null; + try { + p.connection = + DriverManager.getConnection("jdbc:sqlite:" + filename, config.toProperties()); + p.connection.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE); + p.connection.setAutoCommit(false); + + // Check if the file is accessible + try (Statement st = p.connection.createStatement()) { + // Wait for finishing other processes' transactions up to 5 seconds + st.execute("PRAGMA busy_timeout = 5000"); + st.execute("select 1"); + } + p.connection.commit(); + } catch (SQLException e) { + int errorCode = e.getErrorCode(); + if (errorCode == SQLiteErrorCode.SQLITE_BUSY.code) { + return COB_STATUS_61_FILE_SHARING; + } else { + return COB_STATUS_30_PERMANENT_ERROR; + } + } catch (Exception e) { + return COB_STATUS_30_PERMANENT_ERROR; + } + return COB_STATUS_00_SUCCESS; + } + + private int checkVersionOld() { + IndexedFile p = this.filei; + try (Statement st = p.connection.createStatement()) { + String fileLockTableExistsSql = + "select exists(select 1 from sqlite_master where type = 'table' and name =" + + " 'file_lock')"; + ResultSet fileLockTableExistsResultSet = st.executeQuery(fileLockTableExistsSql); + if (fileLockTableExistsResultSet.next()) { + boolean fileLockTableExists = fileLockTableExistsResultSet.getInt(1) == 1; + if (!fileLockTableExists) { + return COB_STATUS_92_VERSION_INCOMPATIBLE; + } + } else { + return COB_STATUS_92_VERSION_INCOMPATIBLE; // file_lock table does not exist + } + + boolean lockedByColumnExists = false; + boolean processIdColumnExists = false; + boolean lockedAtColumnExists = false; + try (ResultSet rs = st.executeQuery("PRAGMA table_info('table0')")) { + while (rs.next()) { + String columnName = rs.getString("name"); + if ("locked_by".equals(columnName)) { + lockedByColumnExists = true; + } else if ("process_id".equals(columnName)) { + processIdColumnExists = true; + } else if ("locked_at".equals(columnName)) { + lockedAtColumnExists = true; + } + if (lockedByColumnExists && processIdColumnExists && lockedAtColumnExists) { + return COB_STATUS_00_SUCCESS; // All required columns exist + } + } + } + } catch (SQLException e) { + return COB_STATUS_30_PERMANENT_ERROR; + } + return COB_STATUS_92_VERSION_INCOMPATIBLE; + } + + private String getOpenModeString(int mode) { + switch (mode) { + case COB_OPEN_INPUT: + return "INPUT"; + case COB_OPEN_OUTPUT: + return "OUTPUT"; + case COB_OPEN_I_O: + return "I-O"; + case COB_OPEN_EXTEND: + return "EXTEND"; + default: + return null; + } + } + + private boolean acquireFileLock(String filename, int mode, boolean fileExists) + throws SQLException { + if (!checkFileIsLocked(filename, mode, fileExists)) { + return false; // File is already locked + } + + IndexedFile p = this.filei; + + // Insert a new lock record into the file_lock table + String openMode = this.getOpenModeString(mode); + if (openMode == null) { + return false; // Invalid open mode + } + String insertSql = + "insert into file_lock (locked_by, process_id, locked_at, open_mode) values (?, ?," + + " datetime('now'), ?)"; + String processUuid = this.getProcessUuid(); + String processId = this.getProcessId(); + + try (PreparedStatement statement = p.connection.prepareStatement(insertSql)) { + statement.setString(1, processUuid); + statement.setString(2, processId); + statement.setString(3, openMode); + int insertedRecordsCount = statement.executeUpdate(); + if (insertedRecordsCount != 1) { + p.connection.rollback(); + return false; + } + p.connection.commit(); + return true; + } catch (SQLException e) { + p.connection.rollback(); + return false; + } + } + + private boolean checkFileIsLocked(String filename, int mode, boolean fileExists) + throws SQLException { + IndexedFile p = this.filei; + try (Statement statement = p.connection.createStatement()) { + if (mode == COB_OPEN_OUTPUT + || (!fileExists && (mode == COB_OPEN_EXTEND || mode == COB_OPEN_I_O))) { + String query = + "select exists(select 1 from sqlite_master where type = 'table' and name =" + + " 'file_lock')"; + try (ResultSet rs = statement.executeQuery(query)) { + // If the file_lock table does not exist, create it and return true + if (!rs.next() || rs.getInt(1) == 0) { + statement.execute( + "CREATE TABLE if not exists file_lock (locked_by text primary key," + + " process_id text, locked_at timestamp, open_mode text" + + " CONSTRAINT check_open_mode CHECK (open_mode IN ('INPUT'," + + " 'OUTPUT', 'I-O', 'EXTEND')))"); + return true; + } + } + } + + String query; + if (mode == COB_OPEN_OUTPUT) { + query = "select exists(select 1 from file_lock)"; + } else { + query = "select exists(select 1 from file_lock where open_mode = 'OUTPUT')"; + } + try (ResultSet rs = statement.executeQuery(query)) { + // If the file is already locked, return false + if (rs.next() && rs.getInt(1) == 1) { + p.connection.rollback(); + return false; + } + } + return true; + } catch (SQLException e) { + p.connection.rollback(); + return false; + } + } + + private void deleteAllTablesExceptForFileLockTable() throws SQLException { + IndexedFile p = this.filei; + try (Statement statement = p.connection.createStatement()) { + for (int i = 0; i < this.nkeys; ++i) { + statement.execute("drop table if exists " + getTableName(i)); + } + statement.execute("drop table if exists metadata_string_int"); + statement.execute("drop table if exists metadata_key"); + } + } + + private void createAllTablesIfNotExists() throws SQLException { + IndexedFile p = this.filei; + try (Statement statement = p.connection.createStatement()) { + for (int i = 0; i < this.nkeys; ++i) { + String tableName = getTableName(i); + if (i == 0) { + statement.execute( + String.format( + "create table if not exists %s (" + + "key blob not null primary key," + + "value blob not null," + + "locked_by text," + + "process_id text," + + "locked_at timestamp" + + ")", + tableName)); + } else { + if (this.keys[i].getFlag() == 0) { + statement.execute( + String.format( + "create table if not exists %s (key blob not null primary" + + " key, value blob not null, constraint %s foreign key" + + " (value) references %s (key))", + tableName, getConstraintName(i), getTableName(0))); + } else { + statement.execute( + String.format( + "create table if not exists %s (key blob not null, value" + + " blob not null, dupNo integer not null, constraint" + + " %s foreign key (value) references %s (key))", + tableName, getConstraintName(i), getTableName(0))); + } + statement.execute( + String.format( + "create index if not exists %s on %s(value)", + getSubIndexName(i), tableName)); + } + statement.execute( + String.format( + "create index if not exists %s on %s(key)", + getIndexName(i), tableName)); + } + } + } + + private void setInitialParameters(String filename) { + IndexedFile p = this.filei; + p.filenamelen = filename.length(); + p.last_dupno = new int[this.nkeys]; + p.rewrite_sec_key = new int[this.nkeys]; + + int maxsize = 0; + for (int i = 0; i < this.nkeys; ++i) { + if (this.keys[i].getField().getSize() > maxsize) { + maxsize = this.keys[i].getField().getSize(); + } + } + + p.temp_key = new CobolDataStorage(maxsize + 4); + p.key_index = 0; + p.last_key = null; + + p.filename = filename; + p.write_cursor_open = false; + p.record_locked = false; + + p.key = DBT_SET(this.keys[0].getField()); + this.updateWhileReading = false; + this.indexedFirstRead = true; + this.callStart = false; + + this.fetchKeyIndex = -1; + } + + // Write a metadata to the database + private void writeMetaData(IndexedFile p) throws SQLException { + Statement statement = p.connection.createStatement(); + // Create a table to store metadata + statement.execute( + "create table if not exists metadata_string_int (key text not null primary key," + + " value integer not null)"); + statement.execute( + "create table if not exists metadata_key (idx integer not null primary key, offset" + + " integer not null, size integer not null, duplicate boolean)"); + statement.close(); + + // Store the size of a record + PreparedStatement recordSizePreparedStmt = + p.connection.prepareStatement( + "insert into metadata_string_int values ('record_size', ?)"); + recordSizePreparedStmt.setInt(1, this.record_max); + recordSizePreparedStmt.execute(); + recordSizePreparedStmt.close(); + + // Store information of all keys + PreparedStatement keyPreparedStmt = + p.connection.prepareStatement("insert into metadata_key values (?, ?, ?, ?)"); + for (int i = 0; i < this.nkeys; i++) { + keyPreparedStmt.setInt(1, i); + keyPreparedStmt.setInt( + 2, + this.keys[i].getField().getDataStorage().getIndex() + - this.record.getDataStorage().getIndex()); + keyPreparedStmt.setInt(3, this.keys[i].getField().getSize()); + keyPreparedStmt.setBoolean(4, this.keys[i].getFlag() != 0); + keyPreparedStmt.execute(); + } + keyPreparedStmt.close(); + } + + @Override + public int close_(int opt) { + IndexedFile p = this.filei; + + this.closeCursor(); + + previousLockedRecordKey = null; + + try { + try (Statement statement = p.connection.createStatement()) { + // Close the file lock + String deleteFileLockSql = "delete from file_lock where locked_by = ?"; + try (PreparedStatement deleteFileLockStatement = + p.connection.prepareStatement(deleteFileLockSql)) { + deleteFileLockStatement.setString(1, this.getProcessUuid()); + deleteFileLockStatement.executeUpdate(); + } + String unlockRecordsSql = + String.format( + "update %s set locked_by = null, process_id = null, locked_at =" + + " null where locked_by = ?", + getTableName(0)); + try (PreparedStatement unlockRecordsStatement = + p.connection.prepareStatement(unlockRecordsSql)) { + unlockRecordsStatement.setString(1, this.getProcessUuid()); + unlockRecordsStatement.executeUpdate(); + } + } + p.connection.commit(); + p.connection.close(); + } catch (SQLException e) { + return COB_STATUS_30_PERMANENT_ERROR; + } + this.fetchKeyIndex = -1; + return COB_STATUS_00_SUCCESS; + } + + // Equivalent to indexed_start_internal in libcob/fileio.c + /** + * TODO: 準備中 + * + * @param cond TODO: 準備中 + * @param key TODO: 準備中 + * @param readOpts TODO: 準備中 + * @param testLock TODO: 準備中 + * @return TODO: 準備中 + */ + public int indexed_start_internal( + int cond, AbstractCobolField key, int readOpts, boolean testLock) { + IndexedFile p = this.filei; + for (p.key_index = 0; p.key_index < this.nkeys; p.key_index++) { + if (this.keys[p.key_index].getField().getDataStorage().isSame(key.getDataStorage())) { + break; + } + } + this.fetchKeyIndex = p.key_index; + + p.key = DBT_SET(key); + + boolean isDuplicate = this.keys[p.key_index].getFlag() != 0; + + this.cursor = + IndexedCursor.createCursor(p.connection, p.key, p.key_index, isDuplicate, cond); + if (!this.cursor.isPresent()) { + return COB_STATUS_30_PERMANENT_ERROR; + } + + IndexedCursor cursor = this.cursor.get(); + Optional optionalResult = cursor.next(); + if (optionalResult.isPresent()) { + FetchResult result = optionalResult.get(); + p.key = result.key; + p.data = result.value; + this.indexedFirstRead = false; + return COB_STATUS_00_SUCCESS; + } else { + return COB_STATUS_23_KEY_NOT_EXISTS; + } + } + + @Override + public int start_(int cond, AbstractCobolField key) { + int ret = indexed_start_internal(cond, key, 0, false); + if (ret == COB_STATUS_00_SUCCESS) { + this.callStart = true; + } + try { + IndexedFile p = this.filei; + p.connection.commit(); + } catch (SQLException rollbackEx) { + return COB_STATUS_30_PERMANENT_ERROR; + } + return ret; + } + + private boolean shouldLockRecord(int readOpts) { + if (this.open_mode != COB_OPEN_I_O) { + return false; + } + if ((readOpts & CobolFile.COB_READ_LOCK) != 0) { + return true; + } else if ((readOpts & CobolFile.COB_READ_NO_LOCK) != 0) { + return false; + } else { + return this.lock_mode != CobolFile.COB_LOCK_MANUAL; + } + } + + private boolean checkOtherProcessLockedRecord(byte[] key) throws SQLException { + IndexedFile p = this.filei; + String query = + String.format( + "select exists(select 1 from %s where key = ? and locked_by != ?)", + getTableName(0)); + try (PreparedStatement selectStatement = p.connection.prepareStatement(query)) { + selectStatement.setBytes(1, key); + selectStatement.setString(2, this.getProcessUuid()); + try (ResultSet rs = selectStatement.executeQuery()) { + return rs.next() && rs.getInt(1) == 1; + } + } + } + + private boolean lockRecord(byte[] key) throws SQLException { + IndexedFile p = this.filei; + String updateSql = + String.format( + "update %s set locked_by = ?, process_id = ?, locked_at = datetime('now')" + + " where key = ?", + getTableName(0)); + try (PreparedStatement updateStatement = p.connection.prepareStatement(updateSql)) { + updateStatement.setString(1, this.getProcessUuid()); + updateStatement.setString(2, this.getProcessId()); + updateStatement.setBytes(3, key); + int updatedRecordcount = updateStatement.executeUpdate(); + return updatedRecordcount == 1; + } + } + + private void unlockPreviousRecord() throws SQLException { + if (previousLockedRecordKey == null) { + previousLockedRecordKey = null; + return; + } + IndexedFile p = this.filei; + String updateSql = + String.format( + "update %s set locked_by = null, process_id = null, locked_at = null where" + + " key = ? and locked_by = ?", + getTableName(0)); + try (PreparedStatement updateStatement = p.connection.prepareStatement(updateSql)) { + updateStatement.setBytes(1, previousLockedRecordKey); + updateStatement.setString(2, this.getProcessUuid()); + updateStatement.executeUpdate(); + } + previousLockedRecordKey = null; + } + + @Override + protected boolean postProcess() { + try { + unlockPreviousRecord(); + } catch (SQLException e) { + return false; + } + return true; + } + + private void unlockPreviousRecord(byte[] key) throws SQLException { + if (previousLockedRecordKey == null) { + previousLockedRecordKey = key; + return; + } + IndexedFile p = this.filei; + String updateSql = + String.format( + "update %s set locked_by = null, process_id = null, locked_at = null where" + + " key = ? and locked_by = ?", + getTableName(0)); + try (PreparedStatement updateStatement = p.connection.prepareStatement(updateSql)) { + updateStatement.setBytes(1, previousLockedRecordKey); + updateStatement.setString(2, this.getProcessUuid()); + updateStatement.executeUpdate(); + } + previousLockedRecordKey = key; + } + + private int read_internal(AbstractCobolField key, int readOpts) { + boolean testLock = false; + this.callStart = false; + int ret = this.indexed_start_internal(COB_EQ, key, readOpts, testLock); + if (ret != COB_STATUS_00_SUCCESS) { + return ret; + } + + return COB_STATUS_00_SUCCESS; + } + + @Override + public int read_(AbstractCobolField key, int readOpts) { + IndexedFile p = this.filei; + int retCode = read_internal(key, readOpts); + if (retCode != COB_STATUS_00_SUCCESS) { + try { + unlockPreviousRecord(); + p.connection.commit(); + } catch (SQLException rollbackEx) { + return COB_STATUS_30_PERMANENT_ERROR; + } + return retCode; + } + byte[] primaryKey = DBT_SET(this.keys[0].getField()); + if (shouldLockRecord(readOpts)) { + try { + if (checkOtherProcessLockedRecord(primaryKey)) { + p.connection.rollback(); + unlockPreviousRecord(); + p.connection.commit(); + return COB_STATUS_51_RECORD_LOCKED; + } + if (!lockRecord(primaryKey)) { + p.connection.rollback(); + unlockPreviousRecord(); + p.connection.commit(); + return COB_STATUS_30_PERMANENT_ERROR; + } + unlockPreviousRecord(primaryKey); + p.connection.commit(); + } catch (SQLException e) { + try { + p.connection.rollback(); + } catch (SQLException rollbackEx) { + return COB_STATUS_30_PERMANENT_ERROR; + } + return COB_STATUS_30_PERMANENT_ERROR; + } + } else { + try { + unlockPreviousRecord(primaryKey); + p.connection.commit(); + } catch (SQLException e) { + try { + p.connection.rollback(); + } catch (SQLException rollbackEx) { + return COB_STATUS_30_PERMANENT_ERROR; + } + return COB_STATUS_30_PERMANENT_ERROR; + } + } + + this.record.setSize(p.data.length); + this.record.getDataStorage().memcpy(p.data, p.data.length); + return COB_STATUS_00_SUCCESS; + } + + private int readNext_internal(int readOpts) { + IndexedFile p = this.filei; + // Immediately after START is called + if (this.callStart) { + this.callStart = false; + this.indexedFirstRead = false; + // If this statement is READ NEXT RECORD and + // the START statement was like `START ~~ KEY IS <=` + if ((readOpts & CobolFile.COB_READ_NEXT) != 0 + && cursor.get().getComparator() == COB_LE) { + AbstractCobolField specifiedKey = this.keys[p.key_index].getField(); + int specifiedKeySize = specifiedKey.getSize(); + int readKeySize = p.key.length; + int length = Math.min(specifiedKeySize, readKeySize); + // The key fetched by START is not the same as the specified key + if (specifiedKey.getDataStorage().memcmp(p.key, length) != 0) { + // READ the next record + return readNext_internal(readOpts); + } + } + return COB_STATUS_00_SUCCESS; + } + + boolean isDuplicate = this.keys[p.key_index].getFlag() != 0; + if (this.indexedFirstRead || this.flag_begin_of_file) { + this.cursor = + IndexedCursor.createCursor( + p.connection, p.key, p.key_index, isDuplicate, COB_GE); + if (!this.cursor.isPresent()) { + return COB_STATUS_10_END_OF_FILE; + } + this.cursor.get().moveToFirst(); + } else if (this.flag_end_of_file) { + this.cursor = + IndexedCursor.createCursor( + p.connection, p.key, p.key_index, isDuplicate, COB_LE); + if (!this.cursor.isPresent()) { + return COB_STATUS_30_PERMANENT_ERROR; + } + this.cursor.get().moveToLast(); + } else if (this.updateWhileReading) { + this.updateWhileReading = false; + if (!this.cursor.isPresent()) { + return COB_STATUS_30_PERMANENT_ERROR; + } + IndexedCursor oldCursor = this.cursor.get(); + Optional newCursor = oldCursor.reloadCursor(); + if (!newCursor.isPresent()) { + this.cursor = Optional.of(oldCursor); + } else { + oldCursor.close(); + this.cursor = newCursor; + } + } + + if (!this.cursor.isPresent()) { + return COB_STATUS_30_PERMANENT_ERROR; + } + + IndexedCursor cursor = this.cursor.get(); + + final CursorReadOption cursorOpt; + if ((readOpts & COB_READ_PREVIOUS) != 0) { + cursorOpt = CursorReadOption.PREV; + cursor.setComparator(COB_LE); + } else { + cursorOpt = CursorReadOption.NEXT; + cursor.setComparator(COB_GE); + } + + Optional optionalResult = cursor.read(cursorOpt); + + if (!optionalResult.isPresent()) { + this.indexedFirstRead = false; + return COB_STATUS_10_END_OF_FILE; + } + + FetchResult result = optionalResult.get(); + p.key = result.key; + p.data = result.value; + + this.indexedFirstRead = false; + return COB_STATUS_00_SUCCESS; + } + + @Override + public int readNext(int readOpts) { + IndexedFile p = this.filei; + int retCode = readNext_internal(readOpts); + if (retCode != COB_STATUS_00_SUCCESS) { + try { + unlockPreviousRecord(); + p.connection.commit(); + } catch (SQLException rollbackEx) { + return COB_STATUS_30_PERMANENT_ERROR; + } + return retCode; + } + byte[] primaryKey = DBT_SET(this.keys[0].getField()); + if (shouldLockRecord(readOpts)) { + try { + if (checkOtherProcessLockedRecord(primaryKey)) { + p.connection.rollback(); + unlockPreviousRecord(); + p.connection.commit(); + return COB_STATUS_51_RECORD_LOCKED; + } + if (!lockRecord(primaryKey)) { + p.connection.rollback(); + unlockPreviousRecord(); + p.connection.commit(); + return COB_STATUS_30_PERMANENT_ERROR; + } + unlockPreviousRecord(primaryKey); + p.connection.commit(); + } catch (SQLException e) { + try { + p.connection.rollback(); + } catch (SQLException rollbackEx) { + return COB_STATUS_30_PERMANENT_ERROR; + } + return COB_STATUS_30_PERMANENT_ERROR; + } + } else { + try { + unlockPreviousRecord(primaryKey); + p.connection.commit(); + } catch (SQLException e) { + try { + p.connection.rollback(); + } catch (SQLException rollbackEx) { + return COB_STATUS_30_PERMANENT_ERROR; + } + return COB_STATUS_30_PERMANENT_ERROR; + } + } + this.record.setSize(p.data.length); + this.record.getDataStorage().memcpy(p.data, p.data.length); + return COB_STATUS_00_SUCCESS; + } + + private void closeCursor() { + if (this.cursor != null) { + if (this.cursor.isPresent()) { + this.cursor.get().close(); + } + } + } + + private boolean keyExistsInTable(IndexedFile p, int index, byte[] key) { + String query = String.format("select * from %s where key = ?", getTableName(index)); + try (PreparedStatement selectStatement = p.connection.prepareStatement(query)) { + selectStatement.setBytes(1, key); + selectStatement.setFetchSize(0); + try (ResultSet rs = selectStatement.executeQuery()) { + return rs.next(); + } + } catch (SQLException e) { + return false; + } + } + + private boolean isDuplicateColumn(int index) { + return this.keys[index].getFlag() != 0; + } + + private int getNextKeyDupNo(Connection conn, int index, byte[] key) { + try { + PreparedStatement selectStatement = + conn.prepareStatement( + String.format( + "select ifnull(max(dupNo), -1) from %s", getTableName(index))); + try (ResultSet rs = selectStatement.executeQuery()) { + return rs.getInt(1) + 1; + } + } catch (SQLException e) { + return 0; + } + } + + private int returnWith(IndexedFile p, boolean closeCursor, int index, int returnCode) { + if (closeCursor) { + this.closeCursor(); + p.write_cursor_open = false; + } + return returnCode; + } + + private int indexed_write_internal(boolean rewrite, int opt) { + return this.indexed_write_internal(rewrite, null, opt); + } + + /** Equivalent to indexed_write_internal in libcob/fileio.c */ + private int indexed_write_internal(boolean rewrite, int[] dupNumbers, int opt) { + IndexedFile p = this.filei; + + boolean closeCursor; + p.write_cursor_open = true; + closeCursor = true; + + if (this.nkeys > 1 && !rewrite) { + if (this.check_alt_keys(false)) { + return returnWith(p, closeCursor, 0, COB_STATUS_22_KEY_EXISTS); + } + p.key = DBT_SET(this.keys[0].getField()); + } + + if (keyExistsInTable(p, 0, p.key)) { + return COB_STATUS_22_KEY_EXISTS; + } + + // insert into the primary table + p.data = DBT_SET(this.record); + try (PreparedStatement insertStatement = + p.connection.prepareStatement( + String.format( + "insert into %s (key, value, locked_by, process_id, locked_at) " + + "values (?, ?, null, null, null)", + getTableName(0)))) { + insertStatement.setBytes(1, p.key); + insertStatement.setBytes(2, p.data); + insertStatement.execute(); + } catch (SQLException e) { + return returnWith(p, closeCursor, 0, COB_STATUS_51_RECORD_LOCKED); + } + + p.data = p.key; + + // insert into sub tables + for (int i = 1; i < this.nkeys; i++) { + + p.key = DBT_SET(this.keys[i].getField()); + try { + if (!isDuplicateColumn(i) && keyExistsInTable(p, i, p.key)) { + return returnWith(p, closeCursor, 0, COB_STATUS_22_KEY_EXISTS); + } + + PreparedStatement insertStatement; + if (isDuplicateColumn(i)) { + int dupNo; + if (dupNumbers == null || dupNumbers[i] < 0 || i != this.fetchKeyIndex) { + dupNo = getNextKeyDupNo(p.connection, i, p.key); + } else { + dupNo = dupNumbers[i]; + } + insertStatement = + p.connection.prepareStatement( + String.format( + "insert into %s values (?, ?, ?)", getTableName(i))); + insertStatement.setBytes(1, p.key); + insertStatement.setBytes(2, p.data); + insertStatement.setInt(3, dupNo); + } else { + insertStatement = + p.connection.prepareStatement( + String.format("insert into %s values (?, ?)", getTableName(i))); + insertStatement.setBytes(1, p.key); + insertStatement.setBytes(2, p.data); + } + insertStatement.execute(); + insertStatement.close(); + } catch (SQLException e) { + return returnWith(p, closeCursor, 0, COB_STATUS_51_RECORD_LOCKED); + } + } + + this.updateWhileReading = true; + + return returnWith(p, closeCursor, 0, COB_STATUS_00_SUCCESS); + } + + @Override + public int write_(int opt) { + IndexedFile p = this.filei; + + p.key = DBT_SET(this.keys[0].getField()); + if (p.last_key == null) { + p.last_key = new CobolDataStorage(p.key.length); + + } else if (this.access_mode == COB_ACCESS_SEQUENTIAL) { + byte[] keyBytes = p.key; + if (p.last_key.memcmp(keyBytes, keyBytes.length) > 0) { + try { + unlockPreviousRecord(); + p.connection.commit(); + } catch (SQLException e) { + return COB_STATUS_30_PERMANENT_ERROR; + } + return COB_STATUS_21_KEY_INVALID; + } + } + + byte[] keyBytes = p.key; + p.last_key.memcpy(keyBytes, keyBytes.length); + + int ret = indexed_write_internal(false, opt); + if (ret == COB_STATUS_00_SUCCESS) { + try { + unlockPreviousRecord(); + if (this.commitOnModification) { + p.connection.commit(); + } + } catch (SQLException e) { + return COB_STATUS_30_PERMANENT_ERROR; + } + } else { + try { + p.connection.rollback(); + unlockPreviousRecord(); + p.connection.commit(); + } catch (SQLException rollbackEx) { + return ret; + } + } + return ret; + } + + /** Equivalent to check_alt_keys in libcob/fileio.c */ + private boolean check_alt_keys(boolean rewrite) { + IndexedFile p = this.filei; + + byte[] primaryKey = DBT_SET(this.keys[0].getField()); + for (int i = 1; i < this.nkeys; ++i) { + if (this.keys[i].getFlag() == 0) { + p.key = DBT_SET(this.keys[i].getField()); + if (rewrite) { + if (checkTable(p, i, p.key, primaryKey)) { + return true; + } + } else { + if (keyExistsInTable(p, i, p.key)) { + return true; + } + } + } + } + return false; + } + + private static boolean checkTable(IndexedFile p, int index, byte[] key, byte[] primaryKey) { + String query = + String.format( + "select key from %s " + "where key = ? and value = ?", getTableName(index)); + try (PreparedStatement selectStatement = p.connection.prepareStatement(query)) { + selectStatement.setBytes(1, key); + selectStatement.setBytes(2, primaryKey); + selectStatement.setFetchSize(0); + try (ResultSet rs = selectStatement.executeQuery()) { + return rs.next(); + } + } catch (SQLException e) { + return false; + } + } + + @Override + /** Equivalent to indexed_rewrite in libcob/fileio.c */ + public int rewrite_(int opt) { + IndexedFile p = this.filei; + + p.write_cursor_open = true; + + if (this.access_mode == COB_ACCESS_SEQUENTIAL + && !IndexedCursor.matchKeyHead(p.key, DBT_SET(this.keys[0].getField()))) { + try { + unlockPreviousRecord(); + p.connection.commit(); + } catch (SQLException e) { + return COB_STATUS_30_PERMANENT_ERROR; + } + return COB_STATUS_21_KEY_INVALID; + } + + byte[] currentKey = DBT_SET(this.keys[0].getField()); + try { + if (checkOtherProcessLockedRecord(currentKey)) { + unlockPreviousRecord(); + p.connection.commit(); + return COB_STATUS_51_RECORD_LOCKED; + } + if (!lockRecord(currentKey)) { + p.connection.rollback(); + unlockPreviousRecord(); + p.connection.commit(); + return COB_STATUS_30_PERMANENT_ERROR; + } + } catch (SQLException e) { + try { + unlockPreviousRecord(); + p.connection.commit(); + } catch (SQLException rollbackEx) { + return COB_STATUS_30_PERMANENT_ERROR; + } + return COB_STATUS_30_PERMANENT_ERROR; + } + + p.key = DBT_SET(this.keys[0].getField()); + int[] dupNumbers = new int[this.nkeys]; + java.util.Arrays.fill(dupNumbers, -1); + + int deleteRet = this.indexed_delete_internal(true, dupNumbers); + + if (deleteRet != COB_STATUS_00_SUCCESS) { + p.write_cursor_open = false; + try { + p.connection.rollback(); + unlockPreviousRecord(); + p.connection.commit(); + } catch (SQLException rollbackEx) { + return deleteRet; + } + return deleteRet; + } + + int writeRet = this.indexed_write_internal(true, dupNumbers, opt); + if (writeRet == COB_STATUS_00_SUCCESS) { + try { + unlockPreviousRecord(); + p.connection.commit(); + } catch (SQLException e) { + p.write_cursor_open = false; + return COB_STATUS_30_PERMANENT_ERROR; + } + } else { + p.write_cursor_open = false; + try { + p.connection.rollback(); + unlockPreviousRecord(); + p.connection.commit(); + } catch (SQLException rollbackEx) { + return COB_STATUS_30_PERMANENT_ERROR; + } + } + return writeRet; + } + + private int indexed_delete_internal(boolean rewrite) { + return this.indexed_delete_internal(rewrite, null); + } + + /** Equivalent to indexed_delete_internal in libcob/fileio.c */ + private int indexed_delete_internal(boolean rewrite, int[] dupNumbers) { + IndexedFile p = this.filei; + boolean closeCursor; + + p.write_cursor_open = true; + closeCursor = true; + + if (this.access_mode != COB_ACCESS_SEQUENTIAL) { + p.key = DBT_SET(this.keys[0].getField()); + } + + if (this.access_mode != COB_ACCESS_SEQUENTIAL && !keyExistsInTable(p, 0, p.key)) { + return returnWith(p, closeCursor, 0, COB_STATUS_23_KEY_NOT_EXISTS); + } + + // delete data from the primary table + String query = String.format("delete from %s where key = ?", getTableName(0)); + try (PreparedStatement statement = p.connection.prepareStatement(query)) { + statement.setBytes(1, p.key); + statement.execute(); + } catch (SQLException e) { + return returnWith(p, closeCursor, 0, COB_STATUS_30_PERMANENT_ERROR); + } + + // delete data from sub tables + for (int i = 1; i < this.nkeys; ++i) { + // save the duplicate number of the record to be deleted + if (isDuplicateColumn(i)) { + try (PreparedStatement statement = + p.connection.prepareStatement( + String.format( + "select dupNo from %s where value = ?", getTableName(i)))) { + statement.setBytes(1, p.key); + try (ResultSet rs = statement.executeQuery()) { + if (rs.next()) { + int dupNo = rs.getInt(1); + if (dupNumbers != null) { + dupNumbers[i] = dupNo; + } + } + } + } catch (SQLException e) { + return returnWith(p, closeCursor, 0, COB_STATUS_30_PERMANENT_ERROR); + } + } + // delete the record + try (PreparedStatement statement = + p.connection.prepareStatement( + String.format("delete from %s where value = ?", getTableName(i)))) { + statement.setBytes(1, p.key); + statement.execute(); + } catch (SQLException e) { + return returnWith(p, closeCursor, 0, COB_STATUS_30_PERMANENT_ERROR); + } + } + + this.updateWhileReading = true; + + return COB_STATUS_00_SUCCESS; + } + + @Override + public int delete_() { + IndexedFile p = this.filei; + byte[] currentKey = DBT_SET(this.keys[0].getField()); + try { + if (checkOtherProcessLockedRecord(currentKey)) { + unlockPreviousRecord(); + p.connection.commit(); + return COB_STATUS_51_RECORD_LOCKED; + } + if (!lockRecord(currentKey)) { + p.connection.rollback(); + unlockPreviousRecord(); + p.connection.commit(); + return COB_STATUS_30_PERMANENT_ERROR; + } + } catch (SQLException e) { + try { + unlockPreviousRecord(); + p.connection.commit(); + } catch (SQLException rollbackEx) { + return COB_STATUS_30_PERMANENT_ERROR; + } + return COB_STATUS_30_PERMANENT_ERROR; + } + + int ret = this.indexed_delete_internal(false); + + if (ret == COB_STATUS_00_SUCCESS) { + try { + unlockPreviousRecord(); + p.connection.commit(); + } catch (SQLException e) { + return COB_STATUS_30_PERMANENT_ERROR; + } + } else { + try { + p.connection.rollback(); + unlockPreviousRecord(); + p.connection.commit(); + } catch (SQLException rollbackEx) { + return ret; + } + } + return ret; + } + + @Override + public void unlock_() { + System.err.println("Unlocking INDEXED file is not implemented"); + } + + /** TODO: 準備中 */ + public void commitJdbcTransaction() { + IndexedFile p = this.filei; + try { + p.connection.commit(); + } catch (SQLException e) { + System.err.println("Failed to commit a transaction"); + } + } + + /** + * Delete all records in the file + * + * @return true if all records are deleted successfully, otherwise false + */ + public boolean deleteAllRecords() { + IndexedFile p = this.filei; + try { + for (int i = this.nkeys - 1; i >= 0; --i) { + Statement statement = p.connection.createStatement(); + statement.execute("delete from " + getTableName(i)); + statement.close(); + } + if (this.commitOnModification) { + p.connection.commit(); + } + return true; + } catch (SQLException e) { + return false; + } + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolItem.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolItem.java index f30fe066..634bd8fb 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolItem.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolItem.java @@ -1,145 +1,145 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.file; - -import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; - -/** TODO: 準備中 */ -class CobolItem { - private CobolItem next; - private int endOfBlock; - private int recordSize; - private byte blockByte = 0; - private CobolDataStorage unique = new CobolDataStorage(new byte[8]); - private CobolDataStorage item; - - /** TODO: 準備中 */ - CobolItem() { - this.next = null; - this.endOfBlock = 0; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - CobolItem getNext() { - return next; - } - - /** - * TODO: 準備中 - * - * @param next TODO: 準備中 - */ - void setNext(CobolItem next) { - this.next = next; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - int getEndOfBlock() { - return endOfBlock; - } - - /** - * TODO: 準備中 - * - * @param endOfBlock TODO: 準備中 - */ - void setEndOfBlock(int endOfBlock) { - this.endOfBlock = endOfBlock; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - int getRecordSize() { - return recordSize; - } - - /** - * TODO: 準備中 - * - * @param recordSize TODO: 準備中 - */ - void setRecordSize(int recordSize) { - this.recordSize = recordSize; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - byte getBlockByte() { - return blockByte; - } - - /** - * TODO: 準備中 - * - * @param blockByte TODO: 準備中 - */ - void setBlockByte(byte blockByte) { - this.blockByte = blockByte; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - CobolDataStorage getUnique() { - return unique; - } - - /** - * TODO: 準備中 - * - * @param unique TODO: 準備中 - */ - void setUnique(CobolDataStorage unique) { - this.unique = unique; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - CobolDataStorage getItem() { - return item; - } - - /** - * TODO: 準備中 - * - * @param item TODO: 準備中 - */ - void setItem(CobolDataStorage item) { - this.item = item; - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.file; + +import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; + +/** TODO: 準備中 */ +class CobolItem { + private CobolItem next; + private int endOfBlock; + private int recordSize; + private byte blockByte = 0; + private CobolDataStorage unique = new CobolDataStorage(new byte[8]); + private CobolDataStorage item; + + /** TODO: 準備中 */ + CobolItem() { + this.next = null; + this.endOfBlock = 0; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + CobolItem getNext() { + return next; + } + + /** + * TODO: 準備中 + * + * @param next TODO: 準備中 + */ + void setNext(CobolItem next) { + this.next = next; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + int getEndOfBlock() { + return endOfBlock; + } + + /** + * TODO: 準備中 + * + * @param endOfBlock TODO: 準備中 + */ + void setEndOfBlock(int endOfBlock) { + this.endOfBlock = endOfBlock; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + int getRecordSize() { + return recordSize; + } + + /** + * TODO: 準備中 + * + * @param recordSize TODO: 準備中 + */ + void setRecordSize(int recordSize) { + this.recordSize = recordSize; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + byte getBlockByte() { + return blockByte; + } + + /** + * TODO: 準備中 + * + * @param blockByte TODO: 準備中 + */ + void setBlockByte(byte blockByte) { + this.blockByte = blockByte; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + CobolDataStorage getUnique() { + return unique; + } + + /** + * TODO: 準備中 + * + * @param unique TODO: 準備中 + */ + void setUnique(CobolDataStorage unique) { + this.unique = unique; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + CobolDataStorage getItem() { + return item; + } + + /** + * TODO: 準備中 + * + * @param item TODO: 準備中 + */ + void setItem(CobolDataStorage item) { + this.item = item; + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolLineSequentialFile.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolLineSequentialFile.java index b7f71d40..da86ae91 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolLineSequentialFile.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolLineSequentialFile.java @@ -1,258 +1,258 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.file; - -import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; -import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; - -/** TODO: 準備中 */ -public class CobolLineSequentialFile extends CobolFile { - - /** - * TODO: 準備中 - * - * @param selectName TODO: 準備中 - * @param fileStatus TODO: 準備中 - * @param assign TODO: 準備中 - * @param record TODO: 準備中 - * @param recordSize TODO: 準備中 - * @param recordMin TODO: 準備中 - * @param recordMax TODO: 準備中 - * @param nkeys TODO: 準備中 - * @param keys TODO: 準備中 - * @param organization TODO: 準備中 - * @param accessMode TODO: 準備中 - * @param lockMode TODO: 準備中 - * @param openMode TODO: 準備中 - * @param flagOptional TODO: 準備中 - * @param lastOpenMode TODO: 準備中 - * @param special TODO: 準備中 - * @param flagNonexistent TODO: 準備中 - * @param flagEndOfFile TODO: 準備中 - * @param flagBeginOfFile TODO: 準備中 - * @param flagFirstRead TODO: 準備中 - * @param flagReadDone TODO: 準備中 - * @param flagSelectFeatures TODO: 準備中 - * @param flagNeedsNl TODO: 準備中 - * @param flagNeedsTop TODO: 準備中 - * @param fileVersion TODO: 準備中 - */ - public CobolLineSequentialFile( - String selectName, - byte[] fileStatus, - AbstractCobolField assign, - AbstractCobolField record, - AbstractCobolField recordSize, - int recordMin, - int recordMax, - int nkeys, - CobolFileKey[] keys, - char organization, - char accessMode, - char lockMode, - char openMode, - boolean flagOptional, - char lastOpenMode, - char special, - boolean flagNonexistent, - boolean flagEndOfFile, - boolean flagBeginOfFile, - char flagFirstRead, - boolean flagReadDone, - char flagSelectFeatures, - boolean flagNeedsNl, - boolean flagNeedsTop, - char fileVersion) { - super( - selectName, - fileStatus, - assign, - record, - recordSize, - recordMin, - recordMax, - nkeys, - keys, - organization, - accessMode, - lockMode, - openMode, - flagOptional, - lastOpenMode, - special, - flagNonexistent, - flagEndOfFile, - flagBeginOfFile, - flagFirstRead, - flagReadDone, - flagSelectFeatures, - flagNeedsNl, - flagNeedsTop, - fileVersion); - } - - @Override - public int start_(int cond, AbstractCobolField key) { - System.out.println("LineSeq.start"); - return 0; - } - - @Override - public int read_(AbstractCobolField key, int readOpts) { - System.out.println("LineSeq.read"); - return 0; - } - - @Override - public int readNext(int readOpts) { - int dataptr = 0; - int n; - int i = 0; - CobolDataStorage data = this.record.getDataStorage(); - - for (; ; ) { - n = this.file.getc(); - if (n == -1) { - if (i == 0) { - return COB_STATUS_10_END_OF_FILE; - } else { - break; - } - } - if (n == 0 && cob_ls_nulls != null) { - n = this.file.getc(); - if (n == -1) { - return COB_STATUS_30_PERMANENT_ERROR; - } - } else { - if (n == '\r') { - continue; - } - if (n == '\n') { - break; - } - } - if (i < this.record.getSize()) { - data.setByte(dataptr++, (byte) n); - i++; - } - } - if (i < this.record.getSize()) { - for (int j = 0; i + j < this.record.getSize(); ++j) { - data.setByte(i + j, (byte) ' '); - } - } - if (this.record_size != null) { - this.record_size.setInt(i); - } - return COB_STATUS_00_SUCCESS; - } - - @Override - public int write_(int opt) throws CobolStopRunException { - int size; - int i; - - /* determine the size to be written */ - if (cob_ls_fixed != null) { - size = this.record.getSize(); - } else { - CobolDataStorage data = this.record.getDataStorage(); - for (i = this.record.getSize() - 1; i >= 0; i--) { - if (data.getByte(i) != ' ') { - break; - } - } - size = i + 1; - } - - if ((this.flag_select_features & COB_SELECT_LINAGE) != 0) { - if (this.flag_needs_top) { - this.flag_needs_top = false; - Linage lingptr = this.linorkeyptr; - for (i = 0; i < lingptr.getLinTop(); i++) { - this.file.putc((byte) '\n'); - } - } - } - - if ((opt & COB_WRITE_AFTER) != 0) { - int ret = file_write_opt(opt); - if (ret != 0) { - return ret; - } - this.flag_needs_nl = true; - } - - if (size != 0) { - if (cob_ls_nulls != null) { - int p = 0; - CobolDataStorage data = this.record.getDataStorage(); - for (i = 0; i < size; ++i, ++p) { - if (data.getByte(p) < ' ') { - this.file.putc((byte) 0); - } - this.file.putc(data.getByte(p)); - } - } else { - if (!this.file.write(this.record.getDataStorage(), size)) { - return COB_STATUS_30_PERMANENT_ERROR; - } - } - } - - if ((this.flag_select_features & COB_SELECT_LINAGE) != 0) { - this.file.putc((byte) '\n'); - } - - if ((opt & COB_WRITE_BEFORE) != 0) { - int ret = file_write_opt(opt); - if (ret != 0) { - return ret; - } - this.flag_needs_nl = false; - } - - if (this.flag_needs_nl && (this.flag_select_features & COB_SELECT_LINAGE) == 0) { - this.file.putc((byte) '\n'); - this.flag_needs_nl = false; - } - - if (eop_status != 0) { - eop_status = 0; - CobolRuntimeException.code = 0x0502; - return COB_STATUS_52_EOP; - } - return COB_STATUS_00_SUCCESS; - } - - @Override - public int rewrite_(int opt) { - System.out.println("LineSeq.rewrite"); - return 0; - } - - @Override - public int delete_() { - System.out.println("LineSeq.delete"); - return 0; - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.file; + +import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; +import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; + +/** TODO: 準備中 */ +public class CobolLineSequentialFile extends CobolFile { + + /** + * TODO: 準備中 + * + * @param selectName TODO: 準備中 + * @param fileStatus TODO: 準備中 + * @param assign TODO: 準備中 + * @param record TODO: 準備中 + * @param recordSize TODO: 準備中 + * @param recordMin TODO: 準備中 + * @param recordMax TODO: 準備中 + * @param nkeys TODO: 準備中 + * @param keys TODO: 準備中 + * @param organization TODO: 準備中 + * @param accessMode TODO: 準備中 + * @param lockMode TODO: 準備中 + * @param openMode TODO: 準備中 + * @param flagOptional TODO: 準備中 + * @param lastOpenMode TODO: 準備中 + * @param special TODO: 準備中 + * @param flagNonexistent TODO: 準備中 + * @param flagEndOfFile TODO: 準備中 + * @param flagBeginOfFile TODO: 準備中 + * @param flagFirstRead TODO: 準備中 + * @param flagReadDone TODO: 準備中 + * @param flagSelectFeatures TODO: 準備中 + * @param flagNeedsNl TODO: 準備中 + * @param flagNeedsTop TODO: 準備中 + * @param fileVersion TODO: 準備中 + */ + public CobolLineSequentialFile( + String selectName, + byte[] fileStatus, + AbstractCobolField assign, + AbstractCobolField record, + AbstractCobolField recordSize, + int recordMin, + int recordMax, + int nkeys, + CobolFileKey[] keys, + char organization, + char accessMode, + char lockMode, + char openMode, + boolean flagOptional, + char lastOpenMode, + char special, + boolean flagNonexistent, + boolean flagEndOfFile, + boolean flagBeginOfFile, + char flagFirstRead, + boolean flagReadDone, + char flagSelectFeatures, + boolean flagNeedsNl, + boolean flagNeedsTop, + char fileVersion) { + super( + selectName, + fileStatus, + assign, + record, + recordSize, + recordMin, + recordMax, + nkeys, + keys, + organization, + accessMode, + lockMode, + openMode, + flagOptional, + lastOpenMode, + special, + flagNonexistent, + flagEndOfFile, + flagBeginOfFile, + flagFirstRead, + flagReadDone, + flagSelectFeatures, + flagNeedsNl, + flagNeedsTop, + fileVersion); + } + + @Override + public int start_(int cond, AbstractCobolField key) { + System.out.println("LineSeq.start"); + return 0; + } + + @Override + public int read_(AbstractCobolField key, int readOpts) { + System.out.println("LineSeq.read"); + return 0; + } + + @Override + public int readNext(int readOpts) { + int dataptr = 0; + int n; + int i = 0; + CobolDataStorage data = this.record.getDataStorage(); + + for (; ; ) { + n = this.file.getc(); + if (n == -1) { + if (i == 0) { + return COB_STATUS_10_END_OF_FILE; + } else { + break; + } + } + if (n == 0 && cob_ls_nulls != null) { + n = this.file.getc(); + if (n == -1) { + return COB_STATUS_30_PERMANENT_ERROR; + } + } else { + if (n == '\r') { + continue; + } + if (n == '\n') { + break; + } + } + if (i < this.record.getSize()) { + data.setByte(dataptr++, (byte) n); + i++; + } + } + if (i < this.record.getSize()) { + for (int j = 0; i + j < this.record.getSize(); ++j) { + data.setByte(i + j, (byte) ' '); + } + } + if (this.record_size != null) { + this.record_size.setInt(i); + } + return COB_STATUS_00_SUCCESS; + } + + @Override + public int write_(int opt) throws CobolStopRunException { + int size; + int i; + + /* determine the size to be written */ + if (cob_ls_fixed != null) { + size = this.record.getSize(); + } else { + CobolDataStorage data = this.record.getDataStorage(); + for (i = this.record.getSize() - 1; i >= 0; i--) { + if (data.getByte(i) != ' ') { + break; + } + } + size = i + 1; + } + + if ((this.flag_select_features & COB_SELECT_LINAGE) != 0) { + if (this.flag_needs_top) { + this.flag_needs_top = false; + Linage lingptr = this.linorkeyptr; + for (i = 0; i < lingptr.getLinTop(); i++) { + this.file.putc((byte) '\n'); + } + } + } + + if ((opt & COB_WRITE_AFTER) != 0) { + int ret = file_write_opt(opt); + if (ret != 0) { + return ret; + } + this.flag_needs_nl = true; + } + + if (size != 0) { + if (cob_ls_nulls != null) { + int p = 0; + CobolDataStorage data = this.record.getDataStorage(); + for (i = 0; i < size; ++i, ++p) { + if (data.getByte(p) < ' ') { + this.file.putc((byte) 0); + } + this.file.putc(data.getByte(p)); + } + } else { + if (!this.file.write(this.record.getDataStorage(), size)) { + return COB_STATUS_30_PERMANENT_ERROR; + } + } + } + + if ((this.flag_select_features & COB_SELECT_LINAGE) != 0) { + this.file.putc((byte) '\n'); + } + + if ((opt & COB_WRITE_BEFORE) != 0) { + int ret = file_write_opt(opt); + if (ret != 0) { + return ret; + } + this.flag_needs_nl = false; + } + + if (this.flag_needs_nl && (this.flag_select_features & COB_SELECT_LINAGE) == 0) { + this.file.putc((byte) '\n'); + this.flag_needs_nl = false; + } + + if (eop_status != 0) { + eop_status = 0; + CobolRuntimeException.code = 0x0502; + return COB_STATUS_52_EOP; + } + return COB_STATUS_00_SUCCESS; + } + + @Override + public int rewrite_(int opt) { + System.out.println("LineSeq.rewrite"); + return 0; + } + + @Override + public int delete_() { + System.out.println("LineSeq.delete"); + return 0; + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolRelativeFile.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolRelativeFile.java index 81b49935..46385377 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolRelativeFile.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolRelativeFile.java @@ -1,503 +1,511 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.file; - -import java.io.*; -import java.nio.ByteBuffer; -import java.nio.channels.*; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; - -/** TODO: 準備中 */ -public class CobolRelativeFile extends CobolFile { - - /** TODO: 準備中 */ - protected static final int COB_EQ = 1; - /** TODO: 準備中 */ - protected static final int COB_LT = 2; - /** TODO: 準備中 */ - protected static final int COB_LE = 3; - /** TODO: 準備中 */ - protected static final int COB_GT = 4; - /** TODO: 準備中 */ - protected static final int COB_GE = 5; - - RandomAccessFile fp; - byte[] size = new byte[8]; - - /** - * TODO: 準備中 - * - * @param selectName TODO: 準備中 - * @param fileStatus TODO: 準備中 - * @param assign TODO: 準備中 - * @param record TODO: 準備中 - * @param recordSize TODO: 準備中 - * @param recordMin TODO: 準備中 - * @param recordMax TODO: 準備中 - * @param nkeys TODO: 準備中 - * @param keys TODO: 準備中 - * @param organization TODO: 準備中 - * @param accessMode TODO: 準備中 - * @param lockMode TODO: 準備中 - * @param openMode TODO: 準備中 - * @param flagOptional TODO: 準備中 - * @param lastOpenMode TODO: 準備中 - * @param special TODO: 準備中 - * @param flagNonexistent TODO: 準備中 - * @param flagEndOfFile TODO: 準備中 - * @param flagBeginOfFile TODO: 準備中 - * @param flagFirstRead TODO: 準備中 - * @param flagReadDone TODO: 準備中 - * @param flagSelectFeatures TODO: 準備中 - * @param flagNeedsNl TODO: 準備中 - * @param flagNeedsTop TODO: 準備中 - * @param fileVersion TODO: 準備中 - */ - public CobolRelativeFile( - String selectName, - byte[] fileStatus, - AbstractCobolField assign, - AbstractCobolField record, - AbstractCobolField recordSize, - int recordMin, - int recordMax, - int nkeys, - CobolFileKey[] keys, - char organization, - char accessMode, - char lockMode, - char openMode, - boolean flagOptional, - char lastOpenMode, - char special, - boolean flagNonexistent, - boolean flagEndOfFile, - boolean flagBeginOfFile, - char flagFirstRead, - boolean flagReadDone, - char flagSelectFeatures, - boolean flagNeedsNl, - boolean flagNeedsTop, - char fileVersion) { - super( - selectName, - fileStatus, - assign, - record, - recordSize, - recordMin, - recordMax, - nkeys, - keys, - organization, - accessMode, - lockMode, - openMode, - flagOptional, - lastOpenMode, - special, - flagNonexistent, - flagEndOfFile, - flagBeginOfFile, - flagFirstRead, - flagReadDone, - flagSelectFeatures, - flagNeedsNl, - flagNeedsTop, - fileVersion); - } - - @Override - public int open_(String filename, int mode, int sharing) throws IOException { - FileChannel ch; - try { - switch (mode) { - case COB_OPEN_INPUT: - this.fp = new RandomAccessFile(this.assign.fieldToString(), "r"); - this.fp.seek(0); - break; - case COB_OPEN_OUTPUT: - Path path = Paths.get(filename); - if (Files.exists(path)) { - Files.delete(path); - } - this.fp = new RandomAccessFile(this.assign.fieldToString(), "rw"); - this.fp.seek(0); - break; - case COB_OPEN_I_O: - this.fp = new RandomAccessFile(this.assign.fieldToString(), "rw"); - this.fp.seek(0); - break; - case COB_OPEN_EXTEND: - this.fp = new RandomAccessFile(this.assign.fieldToString(), "rw"); - this.fp.seek(0); - this.fp.seek(this.fp.length()); - break; - default: - return EACCESS; - } - } catch (IOException e) { - if (this.fp != null) { - this.file.setRandomAccessFile(this.fp, null); - } - if (Files.notExists(Paths.get(filename))) { - return ENOENT; - } else { - return EACCESS; - } - } - - ch = fp.getChannel(); - - FileLock fl = null; - if (!filename.startsWith("/dev/")) { - try { - boolean lockFlag; - if (sharing != 0 || mode == COB_OPEN_OUTPUT) { - lockFlag = false; - } else { - lockFlag = true; - } - fl = ch.tryLock(0L, Long.MAX_VALUE, lockFlag); - } catch (NonWritableChannelException e) { - this.fp.close(); - return EBADF; - } catch (IOException e) { - this.fp.close(); - return COB_STATUS_61_FILE_SHARING; - } - - this.file.setRandomAccessFile(this.fp, fl); - - if (fl == null || !fl.isValid()) { - this.fp.close(); - return COB_STATUS_61_FILE_SHARING; - } - } - - this.file.setRandomAccessFile(this.fp, fl); - if ((this.flag_select_features & COB_SELECT_LINAGE) != 0) { - if (this.file_linage_check()) { - return COB_LINAGE_INVALID; - } - this.flag_needs_top = true; - Linage lingptr = this.getLinorkeyptr(); - lingptr.getLinageCtr().setInt(1); - } - return 0; - } - - @Override - public int close_(int opt) { - try { - switch (opt) { - case COB_CLOSE_NORMAL: - case COB_CLOSE_LOCK: - case COB_CLOSE_NO_REWIND: - if (this.organization == COB_ORG_LINE_SEQUENTIAL) { - if (this.flag_needs_nl && ((this.flag_select_features & COB_SELECT_LINAGE) == 0)) { - this.flag_needs_nl = false; - - this.fp.writeChars("\n"); - } - } - - this.file.releaseLock(); - this.fp.close(); - this.file.close(); - - if (opt == COB_CLOSE_NO_REWIND) { - this.open_mode = COB_OPEN_CLOSED; - return COB_STATUS_07_SUCCESS_NO_UNIT; - } - return COB_STATUS_00_SUCCESS; - default: - this.file.flush(); - return COB_STATUS_07_SUCCESS_NO_UNIT; - } - } catch (IOException e) { - return COB_STATUS_30_PERMANENT_ERROR; - } - } - - @Override - public int start_(int cond, AbstractCobolField key) { - int kindex; - int relsize; - int off; - final int offset = 0; - boolean isSeek = true; - - kindex = key.getInt() - 1; - relsize = this.record_max + size.length; - if (cond == COB_LT) { - kindex--; - } else if (cond == COB_GT) { - kindex++; - } - - for (; ; ) { - off = kindex * relsize; - try { - this.fp.seek((long) off); - try { - this.fp.seek(off); - } catch (IOException e) { - isSeek = false; - } - - if (!isSeek || this.fp.read(size, offset, size.length) != size.length) { - return COB_STATUS_23_KEY_NOT_EXISTS; - } - - if (this.record.getSize() > 0) { - key.setInt(kindex + 1); - this.fp.seek(this.fp.getFilePointer() - size.length); - return COB_STATUS_00_SUCCESS; - } - } catch (IOException e) { - return COB_STATUS_30_PERMANENT_ERROR; - } - switch (cond) { - case COB_EQ: - return COB_STATUS_23_KEY_NOT_EXISTS; - case COB_LT: - case COB_LE: - kindex--; - break; - case COB_GT: - case COB_GE: - kindex++; - break; - default: - break; - } - } - } - - @Override - public int read_(AbstractCobolField key, int readOpts) { - int relnum; - int relsize; - int off; - final int offset = 0; - boolean isSeek = true; - try { - relnum = key.getInt() - 1; - relsize = this.record_max + size.length; - off = relnum * relsize; - try { - this.fp.seek(off); - } catch (IOException e) { - isSeek = false; - } - if (!isSeek || this.fp.read(size, offset, size.length) != size.length) { - return COB_STATUS_23_KEY_NOT_EXISTS; - } - - if (ByteBuffer.wrap(size).getLong() == 0) { - this.fp.seek(this.fp.getFilePointer() - size.length); - return COB_STATUS_23_KEY_NOT_EXISTS; - } - byte[] bytes = new byte[this.record_max]; - if (this.fp.read(bytes, offset, this.record_max) != this.record_max) { - return COB_STATUS_30_PERMANENT_ERROR; - } - this.record.getDataStorage().memcpy(bytes); - return COB_STATUS_00_SUCCESS; - } catch (IOException e) { - return COB_STATUS_30_PERMANENT_ERROR; - } - } - - @Override - public int readNext(int readOpts) { - long off; - int relsize; - int relnum; - int recordSize; - final int offset = 0; - try { - - relsize = this.record_max + size.length; - for (; ; ) { - if (this.fp.read(size, offset, size.length) != size.length) { - return COB_STATUS_10_END_OF_FILE; - } - this.fp.seek(this.fp.getFilePointer() - 8); - recordSize = (int) this.fp.readLong(); - this.record.setSize(recordSize); - - if (this.keys[0].getField() != null) { - if (this.flag_first_read != 0) { - this.keys[0].getField().setInt(1); - this.flag_first_read = 0; - } else { - off = this.fp.getFilePointer(); - relnum = (int) ((off / relsize) + 1); - this.keys[0].getField().setInt(relnum); - if (String.valueOf(relnum).length() - > this.keys[0].getField().getAttribute().getDigits()) { - return COB_STATUS_14_OUT_OF_KEY_RANGE; - } - } - } - - byte[] bytes = new byte[this.record_max]; - if (recordSize > 0) { - if (this.fp.read(bytes, offset, this.record_max) != this.record_max) { - return COB_STATUS_30_PERMANENT_ERROR; - } - this.record.getDataStorage().memcpy(bytes); - return COB_STATUS_00_SUCCESS; - } - - this.fp.seek(this.fp.getFilePointer() + this.record_max); - } - } catch (IOException e) { - return COB_STATUS_30_PERMANENT_ERROR; - } - } - - @Override - public int write_(int opt) { - int relsize; - int i; - int kindex; - int off; - final int offset = 0; - - try { - relsize = this.record_max + size.length; - if (this.access_mode != COB_ACCESS_SEQUENTIAL) { - kindex = this.keys[0].getField().getInt() - 1; - if (kindex < 0) { - return COB_STATUS_21_KEY_INVALID; - } - off = relsize * kindex; - - try { - this.fp.seek((long) off); - } catch (IOException e) { - return COB_STATUS_21_KEY_INVALID; - } - } else { - off = (int) this.fp.getFilePointer(); - } - if (this.fp.read(size, offset, size.length) > 0) { - this.fp.seek(this.fp.getFilePointer() - 4); - int sizeInt = this.fp.readInt(); - this.fp.seek(this.fp.getFilePointer() - size.length); - if (sizeInt > 0) { - return COB_STATUS_22_KEY_EXISTS; - } - } else { - this.fp.seek(off); - } - try { - this.fp.writeLong(this.record.getSize()); - this.fp.write( - this.record.getDataStorage().getByteArray(0, this.record_max), offset, this.record_max); - } catch (IOException e) { - return COB_STATUS_30_PERMANENT_ERROR; - } - - if (this.access_mode == COB_ACCESS_SEQUENTIAL) { - if (this.keys[0].getField() != null) { - off += relsize; - i = (int) (off / relsize); - this.keys[0].getField().setInt(i); - } - } - return COB_STATUS_00_SUCCESS; - } catch (IOException e) { - return COB_STATUS_30_PERMANENT_ERROR; - } - } - - @Override - public int rewrite_(int opt) { - int relsize; - int relnum; - int off; - final int offset = 0; - boolean isSeek = true; - - try { - if (this.access_mode == COB_ACCESS_SEQUENTIAL) { - this.fp.seek(this.fp.getFilePointer() - this.record_max); - } else { - relsize = this.record_max + size.length; - relnum = this.keys[0].getField().getInt() - 1; - off = relnum * relsize; - - try { - this.fp.seek(off); - } catch (IOException e) { - isSeek = false; - } - if (!isSeek || this.fp.read(size, offset, size.length) != size.length) { - return COB_STATUS_23_KEY_NOT_EXISTS; - } - } - - this.fp.write( - this.record.getDataStorage().getByteArray(0, this.record_max), offset, this.record_max); - } catch (IOException e) { - return COB_STATUS_30_PERMANENT_ERROR; - } - return COB_STATUS_00_SUCCESS; - } - - @Override - public int delete_() { - int relsize; - int relnum; - int off; - relnum = this.keys[0].getField().getInt() - 1; - relsize = this.record_max + size.length; - off = relnum * relsize; - final int offset = 0; - - try { - boolean isSeek = true; - try { - this.fp.seek(off); - } catch (IOException e) { - isSeek = false; - } - if (!isSeek || this.fp.read(size, offset, size.length) != size.length) { - return COB_STATUS_23_KEY_NOT_EXISTS; - } - - this.fp.seek(this.fp.getFilePointer() - size.length); - - this.fp.writeLong(0); - - this.fp.seek(this.fp.getFilePointer() + this.record_max); - return COB_STATUS_00_SUCCESS; - - } catch (IOException e) { - return COB_STATUS_30_PERMANENT_ERROR; - } - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.file; + +import java.io.*; +import java.nio.ByteBuffer; +import java.nio.channels.*; +import java.nio.file.Files; +import java.nio.file.Paths; +import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; + +/** TODO: 準備中 */ +public class CobolRelativeFile extends CobolFile { + + /** TODO: 準備中 */ + protected static final int COB_EQ = 1; + + /** TODO: 準備中 */ + protected static final int COB_LT = 2; + + /** TODO: 準備中 */ + protected static final int COB_LE = 3; + + /** TODO: 準備中 */ + protected static final int COB_GT = 4; + + /** TODO: 準備中 */ + protected static final int COB_GE = 5; + + RandomAccessFile fp; + byte[] size = new byte[8]; + + /** + * TODO: 準備中 + * + * @param selectName TODO: 準備中 + * @param fileStatus TODO: 準備中 + * @param assign TODO: 準備中 + * @param record TODO: 準備中 + * @param recordSize TODO: 準備中 + * @param recordMin TODO: 準備中 + * @param recordMax TODO: 準備中 + * @param nkeys TODO: 準備中 + * @param keys TODO: 準備中 + * @param organization TODO: 準備中 + * @param accessMode TODO: 準備中 + * @param lockMode TODO: 準備中 + * @param openMode TODO: 準備中 + * @param flagOptional TODO: 準備中 + * @param lastOpenMode TODO: 準備中 + * @param special TODO: 準備中 + * @param flagNonexistent TODO: 準備中 + * @param flagEndOfFile TODO: 準備中 + * @param flagBeginOfFile TODO: 準備中 + * @param flagFirstRead TODO: 準備中 + * @param flagReadDone TODO: 準備中 + * @param flagSelectFeatures TODO: 準備中 + * @param flagNeedsNl TODO: 準備中 + * @param flagNeedsTop TODO: 準備中 + * @param fileVersion TODO: 準備中 + */ + public CobolRelativeFile( + String selectName, + byte[] fileStatus, + AbstractCobolField assign, + AbstractCobolField record, + AbstractCobolField recordSize, + int recordMin, + int recordMax, + int nkeys, + CobolFileKey[] keys, + char organization, + char accessMode, + char lockMode, + char openMode, + boolean flagOptional, + char lastOpenMode, + char special, + boolean flagNonexistent, + boolean flagEndOfFile, + boolean flagBeginOfFile, + char flagFirstRead, + boolean flagReadDone, + char flagSelectFeatures, + boolean flagNeedsNl, + boolean flagNeedsTop, + char fileVersion) { + super( + selectName, + fileStatus, + assign, + record, + recordSize, + recordMin, + recordMax, + nkeys, + keys, + organization, + accessMode, + lockMode, + openMode, + flagOptional, + lastOpenMode, + special, + flagNonexistent, + flagEndOfFile, + flagBeginOfFile, + flagFirstRead, + flagReadDone, + flagSelectFeatures, + flagNeedsNl, + flagNeedsTop, + fileVersion); + } + + @Override + public int open_(String filename, int mode, int sharing) throws IOException { + FileChannel ch; + try { + switch (mode) { + case COB_OPEN_INPUT: + this.fp = new RandomAccessFile(this.assign.fieldToString(), "r"); + this.fp.seek(0); + break; + case COB_OPEN_OUTPUT: + this.fp = new RandomAccessFile(this.assign.fieldToString(), "rw"); + break; + case COB_OPEN_I_O: + this.fp = new RandomAccessFile(this.assign.fieldToString(), "rw"); + this.fp.seek(0); + break; + case COB_OPEN_EXTEND: + this.fp = new RandomAccessFile(this.assign.fieldToString(), "rw"); + this.fp.seek(0); + this.fp.seek(this.fp.length()); + break; + default: + return EACCESS; + } + } catch (IOException e) { + if (this.fp != null) { + this.file.setRandomAccessFile(this.fp, null); + } + if (Files.notExists(Paths.get(filename))) { + return ENOENT; + } else { + return EACCESS; + } + } + + ch = fp.getChannel(); + + FileLock fl = null; + if (!filename.startsWith("/dev/")) { + try { + boolean isSharedLock; + if (sharing != 0 || mode == COB_OPEN_OUTPUT) { + isSharedLock = false; + } else { + isSharedLock = true; + } + fl = ch.tryLock(0L, Long.MAX_VALUE, isSharedLock); + } catch (NonWritableChannelException e) { + this.fp.close(); + return EBADF; + } catch (IOException e) { + this.fp.close(); + return COB_STATUS_61_FILE_SHARING; + } + + this.file.setRandomAccessFile(this.fp, fl); + + if (fl == null || !fl.isValid()) { + this.fp.close(); + return COB_STATUS_61_FILE_SHARING; + } + } + + if (mode == COB_OPEN_OUTPUT) { + this.fp.setLength(0); + this.fp.seek(0); + } + + this.file.setRandomAccessFile(this.fp, fl); + if ((this.flag_select_features & COB_SELECT_LINAGE) != 0) { + if (this.file_linage_check()) { + return COB_LINAGE_INVALID; + } + this.flag_needs_top = true; + Linage lingptr = this.getLinorkeyptr(); + lingptr.getLinageCtr().setInt(1); + } + return 0; + } + + @Override + public int close_(int opt) { + try { + switch (opt) { + case COB_CLOSE_NORMAL: + case COB_CLOSE_LOCK: + case COB_CLOSE_NO_REWIND: + if (this.organization == COB_ORG_LINE_SEQUENTIAL) { + if (this.flag_needs_nl + && ((this.flag_select_features & COB_SELECT_LINAGE) == 0)) { + this.flag_needs_nl = false; + + this.fp.writeChars("\n"); + } + } + + this.file.releaseLock(); + this.fp.close(); + this.file.close(); + + if (opt == COB_CLOSE_NO_REWIND) { + this.open_mode = COB_OPEN_CLOSED; + return COB_STATUS_07_SUCCESS_NO_UNIT; + } + return COB_STATUS_00_SUCCESS; + default: + this.file.flush(); + return COB_STATUS_07_SUCCESS_NO_UNIT; + } + } catch (IOException e) { + return COB_STATUS_30_PERMANENT_ERROR; + } + } + + @Override + public int start_(int cond, AbstractCobolField key) { + int kindex; + int relsize; + int off; + final int offset = 0; + boolean isSeek = true; + + kindex = key.getInt() - 1; + relsize = this.record_max + size.length; + if (cond == COB_LT) { + kindex--; + } else if (cond == COB_GT) { + kindex++; + } + + for (; ; ) { + off = kindex * relsize; + try { + this.fp.seek((long) off); + try { + this.fp.seek(off); + } catch (IOException e) { + isSeek = false; + } + + if (!isSeek || this.fp.read(size, offset, size.length) != size.length) { + return COB_STATUS_23_KEY_NOT_EXISTS; + } + + if (this.record.getSize() > 0) { + key.setInt(kindex + 1); + this.fp.seek(this.fp.getFilePointer() - size.length); + return COB_STATUS_00_SUCCESS; + } + } catch (IOException e) { + return COB_STATUS_30_PERMANENT_ERROR; + } + switch (cond) { + case COB_EQ: + return COB_STATUS_23_KEY_NOT_EXISTS; + case COB_LT: + case COB_LE: + kindex--; + break; + case COB_GT: + case COB_GE: + kindex++; + break; + default: + break; + } + } + } + + @Override + public int read_(AbstractCobolField key, int readOpts) { + int relnum; + int relsize; + int off; + final int offset = 0; + boolean isSeek = true; + try { + relnum = key.getInt() - 1; + relsize = this.record_max + size.length; + off = relnum * relsize; + try { + this.fp.seek(off); + } catch (IOException e) { + isSeek = false; + } + if (!isSeek || this.fp.read(size, offset, size.length) != size.length) { + return COB_STATUS_23_KEY_NOT_EXISTS; + } + + if (ByteBuffer.wrap(size).getLong() == 0) { + this.fp.seek(this.fp.getFilePointer() - size.length); + return COB_STATUS_23_KEY_NOT_EXISTS; + } + byte[] bytes = new byte[this.record_max]; + if (this.fp.read(bytes, offset, this.record_max) != this.record_max) { + return COB_STATUS_30_PERMANENT_ERROR; + } + this.record.getDataStorage().memcpy(bytes); + return COB_STATUS_00_SUCCESS; + } catch (IOException e) { + return COB_STATUS_30_PERMANENT_ERROR; + } + } + + @Override + public int readNext(int readOpts) { + long off; + int relsize; + int relnum; + int recordSize; + final int offset = 0; + try { + + relsize = this.record_max + size.length; + for (; ; ) { + if (this.fp.read(size, offset, size.length) != size.length) { + return COB_STATUS_10_END_OF_FILE; + } + this.fp.seek(this.fp.getFilePointer() - 8); + recordSize = (int) this.fp.readLong(); + this.record.setSize(recordSize); + + if (this.keys[0].getField() != null) { + if (this.flag_first_read != 0) { + this.keys[0].getField().setInt(1); + this.flag_first_read = 0; + } else { + off = this.fp.getFilePointer(); + relnum = (int) ((off / relsize) + 1); + this.keys[0].getField().setInt(relnum); + if (String.valueOf(relnum).length() + > this.keys[0].getField().getAttribute().getDigits()) { + return COB_STATUS_14_OUT_OF_KEY_RANGE; + } + } + } + + byte[] bytes = new byte[this.record_max]; + if (recordSize > 0) { + if (this.fp.read(bytes, offset, this.record_max) != this.record_max) { + return COB_STATUS_30_PERMANENT_ERROR; + } + this.record.getDataStorage().memcpy(bytes); + return COB_STATUS_00_SUCCESS; + } + + this.fp.seek(this.fp.getFilePointer() + this.record_max); + } + } catch (IOException e) { + return COB_STATUS_30_PERMANENT_ERROR; + } + } + + @Override + public int write_(int opt) { + int relsize; + int i; + int kindex; + int off; + final int offset = 0; + + try { + relsize = this.record_max + size.length; + if (this.access_mode != COB_ACCESS_SEQUENTIAL) { + kindex = this.keys[0].getField().getInt() - 1; + if (kindex < 0) { + return COB_STATUS_21_KEY_INVALID; + } + off = relsize * kindex; + + try { + this.fp.seek((long) off); + } catch (IOException e) { + return COB_STATUS_21_KEY_INVALID; + } + } else { + off = (int) this.fp.getFilePointer(); + } + if (this.fp.read(size, offset, size.length) > 0) { + this.fp.seek(this.fp.getFilePointer() - 4); + int sizeInt = this.fp.readInt(); + this.fp.seek(this.fp.getFilePointer() - size.length); + if (sizeInt > 0) { + return COB_STATUS_22_KEY_EXISTS; + } + } else { + this.fp.seek(off); + } + try { + this.fp.writeLong(this.record.getSize()); + this.fp.write( + this.record.getDataStorage().getByteArray(0, this.record_max), + offset, + this.record_max); + } catch (IOException e) { + return COB_STATUS_30_PERMANENT_ERROR; + } + + if (this.access_mode == COB_ACCESS_SEQUENTIAL) { + if (this.keys[0].getField() != null) { + off += relsize; + i = (int) (off / relsize); + this.keys[0].getField().setInt(i); + } + } + return COB_STATUS_00_SUCCESS; + } catch (IOException e) { + return COB_STATUS_30_PERMANENT_ERROR; + } + } + + @Override + public int rewrite_(int opt) { + int relsize; + int relnum; + int off; + final int offset = 0; + boolean isSeek = true; + + try { + if (this.access_mode == COB_ACCESS_SEQUENTIAL) { + this.fp.seek(this.fp.getFilePointer() - this.record_max); + } else { + relsize = this.record_max + size.length; + relnum = this.keys[0].getField().getInt() - 1; + off = relnum * relsize; + + try { + this.fp.seek(off); + } catch (IOException e) { + isSeek = false; + } + if (!isSeek || this.fp.read(size, offset, size.length) != size.length) { + return COB_STATUS_23_KEY_NOT_EXISTS; + } + } + + this.fp.write( + this.record.getDataStorage().getByteArray(0, this.record_max), + offset, + this.record_max); + } catch (IOException e) { + return COB_STATUS_30_PERMANENT_ERROR; + } + return COB_STATUS_00_SUCCESS; + } + + @Override + public int delete_() { + int relsize; + int relnum; + int off; + relnum = this.keys[0].getField().getInt() - 1; + relsize = this.record_max + size.length; + off = relnum * relsize; + final int offset = 0; + + try { + boolean isSeek = true; + try { + this.fp.seek(off); + } catch (IOException e) { + isSeek = false; + } + if (!isSeek || this.fp.read(size, offset, size.length) != size.length) { + return COB_STATUS_23_KEY_NOT_EXISTS; + } + + this.fp.seek(this.fp.getFilePointer() - size.length); + + this.fp.writeLong(0); + + this.fp.seek(this.fp.getFilePointer() + this.record_max); + return COB_STATUS_00_SUCCESS; + + } catch (IOException e) { + return COB_STATUS_30_PERMANENT_ERROR; + } + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolSequentialFile.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolSequentialFile.java index d46d2ff7..86916d50 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolSequentialFile.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolSequentialFile.java @@ -1,210 +1,212 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.file; - -import java.io.IOException; -import java.nio.ByteBuffer; -import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; - -/** TODO: 準備中 */ -public class CobolSequentialFile extends CobolFile { - - /** - * TODO: 準備中 - * - * @param selectName TODO: 準備中 - * @param fileStatus TODO: 準備中 - * @param assign TODO: 準備中 - * @param record TODO: 準備中 - * @param recordSize TODO: 準備中 - * @param recordMin TODO: 準備中 - * @param recordMax TODO: 準備中 - * @param nkeys TODO: 準備中 - * @param keys TODO: 準備中 - * @param organization TODO: 準備中 - * @param accessMode TODO: 準備中 - * @param lockMode TODO: 準備中 - * @param openMode TODO: 準備中 - * @param flagOptional TODO: 準備中 - * @param lastOpenMode TODO: 準備中 - * @param special TODO: 準備中 - * @param flagNonexistent TODO: 準備中 - * @param flagEndOfFile TODO: 準備中 - * @param flagBeginOfFile TODO: 準備中 - * @param flagFirstRead TODO: 準備中 - * @param flagReadDone TODO: 準備中 - * @param flagSelectFeatures TODO: 準備中 - * @param flagNeedsNl TODO: 準備中 - * @param flagNeedsTop TODO: 準備中 - * @param fileVersion TODO: 準備中 - */ - public CobolSequentialFile( - String selectName, - byte[] fileStatus, - AbstractCobolField assign, - AbstractCobolField record, - AbstractCobolField recordSize, - int recordMin, - int recordMax, - int nkeys, - CobolFileKey[] keys, - char organization, - char accessMode, - char lockMode, - char openMode, - boolean flagOptional, - char lastOpenMode, - char special, - boolean flagNonexistent, - boolean flagEndOfFile, - boolean flagBeginOfFile, - char flagFirstRead, - boolean flagReadDone, - char flagSelectFeatures, - boolean flagNeedsNl, - boolean flagNeedsTop, - char fileVersion) { - super( - selectName, - fileStatus, - assign, - record, - recordSize, - recordMin, - recordMax, - nkeys, - keys, - organization, - accessMode, - lockMode, - openMode, - flagOptional, - lastOpenMode, - special, - flagNonexistent, - flagEndOfFile, - flagBeginOfFile, - flagFirstRead, - flagReadDone, - flagSelectFeatures, - flagNeedsNl, - flagNeedsTop, - fileVersion); - } - - @Override - public int start_(int cond, AbstractCobolField key) { - System.out.println("Seq.start"); - return 0; - } - - @Override - public int read_(AbstractCobolField key, int readOpts) { - System.out.println("Seq.read"); - return 0; - } - - @Override - public int readNext(int readOpts) { - byte[] sbuff = new byte[4]; - this.file.seekInit(); - - if (this.record_min != this.record_max) { - if (this.file.read(sbuff, 4) != 1) { - if (this.file.isAtEnd()) { - return COB_STATUS_10_END_OF_FILE; - } else { - return COB_STATUS_30_PERMANENT_ERROR; - } - } - int size = ByteBuffer.wrap(sbuff).getInt(); - this.record.setSize(size); - } - - try { - int bytesread = this.file.read(this.record.getDataStorage(), this.record.getSize()); - if (bytesread != this.record.getSize()) { - if (bytesread == 0) { - return COB_STATUS_10_END_OF_FILE; - } else { - return COB_STATUS_04_SUCCESS_INCOMPLETE; - } - } - } catch (IOException e) { - return COB_STATUS_30_PERMANENT_ERROR; - } - return COB_STATUS_00_SUCCESS; - } - - @Override - public int write_(int opt) throws CobolStopRunException { - int ret; - byte[] sbuff = new byte[4]; - - this.file.seekInit(); - - /* WRITE AFTER */ - if ((opt & COB_WRITE_AFTER) != 0) { - ret = file_write_opt(opt); - if (ret != 0) { - return ret; - } - } - - if (this.record_min != this.record_max) { - ByteBuffer.wrap(sbuff).putInt(this.record.getSize()); - if (!this.file.write(sbuff, 4)) { - return COB_STATUS_30_PERMANENT_ERROR; - } - } - - /* write the record */ - if (!this.file.write(this.record.getDataStorage(), this.record.getSize())) { - return COB_STATUS_30_PERMANENT_ERROR; - } - - /* WRITE BEFORE */ - if ((opt & COB_WRITE_BEFORE) != 0) { - ret = this.file_write_opt(opt); - if (ret != 0) { - return ret; - } - this.flag_needs_nl = false; - } - return 0; - } - - @Override - public int rewrite_(int opt) { - if (!this.file.seek(-this.record.getSize(), FileIO.SEEK_CUR)) { - return COB_STATUS_30_PERMANENT_ERROR; - } - if (!this.file.write(this.record.getDataStorage(), this.record.getSize())) { - return COB_STATUS_30_PERMANENT_ERROR; - } - return COB_STATUS_00_SUCCESS; - } - - @Override - public int delete_() { - System.out.println("Seq.delete"); - return 0; - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.file; + +import java.io.IOException; +import java.nio.ByteBuffer; +import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException; + +/** TODO: 準備中 */ +public class CobolSequentialFile extends CobolFile { + + /** + * TODO: 準備中 + * + * @param selectName TODO: 準備中 + * @param fileStatus TODO: 準備中 + * @param assign TODO: 準備中 + * @param record TODO: 準備中 + * @param recordSize TODO: 準備中 + * @param recordMin TODO: 準備中 + * @param recordMax TODO: 準備中 + * @param nkeys TODO: 準備中 + * @param keys TODO: 準備中 + * @param organization TODO: 準備中 + * @param accessMode TODO: 準備中 + * @param lockMode TODO: 準備中 + * @param openMode TODO: 準備中 + * @param flagOptional TODO: 準備中 + * @param lastOpenMode TODO: 準備中 + * @param special TODO: 準備中 + * @param flagNonexistent TODO: 準備中 + * @param flagEndOfFile TODO: 準備中 + * @param flagBeginOfFile TODO: 準備中 + * @param flagFirstRead TODO: 準備中 + * @param flagReadDone TODO: 準備中 + * @param flagSelectFeatures TODO: 準備中 + * @param flagNeedsNl TODO: 準備中 + * @param flagNeedsTop TODO: 準備中 + * @param fileVersion TODO: 準備中 + */ + public CobolSequentialFile( + String selectName, + byte[] fileStatus, + AbstractCobolField assign, + AbstractCobolField record, + AbstractCobolField recordSize, + int recordMin, + int recordMax, + int nkeys, + CobolFileKey[] keys, + char organization, + char accessMode, + char lockMode, + char openMode, + boolean flagOptional, + char lastOpenMode, + char special, + boolean flagNonexistent, + boolean flagEndOfFile, + boolean flagBeginOfFile, + char flagFirstRead, + boolean flagReadDone, + char flagSelectFeatures, + boolean flagNeedsNl, + boolean flagNeedsTop, + char fileVersion) { + super( + selectName, + fileStatus, + assign, + record, + recordSize, + recordMin, + recordMax, + nkeys, + keys, + organization, + accessMode, + lockMode, + openMode, + flagOptional, + lastOpenMode, + special, + flagNonexistent, + flagEndOfFile, + flagBeginOfFile, + flagFirstRead, + flagReadDone, + flagSelectFeatures, + flagNeedsNl, + flagNeedsTop, + fileVersion); + } + + @Override + public int start_(int cond, AbstractCobolField key) { + System.out.println("Seq.start"); + return 0; + } + + @Override + public int read_(AbstractCobolField key, int readOpts) { + System.out.println("Seq.read"); + return 0; + } + + @Override + public int readNext(int readOpts) { + byte[] sbuff = new byte[4]; + this.file.seekInit(); + + if (this.record_min != this.record_max) { + if (this.file.read(sbuff, 4) != 1) { + if (this.file.isAtEnd()) { + return COB_STATUS_10_END_OF_FILE; + } else { + return COB_STATUS_30_PERMANENT_ERROR; + } + } + int size = ByteBuffer.wrap(sbuff).getInt(); + size = Math.max(size, this.record_min); + size = Math.min(size, this.record_max); + this.record.setSize(size); + } + + try { + int bytesread = this.file.read(this.record.getDataStorage(), this.record.getSize()); + if (bytesread != this.record.getSize()) { + if (bytesread == 0) { + return COB_STATUS_10_END_OF_FILE; + } else { + return COB_STATUS_04_SUCCESS_INCOMPLETE; + } + } + } catch (IOException e) { + return COB_STATUS_30_PERMANENT_ERROR; + } + return COB_STATUS_00_SUCCESS; + } + + @Override + public int write_(int opt) throws CobolStopRunException { + int ret; + byte[] sbuff = new byte[4]; + + this.file.seekInit(); + + /* WRITE AFTER */ + if ((opt & COB_WRITE_AFTER) != 0) { + ret = file_write_opt(opt); + if (ret != 0) { + return ret; + } + } + + if (this.record_min != this.record_max) { + ByteBuffer.wrap(sbuff).putInt(this.record.getSize()); + if (!this.file.write(sbuff, 4)) { + return COB_STATUS_30_PERMANENT_ERROR; + } + } + + /* write the record */ + if (!this.file.write(this.record.getDataStorage(), this.record.getSize())) { + return COB_STATUS_30_PERMANENT_ERROR; + } + + /* WRITE BEFORE */ + if ((opt & COB_WRITE_BEFORE) != 0) { + ret = this.file_write_opt(opt); + if (ret != 0) { + return ret; + } + this.flag_needs_nl = false; + } + return 0; + } + + @Override + public int rewrite_(int opt) { + if (!this.file.seek(-this.record.getSize(), FileIO.SEEK_CUR)) { + return COB_STATUS_30_PERMANENT_ERROR; + } + if (!this.file.write(this.record.getDataStorage(), this.record.getSize())) { + return COB_STATUS_30_PERMANENT_ERROR; + } + return COB_STATUS_00_SUCCESS; + } + + @Override + public int delete_() { + System.out.println("Seq.delete"); + return 0; + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolSort.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolSort.java index e1094abe..0e9d45e0 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolSort.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolSort.java @@ -1,319 +1,319 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.file; - -import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; -import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; - -/** TODO: 準備中 */ -class CobolSort { - private CobolFile pointer; - private CobolItem empty; - private CobolDataStorage sortReturn; - private AbstractCobolField fnstatus; - private int unique; - private int retrieving; - private int filesUsed; - private int size; - private int rSize; - private int wSize; - private int memory; - private int destinationFile; - private int retrievalQueue; - private MemoryStruct[] queue = new MemoryStruct[4]; - private FileStruct[] file = new FileStruct[4]; - - /** TODO: 準備中 */ - CobolSort() { - for (int i = 0; i < 4; ++i) { - this.queue[i] = new MemoryStruct(); - this.file[i] = new FileStruct(); - } - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - CobolFile getPointer() { - return pointer; - } - - /** - * TODO: 準備中 - * - * @param pointer TODO: 準備中 - */ - void setPointer(CobolFile pointer) { - this.pointer = pointer; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - CobolItem getEmpty() { - return empty; - } - - /** - * TODO: 準備中 - * - * @param empty TODO: 準備中 - */ - void setEmpty(CobolItem empty) { - this.empty = empty; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - CobolDataStorage getSortReturn() { - return sortReturn; - } - - /** - * TODO: 準備中 - * - * @param sortReturn TODO: 準備中 - */ - void setSortReturn(CobolDataStorage sortReturn) { - this.sortReturn = sortReturn; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - AbstractCobolField getFnstatus() { - return fnstatus; - } - - /** - * TODO: 準備中 - * - * @param fnstatus TODO: 準備中 - */ - void setFnstatus(AbstractCobolField fnstatus) { - this.fnstatus = fnstatus; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - int getUnique() { - return unique; - } - - /** - * TODO: 準備中 - * - * @param unique TODO: 準備中 - */ - void setUnique(int unique) { - this.unique = unique; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - int getRetrieving() { - return retrieving; - } - - /** - * TODO: 準備中 - * - * @param retrieving TODO: 準備中 - */ - void setRetrieving(int retrieving) { - this.retrieving = retrieving; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - int getFilesUsed() { - return filesUsed; - } - - /** - * TODO: 準備中 - * - * @param filesUsed TODO: 準備中 - */ - void setFilesUsed(int filesUsed) { - this.filesUsed = filesUsed; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - int getSize() { - return size; - } - - /** - * TODO: 準備中 - * - * @param size TODO: 準備中 - */ - void setSize(int size) { - this.size = size; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - int getrSize() { - return rSize; - } - - /** - * TODO: 準備中 - * - * @param rSize TODO: 準備中 - */ - void setrSize(int rSize) { - this.rSize = rSize; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - int getwSize() { - return wSize; - } - - /** - * TODO: 準備中 - * - * @param wSize TODO: 準備中 - */ - void setwSize(int wSize) { - this.wSize = wSize; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - int getMemory() { - return memory; - } - - /** - * TODO: 準備中 - * - * @param memory TODO: 準備中 - */ - void setMemory(int memory) { - this.memory = memory; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - int getDestinationFile() { - return destinationFile; - } - - /** - * TODO: 準備中 - * - * @param destinationFile TODO: 準備中 - */ - void setDestinationFile(int destinationFile) { - this.destinationFile = destinationFile; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - int getRetrievalQueue() { - return retrievalQueue; - } - - /** - * TODO: 準備中 - * - * @param retrievalQueue TODO: 準備中 - */ - void setRetrievalQueue(int retrievalQueue) { - this.retrievalQueue = retrievalQueue; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - MemoryStruct[] getQueue() { - return queue; - } - - /** - * TODO: 準備中 - * - * @param queue TODO: 準備中 - */ - void setQueue(MemoryStruct[] queue) { - this.queue = queue; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - FileStruct[] getFile() { - return file; - } - - /** - * TODO: 準備中 - * - * @param file TODO: 準備中 - */ - void setFile(FileStruct[] file) { - this.file = file; - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.file; + +import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; +import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; + +/** TODO: 準備中 */ +class CobolSort { + private CobolFile pointer; + private CobolItem empty; + private CobolDataStorage sortReturn; + private AbstractCobolField fnstatus; + private int unique; + private int retrieving; + private int filesUsed; + private int size; + private int rSize; + private int wSize; + private int memory; + private int destinationFile; + private int retrievalQueue; + private MemoryStruct[] queue = new MemoryStruct[4]; + private FileStruct[] file = new FileStruct[4]; + + /** TODO: 準備中 */ + CobolSort() { + for (int i = 0; i < 4; ++i) { + this.queue[i] = new MemoryStruct(); + this.file[i] = new FileStruct(); + } + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + CobolFile getPointer() { + return pointer; + } + + /** + * TODO: 準備中 + * + * @param pointer TODO: 準備中 + */ + void setPointer(CobolFile pointer) { + this.pointer = pointer; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + CobolItem getEmpty() { + return empty; + } + + /** + * TODO: 準備中 + * + * @param empty TODO: 準備中 + */ + void setEmpty(CobolItem empty) { + this.empty = empty; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + CobolDataStorage getSortReturn() { + return sortReturn; + } + + /** + * TODO: 準備中 + * + * @param sortReturn TODO: 準備中 + */ + void setSortReturn(CobolDataStorage sortReturn) { + this.sortReturn = sortReturn; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + AbstractCobolField getFnstatus() { + return fnstatus; + } + + /** + * TODO: 準備中 + * + * @param fnstatus TODO: 準備中 + */ + void setFnstatus(AbstractCobolField fnstatus) { + this.fnstatus = fnstatus; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + int getUnique() { + return unique; + } + + /** + * TODO: 準備中 + * + * @param unique TODO: 準備中 + */ + void setUnique(int unique) { + this.unique = unique; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + int getRetrieving() { + return retrieving; + } + + /** + * TODO: 準備中 + * + * @param retrieving TODO: 準備中 + */ + void setRetrieving(int retrieving) { + this.retrieving = retrieving; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + int getFilesUsed() { + return filesUsed; + } + + /** + * TODO: 準備中 + * + * @param filesUsed TODO: 準備中 + */ + void setFilesUsed(int filesUsed) { + this.filesUsed = filesUsed; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + int getSize() { + return size; + } + + /** + * TODO: 準備中 + * + * @param size TODO: 準備中 + */ + void setSize(int size) { + this.size = size; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + int getrSize() { + return rSize; + } + + /** + * TODO: 準備中 + * + * @param rSize TODO: 準備中 + */ + void setrSize(int rSize) { + this.rSize = rSize; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + int getwSize() { + return wSize; + } + + /** + * TODO: 準備中 + * + * @param wSize TODO: 準備中 + */ + void setwSize(int wSize) { + this.wSize = wSize; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + int getMemory() { + return memory; + } + + /** + * TODO: 準備中 + * + * @param memory TODO: 準備中 + */ + void setMemory(int memory) { + this.memory = memory; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + int getDestinationFile() { + return destinationFile; + } + + /** + * TODO: 準備中 + * + * @param destinationFile TODO: 準備中 + */ + void setDestinationFile(int destinationFile) { + this.destinationFile = destinationFile; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + int getRetrievalQueue() { + return retrievalQueue; + } + + /** + * TODO: 準備中 + * + * @param retrievalQueue TODO: 準備中 + */ + void setRetrievalQueue(int retrievalQueue) { + this.retrievalQueue = retrievalQueue; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + MemoryStruct[] getQueue() { + return queue; + } + + /** + * TODO: 準備中 + * + * @param queue TODO: 準備中 + */ + void setQueue(MemoryStruct[] queue) { + this.queue = queue; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + FileStruct[] getFile() { + return file; + } + + /** + * TODO: 準備中 + * + * @param file TODO: 準備中 + */ + void setFile(FileStruct[] file) { + this.file = file; + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/FileIO.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/FileIO.java index c1caf73a..b3634358 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/FileIO.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/FileIO.java @@ -1,430 +1,432 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.file; - -import java.io.IOException; -import java.io.InputStream; -import java.io.PrintStream; -import java.io.RandomAccessFile; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; -import java.nio.channels.FileLock; -import java.nio.channels.NonReadableChannelException; -import java.nio.channels.NonWritableChannelException; -import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; - -/** TODO: 準備中 */ -class FileIO { - - private FileChannel fc; - private FileLock fl = null; - private boolean useStdOut = true; - private boolean useStdIn = true; - private boolean atEnd = false; - - private static final boolean USE_READ_BUFFER = false; - private static final int READ_BUFFER_SIZE = 1024; - private int readBufferIndex; - private byte[] readBuffer; - private int readBufferEndIndex; - - private int writeBufferSize = 0; - private int writeBufferEndIndex = 0; - private byte[] writeBuffer; - - /** TODO: 準備中 */ - FileIO() { - this.useStdOut = true; - this.useStdIn = true; - - this.readBufferIndex = READ_BUFFER_SIZE; - this.readBuffer = new byte[READ_BUFFER_SIZE]; - this.readBufferEndIndex = READ_BUFFER_SIZE; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - boolean isAtEnd() { - return this.atEnd; - } - - /** - * TODO: 準備中 - * - * @param fc TODO: 準備中 - * @param fl TODO: 準備中 - */ - void setChannel(FileChannel fc, FileLock fl) { - this.fc = fc; - this.fl = fl; - this.useStdOut = false; - this.useStdIn = false; - } - - /** - * TODO: 準備中 - * - * @param ra TODO: 準備中 - * @param fl TODO: 準備中 - */ - void setRandomAccessFile(RandomAccessFile ra, FileLock fl) { - this.useStdOut = false; - this.useStdIn = false; - this.fc = ra.getChannel(); - } - - /** - * TODO: 準備中 - * - * @param out TODO: 準備中 - */ - void setOut(PrintStream out) { - this.useStdOut = true; - } - - /** - * TODO: 準備中 - * - * @param in TODO: 準備中 - */ - void setIn(InputStream in) { - this.useStdIn = true; - } - - /** - * TODO: 準備中 - * - * @param bufferSize TODO: 準備中 - */ - void prepareWriteBuffer(int bufferSize) { - if (bufferSize > 0) { - this.writeBufferSize = bufferSize; - this.writeBufferEndIndex = 0; - if (this.writeBuffer == null || this.writeBuffer.length < bufferSize) { - this.writeBuffer = new byte[bufferSize]; - } - } - } - - private void destroyWriteBuffer() { - this.writeBufferSize = 0; - this.writeBufferEndIndex = 0; - } - - /** - * TODO: 準備中 - * - * @param bytes TODO: 準備中 - * @param size TODO: 準備中 - * @return TODO: 準備中 - */ - int read(byte[] bytes, int size) { - if (useStdIn) { - // 標準入力を使う - System.err.println("read stdin not implmented"); - return 0; - } else { - int readSize; - ByteBuffer data = ByteBuffer.wrap(bytes); - try { - readSize = this.fc.read(data); - } catch (IOException | NonReadableChannelException e) { - return 0; - } - - this.atEnd = readSize == -1; - if (readSize == -1) { - return 0; - } - } - return 1; - } - - /** - * TODO: 準備中 - * - * @param storage TODO: 準備中 - * @param size TODO: 準備中 - * @return TODO: 準備中 - * @throws IOException TODO: 準備中 - */ - int read(CobolDataStorage storage, int size) throws IOException { - if (useStdIn) { - return 0; - } else { - if (this.fc == null) { - throw new IOException(); - } - int i = 0; - try { - for (i = 0; i < size; ++i) { - byte[] b = new byte[1]; - ByteBuffer bb = ByteBuffer.wrap(b); - if (this.fc.read(bb) != 1) { - return i; - } - storage.setByte(i, b[0]); - } - } catch (IOException | NonReadableChannelException e) { - throw e; - } - return size; - } - } - - private boolean writeByteBuffer(ByteBuffer bb) { - try { - this.fc.write(bb); - } catch (IOException | NonWritableChannelException e) { - return false; - } - return true; - } - - private boolean outputWriteBuffer() { - if (writeBufferEndIndex > 0 && writeBufferSize > 0) { - ByteBuffer bb = ByteBuffer.wrap(writeBuffer, 0, writeBufferEndIndex); - if (!writeByteBuffer(bb)) { - return false; - } - writeBufferEndIndex = 0; - } - return true; - } - - /** - * TODO: 準備中 - * - * @param bytes TODO: 準備中 - * @param size TODO: 準備中 - * @return TODO: 準備中 - */ - boolean write(byte[] bytes, int size) { - if (this.fc == null) { - return false; - } - if (writeBufferSize > 0 && size <= writeBufferSize - writeBufferEndIndex) { - System.arraycopy(bytes, 0, writeBuffer, writeBufferEndIndex, size); - writeBufferEndIndex += size; - return true; - } - if (!outputWriteBuffer()) { - return false; - } - if (writeBufferSize > 0 && size <= writeBufferSize - writeBufferEndIndex) { - System.arraycopy(bytes, 0, writeBuffer, writeBufferEndIndex, size); - writeBufferEndIndex += size; - return true; - } - ByteBuffer bb = ByteBuffer.wrap(bytes, 0, size); - return writeByteBuffer(bb); - } - - /** - * TODO: 準備中 - * - * @param storage TODO: 準備中 - * @param size TODO: 準備中 - * @return TODO: 準備中 - */ - boolean write(CobolDataStorage storage, int size) { - if (this.fc == null) { - return false; - } - if (writeBufferSize > 0 && size <= writeBufferSize - writeBufferEndIndex) { - for (int i = 0; i < size; ++i) { - writeBuffer[writeBufferEndIndex + i] = storage.getByte(i); - } - writeBufferEndIndex += size; - return true; - } - if (!outputWriteBuffer()) { - return false; - } - if (writeBufferSize > 0 && size <= writeBufferSize - writeBufferEndIndex) { - for (int i = 0; i < size; ++i) { - writeBuffer[writeBufferEndIndex + i] = storage.getByte(i); - } - writeBufferEndIndex += size; - return true; - } - ByteBuffer bb = storage.getByteBuffer(size); - return writeByteBuffer(bb); - } - - /** - * TODO: 準備中 - * - * @param val TODO: 準備中 - * @return TODO: 準備中 - */ - byte putc(byte val) { - if (this.fc == null) { - return 0; - } - if (writeBufferSize > 0 && 1 <= writeBufferSize - writeBufferEndIndex) { - writeBuffer[writeBufferEndIndex++] = val; - return val; - } - if (!outputWriteBuffer()) { - return -1; - } - if (writeBufferSize > 0 && 1 <= writeBufferSize - writeBufferEndIndex) { - writeBuffer[writeBufferEndIndex++] = val; - return val; - } - byte[] arr = {val}; - if (writeByteBuffer(ByteBuffer.wrap(arr))) { - return val; - } else { - return -1; - } - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - int getc() { - if (this.fc == null) { - return 0; - } - if (USE_READ_BUFFER) { - if (readBufferIndex >= READ_BUFFER_SIZE) { - this.readBufferIndex = 0; - try { - ByteBuffer bb = ByteBuffer.wrap(readBuffer); - int readBytes = this.fc.read(bb); - if (readBytes <= 0) { - this.readBufferEndIndex = -1; - } else { - this.readBufferEndIndex = readBytes; - } - } catch (IOException | NonReadableChannelException e) { - return -1; - } - } - - if (this.readBufferIndex >= this.readBufferEndIndex) { - return -1; - } - - return readBuffer[readBufferIndex++]; - - } else { - try { - byte[] b = new byte[1]; - ByteBuffer bb = ByteBuffer.wrap(b); - if (this.fc.read(bb) == 1) { - return b[0]; - } else { - return -1; - } - } catch (IOException | NonReadableChannelException e) { - return -1; - } - } - } - - /** TODO: 準備中 */ - void close() { - if (!useStdOut && !useStdIn && this.fc != null) { - try { - outputWriteBuffer(); - destroyWriteBuffer(); - this.fc.close(); - } catch (IOException e) { - return; - } - } - } - - /** TODO: 準備中 */ - void flush() { - if (!useStdOut) { - try { - outputWriteBuffer(); - this.fc.force(false); - } catch (IOException e) { - return; - } - } - } - - /** TODO: 準備中 */ - static final int SEEK_SET = 0; - /** TODO: 準備中 */ - static final int SEEK_CUR = 1; - - /** - * TODO: 準備中 - * - * @param offset TODO: 準備中 - * @param origin TODO: 準備中 - * @return TODO: 準備中 - */ - boolean seek(long offset, int origin) { - if (!useStdOut && !useStdIn) { - try { - switch (origin) { - case FileIO.SEEK_SET: - this.fc.position(offset); - break; - case FileIO.SEEK_CUR: - this.fc.position(this.fc.position() + offset); - break; - default: - return false; - } - } catch (IOException e) { - return false; - } - } - return true; - } - - /** TODO: 準備中 */ - void seekInit() {} - - /** TODO: 準備中 */ - void rewind() { - if (!useStdOut && !useStdIn) { - try { - this.fc.position(0L); - } catch (IOException e) { - return; - } - } - } - - /** TODO: 準備中 */ - void releaseLock() { - if ((!useStdOut || !useStdIn) && this.fl != null) { - try { - this.fl.release(); - } catch (IOException e) { - return; - } - } - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.file; + +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; +import java.io.RandomAccessFile; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.channels.FileLock; +import java.nio.channels.NonReadableChannelException; +import java.nio.channels.NonWritableChannelException; +import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; + +/** TODO: 準備中 */ +class FileIO { + + private FileChannel fc; + private FileLock fl = null; + private boolean useStdOut = true; + private boolean useStdIn = true; + private boolean atEnd = false; + + private static final boolean USE_READ_BUFFER = false; + private static final int READ_BUFFER_SIZE = 1024; + private int readBufferIndex; + private byte[] readBuffer; + private int readBufferEndIndex; + + private int writeBufferSize = 0; + private int writeBufferEndIndex = 0; + private byte[] writeBuffer; + + /** TODO: 準備中 */ + FileIO() { + this.useStdOut = true; + this.useStdIn = true; + + this.readBufferIndex = READ_BUFFER_SIZE; + this.readBuffer = new byte[READ_BUFFER_SIZE]; + this.readBufferEndIndex = READ_BUFFER_SIZE; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + boolean isAtEnd() { + return this.atEnd; + } + + /** + * TODO: 準備中 + * + * @param fc TODO: 準備中 + * @param fl TODO: 準備中 + */ + void setChannel(FileChannel fc, FileLock fl) { + this.fc = fc; + this.fl = fl; + this.useStdOut = false; + this.useStdIn = false; + } + + /** + * TODO: 準備中 + * + * @param ra TODO: 準備中 + * @param fl TODO: 準備中 + */ + void setRandomAccessFile(RandomAccessFile ra, FileLock fl) { + this.useStdOut = false; + this.useStdIn = false; + this.fc = ra.getChannel(); + this.fl = fl; + } + + /** + * TODO: 準備中 + * + * @param out TODO: 準備中 + */ + void setOut(PrintStream out) { + this.useStdOut = true; + } + + /** + * TODO: 準備中 + * + * @param in TODO: 準備中 + */ + void setIn(InputStream in) { + this.useStdIn = true; + } + + /** + * TODO: 準備中 + * + * @param bufferSize TODO: 準備中 + */ + void prepareWriteBuffer(int bufferSize) { + if (bufferSize > 0) { + this.writeBufferSize = bufferSize; + this.writeBufferEndIndex = 0; + if (this.writeBuffer == null || this.writeBuffer.length < bufferSize) { + this.writeBuffer = new byte[bufferSize]; + } + } + } + + private void destroyWriteBuffer() { + this.writeBufferSize = 0; + this.writeBufferEndIndex = 0; + } + + /** + * TODO: 準備中 + * + * @param bytes TODO: 準備中 + * @param size TODO: 準備中 + * @return TODO: 準備中 + */ + int read(byte[] bytes, int size) { + if (useStdIn) { + // 標準入力を使う + System.err.println("read stdin not implmented"); + return 0; + } else { + int readSize; + ByteBuffer data = ByteBuffer.wrap(bytes); + try { + readSize = this.fc.read(data); + } catch (IOException | NonReadableChannelException e) { + return 0; + } + + this.atEnd = readSize == -1; + if (readSize == -1) { + return 0; + } + } + return 1; + } + + /** + * TODO: 準備中 + * + * @param storage TODO: 準備中 + * @param size TODO: 準備中 + * @return TODO: 準備中 + * @throws IOException TODO: 準備中 + */ + int read(CobolDataStorage storage, int size) throws IOException { + if (useStdIn) { + return 0; + } else { + if (this.fc == null) { + throw new IOException(); + } + int i = 0; + try { + for (i = 0; i < size; ++i) { + byte[] b = new byte[1]; + ByteBuffer bb = ByteBuffer.wrap(b); + if (this.fc.read(bb) != 1) { + return i; + } + storage.setByte(i, b[0]); + } + } catch (IOException | NonReadableChannelException e) { + throw e; + } + return size; + } + } + + private boolean writeByteBuffer(ByteBuffer bb) { + try { + this.fc.write(bb); + } catch (IOException | NonWritableChannelException e) { + return false; + } + return true; + } + + private boolean outputWriteBuffer() { + if (writeBufferEndIndex > 0 && writeBufferSize > 0) { + ByteBuffer bb = ByteBuffer.wrap(writeBuffer, 0, writeBufferEndIndex); + if (!writeByteBuffer(bb)) { + return false; + } + writeBufferEndIndex = 0; + } + return true; + } + + /** + * TODO: 準備中 + * + * @param bytes TODO: 準備中 + * @param size TODO: 準備中 + * @return TODO: 準備中 + */ + boolean write(byte[] bytes, int size) { + if (this.fc == null) { + return false; + } + if (writeBufferSize > 0 && size <= writeBufferSize - writeBufferEndIndex) { + System.arraycopy(bytes, 0, writeBuffer, writeBufferEndIndex, size); + writeBufferEndIndex += size; + return true; + } + if (!outputWriteBuffer()) { + return false; + } + if (writeBufferSize > 0 && size <= writeBufferSize - writeBufferEndIndex) { + System.arraycopy(bytes, 0, writeBuffer, writeBufferEndIndex, size); + writeBufferEndIndex += size; + return true; + } + ByteBuffer bb = ByteBuffer.wrap(bytes, 0, size); + return writeByteBuffer(bb); + } + + /** + * TODO: 準備中 + * + * @param storage TODO: 準備中 + * @param size TODO: 準備中 + * @return TODO: 準備中 + */ + boolean write(CobolDataStorage storage, int size) { + if (this.fc == null) { + return false; + } + if (writeBufferSize > 0 && size <= writeBufferSize - writeBufferEndIndex) { + for (int i = 0; i < size; ++i) { + writeBuffer[writeBufferEndIndex + i] = storage.getByte(i); + } + writeBufferEndIndex += size; + return true; + } + if (!outputWriteBuffer()) { + return false; + } + if (writeBufferSize > 0 && size <= writeBufferSize - writeBufferEndIndex) { + for (int i = 0; i < size; ++i) { + writeBuffer[writeBufferEndIndex + i] = storage.getByte(i); + } + writeBufferEndIndex += size; + return true; + } + ByteBuffer bb = storage.getByteBuffer(size); + return writeByteBuffer(bb); + } + + /** + * TODO: 準備中 + * + * @param val TODO: 準備中 + * @return TODO: 準備中 + */ + byte putc(byte val) { + if (this.fc == null) { + return 0; + } + if (writeBufferSize > 0 && 1 <= writeBufferSize - writeBufferEndIndex) { + writeBuffer[writeBufferEndIndex++] = val; + return val; + } + if (!outputWriteBuffer()) { + return -1; + } + if (writeBufferSize > 0 && 1 <= writeBufferSize - writeBufferEndIndex) { + writeBuffer[writeBufferEndIndex++] = val; + return val; + } + byte[] arr = {val}; + if (writeByteBuffer(ByteBuffer.wrap(arr))) { + return val; + } else { + return -1; + } + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + int getc() { + if (this.fc == null) { + return 0; + } + if (USE_READ_BUFFER) { + if (readBufferIndex >= READ_BUFFER_SIZE) { + this.readBufferIndex = 0; + try { + ByteBuffer bb = ByteBuffer.wrap(readBuffer); + int readBytes = this.fc.read(bb); + if (readBytes <= 0) { + this.readBufferEndIndex = -1; + } else { + this.readBufferEndIndex = readBytes; + } + } catch (IOException | NonReadableChannelException e) { + return -1; + } + } + + if (this.readBufferIndex >= this.readBufferEndIndex) { + return -1; + } + + return readBuffer[readBufferIndex++]; + + } else { + try { + byte[] b = new byte[1]; + ByteBuffer bb = ByteBuffer.wrap(b); + if (this.fc.read(bb) == 1) { + return b[0]; + } else { + return -1; + } + } catch (IOException | NonReadableChannelException e) { + return -1; + } + } + } + + /** TODO: 準備中 */ + void close() { + if (!useStdOut && !useStdIn && this.fc != null) { + try { + outputWriteBuffer(); + destroyWriteBuffer(); + this.fc.close(); + } catch (IOException e) { + return; + } + } + } + + /** TODO: 準備中 */ + void flush() { + if (!useStdOut) { + try { + outputWriteBuffer(); + this.fc.force(false); + } catch (IOException e) { + return; + } + } + } + + /** TODO: 準備中 */ + static final int SEEK_SET = 0; + + /** TODO: 準備中 */ + static final int SEEK_CUR = 1; + + /** + * TODO: 準備中 + * + * @param offset TODO: 準備中 + * @param origin TODO: 準備中 + * @return TODO: 準備中 + */ + boolean seek(long offset, int origin) { + if (!useStdOut && !useStdIn) { + try { + switch (origin) { + case FileIO.SEEK_SET: + this.fc.position(offset); + break; + case FileIO.SEEK_CUR: + this.fc.position(this.fc.position() + offset); + break; + default: + return false; + } + } catch (IOException e) { + return false; + } + } + return true; + } + + /** TODO: 準備中 */ + void seekInit() {} + + /** TODO: 準備中 */ + void rewind() { + if (!useStdOut && !useStdIn) { + try { + this.fc.position(0L); + } catch (IOException e) { + return; + } + } + } + + /** TODO: 準備中 */ + void releaseLock() { + if ((!useStdOut || !useStdIn) && this.fl != null) { + try { + this.fl.release(); + } catch (IOException e) { + return; + } + } + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/FileStruct.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/FileStruct.java index c7ea71fc..a89226f2 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/FileStruct.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/FileStruct.java @@ -1,61 +1,61 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.file; - -/** TODO: 準備中 */ -class FileStruct { - private FileIO fp; - private int count; - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - FileIO getFp() { - return fp; - } - - /** - * TODO: 準備中 - * - * @param fp TODO: 準備中 - */ - void setFp(FileIO fp) { - this.fp = fp; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - int getCount() { - return count; - } - - /** - * TODO: 準備中 - * - * @param count TODO: 準備中 - */ - void setCount(int count) { - this.count = count; - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.file; + +/** TODO: 準備中 */ +class FileStruct { + private FileIO fp; + private int count; + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + FileIO getFp() { + return fp; + } + + /** + * TODO: 準備中 + * + * @param fp TODO: 準備中 + */ + void setFp(FileIO fp) { + this.fp = fp; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + int getCount() { + return count; + } + + /** + * TODO: 準備中 + * + * @param count TODO: 準備中 + */ + void setCount(int count) { + this.count = count; + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/IndexedCursor.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/IndexedCursor.java index 9231cf6d..627880f9 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/IndexedCursor.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/IndexedCursor.java @@ -1,719 +1,568 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.file; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -/** Represents a result of fetching a data from SQLite tables. */ -class FetchResult { - /** TODO: 準備中 */ - byte[] key; - /** TODO: 準備中 */ - byte[] value; - /** TODO: 準備中 */ - int dupNo; - - /** - * TODO: 準備中 - * - * @param key TODO: 準備中 - * @param value TODO: 準備中 - * @param dupNo TODO: 準備中 - */ - FetchResult(byte[] key, byte[] value, int dupNo) { - this.key = key; - this.value = value; - this.dupNo = dupNo; - } - - /** - * TODO: 準備中 - * - * @param key TODO: 準備中 - * @param value TODO: 準備中 - */ - FetchResult(byte[] key, byte[] value) { - this.key = key; - this.value = value; - this.dupNo = 0; - } -} - -enum CursorReadOption { - NEXT, - PREV, - FIRST, - LAST -} - -/** Emulates a cursor in SQLite */ -final class IndexedCursor { - /** a cursor to the top direction */ - private Optional backwardCursor; - - /** a cursor to the bottom direction */ - private Optional forwardCursor; - - /** a connection to the SQLite database */ - private Connection conn; - - /** firstFetch is true if and only if the cursor has not read any data yet */ - private boolean firstFetch; - - /** a position in buffers that stores the read data */ - private int cursorIndex; - - /** one of COB_EQ, COB_LT, COB_LE, COB_GT, COB_GE in CobolIndexedFile.java */ - private int comparator; - - /** isDuplicate is true if and only if the table key allows duplicates */ - private boolean isDuplicate; - - /** a key */ - private byte[] key; - - /** forwardBuffer stores data located to the bottom direction from the first read position */ - List forwardBuffer; - - /** bakckwardBuffer stores data located to the first direction from the first read position */ - List backwardBuffer; - - /** the index of the table */ - private int tableIndex; - - private boolean nextCursorFetchKeyDiffrent; - private boolean prevCursorFetchKeyDiffrent; - - /** - * TODO: 準備中 - * - * @param comparator TODO: 準備中 - */ - void setComparator(int comparator) { - this.comparator = comparator; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - int getComparator() { - return this.comparator; - } - - private IndexedCursor( - Connection conn, byte[] key, int tableIndex, boolean isDuplicate, int comparator) { - this.conn = conn; - this.key = new byte[key.length]; - System.arraycopy(key, 0, this.key, 0, key.length); - this.cursorIndex = 0; - this.comparator = comparator; - this.firstFetch = true; - this.isDuplicate = isDuplicate; - this.tableIndex = tableIndex; - this.nextCursorFetchKeyDiffrent = false; - this.prevCursorFetchKeyDiffrent = false; - this.forwardBuffer = new ArrayList(); - this.backwardBuffer = new ArrayList(); - } - - /** - * TODO: 準備中 - * - * @param conn TODO: 準備中 - * @param key TODO: 準備中 - * @param tableIndex TODO: 準備中 - * @param isDuplicate TODO: 準備中 - * @param comparator TODO: 準備中 - * @return TODO: 準備中 - */ - static Optional createCursor( - Connection conn, byte[] key, int tableIndex, boolean isDuplicate, int comparator) { - IndexedCursor cursor = new IndexedCursor(conn, key, tableIndex, isDuplicate, comparator); - cursor.forwardCursor = getCursor(conn, key, tableIndex, isDuplicate, comparator, true); - cursor.backwardCursor = getCursor(conn, key, tableIndex, isDuplicate, comparator, false); - if (!cursor.forwardCursor.isPresent() || !cursor.backwardCursor.isPresent()) { - return Optional.empty(); - } else { - return Optional.of(cursor); - } - } - - Optional reloadCursor() { - if (this.firstFetch) { - return createCursor(this.conn, this.key, this.tableIndex, this.isDuplicate, this.comparator); - } - - int newComparator; - if (this.comparator == CobolIndexedFile.COB_EQ) { - newComparator = CobolIndexedFile.COB_EQ; - } else { - newComparator = CobolIndexedFile.COB_GE; - } - - FetchResult result; - if (this.cursorIndex < 0) { - result = this.backwardBuffer.get(-this.cursorIndex - 1); - } else { - result = this.forwardBuffer.get(this.cursorIndex); - } - - IndexedCursor newCursor = - new IndexedCursor(this.conn, this.key, this.tableIndex, this.isDuplicate, this.comparator); - newCursor.forwardCursor = - reloadedCursor( - this.conn, - this.tableIndex, - this.isDuplicate, - newComparator, - result, - this.comparator, - true); - newCursor.backwardCursor = - reloadedCursor( - this.conn, - this.tableIndex, - this.isDuplicate, - newComparator, - result, - this.comparator, - false); - - Optional reFetchResult = - reFetch(this.conn, this.tableIndex, this.isDuplicate, result); - if (reFetchResult.isPresent()) { - FetchResult r = reFetchResult.get(); - newCursor.forwardBuffer.add(r); - newCursor.cursorIndex = 0; - newCursor.firstFetch = false; - } - - if (!newCursor.forwardCursor.isPresent() || !newCursor.backwardCursor.isPresent()) { - return Optional.empty(); - } else { - return Optional.of(newCursor); - } - } - - private static Optional reFetch( - Connection conn, int tableIndex, boolean isDuplicate, FetchResult result) { - final boolean isPrimaryTable = tableIndex == 0; - final String primaryTable = CobolIndexedFile.getTableName(0); - final String subTable = CobolIndexedFile.getTableName(tableIndex); - final String query; - if (isPrimaryTable) { - query = String.format("select key, value from %s where key == ?", primaryTable); - } else if (isDuplicate) { - query = - String.format( - "select %s.key, %s.value, %s.dupNo from " - + "%s join %s on %s.value = %s.key " - + "where %s.key == ? and %s.dupNo == ?", - subTable, - primaryTable, - subTable, - subTable, - primaryTable, - subTable, - primaryTable, - subTable, - subTable); - } else { - query = - String.format( - "select %s.key, %s.value from " - + "%s join %s on %s.value = %s.key " - + "where %s.key == ?", - subTable, primaryTable, subTable, primaryTable, subTable, primaryTable, subTable); - } - - try { - PreparedStatement statement = conn.prepareStatement(query); - if (isDuplicate) { - statement.setBytes(1, result.key); - statement.setInt(2, result.dupNo); - } else { - statement.setBytes(1, result.key); - } - statement.setFetchSize(0); - ResultSet rs = statement.executeQuery(); - if (rs.next()) { - byte[] key = rs.getBytes(1); - byte[] value = rs.getBytes(2); - if (isDuplicate) { - int dupNo = rs.getInt(3); - return Optional.of(new FetchResult(key, value, dupNo)); - } else { - return Optional.of(new FetchResult(key, value)); - } - } - return Optional.empty(); - } catch (SQLException e) { - return Optional.empty(); - } - } - - private static Optional reloadedCursor( - Connection conn, - int tableIndex, - boolean isDuplicate, - int comparator, - FetchResult result, - int comparaotr, - boolean forward) { - - final String compOperator = forward ? ">" : "<"; - - final String sortOrder = forward ? "" : "desc"; - - final String queryPreffix = - getReloadCursorQueryPrefix(tableIndex, isDuplicate, compOperator, sortOrder); - - final String querySuffix = getQuerySuffix(tableIndex, isDuplicate, sortOrder); - - final String query = queryPreffix + querySuffix; - - try { - PreparedStatement statement = conn.prepareStatement(query); - if (isDuplicate) { - statement.setBytes(1, result.key); - statement.setInt(2, result.dupNo); - statement.setBytes(3, result.key); - } else { - statement.setBytes(1, result.key); - } - statement.setFetchSize(0); - return Optional.ofNullable(statement.executeQuery()); - } catch (SQLException e) { - return Optional.empty(); - } - } - - private static String getReloadCursorQueryPrefix( - int index, boolean isDuplicate, String compOperator, String sortOrder) { - final boolean isPrimaryTable = index == 0; - final String primaryTable = CobolIndexedFile.getTableName(0); - final String subTable = CobolIndexedFile.getTableName(index); - if (isPrimaryTable) { - return String.format( - "select key, value from %s where key %s ? order by key %s", - primaryTable, compOperator, sortOrder); - } else if (isDuplicate) { - return String.format( - "select %s.key, %s.value, %s.dupNo from " - + "%s join %s on %s.value = %s.key " - + "where (%s.key == ? and %s.dupNo %s ?) or %s.key %s ? " - + "order by %s.key %s", - subTable, - primaryTable, - subTable, - subTable, - primaryTable, - subTable, - primaryTable, - subTable, - subTable, - compOperator, - subTable, - compOperator, - subTable, - sortOrder); - } else { - return String.format( - "select %s.key, %s.value from " - + "%s join %s on %s.value = %s.key " - + "where %s.key %s ? " - + "order by %s.key %s", - subTable, - primaryTable, - subTable, - primaryTable, - subTable, - primaryTable, - subTable, - compOperator, - subTable, - sortOrder); - } - } - - static boolean matchKeyHead(byte[] originalKey, byte[] fetchKey) { - if (originalKey.length > fetchKey.length) { - return false; - } - for (int i = 0; i < originalKey.length; ++i) { - if (originalKey[i] != fetchKey[i]) { - return false; - } - } - return true; - } - - private Optional fetchNext(ResultSet cursor) { - if (this.comparator == CobolIndexedFile.COB_EQ && this.nextCursorFetchKeyDiffrent) { - return Optional.empty(); - } - try { - if (cursor.next()) { - byte[] fetchKey = cursor.getBytes(1); - byte[] fetchValue = cursor.getBytes(2); - if (this.comparator == CobolIndexedFile.COB_EQ && !matchKeyHead(this.key, fetchKey)) { - this.nextCursorFetchKeyDiffrent = true; - return Optional.empty(); - } - FetchResult result; - if (this.isDuplicate) { - int dupNo = cursor.getInt(3); - result = new FetchResult(fetchKey, fetchValue, dupNo); - } else { - result = new FetchResult(fetchKey, fetchValue); - } - return Optional.of(result); - } else { - return Optional.empty(); - } - } catch (SQLException e) { - return Optional.empty(); - } - } - - private Optional fetchPrev(ResultSet cursor) { - if (this.comparator == CobolIndexedFile.COB_EQ && this.prevCursorFetchKeyDiffrent) { - return Optional.empty(); - } - try { - if (cursor.next()) { - byte[] fetchKey = cursor.getBytes(1); - byte[] fetchValue = cursor.getBytes(2); - if (this.comparator == CobolIndexedFile.COB_EQ && !matchKeyHead(this.key, fetchKey)) { - this.prevCursorFetchKeyDiffrent = true; - return Optional.empty(); - } - FetchResult result; - if (this.isDuplicate) { - int dupNo = cursor.getInt(3); - result = new FetchResult(fetchKey, fetchValue, dupNo); - } else { - result = new FetchResult(fetchKey, fetchValue); - } - return Optional.of(result); - } else { - return Optional.empty(); - } - } catch (SQLException e) { - return Optional.empty(); - } - } - - Optional next() { - if (!this.forwardCursor.isPresent()) { - return Optional.empty(); - } - ResultSet cursor = this.forwardCursor.get(); - if (this.firstFetch) { - this.cursorIndex = 0; - Optional fetchResult = this.fetchNext(cursor); - if (this.comparator == CobolIndexedFile.COB_GT) { - while (fetchResult.isPresent()) { - FetchResult result = fetchResult.get(); - if (!matchKeyHead(this.key, result.key)) { - break; - } - fetchResult = this.fetchNext(cursor); - } - } - this.firstFetch = false; - if (fetchResult.isPresent()) { - this.forwardBuffer.add(fetchResult.get()); - } - return fetchResult; - } else if (this.cursorIndex >= this.forwardBuffer.size()) { - return Optional.empty(); - } else if (-this.cursorIndex > this.backwardBuffer.size()) { - ++this.cursorIndex; - return Optional.empty(); - } else if (this.cursorIndex == this.forwardBuffer.size() - 1) { - Optional fetchResult = this.fetchNext(cursor); - if (fetchResult.isPresent()) { - this.forwardBuffer.add(fetchResult.get()); - ++this.cursorIndex; - } - return fetchResult; - } else if (this.cursorIndex < -1) { - ++this.cursorIndex; - return Optional.of(backwardBuffer.get(-this.cursorIndex - 1)); - } else { - ++this.cursorIndex; - return Optional.of(forwardBuffer.get(this.cursorIndex)); - } - } - - Optional prev() { - if (!this.backwardCursor.isPresent()) { - return Optional.empty(); - } - ResultSet cursor = this.backwardCursor.get(); - if (this.firstFetch) { - this.cursorIndex = -1; - Optional fetchResult = this.fetchPrev(cursor); - if (fetchResult.isPresent()) { - this.firstFetch = false; - this.backwardBuffer.add(fetchResult.get()); - } - return fetchResult; - } else if (this.cursorIndex > this.forwardBuffer.size()) { - --this.cursorIndex; - return Optional.empty(); - } else if (-this.cursorIndex - 1 >= this.backwardBuffer.size()) { - return Optional.empty(); - } else if (-this.cursorIndex == this.backwardBuffer.size()) { - Optional fetchResult = this.fetchPrev(cursor); - if (fetchResult.isPresent()) { - this.backwardBuffer.add(fetchResult.get()); - --this.cursorIndex; - } - return fetchResult; - } else if (this.cursorIndex > 0) { - --this.cursorIndex; - return Optional.of(forwardBuffer.get(this.cursorIndex)); - } else { - --this.cursorIndex; - return Optional.of(backwardBuffer.get(-this.cursorIndex - 1)); - } - } - - void close() { - try { - if (backwardCursor.isPresent()) { - backwardCursor.get().close(); - } - if (forwardCursor.isPresent()) { - forwardCursor.get().close(); - } - } catch (SQLException e) { - return; - } - } - - Optional read(CursorReadOption opt) { - if (opt == CursorReadOption.NEXT) { - return this.next(); - } else if (opt == CursorReadOption.PREV) { - return this.prev(); - } else { - return Optional.empty(); - } - } - - private static Optional getCursor( - Connection conn, - byte[] key, - int index, - boolean isDuplicate, - int comparator, - boolean forward) { - final Optional optionalCompOperator = getCompOperator(comparator, forward); - - if (!optionalCompOperator.isPresent()) { - return Optional.empty(); - } - - final String compOperator = optionalCompOperator.get(); - - final String sortOrder = forward ? "" : "desc"; - - final String queryPreffix = getQueryPrefix(index, compOperator, sortOrder, isDuplicate); - - final String querySuffix = getQuerySuffix(index, isDuplicate, sortOrder); - - final String query = queryPreffix + querySuffix; - - try { - PreparedStatement statement = conn.prepareStatement(query); - statement.setBytes(1, key); - statement.setFetchSize(0); - return Optional.ofNullable(statement.executeQuery()); - } catch (SQLException e) { - return Optional.empty(); - } - } - - private static Optional getCompOperator(int comparator, boolean forward) { - if (comparator == CobolIndexedFile.COB_EQ - || comparator == CobolIndexedFile.COB_GE - || comparator == CobolIndexedFile.COB_LT) { - return Optional.of(forward ? ">=" : "<"); - } else if (comparator == CobolIndexedFile.COB_GT || comparator == CobolIndexedFile.COB_LE) { - return Optional.of(forward ? ">" : "<="); - } else { - return Optional.empty(); - } - } - - private static String getQueryPrefix( - int index, String compOperator, String sortOrder, boolean isDuplicate) { - final boolean isPrimaryTable = index == 0; - final String primaryTable = CobolIndexedFile.getTableName(0); - final String subTable = CobolIndexedFile.getTableName(index); - if (isPrimaryTable) { - return String.format( - "select key, value from %s where key %s ? order by key %s", - primaryTable, compOperator, sortOrder); - } else if (isDuplicate) { - return String.format( - "select %s.key, %s.value, %s.dupNo from " - + "%s join %s on %s.value = %s.key " - + "where %s.key %s ? order by %s.key %s", - subTable, - primaryTable, - subTable, - subTable, - primaryTable, - subTable, - primaryTable, - subTable, - compOperator, - subTable, - sortOrder); - } else { - return String.format( - "select %s.key, %s.value from " - + "%s join %s on %s.value = %s.key " - + "where %s.key %s ? order by %s.key %s", - subTable, - primaryTable, - subTable, - primaryTable, - subTable, - primaryTable, - subTable, - compOperator, - subTable, - sortOrder); - } - } - - private Optional getCursorForFirstLast( - int index, boolean isDuplicate, CursorReadOption option) { - final String query = getQueryForFirstLast(index, isDuplicate, option); - try { - Statement statement = this.conn.createStatement(); - return Optional.ofNullable(statement.executeQuery(query)); - } catch (SQLException e) { - return Optional.empty(); - } - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - boolean moveToFirst() { - Optional cursor = - getCursorForFirstLast(this.tableIndex, this.isDuplicate, CursorReadOption.FIRST); - if (!cursor.isPresent()) { - return false; - } - this.forwardCursor = cursor; - this.backwardCursor = Optional.empty(); - this.firstFetch = true; - this.cursorIndex = 0; - return true; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - boolean moveToLast() { - Optional cursor = - getCursorForFirstLast(this.tableIndex, this.isDuplicate, CursorReadOption.LAST); - if (!cursor.isPresent()) { - return false; - } - this.backwardCursor = cursor; - this.forwardCursor = Optional.empty(); - this.firstFetch = true; - this.cursorIndex = 0; - return true; - } - - private static String getQueryForFirstLast( - int index, boolean isDuplicate, CursorReadOption option) { - final String sortOrder; - if (option == CursorReadOption.FIRST) { - sortOrder = ""; - } else { - sortOrder = "desc"; - } - - boolean isPrimaryTable = index == 0; - final String primaryTable = CobolIndexedFile.getTableName(0); - final String subTable = CobolIndexedFile.getTableName(index); - - if (isPrimaryTable) { - return String.format("select key, value from %s order by key %s", primaryTable, sortOrder); - } else { - String optionColumn; - if (isDuplicate) { - optionColumn = String.format(", %s.dupNo", subTable); - } else { - optionColumn = ""; - } - String query = - String.format( - "select %s.key, %s.value %s from " - + "%s join %s on %s.value = %s.key " - + "order by %s.key %s", - subTable, - primaryTable, - optionColumn, - subTable, - primaryTable, - subTable, - primaryTable, - subTable, - sortOrder); - if (isDuplicate) { - return query + String.format(", dupNo %s", sortOrder); - } else { - return query; - } - } - } - - private static String getQuerySuffix(int index, boolean isDuplicate, String sortOrder) { - if (isDuplicate) { - final String tableName = CobolIndexedFile.getTableName(index); - return String.format(", %s.dupNo %s", tableName, sortOrder); - } else { - return ""; - } - } -} +package jp.osscons.opensourcecobol.libcobj.file; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.Statement; +import java.util.Optional; + +/** Represents a result of fetching a data from SQLite tables. */ +class FetchResult { + /** TODO: 準備中 */ + byte[] key; + + /** TODO: 準備中 */ + byte[] value; + + /** TODO: 準備中 */ + int dupNo; + + /** + * TODO: 準備中 + * + * @param key TODO: 準備中 + * @param value TODO: 準備中 + * @param dupNo TODO: 準備中 + */ + FetchResult(byte[] key, byte[] value, int dupNo) { + this.key = key; + this.value = value; + this.dupNo = dupNo; + } + + /** + * TODO: 準備中 + * + * @param key TODO: 準備中 + * @param value TODO: 準備中 + */ + FetchResult(byte[] key, byte[] value) { + this.key = key; + this.value = value; + this.dupNo = 0; + } +} + +enum CursorReadOption { + NEXT, + PREV, + FIRST, + LAST +} + +/** + * Represents a cursor for navigating through indexed data in a CobolIndexedFile. + */ +enum CursorPosition { + BEFORE_FIRST, + AFTER_LAST, + IN_TABLE, +} + +/** Emulates a cursor in SQLite */ +final class IndexedCursor { + private final Connection conn; + private byte[] key; + private final int tableIndex; + private final boolean isDuplicate; + private int comparator; + + // variables for cursor state + private boolean firstFetch; + private CursorPosition position; + private Optional previousFetchResult; + + private IndexedCursor( + Connection conn, byte[] key, int tableIndex, boolean isDuplicate, int comparator) { + this.conn = conn; + this.key = key; + this.tableIndex = tableIndex; + this.isDuplicate = isDuplicate; + this.comparator = comparator; + + this.firstFetch = true; + this.position = CursorPosition.IN_TABLE; + this.previousFetchResult = Optional.empty(); + } + + static Optional createCursor( + Connection conn, byte[] key, int tableIndex, boolean isDuplicate, int comparator) { + return Optional.of(new IndexedCursor(conn, key, tableIndex, isDuplicate, comparator)); + } + + static boolean matchKeyHead(byte[] originalKey, byte[] fetchKey) { + if (originalKey.length > fetchKey.length) { + return false; + } + for (int i = 0; i < originalKey.length; ++i) { + if (originalKey[i] != fetchKey[i]) { + return false; + } + } + return true; + } + + Optional reloadCursor() { + return Optional.of(this); + } + + void close() {} + + void setComparator(int comparator) { + this.comparator = comparator; + } + + int getComparator() { + return this.comparator; + } + + Optional read(CursorReadOption opt) { + if (opt == CursorReadOption.NEXT) { + return this.next(); + } else if (opt == CursorReadOption.PREV) { + return this.prev(); + } else { + return Optional.empty(); + } + } + + private static String getCompOperator(int comparator) { + if (comparator == CobolIndexedFile.COB_EQ) { + // for partial key match, we use ">=" instead of "=" + return ">="; + } else if (comparator == CobolIndexedFile.COB_GE) { + return ">="; + } else if (comparator == CobolIndexedFile.COB_LE) { + return "<="; + } else if (comparator == CobolIndexedFile.COB_GT) { + return ">"; + } else if (comparator == CobolIndexedFile.COB_LT) { + return "<"; + } else { + return null; + } + } + + Optional fetchFirstRecord() { + this.previousFetchResult = Optional.empty(); + this.position = CursorPosition.IN_TABLE; + + final boolean isPrimaryTable = this.tableIndex == 0; + final String primaryTable = CobolIndexedFile.getTableName(0); + final String subTable = CobolIndexedFile.getTableName(this.tableIndex); + + String query; + if (isPrimaryTable) { + query = String.format("select key, value from %s order by key limit 1", primaryTable); + } else if (this.isDuplicate) { + query = + String.format( + "select key, value from %s order by key, dupNo limit 1", subTable); + } else { + query = String.format("select key, value from %s order by key limit 1", subTable); + } + try (Statement stmt = this.conn.createStatement(); + ResultSet rs = stmt.executeQuery(query)) { + if (rs.next()) { + byte[] key = rs.getBytes("key"); + byte[] value = rs.getBytes("value"); + if (isDuplicate) { + int dupNo = rs.getInt("dupNo"); + return Optional.of(new FetchResult(key, value, dupNo)); + } else { + return Optional.of(new FetchResult(key, value, 0)); + } + } else { + return Optional.empty(); + } + } catch (Exception e) { + return Optional.empty(); + } + } + + Optional fetchLastRecord() { + this.previousFetchResult = Optional.empty(); + this.position = CursorPosition.IN_TABLE; + + final boolean isPrimaryTable = this.tableIndex == 0; + final String primaryTable = CobolIndexedFile.getTableName(0); + final String subTable = CobolIndexedFile.getTableName(this.tableIndex); + + String query; + if (isPrimaryTable) { + query = + String.format( + "select key, value from %s order by key desc limit 1", primaryTable); + } else if (this.isDuplicate) { + query = + String.format( + "select key, value from %s order by key desc, dupNo desc limit 1", + subTable); + } else { + query = String.format("select key, value from %s order by key desc limit 1", subTable); + } + try (Statement stmt = this.conn.createStatement(); + ResultSet rs = stmt.executeQuery(query)) { + if (rs.next()) { + byte[] key = rs.getBytes("key"); + byte[] value = rs.getBytes("value"); + if (isDuplicate) { + int dupNo = rs.getInt("dupNo"); + return Optional.of(new FetchResult(key, value, dupNo)); + } else { + return Optional.of(new FetchResult(key, value, 0)); + } + } else { + return Optional.empty(); + } + } catch (Exception e) { + return Optional.empty(); + } + } + + Optional forwardNextRecord() { + this.position = CursorPosition.IN_TABLE; + + final boolean isPrimaryTable = this.tableIndex == 0; + final String primaryTable = CobolIndexedFile.getTableName(0); + final String subTable = CobolIndexedFile.getTableName(this.tableIndex); + + final String compOperator; + byte[] key; + if (this.previousFetchResult.isPresent()) { + compOperator = ">"; + key = this.previousFetchResult.get().key; + } else { + compOperator = ">="; + key = this.key; + } + + String query; + if (isPrimaryTable) { + query = + String.format( + "select key, value from %s where key %s ? order by key limit 1", + primaryTable, compOperator); + } else if (this.isDuplicate) { + query = + String.format( + "select %s.key, %s.value, %s.dupNo from " + + "%s join %s on %s.value = %s.key " + + "where (%s.key == ? and %s.dupNo %s ?) or %s.key %s ? " + + "order by %s.key, %s.dupNo limit 1", + subTable, + primaryTable, + subTable, + subTable, + primaryTable, + subTable, + primaryTable, + subTable, + subTable, + compOperator, + subTable, + compOperator, + subTable, + subTable); + } else { + query = + String.format( + "select %s.key, %s.value from " + + "%s join %s on %s.value = %s.key " + + "where %s.key %s ? " + + "order by %s.key limit 1", + subTable, + primaryTable, + subTable, + primaryTable, + subTable, + primaryTable, + subTable, + compOperator, + subTable); + } + + try (PreparedStatement stmt = this.conn.prepareStatement(query)) { + stmt.setBytes(1, key); + if (this.isDuplicate) { + int dupNo = + this.previousFetchResult.isPresent() + ? this.previousFetchResult.get().dupNo + : 0; + stmt.setInt(2, dupNo); + stmt.setBytes(3, key); + } + try (ResultSet rs = stmt.executeQuery()) { + if (rs.next()) { + byte[] fetchedKey = rs.getBytes("key"); + byte[] value = rs.getBytes("value"); + if (isDuplicate) { + int dupNo = rs.getInt("dupNo"); + return Optional.of(new FetchResult(fetchedKey, value, dupNo)); + } else { + return Optional.of(new FetchResult(fetchedKey, value, 0)); + } + } else { + this.position = CursorPosition.AFTER_LAST; + return Optional.empty(); + } + } + } catch (Exception e) { + return Optional.empty(); + } + } + + Optional backwardPrevRecord() { + this.position = CursorPosition.IN_TABLE; + + final boolean isPrimaryTable = this.tableIndex == 0; + final String primaryTable = CobolIndexedFile.getTableName(0); + final String subTable = CobolIndexedFile.getTableName(this.tableIndex); + + final String compOperator; + byte[] key; + if (this.previousFetchResult.isPresent()) { + compOperator = "<"; + key = this.previousFetchResult.get().key; + } else { + compOperator = "<="; + key = this.key; + } + + String query; + if (isPrimaryTable) { + query = + String.format( + "select key, value from %s where key %s ? order by key desc limit 1", + primaryTable, compOperator); + } else if (this.isDuplicate) { + query = + String.format( + "select %s.key, %s.value, %s.dupNo from " + + "%s join %s on %s.value = %s.key " + + "where (%s.key == ? and %s.dupNo %s ?) or %s.key %s ? " + + "order by %s.key desc, %s.dupNo desc limit 1", + subTable, + primaryTable, + subTable, + subTable, + primaryTable, + subTable, + primaryTable, + subTable, + subTable, + compOperator, + subTable, + compOperator, + subTable, + subTable); + } else { + query = + String.format( + "select %s.key, %s.value from " + + "%s join %s on %s.value = %s.key " + + "where %s.key %s ? " + + "order by %s.key desc limit 1", + subTable, + primaryTable, + subTable, + primaryTable, + subTable, + primaryTable, + subTable, + compOperator, + subTable); + } + + try (PreparedStatement stmt = this.conn.prepareStatement(query)) { + stmt.setBytes(1, key); + if (this.isDuplicate) { + int dupNo = + this.previousFetchResult.isPresent() + ? this.previousFetchResult.get().dupNo + : 0; + stmt.setInt(2, dupNo); + stmt.setBytes(3, key); + } + try (ResultSet rs = stmt.executeQuery()) { + if (rs.next()) { + byte[] fetchedKey = rs.getBytes("key"); + byte[] value = rs.getBytes("value"); + if (isDuplicate) { + int dupNo = rs.getInt("dupNo"); + return Optional.of(new FetchResult(fetchedKey, value, dupNo)); + } else { + return Optional.of(new FetchResult(fetchedKey, value, 0)); + } + } else { + this.position = CursorPosition.AFTER_LAST; + return Optional.empty(); + } + } + } catch (Exception e) { + return Optional.empty(); + } + } + + private String getSortOrderForStartStatement(int comparator) { + if (comparator == CobolIndexedFile.COB_LT || comparator == CobolIndexedFile.COB_LE) { + return "desc"; + } else { + return "asc"; + } + } + + Optional fetchRecord() { + this.previousFetchResult = Optional.empty(); + this.position = CursorPosition.IN_TABLE; + + final boolean isPrimaryTable = this.tableIndex == 0; + final String primaryTable = CobolIndexedFile.getTableName(0); + final String subTable = CobolIndexedFile.getTableName(this.tableIndex); + final String compOperator = this.getCompOperator(this.comparator); + final String sortOrder = getSortOrderForStartStatement(this.comparator); + + String query; + if (isPrimaryTable) { + query = + String.format( + "select key, value from %s where key %s ? order by key %s", + primaryTable, compOperator, sortOrder); + } else if (this.isDuplicate) { + query = + String.format( + "select %s.key, %s.value, %s.dupNo from " + + "%s join %s on %s.value = %s.key " + + "where %s.key %s ? " + + "order by %s.key %s, %s.dupNo %s", + subTable, + primaryTable, + subTable, + subTable, + primaryTable, + subTable, + primaryTable, + subTable, + compOperator, + subTable, + sortOrder, + subTable, + sortOrder); + } else { + query = + String.format( + "select %s.key, %s.value from " + + "%s join %s on %s.value = %s.key " + + "where %s.key %s ? " + + "order by %s.key %s", + subTable, + primaryTable, + subTable, + primaryTable, + subTable, + primaryTable, + subTable, + compOperator, + subTable, + sortOrder); + } + byte[] key; + if (this.previousFetchResult.isPresent()) { + key = this.previousFetchResult.get().key; + } else { + key = this.key; + } + + try (PreparedStatement stmt = this.conn.prepareStatement(query)) { + stmt.setBytes(1, key); + try (ResultSet rs = stmt.executeQuery()) { + if (rs.next()) { + byte[] fetchedKey = rs.getBytes("key"); + if (this.comparator == CobolIndexedFile.COB_EQ + && !matchKeyHead(this.key, fetchedKey)) { + return Optional.empty(); + } else if (this.comparator == CobolIndexedFile.COB_GT) { + // exclude records that partially match the key + while (matchKeyHead(this.key, fetchedKey)) { + if (!rs.next()) { + return Optional.empty(); + } + fetchedKey = rs.getBytes("key"); + } + } + byte[] value = rs.getBytes("value"); + if (isDuplicate) { + int dupNo = rs.getInt("dupNo"); + return Optional.of(new FetchResult(fetchedKey, value, dupNo)); + } else { + return Optional.of(new FetchResult(fetchedKey, value)); + } + } else { + this.position = CursorPosition.AFTER_LAST; + return Optional.empty(); + } + } + } catch (Exception e) { + return Optional.empty(); + } + } + + Optional next() { + if (this.position == CursorPosition.AFTER_LAST) { + return Optional.empty(); + } + + Optional result; + if (this.firstFetch) { + if (this.position == CursorPosition.BEFORE_FIRST) { + result = fetchFirstRecord(); + } else { + result = fetchRecord(); + } + } else { + result = forwardNextRecord(); + } + if (result.isPresent()) { + this.firstFetch = false; + this.position = CursorPosition.IN_TABLE; + } + this.previousFetchResult = result; + return result; + } + + Optional prev() { + if (this.position == CursorPosition.BEFORE_FIRST) { + return Optional.empty(); + } + + Optional result; + if (this.firstFetch) { + if (this.position == CursorPosition.AFTER_LAST) { + result = fetchLastRecord(); + } else { + result = fetchRecord(); + } + } else { + result = backwardPrevRecord(); + } + + if (result.isPresent()) { + this.firstFetch = false; + this.position = CursorPosition.IN_TABLE; + } + this.previousFetchResult = result; + return result; + } + + boolean moveToFirst() { + this.firstFetch = true; + this.position = CursorPosition.BEFORE_FIRST; + return true; + } + + boolean moveToLast() { + this.firstFetch = true; + this.position = CursorPosition.AFTER_LAST; + return true; + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/IndexedFile.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/IndexedFile.java index e9f27450..5e8c2ab9 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/IndexedFile.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/IndexedFile.java @@ -1,57 +1,70 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.file; - -import java.sql.Connection; -import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; - -/** TODO: 準備中 */ -class IndexedFile { - /** TODO: 準備中 */ - int key_index; - /** TODO: 準備中 */ - CobolDataStorage last_key; - /** TODO: 準備中 */ - CobolDataStorage temp_key; - /** TODO: 準備中 */ - Connection connection; - /** TODO: 準備中 */ - byte[] key; - /** TODO: 準備中 */ - byte[] data; - /** TODO: 準備中 */ - byte[][] last_readkey; - /** TODO: 準備中 */ - int[] last_dupno; - /** TODO: 準備中 */ - int[] rewrite_sec_key; - - /** TODO: 準備中 */ - String filename; - /** TODO: 準備中 */ - Object record_lock; - /** TODO: 準備中 */ - boolean write_cursor_open; - /** TODO: 準備中 */ - int lock_id; - /** TODO: 準備中 */ - boolean record_locked; - /** TODO: 準備中 */ - int filenamelen; -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.file; + +import java.sql.Connection; +import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; + +/** TODO: 準備中 */ +class IndexedFile { + /** TODO: 準備中 */ + int key_index; + + /** TODO: 準備中 */ + CobolDataStorage last_key; + + /** TODO: 準備中 */ + CobolDataStorage temp_key; + + /** TODO: 準備中 */ + Connection connection; + + /** TODO: 準備中 */ + byte[] key; + + /** TODO: 準備中 */ + byte[] data; + + /** TODO: 準備中 */ + byte[][] last_readkey; + + /** TODO: 準備中 */ + int[] last_dupno; + + /** TODO: 準備中 */ + int[] rewrite_sec_key; + + /** TODO: 準備中 */ + String filename; + + /** TODO: 準備中 */ + Object record_lock; + + /** TODO: 準備中 */ + boolean write_cursor_open; + + /** TODO: 準備中 */ + int lock_id; + + /** TODO: 準備中 */ + boolean record_locked; + + /** TODO: 準備中 */ + int filenamelen; +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/KeyComponent.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/KeyComponent.java index 3cdbf53c..fe0c566d 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/KeyComponent.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/KeyComponent.java @@ -1,29 +1,30 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.file; - -import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; - -/** TODO: 準備中 */ -public class KeyComponent { - /** TODO: 準備中 */ - public AbstractCobolField field; - /** TODO: 準備中 */ - public int rb; -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.file; + +import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; + +/** TODO: 準備中 */ +public class KeyComponent { + /** TODO: 準備中 */ + public AbstractCobolField field; + + /** TODO: 準備中 */ + public int rb; +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/Linage.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/Linage.java index bdea17c4..8d26279c 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/Linage.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/Linage.java @@ -1,196 +1,196 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.file; - -import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; - -/** TODO: 準備中 */ -public class Linage { - private AbstractCobolField linage; - private AbstractCobolField linageCtr; - private AbstractCobolField latfoot; - private AbstractCobolField lattop; - private AbstractCobolField latbot; - private int linLines; - private int linFoot; - private int linTop; - private int linBot; - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - AbstractCobolField getLinage() { - return linage; - } - - /** - * TODO: 準備中 - * - * @param linage TODO: 準備中 - */ - public void setLinage(AbstractCobolField linage) { - this.linage = linage; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - AbstractCobolField getLinageCtr() { - return linageCtr; - } - - /** - * TODO: 準備中 - * - * @param linageCtr TODO: 準備中 - */ - public void setLinageCtr(AbstractCobolField linageCtr) { - this.linageCtr = linageCtr; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - AbstractCobolField getLatfoot() { - return latfoot; - } - - /** - * TODO: 準備中 - * - * @param latfoot TODO: 準備中 - */ - public void setLatfoot(AbstractCobolField latfoot) { - this.latfoot = latfoot; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - AbstractCobolField getLattop() { - return lattop; - } - - /** - * TODO: 準備中 - * - * @param lattop TODO: 準備中 - */ - public void setLattop(AbstractCobolField lattop) { - this.lattop = lattop; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - AbstractCobolField getLatbot() { - return latbot; - } - - /** - * TODO: 準備中 - * - * @param latbot TODO: 準備中 - */ - public void setLatbot(AbstractCobolField latbot) { - this.latbot = latbot; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - int getLinLines() { - return linLines; - } - - /** - * TODO: 準備中 - * - * @param linLines TODO: 準備中 - */ - public void setLinLines(int linLines) { - this.linLines = linLines; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - int getLinFoot() { - return linFoot; - } - - /** - * TODO: 準備中 - * - * @param linFoot TODO: 準備中 - */ - public void setLinFoot(int linFoot) { - this.linFoot = linFoot; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - int getLinTop() { - return linTop; - } - - /** - * TODO: 準備中 - * - * @param linTop TODO: 準備中 - */ - public void setLinTop(int linTop) { - this.linTop = linTop; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - int getLinBot() { - return linBot; - } - - /** - * TODO: 準備中 - * - * @param linBot TODO: 準備中 - */ - public void setLinBot(int linBot) { - this.linBot = linBot; - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.file; + +import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; + +/** TODO: 準備中 */ +public class Linage { + private AbstractCobolField linage; + private AbstractCobolField linageCtr; + private AbstractCobolField latfoot; + private AbstractCobolField lattop; + private AbstractCobolField latbot; + private int linLines; + private int linFoot; + private int linTop; + private int linBot; + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + AbstractCobolField getLinage() { + return linage; + } + + /** + * TODO: 準備中 + * + * @param linage TODO: 準備中 + */ + public void setLinage(AbstractCobolField linage) { + this.linage = linage; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + AbstractCobolField getLinageCtr() { + return linageCtr; + } + + /** + * TODO: 準備中 + * + * @param linageCtr TODO: 準備中 + */ + public void setLinageCtr(AbstractCobolField linageCtr) { + this.linageCtr = linageCtr; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + AbstractCobolField getLatfoot() { + return latfoot; + } + + /** + * TODO: 準備中 + * + * @param latfoot TODO: 準備中 + */ + public void setLatfoot(AbstractCobolField latfoot) { + this.latfoot = latfoot; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + AbstractCobolField getLattop() { + return lattop; + } + + /** + * TODO: 準備中 + * + * @param lattop TODO: 準備中 + */ + public void setLattop(AbstractCobolField lattop) { + this.lattop = lattop; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + AbstractCobolField getLatbot() { + return latbot; + } + + /** + * TODO: 準備中 + * + * @param latbot TODO: 準備中 + */ + public void setLatbot(AbstractCobolField latbot) { + this.latbot = latbot; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + int getLinLines() { + return linLines; + } + + /** + * TODO: 準備中 + * + * @param linLines TODO: 準備中 + */ + public void setLinLines(int linLines) { + this.linLines = linLines; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + int getLinFoot() { + return linFoot; + } + + /** + * TODO: 準備中 + * + * @param linFoot TODO: 準備中 + */ + public void setLinFoot(int linFoot) { + this.linFoot = linFoot; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + int getLinTop() { + return linTop; + } + + /** + * TODO: 準備中 + * + * @param linTop TODO: 準備中 + */ + public void setLinTop(int linTop) { + this.linTop = linTop; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + int getLinBot() { + return linBot; + } + + /** + * TODO: 準備中 + * + * @param linBot TODO: 準備中 + */ + public void setLinBot(int linBot) { + this.linBot = linBot; + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/MemoryStruct.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/MemoryStruct.java index 4aea50e6..f754e425 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/MemoryStruct.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/MemoryStruct.java @@ -1,86 +1,86 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.file; - -/** TODO: 準備中 */ -class MemoryStruct { - private CobolItem first; - private CobolItem last; - private int count; - - /** TODO: 準備中 */ - MemoryStruct() { - this.first = null; - this.last = null; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - CobolItem getFirst() { - return first; - } - - /** - * TODO: 準備中 - * - * @param first TODO: 準備中 - */ - void setFirst(CobolItem first) { - this.first = first; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - CobolItem getLast() { - return last; - } - - /** - * TODO: 準備中 - * - * @param last TODO: 準備中 - */ - void setLast(CobolItem last) { - this.last = last; - } - - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - int getCount() { - return count; - } - - /** - * TODO: 準備中 - * - * @param count TODO: 準備中 - */ - void setCount(int count) { - this.count = count; - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.file; + +/** TODO: 準備中 */ +class MemoryStruct { + private CobolItem first; + private CobolItem last; + private int count; + + /** TODO: 準備中 */ + MemoryStruct() { + this.first = null; + this.last = null; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + CobolItem getFirst() { + return first; + } + + /** + * TODO: 準備中 + * + * @param first TODO: 準備中 + */ + void setFirst(CobolItem first) { + this.first = first; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + CobolItem getLast() { + return last; + } + + /** + * TODO: 準備中 + * + * @param last TODO: 準備中 + */ + void setLast(CobolItem last) { + this.last = last; + } + + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + int getCount() { + return count; + } + + /** + * TODO: 準備中 + * + * @param count TODO: 準備中 + */ + void setCount(int count) { + this.count = count; + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/termio/CobolTerminal.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/termio/CobolTerminal.java index 6aa377a2..558232ec 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/termio/CobolTerminal.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/termio/CobolTerminal.java @@ -1,327 +1,353 @@ -/* - * Copyright (C) 2021-2022 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 3.0, - * 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 - */ -package jp.osscons.opensourcecobol.libcobj.termio; - -import java.io.PrintStream; -import java.nio.ByteBuffer; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Scanner; -import jp.osscons.opensourcecobol.libcobj.common.CobolModule; -import jp.osscons.opensourcecobol.libcobj.common.CobolUtil; -import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; -import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; -import jp.osscons.opensourcecobol.libcobj.data.CobolFieldAttribute; -import jp.osscons.opensourcecobol.libcobj.data.CobolFieldFactory; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionId; -import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionInfo; - -/** DISPLAY文やACCEPT文に関するメソッドを実装するクラス */ -public class CobolTerminal { - - /** TDOD: 準備中 */ - private static int commlncnt = 0; - - /** TDOD: 準備中 */ - private static byte[] commlnptr = null; - - /** - * 標準出力または標準エラー出力にデータを出力する - * - * @param dispStdout trueなら標準出力に,それ以外は標準エラー出力に出力する - * @param newline trueなら出力後に改行しない,それ以外の場合は改行する - * @param fields 出力するCOBOL変数(可変長) - */ - public static void display(boolean dispStdout, boolean newline, AbstractCobolField... fields) { - PrintStream stream = dispStdout ? System.out : System.err; - for (AbstractCobolField field : fields) { - CobolFieldAttribute attr = field.getAttribute(); - if (attr.isTypeNumericBinary() && CobolModule.getCurrentModule().flag_pretty_display == 0) { - stream.print(field); - } else if (attr.isTypeNumeric()) { - stream.print(field); - } else { - displayAlnum(field, stream); - } - } - if (newline) { - stream.println(""); - } - } - - private static void displayAlnum(AbstractCobolField f, PrintStream stream) { - CobolDataStorage storage = f.getDataStorage(); - stream.write(storage.getRefOfData(), storage.getIndex(), f.getSize()); - } - - /** - * 標準出力または標準エラー出力にデータを出力する - * - * @param outorerr 0なら標準出力に,それ以外は標準エラー出力に出力する. - * @param newline 0なら出力後に改行しない,それ以外の場合は改行する - * @param varcnt 出力するCOBOL変数の数 - * @param fields 出力するCOBOL変数(可変長) - */ - public static void display(int outorerr, int newline, int varcnt, AbstractCobolField... fields) { - PrintStream stream = outorerr == 0 ? System.out : System.err; - for (AbstractCobolField field : fields) { - CobolFieldAttribute attr = field.getAttribute(); - if (attr.isTypeNumericBinary() && CobolModule.getCurrentModule().flag_pretty_display == 0) { - stream.print(field); - } else if (attr.isTypeNumeric()) { - stream.print(field); - } else { - displayAlnum(field, stream); - } - } - if (newline == 1) { - stream.println(""); - } - } - - private static Scanner scan = null; - - /** - * 標準入力からデータを受け取る - * - * @param f TODO: 準備中 - */ - public static void accept(AbstractCobolField f) { - try { - if (scan == null) { - scan = new Scanner(System.in); - } - - String input = scan.nextLine(); - - // PIC X(n)型のデータに変換 - AbstractCobolField field = CobolFieldFactory.makeCobolField(input); - - if (f.getAttribute().isTypeNumericDisplay() && field.getSize() > f.getSize()) { - field.setSize(f.getSize()); - } - - f.moveFrom(field); - } catch (Exception e) { - e.printStackTrace(); - } - } - - // Time - - /** - * libcob/common.c job_or_current_localtime - * - * @return TODO: 準備中 - */ - private static LocalDateTime jobOrCurrentLocalTime() { - if (CobolUtil.cobLocalTm != null) { - return CobolUtil.cobLocalTm; - } else { - return LocalDateTime.now(); - } - } - - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - */ - public static void acceptDate(AbstractCobolField f) { - LocalDateTime date = jobOrCurrentLocalTime(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyMMdd"); - f.memcpy(date.format(formatter)); - } - - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - */ - public static void acceptDate_yyyymmdd(AbstractCobolField f) { - LocalDateTime date = jobOrCurrentLocalTime(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); - f.memcpy(date.format(formatter)); - } - - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - */ - public static void acceptDay(AbstractCobolField f) { - LocalDateTime date = jobOrCurrentLocalTime(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyDDD"); - f.memcpy(date.format(formatter)); - } - - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - */ - public static void acceptDay_yyyyddd(AbstractCobolField f) { - LocalDateTime date = jobOrCurrentLocalTime(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyDDD"); - f.memcpy(date.format(formatter)); - } - - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - */ - public static void acceptDayOfWeek(AbstractCobolField f) { - LocalDateTime date = jobOrCurrentLocalTime(); - f.memcpy(String.format("%d", date.getDayOfWeek().getValue())); - } - - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - */ - public static void acceptTime(AbstractCobolField f) { - LocalDateTime date = LocalDateTime.now(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HHmmssSS"); - f.memcpy(date.format(formatter)); - } - - // Environment - - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - */ - public static void displayEnvironment(AbstractCobolField f) { - CobolUtil.cobLocalEnv = f.fieldToString(); - } - - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - */ - public static void displayEnvValue(AbstractCobolField f) { - if (CobolUtil.cobLocalEnv == null || CobolUtil.cobLocalEnv.equals("")) { - CobolExceptionInfo.setException(CobolExceptionId.COB_EC_IMP_DISPLAY); - return; - } - CobolUtil.setEnv(CobolUtil.cobLocalEnv, f.getString()); - } - - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - */ - public static void acceptEnvironment(AbstractCobolField f) { - String p = null; - if (CobolUtil.cobLocalEnv != null) { - p = CobolUtil.getEnv(CobolUtil.cobLocalEnv); - } - - if (p == null) { - // TODO setExceptionは暫定実装 - CobolExceptionInfo.setException(CobolExceptionId.COB_EC_IMP_ACCEPT); - p = " "; - } - - AbstractCobolField src = CobolFieldFactory.makeCobolField(p); - // TODO hankakuMoveFromは暫定実装 - f.hankakuMoveFrom(src); - } - - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - */ - public static void displayCommandLine(AbstractCobolField f) { - CobolTerminal.commlnptr = new byte[f.getSize()]; - CobolTerminal.commlncnt = f.getSize(); - for (int i = 0; i < CobolTerminal.commlncnt; ++i) { - CobolTerminal.commlnptr[i] = f.getDataStorage().getByte(i); - } - } - - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - */ - public static void acceptCommandLine(AbstractCobolField f) { - if (CobolTerminal.commlncnt != 0) { - f.memcpy(CobolTerminal.commlnptr, CobolTerminal.commlncnt); - return; - } - - f.memcpy(String.join(" ", CobolUtil.commandLineArgs)); - } - - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - */ - public static void displayArgNumber(AbstractCobolField f) { - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 9, 0, 0, null); - byte[] data = new byte[4]; - AbstractCobolField temp = - CobolFieldFactory.makeCobolField(data.length, new CobolDataStorage(data), attr); - temp.moveFrom(f); - int n = ByteBuffer.wrap(data).getInt(); - if (n < 0 || n > CobolUtil.commandLineArgs.length) { - CobolExceptionInfo.setException(CobolExceptionId.COB_EC_IMP_DISPLAY); - return; - } - CobolUtil.currentArgIndex = n; - } - - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - */ - public static void acceptArgNumber(AbstractCobolField f) { - CobolFieldAttribute attr = - new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 9, 0, 0, null); - byte[] data = new byte[4]; - ByteBuffer.wrap(data).putInt(CobolUtil.commandLineArgs.length); - AbstractCobolField temp = - CobolFieldFactory.makeCobolField(data.length, new CobolDataStorage(data), attr); - f.moveFrom(temp); - } - - /** - * TODO: 準備中 - * - * @param f TODO: 準備中 - */ - public static void acceptArgValue(AbstractCobolField f) { - if (CobolUtil.currentArgIndex > CobolUtil.commandLineArgs.length) { - CobolExceptionInfo.setException(CobolExceptionId.COB_EC_IMP_ACCEPT); - return; - } - f.memcpy(CobolUtil.commandLineArgs[CobolUtil.currentArgIndex - 1]); - CobolUtil.currentArgIndex++; - } -} +/* + * Copyright (C) 2021-2022 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 3.0, + * 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 + */ +package jp.osscons.opensourcecobol.libcobj.termio; + +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.charset.UnsupportedCharsetException; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Scanner; +import jp.osscons.opensourcecobol.libcobj.common.CobolEncoding; +import jp.osscons.opensourcecobol.libcobj.common.CobolModule; +import jp.osscons.opensourcecobol.libcobj.common.CobolUtil; +import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; +import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; +import jp.osscons.opensourcecobol.libcobj.data.CobolFieldAttribute; +import jp.osscons.opensourcecobol.libcobj.data.CobolFieldFactory; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionId; +import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionInfo; + +/** DISPLAY文やACCEPT文に関するメソッドを実装するクラス */ +public class CobolTerminal { + + /** TDOD: 準備中 */ + private static int commlncnt = 0; + + /** TDOD: 準備中 */ + private static byte[] commlnptr = null; + + /** + * 標準出力または標準エラー出力にデータを出力する + * + * @param dispStdout trueなら標準出力に,それ以外は標準エラー出力に出力する + * @param newline trueなら出力後に改行しない,それ以外の場合は改行する + * @param fields 出力するCOBOL変数(可変長) + */ + public static void display(boolean dispStdout, boolean newline, AbstractCobolField... fields) { + PrintStream stream = dispStdout ? System.out : System.err; + for (AbstractCobolField field : fields) { + CobolFieldAttribute attr = field.getAttribute(); + if (attr.isTypeNumericBinary() + && CobolModule.getCurrentModule().flag_pretty_display == 0) { + stream.print(field); + } else if (attr.isTypeNumeric()) { + stream.print(field); + } else { + displayAlnum(field, stream); + } + } + if (newline) { + stream.println(""); + } + } + + private static void displayAlnum(AbstractCobolField f, PrintStream stream) { + CobolDataStorage storage = f.getDataStorage(); + if (CobolUtil.terminalEncoding == CobolEncoding.UTF8) { + byte[] utf8Bytes = + new String(storage.getByteArray(0, f.getSize()), AbstractCobolField.charSetSJIS) + .getBytes(StandardCharsets.UTF_8); + stream.write(utf8Bytes, 0, utf8Bytes.length); + } else { + stream.write(storage.getRefOfData(), storage.getIndex(), f.getSize()); + } + } + + /** + * 標準出力または標準エラー出力にデータを出力する + * + * @param outorerr 0なら標準出力に,それ以外は標準エラー出力に出力する. + * @param newline 0なら出力後に改行しない,それ以外の場合は改行する + * @param varcnt 出力するCOBOL変数の数 + * @param fields 出力するCOBOL変数(可変長) + */ + public static void display( + int outorerr, int newline, int varcnt, AbstractCobolField... fields) { + PrintStream stream = outorerr == 0 ? System.out : System.err; + for (AbstractCobolField field : fields) { + CobolFieldAttribute attr = field.getAttribute(); + if (attr.isTypeNumericBinary() + && CobolModule.getCurrentModule().flag_pretty_display == 0) { + stream.print(field); + } else if (attr.isTypeNumeric()) { + stream.print(field); + } else { + displayAlnum(field, stream); + } + } + if (newline == 1) { + stream.println(""); + } + } + + private static Scanner scan = null; + + /** + * 標準入力からデータを受け取る + * + * @param f TODO: 準備中 + */ + public static void accept(AbstractCobolField f) { + try { + if (scan == null) { + if (CobolUtil.terminalEncoding == CobolEncoding.UTF8) { + scan = new Scanner(new InputStreamReader(System.in, StandardCharsets.UTF_8)); + } else { + try { + scan = + new Scanner( + new InputStreamReader( + System.in, Charset.forName("Shift_JIS"))); + } catch (UnsupportedCharsetException e) { + scan = new Scanner(System.in); + } + } + } + + String input = scan.nextLine(); + + // PIC X(n)型のデータに変換 + AbstractCobolField field = CobolFieldFactory.makeCobolField(input); + + if (f.getAttribute().isTypeNumericDisplay() && field.getSize() > f.getSize()) { + field.setSize(f.getSize()); + } + + f.moveFrom(field); + } catch (Exception e) { + e.printStackTrace(); + } + } + + // Time + + /** + * libcob/common.c job_or_current_localtime + * + * @return TODO: 準備中 + */ + private static LocalDateTime jobOrCurrentLocalTime() { + if (CobolUtil.cobLocalTm != null) { + return CobolUtil.cobLocalTm; + } else { + return LocalDateTime.now(); + } + } + + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + */ + public static void acceptDate(AbstractCobolField f) { + LocalDateTime date = jobOrCurrentLocalTime(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyMMdd"); + f.memcpy(date.format(formatter)); + } + + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + */ + public static void acceptDate_yyyymmdd(AbstractCobolField f) { + LocalDateTime date = jobOrCurrentLocalTime(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); + f.memcpy(date.format(formatter)); + } + + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + */ + public static void acceptDay(AbstractCobolField f) { + LocalDateTime date = jobOrCurrentLocalTime(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyDDD"); + f.memcpy(date.format(formatter)); + } + + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + */ + public static void acceptDay_yyyyddd(AbstractCobolField f) { + LocalDateTime date = jobOrCurrentLocalTime(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyDDD"); + f.memcpy(date.format(formatter)); + } + + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + */ + public static void acceptDayOfWeek(AbstractCobolField f) { + LocalDateTime date = jobOrCurrentLocalTime(); + f.memcpy(String.format("%d", date.getDayOfWeek().getValue())); + } + + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + */ + public static void acceptTime(AbstractCobolField f) { + LocalDateTime date = LocalDateTime.now(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HHmmssSS"); + f.memcpy(date.format(formatter)); + } + + // Environment + + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + */ + public static void displayEnvironment(AbstractCobolField f) { + CobolUtil.cobLocalEnv = f.fieldToString(); + } + + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + */ + public static void displayEnvValue(AbstractCobolField f) { + if (CobolUtil.cobLocalEnv == null || CobolUtil.cobLocalEnv.equals("")) { + CobolExceptionInfo.setException(CobolExceptionId.COB_EC_IMP_DISPLAY); + return; + } + CobolUtil.setEnv(CobolUtil.cobLocalEnv, f.getString()); + } + + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + */ + public static void acceptEnvironment(AbstractCobolField f) { + String p = null; + if (CobolUtil.cobLocalEnv != null) { + p = CobolUtil.getEnv(CobolUtil.cobLocalEnv); + } + + if (p == null) { + // TODO setExceptionは暫定実装 + CobolExceptionInfo.setException(CobolExceptionId.COB_EC_IMP_ACCEPT); + p = " "; + } + + AbstractCobolField src = CobolFieldFactory.makeCobolField(p); + // TODO hankakuMoveFromは暫定実装 + f.hankakuMoveFrom(src); + } + + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + */ + public static void displayCommandLine(AbstractCobolField f) { + CobolTerminal.commlnptr = new byte[f.getSize()]; + CobolTerminal.commlncnt = f.getSize(); + for (int i = 0; i < CobolTerminal.commlncnt; ++i) { + CobolTerminal.commlnptr[i] = f.getDataStorage().getByte(i); + } + } + + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + */ + public static void acceptCommandLine(AbstractCobolField f) { + if (CobolTerminal.commlncnt != 0) { + f.memcpy(CobolTerminal.commlnptr, CobolTerminal.commlncnt); + return; + } + + f.memcpy(String.join(" ", CobolUtil.commandLineArgs)); + } + + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + */ + public static void displayArgNumber(AbstractCobolField f) { + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 9, 0, 0, null); + byte[] data = new byte[4]; + AbstractCobolField temp = + CobolFieldFactory.makeCobolField(data.length, new CobolDataStorage(data), attr); + temp.moveFrom(f); + int n = ByteBuffer.wrap(data).getInt(); + if (n < 0 || n > CobolUtil.commandLineArgs.length) { + CobolExceptionInfo.setException(CobolExceptionId.COB_EC_IMP_DISPLAY); + return; + } + CobolUtil.currentArgIndex = n; + } + + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + */ + public static void acceptArgNumber(AbstractCobolField f) { + CobolFieldAttribute attr = + new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY, 9, 0, 0, null); + byte[] data = new byte[4]; + ByteBuffer.wrap(data).putInt(CobolUtil.commandLineArgs.length); + AbstractCobolField temp = + CobolFieldFactory.makeCobolField(data.length, new CobolDataStorage(data), attr); + f.moveFrom(temp); + } + + /** + * TODO: 準備中 + * + * @param f TODO: 準備中 + */ + public static void acceptArgValue(AbstractCobolField f) { + if (CobolUtil.currentArgIndex > CobolUtil.commandLineArgs.length) { + CobolExceptionInfo.setException(CobolExceptionId.COB_EC_IMP_ACCEPT); + return; + } + f.memcpy(CobolUtil.commandLineArgs[CobolUtil.currentArgIndex - 1]); + CobolUtil.currentArgIndex++; + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolCallResult.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolCallResult.java index 70173c44..292cbf1e 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolCallResult.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolCallResult.java @@ -2,33 +2,33 @@ /** TODO: 準備中 */ public class CobolCallResult { - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - * @throws CobolResultSetException TODO: 準備中 - */ - public int getInt() throws CobolResultSetException { - throw new CobolResultSetException("The result type is not 'int'"); - } + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + * @throws CobolResultSetException TODO: 準備中 + */ + public int getInt() throws CobolResultSetException { + throw new CobolResultSetException("The result type is not 'int'"); + } - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - * @throws CobolResultSetException TODO: 準備中 - */ - public double getDouble() throws CobolResultSetException { - throw new CobolResultSetException("The result type is not 'double'"); - } + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + * @throws CobolResultSetException TODO: 準備中 + */ + public double getDouble() throws CobolResultSetException { + throw new CobolResultSetException("The result type is not 'double'"); + } - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - * @throws CobolResultSetException TODO: 準備中 - */ - public String getString() throws CobolResultSetException { - throw new CobolResultSetException("The result type is not 'String'"); - } + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + * @throws CobolResultSetException TODO: 準備中 + */ + public String getString() throws CobolResultSetException { + throw new CobolResultSetException("The result type is not 'String'"); + } } diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolResultDouble.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolResultDouble.java index 94e7d58a..cb1883fa 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolResultDouble.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolResultDouble.java @@ -2,20 +2,20 @@ /** TODO: 準備中 */ public class CobolResultDouble extends CobolCallResult { - private double value; + private double value; - /** - * TODO: 準備中 - * - * @param d TODO: 準備中 - */ - public CobolResultDouble(double d) { - this.value = d; - } + /** + * TODO: 準備中 + * + * @param d TODO: 準備中 + */ + public CobolResultDouble(double d) { + this.value = d; + } - /** TODO: 準備中 */ - @Override - public double getDouble() throws CobolResultSetException { - return this.value; - } + /** TODO: 準備中 */ + @Override + public double getDouble() throws CobolResultSetException { + return this.value; + } } diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolResultInt.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolResultInt.java index 522aed58..9c543521 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolResultInt.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolResultInt.java @@ -2,20 +2,20 @@ /** TODO: 準備中 */ public class CobolResultInt extends CobolCallResult { - private int value; + private int value; - /** - * TODO: 準備中 - * - * @param i TODO: 準備中 - */ - public CobolResultInt(int i) { - this.value = i; - } + /** + * TODO: 準備中 + * + * @param i TODO: 準備中 + */ + public CobolResultInt(int i) { + this.value = i; + } - /** TODO: 準備中 */ - @Override - public int getInt() throws CobolResultSetException { - return this.value; - } + /** TODO: 準備中 */ + @Override + public int getInt() throws CobolResultSetException { + return this.value; + } } diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolResultSet.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolResultSet.java index 54d08ae4..050e426c 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolResultSet.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolResultSet.java @@ -2,68 +2,68 @@ /** TODO: 準備中 */ public class CobolResultSet { - private CobolCallResult results[]; - private int returnCode; + private CobolCallResult results[]; + private int returnCode; - /** - * TODO: 準備中 - * - * @param returnCode TODO: 準備中 - * @param results TODO: 準備中 - */ - public CobolResultSet(int returnCode, CobolCallResult... results) { - this.returnCode = returnCode; - this.results = results; - } + /** + * TODO: 準備中 + * + * @param returnCode TODO: 準備中 + * @param results TODO: 準備中 + */ + public CobolResultSet(int returnCode, CobolCallResult... results) { + this.returnCode = returnCode; + this.results = results; + } - private void checkIndexInValidRange(int index) throws CobolResultSetException { - if (results.length == 0 || index < 1 || this.results.length < index) { - throw new CobolResultSetException("The index is out of range."); + private void checkIndexInValidRange(int index) throws CobolResultSetException { + if (results.length == 0 || index < 1 || this.results.length < index) { + throw new CobolResultSetException("The index is out of range."); + } } - } - /** - * TODO: 準備中 - * - * @return TODO: 準備中 - */ - public int getReturnCode() { - return this.returnCode; - } + /** + * TODO: 準備中 + * + * @return TODO: 準備中 + */ + public int getReturnCode() { + return this.returnCode; + } - /** - * TODO: 準備中 - * - * @param index TODO: 準備中 - * @return TODO: 準備中 - * @throws CobolResultSetException TODO: 準備中 - */ - public String getString(int index) throws CobolResultSetException { - this.checkIndexInValidRange(index); - return this.results[index - 1].getString(); - } + /** + * TODO: 準備中 + * + * @param index TODO: 準備中 + * @return TODO: 準備中 + * @throws CobolResultSetException TODO: 準備中 + */ + public String getString(int index) throws CobolResultSetException { + this.checkIndexInValidRange(index); + return this.results[index - 1].getString(); + } - /** - * TODO: 準備中 - * - * @param index TODO: 準備中 - * @return TODO: 準備中 - * @throws CobolResultSetException TODO: 準備中 - */ - public int getInt(int index) throws CobolResultSetException { - this.checkIndexInValidRange(index); - return this.results[index - 1].getInt(); - } + /** + * TODO: 準備中 + * + * @param index TODO: 準備中 + * @return TODO: 準備中 + * @throws CobolResultSetException TODO: 準備中 + */ + public int getInt(int index) throws CobolResultSetException { + this.checkIndexInValidRange(index); + return this.results[index - 1].getInt(); + } - /** - * TODO: 準備中 - * - * @param index TODO: 準備中 - * @return TODO: 準備中 - * @throws CobolResultSetException TODO: 準備中 - */ - public double getDouble(int index) throws CobolResultSetException { - this.checkIndexInValidRange(index); - return this.results[index - 1].getDouble(); - } + /** + * TODO: 準備中 + * + * @param index TODO: 準備中 + * @return TODO: 準備中 + * @throws CobolResultSetException TODO: 準備中 + */ + public double getDouble(int index) throws CobolResultSetException { + this.checkIndexInValidRange(index); + return this.results[index - 1].getDouble(); + } } diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolResultSetException.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolResultSetException.java index 8abd52cf..576ca372 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolResultSetException.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolResultSetException.java @@ -2,12 +2,12 @@ /** TODO: 準備中 */ public class CobolResultSetException extends Exception { - /** - * TODO: 準備中 - * - * @param message TODO: 準備中 - */ - public CobolResultSetException(String message) { - super(message); - } + /** + * TODO: 準備中 + * + * @param message TODO: 準備中 + */ + public CobolResultSetException(String message) { + super(message); + } } diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolResultString.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolResultString.java index 2294d3ca..0ef92347 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolResultString.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/ui/CobolResultString.java @@ -2,20 +2,20 @@ /** TODO: 準備中 */ public class CobolResultString extends CobolCallResult { - private String value; + private String value; - /** - * TODO: 準備中 - * - * @param s TODO: 準備中 - */ - public CobolResultString(String s) { - this.value = s; - } + /** + * TODO: 準備中 + * + * @param s TODO: 準備中 + */ + public CobolResultString(String s) { + this.value = s; + } - /** TODO: 準備中 */ - @Override - public String getString() throws CobolResultSetException { - return this.value; - } + /** TODO: 準備中 */ + @Override + public String getString() throws CobolResultSetException { + return this.value; + } } diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/cobj_api/ApiFiles.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/cobj_api/ApiFiles.java index fa252331..b427ba8a 100755 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/cobj_api/ApiFiles.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/cobj_api/ApiFiles.java @@ -13,263 +13,278 @@ /** API連携用のJavaファイルを出力するクラス */ class ApiFiles { - private static JSONObject param; - private static String name; - private static String type; - private static String programId; - - /** - * 入力された値を受け取り、javaCreateメソッドを呼び出す - * - * @param args コマンドラインから入力された文字列 - */ - public static void main(String[] args) { - ApiFilesOptions.getOptions(args); - - if (args.length == 0) { - System.out.println("No json file is specified."); - System.exit(1); + private static String programId; + + /** + * 入力された値を受け取り、javaCreateメソッドを呼び出す + * + * @param args コマンドラインから入力された文字列 + */ + public static void main(String[] args) { + + if (args.length == 0) { + System.err.println("cobj-api: no input files"); + System.exit(1); + } + ApiFilesOptions.getOptions(args); + + String filePath = ApiFilesOptions.filePath; + javaCreate(filePath); } - String filePath; - try { - filePath = args[1]; - } catch (ArrayIndexOutOfBoundsException e) { - filePath = args[0]; + /** API連携用のJavaファイルを生成する */ + static void javaCreate(String filePath) { + try { + String json = new String(Files.readAllBytes(Paths.get(filePath))); + JSONObject obj = new JSONObject(json); + JSONArray params = obj.getJSONArray("procedure_division_using_parameters"); + String outputDir; + FileWriter ctlFile; + FileWriter rcdFile; + programId = obj.getString("program_id"); + + if (ApiFilesOptions.outputDir != null) { + outputDir = ApiFilesOptions.outputDir + "/"; + ctlFile = new FileWriter(outputDir + programId + "Controller.java"); + rcdFile = new FileWriter(outputDir + programId + "Record.java"); + } else { + ctlFile = new FileWriter(programId + "Controller.java"); + rcdFile = new FileWriter(programId + "Record.java"); + } + + writeController(ctlFile, params); + writeRecord(rcdFile, params); + + } catch (IOException e) { + e.printStackTrace(); + System.err.println("Error reading file: " + e.getMessage()); + System.exit(1); + } } - javaCreate(filePath); - } - - /** - * API連携用のJavaファイルを生成する - * - * @param filePath 生成されたJavaファイルを配置するディレクトリのパス - */ - static void javaCreate(String filePath) { - try { - String json = new String(Files.readAllBytes(Paths.get(filePath))); - JSONObject obj = new JSONObject(json); - JSONArray params = obj.getJSONArray("procedure_division_using_parameters"); - String outputDir; - FileWriter ctlFile; - FileWriter rcdFile; - - programId = obj.getString("program_id"); - - if (ApiFilesOptions.outputDir != null) { - outputDir = ApiFilesOptions.outputDir + "/"; - ctlFile = new FileWriter(outputDir + programId + "Controller.java"); - rcdFile = new FileWriter(outputDir + programId + "Record.java"); - } else { - ctlFile = new FileWriter(programId + "Controller.java"); - rcdFile = new FileWriter(programId + "Record.java"); - } - - writeController(ctlFile, params); - writeRecord(rcdFile, params); - - } catch (IOException e) { - e.printStackTrace(); - System.err.println("Error reading file: " + e.getMessage()); - System.exit(1); - } - } - - /** - * Controller.javaのコードを記述する - * - * @param ctlFile Controller.javaのファイルの情報を保持する - * @param programId PROGRAM-IDに記述されているプログラム名 - * @param params PROCEDURE DIVISION USING句に記述されている引数の配列 - */ - private static void writeController(FileWriter ctlFile, JSONArray params) { - PrintWriter ctlWriter = new PrintWriter(ctlFile); - String defaultValue; - String methodName; - String nameController = programId + "Controller"; - String nameRecord = programId + "Record"; - int i; - - if (ApiFilesOptions.packageName != null) { - ctlWriter.println("package " + ApiFilesOptions.packageName + ";"); - } else { - ctlWriter.println("package com.example.restservice;"); - } - - ctlWriter.println( - "import java.util.concurrent.atomic.AtomicLong;\n" - + "import org.springframework.web.bind.annotation.RequestMapping;\n" - + "import org.springframework.web.bind.annotation.GetMapping;\n" - + "import org.springframework.web.bind.annotation.PostMapping;\n" - + "import org.springframework.web.bind.annotation.RequestParam;\n" - + "import org.springframework.web.bind.annotation.RequestBody;\n" - + "import org.springframework.web.bind.annotation.RestController;\n" - + "import jp.osscons.opensourcecobol.libcobj.ui.*;\n"); - - ctlWriter.println( - "@RestController\n" - + "@RequestMapping(\"/" - + programId - + "\")\n" - + "public class " - + nameController - + " {\n\n" - + " @GetMapping\n" - + " public " - + nameRecord - + " " - + nameController - + "("); - - for (i = 0; i < params.length(); ++i) { - param = params.getJSONObject(i); - name = param.getString("variable_name").replace('-', '_'); - type = param.getString("java_type"); - if ("String".equals(type)) { - defaultValue = "\"\""; - } else { - defaultValue = "\"0\""; - } - - ctlWriter.print( - " @RequestParam(value = " - + "\"" - + name - + "\", defaultValue = " - + defaultValue - + ") " - + type - + " " - + name); - - if (i < params.length() - 1) { - ctlWriter.println(","); - } else { - ctlWriter.println(); - } + /** + * Controller.javaのコードを記述する + * + * @param ctlFile Controller.javaのファイルの情報を保持する + * @param programId PROGRAM-IDに記述されているプログラム名 + * @param params PROCEDURE DIVISION USING句に記述されている引数の配列 + */ + private static void writeController(FileWriter ctlFile, JSONArray params) { + JSONObject param; + PrintWriter ctlWriter = new PrintWriter(ctlFile); + String defaultValue; + String methodName; + String nameController = programId + "Controller"; + String nameRecord = programId + "Record"; + String name; + String type; + int i; + + if (ApiFilesOptions.packageName != null) { + ctlWriter.println("package " + ApiFilesOptions.packageName + ";"); + } else { + ctlWriter.println("package com.example.restservice;"); + } + + ctlWriter.println( + "import java.util.concurrent.atomic.AtomicLong;\n" + + "import org.springframework.web.bind.annotation.RequestMapping;\n" + + "import org.springframework.web.bind.annotation.GetMapping;\n" + + "import org.springframework.web.bind.annotation.PostMapping;\n" + + "import org.springframework.web.bind.annotation.RequestParam;\n" + + "import org.springframework.web.bind.annotation.RequestBody;\n" + + "import org.springframework.web.bind.annotation.RestController;\n" + + "import jp.osscons.opensourcecobol.libcobj.ui.*;\n"); + + ctlWriter.println( + "@RestController\n" + + "@RequestMapping(\"/" + + programId + + "\")\n" + + "public class " + + nameController + + " {\n\n" + + " @GetMapping\n" + + " public " + + nameRecord + + " " + + nameController + + "("); + + for (i = 0; i < params.length(); ++i) { + param = params.getJSONObject(i); + name = param.getString("variable_name").replace('-', '_'); + type = param.getString("java_type"); + if ("String".equals(type)) { + defaultValue = "\"\""; + } else { + defaultValue = "\"0\""; + } + + ctlWriter.print( + " @RequestParam(value = " + + "\"" + + name + + "\", defaultValue = " + + defaultValue + + ") " + + type + + " " + + name); + + if (i < params.length() - 1) { + ctlWriter.println(","); + } else { + ctlWriter.println(); + } + } + + ctlWriter.print(" ) {\n" + " return " + programId + "Execute("); + + argPrint(ctlWriter, params, false, false); + + ctlWriter.println(");\n" + " }\n"); + + ctlWriter.print( + " @PostMapping\n" + + " public " + + nameRecord + + " " + + nameController + + "Execute(@RequestBody " + + nameRecord + + " " + + programId + + "Record) {\n" + + " return " + + programId + + "Execute("); + + argPrint(ctlWriter, params, false, true); + + ctlWriter.println(");\n" + " }\n"); + ctlWriter.print(" private " + nameRecord + " " + programId + "Execute("); + + argPrint(ctlWriter, params, true, false); + + ctlWriter.print( + ") {\n" + + " int statuscode = 200;\n" + + " " + + programId + + " " + + programId + + "Cobol = new " + + programId + + "();\n" + + " CobolResultSet result = " + + programId + + "Cobol.execute("); + + argPrint(ctlWriter, params, false, false); + ctlWriter.println(");\n" + " try {"); + + for (i = 0; i < params.length(); ++i) { + param = params.getJSONObject(i); + name = param.getString("variable_name").replace('-', '_'); + type = param.getString("java_type"); + if ("String".equals(type)) { + methodName = "getString"; + } else if ("int".equals(type)) { + methodName = "getInt"; + } else { + methodName = "getDouble"; + } + ctlWriter.println( + " " + name + " = result." + methodName + "(" + (i + 1) + ");"); + } + + ctlWriter.print( + " } catch (Exception e) {\n" + + " statuscode = 500;\n" + + " }\n" + + " return new " + + programId + + "Record(statuscode, "); + + argPrint(ctlWriter, params, false, false); + + ctlWriter.println(");\n" + " }\n" + "}"); + ctlWriter.close(); } - ctlWriter.print(" ) {\n" + " return " + programId + "Execute("); - - argPrint(ctlWriter, params, false, false); - - ctlWriter.println(");\n" + " }\n"); - - ctlWriter.print( - " @PostMapping\n" - + " public " - + nameRecord - + " " - + nameController - + "Execute(@RequestBody " - + nameRecord - + " " - + programId - + "Record) {\n" - + " return " - + programId - + "Execute("); - - argPrint(ctlWriter, params, false, true); - - ctlWriter.println(");\n" + " }\n"); - ctlWriter.print(" private " + nameRecord + " " + programId + "Execute("); - - argPrint(ctlWriter, params, true, false); - - ctlWriter.print( - ") {\n" - + " int statuscode = 200;\n" - + " " - + programId - + " " - + programId - + "Cobol = new " - + programId - + "();\n" - + " CobolResultSet result = " - + programId - + "Cobol.execute("); - - argPrint(ctlWriter, params, false, false); - ctlWriter.println(");\n" + " try {"); - - for (i = 0; i < params.length(); ++i) { - param = params.getJSONObject(i); - name = param.getString("variable_name").replace('-', '_'); - type = param.getString("java_type"); - if ("String".equals(type)) { - methodName = "getString"; - } else if ("int".equals(type)) { - methodName = "getInt"; - } else { - methodName = "getDouble"; - } - ctlWriter.println(" " + name + " = result." + methodName + "(" + (i + 1) + ");"); + /** + * Record.javaのコードを記述する + * + * @param rcdFile Record.javaのファイル情報を保持する + * @param params PROCEDURE DIVISION USING句に記述されている引数の配列 + */ + private static void writeRecord(FileWriter rcdFile, JSONArray params) { + JSONObject param; + PrintWriter rcdWriter = new PrintWriter(rcdFile); + String defaultValue; + String type; + int i; + + if (ApiFilesOptions.packageName != null) { + rcdWriter.println("package " + ApiFilesOptions.packageName + ";"); + } else { + rcdWriter.println("package com.example.restservice;"); + } + + rcdWriter.print("public record " + programId + "Record(int statuscode, "); + + argPrint(rcdWriter, params, true, false); + + rcdWriter.print(") {\n" + " public " + programId + "Record(){\n" + " this(200, "); + for (i = 0; i < params.length(); ++i) { + param = params.getJSONObject(i); + type = param.getString("java_type"); + + if ("String".equals(type)) { + defaultValue = "\"\""; + } else { + defaultValue = "0"; + } + + rcdWriter.print(defaultValue); + if (i < params.length() - 1) { + rcdWriter.print(", "); + } + } + + rcdWriter.println(");\n" + " }\n" + "}"); + rcdWriter.close(); } - ctlWriter.print( - " } catch (Exception e) {\n" - + " statuscode = 500;\n" - + " }\n" - + " return new " - + programId - + "Record(statuscode, "); - - argPrint(ctlWriter, params, false, false); - - ctlWriter.println(");\n" + " }\n" + "}"); - ctlWriter.close(); - } - - /** - * Record.javaのコードを記述する - * - * @param rcdFile Record.javaのファイル情報を保持する - * @param programId PROGRAM-IDに記述されているプログラム名 - * @param params PROCEDURE DIVISION USING句に記述されている引数の配列 - */ - private static void writeRecord(FileWriter rcdFile, JSONArray params) { - PrintWriter rcdWriter = new PrintWriter(rcdFile); - - rcdWriter.print( - "package com.example.restservice;\n" - + "public record " - + programId - + "Record(int statuscode, "); - - argPrint(rcdWriter, params, true, false); - - rcdWriter.println(") {}"); - rcdWriter.close(); - } - - /** - * 生成されるJavaファイルに記述されるメソッドの引数などを記述する - * - * @param writer 生成されるJavaファイルの情報を保持する - * @param params PROCEDURE DIVISION USING句に記述されている引数の配列 - * @param isType 引数の型を記述するかどうか - * @param isRecord 引数がレコード型かどうか - */ - private static void argPrint( - PrintWriter writer, JSONArray params, boolean isType, boolean isRecord) { - int i; - - for (i = 0; i < params.length(); ++i) { - param = params.getJSONObject(i); - name = param.getString("variable_name").replace('-', '_'); - if (isType) { - type = param.getString("java_type"); - name = type + " " + name; - } else if (isRecord) { - name = programId + "Record." + name + "()"; - } - writer.print(name); - if (i < params.length() - 1) { - writer.print(", "); - } + /** + * 生成されるJavaファイルに記述されるメソッドの引数などを記述する + * + * @param writer 生成されるJavaファイルの情報を保持する + * @param params PROCEDURE DIVISION USING句に記述されている引数の配列 + * @param isType 引数の型を記述するかどうか + * @param isRecord 引数がレコード型かどうか + */ + private static void argPrint( + PrintWriter writer, JSONArray params, boolean isType, boolean isRecord) { + JSONObject param; + String name; + String type; + int i; + + for (i = 0; i < params.length(); ++i) { + param = params.getJSONObject(i); + name = param.getString("variable_name").replace('-', '_'); + if (isType) { + type = param.getString("java_type"); + name = type + " " + name; + } else if (isRecord) { + name = programId + "Record." + name + "()"; + } + writer.print(name); + if (i < params.length() - 1) { + writer.print(", "); + } + } } - } } diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/cobj_api/ApiFilesOptions.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/cobj_api/ApiFilesOptions.java old mode 100644 new mode 100755 index fedff8f8..5e352e56 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/cobj_api/ApiFilesOptions.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/cobj_api/ApiFilesOptions.java @@ -3,93 +3,129 @@ import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; /** cobj-apiコマンドのオプションを定義するクラス */ class ApiFilesOptions { - /** cobj-apiコマンドによって生成されるJavaファイルに記述されるパッケージ名 */ - static String packageName; - /** cobj-apiコマンドによって生成されるJavaファイルが配置されるディレクトリ名 */ - static String outputDir; + /** cobj-apiコマンドによって生成されるJavaファイルに記述されるパッケージ名 */ + static String packageName; - /** - * 入力されたオプションを取得する - * - * @param args コマンドラインから入力された文字列 - */ - static void getOptions(String[] args) { - Options options = new Options(); - options.addOption("h", "help", false, "Prints the help message"); - options.addOption( - "jp", "java-package", true, "Specify the package name of the generated source code"); - options.addOption( - "o", - "output-dir", - true, - "Set the output destination of the java file to an arbitrary destination"); - options.addOption("v", "version", false, "Prints the version of the cobj-api"); - CommandLineParser parser = new DefaultParser(); - CommandLine cmd; + /** cobj-apiコマンドによって生成されるJavaファイルが配置されるディレクトリ名 */ + static String outputDir; - try { - cmd = parser.parse(options, args); - } catch (ParseException e) { - printHelpMessage(); - System.exit(1); - return; - } + static String filePath; + + /** + * 入力されたオプションを取得する + * + * @param args コマンドラインから入力された文字列 + */ + static void getOptions(String[] args) { + Options options = new Options(); + + options.addOption(Option.builder("h").longOpt("help").build()); + options.addOption(Option.builder("java-package").longOpt("java-package").hasArgs().build()); + options.addOption(Option.builder("o").hasArgs().build()); + options.addOption(Option.builder("output-dir").longOpt("output-dir").hasArgs().build()); + options.addOption(Option.builder("v").longOpt("version").build()); + + CommandLineParser parser = new DefaultParser(); - if (cmd.hasOption("h")) { - printHelpMessage(); - System.exit(0); - return; - } else if (cmd.hasOption("v")) { - System.out.println("1.1.2"); - System.exit(0); - return; - } else if (cmd.getOptionValue("java-package") != null) { - String packageName = cmd.getOptionValue("java-package"); - setJavaPackage(packageName); - return; - } else if (cmd.getOptionValue("output-dir") != null) { - String outputDir = cmd.getOptionValue("output-dir"); - setOutputDir(outputDir); - return; + try { + CommandLine cmd = parser.parse(options, args); + int optionCount = 0; + String outputDir; + + if (cmd.getOptions().length != 0) { + for (Option option : cmd.getOptions()) { + switch (option.getOpt()) { + case "h": + printHelpMessage(); + System.exit(0); + break; + case "v": + System.out.println("1.1.14"); + System.exit(0); + break; + case "java-package": + if (!args[optionCount].contains("=")) { + System.err.println("error: Please check the usage of options.\n"); + printHelpMessage(); + System.exit(1); + } + String packageName = option.getValue(); + setJavaPackage(packageName); + break; + case "output-dir": + if (!args[optionCount].contains("=")) { + System.err.println("error: Please check the usage of options.\n"); + printHelpMessage(); + System.exit(1); + } + outputDir = option.getValue(); + setOutputDir(outputDir); + break; + case "o": + outputDir = option.getValue(); + setOutputDir(outputDir); + optionCount++; + break; + default: + break; + } + optionCount++; + } + filePath = args[optionCount]; + } else { + filePath = args[0]; + } + } catch (ParseException e) { + System.err.println("error: " + e.getMessage() + "\n"); + printHelpMessage(); + System.exit(1); + } catch (ArrayIndexOutOfBoundsException e) { + System.err.println("error: Please check the usage of options.\n"); + printHelpMessage(); + System.exit(1); + } } - } - /** cobj-apiコマンドのヘルプメッセージを出力する */ - private static void printHelpMessage() { - System.out.println("Usage: cobj-api [options] "); - System.out.println(); - System.out.println("Arguments:"); - System.out.println(" : a json file generated by cobj with `-info-json-dir` option"); - System.out.println(); - System.out.println("Options:"); - System.out.println(" -h, --help\t\t\t\tDisplay this message"); - System.out.println( - " -java-package=\t\tSpecify the package name of the generated source code"); - System.out.println( - " -o=, --output-dir=\t\tSet the output destination of the java file to an arbitrary destination"); - System.out.println(" -v, --version\t\t\t\tPrints the version of the cobj-api"); - } + /** cobj-apiコマンドのヘルプメッセージを出力する */ + private static void printHelpMessage() { + System.out.println("Usage: cobj-api [options] "); + System.out.println(); + System.out.println("Arguments:"); + System.out.println( + " : a json file generated by cobj with `-info-json-dir` option"); + System.out.println(); + System.out.println("Options:"); + System.out.println(" -h, --help\t\t\t\tDisplay this message"); + System.out.println( + " -java-package=\t\tSpecify the package name of the generated source" + + " code"); + System.out.println( + " -o , --output-dir=\t\tSet the output destination of the java file to" + + " an arbitrary destination"); + System.out.println(" -v, --version\t\t\t\tPrints the version of the cobj-api"); + } - /** - * 生成されるJavaファイルに記述されるパッケージ名を設定する - * - * @param packageName 生成されるJavaファイルに記述されるパッケージ名 - */ - static void setJavaPackage(String packageName) { - ApiFilesOptions.packageName = packageName; - } + /** + * 生成されるJavaファイルに記述されるパッケージ名を設定する + * + * @param packageName 生成されるJavaファイルに記述されるパッケージ名 + */ + static void setJavaPackage(String packageName) { + ApiFilesOptions.packageName = packageName; + } - /** - * 生成されるJavaファイルが配置されるディレクトリ名を設定する - * - * @param outputDir 生成されるJavaファイルが配置されるディレクトリ名 - */ - static void setOutputDir(String outputDir) { - ApiFilesOptions.outputDir = outputDir; - } + /** + * 生成されるJavaファイルが配置されるディレクトリ名を設定する + * + * @param outputDir 生成されるJavaファイルが配置されるディレクトリ名 + */ + static void setOutputDir(String outputDir) { + ApiFilesOptions.outputDir = outputDir; + } } diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/CobolFileKeyInfo.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/CobolFileKeyInfo.java new file mode 100644 index 00000000..a015d2bd --- /dev/null +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/CobolFileKeyInfo.java @@ -0,0 +1,13 @@ +package jp.osscons.opensourcecobol.libcobj.user_util.indexed_file; + +class CobolFileKeyInfo { + public int offset; + public int size; + public boolean duplicate; + + public CobolFileKeyInfo(int offset, int size, boolean duplicate) { + this.offset = offset; + this.size = size; + this.duplicate = duplicate; + } +} diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/ErrorLib.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/ErrorLib.java index de59d84b..6d9f9480 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/ErrorLib.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/ErrorLib.java @@ -2,55 +2,56 @@ /** Manage error info */ class ErrorLib { - /** - * Error when indexed file does not exist - * - * @param indexedFilePath TODO: 準備中 - * @return 1 - */ - static int errorFileDoesNotExist(String indexedFilePath) { - System.err.println("error: '" + indexedFilePath + "' does not exist."); - return 1; - } - /** - * Error when indexed file is not a valid indexed file - * - * @param indexedFilePath TODO: 準備中 - * @return 1 - */ - static int errorInvalidIndexedFile(String indexedFilePath) { - System.err.println("error: '" + indexedFilePath + "' is not a valid indexed file."); - return 1; - } + /** + * Error when indexed file does not exist + * + * @param indexedFilePath TODO: 準備中 + * @return 1 + */ + static int errorFileDoesNotExist(String indexedFilePath) { + System.err.println("error: '" + indexedFilePath + "' does not exist."); + return 1; + } - /** - * Error when IO operations of indexed files - * - * @return 1 - */ - static int errorIO() { - System.err.println("error: IO error."); - return 1; - } + /** + * Error when indexed file is not a valid indexed file + * + * @param indexedFilePath TODO: 準備中 + * @return 1 + */ + static int errorInvalidIndexedFile(String indexedFilePath) { + System.err.println("error: '" + indexedFilePath + "' is not a valid indexed file."); + return 1; + } - /** - * Error when some keys in input data have conflicts - * - * @return 1 - */ - static int errorDuplicateKeys() { - System.err.println("error: loading fails because of duplicate keys."); - return 1; - } + /** + * Error when IO operations of indexed files + * + * @return 1 + */ + static int errorIO() { + System.err.println("error: IO error."); + return 1; + } - /** - * Error when some records in input data have invalid size - * - * @param correctSize TODO: 準備中 - * @return TODO: 準備中 - */ - static int errorDataSizeMismatch(int correctSize) { - System.err.println("error: all record must have the length of " + correctSize + " bytes."); - return 1; - } + /** + * Error when some keys in input data have conflicts + * + * @return 1 + */ + static int errorDuplicateKeys() { + System.err.println("error: loading fails because of duplicate keys."); + return 1; + } + + /** + * Error when some records in input data have invalid size + * + * @param correctSize TODO: 準備中 + * @return TODO: 準備中 + */ + static int errorDataSizeMismatch(int correctSize) { + System.err.println("error: all record must have the length of " + correctSize + " bytes."); + return 1; + } } diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/FileLineSeqRecordReader.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/FileLineSeqRecordReader.java index 0a21c945..149e8fa7 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/FileLineSeqRecordReader.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/FileLineSeqRecordReader.java @@ -7,60 +7,61 @@ /** TODO: 準備中 */ class FileLineSeqRecordReader implements RecordReader { - /** TODO: 準備中 */ - int recordSize; - /** TODO: 準備中 */ - BufferedReader reader; + /** TODO: 準備中 */ + int recordSize; - private String filePath; + /** TODO: 準備中 */ + BufferedReader reader; - /** - * TODO: 準備中 - * - * @param recordSize TODO: 準備中 - * @param filePath TODO: 準備中 - */ - FileLineSeqRecordReader(int recordSize, String filePath) { - this.recordSize = recordSize; - this.filePath = filePath; - } + private String filePath; - @Override - public void open() { - try { - this.reader = new BufferedReader(new FileReader(this.filePath)); - } catch (IOException e) { - this.reader = null; + /** + * TODO: 準備中 + * + * @param recordSize TODO: 準備中 + * @param filePath TODO: 準備中 + */ + FileLineSeqRecordReader(int recordSize, String filePath) { + this.recordSize = recordSize; + this.filePath = filePath; } - } - @Override - public LoadResult read(CobolDataStorage record) { - if (this.reader == null) { - return LoadResult.LoadResultOther; + @Override + public void open() { + try { + this.reader = new BufferedReader(new FileReader(this.filePath)); + } catch (IOException e) { + this.reader = null; + } } - try { - String line = this.reader.readLine(); - if (line == null) { - return LoadResult.AtEnd; - } - byte[] readData = line.getBytes(); - if (readData.length != this.recordSize) { - return LoadResult.LoadResultDataSizeMismatch; - } - record.memcpy(readData, this.recordSize); - return LoadResult.LoadResultSuccess; - } catch (IOException e) { - return LoadResult.LoadResultOther; + + @Override + public LoadResult read(CobolDataStorage record) { + if (this.reader == null) { + return LoadResult.LoadResultOther; + } + try { + String line = this.reader.readLine(); + if (line == null) { + return LoadResult.AtEnd; + } + byte[] readData = line.getBytes(); + if (readData.length != this.recordSize) { + return LoadResult.LoadResultDataSizeMismatch; + } + record.memcpy(readData, this.recordSize); + return LoadResult.LoadResultSuccess; + } catch (IOException e) { + return LoadResult.LoadResultOther; + } } - } - @Override - public void close() { - try { - this.reader.close(); - } catch (IOException e) { - return; + @Override + public void close() { + try { + this.reader.close(); + } catch (IOException e) { + return; + } } - } } diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/FileSeqRecordReader.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/FileSeqRecordReader.java index 14000394..2f94103f 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/FileSeqRecordReader.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/FileSeqRecordReader.java @@ -6,62 +6,62 @@ /** TODO: 準備中 */ public class FileSeqRecordReader implements RecordReader { - private FileInputStream reader; - private String filePath; - private byte[] readData; + private FileInputStream reader; + private String filePath; + private byte[] readData; - /** - * TODO: 準備中 - * - * @param recordSize TODO: 準備中 - * @param filePath TODO: 準備中 - */ - FileSeqRecordReader(int recordSize, String filePath) { - this.filePath = filePath; - this.readData = new byte[recordSize]; - } - - @Override - public void open() { - try { - this.reader = new FileInputStream(this.filePath); - } catch (IOException e) { - this.reader = null; + /** + * TODO: 準備中 + * + * @param recordSize TODO: 準備中 + * @param filePath TODO: 準備中 + */ + FileSeqRecordReader(int recordSize, String filePath) { + this.filePath = filePath; + this.readData = new byte[recordSize]; } - } - @Override - public LoadResult read(CobolDataStorage record) { - if (this.reader == null) { - return LoadResult.LoadResultOther; + @Override + public void open() { + try { + this.reader = new FileInputStream(this.filePath); + } catch (IOException e) { + this.reader = null; + } } - try { - int readSize = this.reader.read(this.readData); - if (readSize == -1) { - return LoadResult.AtEnd; - } - if (readSize != this.readData.length) { - if (readSize == 1 && this.readData[0] == '\n') { - return LoadResult.AtEnd; - } else if (readSize == 2 && this.readData[0] == '\r' && this.readData[1] == '\n') { - return LoadResult.AtEnd; - } else { - return LoadResult.LoadResultDataSizeMismatch; + + @Override + public LoadResult read(CobolDataStorage record) { + if (this.reader == null) { + return LoadResult.LoadResultOther; + } + try { + int readSize = this.reader.read(this.readData); + if (readSize == -1) { + return LoadResult.AtEnd; + } + if (readSize != this.readData.length) { + if (readSize == 1 && this.readData[0] == '\n') { + return LoadResult.AtEnd; + } else if (readSize == 2 && this.readData[0] == '\r' && this.readData[1] == '\n') { + return LoadResult.AtEnd; + } else { + return LoadResult.LoadResultDataSizeMismatch; + } + } + record.memcpy(this.readData, this.readData.length); + return LoadResult.LoadResultSuccess; + } catch (IOException e) { + return LoadResult.LoadResultOther; } - } - record.memcpy(this.readData, this.readData.length); - return LoadResult.LoadResultSuccess; - } catch (IOException e) { - return LoadResult.LoadResultOther; } - } - @Override - public void close() { - try { - this.reader.close(); - } catch (IOException e) { - return; + @Override + public void close() { + try { + this.reader.close(); + } catch (IOException e) { + return; + } } - } } diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/IndexedFileUtilMain.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/IndexedFileUtilMain.java index 59370914..0b9f7ad0 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/IndexedFileUtilMain.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/IndexedFileUtilMain.java @@ -13,6 +13,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import jp.osscons.opensourcecobol.libcobj.common.CobolModule; import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; import jp.osscons.opensourcecobol.libcobj.data.CobolDataStorage; @@ -37,497 +39,864 @@ * data from the indexed file. */ class IndexedFileUtilMain { - private static final String version = jp.osscons.opensourcecobol.libcobj.Const.version; - - /** - * Main method - * - * @param args TODO: 準備中 - */ - public static void main(String[] args) { - - // Build a command line parser - Options options = new Options(); - options.addOption("h", "help", false, "Print this message."); - options.addOption("v", "version", false, "Print the version"); - options.addOption("n", "new", false, "Delete all data before loading"); - options.addOption("f", "format", true, "Specify the format of the input and output data"); - CommandLineParser parser = new DefaultParser(); - CommandLine cmd; - - // Parse command line arguments - try { - cmd = parser.parse(options, args); - } catch (ParseException e) { - printHelpMessage(); - System.exit(1); - return; - } - - // Process -h, --help option - if (cmd.hasOption("h")) { - printHelpMessage(); - System.exit(0); - return; - } + private static final String version = jp.osscons.opensourcecobol.libcobj.Const.version; + + /** + * Main method + * + * @param args TODO: 準備中 + */ + public static void main(String[] args) { + + // Build a command line parser + Options options = new Options(); + options.addOption("h", "help", false, "Print this message."); + options.addOption("v", "version", false, "Print the version"); + options.addOption("n", "new", false, "Delete all data before loading"); + options.addOption("f", "format", true, "Specify the format of the input and output data"); + options.addOption("s", "size", true, "Specify the record size of the indexed file."); + options.addOption("k", "key", true, "Specify the key information of the indexed file."); + CommandLineParser parser = new DefaultParser(); + CommandLine cmd; + + // Parse command line arguments + try { + cmd = parser.parse(options, args); + } catch (ParseException e) { + printHelpMessage(); + System.exit(1); + return; + } - // Process -v, --version option - if (cmd.hasOption("v")) { - System.out.println(version); - System.exit(0); - return; - } + // Process -h, --help option + if (cmd.hasOption("h")) { + printHelpMessage(); + System.exit(0); + return; + } - // Process -f, --format option - UserDataFormat userDataFormat = UserDataFormat.SEQUENTIAL; - String userDataFormatString = cmd.getOptionValue("f"); - if (userDataFormatString != null) { - userDataFormatString = userDataFormatString.toLowerCase(); - if ("txt".equals(userDataFormatString)) { - userDataFormat = UserDataFormat.LINE_SEQUENTIAL; - } else if ("bin".equals(userDataFormatString)) { - userDataFormat = UserDataFormat.SEQUENTIAL; - } else { - System.err.println( - String.format( - "error: '%s' is invalid value of -f and --format option.", userDataFormatString)); - System.err.println(" possible values of -f and --format option is 'txt' and 'bin'."); - System.exit(1); - } - } + // Process -v, --version option + if (cmd.hasOption("v")) { + System.out.println(version); + System.exit(0); + return; + } - // If no sub command is specified, print help message and exit. - String[] unrecognizedArgs = cmd.getArgs(); - if (unrecognizedArgs.length == 0) { - printHelpMessage(); - System.exit(0); - return; - } + // Process -f, --format option + UserDataFormat userDataFormat = UserDataFormat.SEQUENTIAL; + String userDataFormatString = cmd.getOptionValue("f"); + if (userDataFormatString != null) { + userDataFormatString = userDataFormatString.toLowerCase(); + if ("txt".equals(userDataFormatString)) { + userDataFormat = UserDataFormat.LINE_SEQUENTIAL; + } else if ("bin".equals(userDataFormatString)) { + userDataFormat = UserDataFormat.SEQUENTIAL; + } else { + System.err.println( + String.format( + "error: '%s' is invalid value of -f and --format option.", + userDataFormatString)); + System.err.println( + " possible values of -f and --format option is 'txt' and 'bin'."); + System.exit(1); + } + } - // Dispatch sub commands - String subCommand = unrecognizedArgs[0]; - if ("info".equals(subCommand)) { - if (unrecognizedArgs.length != 2) { - if (unrecognizedArgs.length < 2) { - System.err.println("error: no indexed file is specified."); - } else { - System.err.println("error: too many indexed files are specified."); + // If no sub command is specified, print help message and exit. + String[] unrecognizedArgs = cmd.getArgs(); + if (unrecognizedArgs.length == 0) { + printHelpMessage(); + System.exit(0); + return; } - System.exit(1); - } - String indexedFilePath = args[1]; - int exitCode = processInfoCommand(indexedFilePath); - System.exit(exitCode); - } else if ("load".equals(subCommand)) { - if (unrecognizedArgs.length < 2 || unrecognizedArgs.length > 3) { - if (unrecognizedArgs.length < 2) { - System.err.println("error: no indexed file is specified."); - } else { - System.err.println("error: too many indexed files are specified."); - } - System.exit(1); - } - String indexedFilePath = unrecognizedArgs[1]; - Optional filePath; - if (unrecognizedArgs.length == 3) { - filePath = Optional.of(unrecognizedArgs[2]); - } else { - filePath = Optional.empty(); - } - boolean deleteBeforeLoading = cmd.hasOption("n"); - int exitCode = - processLoadCommand(indexedFilePath, deleteBeforeLoading, userDataFormat, filePath); - System.exit(exitCode); - - } else if ("unload".equals(subCommand)) { - if (unrecognizedArgs.length < 2 || unrecognizedArgs.length > 3) { - if (unrecognizedArgs.length < 2) { - System.err.println("error: no indexed file is specified."); + // Dispatch sub commands + String subCommand = unrecognizedArgs[0]; + if ("info".equals(subCommand)) { + if (unrecognizedArgs.length != 2) { + if (unrecognizedArgs.length < 2) { + System.err.println("error: no indexed file is specified."); + } else { + System.err.println("error: too many indexed files are specified."); + } + System.exit(1); + } + String indexedFilePath = args[1]; + int exitCode = processInfoCommand(indexedFilePath); + System.exit(exitCode); + } else if ("create".equals(subCommand)) { + try { + validateCreateCommandArgs(unrecognizedArgs, cmd); + String indexedFilePath = unrecognizedArgs[1]; + int recordSize = parseRecordSize(cmd); + List keyInfoList = parseKeyOptions(cmd); + validateKeyInfoList(keyInfoList, recordSize); + processCreateIndexedFile(indexedFilePath, recordSize, keyInfoList, cmd); + System.exit(0); + } catch (Exception e) { + System.err.println("error: " + e.getMessage()); + System.exit(1); + } + } else if ("migrate".equals(subCommand)) { + if (unrecognizedArgs.length < 2) { + System.err.println("error: no indexed file is specified."); + System.exit(1); + } + boolean hasError = false; + for (int i = 1; i < unrecognizedArgs.length; i++) { + String indexedFilePath = unrecognizedArgs[i]; + try { + migrateIndexedFile(indexedFilePath); + } catch (Exception e) { + System.err.println("error: " + e.getMessage()); + hasError = true; + } + } + System.exit(hasError ? 1 : 0); + } else if ("unlock".equals(subCommand)) { + if (unrecognizedArgs.length < 2) { + System.err.println("error: no indexed file is specified."); + System.exit(1); + } + boolean hasError = false; + for (int i = 1; i < unrecognizedArgs.length; i++) { + String indexedFilePath = unrecognizedArgs[i]; + try { + unlockIndexedFile(indexedFilePath); + } catch (Exception e) { + System.err.println("error: " + e.getMessage()); + hasError = true; + } + } + System.exit(hasError ? 1 : 0); + } else if ("load".equals(subCommand)) { + if (unrecognizedArgs.length < 2 || unrecognizedArgs.length > 3) { + if (unrecognizedArgs.length < 2) { + System.err.println("error: no indexed file is specified."); + } else { + System.err.println("error: too many indexed files are specified."); + } + System.exit(1); + } + String indexedFilePath = unrecognizedArgs[1]; + Optional filePath; + if (unrecognizedArgs.length == 3) { + filePath = Optional.of(unrecognizedArgs[2]); + } else { + filePath = Optional.empty(); + } + boolean deleteBeforeLoading = cmd.hasOption("n"); + int exitCode = + processLoadCommand( + indexedFilePath, deleteBeforeLoading, userDataFormat, filePath); + System.exit(exitCode); + + } else if ("unload".equals(subCommand)) { + if (unrecognizedArgs.length < 2 || unrecognizedArgs.length > 3) { + if (unrecognizedArgs.length < 2) { + System.err.println("error: no indexed file is specified."); + } else { + System.err.println("error: too many indexed files are specified."); + } + System.exit(1); + } + String indexedFilePath = unrecognizedArgs[1]; + Optional filePath; + if (unrecognizedArgs.length == 3) { + filePath = Optional.of(unrecognizedArgs[2]); + } else { + filePath = Optional.empty(); + } + int exitCode = processUnloadCommand(indexedFilePath, userDataFormat, filePath); + System.exit(exitCode); } else { - System.err.println("error: too many indexed files are specified."); - } - System.exit(1); - } - String indexedFilePath = unrecognizedArgs[1]; - Optional filePath; - if (unrecognizedArgs.length == 3) { - filePath = Optional.of(unrecognizedArgs[2]); - } else { - filePath = Optional.empty(); - } - int exitCode = processUnloadCommand(indexedFilePath, userDataFormat, filePath); - System.exit(exitCode); - } else { - printHelpMessage(); - System.exit(1); - } - } - - /** Print help message. */ - private static void printHelpMessage() { - System.out.println( - "cobj-idx - A utility tool to handle an indexed file of opensource COBOL 4J"); - System.out.println(); - System.out.println("Usage:"); - System.out.println("cobj-idx [options] "); - System.out.println(); - System.err.println("Sub commands:"); - System.out.println(); - System.out.println("cobj-idx info "); - System.out.println(" Show information of the indexed file."); - System.out.println(); - System.out.println("cobj-idx load "); - System.out.println(" Load the data from stdin into the indexed file."); - System.out.println(" The default format of the input data is SQUENTIAL of COBOL."); - System.out.println(); - System.out.println("cobj-idx load "); - System.out.println(" Load data from the input fiile into the indexed file."); - System.out.println(" The default format of the input data is SQUENTIAL of COBOL."); - System.out.println(); - System.out.println("cobj-idx unload "); - System.out.println(" Write the records stored in the indexed file into stdout."); - System.out.println(" The default format of the output data is SEQUENTIAL of COBOL."); - System.out.println(); - System.out.println("cobj-idx unload "); - System.out.println(" Write the records stored in the indexed file into the output file."); - System.out.println(" The default format of the output data is SEQUENTIAL of COBOL."); - System.out.println(); - System.out.println("Options:"); - System.out.println(); - System.out.println("-f , --format="); - System.out.println(" Specify the format of the input and output data."); - System.out.println(" Possible values are 'txt' and the default value 'bin'"); - System.out.println(" 'bin' and 'txt' means SEQUENTIAL and LINE SEQUENTIAL respectively."); - System.out.println( - " When doing a `load`, this option specifies the format of input data which will be inserted to an indexed file."); - System.out.println( - " When doing an `unload`, this option specifies the format of output data which will be read from an indexed file."); - System.out.println(); - System.out.println("-h --help"); - System.out.println(" Print this message."); - System.out.println(); - System.out.println("-n, --new"); - System.out.println( - " Delete all data before inserting new data. This option is only valid when the sub command is 'load'."); - System.out.println(); - System.out.println("-v, --version"); - System.out.println(" Print the version of cobj-idx."); - } - - /** - * Process info sub command, which shows information of the indexed file. - * - * @param indexedFilePath TODO: 準備中 - * @return 0 if success, otherwise non-zero. The return value is error code. - */ - private static int processInfoCommand(String indexedFilePath) { - File indexedFile = new File(indexedFilePath); - if (!indexedFile.exists()) { - return ErrorLib.errorFileDoesNotExist(indexedFilePath); + printHelpMessage(); + System.exit(1); + } } - if (!indexedFile.isFile()) { - return ErrorLib.errorInvalidIndexedFile(indexedFilePath); + + /** Print help message. */ + private static void printHelpMessage() { + System.out.println( + "cobj-idx - A utility tool to handle an indexed file of opensource COBOL 4J"); + System.out.println(); + System.out.println("Usage:"); + System.out.println("cobj-idx [options] "); + System.out.println(); + System.err.println("Sub commands:"); + System.out.println(); + System.out.println("cobj-idx info "); + System.out.println(" Show information of the indexed file."); + System.out.println(); + System.out.println( + "cobj-idx create --size= --key="); + System.out.println(" Create a new indexed file."); + System.out.println(" The record size and key information are specified by the options."); + System.out.println(" By default, this command does not overwrite the indexed file."); + System.out.println(" To overwrite the indexed file, use the --new option."); + System.out.println(" Example) cobj-idx create test.idx --size=100 --key=2,2:5,4:d15,5"); + System.out.println(" File name: test.idx"); + System.out.println(" Record size: 100"); + System.out.println(" Primary key: 2-3"); + System.out.println(" Alternate key (No Duplicates):5-8"); + System.out.println(" Alternate key (Duplicates): 15-19"); + System.out.println(); + System.out.println("cobj-idx load "); + System.out.println(" Load the data from stdin into the indexed file."); + System.out.println(" The default format of the input data is SEQUENTIAL of COBOL."); + System.out.println(); + System.out.println("cobj-idx load "); + System.out.println(" Load data from the input file into the indexed file."); + System.out.println(" The default format of the input data is SEQUENTIAL of COBOL."); + System.out.println(); + System.out.println("cobj-idx unload "); + System.out.println(" Write the records stored in the indexed file into stdout."); + System.out.println(" The default format of the output data is SEQUENTIAL of COBOL."); + System.out.println(); + System.out.println("cobj-idx unload "); + System.out.println( + " Write the records stored in the indexed file into the output file."); + System.out.println(" The default format of the output data is SEQUENTIAL of COBOL."); + System.out.println(); + System.out.println("cobj-idx migrate [...]"); + System.out.println( + " Migrate the indexed file whose version is older than 1.1.12 to the latest" + + " version."); + System.out.println(); + System.out.println("cobj-idx unlock [...]"); + System.out.println(" Unlock all locks of the indexed file."); + System.out.println(); + System.out.println("Options:"); + System.out.println(); + System.out.println("-f , --format="); + System.out.println(" Specify the format of the input and output data."); + System.out.println(" Possible values are 'txt' and the default value 'bin'"); + System.out.println( + " 'bin' and 'txt' means SEQUENTIAL and LINE SEQUENTIAL respectively."); + System.out.println( + " When doing a `load`, this option specifies the format of input data which will" + + " be inserted to an indexed file."); + System.out.println( + " When doing an `unload`, this option specifies the format of output data which" + + " will be read from an indexed file."); + System.out.println(); + System.out.println("-h --help"); + System.out.println(" Print this message."); + System.out.println(); + System.out.println("-n, --new"); + System.out.println( + " Delete all data before inserting new data. This option is only valid when the" + + " sub command is 'load'."); + System.out.println(); + System.out.println("-v, --version"); + System.out.println(" Print the version of cobj-idx."); } - SQLiteConfig config = new SQLiteConfig(); - config.setReadOnly(true); - StringBuilder sb = new StringBuilder(); - - try (Connection conn = - DriverManager.getConnection("jdbc:sqlite:" + indexedFilePath, config.toProperties()); - Statement stmt = conn.createStatement(); ) { - // Retrieve the record size - ResultSet rs = - stmt.executeQuery("select value from metadata_string_int where key = 'record_size'"); - if (!rs.next()) { - return ErrorLib.errorInvalidIndexedFile(indexedFilePath); - } - int recordSize = rs.getInt("value"); - sb.append("Size of a record: " + recordSize + "\n"); - - // Retrieve the number of records - rs = stmt.executeQuery("select count(*) from table0"); - if (!rs.next()) { - return ErrorLib.errorInvalidIndexedFile(indexedFilePath); - } - sb.append("Number of records: " + rs.getInt(1) + "\n"); - - // Retrieve the number of keys - rs = stmt.executeQuery("select idx, offset, size, duplicate from metadata_key order by idx"); - while (rs.next()) { - int idx = rs.getInt("idx"); - int offset = rs.getInt("offset") + 1; - int size = rs.getInt("size"); - boolean duplicate = rs.getBoolean("duplicate"); - if (idx == 0) { - sb.append("Primary key position: "); + /** + * Parse the key options and return a list of CobolFileKeyInfo. + * + * @param cmd the CommandLine object containing the parsed command line arguments + * @return a list of CobolFileKeyInfo objects parsed from the key options in the provided CommandLine argument + */ + private static List parseKeyOptions(CommandLine cmd) throws Exception { + if (cmd.hasOption("k")) { + ArrayList keyInfoList = new ArrayList<>(); + + String keyOption = cmd.getOptionValue("k"); + Pattern pattern = + Pattern.compile("[1-9][0-9]*,[1-9][0-9]*(:d?[1-9][0-9]*,[1-9][0-9]*)*"); + Matcher matcher = pattern.matcher(keyOption); + + if (!matcher.matches()) { + Pattern patternPrimaryKeyDup = + Pattern.compile("d[1-9][0-9]*,[1-9][0-9]*(:d?[1-9][0-9]*,[1-9][0-9]*)*"); + Matcher matcherPrimaryKeyDup = patternPrimaryKeyDup.matcher(keyOption); + if (matcherPrimaryKeyDup.matches()) { + throw new IllegalArgumentException( + "the first key (primary key) must not be a duplicate key."); + } + + Pattern patternContains0 = Pattern.compile("[0-9]+,[0-9]+(:d?[0-9]+,[0-9]+)*"); + matcher = patternContains0.matcher(keyOption); + if (matcher.matches()) { + String[] keys = keyOption.split(":"); + for (String key : keys) { + String[] keyInfo = key.split(","); + String offsetString = keyInfo[0]; + if (offsetString.startsWith("d")) { + offsetString = offsetString.substring(1); + } + + if ("0".equals(offsetString)) { + throw new IllegalArgumentException( + String.format( + "key offsets must be greater than 0: %s", keyOption)); + } else if (offsetString.startsWith("0")) { + throw new IllegalArgumentException( + String.format( + "key offsets must not start with 0: %s", keyOption)); + } + String sizeString = keyInfo[1]; + if ("0".equals(sizeString)) { + throw new IllegalArgumentException( + String.format( + "key sizes must be greater than 0: %s", keyOption)); + } else if (sizeString.startsWith("0")) { + throw new IllegalArgumentException( + String.format( + "key sizes must not start with 0: %s", keyOption)); + } + } + } + throw new IllegalArgumentException( + String.format("invalid key information: %s", keyOption)); + } + String[] keys = keyOption.split(":"); + for (int i = 0; i < keys.length; i++) { + String key = keys[i]; + boolean isFirstKey = (i == 0); + String[] keyInfo = key.split(","); + if (keyInfo.length != 2) { + throw new IllegalArgumentException( + String.format("invalid key information: %s", keyOption)); + } + String offsetString = keyInfo[0]; + boolean duplicate = false; + if (keyInfo[0].startsWith("d")) { + if (isFirstKey) { + throw new IllegalArgumentException( + String.format( + "the first key (primary key) must not be a duplicate" + + " key.")); + } + offsetString = keyInfo[0].substring(1); + duplicate = true; + } + int offset = Integer.parseInt(offsetString); + int size = Integer.parseInt(keyInfo[1]); + + CobolFileKeyInfo keyInfoObj = new CobolFileKeyInfo(offset, size, duplicate); + keyInfoList.add(keyInfoObj); + } + return keyInfoList; } else { - sb.append("Alternate key position "); - if (duplicate) { - sb.append("(Duplicates): "); - } else { - sb.append("(No duplicate): "); - } - } - sb.append(offset + "-" + (offset + size - 1) + "\n"); - } - - System.out.print(sb.toString()); - return 0; - } catch (SQLException e) { - return ErrorLib.errorInvalidIndexedFile(indexedFilePath); - } - } - - /** - * Process load sub command, which loads data inputted from stdin to the indexed file. - * - * @param indexedFilePath TODO: 準備中 - * @return TODO: 準備中 - */ - private static int processLoadCommand( - String indexedFilePath, - boolean deleteBeforeLoading, - UserDataFormat userDataFormat, - Optional filePath) { - File indexedFile = new File(indexedFilePath); - if (!indexedFile.exists()) { - return ErrorLib.errorFileDoesNotExist(indexedFilePath); - } - if (!indexedFile.isFile()) { - return ErrorLib.errorInvalidIndexedFile(indexedFilePath); - } - Optional cobolFileRet = createCobolFileFromIndexedFilePath(indexedFilePath); - if (!cobolFileRet.isPresent()) { - return ErrorLib.errorInvalidIndexedFile(indexedFilePath); + throw new IllegalArgumentException("no key information is specified."); + } } - CobolIndexedFile cobolIndexedFile = (CobolIndexedFile) cobolFileRet.get(); - - // Set the module - CobolModule module = - new CobolModule(null, null, null, null, 0, '.', '$', ',', 1, 1, 1, 0, null); - CobolModule.push(module); - - // Open the indexed file - CobolRuntimeException.code = 0; - cobolIndexedFile.setCommitOnModification(false); - cobolIndexedFile.open(CobolFile.COB_OPEN_EXTEND, 0, null); - if (CobolRuntimeException.code != 0) { - return ErrorLib.errorIO(); + + /** + * Process info sub command, which shows information of the indexed file. + * + * @param indexedFilePath TODO: 準備中 + * @return 0 if success, otherwise non-zero. The return value is error code. + */ + private static int processInfoCommand(String indexedFilePath) { + File indexedFile = new File(indexedFilePath); + if (!indexedFile.exists()) { + return ErrorLib.errorFileDoesNotExist(indexedFilePath); + } + if (!indexedFile.isFile()) { + return ErrorLib.errorInvalidIndexedFile(indexedFilePath); + } + + SQLiteConfig config = new SQLiteConfig(); + config.setReadOnly(true); + StringBuilder sb = new StringBuilder(); + + try (Connection conn = + DriverManager.getConnection( + "jdbc:sqlite:" + indexedFilePath, config.toProperties()); + Statement stmt = conn.createStatement(); ) { + // Retrieve the record size + ResultSet rs = + stmt.executeQuery( + "select value from metadata_string_int where key = 'record_size'"); + if (!rs.next()) { + return ErrorLib.errorInvalidIndexedFile(indexedFilePath); + } + int recordSize = rs.getInt("value"); + sb.append("Size of a record: " + recordSize + "\n"); + + // Retrieve the number of records + rs = stmt.executeQuery("select count(*) from table0"); + if (!rs.next()) { + return ErrorLib.errorInvalidIndexedFile(indexedFilePath); + } + sb.append("Number of records: " + rs.getInt(1) + "\n"); + + // Retrieve the number of keys + rs = + stmt.executeQuery( + "select idx, offset, size, duplicate from metadata_key order by idx"); + while (rs.next()) { + int idx = rs.getInt("idx"); + int offset = rs.getInt("offset") + 1; + int size = rs.getInt("size"); + boolean duplicate = rs.getBoolean("duplicate"); + if (idx == 0) { + sb.append("Primary key position: "); + } else { + sb.append("Alternate key position "); + if (duplicate) { + sb.append("(Duplicates): "); + } else { + sb.append("(No duplicate): "); + } + } + sb.append(offset + "-" + (offset + size - 1) + "\n"); + } + + System.out.print(sb.toString()); + return 0; + } catch (SQLException e) { + return ErrorLib.errorInvalidIndexedFile(indexedFilePath); + } } - if (deleteBeforeLoading) { - cobolIndexedFile.deleteAllRecords(); + private static void migrateIndexedFile(String indexedFilePath) throws Exception { + try (Connection conn = DriverManager.getConnection("jdbc:sqlite:" + indexedFilePath); + Statement st = conn.createStatement()) { + String createTableSql = + "CREATE TABLE IF NOT EXISTS file_lock (locked_by text primary key,process_id" + + " text,locked_at timestamp,open_mode text CONSTRAINT check_open_mode" + + " CHECK (open_mode IN ('INPUT', 'OUTPUT', 'I-O', 'EXTEND')))"; + st.executeUpdate(createTableSql); + + boolean lockedByColumnExists = false; + boolean processIdColumnExists = false; + boolean lockedAtColumnExists = false; + try (ResultSet rs = st.executeQuery("PRAGMA table_info('table0')")) { + while (rs.next()) { + String columnName = rs.getString("name"); + if ("locked_by".equals(columnName)) { + lockedByColumnExists = true; + } else if ("process_id".equals(columnName)) { + processIdColumnExists = true; + } else if ("locked_at".equals(columnName)) { + lockedAtColumnExists = true; + } + if (lockedByColumnExists && processIdColumnExists && lockedAtColumnExists) { + break; + } + } + } + if (!lockedByColumnExists) { + st.executeUpdate("ALTER TABLE table0 ADD COLUMN locked_by text"); + } + if (!processIdColumnExists) { + st.executeUpdate("ALTER TABLE table0 ADD COLUMN process_id text"); + } + if (!lockedAtColumnExists) { + st.executeUpdate("ALTER TABLE table0 ADD COLUMN locked_at timestamp"); + } + } catch (SQLException e) { + throw new Exception( + String.format("failed to connect to the indexed file: %s", indexedFilePath), e); + } } - RecordReader reader = - RecordReader.getInstance(userDataFormat, cobolIndexedFile.record_max, filePath); - reader.open(); - LoadResult loadResult = LoadResult.LoadResultSuccess; - // Read records from stdin or a file and write them to the indexed file - while (true) { - loadResult = reader.read(cobolIndexedFile.record.getDataStorage()); - if (loadResult != LoadResult.LoadResultSuccess) { - break; - } - - // Write the record to the indexed file - CobolRuntimeException.code = 0; - try { - cobolIndexedFile.write(cobolIndexedFile.record, 0, null); - } catch (CobolStopRunException e) { - loadResult = LoadResult.LoadResultOther; - break; - } - if (CobolRuntimeException.code != 0) { - loadResult = LoadResult.LoadResultOther; - break; - } + private static void unlockIndexedFile(String indexedFilePath) throws Exception { + try (Connection conn = DriverManager.getConnection("jdbc:sqlite:" + indexedFilePath); + Statement st = conn.createStatement()) { + st.executeUpdate("DELETE FROM file_lock"); + st.executeUpdate( + "UPDATE table0 SET locked_by = NULL, process_id = NULL, locked_at = NULL"); + } catch (SQLException e) { + throw new Exception( + String.format("failed to connect to the indexed file: %s", indexedFilePath), e); + } } - reader.close(); + /** + * Process load sub command, which loads data inputted from stdin to the indexed file. + * + * @param indexedFilePath TODO: 準備中 + * @return TODO: 準備中 + */ + private static int processLoadCommand( + String indexedFilePath, + boolean deleteBeforeLoading, + UserDataFormat userDataFormat, + Optional filePath) { + File indexedFile = new File(indexedFilePath); + if (!indexedFile.exists()) { + return ErrorLib.errorFileDoesNotExist(indexedFilePath); + } + if (!indexedFile.isFile()) { + return ErrorLib.errorInvalidIndexedFile(indexedFilePath); + } + Optional cobolFileRet = createCobolFileFromIndexedFilePath(indexedFilePath); + if (!cobolFileRet.isPresent()) { + return ErrorLib.errorInvalidIndexedFile(indexedFilePath); + } + CobolIndexedFile cobolIndexedFile = (CobolIndexedFile) cobolFileRet.get(); - if (loadResult == LoadResult.LoadResultDataSizeMismatch) { - return ErrorLib.errorDataSizeMismatch(cobolIndexedFile.record.getSize()); - } else if (loadResult == LoadResult.LoadResultOther) { - return ErrorLib.errorDuplicateKeys(); - } else { - cobolIndexedFile.commitJdbcTransaction(); - cobolIndexedFile.close(0, null); - return 0; - } - } - - /** - * Process unload sub command, which writes records stored in the indexed file to stdout. - * - * @param indexedFilePath The path of the indexed file. - * @param userDataFormat The format of the output data. If this value is - * UserDataFormat.LINE_SEQUENTIAL, each records are separated by a newline character (0x20). - * If this value is UserDataFormat.SEQUENTIAL, each records are concatenated without any - * separator. - * @return 0 if success, otherwise non-zero. The return value is error code. - */ - private static int processUnloadCommand( - String indexedFilePath, UserDataFormat userDataFormat, Optional filePath) { - File indexedFile = new File(indexedFilePath); - if (!indexedFile.exists()) { - return ErrorLib.errorFileDoesNotExist(indexedFilePath); - } - if (!indexedFile.isFile()) { - return ErrorLib.errorInvalidIndexedFile(indexedFilePath); - } - Optional cobolFileRet = createCobolFileFromIndexedFilePath(indexedFilePath); - if (!cobolFileRet.isPresent()) { - return ErrorLib.errorInvalidIndexedFile(indexedFilePath); - } - CobolFile cobolFile = cobolFileRet.get(); - - // Set the module - CobolModule module = - new CobolModule(null, null, null, null, 0, '.', '$', ',', 1, 1, 1, 0, null); - CobolModule.push(module); - - // Open the indexed file - CobolRuntimeException.code = 0; - cobolFile.open(CobolFile.COB_OPEN_INPUT, 0, null); - if (CobolRuntimeException.code != 0) { - return ErrorLib.errorIO(); + // Set the module + CobolModule module = + new CobolModule(null, null, null, null, 0, '.', '$', ',', 1, 1, 1, 0, null); + CobolModule.push(module); + + // Open the indexed file + CobolRuntimeException.code = 0; + cobolIndexedFile.setCommitOnModification(false); + cobolIndexedFile.open(CobolFile.COB_OPEN_EXTEND, 0, null); + if (CobolRuntimeException.code != 0) { + return ErrorLib.errorIO(); + } + + if (deleteBeforeLoading) { + cobolIndexedFile.deleteAllRecords(); + } + + RecordReader reader = + RecordReader.getInstance(userDataFormat, cobolIndexedFile.record_max, filePath); + reader.open(); + LoadResult loadResult = LoadResult.LoadResultSuccess; + // Read records from stdin or a file and write them to the indexed file + while (true) { + loadResult = reader.read(cobolIndexedFile.record.getDataStorage()); + if (loadResult != LoadResult.LoadResultSuccess) { + break; + } + + // Write the record to the indexed file + CobolRuntimeException.code = 0; + try { + cobolIndexedFile.write(cobolIndexedFile.record, 0, null); + } catch (CobolStopRunException e) { + loadResult = LoadResult.LoadResultOther; + break; + } + if (CobolRuntimeException.code != 0) { + loadResult = LoadResult.LoadResultOther; + break; + } + } + + reader.close(); + + if (loadResult == LoadResult.LoadResultDataSizeMismatch) { + return ErrorLib.errorDataSizeMismatch(cobolIndexedFile.record.getSize()); + } else if (loadResult == LoadResult.LoadResultOther) { + return ErrorLib.errorDuplicateKeys(); + } else { + cobolIndexedFile.commitJdbcTransaction(); + cobolIndexedFile.close(0, null); + return 0; + } } - // Read records from the indexed file and write them to stdout or a file - boolean isIndexedFileEmpty = true; - try (OutputStream stream = getOutputStream(filePath)) { - while (true) { + /** + * Process unload sub command, which writes records stored in the indexed file to stdout. + * + * @param indexedFilePath The path of the indexed file. + * @param userDataFormat The format of the output data. If this value is + * UserDataFormat.LINE_SEQUENTIAL, each records are separated by a newline character (0x20). + * If this value is UserDataFormat.SEQUENTIAL, each records are concatenated without any + * separator. + * @return 0 if success, otherwise non-zero. The return value is error code. + */ + private static int processUnloadCommand( + String indexedFilePath, UserDataFormat userDataFormat, Optional filePath) { + File indexedFile = new File(indexedFilePath); + if (!indexedFile.exists()) { + return ErrorLib.errorFileDoesNotExist(indexedFilePath); + } + if (!indexedFile.isFile()) { + return ErrorLib.errorInvalidIndexedFile(indexedFilePath); + } + Optional cobolFileRet = createCobolFileFromIndexedFilePath(indexedFilePath); + if (!cobolFileRet.isPresent()) { + return ErrorLib.errorInvalidIndexedFile(indexedFilePath); + } + CobolFile cobolFile = cobolFileRet.get(); + + // Set the module + CobolModule module = + new CobolModule(null, null, null, null, 0, '.', '$', ',', 1, 1, 1, 0, null); + CobolModule.push(module); + + // Open the indexed file CobolRuntimeException.code = 0; - cobolFile.read(0, null, 1); - if (CobolRuntimeException.code == 0) { - isIndexedFileEmpty = false; - CobolDataStorage storage = cobolFile.record.getDataStorage(); - stream.write(storage.getRefOfData(), storage.getIndex(), cobolFile.record.getSize()); - if (userDataFormat == UserDataFormat.LINE_SEQUENTIAL) { - stream.write('\n'); - } - } else if (CobolRuntimeException.code == 0x0501) { - break; + cobolFile.open(CobolFile.COB_OPEN_INPUT, 0, null); + if (CobolRuntimeException.code != 0) { + return ErrorLib.errorIO(); + } + + // Read records from the indexed file and write them to stdout or a file + boolean isIndexedFileEmpty = true; + try (OutputStream stream = getOutputStream(filePath)) { + while (true) { + CobolRuntimeException.code = 0; + cobolFile.read(0, null, 1); + if (CobolRuntimeException.code == 0) { + isIndexedFileEmpty = false; + CobolDataStorage storage = cobolFile.record.getDataStorage(); + stream.write( + storage.getRefOfData(), storage.getIndex(), cobolFile.record.getSize()); + if (userDataFormat == UserDataFormat.LINE_SEQUENTIAL) { + stream.write('\n'); + } + } else if (CobolRuntimeException.code == 0x0501) { + break; + } else { + return ErrorLib.errorIO(); + } + } + if (userDataFormat == UserDataFormat.SEQUENTIAL && !isIndexedFileEmpty) { + stream.write('\n'); + } + } catch (IOException e) { + return ErrorLib.errorIO(); + } + + cobolFile.close(CobolFile.COB_CLOSE_NORMAL, null); + + CobolModule.pop(); + return 0; + } + + private static OutputStream getOutputStream(Optional filePath) + throws FileNotFoundException { + if (filePath.isPresent()) { + return new FileOutputStream(filePath.get()); } else { - return ErrorLib.errorIO(); - } - } - if (userDataFormat == UserDataFormat.SEQUENTIAL && !isIndexedFileEmpty) { - stream.write('\n'); - } - } catch (IOException e) { - return ErrorLib.errorIO(); + return System.out; + } } - cobolFile.close(CobolFile.COB_CLOSE_NORMAL, null); + private static Optional createCobolFileFromIndexedFilePath(String indexedFilePath) { + SQLiteConfig config = new SQLiteConfig(); + config.setReadOnly(true); + + try (Connection conn = + DriverManager.getConnection( + "jdbc:sqlite:" + indexedFilePath, config.toProperties()); + Statement stmt = conn.createStatement(); ) { + + ResultSet rs = + stmt.executeQuery( + "select value from metadata_string_int where key = 'record_size'"); + if (!rs.next()) { + return Optional.empty(); + } + + int recordSize = rs.getInt("value"); + + // Create a record field and data storage + AbstractCobolField recordField = createIndexedRecordField(recordSize); + CobolDataStorage recordDataStorage = recordField.getDataStorage(); + + // Retrive key information + List keyList = new ArrayList<>(); + rs = + stmt.executeQuery( + "select idx, offset, size, duplicate from metadata_key order by" + + " idx"); + while (rs.next()) { + int offset = rs.getInt("offset"); + int size = rs.getInt("size"); + boolean duplicate = rs.getBoolean("duplicate"); + addCobolFileKeyToList(keyList, recordDataStorage, offset, size, duplicate); + } + + // Return a CobolFile instance + return Optional.of( + createCobolFileInstance(indexedFilePath, recordSize, recordField, keyList)); + } catch (SQLException e) { + return Optional.empty(); + } + } - CobolModule.pop(); - return 0; - } + /** + * Create a CobolFile instance from the path of the indexed file. + * + * @param indexedFilePath TODO: 準備中 + * @return CobolFile instance if success, otherwise empty. + */ + private static Optional createCobolFile( + String indexedFilePath, Integer recordSize, List keyInfoList) { + SQLiteConfig config = new SQLiteConfig(); + config.setReadOnly(true); + + // Create a record field + AbstractCobolField recordField = createIndexedRecordField(recordSize); + CobolDataStorage recordDataStorage = recordField.getDataStorage(); + + // Retrive key information + List keyList = new ArrayList<>(); + for (CobolFileKeyInfo key : keyInfoList) { + addCobolFileKeyToList( + keyList, recordDataStorage, key.offset - 1, key.size, key.duplicate); + } - private static OutputStream getOutputStream(Optional filePath) - throws FileNotFoundException { - if (filePath.isPresent()) { - return new FileOutputStream(filePath.get()); - } else { - return System.out; + // Return a CobolFile instance + return Optional.of( + createCobolFileInstance(indexedFilePath, recordSize, recordField, keyList)); } - } - - /** - * Create a CobolFile instance from the path of the indexed file. - * - * @param indexedFilePath TODO: 準備中 - * @return CobolFile instance if success, otherwise empty. - */ - private static Optional createCobolFileFromIndexedFilePath(String indexedFilePath) { - SQLiteConfig config = new SQLiteConfig(); - config.setReadOnly(true); - - try (Connection conn = - DriverManager.getConnection("jdbc:sqlite:" + indexedFilePath, config.toProperties()); - Statement stmt = conn.createStatement(); ) { - - // Retrieve the record size - ResultSet rs = - stmt.executeQuery("select value from metadata_string_int where key = 'record_size'"); - if (!rs.next()) { - return Optional.empty(); - } - int recordSize = rs.getInt("value"); - - // Create a record field - byte[] recordByteArray = new byte[recordSize]; - CobolDataStorage recordDataStorage = new CobolDataStorage(recordByteArray); - AbstractCobolField recordField = - CobolFieldFactory.makeCobolField( - recordSize, recordDataStorage, new CobolFieldAttribute(1, 0, 0, 0, null)); - - // Retrive key information - List keyList = new ArrayList(); - rs = stmt.executeQuery("select idx, offset, size, duplicate from metadata_key order by idx"); - while (rs.next()) { - int offset = rs.getInt("offset"); - int size = rs.getInt("size"); - boolean duplicate = rs.getBoolean("duplicate"); + + private static AbstractCobolField createIndexedRecordField(int recordSize) { + byte[] recordByteArray = new byte[recordSize]; + CobolDataStorage recordDataStorage = new CobolDataStorage(recordByteArray); + return CobolFieldFactory.makeCobolField( + recordSize, recordDataStorage, new CobolFieldAttribute(1, 0, 0, 0, null)); + } + + private static void addCobolFileKeyToList( + List keyList, + CobolDataStorage recordStorage, + int offset, + int size, + boolean duplicate) { CobolFileKey cobolFileKey = new CobolFileKey(); cobolFileKey.setOffset(offset); cobolFileKey.setFlag(duplicate ? 1 : 0); AbstractCobolField keyField = - CobolFieldFactory.makeCobolField( - size, - recordDataStorage.getSubDataStorage(offset), - new CobolFieldAttribute(33, 0, 0, 0, null)); + CobolFieldFactory.makeCobolField( + size, + recordStorage.getSubDataStorage(offset), + new CobolFieldAttribute(33, 0, 0, 0, null)); cobolFileKey.setField(keyField); keyList.add(cobolFileKey); - } - - // Construct a CobolFile instance - byte[] fileStatus = new byte[4]; - byte[] indxedFilePathBytes = indexedFilePath.getBytes(); - AbstractCobolField assignField = - CobolFieldFactory.makeCobolField( - indxedFilePathBytes.length, - new CobolDataStorage(indxedFilePathBytes), - new CobolFieldAttribute(33, 0, 0, 0, null)); - CobolFileKey[] keyArray = new CobolFileKey[keyList.size()]; - keyList.toArray(keyArray); - CobolFile cobolFile = - CobolFileFactory.makeCobolFileInstance( - "f", - fileStatus, - assignField, - recordField, - null, - recordSize, - recordSize, - keyArray.length, - keyArray, - (char) 3, - (char) 1, - (char) 0, - (char) 0, - false, - (char) 0, - (char) 0, - false, - false, - false, - (char) 0, - false, - (char) 2, - false, - false, - (char) 0); - conn.close(); - return Optional.of(cobolFile); - } catch (SQLException e) { - return Optional.empty(); } - } + + private static CobolFile createCobolFileInstance( + String indexedFilePath, + int recordSize, + AbstractCobolField recordField, + List keyList) { + byte[] fileStatus = new byte[4]; + byte[] indxedFilePathBytes = indexedFilePath.getBytes(AbstractCobolField.charSetSJIS); + AbstractCobolField assignField = + CobolFieldFactory.makeCobolField( + indxedFilePathBytes.length, + new CobolDataStorage(indxedFilePathBytes), + new CobolFieldAttribute(33, 0, 0, 0, null)); + CobolFileKey[] keyArray = new CobolFileKey[keyList.size()]; + keyList.toArray(keyArray); + return CobolFileFactory.makeCobolFileInstance( + "f", + fileStatus, + assignField, + recordField, + null, + recordSize, + recordSize, + keyArray.length, + keyArray, + (char) 3, + (char) 1, + (char) 0, + (char) 0, + false, + (char) 0, + (char) 0, + false, + false, + false, + (char) 0, + false, + (char) 2, + false, + false, + (char) 0); + } + + private static void validateCreateCommandArgs(String[] unrecognizedArgs, CommandLine cmd) { + if (unrecognizedArgs.length < 2) { + throw new IllegalArgumentException("no indexed file is specified."); + } + if (!cmd.hasOption("s")) { + throw new IllegalArgumentException("no record size is specified."); + } + } + + private static int parseRecordSize(CommandLine cmd) { + String recordSizeString = cmd.getOptionValue("s"); + int recordSize; + try { + recordSize = Integer.parseInt(recordSizeString); + } catch (NumberFormatException e) { + throw new IllegalArgumentException( + String.format("invalid record size: %s", recordSizeString), e); + } + if (recordSize <= 0) { + throw new IllegalArgumentException( + String.format("invalid record size: %d", recordSize)); + } + return recordSize; + } + + private static void validateKeyInfoList(List keyInfoList, int recordSize) { + if (keyInfoList.isEmpty()) { + throw new IllegalArgumentException("no key information is specified."); + } else if (keyInfoList.get(0).duplicate) { + throw new IllegalArgumentException( + "the first key (primary key) must not be a duplicate key."); + } + for (CobolFileKeyInfo keyInfo : keyInfoList) { + if (keyInfo.offset <= 0 + || keyInfo.size <= 0 + || keyInfo.offset + keyInfo.size > recordSize + 1) { + throw new IllegalArgumentException( + String.format( + "invalid key information: offset=%d, size=%d, record size=%d", + keyInfo.offset, keyInfo.size, recordSize)); + } + } + // Check if key ranges overlap + for (int i = 0; i < keyInfoList.size(); i++) { + CobolFileKeyInfo key1Info = keyInfoList.get(i); + int key1IndexInf = key1Info.offset; + int key1IndexSup = key1Info.offset + key1Info.size - 1; + for (int j = 0; j < i; j++) { + CobolFileKeyInfo key2Info = keyInfoList.get(j); + int key2IndexInf = key2Info.offset; + int key2IndexSup = key2Info.offset + key2Info.size - 1; + if (!(key1IndexSup < key2IndexInf || key2IndexSup < key1IndexInf)) { + throw new IllegalArgumentException( + String.format( + "keys overlap: %d,%d and %d,%d", + key1Info.offset, + key1Info.size, + key2Info.offset, + key2Info.size)); + } + } + } + } + + private static void processCreateIndexedFile( + String indexedFilePath, + int recordSize, + List keyInfoList, + CommandLine cmd) { + Optional cobolFile = createCobolFile(indexedFilePath, recordSize, keyInfoList); + if (!cobolFile.isPresent()) { + throw new IllegalArgumentException( + String.format( + "failed to create a cobol file from the indexed file: %s", + indexedFilePath)); + } + CobolIndexedFile cobolIndexedFile = (CobolIndexedFile) cobolFile.get(); + boolean enableOverwriteOption = cmd.hasOption("n"); + boolean indexedFileAlreadyExists = new File(indexedFilePath).exists(); + if (enableOverwriteOption || !indexedFileAlreadyExists) { + CobolModule module = + new CobolModule(null, null, null, null, 0, '.', '$', ',', 1, 1, 1, 0, null); + CobolModule.push(module); + cobolIndexedFile.open(CobolFile.COB_OPEN_OUTPUT, 0, null); + if (CobolRuntimeException.code != 0) { + throw new IllegalArgumentException("failed to open the indexed file."); + } + cobolIndexedFile.close(0, null); + } else { + throw new IllegalArgumentException( + String.format( + "%s already exists. Use -n or --new option to overwrite it.", + indexedFilePath)); + } + } } diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/LoadResult.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/LoadResult.java index f6f75f3d..e4de5757 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/LoadResult.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/LoadResult.java @@ -2,12 +2,12 @@ /** Enum to specify the result of the load operation. */ enum LoadResult { - /** The load operation succeeded. */ - LoadResultSuccess, - /** The load operation failed because there exists a record whose size is invalid. */ - LoadResultDataSizeMismatch, - /** The load operation failed because duplicate keys are detected or other error occurs. */ - LoadResultOther, - /** Reach the end of input data */ - AtEnd, + /** The load operation succeeded. */ + LoadResultSuccess, + /** The load operation failed because there exists a record whose size is invalid. */ + LoadResultDataSizeMismatch, + /** The load operation failed because duplicate keys are detected or other error occurs. */ + LoadResultOther, + /** Reach the end of input data */ + AtEnd, }; diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/RecordReader.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/RecordReader.java index 0383447a..16c88f98 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/RecordReader.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/RecordReader.java @@ -5,41 +5,41 @@ /** TODO: 準備中 */ interface RecordReader { - /** TODO: 準備中 */ - void open(); + /** TODO: 準備中 */ + void open(); - /** - * TODO: 準備中 - * - * @param record TODO: 準備中 - * @return TODO: 準備中 - */ - LoadResult read(CobolDataStorage record); + /** + * TODO: 準備中 + * + * @param record TODO: 準備中 + * @return TODO: 準備中 + */ + LoadResult read(CobolDataStorage record); - /** TODO: 準備中 */ - void close(); + /** TODO: 準備中 */ + void close(); - /** - * TODO: 準備中 - * - * @param userDataFormat TODO: 準備中 - * @param recordSize TODO: 準備中 - * @param filePath TODO: 準備中 - * @return TODO: 準備中 - */ - static RecordReader getInstance( - UserDataFormat userDataFormat, int recordSize, Optional filePath) { - if (filePath.isPresent()) { - switch (userDataFormat) { - case LINE_SEQUENTIAL: - return new FileLineSeqRecordReader(recordSize, filePath.get()); - case SEQUENTIAL: - return new FileSeqRecordReader(recordSize, filePath.get()); - default: - return null; - } - } else { - return StdinRecordReader.getInstance(userDataFormat, recordSize); + /** + * TODO: 準備中 + * + * @param userDataFormat TODO: 準備中 + * @param recordSize TODO: 準備中 + * @param filePath TODO: 準備中 + * @return TODO: 準備中 + */ + static RecordReader getInstance( + UserDataFormat userDataFormat, int recordSize, Optional filePath) { + if (filePath.isPresent()) { + switch (userDataFormat) { + case LINE_SEQUENTIAL: + return new FileLineSeqRecordReader(recordSize, filePath.get()); + case SEQUENTIAL: + return new FileSeqRecordReader(recordSize, filePath.get()); + default: + return null; + } + } else { + return StdinRecordReader.getInstance(userDataFormat, recordSize); + } } - } } diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/RecordWriter.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/RecordWriter.java index ef869e9a..ba2c683a 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/RecordWriter.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/RecordWriter.java @@ -2,17 +2,17 @@ /** TODO: 準備中 */ interface RecordWriter { - /** TODO: 準備中 */ - void open(); + /** TODO: 準備中 */ + void open(); - /** - * TODO: 準備中 - * - * @param record TODO: 準備中 - * @return TODO: 準備中 - */ - boolean write(byte[] record); + /** + * TODO: 準備中 + * + * @param record TODO: 準備中 + * @return TODO: 準備中 + */ + boolean write(byte[] record); - /** TODO: 準備中 */ - void close(); + /** TODO: 準備中 */ + void close(); } diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/StdinRecordReader.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/StdinRecordReader.java index a213a89e..bc5d8d68 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/StdinRecordReader.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/StdinRecordReader.java @@ -5,125 +5,126 @@ /** TODO: 準備中 */ class StdinRecordReader implements RecordReader { - /** TODO: 準備中 */ - protected int recordSize; - /** TODO: 準備中 */ - protected Scanner scan; + /** TODO: 準備中 */ + protected int recordSize; - /** - * TODO: 準備中 - * - * @param recordSize TODO: 準備中 - */ - protected StdinRecordReader(int recordSize) { - this.recordSize = recordSize; - } + /** TODO: 準備中 */ + protected Scanner scan; - @Override - public void open() { - this.scan = new Scanner(System.in); - } - - @Override - public LoadResult read(CobolDataStorage record) { - return null; - } - - @Override - public void close() { - this.scan.close(); - } - - static class StdinLineSeqReader extends StdinRecordReader { /** * TODO: 準備中 * * @param recordSize TODO: 準備中 */ - StdinLineSeqReader(int recordSize) { - super(recordSize); + protected StdinRecordReader(int recordSize) { + this.recordSize = recordSize; } @Override - public LoadResult read(CobolDataStorage record) { - if (scan.hasNextLine()) { - byte[] readData = scan.nextLine().getBytes(); - if (readData.length != this.recordSize) { - return LoadResult.LoadResultDataSizeMismatch; - } - record.memcpy(readData, this.recordSize); - return LoadResult.LoadResultSuccess; - } else { - return LoadResult.AtEnd; - } + public void open() { + this.scan = new Scanner(System.in); } - } - static class StdinSeqReader extends StdinRecordReader { - private boolean firstFetchFail; - private byte[] readData; - private int readDataOffset; - - /** - * TODO: 準備中 - * - * @param recordSize TODO: 準備中 - */ - public StdinSeqReader(int recordSize) { - super(recordSize); + @Override + public LoadResult read(CobolDataStorage record) { + return null; } @Override - public void open() { - super.open(); - this.firstFetchFail = false; - this.readData = null; - this.readDataOffset = 0; + public void close() { + this.scan.close(); } - @Override - public LoadResult read(CobolDataStorage record) { - if (firstFetchFail) { - return LoadResult.LoadResultDataSizeMismatch; - } - if (readData == null) { - if (!this.scan.hasNextLine()) { - return LoadResult.AtEnd; + static class StdinLineSeqReader extends StdinRecordReader { + /** + * TODO: 準備中 + * + * @param recordSize TODO: 準備中 + */ + StdinLineSeqReader(int recordSize) { + super(recordSize); } - this.readData = this.scan.next().getBytes(); - if (readData.length % this.recordSize != 0) { - this.firstFetchFail = true; - return LoadResult.LoadResultDataSizeMismatch; + + @Override + public LoadResult read(CobolDataStorage record) { + if (scan.hasNextLine()) { + byte[] readData = scan.nextLine().getBytes(); + if (readData.length != this.recordSize) { + return LoadResult.LoadResultDataSizeMismatch; + } + record.memcpy(readData, this.recordSize); + return LoadResult.LoadResultSuccess; + } else { + return LoadResult.AtEnd; + } } - } - if (readDataOffset >= readData.length) { - return LoadResult.AtEnd; - } - record.memcpy(this.readData, this.readDataOffset, this.recordSize); - this.readDataOffset += this.recordSize; - return LoadResult.LoadResultSuccess; } - } - /** - * TODO: 準備中 - * - * @param userDataFormat TODO: 準備中 - * @param recordSize TODO: 準備中 - * @return TODO: 準備中 - */ - static RecordReader getInstance(UserDataFormat userDataFormat, int recordSize) { - switch (userDataFormat) { - case LINE_SEQUENTIAL: - { - return new StdinLineSeqReader(recordSize); + static class StdinSeqReader extends StdinRecordReader { + private boolean firstFetchFail; + private byte[] readData; + private int readDataOffset; + + /** + * TODO: 準備中 + * + * @param recordSize TODO: 準備中 + */ + public StdinSeqReader(int recordSize) { + super(recordSize); } - case SEQUENTIAL: - { - return new StdinSeqReader(recordSize); + + @Override + public void open() { + super.open(); + this.firstFetchFail = false; + this.readData = null; + this.readDataOffset = 0; + } + + @Override + public LoadResult read(CobolDataStorage record) { + if (firstFetchFail) { + return LoadResult.LoadResultDataSizeMismatch; + } + if (readData == null) { + if (!this.scan.hasNextLine()) { + return LoadResult.AtEnd; + } + this.readData = this.scan.next().getBytes(); + if (readData.length % this.recordSize != 0) { + this.firstFetchFail = true; + return LoadResult.LoadResultDataSizeMismatch; + } + } + if (readDataOffset >= readData.length) { + return LoadResult.AtEnd; + } + record.memcpy(this.readData, this.readDataOffset, this.recordSize); + this.readDataOffset += this.recordSize; + return LoadResult.LoadResultSuccess; + } + } + + /** + * TODO: 準備中 + * + * @param userDataFormat TODO: 準備中 + * @param recordSize TODO: 準備中 + * @return TODO: 準備中 + */ + static RecordReader getInstance(UserDataFormat userDataFormat, int recordSize) { + switch (userDataFormat) { + case LINE_SEQUENTIAL: + { + return new StdinLineSeqReader(recordSize); + } + case SEQUENTIAL: + { + return new StdinSeqReader(recordSize); + } + default: + return null; } - default: - return null; } - } } diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/UserDataFormat.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/UserDataFormat.java index 92d867d7..7dfefdbe 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/UserDataFormat.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/UserDataFormat.java @@ -2,14 +2,14 @@ /** Enum to specify the format of the input and output data. */ enum UserDataFormat { - /** - * This value means the line-sequential format of COBOL. Each records are separated by a newline - * character (0x20). - */ - LINE_SEQUENTIAL, - /** - * This value means the sequential format of COBOL. Each records are concatenated without any - * separator. - */ - SEQUENTIAL, + /** + * This value means the line-sequential format of COBOL. Each records are separated by a newline + * character (0x20). + */ + LINE_SEQUENTIAL, + /** + * This value means the sequential format of COBOL. Each records are concatenated without any + * separator. + */ + SEQUENTIAL, } diff --git a/libcobj/app/src/test/java/jp/osscons/opensourcecobol/libcobj/user_util/cobj_api/ApiFilesTest.java b/libcobj/app/src/test/java/jp/osscons/opensourcecobol/libcobj/user_util/cobj_api/ApiFilesTest.java index 5612c709..9eb933ed 100644 --- a/libcobj/app/src/test/java/jp/osscons/opensourcecobol/libcobj/user_util/cobj_api/ApiFilesTest.java +++ b/libcobj/app/src/test/java/jp/osscons/opensourcecobol/libcobj/user_util/cobj_api/ApiFilesTest.java @@ -13,29 +13,29 @@ class ApiFilesTest { - boolean compOutputFiles(String fileName) { - ApiFiles.javaCreate(fileName); - try { - return Arrays.equals( - Files.readAllBytes( - Paths.get( - "src/test/java/jp/osscons/opensourcecobol/libcobj/user_util/cobj_api/testController.txt")), - Files.readAllBytes(Paths.get("testController.java"))) - && Arrays.equals( - Files.readAllBytes( - Paths.get( - "src/test/java/jp/osscons/opensourcecobol/libcobj/user_util/cobj_api/testRecord.txt")), - Files.readAllBytes(Paths.get("testRecord.java"))); - } catch (IOException e) { - e.printStackTrace(); - return false; + boolean compOutputFiles(String fileName) { + ApiFiles.javaCreate(fileName); + try { + return Arrays.equals( + Files.readAllBytes( + Paths.get( + "src/test/java/jp/osscons/opensourcecobol/libcobj/user_util/cobj_api/testController.txt")), + Files.readAllBytes(Paths.get("testController.java"))) + && Arrays.equals( + Files.readAllBytes( + Paths.get( + "src/test/java/jp/osscons/opensourcecobol/libcobj/user_util/cobj_api/testRecord.txt")), + Files.readAllBytes(Paths.get("testRecord.java"))); + } catch (IOException e) { + e.printStackTrace(); + return false; + } } - } - @Test - void checkOutputFiles() { - String fileName = - "src/test/java/jp/osscons/opensourcecobol/libcobj/user_util/cobj_api/test.json"; - assertTrue(compOutputFiles(fileName)); - } + @Test + void checkOutputFiles() { + String fileName = + "src/test/java/jp/osscons/opensourcecobol/libcobj/user_util/cobj_api/test.json"; + assertTrue(compOutputFiles(fileName)); + } } diff --git a/libcobj/app/src/test/java/jp/osscons/opensourcecobol/libcobj/user_util/cobj_api/testRecord.txt b/libcobj/app/src/test/java/jp/osscons/opensourcecobol/libcobj/user_util/cobj_api/testRecord.txt index 93bfe2f0..77f80344 100644 --- a/libcobj/app/src/test/java/jp/osscons/opensourcecobol/libcobj/user_util/cobj_api/testRecord.txt +++ b/libcobj/app/src/test/java/jp/osscons/opensourcecobol/libcobj/user_util/cobj_api/testRecord.txt @@ -1,2 +1,6 @@ package com.example.restservice; -public record testRecord(int statuscode, int param1, double param2, String param3) {} +public record testRecord(int statuscode, int param1, double param2, String param3) { + public testRecord(){ + this(200, 0, 0, ""); + } +} diff --git a/libcobj/bin/cobj-idx b/libcobj/bin/cobj-idx index 3cc8777b..1f05b658 100755 --- a/libcobj/bin/cobj-idx +++ b/libcobj/bin/cobj-idx @@ -1,3 +1,6 @@ #!/bin/bash -java jp.osscons.opensourcecobol.libcobj.user_util.indexed_file.IndexedFileUtilMain $@ \ No newline at end of file +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +LIBCOBJ_JAR="$SCRIPT_DIR/../app/build/libs/libcobj.jar" + +java -cp "$LIBCOBJ_JAR" jp.osscons.opensourcecobol.libcobj.user_util.indexed_file.IndexedFileUtilMain $@ \ No newline at end of file diff --git a/libcobj/settings.gradle.kts b/libcobj/settings.gradle.kts index 5bc028ae..6eabf8c3 100644 --- a/libcobj/settings.gradle.kts +++ b/libcobj/settings.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" + id("org.gradle.toolchains.foojay-resolver-convention") version "0.10.0" } rootProject.name = "opensourcecobol4j" diff --git a/opensourcecobol4j.sln b/opensourcecobol4j.sln deleted file mode 100644 index 1c8de1d9..00000000 --- a/opensourcecobol4j.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.9.34728.123 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "opensourcecobol4j", "opensourcecobol4j\opensourcecobol4j.vbproj", "{FA5DE185-53AB-4630-A7BD-6BA0732385D6}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {FA5DE185-53AB-4630-A7BD-6BA0732385D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FA5DE185-53AB-4630-A7BD-6BA0732385D6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FA5DE185-53AB-4630-A7BD-6BA0732385D6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FA5DE185-53AB-4630-A7BD-6BA0732385D6}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {90D1E2AE-DF84-42DA-BD60-5CF828763604} - EndGlobalSection -EndGlobal diff --git a/tests/.gitignore b/tests/.gitignore index dc3ff865..2d979a6a 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -6,4 +6,5 @@ run~ syntax~ command-line-options~ cobj-idx~ +file-lock~ *.dir diff --git a/tests/Makefile.am b/tests/Makefile.am index c3934445..b0d89750 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -26,10 +26,11 @@ TESTS = syntax \ run-O \ data-rep \ data-rep-O \ - i18n_utf8 \ + cobol_utf8 \ jp-compat \ command-line-options \ cobj-idx \ + file-lock \ misc else TESTS = syntax \ @@ -41,6 +42,7 @@ TESTS = syntax \ jp-compat \ command-line-options \ cobj-idx \ + file-lock \ misc endif @@ -73,7 +75,8 @@ run_DEPENDENCIES = \ run.src/subscripts.at \ run.src/extensions.at \ run.src/return-code.at \ - run.src/functions.at + run.src/functions.at \ + run.src/system-routines.at data_rep_DEPENDENCIES = \ data-rep.at \ @@ -109,6 +112,22 @@ i18n_sjis_DEPENDENCIES = \ i18n_sjis.src/national.at \ i18n_sjis.src/mb-space.at +cobol_utf8_DEPENDENCIES = \ + cobol_utf8.at \ + cobol_utf8.src/user-defined-word.at \ + cobol_utf8.src/pic-x.at \ + cobol_utf8.src/pic-n.at \ + cobol_utf8.src/program-id.at \ + cobol_utf8.src/error-print.at \ + cobol_utf8.src/limits.at \ + cobol_utf8.src/national.at \ + cobol_utf8.src/mb-space.at \ + cobol_utf8.src/compare-national-diff-size.at \ + cobol_utf8.src/compare-national.at \ + cobol_utf8.src/file-handler-japanese.at \ + cobol_utf8.src/japanese-char-section-var.at \ + cobol_utf8.src/java-interface.at + jp_compat_DEPENDENCIES = \ jp-compat.at \ jp-compat.src/split-keys.at \ @@ -169,7 +188,6 @@ command_line_options_DEPENDENCIES = \ command-line-options.src/ffold-copy.at \ command-line-options.src/info-java-dir.at \ command-line-options.src/java-package.at \ - command-line-options.src/edit-code-command.at \ command-line-options.src/file-path.at \ command-line-options.src/fdefaultbyte.at \ command-line-options.src/ffunctions-all.at \ @@ -182,11 +200,28 @@ command_line_options_DEPENDENCIES = \ cobj_idx_DEPENDENCIES = \ cobj-idx.at \ + cobj-idx.src/create.at \ cobj-idx.src/info.at \ cobj-idx.src/load.at \ cobj-idx.src/unload.at \ + cobj-idx.src/migrate.at \ + cobj-idx.src/unlock.at \ cobj-idx.src/misc.at +indexed_lock_DEPENDENCIES = \ + file-lock.at \ + file-lock.src/lock-file.at \ + file-lock.src/access-same-record.at \ + file-lock.src/access-different-record.at \ + file-lock.src/input-mode.at \ + file-lock.src/same-process.at \ + file-lock.src/open-start-write-rewrite.at \ + file-lock.src/release-lock.at \ + file-lock.src/open-input.at \ + file-lock.src/lock-mode-clause.at \ + file-lock.src/old-file.at \ + file-lock.src/lock-mode-automatic.at + misc_DEPENDENCIES = \ misc.src/signed-comp3.at \ misc.src/index-comp.at \ @@ -216,7 +251,19 @@ misc_DEPENDENCIES = \ misc.src/validate-indexed-file-keys.at \ misc.src/record-key-duplicates-error.at \ misc.src/copy-comments.at \ - misc.src/read_prev_after_start.at + misc.src/read_prev_after_start.at \ + misc.src/japanese-char-section-var.at \ + misc.src/evaluate-switch.at \ + misc.src/fserial-variable.at \ + misc.src/file-handler-japanese.at \ + misc.src/perform-until-div.at \ + misc.src/search-occurs-depending.at \ + misc.src/fix-subtract.at \ + misc.src/display-numeric-NUMERIC-class.at \ + misc.src/display-inspect-sign.at \ + misc.src/comp1-comp2.at \ + misc.src/variable-length-file.at \ + misc.src/convert-string-concat.at EXTRA_DIST = $(srcdir)/package.m4 \ $(TESTS) \ @@ -255,8 +302,10 @@ $(srcdir)/syntax: $(syntax_DEPENDENCIES) $(srcdir)/run: $(run_DEPENDENCIES) $(srcdir)/data-rep: $(data_rep_DEPENDENCIES) $(srcdir)/i18n_utf8: $(i18n_utf8_DEPENDENCIES) +$(srcdir)/cobol_utf8: $(cobol_utf8_DEPENDENCIES) $(srcdir)/i18n_sjis: $(i18n_sjis_DEPENDENCIES) $(srcdir)/jp-compat: $(jp_compat_DEPENDENCIES) $(srcdir)/command-line-options: $(command_line_options_DEPENDENCIES) $(srcdir)/cobj-idx: $(cobj_idx_DEPENDENCIES) +$(srcdir)/file-lock: $(indexed_lock_DEPENDENCIES) $(srcdir)/misc: $(misc_DEPENDENCIES) diff --git a/tests/Makefile.in b/tests/Makefile.in index a84a5a63..a6fe74f8 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.16.5 from Makefile.am. +# Makefile.in generated by automake 1.16.2 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2021 Free Software Foundation, Inc. +# Copyright (C) 1994-2020 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -168,6 +168,8 @@ am__define_uniq_tagged_files = \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags am__tty_colors_dummy = \ mgn= red= grn= lgn= blu= brg= std=; \ am__color_tests=no @@ -350,7 +352,6 @@ am__set_TESTS_bases = \ bases='$(TEST_LOGS)'; \ bases=`for i in $$bases; do echo $$i; done | sed 's/\.log$$//'`; \ bases=`echo $$bases` -AM_TESTSUITE_SUMMARY_HEADER = ' for $(PACKAGE_STRING)' RECHECK_LOGS = $(TEST_LOGS) TEST_SUITE_LOG = test-suite.log TEST_EXTENSIONS = @EXEEXT@ .test @@ -375,7 +376,7 @@ TEST_LOG_COMPILE = $(TEST_LOG_COMPILER) $(AM_TEST_LOG_FLAGS) \ DIST_SUBDIRS = $(SUBDIRS) am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/atlocal.in \ $(top_srcdir)/mkinstalldirs $(top_srcdir)/test-driver \ - ChangeLog README.md + ChangeLog DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) am__relativize = \ dir0=`pwd`; \ @@ -435,8 +436,6 @@ COB_SHARED_OPT = @COB_SHARED_OPT@ COB_SPLITKEY_FLAGS = @COB_SPLITKEY_FLAGS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ -CSCOPE = @CSCOPE@ -CTAGS = @CTAGS@ CXXCPP = @CXXCPP@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ @@ -448,7 +447,6 @@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ -ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ @@ -572,6 +570,7 @@ SUBDIRS = cobol85 @I18N_UTF8_FALSE@ jp-compat \ @I18N_UTF8_FALSE@ command-line-options \ @I18N_UTF8_FALSE@ cobj-idx \ +@I18N_UTF8_FALSE@ file-lock \ @I18N_UTF8_FALSE@ misc @I18N_UTF8_TRUE@TESTS = syntax \ @@ -579,10 +578,11 @@ SUBDIRS = cobol85 @I18N_UTF8_TRUE@ run-O \ @I18N_UTF8_TRUE@ data-rep \ @I18N_UTF8_TRUE@ data-rep-O \ -@I18N_UTF8_TRUE@ i18n_utf8 \ +@I18N_UTF8_TRUE@ cobol_utf8 \ @I18N_UTF8_TRUE@ jp-compat \ @I18N_UTF8_TRUE@ command-line-options \ @I18N_UTF8_TRUE@ cobj-idx \ +@I18N_UTF8_TRUE@ file-lock \ @I18N_UTF8_TRUE@ misc syntax_DEPENDENCIES = \ @@ -614,7 +614,8 @@ run_DEPENDENCIES = \ run.src/subscripts.at \ run.src/extensions.at \ run.src/return-code.at \ - run.src/functions.at + run.src/functions.at \ + run.src/system-routines.at data_rep_DEPENDENCIES = \ data-rep.at \ @@ -650,6 +651,22 @@ i18n_sjis_DEPENDENCIES = \ i18n_sjis.src/national.at \ i18n_sjis.src/mb-space.at +cobol_utf8_DEPENDENCIES = \ + cobol_utf8.at \ + cobol_utf8.src/user-defined-word.at \ + cobol_utf8.src/pic-x.at \ + cobol_utf8.src/pic-n.at \ + cobol_utf8.src/program-id.at \ + cobol_utf8.src/error-print.at \ + cobol_utf8.src/limits.at \ + cobol_utf8.src/national.at \ + cobol_utf8.src/mb-space.at \ + cobol_utf8.src/compare-national-diff-size.at \ + cobol_utf8.src/compare-national.at \ + cobol_utf8.src/file-handler-japanese.at \ + cobol_utf8.src/japanese-char-section-var.at \ + cobol_utf8.src/java-interface.at + jp_compat_DEPENDENCIES = \ jp-compat.at \ jp-compat.src/split-keys.at \ @@ -710,7 +727,6 @@ command_line_options_DEPENDENCIES = \ command-line-options.src/ffold-copy.at \ command-line-options.src/info-java-dir.at \ command-line-options.src/java-package.at \ - command-line-options.src/edit-code-command.at \ command-line-options.src/file-path.at \ command-line-options.src/fdefaultbyte.at \ command-line-options.src/ffunctions-all.at \ @@ -723,11 +739,28 @@ command_line_options_DEPENDENCIES = \ cobj_idx_DEPENDENCIES = \ cobj-idx.at \ + cobj-idx.src/create.at \ cobj-idx.src/info.at \ cobj-idx.src/load.at \ cobj-idx.src/unload.at \ + cobj-idx.src/migrate.at \ + cobj-idx.src/unlock.at \ cobj-idx.src/misc.at +indexed_lock_DEPENDENCIES = \ + file-lock.at \ + file-lock.src/lock-file.at \ + file-lock.src/access-same-record.at \ + file-lock.src/access-different-record.at \ + file-lock.src/input-mode.at \ + file-lock.src/same-process.at \ + file-lock.src/open-start-write-rewrite.at \ + file-lock.src/release-lock.at \ + file-lock.src/open-input.at \ + file-lock.src/lock-mode-clause.at \ + file-lock.src/old-file.at \ + file-lock.src/lock-mode-automatic.at + misc_DEPENDENCIES = \ misc.src/signed-comp3.at \ misc.src/index-comp.at \ @@ -757,7 +790,19 @@ misc_DEPENDENCIES = \ misc.src/validate-indexed-file-keys.at \ misc.src/record-key-duplicates-error.at \ misc.src/copy-comments.at \ - misc.src/read_prev_after_start.at + misc.src/read_prev_after_start.at \ + misc.src/japanese-char-section-var.at \ + misc.src/evaluate-switch.at \ + misc.src/fserial-variable.at \ + misc.src/file-handler-japanese.at \ + misc.src/perform-until-div.at \ + misc.src/search-occurs-depending.at \ + misc.src/fix-subtract.at \ + misc.src/display-numeric-NUMERIC-class.at \ + misc.src/display-inspect-sign.at \ + misc.src/comp1-comp2.at \ + misc.src/variable-length-file.at \ + misc.src/convert-string-concat.at EXTRA_DIST = $(srcdir)/package.m4 \ $(TESTS) \ @@ -1019,7 +1064,7 @@ $(TEST_SUITE_LOG): $(TEST_LOGS) test x"$$VERBOSE" = x || cat $(TEST_SUITE_LOG); \ fi; \ echo "$${col}$$br$${std}"; \ - echo "$${col}Testsuite summary"$(AM_TESTSUITE_SUMMARY_HEADER)"$${std}"; \ + echo "$${col}Testsuite summary for $(PACKAGE_STRING)$${std}"; \ echo "$${col}$$br$${std}"; \ create_testsuite_report --maybe-color; \ echo "$$col$$br$$std"; \ @@ -1116,6 +1161,13 @@ cobj-idx.log: cobj-idx --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ "$$tst" $(AM_TESTS_FD_REDIRECT) +file-lock.log: file-lock + @p='file-lock'; \ + b='file-lock'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) misc.log: misc @p='misc'; \ b='misc'; \ @@ -1123,9 +1175,9 @@ misc.log: misc --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ "$$tst" $(AM_TESTS_FD_REDIRECT) -i18n_utf8.log: i18n_utf8 - @p='i18n_utf8'; \ - b='i18n_utf8'; \ +cobol_utf8.log: cobol_utf8 + @p='cobol_utf8'; \ + b='cobol_utf8'; \ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ @@ -1144,6 +1196,7 @@ i18n_utf8.log: i18n_utf8 @am__EXEEXT_TRUE@ --log-file $$b.log --trs-file $$b.trs \ @am__EXEEXT_TRUE@ $(am__common_driver_flags) $(AM_TEST_LOG_DRIVER_FLAGS) $(TEST_LOG_DRIVER_FLAGS) -- $(TEST_LOG_COMPILE) \ @am__EXEEXT_TRUE@ "$$tst" $(AM_TESTS_FD_REDIRECT) + distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am @@ -1351,10 +1404,12 @@ $(srcdir)/syntax: $(syntax_DEPENDENCIES) $(srcdir)/run: $(run_DEPENDENCIES) $(srcdir)/data-rep: $(data_rep_DEPENDENCIES) $(srcdir)/i18n_utf8: $(i18n_utf8_DEPENDENCIES) +$(srcdir)/cobol_utf8: $(cobol_utf8_DEPENDENCIES) $(srcdir)/i18n_sjis: $(i18n_sjis_DEPENDENCIES) $(srcdir)/jp-compat: $(jp_compat_DEPENDENCIES) $(srcdir)/command-line-options: $(command_line_options_DEPENDENCIES) $(srcdir)/cobj-idx: $(cobj_idx_DEPENDENCIES) +$(srcdir)/file-lock: $(indexed_lock_DEPENDENCIES) $(srcdir)/misc: $(misc_DEPENDENCIES) # Tell versions [3.59,3.63) of GNU make to not export all variables. diff --git a/tests/a.sh b/tests/a.sh new file mode 100644 index 00000000..3453fc86 --- /dev/null +++ b/tests/a.sh @@ -0,0 +1,15 @@ +LANG=C.utf8 \ +LC_CTYPE="C.utf8" \ +LC_NUMERIC="C.utf8" \ +LC_TIME="C.utf8" \ +LC_COLLATE="C.utf8" \ +LC_MONETARY="C.utf8" \ +LC_MESSAGES="C.utf8" \ +LC_PAPER="C.utf8" \ +LC_NAME="C.utf8" \ +LC_ADDRESS="C.utf8" \ +LC_TELEPHONE="C.utf8" \ +LC_MEASUREMENT="C.utf8" \ +LC_IDENTIFICATION="C.utf8" \ +LC_ALL="" \ +./cobol_utf8 \ No newline at end of file diff --git a/tests/a.txt b/tests/a.txt new file mode 100644 index 00000000..05009d66 --- /dev/null +++ b/tests/a.txt @@ -0,0 +1 @@ +{ diff --git a/tests/cobj-idx.at b/tests/cobj-idx.at index fc2edb05..80fb4bde 100644 --- a/tests/cobj-idx.at +++ b/tests/cobj-idx.at @@ -1,7 +1,9 @@ AT_INIT([cobj-idx]) +m4_include([create.at]) m4_include([info.at]) m4_include([load.at]) m4_include([unload.at]) m4_include([cobj-idx.src/misc.at]) - +m4_include([migrate.at]) +m4_include([unlock.at]) diff --git a/tests/cobj-idx.src/create.at b/tests/cobj-idx.src/create.at new file mode 100644 index 00000000..ce2a09f6 --- /dev/null +++ b/tests/cobj-idx.src/create.at @@ -0,0 +1,308 @@ +AT_SETUP([create: basic]) + +# Normal case: Test for basic INDEXED file creation +AT_CHECK([${COBJ_IDX} create test.idx --size=30 --key=1,5]) + +# Verify that the created file exists +AT_CHECK([test -f test.idx]) + +# Check information of the created INDEXED file using info command +AT_CHECK([${COBJ_IDX} info test.idx], [0], +[Size of a record: 30 +Number of records: 0 +Primary key position: 1-5 +]) + +AT_CLEANUP + +AT_SETUP([create: with multiple keys]) + +# Normal case: Test for INDEXED file creation with multiple keys +AT_CHECK([${COBJ_IDX} create multikey.idx --size=50 --key=1,5:10,3:d20,6], [0], [], []) + +# Verify that the created file exists +AT_CHECK([test -f multikey.idx]) + +# Check information of the created INDEXED file using info command +AT_CHECK([${COBJ_IDX} info multikey.idx], [0], +[Size of a record: 50 +Number of records: 0 +Primary key position: 1-5 +Alternate key position (No duplicate): 10-12 +Alternate key position (Duplicates): 20-25 +]) + +AT_CLEANUP + +AT_SETUP([create: overwrite existing file]) + +# Create an existing file first +AT_CHECK([${COBJ_IDX} create overwrite.idx --size=10 --key=1,3]) + +# Try to overwrite without --new option +AT_CHECK([${COBJ_IDX} create overwrite.idx --size=20 --key=1,5], [1], [], +[error: overwrite.idx already exists. Use -n or --new option to overwrite it. +]) + +# Overwrite with --new option +AT_CHECK([${COBJ_IDX} create overwrite.idx --size=20 --key=1,5 --new]) + +# Confirm that the file was overwritten +AT_CHECK([${COBJ_IDX} info overwrite.idx], [0], +[Size of a record: 20 +Number of records: 0 +Primary key position: 1-5 +]) + +AT_CLEANUP + +AT_SETUP([create: error no indexed file]) + +# Error case: No INDEXED file name is specified +AT_CHECK([${COBJ_IDX} create], [1], [], +[error: no indexed file is specified. +]) + +AT_CHECK([${COBJ_IDX} create --key=1,3], [1], [], +[error: no indexed file is specified. +]) + +AT_CHECK([${COBJ_IDX} create --key=1,3:5,2], [1], [], +[error: no indexed file is specified. +]) + + +AT_CLEANUP + +AT_SETUP([create: error no record size]) + +# Error case: No record size is specified +AT_CHECK([${COBJ_IDX} create nosize.idx], [1], [], +[error: no record size is specified. +]) + +AT_CLEANUP + +AT_SETUP([create: error invalid record size]) + +# Error case: Invalid record size (string) +AT_CHECK([${COBJ_IDX} create invalid.idx --size=abc --key=1,5], [1], [], +[error: invalid record size: abc +]) + +# Error case: Invalid record size (negative number) +AT_CHECK([${COBJ_IDX} create invalid.idx --size=-10 --key=1,5], [1], [], +[error: invalid record size: -10 +]) + +# Error case: Invalid record size (zero) +AT_CHECK([${COBJ_IDX} create invalid.idx --size=0 --key=1,5], [1], [], +[error: invalid record size: 0 +]) + +AT_CLEANUP + +AT_SETUP([create: error no key]) + +# Error case: No key information is specified +AT_CHECK([${COBJ_IDX} create nokey.idx --size=30], [1], [], +[error: no key information is specified. +]) + +AT_CLEANUP + +AT_SETUP([create: error primary key is duplicate]) + +# Error case: Primary key is specified as a duplicate key +AT_CHECK([${COBJ_IDX} create dupkey.idx --size=30 --key=d1,5], [1], [], +[error: the first key (primary key) must not be a duplicate key. +]) + +AT_CLEANUP + +AT_SETUP([create: error invalid key format]) + +# Error case: Invalid key information format +AT_CHECK([${COBJ_IDX} create badkey.idx --size=30 --key=1], [1], [], +[error: invalid key information: 1 +]) + +AT_CHECK([${COBJ_IDX} create badkey.idx --size=30 --key=a,5], [1], [], +[error: invalid key information: a,5 +]) + +AT_CLEANUP + +AT_SETUP([create: error key out of range]) + +# Error case: Key range exceeds record size +AT_CHECK([${COBJ_IDX} create outrange.idx --size=10 --key=5,10], [1], [], +[error: invalid key information: offset=5, size=10, record size=10 +]) + +# Error case: Offset is less than or equal to 0 +AT_CHECK([${COBJ_IDX} create badoffset.idx --size=30 --key=0,5], [1], [], +[error: key offsets must be greater than 0: 0,5 +]) + +# Error case: Size is less than or equal to 0 +AT_CHECK([${COBJ_IDX} create badsize.idx --size=30 --key=1,0], [1], [], +[error: key sizes must be greater than 0: 1,0 +]) + +AT_CHECK([${COBJ_IDX} create test.idx --size=100 --key=0,2:15,4:d20,5], [1], [], +[error: key offsets must be greater than 0: 0,2:15,4:d20,5 +]) + +AT_CHECK([${COBJ_IDX} create test.idx --size=100 --key=10,2:0,4:d20,5], [1], [], +[error: key offsets must be greater than 0: 10,2:0,4:d20,5 +]) + +AT_CHECK([${COBJ_IDX} create test.idx --size=100 --key=10,2:15,4:d0,5], [1], [], +[error: key offsets must be greater than 0: 10,2:15,4:d0,5 +]) + +AT_CHECK([${COBJ_IDX} create test.idx --size=100 --key=10,0:15,4:d20,5], [1], [], +[error: key sizes must be greater than 0: 10,0:15,4:d20,5 +]) + +AT_CHECK([${COBJ_IDX} create test.idx --size=100 --key=10,2:15,0:d20,5], [1], [], +[error: key sizes must be greater than 0: 10,2:15,0:d20,5 +]) + +AT_CHECK([${COBJ_IDX} create test.idx --size=100 --key=10,2:15,4:d20,0], [1], [], +[error: key sizes must be greater than 0: 10,2:15,4:d20,0 +]) + +AT_CLEANUP + +AT_SETUP([create: error overlapping keys]) + +# Error case: Overlapping key ranges +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=1,5:3,5 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=1,5:5,1 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=1,5:5,2 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=1,5:5,1 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=1,5:5,2 2> /dev/null], [1]) + +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=2,4:1,6 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=2,4:2,5 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=2,4:1,5 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=2,4:2,4 2> /dev/null], [1]) + +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=3,5:1,5 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=5,1:1,5 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=5,2:1,5 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=5,1:1,5 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=5,2:1,5 2> /dev/null], [1]) + +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=1,6:2,4 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=2,5:2,4 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=1,5:2,4 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=2,4:2,4 2> /dev/null], [1]) + +############### + +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=1,5:d3,5 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=1,5:d5,1 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=1,5:d5,2 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=1,5:d5,1 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=1,5:d5,2 2> /dev/null], [1]) + +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=2,4:d1,6 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=2,4:d2,5 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=2,4:d1,5 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=2,4:d2,4 2> /dev/null], [1]) + +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=3,5:d1,5 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=5,1:d1,5 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=5,2:d1,5 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=5,1:d1,5 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=5,2:d1,5 2> /dev/null], [1]) + +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=1,6:d2,4 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=2,5:d2,4 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=1,5:d2,4 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=2,4:d2,4 2> /dev/null], [1]) + +############### + +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=15,5:1,5:d3,5 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=15,5:1,5:d5,1 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=15,5:1,5:d5,2 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=15,5:1,5:d5,1 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=15,5:1,5:d5,2 2> /dev/null], [1]) + +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=15,5:2,4:d1,6 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=15,5:2,4:d2,5 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=15,5:2,4:d1,5 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=15,5:2,4:d2,4 2> /dev/null], [1]) + +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=15,5:3,5:d1,5 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=15,5:5,1:d1,5 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=15,5:5,2:d1,5 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=15,5:5,1:d1,5 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=15,5:5,2:d1,5 2> /dev/null], [1]) + +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=15,5:1,6:d2,4 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=15,5:2,5:d2,4 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=15,5:1,5:d2,4 2> /dev/null], [1]) +AT_CHECK([${COBJ_IDX} create overlap.idx --size=30 --key=15,5:2,4:d2,4 2> /dev/null], [1]) + +AT_CLEANUP + +AT_SETUP([create: load and unload after creation]) + +# Normal case: Create an INDEXED file +AT_CHECK([${COBJ_IDX} create loadtest.idx --size=30 --key=1,5]) + +# Prepare test data for loading +AT_DATA([load_data.txt], +[abcde12345test data record 1** +fghij67890test data record 2** +]) + +# Load data into the created file (LINE_SEQUENTIAL format) +AT_CHECK([${COBJ_IDX} load loadtest.idx load_data.txt --format=txt]) + +# Unload and verify the data +AT_CHECK([${COBJ_IDX} unload loadtest.idx --format=txt], [0], +[abcde12345test data record 1** +fghij67890test data record 2** +]) + +# Test loading and unloading with binary format +AT_DATA([binary_data.bin], +[key0112345binary format 1key0267890binary format 2 +]) + +# Create a new file +AT_CHECK([${COBJ_IDX} create bintest.idx --size=25 --key=1,5]) + +# Load binary data +AT_CHECK([${COBJ_IDX} load bintest.idx binary_data.bin]) + +# Unload and verify the data +AT_CHECK([${COBJ_IDX} unload bintest.idx], [0], +[key0112345binary format 1key0267890binary format 2 +]) + +# Test with a file having multiple keys +AT_CHECK([${COBJ_IDX} create multiloadtest.idx --size=30 --key=1,5:10,5:d20,5]) + +AT_DATA([multikey_data.txt], +[abcde12345hello67890key3@@@@@@ +fghij54321world12345key4@@@@@@ +klmno12345test 67890key5@@@@@@ +]) + +AT_CHECK([${COBJ_IDX} load multiloadtest.idx multikey_data.txt --format=txt]) + +# Unload and verify the data +AT_CHECK([${COBJ_IDX} unload multiloadtest.idx --format=txt], [0], +[abcde12345hello67890key3@@@@@@ +fghij54321world12345key4@@@@@@ +klmno12345test 67890key5@@@@@@ +]) + +AT_CLEANUP \ No newline at end of file diff --git a/tests/cobj-idx.src/load.at b/tests/cobj-idx.src/load.at index e0754e98..5c7f4b01 100644 --- a/tests/cobj-idx.src/load.at +++ b/tests/cobj-idx.src/load.at @@ -13,7 +13,8 @@ AT_DATA([load.cbl], alternate record key is alt-key-1 alternate record key is alt-key-2 alternate record key is alt-key-dup-1 with duplicates - alternate record key is alt-key-dup-2 with duplicates. + alternate record key is alt-key-dup-2 with duplicates + file status is file-status. data division. file section. fd f. @@ -25,9 +26,13 @@ AT_DATA([load.cbl], 03 alt-key-dup-2 pic x(5). 03 rec-value pic x(5). working-storage section. + 01 file-status pic xx. procedure division. main-proc. open input f. + if file-status not = '00' + stop run + end-if. perform forever read f next at end diff --git a/tests/cobj-idx.src/migrate.at b/tests/cobj-idx.src/migrate.at new file mode 100644 index 00000000..175820df --- /dev/null +++ b/tests/cobj-idx.src/migrate.at @@ -0,0 +1,100 @@ +AT_SETUP([migrate]) + +AT_DATA([check_file.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. check_file. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO INDEX_FILE_PATH + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 DUMMY PIC X(10) VALUE "DUMMY DATA". + PROCEDURE DIVISION. + MAIN-PROCEDURE. + + OPEN I-O f. + + MOVE "AAAA1" TO REC-KEY. + READ F WITH LOCK. + DISPLAY REC. + + MOVE "AAAA2" TO REC-KEY. + REWRITE REC. + + MOVE "AAAA2" TO REC-KEY. + READ F WITH LOCK. + DISPLAY REC. + + MOVE "AAAA2" TO REC-KEY. + DELETE F. + DISPLAY FILE-STATUS. + + MOVE "AAAA1" TO REC-KEY. + START F KEY IS = REC-KEY. + PERFORM FOREVER + READ F NEXT RECORD + AT END + EXIT PERFORM + NOT AT END + DISPLAY REC + END-READ + END-PERFORM. + CLOSE f. +]) + +# copy the indexed file created with the older compiler to the current directory +AT_CHECK([cp ../../cobj-idx.src/test-data/indexed_file.dat .]) + +# convert the indexed file to the current format +AT_CHECK([${COBJ_IDX} migrate indexed_file.dat]) + +# check the converted file +AT_CHECK([${COMPILE} --assign_external check_file.cbl]) +AT_CHECK([INDEX_FILE_PATH=indexed_file.dat java check_file], [0], +[AAAA1BBBB1CCCC1 +AAAA2BBBB1CCCC1 +00 +AAAA1BBBB1CCCC1 +AAAA3BBBB3CCCC3 +]) + +# Test migrate with multiple files +AT_CHECK([cp ../../cobj-idx.src/test-data/indexed_file.dat indexed_file2.dat]) +AT_CHECK([cp ../../cobj-idx.src/test-data/indexed_file.dat indexed_file3.dat]) +AT_CHECK([${COBJ_IDX} migrate indexed_file2.dat indexed_file3.dat]) + +# check that indexed_file2.dat works properly after migration +AT_CHECK([INDEX_FILE_PATH=indexed_file2.dat java check_file], [0], +[AAAA1BBBB1CCCC1 +AAAA2BBBB1CCCC1 +00 +AAAA1BBBB1CCCC1 +AAAA3BBBB3CCCC3 +]) + +# check that indexed_file3.dat works properly after migration +AT_CHECK([INDEX_FILE_PATH=indexed_file3.dat java check_file], [0], +[AAAA1BBBB1CCCC1 +AAAA2BBBB1CCCC1 +00 +AAAA1BBBB1CCCC1 +AAAA3BBBB3CCCC3 +]) + +AT_CLEANUP \ No newline at end of file diff --git a/tests/cobj-idx.src/test-data/indexed_file.dat b/tests/cobj-idx.src/test-data/indexed_file.dat new file mode 100644 index 00000000..a40fc42a Binary files /dev/null and b/tests/cobj-idx.src/test-data/indexed_file.dat differ diff --git a/tests/cobj-idx.src/unlock.at b/tests/cobj-idx.src/unlock.at new file mode 100644 index 00000000..bdc2ee77 --- /dev/null +++ b/tests/cobj-idx.src/unlock.at @@ -0,0 +1,186 @@ +AT_SETUP([unlock]) + +# Create a sample indexed file named 'indexed_file.dat' and exit the program without closing the file +AT_DATA([create_and_exit.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. create_and_exit. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "indexed_file.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 DUMMY PIC X(10) VALUE "DUMMY DATA". + PROCEDURE DIVISION. + MAIN-PROCEDURE. + OPEN OUTPUT f. + MOVE "AAAA1" TO REC-KEY. + MOVE "BBBB1" TO REC-KEY2. + MOVE "CCCC1" TO REC-DATA. + WRITE REC. + CLOSE f. + + OPEN I-O f. + MOVE "AAAA1" TO REC-KEY. + READ f WITH LOCK. + CALL "force_exit". +]) + +AT_DATA([force_exit.java], [ +import java.io.UnsupportedEncodingException; +import jp.osscons.opensourcecobol.libcobj.*; +import jp.osscons.opensourcecobol.libcobj.common.*; +import jp.osscons.opensourcecobol.libcobj.data.*; +import jp.osscons.opensourcecobol.libcobj.exceptions.*; +import jp.osscons.opensourcecobol.libcobj.termio.*; +import jp.osscons.opensourcecobol.libcobj.call.*; +import jp.osscons.opensourcecobol.libcobj.file.*; +import jp.osscons.opensourcecobol.libcobj.ui.*; +import java.util.Optional; + +public class force_exit implements CobolRunnable { + @Override + public int run(CobolDataStorage... argStorages) { + System.exit(0); + return 0; + } + + @Override + public void cancel() { + return; + } + + @Override + public boolean isActive() { + return false; + } +} +]) + +AT_DATA([check_file_lock.cbl],[ + IDENTIFICATION DIVISION. + PROGRAM-ID. check_file_lock. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "indexed_file.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 DUMMY PIC X(10) VALUE "DUMMY DATA". + PROCEDURE DIVISION. + MAIN-PROCEDURE. + OPEN OUTPUT f. + DISPLAY FILE-STATUS. + CLOSE f. +]) + +AT_DATA([check_record_lock.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. check_record_lock. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "indexed_file.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + PROCEDURE DIVISION. + MAIN-PROCEDURE. + + OPEN I-O f. + + MOVE "AAAA1" TO REC-KEY. + READ F WITH LOCK. + DISPLAY FILE-STATUS. + + CLOSE f. +]) + +AT_CHECK([${COMPILE} *.cbl]) +AT_CHECK([javac force_exit.java]) + +# Create the indexed file and exit the program without closing the file +AT_CHECK([java create_and_exit]) +# Check the file is locked +AT_CHECK([java check_file_lock], [0], +[61 +]) + +AT_CHECK([rm -f indexed_file.dat]) +# Create the indexed file and exit the program without closing the file +AT_CHECK([java create_and_exit]) +# Unlock the file +AT_CHECK([${COBJ_IDX} unlock indexed_file.dat]) +# Check the file lock is released +AT_CHECK([java check_file_lock], [0], +[00 +]) + +AT_CHECK([rm -f indexed_file.dat]) +# Create the indexed file and exit the program without closing the file +AT_CHECK([java create_and_exit]) +# Unlock the file +AT_CHECK([${COBJ_IDX} unlock indexed_file.dat]) +# Check the record lock is released +AT_CHECK([java check_record_lock], [0], +[00 +]) + +# Test unlock with multiple files +AT_CHECK([rm -f indexed_file.dat indexed_file2.dat]) +# Create multiple locked files +AT_CHECK([java create_and_exit]) +AT_CHECK([cp indexed_file.dat indexed_file2.dat]) +AT_CHECK([java create_and_exit]) # This will leave indexed_file.dat locked +# Unlock multiple files +AT_CHECK([${COBJ_IDX} unlock indexed_file.dat indexed_file2.dat]) +# Check both files are unlocked +AT_CHECK([java check_file_lock], [0], +[00 +]) + +AT_CLEANUP \ No newline at end of file diff --git a/tests/cobol85/Makefile.in b/tests/cobol85/Makefile.in index f6440604..a05e5b82 100644 --- a/tests/cobol85/Makefile.in +++ b/tests/cobol85/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.16.5 from Makefile.am. +# Makefile.in generated by automake 1.16.2 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2021 Free Software Foundation, Inc. +# Copyright (C) 1994-2020 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -117,8 +117,7 @@ am__can_run_installinfo = \ *) (install-info --version) >/dev/null 2>&1;; \ esac am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) -am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/mkinstalldirs \ - README.md +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/mkinstalldirs DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ ALLOCA = @ALLOCA@ @@ -153,8 +152,6 @@ COB_SHARED_OPT = @COB_SHARED_OPT@ COB_SPLITKEY_FLAGS = @COB_SPLITKEY_FLAGS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ -CSCOPE = @CSCOPE@ -CTAGS = @CTAGS@ CXXCPP = @CXXCPP@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ @@ -166,7 +163,6 @@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ -ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ @@ -334,6 +330,7 @@ ctags CTAGS: cscope cscopelist: + distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am diff --git a/tests/cobol_utf8.at b/tests/cobol_utf8.at new file mode 100644 index 00000000..fca53cf8 --- /dev/null +++ b/tests/cobol_utf8.at @@ -0,0 +1,37 @@ +### OpenCOBOL Test Suite -*- m4 -*- + +# Copyright (C) 2003-2009 Keisuke Nishida +# Copyright (C) 2007-2009 Roger While +# Copyright (C) 2021-2022 TOKYO SYSTEM HOUSE Co., Ltd. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this software; see the file COPYING. If not, write to +# the Free Software Foundation, 51 Franklin Street, Fifth Floor +# Boston, MA 02110-1301 USA + +AT_INIT([I18n Shift_JIS Tests]) + +m4_include([user-defined-word.at]) +m4_include([pic-x.at]) +m4_include([pic-n.at]) +m4_include([program-id.at]) +m4_include([error-print.at]) +m4_include([limits.at]) +m4_include([national.at]) +m4_include([mb-space.at]) + +m4_include([compare-national-diff-size.at]) +m4_include([compare-national.at]) +m4_include([file-handler-japanese.at]) +m4_include([japanese-char-section-var.at]) +m4_include([java-interface.at]) diff --git a/tests/cobol_utf8.src/compare-national-diff-size.at b/tests/cobol_utf8.src/compare-national-diff-size.at new file mode 100644 index 00000000..063768fb --- /dev/null +++ b/tests/cobol_utf8.src/compare-national-diff-size.at @@ -0,0 +1,55 @@ +AT_SETUP([Compare national of different sizes]) +export LC_ALL='' + +AT_DATA([prog.cbl],[ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + ENVIRONMENT DIVISION. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 WK-STR1-1 PIC N(04) value "猫". + 01 WK-STR1-2 PIC N(02) value "猫". + 01 WK-STR2-1 PIC N(04) value "猫犬". + 01 WK-STR2-2 PIC N(02) value "猫犬". + 01 WK-STR3-1 PIC N(04). + 01 WK-STR3-2 PIC N(02). + 01 WK-STR4-1 PIC N(04) VALUE SPACE. + 01 WK-STR4-2 PIC N(02) VALUE SPACE. + 01 WK-STR5-1 PIC N(100) value "猫". + 01 WK-STR5-2 PIC N(1) value "猫". + PROCEDURE DIVISION. + IF WK-STR1-1 NOT = WK-STR1-2 + DISPLAY "NG" + END-IF. + IF WK-STR1-2 NOT = WK-STR1-1 + DISPLAY "NG" + END-IF. + IF WK-STR2-1 NOT = WK-STR2-2 + DISPLAY "NG" + END-IF. + IF WK-STR2-2 NOT = WK-STR2-1 + DISPLAY "NG" + END-IF. + IF WK-STR3-1 NOT = WK-STR3-2 + DISPLAY "NG" + END-IF. + IF WK-STR3-2 NOT = WK-STR3-1 + DISPLAY "NG" + END-IF. + IF WK-STR4-1 NOT = WK-STR4-2 + DISPLAY "NG" + END-IF. + IF WK-STR4-2 NOT = WK-STR4-1 + DISPLAY "NG" + END-IF. + IF WK-STR5-1 NOT = WK-STR5-2 + DISPLAY "NG" + END-IF. + IF WK-STR5-2 NOT = WK-STR5-1 + DISPLAY "NG" + END-IF. +]) +AT_CHECK([cobj prog.cbl]) +AT_CHECK([java prog]) + +AT_CLEANUP diff --git a/tests/cobol_utf8.src/compare-national.at b/tests/cobol_utf8.src/compare-national.at new file mode 100644 index 00000000..3c3d19bf --- /dev/null +++ b/tests/cobol_utf8.src/compare-national.at @@ -0,0 +1,44 @@ +AT_SETUP([compare national]) +export LC_ALL='' + +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 A PIC N VALUE N"あ". + 01 I PIC N VALUE N"い". + 01 X1 PIC N VALUE "丘". + 01 X2 PIC N VALUE "岡". + 01 X3 PIC N VALUE "花". + 01 X4 PIC N VALUE "鼻". + PROCEDURE DIVISION. + IF A = I + DISPLAY "A = I" + ELSE + DISPLAY "A != I" + END-IF. + + IF X1 = X2 + DISPLAY "X1 = X2" + ELSE + DISPLAY "X1 != X2" + END-IF. + + IF X3 = X4 + DISPLAY "X3 = X4" + ELSE + DISPLAY "X3 != X4" + END-IF. + + STOP RUN. +]) + +AT_CHECK([${COBJ} prog.cbl]) +AT_CHECK([${RUN_MODULE} prog], [0], +[A != I +X1 != X2 +X3 != X4 +]) + +AT_CLEANUP diff --git a/tests/cobol_utf8.src/error-print.at b/tests/cobol_utf8.src/error-print.at new file mode 100644 index 00000000..fe3f0718 --- /dev/null +++ b/tests/cobol_utf8.src/error-print.at @@ -0,0 +1,82 @@ +AT_SETUP([undefined not message]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + identification division. + program-id. prog. + data division. + working-storage section. + 01 wk-01. + 03 wk-02 pic x(2). + 03 wk−03 redefines wk-02 pic n(2). + 01 cnt pic 9(1). + procedure division. + inspect wk−03 tallying cnt + for characters before initial space. + stop run. +]) + +AT_CHECK([${COMPILE} -x prog.cob], [1], [], +[prog.cob:8: Error: Size of 'wk_03' larger than size of 'wk-02' +]) + +AT_CLEANUP + +AT_SETUP([Encoding alphanumeric name item]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + PROCEDURE DIVISION. + DISPLAY A___82A0___A. + STOP RUN. +]) + +AT_CHECK([${COMPILE} -x prog.cob], [1], [], +[prog.cob:6: Error: 'A___82A0___A' undefined +]) + +AT_CLEANUP + +AT_SETUP([Encoding national name item]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + PROCEDURE DIVISION. + DISPLAY A___あ___A. + STOP RUN. +]) + +AT_CHECK([${COMPILE} -x prog.cob], [1], [], +[prog.cob:6: Error: 'A___あ___A' undefined +]) + +AT_CLEANUP + +AT_SETUP([Decoding national section name]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + PROCEDURE DIVISION. + テスト SECTION. + MOVE 1 TO 項目1. + テスト段落. + MOVE 1 TO 項目2. +]) + +AT_CHECK([${COMPILE} -x prog.cob], [1], [], +[prog.cob: In section 'テスト': +prog.cob:7: Error: '項目1' undefined +prog.cob: In paragraph 'テスト段落': +prog.cob:9: Error: '項目2' undefined +]) + +AT_CLEANUP diff --git a/tests/cobol_utf8.src/file-handler-japanese.at b/tests/cobol_utf8.src/file-handler-japanese.at new file mode 100644 index 00000000..18a8b71f --- /dev/null +++ b/tests/cobol_utf8.src/file-handler-japanese.at @@ -0,0 +1,26 @@ +AT_SETUP([file-handler-japanese]) +export LC_ALL='' + +# This test verifies that Issue 539 is fixed. + +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT テストファイル + ORGANIZATION IS SEQUENTIAL. + DATA DIVISION. + FILE SECTION. + FD テストファイル. + 01 REC PIC X(10). + PROCEDURE DIVISION. + STOP RUN. +]) + +AT_CHECK([${COBJ} prog.cbl]) +AT_CHECK([grep 'h_テストファイル' prog.java > /dev/null]) +AT_CHECK([grep 'h_ウスエサァイル' prog.java], [1]) + +AT_CLEANUP \ No newline at end of file diff --git a/tests/cobol_utf8.src/japanese-char-section-var.at b/tests/cobol_utf8.src/japanese-char-section-var.at new file mode 100644 index 00000000..2fa32ec8 --- /dev/null +++ b/tests/cobol_utf8.src/japanese-char-section-var.at @@ -0,0 +1,48 @@ +AT_SETUP([japanese word section variable]) +export LC_ALL='' + +AT_DATA([prog.cbl], [ IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 新宿 PIC x(5) VALUE "00000". + 01 横浜−1 PIC x(5) VALUE "11111". + 01 甲府−2 PIC x(5) VALUE "22222". + 01 宇都宮1 PIC x(5) VALUE "33333". + 01 仙台2 PIC x(5) VALUE "44444". + PROCEDURE DIVISION. + 東京ラベル. + DISPLAY 新宿. + 神奈川−1ラベル. + DISPLAY 横浜−1. + 山梨−2ラベル. + DISPLAY 甲府−2. + 栃木1ラベル. + DISPLAY 宇都宮1. + 宮城2ラベル. + DISPLAY 仙台2. +]) + + +AT_CHECK([${COMPILE} prog.cbl]) +AT_CHECK([${RUN_MODULE} prog], [0], +[00000 +11111 +22222 +33333 +44444 +]) +AT_CHECK([cat prog.java | grep "新宿" > /dev/null]) +AT_CHECK([cat prog.java | grep "横浜_1" > /dev/null]) +AT_CHECK([cat prog.java | grep "甲府_2" > /dev/null]) +AT_CHECK([cat prog.java | grep "宇都宮1" > /dev/null]) +AT_CHECK([cat prog.java | grep "仙台2" > /dev/null]) + +AT_CHECK([cat prog.java | grep "東京ラベル" > /dev/null]) +AT_CHECK([cat prog.java | grep "神奈川_1ラベル" > /dev/null]) +AT_CHECK([cat prog.java | grep "山梨_2ラベル" > /dev/null]) +AT_CHECK([cat prog.java | grep "栃木1ラベル" > /dev/null]) +AT_CHECK([cat prog.java | grep "宮城2ラベル" > /dev/null]) + +AT_CLEANUP diff --git a/tests/cobol_utf8.src/java-interface.at b/tests/cobol_utf8.src/java-interface.at new file mode 100644 index 00000000..38f020e2 --- /dev/null +++ b/tests/cobol_utf8.src/java-interface.at @@ -0,0 +1,600 @@ +AT_SETUP([no-argument]) +export LC_ALL='' + +AT_DATA([b.cbl], [ + identification division. + program-id. b. + data division. + linkage section. + procedure division. + display " b". +]) + +AT_DATA([a.java], [ +import jp.osscons.opensourcecobol.libcobj.ui.*; +public class a { + public static void main(String@<:@@:>@ args) { + b prog = new b(); + CobolResultSet rs = prog.execute(); + } +} +]) + +AT_CHECK([cobj b.cbl]) +AT_CHECK([javac a.java]) +AT_CHECK([java a], [0], +[ b +]) + +AT_CLEANUP + +AT_SETUP([PIC 9(3)]) +export LC_ALL='' + +AT_DATA([b.cbl], [ + identification division. + program-id. b. + data division. + linkage section. + 01 arg pic 9(3). + procedure division using arg. + display " arg: " arg. + add 1 to arg. +]) + +AT_DATA([a.java], [ +import jp.osscons.opensourcecobol.libcobj.ui.*; +public class a { + public static void main(String@<:@@:>@ args) { + b prog = new b(); + CobolResultSet rs; + int@<:@@:>@ data_list = {0, 1, 2, 998}; + try{ + for(int data : data_list) { + rs = prog.execute(data); + System.out.println(" arg: " + rs.getInt(1)); + } + } catch(CobolResultSetException e) { + e.printStackTrace(); + } + } +} +]) + +AT_CHECK([cobj b.cbl]) +AT_CHECK([javac a.java]) +AT_CHECK([java a], [0], +[ arg: 000 + arg: 1 + arg: 001 + arg: 2 + arg: 002 + arg: 3 + arg: 998 + arg: 999 +]) + +AT_CLEANUP + +AT_SETUP([PIC S9(3)]) +export LC_ALL='' + +AT_DATA([b.cbl], [ + identification division. + program-id. b. + data division. + linkage section. + 01 arg pic S9(3). + procedure division using arg. + display " arg: " arg. + add 1 to arg. +]) + +AT_DATA([a.java], [ +import jp.osscons.opensourcecobol.libcobj.ui.*; +public class a { + public static void main(String@<:@@:>@ args) { + b prog = new b(); + CobolResultSet rs; + int@<:@@:>@ data_list = {-999, -2, -1, 0, 1, 2, 998}; + try{ + for(int data : data_list) { + rs = prog.execute(data); + System.out.println(" arg: " + rs.getInt(1)); + } + } catch(CobolResultSetException e) { + e.printStackTrace(); + } + } +} +]) + +AT_CHECK([cobj b.cbl]) +AT_CHECK([javac a.java]) +AT_CHECK([java a], [0], +[ arg: -999 + arg: -998 + arg: -002 + arg: -1 + arg: -001 + arg: 0 + arg: +000 + arg: 1 + arg: +001 + arg: 2 + arg: +002 + arg: 3 + arg: +998 + arg: 999 +]) + +AT_CLEANUP + +AT_SETUP([PIC S9(3)V99]) +export LC_ALL='' + +AT_DATA([b.cbl], [ + identification division. + program-id. b. + data division. + linkage section. + 01 arg pic S9(3)V99. + procedure division using arg. + display " arg: " arg. + add 1 to arg. +]) + +AT_DATA([a.java], [ +import jp.osscons.opensourcecobol.libcobj.ui.*; +public class a { + public static void main(String@<:@@:>@ args) { + b prog = new b(); + CobolResultSet rs; + double@<:@@:>@ data_list = {-999.99, -2.01, -1.01, -1.00, 0, 1.01, 2.01, 998.99}; + try{ + for(double data : data_list) { + rs = prog.execute(data); + System.out.println(" arg: " + rs.getDouble(1)); + } + } catch(CobolResultSetException e) { + e.printStackTrace(); + } + } +} +]) + +AT_CHECK([cobj b.cbl]) +AT_CHECK([javac a.java]) +AT_CHECK([java a], [0], +[ arg: -999.99 + arg: -998.99 + arg: -002.01 + arg: -1.01 + arg: -001.01 + arg: -0.01 + arg: -001.00 + arg: 0.0 + arg: +000.00 + arg: 1.0 + arg: +001.01 + arg: 2.01 + arg: +002.01 + arg: 3.01 + arg: +998.99 + arg: 999.99 +]) + +AT_CLEANUP + + +AT_SETUP([PIC 9(3) USAGE COMP-3]) +export LC_ALL='' + +AT_DATA([b.cbl], [ + identification division. + program-id. b. + data division. + linkage section. + 01 arg pic 9(3) USAGE COMP-3. + procedure division using arg. + display " arg: " arg. + add 1 to arg. +]) + +AT_DATA([a.java], [ +import jp.osscons.opensourcecobol.libcobj.ui.*; +public class a { + public static void main(String@<:@@:>@ args) { + b prog = new b(); + CobolResultSet rs; + int@<:@@:>@ data_list = {0, 1, 2, 998}; + try{ + for(int data : data_list) { + rs = prog.execute(data); + System.out.println(" arg: " + rs.getInt(1)); + } + } catch(CobolResultSetException e) { + e.printStackTrace(); + } + } +} +]) + +AT_CHECK([cobj b.cbl]) +AT_CHECK([javac a.java]) +AT_CHECK([java a], [0], +[ arg: 000 + arg: 1 + arg: 001 + arg: 2 + arg: 002 + arg: 3 + arg: 998 + arg: 999 +]) + +AT_CLEANUP + +AT_SETUP([PIC S9(3) USAGE COMP-3]) +export LC_ALL='' + +AT_DATA([b.cbl], [ + identification division. + program-id. b. + data division. + linkage section. + 01 arg pic S9(3) USAGE COMP-3. + procedure division using arg. + display " arg: " arg. + add 1 to arg. +]) + +AT_DATA([a.java], [ +import jp.osscons.opensourcecobol.libcobj.ui.*; +public class a { + public static void main(String@<:@@:>@ args) { + b prog = new b(); + CobolResultSet rs; + int@<:@@:>@ data_list = {-999, -2, -1, 0, 1, 2, 998}; + try{ + for(int data : data_list) { + rs = prog.execute(data); + System.out.println(" arg: " + rs.getInt(1)); + } + } catch(CobolResultSetException e) { + e.printStackTrace(); + } + } +} +]) + +AT_CHECK([cobj b.cbl]) +AT_CHECK([javac a.java]) +AT_CHECK([java a], [0], +[ arg: -999 + arg: -998 + arg: -002 + arg: -1 + arg: -001 + arg: 0 + arg: +000 + arg: 1 + arg: +001 + arg: 2 + arg: +002 + arg: 3 + arg: +998 + arg: 999 +]) + +AT_CLEANUP + +AT_SETUP([PIC S9(3)V99 USAGE COMP-3]) +export LC_ALL='' + +AT_DATA([b.cbl], [ + identification division. + program-id. b. + data division. + linkage section. + 01 arg pic S9(3)V99 USAGE COMP-3. + procedure division using arg. + display " arg: " arg. + add 1 to arg. +]) + +AT_DATA([a.java], [ +import jp.osscons.opensourcecobol.libcobj.ui.*; +public class a { + public static void main(String@<:@@:>@ args) { + b prog = new b(); + CobolResultSet rs; + double@<:@@:>@ data_list = {-999.99, -2.01, -1.01, -1.00, 0, 1.01, 2.01, 998.99}; + try{ + for(double data : data_list) { + rs = prog.execute(data); + System.out.println(" arg: " + rs.getDouble(1)); + } + } catch(CobolResultSetException e) { + e.printStackTrace(); + } + } +} +]) + +AT_CHECK([cobj b.cbl]) +AT_CHECK([javac a.java]) +AT_CHECK([java a], [0], +[ arg: -999.99 + arg: -998.99 + arg: -002.01 + arg: -1.01 + arg: -001.01 + arg: -0.01 + arg: -001.00 + arg: 0.0 + arg: +000.00 + arg: 1.0 + arg: +001.01 + arg: 2.01 + arg: +002.01 + arg: 3.01 + arg: +998.99 + arg: 999.99 +]) + +AT_CLEANUP + +AT_SETUP([PIC X(3)]) +export LC_ALL='' + +AT_DATA([b.cbl], [ + identification division. + program-id. b. + data division. + linkage section. + 01 arg pic X(3). + procedure division using arg. + display " arg: " arg. + MOVE "123" TO arg. +]) + +AT_DATA([a.java], [ +import jp.osscons.opensourcecobol.libcobj.ui.*; +public class a { + public static void main(String@<:@@:>@ args) { + b prog = new b(); + CobolResultSet rs; + try{ + rs = prog.execute("abc"); + System.out.println(" arg: " + rs.getString(1)); + } catch(CobolResultSetException e) { + e.printStackTrace(); + } + } +} +]) + +AT_CHECK([cobj b.cbl]) +AT_CHECK([javac a.java]) +AT_CHECK([java a], [0], +[ arg: abc + arg: 123 +]) + +AT_CLEANUP + +AT_SETUP([Out of range]) +export LC_ALL='' + +AT_DATA([b.cbl], [ + identification division. + program-id. b. + data division. + linkage section. + 01 arg pic 9(3). + procedure division using arg. + add 1 to arg. +]) + +AT_DATA([a.java], [ +import jp.osscons.opensourcecobol.libcobj.ui.*; +public class a { + public static void main(String@<:@@:>@ args) { + b prog = new b(); + CobolResultSet rs; + try{ + rs = prog.execute(0); + System.out.println(" arg: " + rs.getInt(2)); + } catch(CobolResultSetException e) { + e.printStackTrace(); + } + } +} +]) + +AT_CHECK([cobj b.cbl]) +AT_CHECK([javac a.java]) +AT_CHECK([java a 2>&1 | grep 'The index is out of range' > /dev/null], [0]) +AT_CLEANUP + +AT_SETUP([Type mismatch]) +export LC_ALL='' + +AT_DATA([b.cbl], [ + identification division. + program-id. b. + data division. + linkage section. + 01 arg-i pic 9(3). + 01 arg-d pic 9(3)V9. + 01 arg-s pic X(3). + procedure division using arg-i arg-d arg-s. +]) + +AT_DATA([a.java], [ +import jp.osscons.opensourcecobol.libcobj.ui.*; +public class a { + public static void main(String@<:@@:>@ args) { + b prog = new b(); + CobolResultSet rs = prog.execute(1, 1.1, "abc"); + try{ + rs.getDouble(1); + } catch(CobolResultSetException e) { + e.printStackTrace(); + } + try{ + rs.getString(1); + } catch(CobolResultSetException e) { + e.printStackTrace(); + } + try{ + rs.getInt(2); + } catch(CobolResultSetException e) { + e.printStackTrace(); + } + try{ + rs.getString(2); + } catch(CobolResultSetException e) { + e.printStackTrace(); + } + try{ + rs.getInt(3); + } catch(CobolResultSetException e) { + e.printStackTrace(); + } + try{ + rs.getDouble(3); + } catch(CobolResultSetException e) { + e.printStackTrace(); + } + } +} +]) + +AT_CHECK([cobj b.cbl]) +AT_CHECK([javac a.java]) +AT_CHECK([java a 2>&1 | grep 'jp.osscons.opensourcecobol.libcobj.ui.CobolResultSetException'], [0], +[jp.osscons.opensourcecobol.libcobj.ui.CobolResultSetException: The result type is not 'double' +jp.osscons.opensourcecobol.libcobj.ui.CobolResultSetException: The result type is not 'String' +jp.osscons.opensourcecobol.libcobj.ui.CobolResultSetException: The result type is not 'int' +jp.osscons.opensourcecobol.libcobj.ui.CobolResultSetException: The result type is not 'String' +jp.osscons.opensourcecobol.libcobj.ui.CobolResultSetException: The result type is not 'int' +jp.osscons.opensourcecobol.libcobj.ui.CobolResultSetException: The result type is not 'double' +]) +AT_CLEANUP + +AT_SETUP([Japanese]) +export LC_ALL='' + +AT_DATA([b.cbl], [ + identification division. + program-id. b. + data division. + linkage section. + 01 arg-1 pic 9(3). + 01 arg-2 pic N(5). + procedure division using arg-1 arg-2. + display arg-1. + display arg-2. + add 1 to arg-1. + move N"かきくけこ" to arg-2. +]) + +AT_DATA([a.java], [ +import jp.osscons.opensourcecobol.libcobj.ui.*; +public class a { + public static void main(String@<:@@:>@ args) { + b prog = new b(); + CobolResultSet rs = prog.execute(100, "あいうえお"); + try{ + int ret1 = rs.getInt(1); + String ret2 = rs.getString(2); + System.out.println("ret1: " + ret1); + System.out.println("ret2: " + ret2); + } catch(CobolResultSetException e){ + e.printStackTrace(); + } + } +} +]) + +AT_CHECK([cobj b.cbl]) +AT_CHECK([javac -encoding UTF8 a.java]) +AT_CHECK([java -Dfile.encoding=SJIS a > out1.txt]) +AT_CHECK([echo -n '100 +あいうえお +ret1: 101 +ret2: かきくけこ +' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) +AT_CLEANUP + + +AT_SETUP([COMP-3 Integer.MIN_VALUE]) +export LC_ALL='' + +AT_DATA([b.cbl], [ + identification division. + program-id. b. + data division. + linkage section. + 01 k1 pic S9(1) usage comp-3 value zero. + 01 k2 pic S9(2) usage comp-3 value zero. + 01 k3 pic S9(3) usage comp-3 value zero. + 01 k4 pic S9(4) usage comp-3 value zero. + 01 k5 pic S9(5) usage comp-3 value zero. + 01 k6 pic S9(6) usage comp-3 value zero. + 01 k7 pic S9(7) usage comp-3 value zero. + 01 k8 pic S9(8) usage comp-3 value zero. + 01 k9 pic S9(9) usage comp-3 value zero. + 01 k10 pic S9(10) usage comp-3 value zero. + 01 k11 pic S9(11) usage comp-3 value zero. + 01 k12 pic S9(12) usage comp-3 value zero. + 01 k13 pic S9(13) usage comp-3 value zero. + procedure division + using k1 k2 k3 k4 k5 k6 k7 k8 k9 k10 k11 k12 k13. + + display k1. + display k2. + display k3. + display k4. + display k5. + display k6. + display k7. + display k8. + display k9. + display k10. + display k11. + display k12. + display k13. +]) + +AT_DATA([a.java], [ +public class a { + public static void main(String@<:@@:>@ args) { + int v = Integer.MIN_VALUE; + b prog = new b(); + prog.execute(v, v, v, v, v, v, v, v, v, v, v, v, v); + } +} +]) + +AT_CHECK([cobj b.cbl]) +AT_CHECK([javac a.java]) +AT_CHECK([java a], [0], +[-8 +-48 +-648 +-3648 +-83648 +-483648 +-7483648 +-47483648 +-147483648 +-2147483648 +-02147483648 +-002147483648 +-0002147483648 +]) +AT_CLEANUP \ No newline at end of file diff --git a/tests/cobol_utf8.src/limits.at b/tests/cobol_utf8.src/limits.at new file mode 100644 index 00000000..9355959f --- /dev/null +++ b/tests/cobol_utf8.src/limits.at @@ -0,0 +1,289 @@ +AT_SETUP([Field length limit PIC A/VALID]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 VALID-X PIC A(16777216). + PROCEDURE DIVISION. + STOP RUN. +]) + +AT_CHECK([${COMPILE_LIMIT_TEST} prog.cob], [0]) + +AT_CLEANUP + +AT_SETUP([Field length limit PIC A/TOO LONG]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 VALID-X PIC A(16777217). + PROCEDURE DIVISION. + STOP RUN. +]) + +AT_CHECK([${COMPILE_LIMIT_TEST} prog.cob], [1], [], +[prog.cob:6: Error: Alphabetic field cannot be larger than 16777216 digits +]) + +AT_CLEANUP + +AT_SETUP([Field length limit PIC X/VALID]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 VALID-X PIC X(16777216). + PROCEDURE DIVISION. + STOP RUN. +]) + +AT_CHECK([${COMPILE_LIMIT_TEST} prog.cob], [0]) + +AT_CLEANUP + +AT_SETUP([Field length limit PIC X/TOO LONG]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 VALID-X PIC X(16777217). + PROCEDURE DIVISION. + STOP RUN. +]) + +AT_CHECK([${COMPILE_LIMIT_TEST} prog.cob], [1], [], +[prog.cob:6: Error: AlphaNumeric field cannot be larger than 16777216 digits +]) + +AT_CLEANUP + +AT_SETUP([Field length limit PIC B9/VALID]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 VALID-X PIC B9(159). + PROCEDURE DIVISION. + STOP RUN. +]) + +AT_CHECK([${COMPILE_LIMIT_TEST} prog.cob], [0]) + +AT_CLEANUP + +AT_SETUP([Field length limit PIC B9/TOO LONG]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 VALID-X PIC B9(160). + PROCEDURE DIVISION. + STOP RUN. +]) + +AT_CHECK([${COMPILE_LIMIT_TEST} prog.cob], [1], [], +[prog.cob:6: Error: NumericEdit field cannot be larger than 160 digits +]) + +AT_CLEANUP + +AT_SETUP([Field length limit PIC B/VALID]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 VALID-X PIC B(16777216). + PROCEDURE DIVISION. + STOP RUN. +]) + +AT_CHECK([${COMPILE_LIMIT_TEST} prog.cob], [0]) + +AT_CLEANUP + +AT_SETUP([Field length limit PIC B/TOO LONG]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 VALID-X PIC B(16777217). + PROCEDURE DIVISION. + STOP RUN. +]) + +AT_CHECK([${COMPILE_LIMIT_TEST} prog.cob], [1], [], + +[prog.cob:6: Error: AlphaNumericEdit field cannot be larger than 16777216 digits +]) + +AT_CLEANUP + +AT_SETUP([Field length limit PIC BA/VALID]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 VALID-X PIC BA(16777215). + PROCEDURE DIVISION. + STOP RUN. +]) + +AT_CHECK([${COMPILE_LIMIT_TEST} prog.cob], [0]) + +AT_CLEANUP + +AT_SETUP([Field length limit PIC BA/TOO LONG]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 VALID-X PIC BA(16777216). + PROCEDURE DIVISION. + STOP RUN. +]) + +AT_CHECK([${COMPILE_LIMIT_TEST} prog.cob], [1], [], +[prog.cob:6: Error: AlphaNumericEdit field cannot be larger than 16777216 digits +]) + +AT_CLEANUP + +AT_SETUP([Field length limit PIC BX/VALID]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 VALID-X PIC BX(16777215). + PROCEDURE DIVISION. + STOP RUN. +]) + +AT_CHECK([${COMPILE_LIMIT_TEST} prog.cob], [0]) + +AT_CLEANUP + +AT_SETUP([Field length limit PIC BX/TOO LONG]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 VALID-X PIC BX(16777216). + PROCEDURE DIVISION. + STOP RUN. +]) + +AT_CHECK([${COMPILE_LIMIT_TEST} prog.cob], [1], [], +[prog.cob:6: Error: AlphaNumericEdit field cannot be larger than 16777216 digits +]) + +AT_CLEANUP + +AT_SETUP([Field length limit PIC N/VALID (SJIS)]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 VALID-N PIC N(8388608). + PROCEDURE DIVISION. + STOP RUN. +]) + +AT_CHECK([${COMPILE_LIMIT_TEST} prog.cob], [0]) + +AT_CLEANUP + +AT_SETUP([Field length limit PIC N/TOO LONG (SJIS)]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 INVALID-N PIC N(8388609). + PROCEDURE DIVISION. + STOP RUN. +]) + +AT_CHECK([${COMPILE_LIMIT_TEST} prog.cob], [1], [], +[prog.cob:6: Error: National field cannot be larger than 8388608 digits +]) + +AT_CLEANUP + +AT_SETUP([Field length limit PIC BN/VALID (SJIS)]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 VALID-BN PIC BN(8388607). + PROCEDURE DIVISION. + STOP RUN. +]) + +AT_CHECK([${COMPILE_LIMIT_TEST} prog.cob], [0]) + +AT_CLEANUP + +AT_SETUP([Field length limit PIC BN/TOO LONG (SJIS)]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 INVALID-BN PIC BN(8388608). + PROCEDURE DIVISION. + STOP RUN. +]) + +AT_CHECK([${COMPILE_LIMIT_TEST} prog.cob], [1], [], +[prog.cob:6: Error: NationalEdit field cannot be larger than 8388608 digits +]) + +AT_CLEANUP + diff --git a/tests/cobol_utf8.src/mb-space.at b/tests/cobol_utf8.src/mb-space.at new file mode 100644 index 00000000..869e87f1 --- /dev/null +++ b/tests/cobol_utf8.src/mb-space.at @@ -0,0 +1,71 @@ +AT_SETUP([Zenkaku SPC delims in headings]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA       DIVISION. + WORKING-STORAGE  SECTION. + 01 項目 PIC X. + PROCEDURE   DIVISION. + DISPLAY "OK" WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([${COMPILE} prog.cob]) +AT_CHECK([java prog], [0], [OK]) + +AT_CLEANUP + +AT_SETUP([Zenkaku SPC delims in record def]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 項目 PIC X(40) VALUE + "Zen SPC between item name and PIC clause". +  01 F00 PIC X. +   01 F01 PIC X. + 01 F02 PIC X. + 01 F03 PIC X. + 01 F04 PIC X . + PROCEDURE DIVISION. + DISPLAY 項目 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([${COMPILE} prog.cob]) +AT_CHECK([java prog], [0], [Zen SPC between item name and PIC clause]) + +AT_CLEANUP + +AT_SETUP([Zenkaku SPC delims in COPY stmt]) +export LC_ALL='' + +AT_DATA([inc.cpy], [ + 01 項目 PIC X(2) VALUE "OK". +  01 F00 PIC X. +   01 F01 PIC X. + 01 F02 PIC X. + 01 F03 PIC X. + 01 F04 PIC X . +]) + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + COPY  inc. + PROCEDURE DIVISION. + DISPLAY 項目 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([${COMPILE} prog.cob]) +AT_CHECK([java prog], [0], [OK]) + +AT_CLEANUP diff --git a/tests/cobol_utf8.src/national.at b/tests/cobol_utf8.src/national.at new file mode 100644 index 00000000..2f8a8e65 --- /dev/null +++ b/tests/cobol_utf8.src/national.at @@ -0,0 +1,271 @@ +AT_SETUP([FUNCTION NATIONAL single-byte]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 I-STR PIC X(5). + 01 O-STR PIC X(10). + PROCEDURE DIVISION. + MOVE "ABCDZ" TO I-STR. + MOVE FUNCTION NATIONAL(I-STR) TO O-STR. + DISPLAY O-STR WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj ${FLAGS_JP_COMPAT} prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n 'ABCDZ'| nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([FUNCTION NATIONAL multi-byte]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 I-STR PIC X(9). + 01 O-STR PIC X(12). + PROCEDURE DIVISION. + MOVE "ABC123" TO I-STR. + MOVE FUNCTION NATIONAL(I-STR) TO O-STR. + DISPLAY O-STR WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj ${FLAGS_JP_COMPAT} prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n 'ABC123'| nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + + +AT_CLEANUP + +AT_SETUP([FUNCTION NATIONAL KIGOU-exclamation]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 I-STR PIC X(5). + 01 O-STR PIC X(10). + PROCEDURE DIVISION. + MOVE "!!!!!" TO I-STR. + MOVE FUNCTION NATIONAL(I-STR) TO O-STR. + DISPLAY O-STR WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj ${FLAGS_JP_COMPAT} prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '!!!!!' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([FUNCTION NATIONAL KIGOU-yen]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 I-STR PIC X(1). + 01 O-STR PIC X(10). + PROCEDURE DIVISION. + MOVE "¥" TO I-STR. + MOVE FUNCTION NATIONAL(I-STR) TO O-STR. + DISPLAY O-STR WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj ${FLAGS_JP_COMPAT} prog.cob], [0], [], +[prog.cob:9: Warning: Value size exceeds data size +prog.cob:6: Warning: 'I-STR' defined here as PIC X(1) +]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '¥ ' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([FUNCTION NATIONAL KIGOU-plus]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 I-STR PIC X(2). + 01 O-STR PIC X(10). + PROCEDURE DIVISION. + MOVE "+ " TO I-STR. + MOVE FUNCTION NATIONAL(I-STR) TO O-STR. + DISPLAY O-STR WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj ${FLAGS_JP_COMPAT} prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '+  ' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([FUNCTION NATIONAL (HanKana w/ Daku-on)]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 I-STR PIC X(16). + 01 O-STR PIC X(16). + PROCEDURE DIVISION. + MOVE "レディガガ" TO I-STR. + MOVE FUNCTION NATIONAL(I-STR) TO O-STR. + DISPLAY O-STR WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj ${FLAGS_JP_COMPAT} prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n 'レディガガ   ' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([FUNCTION NATIONAL (HanKana w/ Han-daku-on)]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 I-STR PIC X(10). + 01 O-STR PIC X(10). + PROCEDURE DIVISION. + MOVE "ポピン" TO I-STR. + MOVE FUNCTION NATIONAL(I-STR) TO O-STR. + DISPLAY O-STR WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj ${FLAGS_JP_COMPAT} prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n 'ポピン  ' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([N Literal (NO zenakaku conversion)]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + PROCEDURE DIVISION. + DISPLAY N"いろは". + DISPLAY N"イロハ". + DISPLAY N"ポピン". + DISPLAY N"ABC". + DISPLAY N"#$%". + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n 'いろは +イロハ +ポピン +ABC +#$% +'| nkf -x --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([NC Literal (NO zenakaku conversion)]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + PROCEDURE DIVISION. + DISPLAY NC"いろは". + DISPLAY NC"イロハ". + DISPLAY NC"ポピン". + DISPLAY NC"ABC". + DISPLAY NC"#$%". + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n 'いろは +イロハ +ポピン +ABC +#$% +'| nkf -x --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([ND Literal (NO zenakaku conversion)]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + PROCEDURE DIVISION. + DISPLAY ND"いろは". + DISPLAY ND"イロハ". + DISPLAY ND"ポピン". + DISPLAY ND"ABC". + DISPLAY ND"#$%". + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n 'いろは +イロハ +ポピン +ABC +#$% +'| nkf -x --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([NX Literal]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + PROCEDURE DIVISION. + DISPLAY NX"E38184E3828DE381AF". + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n 'いろは +' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP diff --git a/tests/cobol_utf8.src/pic-n.at b/tests/cobol_utf8.src/pic-n.at new file mode 100644 index 00000000..95c108af --- /dev/null +++ b/tests/cobol_utf8.src/pic-n.at @@ -0,0 +1,559 @@ +AT_SETUP([PIC N Value clause]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC N(7) VALUE "日本語の文字列". + PROCEDURE DIVISION. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '日本語の文字列' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([PIC N Move]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC N(7). + PROCEDURE DIVISION. + MOVE "日本語の文字列" TO F0. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '日本語の文字列' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([PIC N Move with trunc]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC N(3). + PROCEDURE DIVISION. + MOVE "日本語の文字列" TO F0. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '日本語' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([PIC N Move with padding by full-width SPC]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC N(9). + PROCEDURE DIVISION. + MOVE "日本語の文字列" TO F0. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '日本語の文字列  ' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([PIC N Move with justify]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC N(9) JUSTIFIED RIGHT. + PROCEDURE DIVISION. + MOVE "日本語の文字列" TO F0. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '  日本語の文字列' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([PIC N EDITED w/ VALUE]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC NN/NNBNN0 VALUE '日本/中国 文字0'. + PROCEDURE DIVISION. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '日本/中国 文字0' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([INITIALIZE PIC N EDITED]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC NN/NNBNN0 VALUE '日本/中国 文字0'. + PROCEDURE DIVISION. + MOVE "春夏秋冬寒暖" TO F0. + INITIALIZE F0. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '  /     0' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([INITIALIZE PIC N EDITED TO VALUE]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC NN/NNBNN0 VALUE '日本/中国 文字0'. + PROCEDURE DIVISION. + MOVE "春夏秋冬寒暖" TO F0. + INITIALIZE F0 NATIONAL TO VALUE. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '日本/中国 文字0' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([PIC N Move to NATIONAL EDITED]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC NN/NNBNN0. + PROCEDURE DIVISION. + MOVE "日本中国文字" TO F0. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '日本/中国 文字0' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([PIC N Move with half-width alnum conv.]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC N(7). + PROCEDURE DIVISION. + MOVE "ABC0123" TO F0. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n 'ABC0123' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([PIC N Move with half-width kana conv.]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC N(7). + PROCEDURE DIVISION. + MOVE "コメダコーヒー" TO F0. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob], [0]) +AT_CHECK([java prog | od -tx1 -An | sed -e 's/ */ /g' -e 's/ *$//'], [0], [ 83 52 83 81 83 5f 83 52 81 5b 83 71 81 5b +]) + +AT_CLEANUP + +AT_SETUP([PIC N Ref mod(n:)]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC N(7). + PROCEDURE DIVISION. + MOVE "日本語の文字列" TO F0. + DISPLAY F0(5:) WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '文字列' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([PIC N Ref mod(n:m)]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC N(7). + PROCEDURE DIVISION. + MOVE "日本語の文字列" TO F0. + DISPLAY F0(5:2) WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '文字' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([PIC N STRING by size]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC N(2) VALUE "私の". + 01 F1 PIC N(3) VALUE "名前は". + 01 F2 PIC N(5) VALUE "ありません". + 01 FF PIC N(10). + PROCEDURE DIVISION. + STRING F0 F1 F2 DELIMITED BY SIZE + INTO FF. + DISPLAY FF WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '私の名前はありません' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([PIC N STRING with delimiter (causes warn)]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC N(2) VALUE "私の". + 01 F1 PIC N(4) VALUE "名前△は". + 01 F2 PIC N(6) VALUE "△ありません". + 01 FF PIC N(4). + PROCEDURE DIVISION. + STRING F0 F1 F2 DELIMITED BY "△" + INTO FF. + DISPLAY FF WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '私の名前' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([PIC N STRING with NATIONAL delimiter]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC N(2) VALUE "私の". + 01 F1 PIC N(4) VALUE "名前△は". + 01 F2 PIC N(6) VALUE "△ありません". + 01 FF PIC N(4). + PROCEDURE DIVISION. + STRING F0 F1 F2 DELIMITED BY N"△" + INTO FF. + DISPLAY FF WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '私の名前' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([PIC N STRING with pointer]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC N(2) VALUE "私の". + 01 F1 PIC N(3) VALUE "名前は". + 01 F2 PIC N(5) VALUE "ありません". + 01 FF PIC N(10) VALUE "言えません○※△■×". + 01 FP PIC 99 VALUE 6. + PROCEDURE DIVISION. + STRING F0 F1 F2 DELIMITED BY SIZE + INTO FF WITH POINTER FP. + DISPLAY FF WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '言えません私の名前は' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([PIC N INSPECT REPLACING]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC N(10) VALUE "1234512345". + PROCEDURE DIVISION. + INSPECT F0 REPLACING ALL "5" BY "0". + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '1234012340' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([PIC N INSPECT REPLACING by ZERO]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC N(10) VALUE "1234512345". + PROCEDURE DIVISION. + INSPECT F0 REPLACING ALL "5" BY ZERO. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '1234012340' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([PIC N INSPECT REPLACING by NATIONAL ZERO]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC N(10) VALUE "1234512345". + PROCEDURE DIVISION. + INSPECT F0 REPLACING ALL N"5" BY ZERO. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '1234012340' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([PIC N INSPECT TALLYING]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC N(10) VALUE "1234512345". + 01 CN PIC 99. + PROCEDURE DIVISION. + INSPECT F0 TALLYING CN FOR ALL "45". + DISPLAY CN WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '02' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([PIC N Move with half-width dakuten kana.]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC N(7). + PROCEDURE DIVISION. + MOVE "゙ダ・ヴィンチ" TO F0. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '゛ダ・ヴィンチ' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([PIC N Move with half-width han-dakuten kana.]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC N(7). + PROCEDURE DIVISION. + MOVE "゚ポンデリング" TO F0. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '゜ポンデリング' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([PIC N WRITE FROM Japanese literal]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT TEST-FILE ASSIGN TO "TESTFILE" + ORGANIZATION IS SEQUENTIAL. + DATA DIVISION. + FILE SECTION. + FD TEST-FILE. + 01 TEST-DATA PIC N(18). + WORKING-STORAGE SECTION. + PROCEDURE DIVISION. + OPEN OUTPUT TEST-FILE. + WRITE TEST-DATA FROM "縄文弥生古墳飛鳥奈良平安鎌倉室町江戸". + CLOSE TEST-FILE. + + OPEN INPUT TEST-FILE. + READ TEST-FILE + NOT AT END + DISPLAY TEST-DATA + END-READ. + CLOSE TEST-FILE. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '縄文弥生古墳飛鳥奈良平安鎌倉室町江戸 +' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP diff --git a/tests/cobol_utf8.src/pic-x.at b/tests/cobol_utf8.src/pic-x.at new file mode 100644 index 00000000..978c6b0c --- /dev/null +++ b/tests/cobol_utf8.src/pic-x.at @@ -0,0 +1,696 @@ +AT_SETUP([Value clause]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC X(14) VALUE "日本語の文字列". + PROCEDURE DIVISION. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob 2> /dev/null]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n 日本語の文字列 | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([Move]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC X(14). + PROCEDURE DIVISION. + MOVE "日本語の文字列" TO F0. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n 日本語の文字列 | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([Move with trunc]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC X(6). + PROCEDURE DIVISION. + MOVE "日本語の文字列" TO F0. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n 日本語 | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([Move ALL with trunc and trimming]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC X(7). + PROCEDURE DIVISION. + MOVE ALL "喜" TO F0. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob], [0]) +AT_CHECK([java prog | od -tx1 -An | sed -e 's/ */ /g' -e 's/ *$//'], [0], [ 8a ec 8a ec 8a ec 20 +]) + +AT_CLEANUP + +AT_SETUP([Move with trunc and trimming 1]) +export LC_ALL='' +AT_CHECK([${SKIP_TEST}]) + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC X(7). + PROCEDURE DIVISION. + MOVE "日本語の文字列" TO F0. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog | od -tx1 -An | sed -e 's/ */ /g' -e 's/ *$//'], [0], [ 93 fa 96 7b 8c ea 82 +]) + +AT_CLEANUP + +AT_SETUP([Move from field with trunc and trimming 1]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 FS PIC X(14) VALUE "日本語の文字列". + 01 F0 PIC X(7). + PROCEDURE DIVISION. + MOVE FS TO F0. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob], [0]) +AT_CHECK([java prog | od -tx1 -An | sed -e 's/ */ /g' -e 's/ *$//'], [0], [ 93 fa 96 7b 8c ea 82 +]) + +AT_CLEANUP + +AT_SETUP([Move with padding]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC X(16). + PROCEDURE DIVISION. + MOVE "日本語の文字列" TO F0. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '日本語の文字列 ' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([Move with justify]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC X(15) JUSTIFIED RIGHT. + PROCEDURE DIVISION. + MOVE "日本語の文字列" TO F0. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n ' 日本語の文字列' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([Move to alnum EDITED]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC XXXX/XXXXBXXXX0. + PROCEDURE DIVISION. + MOVE "日本中国文字" TO F0. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '日本/中国 文字0' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([Move to alnum EDITED (pic too short)]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC XX/XXBXX0. + PROCEDURE DIVISION. + MOVE "日本中国文字" TO F0. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '日/本 中0' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([Move to alnum EDITED (pic too long)]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC XX/XXBXX0. + PROCEDURE DIVISION. + MOVE "日本" TO F0. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '日/本 0' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([Move to alnum EDITED (No char break)]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC X(2)BX(2). + PROCEDURE DIVISION. + MOVE "日本" TO F0. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '日 本' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([Move to alnum EDITED (char break & junk chars)]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC X(1)BX(3). + PROCEDURE DIVISION. + MOVE "日本" TO F0. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob], [0]) +AT_CHECK([java prog | od -tx1 -An | sed -e 's/ */ /g' -e 's/ *$//'], [0], [ 93 20 fa 96 7b +]) + +AT_CLEANUP + +AT_SETUP([Move group to group in bad alignment]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0. + 03 XX0 PIC X(4) VALUE "日本". + 01 F1. + 03 XX1 PIC X(3). + 03 FILLER PIC X(1). + + PROCEDURE DIVISION. + MOVE F0 TO F1. + DISPLAY XX1 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob], [0]) +AT_CHECK([java prog | od -tx1 -An | sed -e 's/ */ /g' -e 's/ *$//'], [0], [ 93 fa 96 +]) + +AT_CLEANUP + +AT_SETUP([Redifinition breaking char pos.]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0. + 03 XX0 PIC X(4) VALUE "日本". + 01 F1 REDEFINES F0. + 03 XX1 PIC X(3). + 03 FILLER PIC X(1). + + PROCEDURE DIVISION. + DISPLAY XX1 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob], [0]) +AT_CHECK([java prog | od -tx1 -An | sed -e 's/ */ /g' -e 's/ *$//'], [0], [ 93 fa 96 +]) + +AT_CLEANUP + + +AT_SETUP([Ref mod(n:)]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC X(14). + PROCEDURE DIVISION. + MOVE "日本語の文字列" TO F0. + DISPLAY F0(9:) WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '文字列' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([Ref mod(n:m)]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC X(14). + PROCEDURE DIVISION. + MOVE "日本語の文字列" TO F0. + DISPLAY F0(9:4) WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '文字' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([STRING by size]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC X(4) VALUE "私の". + 01 F1 PIC X(6) VALUE "名前は". + 01 F2 PIC X(10) VALUE "ありません". + 01 FF PIC X(20). + PROCEDURE DIVISION. + STRING F0 F1 F2 DELIMITED BY SIZE + INTO FF. + DISPLAY FF WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '私の名前はありません' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([STRING with delimiter]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC X(4) VALUE "私の". + 01 F1 PIC X(8) VALUE "名前△は". + 01 F2 PIC X(12) VALUE "△ありません". + 01 FF PIC X(8). + PROCEDURE DIVISION. + STRING F0 F1 F2 DELIMITED BY "△" + INTO FF. + DISPLAY FF WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '私の名前' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([STRING with pointer]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC X(4) VALUE "私の". + 01 F1 PIC X(6) VALUE "名前は". + 01 F2 PIC X(10) VALUE "ありません". + 01 FF PIC X(20) VALUE "言えません○※△■×". + 01 FP PIC 99 VALUE 11. + PROCEDURE DIVISION. + STRING F0 F1 F2 DELIMITED BY SIZE + INTO FF WITH POINTER FP. + DISPLAY FF WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '言えません私の名前は' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([INSPECT REPLACING]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC X(20) VALUE "1234512345". + PROCEDURE DIVISION. + INSPECT F0 REPLACING ALL "5" BY "0". + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '1234012340' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([INSPECT REPLACING by ZERO]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC X(20) VALUE "1234512345". + PROCEDURE DIVISION. + INSPECT F0 REPLACING ALL "5" BY ZERO. + DISPLAY F0 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '1234012340' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([INSPECT TALLYING]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC X(30) VALUE "1234512345". + 01 CN PIC 99. + PROCEDURE DIVISION. + INSPECT F0 TALLYING CN FOR ALL "45". + DISPLAY CN WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '02' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([WRITE FROM Japanese literal]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT TEST-FILE ASSIGN TO "TESTFILE" + ORGANIZATION IS SEQUENTIAL. + DATA DIVISION. + FILE SECTION. + FD TEST-FILE. + 01 TEST-DATA PIC X(36). + WORKING-STORAGE SECTION. + PROCEDURE DIVISION. + OPEN OUTPUT TEST-FILE. + WRITE TEST-DATA FROM "縄文弥生古墳飛鳥奈良平安鎌倉室町江戸". + CLOSE TEST-FILE. + + OPEN INPUT TEST-FILE. + READ TEST-FILE + NOT AT END + DISPLAY TEST-DATA + END-READ. + CLOSE TEST-FILE. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n '縄文弥生古墳飛鳥奈良平安鎌倉室町江戸 +' | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([Group item COB_TERMINAL_ENCODING]) + +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 WK-AREA. + 03 WK-CD PIC X(04). + 03 WK-NAME PIC X(20). + 03 WK-DPT-CD PIC X(02). + 03 WK-ENT-DATE PIC 9(08). + 03 WK-RETURN PIC 9(01). + PROCEDURE DIVISION. + MAIN. + MOVE "0012千葉 二郎 02199904010" TO WK-AREA. + DISPLAY "従業員番号: " WK-CD. + DISPLAY "名前   : " WK-NAME. + DISPLAY "部署コード: " WK-DPT-CD. + DISPLAY "入社日  : " WK-ENT-DATE. + STOP RUN. +]) + +AT_CHECK([cobj prog.cbl]) +AT_CHECK([COB_TERMINAL_ENCODING=UTF-8 java prog], [0], +[従業員番号: 0012 +名前   : 千葉 二郎 @&t@ +部署コード: 02 +入社日  : 19990401 +]) + +AT_CLEANUP + +AT_SETUP([Initializing Group items]) + +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC X(17) VALUE "千葉 二郎". + PROCEDURE DIVISION. + DISPLAY F0. + STOP RUN. +]) + +AT_CHECK([cobj prog.cbl]) +AT_CHECK([COB_TERMINAL_ENCODING=UTF-8 java prog], [0], +[千葉 二郎 @&t@ +]) + +AT_CLEANUP + +AT_SETUP([Exceed column 72 with Japanese literal]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 str PIC X(5) VALUE 'アイウエオ'. + PROCEDURE DIVISION. + DISPLAY str. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog > out1.txt]) +AT_CHECK([echo -n 'アイウエオ +' | nkf -x --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +#AT_SETUP([Readable string literals]) +#export LC_ALL='' +## Older compilers converts string literals "日本語" in COBOL source code +## to `CobolUtil.toBytes((byte)0x93, (byte)0xfa, (byte)0x96, (byte)0x7b, (byte)0x8c, (byte)0xea)` in Java source code. +## The following tests check that the compiler converts the string literals to readable ones. +# +#AT_DATA([prog1.cob], [ +# IDENTIFICATION DIVISION. +# PROGRAM-ID. prog1. +# DATA DIVISION. +# WORKING-STORAGE SECTION. +# 01 F0 PIC X(30) VALUE "東京1". +# PROCEDURE DIVISION. +# MOVE "東京2" TO F0. +# DISPLAY "東京3". +#]) +# +#AT_CHECK([cobj prog1.cob]) +#AT_CHECK([grep '東京1' < prog1.java > /dev/null]) +#AT_CHECK([grep '東京2' < prog1.java > /dev/null]) +#AT_CHECK([grep '東京3' < prog1.java > /dev/null]) +# +## ' ' is the first multi-byte Shift-JIS character with respect to the byte order +## see http://charset.7jp.net/sjis.html +#AT_DATA([prog2.cob], [ +# IDENTIFICATION DIVISION. +# PROGRAM-ID. prog2. +# DATA DIVISION. +# WORKING-STORAGE SECTION. +# 01 F0 PIC X(30) VALUE " 1". +# PROCEDURE DIVISION. +# MOVE " 2" TO F0. +# DISPLAY " 3". +#]) +# +#AT_CHECK([cobj prog2.cob]) +#AT_CHECK([grep ' 1' < prog2.java > /dev/null]) +#AT_CHECK([grep ' 2' < prog2.java > /dev/null]) +#AT_CHECK([grep ' 3' < prog2.java > /dev/null]) +# +## '熙' is the last printable Shift-JIS character with respect to the byte order. +## See http://charset.7jp.net/sjis.html +#AT_DATA([prog3.cob], [ +# IDENTIFICATION DIVISION. +# PROGRAM-ID. prog3. +# DATA DIVISION. +# WORKING-STORAGE SECTION. +# 01 F0 PIC X(30) VALUE "熙1". +# PROCEDURE DIVISION. +# MOVE "熙2" TO F0. +# DISPLAY "熙3". +#]) +# +#AT_CHECK([cobj prog3.cob]) +#AT_CHECK([grep '熙1' < prog3.java > /dev/null]) +#AT_CHECK([grep '熙2' < prog3.java > /dev/null]) +#AT_CHECK([grep '熙3' < prog3.java > /dev/null]) +# +#AT_CLEANUP \ No newline at end of file diff --git a/tests/cobol_utf8.src/program-id.at b/tests/cobol_utf8.src/program-id.at new file mode 100644 index 00000000..14ddc3f5 --- /dev/null +++ b/tests/cobol_utf8.src/program-id.at @@ -0,0 +1,94 @@ +AT_SETUP([PROGRAM-ID NATIONAL C89 no warning]) +export LC_ALL='' + +AT_DATA([test.conf], [ +include "default.conf" +c89-identifier-length-check: yes +]) + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. 東京都. + DATA DIVISION. + PROCEDURE DIVISION. + END PROGRAM 東京都. +]) + +AT_CHECK([${COMPILE} -conf=test.conf prog.cob], [0]) + +AT_CLEANUP + + +AT_SETUP([PROGRAM-ID NATIONAL C89 warning]) +export LC_ALL='' +AT_CHECK([${SKIP_TEST}]) +AT_DATA([test.conf], [ +include "default.conf" +c89-identifier-length-check: yes +]) + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. 東京湾岸港湾局. + DATA DIVISION. + PROCEDURE DIVISION. + END PROGRAM 東京湾岸港湾局. +]) + +AT_CHECK([${COMPILE} -conf=test.conf prog.cob], [0], [], +[prog.cob:3: Warning: PROGRAM-ID length exceeds C89 function name limit +prog.cob:6: Warning: PROGRAM-ID length exceeds C89 function name limit +]) + +AT_CLEANUP + +AT_SETUP([PROGRAM-ID NATIONAL C89 ignore]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. 東京湾岸港湾局. + DATA DIVISION. + PROCEDURE DIVISION. + END PROGRAM 東京湾岸港湾局. +]) + +AT_CHECK([${COMPILE} prog.cob], [0]) + + +AT_CLEANUP + +AT_SETUP([PROGRAM-ID NATIONAL 32 character no over]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. あいうえおかきくけこさしすせそ + -たちつてとなにぬねのはひふへほ. + DATA DIVISION. + PROCEDURE DIVISION. + STOP RUN. +]) + +AT_CHECK([${COMPILE} prog.cob], [0]) + +AT_CLEANUP + +AT_SETUP([PROGRAM-ID NATIONAL 32 character over]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. あいうえおかきくけこさしすせそ + -たちつてとなにぬねのはひふへほまみ. + DATA DIVISION. + PROCEDURE DIVISION. + STOP RUN. +]) + +AT_CHECK([${COMPILE} prog.cob], [1], [], +[prog.cob:3: Error: User defined name must be less than 32 characters +]) + +AT_CLEANUP + diff --git a/tests/cobol_utf8.src/user-defined-word.at b/tests/cobol_utf8.src/user-defined-word.at new file mode 100644 index 00000000..36f0ccbd --- /dev/null +++ b/tests/cobol_utf8.src/user-defined-word.at @@ -0,0 +1,515 @@ +AT_SETUP([Program name]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. 日本語のプログラム名. + PROCEDURE DIVISION. + STOP RUN. +]) + +AT_CHECK([${COMPILE} prog.cob]) + +AT_CLEANUP + +AT_SETUP([Field name]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 O−文字列 PIC X(7) USAGE DISPLAY. + PROCEDURE DIVISION. + MOVE "Unicode" TO O−文字列. + DISPLAY O−文字列 WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([${COMPILE} prog.cob]) +AT_CHECK([java prog], [0], [Unicode]) + +AT_CLEANUP + +AT_SETUP([Long field name]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 項目ABCDEFGH012345 + PIC X(7). + PROCEDURE DIVISION. + MOVE "Unicode" + TO + 項目ABCDEFGH012345. + DISPLAY + 項目ABCDEFGH012345 + WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([${COMPILE} prog.cob]) +AT_CHECK([java prog], [0], [Unicode]) + +AT_CLEANUP + + +AT_SETUP([Field lookup]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 項目2 PIC X(1) VALUE "A". + 01 項目R PIC X(1) VALUE "B". + PROCEDURE DIVISION. + DISPLAY 項目2 項目R WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([${COMPILE} prog.cob]) +AT_CHECK([java prog], [0], [AB]) + +AT_CLEANUP + +AT_SETUP([Section name]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + PROCEDURE DIVISION. + PERFORM S−初期化. + PERFORM S−終了. + S−初期化 SECTION. + DISPLAY "Hello, " WITH NO ADVANCING. + S−終了 SECTION. + DISPLAY "and good bye." WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([${COMPILE} prog.cob]) +AT_CHECK([java prog], [0], [Hello, and good bye.]) + +AT_CLEANUP + +AT_SETUP([Long section name]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + PROCEDURE DIVISION. + PERFORM s12345678901234567890. + PERFORM S−終了. + s12345678901234567890 SECTION. + DISPLAY "Hello, " WITH NO ADVANCING. + S−終了 SECTION. + DISPLAY "and good bye." WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([${COMPILE} prog.cob]) +AT_CHECK([java prog], [0], [Hello, and good bye.]) + +AT_CLEANUP + +AT_SETUP([Too long section name]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + PROCEDURE DIVISION. + PERFORM s1234567890123456789012345678901. + PERFORM S−終了. + s1234567890123456789012345678901 SECTION. + DISPLAY "Hello, " WITH NO ADVANCING. + S−終了 SECTION. + DISPLAY "and good bye." WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([${COMPILE} prog.cob], [1], [], +[prog.cob:7: Error: User defined name must be less than 32 characters +prog.cob:9: Error: User defined name must be less than 32 characters +]) + +AT_CLEANUP + +AT_SETUP([Nihongo Filename]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT テストファイル ASSIGN TO "./テスト_ファイル" + ORGANIZATION IS INDEXED + ACCESS MODE IS SEQUENTIAL + RECORD KEY IS TEST-KEY. + DATA DIVISION. + FILE SECTION. + FD テストファイル. + 01 TEST-KEY PIC X(10). + PROCEDURE DIVISION. + OPEN OUTPUT テストファイル. + MOVE "TEST000000" TO TEST-KEY. + WRITE TEST-KEY. + CLOSE テストファイル. + OPEN INPUT テストファイル. + READ テストファイル + NOT AT END + DISPLAY "OK" NO ADVANCING + END-READ. + CLOSE テストファイル. + STOP RUN. +]) + +AT_CHECK([${COMPILE} prog.cob]) +AT_CHECK([java prog], [0], [OK]) + +AT_CLEANUP + +AT_SETUP([Nihongo field name in numeric test msg.]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 TEST-REC. + 03 U項目 PIC 9(4) VALUE 1000. + 01 X項目 PIC X(4) VALUE 'ABCD'. + PROCEDURE DIVISION. + MOVE X項目 TO TEST-REC. + ADD 1 TO U項目. + GOBACK. +]) + +AT_CHECK([${COMPILE} -debug prog.cob]) +AT_CHECK([java prog 2> out1.txt], [1]) +AT_CHECK([echo "prog.cob:11: libcobj: 'U項目' not numeric: 'ABCD'" | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([Nihongo field name in BASED test msg.]) +export LC_ALL='' +AT_CHECK([${SKIP_TEST}]) + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 X項目 PIC X(4) VALUE 'ABCD'. + 01 Y項目 PIC X(4) BASED. + PROCEDURE DIVISION. + MOVE X項目 TO Y項目. + GOBACK. +]) + +AT_CHECK([${COMPILE} -debug prog.cob]) + +AT_CHECK([java prog 2> out1.txt], [1]) +AT_CHECK([echo "prog.cob:9: libcobj: BASED/LINKAGE item 'Y項目' has NULL address" | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([Nihongo field name in ODO test msg.]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 I項目 PIC 9 VALUE 4. + 01 X. + 03 Y項目 PIC 9 OCCURS 1 TO 3 DEPENDING ON I項目. + PROCEDURE DIVISION. + MOVE 1 TO Y項目(3). + GOBACK. +]) + +AT_CHECK([${COMPILE} -debug prog.cob]) + +AT_CHECK([java prog 2> out1.txt], [1]) +AT_CHECK([echo "prog.cob:10: libcobj: OCCURS DEPENDING ON 'I項目' out of bounds: 4" | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([Nihongo field name in Subscript test msg.]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 I項目 PIC 9 VALUE 2. + 01 X. + 03 Y項目 PIC 9 OCCURS 1 TO 3 DEPENDING ON I項目. + PROCEDURE DIVISION. + MOVE 1 TO Y項目(3). + GOBACK. +]) + +AT_CHECK([${COMPILE} -debug prog.cob]) + +AT_CHECK([java prog 2> out1.txt], [1]) +AT_CHECK([echo "prog.cob:10: libcobj: Subscript of 'Y項目' out of bounds: 3" | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([Nihongo field name in length of ref_mod test msg.]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 I PIC 9 VALUE 2. + 01 J PIC 9 VALUE 6. + 01 X項目 PIC X(5) VALUE "ABCDE". + PROCEDURE DIVISION. + DISPLAY X項目(I:J). + GOBACK. +]) + +AT_CHECK([${COMPILE} -debug prog.cob]) + +AT_CHECK([java prog 2> out1.txt], [1]) +AT_CHECK([echo "prog.cob:10: libcobj: Length of 'X項目' out of bounds: 6" | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([Nihongo field name in offset of ref_mod test msg.]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 I PIC 9 VALUE 6. + 01 J PIC 9 VALUE 2. + 01 X項目 PIC X(5) VALUE "ABCDE". + PROCEDURE DIVISION. + DISPLAY X項目(I:J). + GOBACK. +]) + +AT_CHECK([${COMPILE} -debug prog.cob]) + +AT_CHECK([java prog 2> out1.txt], [1]) +AT_CHECK([echo "prog.cob:10: libcobj: Offset of 'X項目' out of bounds: 6" | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([Nihongo field name in length of N_refmod test msg.]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 I PIC 9 VALUE 2. + 01 J PIC 99 VALUE 18. + 01 X項目 PIC N(5) VALUE "ABCDE". + PROCEDURE DIVISION. + DISPLAY X項目(I:J). + GOBACK. +]) + +AT_CHECK([${COMPILE} -debug prog.cob]) + +AT_CHECK([java prog 2> out1.txt], [1]) +AT_CHECK([echo "prog.cob:10: libcobj: Length of 'X項目' out of bounds: 18" | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([Nihongo field name in offset of N_refmod test msg.]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 I PIC 99 VALUE 18. + 01 J PIC 9 VALUE 2. + 01 X項目 PIC N(5) VALUE "ABCDE". + PROCEDURE DIVISION. + DISPLAY X項目(I:J). + GOBACK. +]) + +AT_CHECK([${COMPILE} -debug prog.cob]) + +AT_CHECK([java prog 2> out1.txt], [1]) +AT_CHECK([echo "prog.cob:10: libcobj: Offset of 'X項目' out of bounds: 18" | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([Nihongo field name in extaddr test msg.]) +export LC_ALL='' +AT_CHECK([${SKIP_TEST}]) + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. check1. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 X項目 PIC X(5) EXTERNAL. + PROCEDURE DIVISION. + CALL 'check2'. + + IDENTIFICATION DIVISION. + PROGRAM-ID. check2. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 X項目 PIC X(6) EXTERNAL. + PROCEDURE DIVISION. + END PROGRAM check2. + END PROGRAM check1. +]) + +AT_CHECK([${COMPILE} -debug prog.cob]) + +AT_CHECK([java prog 2> out1.txt], [1]) +AT_CHECK([echo "prog.cob:8: libcobj: EXTERNAL item 'X項目' has size > 6" | nkf --ic=UTF-8 --oc=Shift_JIS > out2.txt]) +AT_CHECK([diff out1.txt out2.txt]) + +AT_CLEANUP + +AT_SETUP([Nihongo field name in undefined error msg.]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 G集団項目. + 03 A項目 PIC X. + PROCEDURE DIVISION. +001009 DISPLAY NO-FLD. +001010 DISPLAY NO-FLD IN G-GRP. +001011 DISPLAY NO-FLD IN NO-GRP. +001012 DISPLAY NO項目. +001013 DISPLAY NO項目 IN G集団項目. +001014 DISPLAY NO項目 IN NO集団項目. +001015 DISPLAY NO-FLD IN G集団項目. +001016 DISPLAY NO-FLD IN NO集団項目. +001017 DISPLAY NO項目 IN G-GRP. +001018 DISPLAY NO項目 IN NO-GRP. +001019 DISPLAY NO項目 IN G集団項目 IN NO集団項目. +]) + +AT_CHECK([${COMPILE} -debug prog.cob], [1], [], +[prog.cob:9: Error: 'NO-FLD' undefined +prog.cob:10: Error: 'NO-FLD' in 'G-GRP' undefined +prog.cob:11: Error: 'NO-FLD' in 'NO-GRP' undefined +prog.cob:12: Error: 'NO項目' undefined +prog.cob:13: Error: 'NO項目' in 'G集団項目' undefined +prog.cob:14: Error: 'NO項目' in 'NO集団項目' undefined +prog.cob:15: Error: 'NO-FLD' in 'G集団項目' undefined +prog.cob:16: Error: 'NO-FLD' in 'NO集団項目' undefined +prog.cob:17: Error: 'NO項目' in 'G-GRP' undefined +prog.cob:18: Error: 'NO項目' in 'NO-GRP' undefined +prog.cob:19: Error: 'NO項目' in 'G集団項目' in 'NO集団項目' undefined +]) + +AT_CLEANUP + +AT_SETUP([Nihongo field name in ambiguous error msg.]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 A項目 PIC X. + 01 G1集団. + 03 A項目 PIC X. + 03 B項目 PIC X. + 03 G2集団. + 05 A項目 PIC X. + 05 B項目 PIC X. + PROCEDURE DIVISION. +001014 DISPLAY A項目. +001015 DISPLAY B項目 IN G1集団. + GOBACK. +]) + +AT_CHECK([${COMPILE_ONLY} prog.cob], [1], [], +[prog.cob:8: Warning: Redefinition of 'A項目' +prog.cob:6: Warning: 'A項目' previously defined here +prog.cob:11: Warning: Redefinition of 'A項目' +prog.cob:6: Warning: 'A項目' previously defined here +prog.cob:14: Error: 'A項目' ambiguous; need qualification +prog.cob:6: Error: 'A項目' defined here +prog.cob:8: Error: 'A項目' in 'G1集団' defined here +prog.cob:11: Error: 'A項目' in 'G2集団' in 'G1集団' defined here +prog.cob:15: Error: 'B項目' in 'G1集団' ambiguous; need qualification +prog.cob:9: Error: 'B項目' in 'G1集団' defined here +prog.cob:12: Error: 'B項目' in 'G2集団' in 'G1集団' defined here +]) + +AT_CLEANUP + +AT_SETUP([Nihongo label name in ambiguous error msg.]) +export LC_ALL='' + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + PROCEDURE DIVISION. +001006 L0見出し. +001007 GO TO L1見出し. +001008 GO TO L2見出し IN S1節. +001009 L1見出し. GOBACK. +001010 L1見出し. GOBACK. +001011 S1節 SECTION. +001012 L2見出し. GOBACK. +001013 L2見出し. GOBACK. +]) + +AT_CHECK([${COMPILE_ONLY} prog.cob], [1], [], +[prog.cob:7: Error: 'L1見出し' ambiguous; need qualification +prog.cob:9: Error: 'L1見出し' in 'MAIN SECTION' defined here +prog.cob:10: Error: 'L1見出し' in 'MAIN SECTION' defined here +prog.cob:8: Error: 'L2見出し' in 'S1節' ambiguous; need qualification +prog.cob:12: Error: 'L2見出し' in 'S1節' defined here +prog.cob:13: Error: 'L2見出し' in 'S1節' defined here +]) + +AT_CLEANUP diff --git a/tests/command-line-options.at b/tests/command-line-options.at index b057fd5b..bf321222 100644 --- a/tests/command-line-options.at +++ b/tests/command-line-options.at @@ -36,5 +36,3 @@ m4_include([jar.at]) m4_include([std.at]) m4_include([conf.at]) m4_include([Wimplicit-define.at]) - -# m4_include([edit-code-command.at]) diff --git a/tests/command-line-options.src/allow-key-in-rhs.conf b/tests/command-line-options.src/allow-key-in-rhs.conf new file mode 100644 index 00000000..daa28900 --- /dev/null +++ b/tests/command-line-options.src/allow-key-in-rhs.conf @@ -0,0 +1,153 @@ +# COBOL compiler configuration -*- sh -*- + +# Value: any string +name: "OpenCOBOL" + +# Value: int +tab-width: 8 +text-column: 72 + +# Value: 'record-sequential', 'line-sequential' +# This sets the default organization for sequential files, +# where the organization is not explicitly defined. +default-organization: record-sequential + +# Value: 'cobol2002', 'mf', 'ibm', 'jph1' +assign-clause: mf + +# If yes, file names are resolved at run time using environment variables. +# For example, given ASSIGN TO "DATAFILE", the actual file name will be +# 1. the value of environment variable 'DD_DATAFILE' or +# 2. the value of environment variable 'dd_DATAFILE' or +# 3. the value of environment variable 'DATAFILE' or +# 4. the literal "DATAFILE" +# If no, the value of the assign clause is the file name. +# +# Value: 'yes', 'no' +filename-mapping: yes + +# Value: 'yes', 'no' +pretty-display: yes + +# Value: 'yes', 'no' +auto-initialize: yes + +# Value: 'yes', 'no' +complex-odo: no + +# Value: 'yes', 'no' +indirect-redefines: no + +# Binary byte size - defines the allocated bytes according to PIC +# Value: signed unsigned bytes +# ------ -------- ----- +# '2-4-8' 1 - 4 2 +# 5 - 9 4 +# 10 - 18 8 +# +# '1-2-4-8' 1 - 2 1 +# 3 - 4 2 +# 5 - 9 4 +# 10 - 18 8 +# +# '1--8' 1 - 2 1 - 2 1 +# 3 - 4 3 - 4 2 +# 5 - 6 5 - 7 3 +# 7 - 9 8 - 9 4 +# 10 - 11 10 - 12 5 +# 12 - 14 13 - 14 6 +# 15 - 16 15 - 16 7 +# 17 - 18 17 - 18 8 +binary-size: 1-2-4-8 + +# Value: 'yes', 'no' +binary-truncate: yes + +# Value: 'native', 'big-endian' +binary-byteorder: big-endian + +# Value: 'any', 'fatal', 'never' +abort-on-io-exception: any + +# Value: 'yes', 'no' +larger-redefines-ok: no + +# Value: 'yes', 'no' +relaxed-syntax-check: no + +# Perform type OSVS - If yes, the exit point of any currently executing perform +# is recognized if reached. +# Value: 'yes', 'no' +perform-osvs: no + +# If yes, linkage-section items remain allocated +# between invocations. +# Value: 'yes', 'no' +sticky-linkage: no + +# If yes, set the file assign to the external file +# Value: 'yes', 'no' +assign_external: no + +# If yes, allow non-matching level numbers +# Value: 'yes', 'no' +relax-level-hierarchy: no + +# not-reserved: +# Value: Word to be taken out of the reserved words list +# (case independent) + +# Dialect features +# Value: 'ok', 'archaic', 'obsolete', 'skip', 'ignore', 'unconformable' +author-paragraph: obsolete +memory-size-clause: obsolete +multiple-file-tape-clause: obsolete +label-records-clause: obsolete +value-of-clause: obsolete +data-records-clause: obsolete +top-level-occurs-clause: skip +synchronized-clause: ok +goto-statement-without-name: obsolete +stop-literal-statement: obsolete +debugging-line: obsolete +padding-character-clause: obsolete +next-sentence-phrase: archaic +eject-statement: skip +entry-statement: obsolete +move-noninteger-to-alphanumeric: error +odo-without-to: ok + +# Value: any single character +default-currency-symbol: $ + +# Value: int +max-alpha-character-data-size: 2147483647 +max-sjis-character-data-size: 1073741823 +max-utf8-character-data-size: 715827882 + +# If yes, length of PROGRAM-ID of after translation is bigger than +# 31 characters, give warning. +c89-identifier-length-check: no + +# jp compatible +# Value: 'yes', 'no' +allow-end-program-with-wrong-name: no +allow-missing-also-clause-in-evaluate: no +allow-empty-imperative-statement: no +enable-program-status-register: no +enable-sort-status-register: no +enable-special-names-argument-clause: no +enable-special-names-environment-clause: no +enable-leng-intrinsic-function: no +enable-length-an-intrinsic-function: no +enable-national-intrinsic-function: no +use-invalidkey-handler-on-status34: no +cobol68-copy-in-data-description: no +switch-no-mnemonic: no +allow-is-in-sort-key-spec: no +allow-search-key-in-rhs: yes +ignore-invalid-record-contains: no +enable-zero-division-error: no +enable-check-subscript-out-of-bounds: no +enable-expect-numeric-error: no +enable-expect-compute-string-error: no diff --git a/tests/command-line-options.src/conf.at b/tests/command-line-options.src/conf.at index 0f1b6a41..ee3f161e 100644 --- a/tests/command-line-options.src/conf.at +++ b/tests/command-line-options.src/conf.at @@ -17,3 +17,169 @@ AT_CHECK([${COBJ} -conf=hello.conf prog.cbl], [1], [], ]) AT_CLEANUP + + +AT_SETUP([allow search key in rhs]) + +# without SEARCH ALL +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + PROCEDURE DIVISION. + MAIN-RTN. + DISPLAY "HELLO, WORLD!!". + STOP RUN. +]) +AT_CHECK([${COBJ} prog.cbl], [0]) +AT_CHECK([${COBJ} -conf=../../command-line-options.src/allow-key-in-rhs.conf prog.cbl], [0]) + + +# key item of OCCURS is LEFT hand side on WHEN condition +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 ELEMENT_COUNT PIC 9(03) VALUE 3. + 01 RECORD_ARRAY. + 02 FILLER OCCURS 3. + 03 METRIC_COUNT PIC 9(03). + 01 RECORD_ID PIC X(02). + 01 RECORD_KEY. + 02 RECORD_STRUCT. + 03 RECORD_CODE PIC X(04). + 03 RECORD_TYPE PIC X(02). + 02 SERIAL_NO PIC 9(02). + 01 DATA_TABLE. + 02 ELEMENT OCCURS 1 TO 150 + DEPENDING ON ELEMENT_COUNT + ASCENDING KEY TABLE_KEY INDEXED BY INDEX_K. + 03 TABLE_KEY. + 04 KEY_CODE. + 05 RECORD_CODE_KEY PIC X(04). + 05 RECORD_TYPE_KEY PIC X(02). + 04 SERIAL_NO_KEY PIC 9(02). + 03 FILLER PIC X(02). + 03 METRIC_DATA. + 04 METRIC_ELEMENT OCCURS 10 INDEXED BY INDEX_J. + 05 METER_NO PIC X(08). + 05 ADDITION_FLAG PIC X(01). + 03 FILLER PIC X(02). + * + PROCEDURE DIVISION. + MAIN_ROUTINE. + SEARCH ALL ELEMENT + AT END + MOVE ZERO TO METRIC_COUNT(1) + GO TO EXIT_ROUTINE + WHEN TABLE_KEY(INDEX_K) = RECORD_KEY + MOVE KEY_CODE(INDEX_K) TO RECORD_ID + SET METRIC_COUNT(1) TO INDEX_K. + EXIT_ROUTINE. + MAIN_EXIT. + STOP RUN. +]) +AT_CHECK([${COBJ} prog.cbl], [0]) +AT_CHECK([${COBJ} -conf=../../command-line-options.src/allow-key-in-rhs.conf prog.cbl], [0]) + + +# key item of OCCURS is RIGHT hand side on WHEN condition +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 ELEMENT_COUNT PIC 9(03) VALUE 3. + 01 RECORD_ARRAY. + 02 FILLER OCCURS 3. + 03 METRIC_COUNT PIC 9(03). + 01 RECORD_ID PIC X(02). + 01 RECORD_KEY. + 02 RECORD_STRUCT. + 03 RECORD_CODE PIC X(04). + 03 RECORD_TYPE PIC X(02). + 02 SERIAL_NO PIC 9(02). + 01 DATA_TABLE. + 02 ELEMENT OCCURS 1 TO 150 + DEPENDING ON ELEMENT_COUNT + ASCENDING KEY TABLE_KEY INDEXED BY INDEX_K. + 03 TABLE_KEY. + 04 KEY_CODE. + 05 RECORD_CODE_KEY PIC X(04). + 05 RECORD_TYPE_KEY PIC X(02). + 04 SERIAL_NO_KEY PIC 9(02). + 03 FILLER PIC X(02). + 03 METRIC_DATA. + 04 METRIC_ELEMENT OCCURS 10 INDEXED BY INDEX_J. + 05 METER_NO PIC X(08). + 05 ADDITION_FLAG PIC X(01). + 03 FILLER PIC X(02). + * + PROCEDURE DIVISION. + MAIN_ROUTINE. + SEARCH ALL ELEMENT + AT END + MOVE ZERO TO METRIC_COUNT(1) + GO TO EXIT_ROUTINE + WHEN RECORD_KEY = TABLE_KEY(INDEX_K) + MOVE KEY_CODE(INDEX_K) TO RECORD_ID + SET METRIC_COUNT(1) TO INDEX_K. + EXIT_ROUTINE. + MAIN_EXIT. + STOP RUN. +]) +AT_CHECK([(${COBJ} prog.cbl | grep "Undeclared key") > a.txt 2>&1], [1]) +AT_CHECK([${COBJ} -conf=../../command-line-options.src/allow-key-in-rhs.conf prog.cbl], [0]) + + +# only key item on WHEN condition +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 ELEMENT_COUNT PIC 9(03) VALUE 3. + 01 RECORD_ARRAY. + 02 FILLER OCCURS 3. + 03 METRIC_COUNT PIC 9(03). + 01 RECORD_ID PIC X(02). + 01 RECORD_KEY. + 02 RECORD_STRUCT. + 03 RECORD_CODE PIC X(04). + 03 RECORD_TYPE PIC X(02). + 02 SERIAL_NO PIC 9(02). + 01 DATA_TABLE. + 02 ELEMENT OCCURS 1 TO 150 + DEPENDING ON ELEMENT_COUNT + ASCENDING KEY TABLE_KEY INDEXED BY INDEX_K. + 03 TABLE_KEY. + 04 KEY_CODE. + 05 RECORD_CODE_KEY PIC X(04). + 05 RECORD_TYPE_KEY PIC X(02). + 04 SERIAL_NO_KEY PIC 9(02). + 03 FILLER PIC X(02). + 03 METRIC_DATA. + 04 METRIC_ELEMENT OCCURS 10 INDEXED BY INDEX_J. + 05 METER_NO PIC X(08). + 05 ADDITION_FLAG PIC X(01). + 03 FILLER PIC X(02). + * + PROCEDURE DIVISION. + MAIN_ROUTINE. + SEARCH ALL ELEMENT + AT END + MOVE ZERO TO METRIC_COUNT(1) + GO TO EXIT_ROUTINE + WHEN TABLE_KEY(INDEX_K) + MOVE KEY_CODE(INDEX_K) TO RECORD_ID + SET METRIC_COUNT(1) TO INDEX_K. + EXIT_ROUTINE. + MAIN_EXIT. + STOP RUN. +]) +AT_CHECK([(${COBJ} prog.cbl | grep "Invalid type cast") > a.txt 2>&1], [1]) +AT_CHECK([(${COBJ} -conf=../../command-line-options.src/allow-key-in-rhs.conf prog.cbl | grep "Invalid type cast") > a.txt 2>&1], [1]) + +AT_CLEANUP diff --git a/tests/command-line-options.src/edit-code-command.at b/tests/command-line-options.src/edit-code-command.at deleted file mode 100644 index 7985cbb2..00000000 --- a/tests/command-line-options.src/edit-code-command.at +++ /dev/null @@ -1,94 +0,0 @@ -AT_SETUP([-edit-code-command]) - -AT_DATA([prog.cbl], [ - identification division. - program-id. prog. - procedure division. - display "hello". -]) - -AT_DATA([SampleInterface.java], [ - public interface SampleInterface { - public void sampleInterfaceRun(); - } -]) - -AT_DATA([CallSampleInterface.java], [ - public class CallSampleInterface { - public static void main(String@<:@@:>@ args) { - SampleInterface s = new prog(); - s.sampleInterfaceRun(); - } - } -]) - -AT_DATA([edit.sh], [ -#!/bin/bash - -while getopts c:t-: opt; do - optarg="$OPTARG" - if @<:@@<:@ "$opt" = - @:>@@:>@; then - opt="-${OPTARG%%=*}" - optarg="${OPTARG/${OPTARG%%=*}/}" - optarg="${optarg#=}" - - if @<:@@<:@ -z "$optarg" @:>@@:>@ && @<:@@<:@ ! "${!OPTIND}" = -* @:>@@:>@; then - optarg="${!OPTIND}" - shift - fi - fi - - case "-$opt" in - --target) - target="$optarg" - ;; - --class-name) - class_name="$optarg" - ;; - --) - break - ;; - esac -done -shift $((OPTIND - 1)) - - -case "$target" in - # when `--target=main-class` is specified - main-class-annotation) - echo "//annotation here" - exit 0 - ;; - # when `--target=file-header` is specified - file-header) - echo '//file-header here' - exit 0 - ;; - # when `--target=main-class` is specified - main-class-implements) - echo -n 'SampleInterface' - exit 0 - ;; - # when `--target=main-class` is specified - main-class-contents) - echo ' @Override' - echo ' public void sampleInterfaceRun() { System.out.println("COBOL"); }' - exit 0 - ;; -esac - -exit 1 - -]) - -AT_CHECK([${COBJ} -edit-code-command="bash edit.sh" prog.cbl], [0]) -AT_CHECK([java prog], [0], [hello -]) -AT_CHECK([javac CallSampleInterface.java]) -AT_CHECK([java CallSampleInterface], [0], [COBOL -]) -AT_CHECK([cat prog.java | grep 'annotation here' > /dev/null], [0]) -AT_CHECK([cat prog.java | grep 'file-header here' > /dev/null], [0]) -AT_CHECK([cobj --help | grep 'edit-code-command' > /dev/null], [0]) - -AT_CLEANUP \ No newline at end of file diff --git a/tests/command-line-options.src/free.at b/tests/command-line-options.src/free.at index 2eedccec..8c6033cf 100644 --- a/tests/command-line-options.src/free.at +++ b/tests/command-line-options.src/free.at @@ -35,4 +35,57 @@ HELLO WORLD ]) +AT_CLEANUP + +AT_SETUP([-variable]) + +AT_DATA([prog.cbl], [ +000001 IDENTIFICATION DIVISION. +000002 PROGRAM-ID. prog. +000003 DATA DIVISION. +000004 WORKING-STORAGE SECTION. +000005 PROCEDURE DIVISION. +000006 DISPLAY "HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO". +]) + +AT_CHECK([${COBJ} -variable prog.cbl]) +AT_CHECK([${RUN_MODULE} prog], [0], +[HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO +]) + +AT_DATA([prog2.cbl], [ +000001 IDENTIFICATION DIVISION. +000002 PROGRAM-ID. prog2. +000003 DATA DIVISION. +000004 WORKING-STORAGE SECTION. +000005PROCEDURE DIVISION. +000006 STOP RUN. +]) + +AT_CHECK([${COBJ} -variable prog2.cbl], [1], [], +[prog2.cbl:5: Error: Invalid indicator 'P' at column 7 +]) + +AT_DATA([prog3.cbl], [ +000001 IDENTIFICATION DIVISION. +000002 PROGRAM-ID. prog3. +000003 DATA DIVISION. +000004 WORKING-STORAGE SECTION. +000005 COPY inc. +000006 PROCEDURE DIVISION. +000007 DISPLAY AFTER-72. +000008 DISPLAY "HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO". +000009 STOP RUN. +]) + +AT_DATA([inc.cpy], [ +000001 01 AFTER-72 PIC X(119) VALUE "HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO". +]) + +AT_CHECK([${COBJ} -variable prog3.cbl]) +AT_CHECK([${RUN_MODULE} prog3], [0], +[HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO +HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO +]) + AT_CLEANUP \ No newline at end of file diff --git a/tests/command-line-options.src/fserial-variable.at b/tests/command-line-options.src/fserial-variable.at index 082af5aa..55863736 100644 --- a/tests/command-line-options.src/fserial-variable.at +++ b/tests/command-line-options.src/fserial-variable.at @@ -30,16 +30,33 @@ A 3 B ]) +AT_CHECK([grep 'b_5' prog.java > /dev/null], [0]) +AT_CHECK([grep 'b_6' prog.java > /dev/null], [0]) +AT_CHECK([grep 'b_7' prog.java > /dev/null], [0]) +AT_CHECK([grep 'b_8' prog.java > /dev/null], [0]) +AT_CHECK([grep 'b_9' prog.java > /dev/null], [0]) +AT_CHECK([grep 'b_10' prog.java > /dev/null], [0]) +AT_CHECK([grep 'b_11' prog.java > /dev/null], [0]) +AT_CHECK([grep 'f_5' prog.java > /dev/null], [0]) +AT_CHECK([grep 'f_6' prog.java > /dev/null], [0]) +AT_CHECK([grep 'f_7' prog.java > /dev/null], [0]) +AT_CHECK([grep 'f_9' prog.java > /dev/null], [0]) +AT_CHECK([grep 'f_10' prog.java > /dev/null], [0]) +AT_CHECK([grep 'f_11' prog.java > /dev/null], [0]) + AT_CHECK([grep 'f_AAA' prog.java], [1]) AT_CHECK([grep 'b_AAA' prog.java], [1]) AT_CHECK([grep 'f_BBB' prog.java], [1]) AT_CHECK([grep 'b_BBB' prog.java], [1]) AT_CHECK([grep 'f_CCC' prog.java], [1]) AT_CHECK([grep 'b_CCC' prog.java], [1]) -AT_CHECK([grep 'f_DDD' prog.java], [1]) -AT_CHECK([grep 'f_EEE' prog.java], [1]) -AT_CHECK([grep 'f_FFF' prog.java], [1]) AT_CHECK([grep 'b_GRP' prog.java], [1]) +AT_CHECK([grep 'f_DDD__GRP' prog.java], [1]) +AT_CHECK([grep 'b_DDD__GRP' prog.java], [1]) +AT_CHECK([grep 'f_EEE__GRP' prog.java], [1]) +AT_CHECK([grep 'b_EEE__GRP' prog.java], [1]) +AT_CHECK([grep 'f_FFF__GRP' prog.java], [1]) +AT_CHECK([grep 'b_FFF__GRP' prog.java], [1]) AT_CHECK([${COMPILE} prog.cbl]) AT_CHECK([${RUN_MODULE} prog], [0], @@ -56,9 +73,26 @@ AT_CHECK([grep 'f_BBB' prog.java > /dev/null], [0]) AT_CHECK([grep 'b_BBB' prog.java > /dev/null], [0]) AT_CHECK([grep 'f_CCC' prog.java > /dev/null], [0]) AT_CHECK([grep 'b_CCC' prog.java > /dev/null], [0]) -AT_CHECK([grep 'f_DDD' prog.java > /dev/null], [0]) -AT_CHECK([grep 'f_EEE' prog.java > /dev/null], [0]) -AT_CHECK([grep 'f_FFF' prog.java > /dev/null], [0]) AT_CHECK([grep 'b_GRP' prog.java > /dev/null], [0]) +AT_CHECK([grep 'f_DDD__GRP' prog.java > /dev/null], [0]) +AT_CHECK([grep 'b_DDD__GRP' prog.java > /dev/null], [0]) +AT_CHECK([grep 'f_EEE__GRP' prog.java > /dev/null], [0]) +AT_CHECK([grep 'b_EEE__GRP' prog.java > /dev/null], [0]) +AT_CHECK([grep 'f_FFF__GRP' prog.java > /dev/null], [0]) +AT_CHECK([grep 'b_FFF__GRP' prog.java > /dev/null], [0]) + +AT_CHECK([grep 'b_5' prog.java], [1]) +AT_CHECK([grep 'b_6' prog.java], [1]) +AT_CHECK([grep 'b_7' prog.java], [1]) +AT_CHECK([grep 'b_8' prog.java], [1]) +AT_CHECK([grep 'b_9' prog.java], [1]) +AT_CHECK([grep 'b_10' prog.java], [1]) +AT_CHECK([grep 'b_11' prog.java], [1]) +AT_CHECK([grep 'f_5' prog.java], [1]) +AT_CHECK([grep 'f_6' prog.java], [1]) +AT_CHECK([grep 'f_7' prog.java], [1]) +AT_CHECK([grep 'f_9' prog.java], [1]) +AT_CHECK([grep 'f_10' prog.java], [1]) +AT_CHECK([grep 'f_11' prog.java], [1]) AT_CLEANUP diff --git a/tests/command-line-options.src/info-java-dir.at b/tests/command-line-options.src/info-java-dir.at index 75663668..a4cdd7c8 100644 --- a/tests/command-line-options.src/info-java-dir.at +++ b/tests/command-line-options.src/info-java-dir.at @@ -10,7 +10,8 @@ AT_DATA([callee.cbl], [ LINKAGE SECTION. 01 P1 PIC X ANY LENGTH. 01 P2 PIC 99. - PROCEDURE DIVISION USING P1 P2. + 01 P3 PIC 9V9. + PROCEDURE DIVISION USING P1 P2 P3. GOBACK. ]) @@ -28,7 +29,7 @@ AT_DATA([prog.cbl], [ AT_CHECK([${COBJ} -info-json-dir=./ callee.cbl prog.cbl]) AT_CHECK([cat info_callee.json], [0], [{ - "opensourcecobol4j_version": "1.1.2", + "opensourcecobol4j_version": "1.1.14", "program_id": "callee", "procedure_division_using_parameters": @<:@ { @@ -38,6 +39,10 @@ AT_CHECK([cat info_callee.json], [0], { "variable_name": "P2", "java_type": "int" + }, + { + "variable_name": "P3", + "java_type": "double" } @:>@ } @@ -45,7 +50,7 @@ AT_CHECK([cat info_callee.json], [0], AT_CHECK([cat info_prog.json], [0], [{ - "opensourcecobol4j_version": "1.1.2", + "opensourcecobol4j_version": "1.1.14", "program_id": "prog", "procedure_division_using_parameters": @<:@ @:>@ @@ -64,7 +69,7 @@ AT_CHECK([${COBJ} -info-json-dir=bbb callee.cbl prog.cbl]) AT_CHECK([cat bbb/info_callee.json], [0], [{ - "opensourcecobol4j_version": "1.1.2", + "opensourcecobol4j_version": "1.1.14", "program_id": "callee", "procedure_division_using_parameters": @<:@ { @@ -74,6 +79,10 @@ AT_CHECK([cat bbb/info_callee.json], [0], { "variable_name": "P2", "java_type": "int" + }, + { + "variable_name": "P3", + "java_type": "double" } @:>@ } @@ -81,7 +90,7 @@ AT_CHECK([cat bbb/info_callee.json], [0], AT_CHECK([cat bbb/info_prog.json], [0], [{ - "opensourcecobol4j_version": "1.1.2", + "opensourcecobol4j_version": "1.1.14", "program_id": "prog", "procedure_division_using_parameters": @<:@ @:>@ diff --git a/tests/data-rep.src/binary.at b/tests/data-rep.src/binary.at index 6a3dab9a..f24f887e 100644 --- a/tests/data-rep.src/binary.at +++ b/tests/data-rep.src/binary.at @@ -215,9 +215,9 @@ AT_CHECK([java prog], [0], AT_CLEANUP -# 2-4-8 native +# 2-4-8 little-endian -AT_SETUP([BINARY: 2-4-8 native]) +AT_SETUP([BINARY: 2-4-8 little-endian]) AT_CHECK([${SKIP_TEST}]) if test "x$COB_BIGENDIAN" = "xyes"; then @@ -227,7 +227,7 @@ else AT_DATA([test.conf], [ include "cobol2002.conf" binary-size: 2-4-8 -binary-byteorder: native +binary-byteorder: little-endian ]) AT_DATA([dump.java], [ @@ -616,9 +616,9 @@ AT_CHECK([java prog], [0], AT_CLEANUP -# 1-2-4-8 native +# 1-2-4-8 little-endian -AT_SETUP([BINARY: 1-2-4-8 native]) +AT_SETUP([BINARY: 1-2-4-8 little-endian]) AT_CHECK([${SKIP_TEST}]) if test "x$COB_BIGENDIAN" = "xyes"; then @@ -628,7 +628,7 @@ else AT_DATA([test.conf], [ include "cobol2002.conf" binary-size: 1-2-4-8 -binary-byteorder: native +binary-byteorder: little-endian ]) AT_DATA([dump.java], [ @@ -1019,9 +1019,9 @@ AT_CHECK([java prog], [0], AT_CLEANUP -# 1--8 native +# 1--8 little-endian -AT_SETUP([BINARY: 1--8 native]) +AT_SETUP([BINARY: 1--8 little-endian]) AT_CHECK([${SKIP_TEST}]) if test "x$COB_BIGENDIAN" = "xyes"; then @@ -1031,7 +1031,7 @@ else AT_DATA([test.conf], [ include "cobol2002.conf" binary-size: 1--8 -binary-byteorder: native +binary-byteorder: little-endian ]) AT_DATA([dump.java], [ @@ -1277,3 +1277,285 @@ AT_CHECK([java prog], [0], ]) AT_CLEANUP + +# compare COMP data + +AT_SETUP([compare COMP]) + +AT_DATA([prog.cbl],[ + identification division. + program-id. prog. + data division. + working-storage section. + 01 u9 pic 9(9) comp. + 01 u18 pic 9(18) comp. + 01 s4 pic s9(4) comp. + 01 s9 pic s9(9) comp. + 01 s18 pic s9(18) comp. + procedure division. + move 2 to u9. move -1 to s4. + if u9 <= s4 then display "ng 00-00" end-if. + move 2 to u9. move -3 to s4. + if u9 <= s4 then display "ng 00-01" end-if. + move 2 to u9. move -9999 to s4. + if u9 <= s4 then display "ng 00-02" end-if. + move 2 to u9. move 0 to s4. + if u9 <= s4 then display "ng 00-03" end-if. + move 2 to u9. move 1 to s4. + if u9 <= s4 then display "ng 00-04" end-if. + move 2 to u9. move 2 to s4. + if u9 <> s4 then display "ng 00-05" end-if. + move 2 to u9. move 3 to s4. + if u9 >= s4 then display "ng 00-06" end-if. + move 2 to u9. move 9999 to s4. + if u9 >= s4 then display "ng 00-06" end-if. + move 0 to u9. move -1 to s4. + if u9 <= s4 then display "ng 00-07" end-if. + move 0 to u9. move -3 to s4. + if u9 <= s4 then display "ng 00-08" end-if. + move 0 to u9. move -9999 to s4. + if u9 <= s4 then display "ng 00-09" end-if. + move 0 to u9. move 0 to s4. + if u9 <> s4 then display "ng 00-10" end-if. + move 0 to u9. move 1 to s4. + if u9 >= s4 then display "ng 00-11" end-if. + move 0 to u9. move 2 to s4. + if u9 >= s4 then display "ng 00-12" end-if. + move 0 to u9. move 3 to s4. + if u9 >= s4 then display "ng 00-13" end-if. + move 0 to u9. move 9999 to s4. + if u9 >= s4 then display "ng 00-14" end-if. + move 999999999 to u9. move -1 to s4. + if u9 <= s4 then display "ng 00-15" end-if. + move 999999999 to u9. move -3 to s4. + if u9 <= s4 then display "ng 00-16" end-if. + move 999999999 to u9. move -9999 to s4. + if u9 <= s4 then display "ng 00-17" end-if. + move 999999999 to u9. move 0 to s4. + if u9 <= s4 then display "ng 00-18" end-if. + move 999999999 to u9. move 1 to s4. + if u9 <= s4 then display "ng 00-19" end-if. + move 999999999 to u9. move 2 to s4. + if u9 <= s4 then display "ng 00-20" end-if. + move 999999999 to u9. move 9999 to s4. + if u9 <= s4 then display "ng 00-21" end-if. + ****************************************************************** + move 2 to u9. move -1 to s9. + if u9 <= s9 then display "ng 01-00" end-if. + move 2 to u9. move -3 to s9. + if u9 <= s9 then display "ng 01-01" end-if. + move 2 to u9. move -999999999 to s9. + if u9 <= s9 then display "ng 01-02" end-if. + move 2 to u9. move 0 to s9. + if u9 <= s9 then display "ng 01-03" end-if. + move 2 to u9. move 1 to s9. + if u9 <= s9 then display "ng 01-04" end-if. + move 2 to u9. move 2 to s9. + if u9 <> s9 then display "ng 01-05" end-if. + move 2 to u9. move 3 to s9. + if u9 >= s9 then display "ng 01-06" end-if. + move 2 to u9. move 999999999 to s9. + if u9 >= s9 then display "ng 01-06" end-if. + move 0 to u9. move -1 to s9. + if u9 <= s9 then display "ng 01-07" end-if. + move 0 to u9. move -3 to s9. + if u9 <= s9 then display "ng 01-08" end-if. + move 0 to u9. move -999999999 to s9. + if u9 <= s9 then display "ng 01-09" end-if. + move 0 to u9. move 0 to s9. + if u9 <> s9 then display "ng 01-10" end-if. + move 0 to u9. move 1 to s9. + if u9 >= s9 then display "ng 01-11" end-if. + move 0 to u9. move 2 to s9. + if u9 >= s9 then display "ng 01-12" end-if. + move 0 to u9. move 3 to s9. + if u9 >= s9 then display "ng 01-13" end-if. + move 0 to u9. move 999999999 to s9. + if u9 >= s9 then display "ng 01-14" end-if. + move 999999999 to u9. move -1 to s9. + if u9 <= s9 then display "ng 01-15" end-if. + move 999999999 to u9. move -3 to s9. + if u9 <= s9 then display "ng 01-16" end-if. + move 999999999 to u9. move -999999999 to s9. + if u9 <= s9 then display "ng 01-17" end-if. + move 999999999 to u9. move 0 to s9. + if u9 <= s9 then display "ng 01-18" end-if. + move 999999999 to u9. move 1 to s9. + if u9 <= s9 then display "ng 01-19" end-if. + move 999999999 to u9. move 2 to s9. + if u9 <= s9 then display "ng 01-20" end-if. + move 999999999 to u9. move 999999999 to s9. + if u9 <> s9 then display "ng 01-21" end-if. + ****************************************************************** + move 2 to u9. move -1 to s18. + if u9 <= s18 then display "ng 02-00" end-if. + move 2 to u9. move -3 to s18. + if u9 <= s18 then display "ng 02-01" end-if. + move 2 to u9. move -999999999999999999 to s18. + if u9 <= s18 then display "ng 02-02" end-if. + move 2 to u9. move 0 to s18. + if u9 <= s18 then display "ng 02-03" end-if. + move 2 to u9. move 1 to s18. + if u9 <= s18 then display "ng 02-04" end-if. + move 2 to u9. move 2 to s18. + if u9 <> s18 then display "ng 02-05" end-if. + move 2 to u9. move 3 to s18. + if u9 >= s18 then display "ng 02-06" end-if. + move 2 to u9. move 999999999999999999 to s18. + if u9 >= s18 then display "ng 02-06" end-if. + move 0 to u9. move -1 to s18. + if u9 <= s18 then display "ng 02-07" end-if. + move 0 to u9. move -3 to s18. + if u9 <= s18 then display "ng 02-08" end-if. + move 0 to u9. move -999999999999999999 to s18. + if u9 <= s18 then display "ng 02-09" end-if. + move 0 to u9. move 0 to s18. + if u9 <> s18 then display "ng 02-10" end-if. + move 0 to u9. move 1 to s18. + if u9 >= s18 then display "ng 02-11" end-if. + move 0 to u9. move 2 to s18. + if u9 >= s18 then display "ng 02-12" end-if. + move 0 to u9. move 3 to s18. + if u9 >= s18 then display "ng 02-13" end-if. + move 0 to u9. move 999999999999999999 to s18. + if u9 >= s18 then display "ng 02-14" end-if. + move 999999999 to u9. move -1 to s18. + if u9 <= s18 then display "ng 02-15" end-if. + move 999999999 to u9. move -3 to s18. + if u9 <= s18 then display "ng 02-16" end-if. + move 999999999 to u9. move -999999999999999999 to s18. + if u9 <= s18 then display "ng 02-17" end-if. + move 999999999 to u9. move 0 to s18. + if u9 <= s18 then display "ng 02-18" end-if. + move 999999999 to u9. move 1 to s18. + if u9 <= s18 then display "ng 02-19" end-if. + move 999999999 to u9. move 2 to s18. + if u9 <= s18 then display "ng 02-20" end-if. + move 999999999 to u9. move 999999999999999999 to s18. + if u9 >= s18 then display "ng 02-21" end-if. + ****************************************************************** + move 2 to u18. move -1 to s9. + if u18 <= s9 then display "ng 03-00" end-if. + move 2 to u18. move -3 to s9. + if u18 <= s9 then display "ng 03-01" end-if. + move 2 to u18. move -999999999 to s9. + if u18 <= s9 then display "ng 03-02" end-if. + move 2 to u18. move 0 to s9. + if u18 <= s9 then display "ng 03-03" end-if. + move 2 to u18. move 1 to s9. + if u18 <= s9 then display "ng 03-04" end-if. + move 2 to u18. move 2 to s9. + if u18 <> s9 then display "ng 03-05" end-if. + move 2 to u18. move 3 to s9. + if u18 >= s9 then display "ng 03-06" end-if. + move 2 to u18. move 999999999 to s9. + if u18 >= s9 then display "ng 03-06" end-if. + move 0 to u18. move -1 to s9. + if u18 <= s9 then display "ng 03-07" end-if. + move 0 to u18. move -3 to s9. + if u18 <= s9 then display "ng 03-08" end-if. + move 0 to u18. move -999999999 to s9. + if u18 <= s9 then display "ng 03-09" end-if. + move 0 to u18. move 0 to s9. + if u18 <> s9 then display "ng 03-10" end-if. + move 0 to u18. move 1 to s9. + if u18 >= s9 then display "ng 03-11" end-if. + move 0 to u18. move 2 to s9. + if u18 >= s9 then display "ng 03-12" end-if. + move 0 to u18. move 3 to s9. + if u18 >= s9 then display "ng 03-13" end-if. + move 0 to u18. move 999999999 to s9. + if u18 >= s9 then display "ng 03-14" end-if. + move 999999999999999999 to u18. move -1 to s9. + if u18 <= s9 then display "ng 03-15" end-if. + move 999999999999999999 to u18. move -3 to s9. + if u18 <= s9 then display "ng 03-16" end-if. + move 999999999999999999 to u18. move -999999999 to s9. + if u18 <= s9 then display "ng 03-17" end-if. + move 999999999999999999 to u18. move 0 to s9. + if u18 <= s9 then display "ng 03-18" end-if. + move 999999999999999999 to u18. move 1 to s9. + if u18 <= s9 then display "ng 03-19" end-if. + move 999999999999999999 to u18. move 2 to s9. + if u18 <= s9 then display "ng 03-20" end-if. + move 999999999999999999 to u18. move 999999999 to s9. + if u18 <= s9 then display "ng 03-21" end-if. + ****************************************************************** + move 2 to u18. move -1 to s18. + if u18 <= s18 then display "ng 04-00" end-if. + move 2 to u18. move -3 to s18. + if u18 <= s18 then display "ng 04-01" end-if. + move 2 to u18. move -999999999999999999 to s18. + if u18 <= s18 then display "ng 04-02" end-if. + move 2 to u18. move 0 to s18. + if u18 <= s18 then display "ng 04-03" end-if. + move 2 to u18. move 1 to s18. + if u18 <= s18 then display "ng 04-04" end-if. + move 2 to u18. move 2 to s18. + if u18 <> s18 then display "ng 04-05" end-if. + move 2 to u18. move 3 to s18. + if u18 >= s18 then display "ng 04-06" end-if. + move 2 to u18. move 999999999999999999 to s18. + if u18 >= s18 then display "ng 04-06" end-if. + move 0 to u18. move -1 to s18. + if u18 <= s18 then display "ng 04-07" end-if. + move 0 to u18. move -3 to s18. + if u18 <= s18 then display "ng 04-08" end-if. + move 0 to u18. move -999999999999999999 to s18. + if u18 <= s18 then display "ng 04-09" end-if. + move 0 to u18. move 0 to s18. + if u18 <> s18 then display "ng 04-10" end-if. + move 0 to u18. move 1 to s18. + if u18 >= s18 then display "ng 04-11" end-if. + move 0 to u18. move 2 to s18. + if u18 >= s18 then display "ng 04-12" end-if. + move 0 to u18. move 3 to s18. + if u18 >= s18 then display "ng 04-13" end-if. + move 0 to u18. move 999999999999999999 to s18. + if u18 >= s18 then display "ng 04-14" end-if. + move 999999999999999999 to u18. move -1 to s18. + if u18 <= s18 then display "ng 04-15" end-if. + move 999999999999999999 to u18. move -3 to s18. + if u18 <= s18 then display "ng 04-16" end-if. + move 999999999999999999 to u18. move -999999999999999999 to s18. + if u18 <= s18 then display "ng 04-17" end-if. + move 999999999999999999 to u18. move 0 to s18. + if u18 <= s18 then display "ng 04-18" end-if. + move 999999999999999999 to u18. move 1 to s18. + if u18 <= s18 then display "ng 04-19" end-if. + move 999999999999999999 to u18. move 2 to s18. + if u18 <= s18 then display "ng 04-20" end-if. + move 999999999999999999 to u18. move 999999999999999999 to s18. + if u18 <> s18 then display "ng 04-21" end-if. + ****************************************************************** + stop run. +]) + +AT_CHECK([${COMPILE} prog.cbl]) +AT_CHECK([java prog]) + +AT_CLEANUP + +AT_SETUP([COMP: WRITE AFTER LINE]) +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "FILE". + DATA DIVISION. + FILE SECTION. + FD F. + 01 F-REC PIC X(10). + WORKING-STORAGE SECTION. + 01 A PIC S9(6) COMP VALUE 0. + 01 REC PIC X(10). + PROCEDURE DIVISION. + WRITE F-REC FROM REC AFTER A LINE. + STOP RUN. +]) + +AT_CHECK([${COMPILE} prog.cbl]) + +AT_CLEANUP \ No newline at end of file diff --git a/tests/file-lock.at b/tests/file-lock.at new file mode 100644 index 00000000..24985fce --- /dev/null +++ b/tests/file-lock.at @@ -0,0 +1,13 @@ +AT_INIT([file-lock]) + +m4_include([lock-file.at]) +m4_include([access-same-record.at]) +m4_include([access-different-record.at]) +m4_include([input-mode.at]) +m4_include([same-process.at]) +m4_include([open-start-write-rewrite.at]) +m4_include([release-lock.at]) +m4_include([open-input.at]) +m4_include([lock-mode-clause.at]) +m4_include([lock-mode-automatic.at]) +m4_include([old-file.at]) diff --git a/tests/file-lock.src/access-different-record.at b/tests/file-lock.src/access-different-record.at new file mode 100644 index 00000000..52fccb2a --- /dev/null +++ b/tests/file-lock.src/access-different-record.at @@ -0,0 +1,368 @@ +AT_SETUP([Record locking of indexed files (different records)]) +AT_DATA([a.sh], [ +javac wait.java setValue.java + +OPERATION_READ="READ F." +OPERATION_READ_WITH_LOCK="READ F WITH LOCK." +OPERATION_READ_WITH_NO_LOCK="READ F WITH NO LOCK." +OPERATION_START="START F KEY IS = REC-KEY." +OPERATION_READ_NEXT_RECORD="START F KEY IS = REC-KEY. READ F NEXT RECORD." +OPERATION_READ_NEXT_RECORD_WITH_LOCK="START F KEY IS = REC-KEY. READ F NEXT RECORD WITH LOCK." +OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK="START F KEY IS = REC-KEY. READ F NEXT RECORD WITH NO LOCK." +OPERATION_WRITE="WRITE REC." +OPERATION_REWRITE="REWRITE REC." +OPERATION_DELETE="DELETE F." + +OPERATIONS=( + "OPERATION_READ" + "OPERATION_READ_WITH_LOCK" + "OPERATION_READ_WITH_NO_LOCK" + "OPERATION_START" + "OPERATION_READ_NEXT_RECORD" + "OPERATION_READ_NEXT_RECORD_WITH_LOCK" + "OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" + "OPERATION_WRITE" + "OPERATION_REWRITE" + "OPERATION_DELETE" +) + + +declare -A PROGRAM_ID_TABLE1 + +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ"@:>@="id_read1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_WITH_LOCK"@:>@="id_read_with_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_WITH_NO_LOCK"@:>@="id_read_with_no_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_START"@:>@="id_start" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_NEXT_RECORD"@:>@="id_read_next_rec1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_NEXT_RECORD_WITH_LOCK"@:>@="id_read_next_rec_with_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK"@:>@="id_read_next_rec_with_no_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_WRITE"@:>@="id_write1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_REWRITE"@:>@="id_rewrite1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_DELETE"@:>@="id_delete1" + +declare -A PROGRAM_ID_TABLE1_FOR_WRITE + +PROGRAM_ID_TABLE1_FOR_WRITE@<:@"$OPERATION_READ"@:>@="id_read1_write" +PROGRAM_ID_TABLE1_FOR_WRITE@<:@"$OPERATION_READ_WITH_LOCK"@:>@="id_read_lock1_write" +PROGRAM_ID_TABLE1_FOR_WRITE@<:@"$OPERATION_READ_WITH_NO_LOCK"@:>@="id_read_no_lock1_write" +PROGRAM_ID_TABLE1_FOR_WRITE@<:@"$OPERATION_START"@:>@="id_start_write" +PROGRAM_ID_TABLE1_FOR_WRITE@<:@"$OPERATION_READ_NEXT_RECORD"@:>@="id_read_next_rec1_write" +PROGRAM_ID_TABLE1_FOR_WRITE@<:@"$OPERATION_READ_NEXT_RECORD_WITH_LOCK"@:>@="id_read_next_rec_lock1_write" +PROGRAM_ID_TABLE1_FOR_WRITE@<:@"$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK"@:>@="id_read_next_rec_no_lock1_write" +PROGRAM_ID_TABLE1_FOR_WRITE@<:@"$OPERATION_WRITE"@:>@="id_write1_write" +PROGRAM_ID_TABLE1_FOR_WRITE@<:@"$OPERATION_REWRITE"@:>@="id_rewrite1_write" +PROGRAM_ID_TABLE1_FOR_WRITE@<:@"$OPERATION_DELETE"@:>@="id_delete1_write" + +declare -A PROGRAM_ID_TABLE2 + +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ"@:>@="id_read2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_WITH_LOCK"@:>@="id_read_with_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_WITH_NO_LOCK"@:>@="id_read_with_no_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_START"@:>@="id_start" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_NEXT_RECORD"@:>@="id_read_next_rec2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_NEXT_RECORD_WITH_LOCK"@:>@="id_read_next_rec_with_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK"@:>@="id_read_next_rec_with_no_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_WRITE"@:>@="id_write2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_REWRITE"@:>@="id_rewrite2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_DELETE"@:>@="id_delete2" + + +PROGRAM1_OPERATIONS=( + "$OPERATION_READ" + "$OPERATION_READ_WITH_LOCK" + "$OPERATION_READ_WITH_NO_LOCK" + "$OPERATION_READ_NEXT_RECORD" + "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" + "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" +) + +PROGRAM2_OPERATIONS=( + "$OPERATION_READ" + "$OPERATION_READ_WITH_LOCK" + "$OPERATION_READ_WITH_NO_LOCK" + "$OPERATION_READ_NEXT_RECORD" + "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" + "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" + "$OPERATION_START" + "$OPERATION_WRITE" + "$OPERATION_REWRITE" + "$OPERATION_DELETE" +) + +for operation in "${PROGRAM1_OPERATIONS@<:@@@:>@}"; do + cat prog1.template.cbl | + sed -e 's/@WRITE_RECORD@/MOVE "AAAA2BBBB2CCCC2" TO REC. WRITE REC./' |\ + sed -e "s/@OPERATION@/${operation}/" |\ + sed -e "s/@PROGRAM_ID@/${PROGRAM_ID_TABLE1@<:@${operation}@:>@}/" \ + > prog1.cbl + cobj prog1.cbl + + cat prog1.template.cbl | + sed -e 's/@WRITE_RECORD@//' |\ + sed -e "s/@OPERATION@/${operation}/" |\ + sed -e "s/@PROGRAM_ID@/${PROGRAM_ID_TABLE1_FOR_WRITE@<:@${operation}@:>@}/" \ + > prog1.cbl + cobj prog1.cbl +done + +for operation in "${PROGRAM2_OPERATIONS@<:@@@:>@}"; do + cat prog2.template.cbl | + sed -e "s/@OPERATION@/${operation}/" |\ + sed -e "s/@PROGRAM_ID@/${PROGRAM_ID_TABLE2@<:@${operation}@:>@}/" \ + > prog2.cbl + cobj prog2.cbl +done + +function run_test() { + if test "$1" == "" -o "$2" == "" -o "$3" == "" -o "$4" == "" -o "$5" == "" -o "$6" == ""; then + echo empty strings are in arguments + echo "\$1: $1" + echo "\$2: $2" + echo "\$3: $3" + echo "\$4: $4" + echo "\$5: $5" + echo "\$6: $6" + return 1 + fi + OPERATION1=$1 + OPERATION2=$2 + PROG1_STATUS=$3 + PROG2_STATUS=$4 + PROG2_MESSAGE=$5 + FINAL_RECORD_STATE=$6 + + rm -f playground-record-lock-* + + if test "$OPERATION2" == "$OPERATION_WRITE"; then + java -Xlog:perf+memops=off ${PROGRAM_ID_TABLE1_FOR_WRITE@<:@$OPERATION1@:>@} > prog1.log & + else + java -Xlog:perf+memops=off ${PROGRAM_ID_TABLE1@<:@$OPERATION1@:>@} > prog1.log & + fi + PID1=$! + java -Xlog:perf+memops=off ${PROGRAM_ID_TABLE2@<:@$OPERATION2@:>@} > prog2.log & + PID2=$! + + wait $PID1 $PID2 + + echo "$PROG1_STATUS" > prog1.expected.log + echo "$FINAL_RECORD_STATE" >> prog1.expected.log + + echo "$PROG2_STATUS" > prog2.expected.log + echo "$PROG2_MESSAGE" >> prog2.expected.log + + if ! diff prog1.log prog1.expected.log || ! diff prog2.log prog2.expected.log; then + echo "$OPERATION1, $OPERATION2, $PROG1_STATUS, $PROG2_STATUS, $PROG2_MESSAGE" + echo prog1.log === + cat prog1.log + echo prog1.expected.log === + cat prog1.expected.log + echo prog2.log === + cat prog2.log + echo prog2.expected.log === + cat prog2.expected.log + fi +} + +run_test "$OPERATION_READ" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_WRITE" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_REWRITE" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_DELETE" "00" "00" "not changed" "record not changed" + +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_WRITE" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_REWRITE" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_DELETE" "00" "00" "not changed" "record not changed" + +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_WRITE" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_REWRITE" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_DELETE" "00" "00" "not changed" "record not changed" + +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_WRITE" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_REWRITE" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_DELETE" "00" "00" "not changed" "record not changed" + +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_WRITE" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_REWRITE" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_DELETE" "00" "00" "not changed" "record not changed" + +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_WRITE" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_REWRITE" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_DELETE" "00" "00" "not changed" "record not changed" +]) + + +AT_CHECK([cp ../../file-lock.src/module-sync/wait.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/setValue.java .]) + +AT_DATA([prog1.template.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. @PROGRAM_ID@. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "f.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + * LOCK MODE IS AUTOMATIC + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 DUMMY PIC X(10) VALUE "DUMMY DATA". + PROCEDURE DIVISION. + MAIN-PROCEDURE. + OPEN OUTPUT f. + MOVE "AAAA1" TO REC-KEY. + MOVE "BBBB1" TO REC-KEY2. + MOVE "CCCC1" TO REC-DATA. + WRITE REC. + @WRITE_RECORD@ + CLOSE f. + + OPEN I-O f. + + MOVE "AAAA1" TO REC-KEY. + @OPERATION@ + + DISPLAY FILE-STATUS. + + CALL "setValue" USING + "playground-record-lock-01" + "AAAA1 record is locked". + CALL "wait" USING + "playground-record-lock-02" + "end of prog2". + CLOSE f. + + OPEN INPUT f. + MOVE "AAAA1" TO REC-KEY. + READ F. + + IF FILE-STATUS = "23" + DISPLAY "record deleted" + GO TO FINISH + END-IF. + + IF REC = "AAAA1_____*****" + DISPLAY "record rewritten" + GO TO FINISH + END-IF. + + IF REC = "AAAA1BBBB1CCCC1" + DISPLAY "record not changed" + ELSE + DISPLAY "unexpected: rec=" REC + END-IF. + + FINISH. + CLOSE f. + +]) + +AT_DATA([prog2.template.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. @PROGRAM_ID@. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "f.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 REC-BACKUP PIC X(15). + PROCEDURE DIVISION. + MAIN-PROCEDURE. + CALL "wait" USING + "playground-record-lock-01" + "AAAA1 record is locked". + + OPEN I-O f. + + INITIALIZE REC. + MOVE "AAAA2_____*****" TO REC. + MOVE REC TO REC-BACKUP. + + @OPERATION@ + + DISPLAY FILE-STATUS. + IF REC = REC-BACKUP + DISPLAY "not changed" + ELSE + DISPLAY "changed" + END-IF. + + CLOSE f. + + CALL "setValue" USING + "playground-record-lock-02" + "end of prog2". +]) + +AT_CHECK([bash a.sh]) +AT_CLEANUP + diff --git a/tests/file-lock.src/access-same-record.at b/tests/file-lock.src/access-same-record.at new file mode 100644 index 00000000..21e3414e --- /dev/null +++ b/tests/file-lock.src/access-same-record.at @@ -0,0 +1,340 @@ +AT_SETUP([Record locking of indexed files (same record)]) +AT_DATA([a.sh], [ +javac wait.java setValue.java + +OPERATION_READ="READ F." +OPERATION_READ_WITH_LOCK="READ F WITH LOCK." +OPERATION_READ_WITH_NO_LOCK="READ F WITH NO LOCK." +OPERATION_START="START F KEY IS = REC-KEY." +OPERATION_READ_NEXT_RECORD="START F KEY IS = REC-KEY. READ F NEXT RECORD." +OPERATION_READ_NEXT_RECORD_WITH_LOCK="START F KEY IS = REC-KEY. READ F NEXT RECORD WITH LOCK." +OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK="START F KEY IS = REC-KEY. READ F NEXT RECORD WITH NO LOCK." +OPERATION_WRITE="WRITE REC." +OPERATION_REWRITE="REWRITE REC." +OPERATION_DELETE="DELETE F." + +OPERATIONS=( + "OPERATION_READ" + "OPERATION_READ_WITH_LOCK" + "OPERATION_READ_WITH_NO_LOCK" + "OPERATION_START" + "OPERATION_READ_NEXT_RECORD" + "OPERATION_READ_NEXT_RECORD_WITH_LOCK" + "OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" + "OPERATION_WRITE" + "OPERATION_REWRITE" + "OPERATION_DELETE" +) + + +declare -A PROGRAM_ID_TABLE1 + +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ"@:>@="id_read1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_WITH_LOCK"@:>@="id_read_with_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_WITH_NO_LOCK"@:>@="id_read_with_no_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_START"@:>@="id_start" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_NEXT_RECORD"@:>@="id_read_next_rec1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_NEXT_RECORD_WITH_LOCK"@:>@="id_read_next_rec_with_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK"@:>@="id_read_next_rec_with_no_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_WRITE"@:>@="id_write1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_REWRITE"@:>@="id_rewrite1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_DELETE"@:>@="id_delete1" + +declare -A PROGRAM_ID_TABLE2 + +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ"@:>@="id_read2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_WITH_LOCK"@:>@="id_read_with_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_WITH_NO_LOCK"@:>@="id_read_with_no_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_START"@:>@="id_start" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_NEXT_RECORD"@:>@="id_read_next_rec2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_NEXT_RECORD_WITH_LOCK"@:>@="id_read_next_rec_with_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK"@:>@="id_read_next_rec_with_no_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_WRITE"@:>@="id_write2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_REWRITE"@:>@="id_rewrite2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_DELETE"@:>@="id_delete2" + + +PROGRAM1_OPERATIONS=( + "$OPERATION_READ" + "$OPERATION_READ_WITH_LOCK" + "$OPERATION_READ_WITH_NO_LOCK" + "$OPERATION_READ_NEXT_RECORD" + "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" + "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" +) + +PROGRAM2_OPERATIONS=( + "$OPERATION_READ" + "$OPERATION_READ_WITH_LOCK" + "$OPERATION_READ_WITH_NO_LOCK" + "$OPERATION_READ_NEXT_RECORD" + "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" + "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" + "$OPERATION_START" + "$OPERATION_WRITE" + "$OPERATION_REWRITE" + "$OPERATION_DELETE" +) + +for operation in "${PROGRAM1_OPERATIONS@<:@@@:>@}"; do + cat prog1.template.cbl | + sed -e "s/@OPERATION@/${operation}/" |\ + sed -e "s/@PROGRAM_ID@/${PROGRAM_ID_TABLE1@<:@${operation}@:>@}/" \ + > prog1.cbl + cobj prog1.cbl +done + +for operation in "${PROGRAM2_OPERATIONS@<:@@@:>@}"; do + cat prog2.template.cbl | + sed -e "s/@OPERATION@/${operation}/" |\ + sed -e "s/@PROGRAM_ID@/${PROGRAM_ID_TABLE2@<:@${operation}@:>@}/" \ + > prog2.cbl + cobj prog2.cbl +done + +function run_test() { + if test "$1" == "" -o "$2" == "" -o "$3" == "" -o "$4" == "" -o "$5" == "" -o "$6" == ""; then + echo empty strings are in arguments + echo "\$1: $1" + echo "\$2: $2" + echo "\$3: $3" + echo "\$4: $4" + echo "\$5: $5" + echo "\$6: $6" + return 1 + fi + OPERATION1=$1 + OPERATION2=$2 + PROG1_STATUS=$3 + PROG2_STATUS=$4 + PROG2_MESSAGE=$5 + FINAL_RECORD_STATE=$6 + + rm -f playground-record-lock-* + + java -Xlog:perf+memops=off ${PROGRAM_ID_TABLE1@<:@$OPERATION1@:>@} > prog1.log & + PID1=$! + java -Xlog:perf+memops=off ${PROGRAM_ID_TABLE2@<:@$OPERATION2@:>@} > prog2.log & + PID2=$! + + wait $PID1 $PID2 + + echo "$PROG1_STATUS" > prog1.expected.log + echo "$FINAL_RECORD_STATE" >> prog1.expected.log + + echo "$PROG2_STATUS" > prog2.expected.log + echo "$PROG2_MESSAGE" >> prog2.expected.log + + if ! diff prog1.log prog1.expected.log || ! diff prog2.log prog2.expected.log; then + echo "$OPERATION1, $OPERATION2, $PROG1_STATUS, $PROG2_STATUS, $PROG2_MESSAGE" + echo prog1.log === + cat prog1.log + echo prog1.expected.log === + cat prog1.expected.log + echo prog2.log === + cat prog2.log + echo prog2.expected.log === + cat prog2.expected.log + fi +} + +run_test "$OPERATION_READ" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_READ" "$OPERATION_DELETE" "00" "00" "not changed" "record deleted" + +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_REWRITE" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_DELETE" "00" "51" "not changed" "record not changed" + +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_DELETE" "00" "00" "not changed" "record deleted" + +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_DELETE" "00" "00" "not changed" "record deleted" + +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_REWRITE" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_DELETE" "00" "51" "not changed" "record not changed" + +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_DELETE" "00" "00" "not changed" "record deleted" +]) + + +AT_CHECK([cp ../../file-lock.src/module-sync/wait.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/setValue.java .]) + +AT_DATA([prog1.template.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. @PROGRAM_ID@. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "f.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + * LOCK MODE IS AUTOMATIC + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 DUMMY PIC X(10) VALUE "DUMMY DATA". + PROCEDURE DIVISION. + MAIN-PROCEDURE. + OPEN OUTPUT f. + MOVE "AAAA1" TO REC-KEY. + MOVE "BBBB1" TO REC-KEY2. + MOVE "CCCC1" TO REC-DATA. + WRITE REC. + CLOSE f. + + OPEN I-O f. + + MOVE "AAAA1" TO REC-KEY. + @OPERATION@ + + DISPLAY FILE-STATUS. + + CALL "setValue" USING + "playground-record-lock-01" + "AAAA1 record is locked". + CALL "wait" USING + "playground-record-lock-02" + "end of prog2". + CLOSE f. + + OPEN INPUT f. + MOVE "AAAA1" TO REC-KEY. + READ F. + + IF FILE-STATUS = "23" + DISPLAY "record deleted" + GO TO FINISH + END-IF. + + IF REC = "AAAA1_____*****" + DISPLAY "record rewritten" + GO TO FINISH + END-IF. + + IF REC = "AAAA1BBBB1CCCC1" + DISPLAY "record not changed" + ELSE + DISPLAY "unexpected: rec=" REC + END-IF. + + FINISH. + CLOSE f. +]) + +AT_DATA([prog2.template.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. @PROGRAM_ID@. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "f.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 REC-BACKUP PIC X(15). + PROCEDURE DIVISION. + MAIN-PROCEDURE. + CALL "wait" USING + "playground-record-lock-01" + "AAAA1 record is locked". + + OPEN I-O f. + + INITIALIZE REC. + MOVE "AAAA1_____*****" TO REC. + MOVE REC TO REC-BACKUP. + + @OPERATION@ + + DISPLAY FILE-STATUS. + IF REC = REC-BACKUP + DISPLAY "not changed" + ELSE + DISPLAY "changed" + END-IF. + + CLOSE f. + + CALL "setValue" USING + "playground-record-lock-02" + "end of prog2". +]) + +AT_CHECK([bash a.sh]) +AT_CLEANUP diff --git a/tests/file-lock.src/indexed-file/old_indexed_file.dat b/tests/file-lock.src/indexed-file/old_indexed_file.dat new file mode 100644 index 00000000..b9ce5729 Binary files /dev/null and b/tests/file-lock.src/indexed-file/old_indexed_file.dat differ diff --git a/tests/file-lock.src/input-mode.at b/tests/file-lock.src/input-mode.at new file mode 100644 index 00000000..0b6ae385 --- /dev/null +++ b/tests/file-lock.src/input-mode.at @@ -0,0 +1,318 @@ +AT_SETUP([Record locking of indexed files (input mode)]) +AT_DATA([a.sh], [ +javac wait.java setValue.java + +OPERATION_READ="READ F." +OPERATION_READ_WITH_LOCK="READ F WITH LOCK." +OPERATION_READ_WITH_NO_LOCK="READ F WITH NO LOCK." +OPERATION_START="START F KEY IS = REC-KEY." +OPERATION_READ_NEXT_RECORD="START F KEY IS = REC-KEY. READ F NEXT RECORD." +OPERATION_READ_NEXT_RECORD_WITH_LOCK="START F KEY IS = REC-KEY. READ F NEXT RECORD WITH LOCK." +OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK="START F KEY IS = REC-KEY. READ F NEXT RECORD WITH NO LOCK." +OPERATION_WRITE="WRITE REC." +OPERATION_REWRITE="REWRITE REC." +OPERATION_DELETE="DELETE F." + +OPERATIONS=( + "OPERATION_READ" + "OPERATION_READ_WITH_LOCK" + "OPERATION_READ_WITH_NO_LOCK" + "OPERATION_START" + "OPERATION_READ_NEXT_RECORD" + "OPERATION_READ_NEXT_RECORD_WITH_LOCK" + "OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" + "OPERATION_WRITE" + "OPERATION_REWRITE" + "OPERATION_DELETE" +) + + +declare -A PROGRAM_ID_TABLE1 + +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ"@:>@="id_read1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_WITH_LOCK"@:>@="id_read_with_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_WITH_NO_LOCK"@:>@="id_read_with_no_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_START"@:>@="id_start" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_NEXT_RECORD"@:>@="id_read_next_rec1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_NEXT_RECORD_WITH_LOCK"@:>@="id_read_next_rec_with_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK"@:>@="id_read_next_rec_with_no_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_WRITE"@:>@="id_write1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_REWRITE"@:>@="id_rewrite1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_DELETE"@:>@="id_delete1" + +declare -A PROGRAM_ID_TABLE2 + +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ"@:>@="id_read2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_WITH_LOCK"@:>@="id_read_with_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_WITH_NO_LOCK"@:>@="id_read_with_no_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_START"@:>@="id_start" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_NEXT_RECORD"@:>@="id_read_next_rec2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_NEXT_RECORD_WITH_LOCK"@:>@="id_read_next_rec_with_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK"@:>@="id_read_next_rec_with_no_lock2" + + +PROGRAM1_OPERATIONS=( + "$OPERATION_READ" + "$OPERATION_READ_WITH_LOCK" + "$OPERATION_READ_WITH_NO_LOCK" + "$OPERATION_READ_NEXT_RECORD" + "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" + "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" +) + +PROGRAM2_OPERATIONS=( + "$OPERATION_READ" + "$OPERATION_READ_WITH_LOCK" + "$OPERATION_READ_WITH_NO_LOCK" + "$OPERATION_READ_NEXT_RECORD" + "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" + "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" + "$OPERATION_START" +) + +for operation in "${PROGRAM1_OPERATIONS@<:@@@:>@}"; do + cat prog1.template.cbl | + sed -e "s/@OPERATION@/${operation}/" |\ + sed -e "s/@PROGRAM_ID@/${PROGRAM_ID_TABLE1@<:@${operation}@:>@}/" \ + > prog1.cbl + cobj prog1.cbl +done + +for operation in "${PROGRAM2_OPERATIONS@<:@@@:>@}"; do + cat prog2.template.cbl | + sed -e "s/@OPERATION@/${operation}/" |\ + sed -e "s/@PROGRAM_ID@/${PROGRAM_ID_TABLE2@<:@${operation}@:>@}/" \ + > prog2.cbl + cobj prog2.cbl +done + +function run_test() { + if test "$1" == "" -o "$2" == "" -o "$3" == "" -o "$4" == "" -o "$5" == "" -o "$6" == ""; then + echo empty strings are in arguments + echo "\$1: $1" + echo "\$2: $2" + echo "\$3: $3" + echo "\$4: $4" + echo "\$5: $5" + echo "\$6: $6" + return 1 + fi + OPERATION1=$1 + OPERATION2=$2 + PROG1_STATUS=$3 + PROG2_STATUS=$4 + PROG2_MESSAGE=$5 + FINAL_RECORD_STATE=$6 + + rm -f playground-record-lock-* + + java -Xlog:perf+memops=off ${PROGRAM_ID_TABLE1@<:@$OPERATION1@:>@} > prog1.log & + PID1=$! + java -Xlog:perf+memops=off ${PROGRAM_ID_TABLE2@<:@$OPERATION2@:>@} > prog2.log & + PID2=$! + + wait $PID1 $PID2 + + echo "$PROG1_STATUS" > prog1.expected.log + echo "$FINAL_RECORD_STATE" >> prog1.expected.log + + echo "$PROG2_STATUS" > prog2.expected.log + echo "$PROG2_MESSAGE" >> prog2.expected.log + + if ! diff prog1.log prog1.expected.log || ! diff prog2.log prog2.expected.log; then + echo "$OPERATION1, $OPERATION2, $PROG1_STATUS, $PROG2_STATUS, $PROG2_MESSAGE" + echo prog1.log === + cat prog1.log + echo prog1.expected.log === + cat prog1.expected.log + echo prog2.log === + cat prog2.log + echo prog2.expected.log === + cat prog2.expected.log + fi +} + +run_test "$OPERATION_READ" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" + +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" + +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" + +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" + +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" + +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" + +]) + + +AT_CHECK([cp ../../file-lock.src/module-sync/wait.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/setValue.java .]) + +AT_DATA([prog1.template.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. @PROGRAM_ID@. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "f.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + * LOCK MODE IS AUTOMATIC + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 DUMMY PIC X(10) VALUE "DUMMY DATA". + PROCEDURE DIVISION. + MAIN-PROCEDURE. + OPEN OUTPUT f. + MOVE "AAAA1" TO REC-KEY. + MOVE "BBBB1" TO REC-KEY2. + MOVE "CCCC1" TO REC-DATA. + WRITE REC. + CLOSE f. + + OPEN I-O f. + + MOVE "AAAA1" TO REC-KEY. + @OPERATION@ + + DISPLAY FILE-STATUS. + + CALL "setValue" USING + "playground-record-lock-01" + "AAAA1 record is locked". + CALL "wait" USING + "playground-record-lock-02" + "end of prog2". + CLOSE f. + + OPEN INPUT f. + MOVE "AAAA1" TO REC-KEY. + READ F. + + IF FILE-STATUS = "23" + DISPLAY "record deleted" + GO TO FINISH + END-IF. + + IF REC = "AAAA1_____*****" + DISPLAY "record rewritten" + GO TO FINISH + END-IF. + + IF REC = "AAAA1BBBB1CCCC1" + DISPLAY "record not changed" + ELSE + DISPLAY "unexpected: rec=" REC + END-IF. + + FINISH. + CLOSE f. + +]) + +AT_DATA([prog2.template.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. @PROGRAM_ID@. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "f.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 REC-BACKUP PIC X(15). + PROCEDURE DIVISION. + MAIN-PROCEDURE. + CALL "wait" USING + "playground-record-lock-01" + "AAAA1 record is locked". + + OPEN INPUT f. + + INITIALIZE REC. + MOVE "AAAA1_____*****" TO REC. + MOVE REC TO REC-BACKUP. + + @OPERATION@ + + DISPLAY FILE-STATUS. + IF REC = REC-BACKUP + DISPLAY "not changed" + ELSE + DISPLAY "changed" + END-IF. + + CLOSE f. + + CALL "setValue" USING + "playground-record-lock-02" + "end of prog2". +]) + +AT_CHECK([bash a.sh]) +AT_CLEANUP diff --git a/tests/file-lock.src/lock-file.at b/tests/file-lock.src/lock-file.at new file mode 100644 index 00000000..bfe47620 --- /dev/null +++ b/tests/file-lock.src/lock-file.at @@ -0,0 +1,543 @@ +AT_SETUP([File locking of indexed files]) +AT_DATA([make_indexed_file.cbl],[ + identification division. + program-id. make_indexed_file@@id@@. + + environment division. + input-output section. + + file-control. + select indexed-file + assign to external "indexed@@id@@.dat" + organization is indexed + record key is rec-key + file status is indexed-file-status. + + data division. + file section. + fd indexed-file. + 01 dup-record. + 05 rec-key pic x(5). + 05 rec-value pic x(5). + working-storage section. + 01 indexed-file-status pic 99. + procedure division. + main-procedure. + + open output indexed-file. + close indexed-file. +]) + +AT_DATA([prog1.cbl], [ + identification division. + program-id. prog1@@id@@. + + environment division. + input-output section. + + file-control. + select indexed-file + assign to "indexed@@id@@.dat" + organization is indexed + record key is rec-key + file status is indexed-file-status. + + select shared-file1 + assign to "shared1@@id@@.dat" + organization is sequential + file status is shared-file1-status. + + select shared-file2 + assign to "shared2@@id@@.dat" + organization is sequential + file status is shared-file2-status. + + data division. + file section. + fd indexed-file. + 01 dup-record. + 05 rec-key pic x(5). + 05 rec-value pic x(5). + fd shared-file1. + 01 shared-record1 pic x(10). + fd shared-file2. + 01 shared-record2 pic x(10). + working-storage section. + 01 indexed-file-status pic 99. + 01 shared-file1-status pic 99. + 01 shared-file2-status pic 99. + procedure division. + main-procedure. + + * open the indexed file before the other process does. + open @@open_mode@@ indexed-file. + + * Notify the other process that + * this process opened the indexed file. + open output shared-file1. + close shared-file1. + + * Wait for the other process to finish. + call "C$SLEEP" using 1. + perform forever + open input shared-file2 + if shared-file2-status = 0 + exit perform + end-if + close shared-file2 + call "C$SLEEP" using 1 + end-perform. + close shared-file2. + + * Close the indexed file after the other process has finished. + close indexed-file. +]) + +AT_DATA([prog2.cbl], [ + identification division. + program-id. prog2@@id@@. + + environment division. + input-output section. + + file-control. + select indexed-file + assign to "indexed@@id@@.dat" + organization is indexed + record key is rec-key + file status is indexed-file-status. + + select shared-file1 + assign to "shared1@@id@@.dat" + organization is sequential + file status is shared-file1-status. + + select shared-file2 + assign to "shared2@@id@@.dat" + organization is sequential + file status is shared-file2-status. + + data division. + file section. + fd indexed-file. + 01 dup-record. + 05 rec-key pic x(5). + 05 rec-value pic x(5). + fd shared-file1. + 01 shared-record1 pic x(10). + fd shared-file2. + 01 shared-record2 pic x(10). + working-storage section. + 01 indexed-file-status pic 99. + 01 shared-file1-status pic 99. + 01 shared-file2-status pic 99. + procedure division. + main-procedure. + + * Wait for the other process to open the indexed file. + call "C$SLEEP" using 1. + perform forever + open input shared-file1 + if shared-file1-status = 0 + close shared-file1 + exit perform + end-if + close shared-file1 + call "C$SLEEP" using 1 + end-perform. + + * Open the indexed file that another process has already opened. + open @@open_mode@@ indexed-file. + display indexed-file-status. + close indexed-file. + + * Notify the other process that + * this process finished. + open output shared-file2. + close shared-file2. +]) + +AT_DATA([run.sh], [ +#!/bin/bash + +function run_test() { + SEQ_NUMBER=$1 + OPEN_MODE_1=$2 + OPEN_MODE_2=$3 + EXPECTED_EXIT_CODE=$4 + + rm -f *.dat + + TEST_ID="$(echo "${OPEN_MODE_1}_${OPEN_MODE_2}" | sed 's/-/_/g')" + + PROGRAM_NAME_1="prog1${TEST_ID}" + PROGRAM_NAME_2="prog2${TEST_ID}" + + cat "prog1.cbl" | + sed "s/@@id@@/${TEST_ID}/g" | + sed "s/@@open_mode@@/${OPEN_MODE_1}/g" \ + > ${PROGRAM_NAME_1}.cbl + + cat "prog2.cbl" | + sed "s/@@id@@/${TEST_ID}/g" | + sed "s/@@open_mode@@/${OPEN_MODE_2}/g" \ + > ${PROGRAM_NAME_2}.cbl + + cat "make_indexed_file.cbl" | + sed "s/@@id@@/${TEST_ID}/g" \ + > make_indexed_file${TEST_ID}.cbl + + cobj ${PROGRAM_NAME_1}.cbl ${PROGRAM_NAME_2}.cbl make_indexed_file${TEST_ID}.cbl + + java -Xlog:perf+memops=off make_indexed_file${TEST_ID} + + java -Xlog:perf+memops=off $PROGRAM_NAME_1 & + PID1=$! + + java -Xlog:perf+memops=off $PROGRAM_NAME_2 > ${TEST_ID}.log & + PID2=$! + + wait $PID1 $PID2 + if test "$(cat ${TEST_ID}.log)" != "${EXPECTED_EXIT_CODE}"; then + echo "<${SEQ_NUMBER}> Test ${TEST_ID} failed. Expected exit code: ${EXPECTED_EXIT_CODE}, got: $(cat ${TEST_ID}.log)" \ + exit 1 + fi +} + +################################### + +run_test 00 INPUT INPUT 00 +run_test 01 INPUT OUTPUT 61 +run_test 02 INPUT I-O 00 +run_test 03 INPUT EXTEND 00 +run_test 04 OUTPUT INPUT 61 +run_test 05 OUTPUT OUTPUT 61 +run_test 06 OUTPUT I-O 61 +run_test 07 OUTPUT EXTEND 61 +run_test 08 I-O INPUT 00 +run_test 09 I-O OUTPUT 61 +run_test 10 I-O I-O 00 +run_test 11 I-O EXTEND 00 +run_test 12 EXTEND INPUT 00 +run_test 13 EXTEND OUTPUT 61 +run_test 14 EXTEND I-O 00 +run_test 15 EXTEND EXTEND 00 +]) + +AT_CHECK([bash run.sh]) +AT_CLEANUP + +AT_SETUP([File locking of SEQUENTIAL, LINE SEQUENTIAL and RELATIVE files]) +AT_DATA([prog1-template.cbl],[ + identification division. + program-id. + prog1_@@id@@. + environment division. + input-output section. + + file-control. + select f + assign to "file.dat" + organization is @@file_organization@@ + file status is f-status. + + select shared-file1 + assign to "shared1.dat" + organization is sequential + file status is shared-file1-status. + + select shared-file2 + assign to "shared2.dat" + organization is sequential + file status is shared-file2-status. + + data division. + file section. + fd f. + 01 f-record. + 05 rec-key pic x(5). + 05 rec-value pic x(5). + fd shared-file1. + 01 shared-record1 pic x(10). + fd shared-file2. + 01 shared-record2 pic x(10). + working-storage section. + 01 f-status pic 99. + 01 shared-file1-status pic 99. + 01 shared-file2-status pic 99. + procedure division. + main-procedure. + + * create the target file. + open output f. + close f. + + * open the target file before the other process does. + open @@open_mode@@ f. + + * Notify the other process that + * this process opened the target file. + open output shared-file1. + close shared-file1. + + * Wait for the other process to finish. + *call "C$SLEEP" using 1. + perform forever + open input shared-file2 + if shared-file2-status = 0 + exit perform + end-if + close shared-file2 + * call "C$SLEEP" using 1 + end-perform. + close shared-file2. + + * Close the target file after the other process has finished. + close f. +]) + +AT_DATA([prog2-template.cbl],[ + identification division. + program-id. + prog2_@@id@@. + environment division. + input-output section. + + file-control. + select f + assign to "file.dat" + organization is @@file_organization@@ + file status is f-status. + + select shared-file1 + assign to "shared1.dat" + organization is sequential + file status is shared-file1-status. + + select shared-file2 + assign to "shared2.dat" + organization is sequential + file status is shared-file2-status. + + data division. + file section. + fd f. + 01 f-record. + 05 rec-key pic x(5). + 05 rec-value pic x(5). + fd shared-file1. + 01 shared-record1 pic x(10). + fd shared-file2. + 01 shared-record2 pic x(10). + working-storage section. + 01 f-status pic 99. + 01 shared-file1-status pic 99. + 01 shared-file2-status pic 99. + procedure division. + main-procedure. + + * Wait for the other process to open the indexed file. + *call "C$SLEEP" using 1. + perform forever + open input shared-file1 + if shared-file1-status = 0 + close shared-file1 + exit perform + end-if + close shared-file1 + * call "C$SLEEP" using 1 + end-perform. + + * Open the target file that another process has already opened. + open @@open_mode@@ f. + display f-status. + close f. + + * Notify the other process that + * this process finished. + open output shared-file2. + close shared-file2. +]) + +AT_DATA([run.sh], [ +#!/bin/bash + +set -e + +COMPILER="cobj" +RUNNER="java -Xlog:perf+memops=off" + +rm -f file.dat shared1.dat shared2.dat + +function compile_all() { + for ORGANIZATION in "sequential" "line sequential" "relative"; do + for OPEN_MODE_1 in "INPUT" "OUTPUT" "I-O" "EXTEND"; do + for OPEN_MODE_2 in "INPUT" "OUTPUT" "I-O" "EXTEND"; do + ID=$(echo "${ORGANIZATION:0:1}_${OPEN_MODE_1}_${OPEN_MODE_2}" | sed 's/-/_/g') + PROGRAM_ID_1="prog1_${ID}" + PROGRAM_ID_2="prog2_${ID}" + PROGRAM1_FILE="${PROGRAM_ID_1}.cbl" + PROGRAM2_FILE="${PROGRAM_ID_2}.cbl" + + cat prog1-template.cbl | + sed "s/@@id@@/${ID}/g; s/@@file_organization@@/${ORGANIZATION}/g; s/@@open_mode@@/${OPEN_MODE_1}/g" \ + > "${PROGRAM1_FILE}" + cat prog2-template.cbl | + sed "s/@@id@@/${ID}/g; s/@@file_organization@@/${ORGANIZATION}/g; s/@@open_mode@@/${OPEN_MODE_2}/g" \ + > "${PROGRAM2_FILE}" + + "${COMPILER}" "${PROGRAM1_FILE}" "${PROGRAM2_FILE}" + done + done + done +} + +function run_test() { + ORGANIZATION="$1" + OPEN_MODE_1="$2" + OPEN_MODE_2="$3" + + ID=$(echo "${ORGANIZATION:0:1}_${OPEN_MODE_1}_${OPEN_MODE_2}" | sed 's/-/_/g') + PROGRAM_ID_1="prog1_${ID}" + PROGRAM_ID_2="prog2_${ID}" + PROGRAM1_FILE="${PROGRAM_ID_1}.cbl" + PROGRAM2_FILE="${PROGRAM_ID_2}.cbl" + PROGRAM1_LOG="${PROGRAM_ID_1}.log" + PROGRAM2_LOG="${PROGRAM_ID_2}.log" + + rm -f file.dat shared1.dat shared2.dat + + cat prog1-template.cbl | + sed "s/@@id@@/${ID}/g; s/@@file_organization@@/${ORGANIZATION}/g; s/@@open_mode@@/${OPEN_MODE_1}/g" \ + > "${PROGRAM1_FILE}" + cat prog2-template.cbl | + sed "s/@@id@@/${ID}/g; s/@@file_organization@@/${ORGANIZATION}/g; s/@@open_mode@@/${OPEN_MODE_2}/g" \ + > "${PROGRAM2_FILE}" + + "${COMPILER}" "${PROGRAM1_FILE}" "${PROGRAM2_FILE}" + + ${RUNNER} "${PROGRAM_ID_1}"& + PID1=$! + ${RUNNER} "${PROGRAM_ID_2}" > "${PROGRAM2_LOG}" & + PID2=$! + wait $PID1 $PID2 + + echo "${ORGANIZATION} - ${OPEN_MODE_1} & ${OPEN_MODE_2} - $(cat "${PROGRAM2_LOG}")" +} + +# First, compile all combinations +compile_all + +# Then, run a specific test case +run_test "sequential" "INPUT" "INPUT" +run_test "sequential" "INPUT" "OUTPUT" +run_test "sequential" "INPUT" "I-O" +run_test "sequential" "INPUT" "EXTEND" + +run_test "sequential" "OUTPUT" "INPUT" +run_test "sequential" "OUTPUT" "OUTPUT" +run_test "sequential" "OUTPUT" "I-O" +run_test "sequential" "OUTPUT" "EXTEND" + +run_test "sequential" "I-O" "INPUT" +run_test "sequential" "I-O" "OUTPUT" +run_test "sequential" "I-O" "I-O" +run_test "sequential" "I-O" "EXTEND" + +run_test "sequential" "EXTEND" "INPUT" +run_test "sequential" "EXTEND" "OUTPUT" +run_test "sequential" "EXTEND" "I-O" +run_test "sequential" "EXTEND" "EXTEND" + +run_test "line sequential" "INPUT" "INPUT" +run_test "line sequential" "INPUT" "OUTPUT" +run_test "line sequential" "INPUT" "I-O" +run_test "line sequential" "INPUT" "EXTEND" + +run_test "line sequential" "OUTPUT" "INPUT" +run_test "line sequential" "OUTPUT" "OUTPUT" +run_test "line sequential" "OUTPUT" "I-O" +run_test "line sequential" "OUTPUT" "EXTEND" + +run_test "line sequential" "I-O" "INPUT" +run_test "line sequential" "I-O" "OUTPUT" +run_test "line sequential" "I-O" "I-O" +run_test "line sequential" "I-O" "EXTEND" + +run_test "line sequential" "EXTEND" "INPUT" +run_test "line sequential" "EXTEND" "OUTPUT" +run_test "line sequential" "EXTEND" "I-O" +run_test "line sequential" "EXTEND" "EXTEND" + +run_test "relative" "INPUT" "INPUT" +run_test "relative" "INPUT" "OUTPUT" +run_test "relative" "INPUT" "I-O" +run_test "relative" "INPUT" "EXTEND" + +run_test "relative" "OUTPUT" "INPUT" +run_test "relative" "OUTPUT" "OUTPUT" +run_test "relative" "OUTPUT" "I-O" +run_test "relative" "OUTPUT" "EXTEND" + +run_test "relative" "I-O" "INPUT" +run_test "relative" "I-O" "OUTPUT" +run_test "relative" "I-O" "I-O" +run_test "relative" "I-O" "EXTEND" + +run_test "relative" "EXTEND" "INPUT" +run_test "relative" "EXTEND" "OUTPUT" +run_test "relative" "EXTEND" "I-O" +run_test "relative" "EXTEND" "EXTEND" +]) + +AT_CHECK([bash run.sh], [0], +[sequential - INPUT & INPUT - 00 +sequential - INPUT & OUTPUT - 61 +sequential - INPUT & I-O - 61 +sequential - INPUT & EXTEND - 61 +sequential - OUTPUT & INPUT - 61 +sequential - OUTPUT & OUTPUT - 61 +sequential - OUTPUT & I-O - 61 +sequential - OUTPUT & EXTEND - 61 +sequential - I-O & INPUT - 61 +sequential - I-O & OUTPUT - 61 +sequential - I-O & I-O - 61 +sequential - I-O & EXTEND - 61 +sequential - EXTEND & INPUT - 61 +sequential - EXTEND & OUTPUT - 61 +sequential - EXTEND & I-O - 61 +sequential - EXTEND & EXTEND - 61 +line sequential - INPUT & INPUT - 00 +line sequential - INPUT & OUTPUT - 61 +line sequential - INPUT & I-O - 61 +line sequential - INPUT & EXTEND - 61 +line sequential - OUTPUT & INPUT - 61 +line sequential - OUTPUT & OUTPUT - 61 +line sequential - OUTPUT & I-O - 61 +line sequential - OUTPUT & EXTEND - 61 +line sequential - I-O & INPUT - 61 +line sequential - I-O & OUTPUT - 61 +line sequential - I-O & I-O - 61 +line sequential - I-O & EXTEND - 61 +line sequential - EXTEND & INPUT - 61 +line sequential - EXTEND & OUTPUT - 61 +line sequential - EXTEND & I-O - 61 +line sequential - EXTEND & EXTEND - 61 +relative - INPUT & INPUT - 00 +relative - INPUT & OUTPUT - 61 +relative - INPUT & I-O - 61 +relative - INPUT & EXTEND - 61 +relative - OUTPUT & INPUT - 61 +relative - OUTPUT & OUTPUT - 61 +relative - OUTPUT & I-O - 61 +relative - OUTPUT & EXTEND - 61 +relative - I-O & INPUT - 61 +relative - I-O & OUTPUT - 61 +relative - I-O & I-O - 61 +relative - I-O & EXTEND - 61 +relative - EXTEND & INPUT - 61 +relative - EXTEND & OUTPUT - 61 +relative - EXTEND & I-O - 61 +relative - EXTEND & EXTEND - 61 +]) +AT_CLEANUP \ No newline at end of file diff --git a/tests/file-lock.src/lock-mode-automatic.at b/tests/file-lock.src/lock-mode-automatic.at new file mode 100644 index 00000000..f96c9eff --- /dev/null +++ b/tests/file-lock.src/lock-mode-automatic.at @@ -0,0 +1,348 @@ +AT_SETUP([-lock-mode-automatic]) +AT_DATA([a.sh], [ +javac wait.java setValue.java + +OPERATION_READ="READ F." +OPERATION_READ_WITH_LOCK="READ F WITH LOCK." +OPERATION_READ_WITH_NO_LOCK="READ F WITH NO LOCK." +OPERATION_START="START F KEY IS = REC-KEY." +OPERATION_READ_NEXT_RECORD="START F KEY IS = REC-KEY. READ F NEXT RECORD." +OPERATION_READ_NEXT_RECORD_WITH_LOCK="START F KEY IS = REC-KEY. READ F NEXT RECORD WITH LOCK." +OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK="START F KEY IS = REC-KEY. READ F NEXT RECORD WITH NO LOCK." +OPERATION_WRITE="WRITE REC." +OPERATION_REWRITE="REWRITE REC." +OPERATION_DELETE="DELETE F." +OPERATION_OPEN="INITIALIZE DUMMY." # dummy operation +OPERATION_CLOSE="CLOSE F." + +OPERATIONS=( + "OPERATION_READ" + "OPERATION_READ_WITH_LOCK" + "OPERATION_READ_WITH_NO_LOCK" + "OPERATION_START" + "OPERATION_READ_NEXT_RECORD" + "OPERATION_READ_NEXT_RECORD_WITH_LOCK" + "OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" + "OPERATION_WRITE" + "OPERATION_REWRITE" + "OPERATION_DELETE" + "OPERATION_OPEN" +) + + +declare -A PROGRAM_ID_TABLE1 + +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ"@:>@="id_read1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_WITH_LOCK"@:>@="id_read_with_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_WITH_NO_LOCK"@:>@="id_read_with_no_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_START"@:>@="id_start1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_NEXT_RECORD"@:>@="id_read_next_rec1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_NEXT_RECORD_WITH_LOCK"@:>@="id_read_next_rec_with_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK"@:>@="id_read_next_rec_with_no_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_WRITE"@:>@="id_write1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_REWRITE"@:>@="id_rewrite1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_DELETE"@:>@="id_delete1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_OPEN"@:>@="id_open1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_CLOSE"@:>@="id_close1" + +declare -A PROGRAM_ID_TABLE2 + +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ"@:>@="id_read2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_WITH_LOCK"@:>@="id_read_with_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_WITH_NO_LOCK"@:>@="id_read_with_no_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_START"@:>@="id_start2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_NEXT_RECORD"@:>@="id_read_next_rec2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_NEXT_RECORD_WITH_LOCK"@:>@="id_read_next_rec_with_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK"@:>@="id_read_next_rec_with_no_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_WRITE"@:>@="id_write2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_REWRITE"@:>@="id_rewrite2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_DELETE"@:>@="id_delete2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_OPEN"@:>@="id_open2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_CLOSE"@:>@="id_close2" + +PROGRAM1_OPERATIONS=( + "$OPERATION_READ" + "$OPERATION_READ_WITH_LOCK" + "$OPERATION_READ_WITH_NO_LOCK" + "$OPERATION_READ_NEXT_RECORD" + "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" + "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" +) + +PROGRAM2_OPERATIONS=( + "$OPERATION_READ" + "$OPERATION_READ_WITH_LOCK" + "$OPERATION_READ_WITH_NO_LOCK" + "$OPERATION_START" + "$OPERATION_READ_NEXT_RECORD" + "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" + "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" + "$OPERATION_WRITE" + "$OPERATION_REWRITE" + "$OPERATION_DELETE" +) + +for operation in "${PROGRAM1_OPERATIONS@<:@@@:>@}"; do + cat prog1.template.cbl | + sed -e "s/@OPERATION@/${operation}/" |\ + sed -e "s/@PROGRAM_ID@/${PROGRAM_ID_TABLE1@<:@${operation}@:>@}/" \ + > prog1.cbl + cobj prog1.cbl -lock-mode-automatic +done + +for operation in "${PROGRAM2_OPERATIONS@<:@@@:>@}"; do + cat prog2.template.cbl | + sed -e "s/@OPERATION@/${operation}/" |\ + sed -e "s/@PROGRAM_ID@/${PROGRAM_ID_TABLE2@<:@${operation}@:>@}/" \ + > prog2.cbl + cobj prog2.cbl +done + + +function run_test() { + if test "$1" == "" -o "$2" == "" -o "$3" == "" -o "$4" == "" -o "$5" == "" -o "$6" == ""; then + echo empty strings are in arguments + echo "\$1: $1" + echo "\$2: $2" + echo "\$3: $3" + echo "\$4: $4" + echo "\$5: $5" + echo "\$6: $6" + return 1 + fi + OPERATION1=$1 + OPERATION2=$2 + PROG1_STATUS=$3 + PROG2_STATUS=$4 + PROG2_MESSAGE=$5 + FINAL_RECORD_STATE=$6 + + rm -f playground-record-lock-* f.dat pro1.log prog2.log + + java -Xlog:perf+memops=off ${PROGRAM_ID_TABLE1@<:@$OPERATION1@:>@} > prog1.log & + PID1=$! + java -Xlog:perf+memops=off ${PROGRAM_ID_TABLE2@<:@$OPERATION2@:>@} > prog2.log & + PID2=$! + + wait $PID1 $PID2 + + echo "$PROG1_STATUS" > prog1.expected.log + echo "$FINAL_RECORD_STATE" >> prog1.expected.log + + echo "$PROG2_STATUS" > prog2.expected.log + echo "$PROG2_MESSAGE" >> prog2.expected.log + + if ! diff prog1.log prog1.expected.log || ! diff prog2.log prog2.expected.log; then + echo "$OPERATION1, $OPERATION2, $PROG1_STATUS, $PROG2_STATUS, $PROG2_MESSAGE" + echo prog1.log === + cat prog1.log + echo prog1.expected.log === + cat prog1.expected.log + echo prog2.log === + cat prog2.log + echo prog2.expected.log === + cat prog2.expected.log + fi +} + +run_test "$OPERATION_READ" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_WITH_LOCK" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_REWRITE" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_DELETE" "00" "51" "not changed" "record not changed" + +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_REWRITE" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_DELETE" "00" "51" "not changed" "record not changed" + +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_DELETE" "00" "00" "not changed" "record deleted" + +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_WITH_LOCK" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_REWRITE" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_DELETE" "00" "51" "not changed" "record not changed" + +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_REWRITE" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_DELETE" "00" "51" "not changed" "record not changed" + +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_DELETE" "00" "00" "not changed" "record deleted" +]) + + +AT_CHECK([cp ../../file-lock.src/module-sync/wait.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/setValue.java .]) + +AT_DATA([prog1.template.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. @PROGRAM_ID@. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "f.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 DUMMY PIC X(10) VALUE "DUMMY DATA". + PROCEDURE DIVISION. + MAIN-PROCEDURE. + OPEN OUTPUT f. + MOVE "AAAA1" TO REC-KEY. + MOVE "BBBB1" TO REC-KEY2. + MOVE "CCCC1" TO REC-DATA. + WRITE REC. + CLOSE f. + + OPEN I-O f. + + MOVE "AAAA1" TO REC-KEY. + @OPERATION@ + + DISPLAY FILE-STATUS. + + CALL "setValue" USING + "playground-record-lock-01" + "AAAA1 record is locked". + CALL "wait" USING + "playground-record-lock-02" + "end of prog2". + + CLOSE F. + + OPEN INPUT f. + MOVE "AAAA1" TO REC-KEY. + READ F. + + IF FILE-STATUS = "23" + DISPLAY "record deleted" + GO TO FINISH + END-IF. + + IF REC = "AAAA1_____*****" + DISPLAY "record rewritten" + GO TO FINISH + END-IF. + + IF REC = "AAAA1BBBB1CCCC1" + DISPLAY "record not changed" + ELSE + DISPLAY "unexpected: rec=" REC + END-IF. + + FINISH. + CLOSE f. + +]) + +AT_DATA([prog2.template.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. @PROGRAM_ID@. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "f.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 REC-BACKUP PIC X(15). + PROCEDURE DIVISION. + MAIN-PROCEDURE. + CALL "wait" USING + "playground-record-lock-01" + "AAAA1 record is locked". + + OPEN I-O f. + + INITIALIZE REC. + MOVE "AAAA1_____*****" TO REC. + MOVE REC TO REC-BACKUP. + @OPERATION@ + + DISPLAY FILE-STATUS. + + IF REC = REC-BACKUP + DISPLAY "not changed" + ELSE + DISPLAY "changed" + END-IF. + + CLOSE f. + + CALL "setValue" USING + "playground-record-lock-02" + "end of prog2". +]) + +AT_CHECK([bash a.sh]) +AT_CLEANUP diff --git a/tests/file-lock.src/lock-mode-clause.at b/tests/file-lock.src/lock-mode-clause.at new file mode 100644 index 00000000..0bb43e5e --- /dev/null +++ b/tests/file-lock.src/lock-mode-clause.at @@ -0,0 +1,427 @@ +AT_SETUP([LOCK MODE IS MANUAL/AUTOMATIC]) +AT_DATA([a.sh], [ +javac wait.java setValue.java + +OPERATION_READ="READ F." +OPERATION_READ_WITH_LOCK="READ F WITH LOCK." +OPERATION_READ_WITH_NO_LOCK="READ F WITH NO LOCK." +OPERATION_START="START F KEY IS = REC-KEY." +OPERATION_READ_NEXT_RECORD="START F KEY IS = REC-KEY. READ F NEXT RECORD." +OPERATION_READ_NEXT_RECORD_WITH_LOCK="START F KEY IS = REC-KEY. READ F NEXT RECORD WITH LOCK." +OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK="START F KEY IS = REC-KEY. READ F NEXT RECORD WITH NO LOCK." +OPERATION_WRITE="WRITE REC." +OPERATION_REWRITE="REWRITE REC." +OPERATION_DELETE="DELETE F." +OPERATION_OPEN="INITIALIZE DUMMY." # dummy operation +OPERATION_CLOSE="CLOSE F." + +OPERATIONS=( + "OPERATION_READ" + "OPERATION_READ_WITH_LOCK" + "OPERATION_READ_WITH_NO_LOCK" + "OPERATION_START" + "OPERATION_READ_NEXT_RECORD" + "OPERATION_READ_NEXT_RECORD_WITH_LOCK" + "OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" + "OPERATION_WRITE" + "OPERATION_REWRITE" + "OPERATION_DELETE" + "OPERATION_OPEN" +) + + +declare -A PROGRAM_ID_TABLE1 + +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ"@:>@="id_read1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_WITH_LOCK"@:>@="id_read_with_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_WITH_NO_LOCK"@:>@="id_read_with_no_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_START"@:>@="id_start1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_NEXT_RECORD"@:>@="id_read_next_rec1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_NEXT_RECORD_WITH_LOCK"@:>@="id_read_next_rec_with_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK"@:>@="id_read_next_rec_with_no_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_WRITE"@:>@="id_write1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_REWRITE"@:>@="id_rewrite1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_DELETE"@:>@="id_delete1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_OPEN"@:>@="id_open1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_CLOSE"@:>@="id_close1" + +declare -A PROGRAM_ID_TABLE2 + +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ"@:>@="id_read2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_WITH_LOCK"@:>@="id_read_with_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_WITH_NO_LOCK"@:>@="id_read_with_no_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_START"@:>@="id_start2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_NEXT_RECORD"@:>@="id_read_next_rec2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_NEXT_RECORD_WITH_LOCK"@:>@="id_read_next_rec_with_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK"@:>@="id_read_next_rec_with_no_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_WRITE"@:>@="id_write2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_REWRITE"@:>@="id_rewrite2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_DELETE"@:>@="id_delete2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_OPEN"@:>@="id_open2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_CLOSE"@:>@="id_close2" + +PROGRAM1_OPERATIONS=( + "$OPERATION_READ" + "$OPERATION_READ_WITH_LOCK" + "$OPERATION_READ_WITH_NO_LOCK" + "$OPERATION_READ_NEXT_RECORD" + "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" + "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" +) + +PROGRAM2_OPERATIONS=( + "$OPERATION_READ" + "$OPERATION_READ_WITH_LOCK" + "$OPERATION_READ_WITH_NO_LOCK" + "$OPERATION_START" + "$OPERATION_READ_NEXT_RECORD" + "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" + "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" + "$OPERATION_WRITE" + "$OPERATION_REWRITE" + "$OPERATION_DELETE" +) + +for operation in "${PROGRAM1_OPERATIONS@<:@@@:>@}"; do + cat prog1.template.cbl | + sed -e "s/@OPERATION@/${operation}/" |\ + sed -e "s/@LOCK-MODE@/MANUAL/" |\ + sed -e "s/@PROGRAM_ID@/${PROGRAM_ID_TABLE1@<:@${operation}@:>@}/" \ + > prog1.cbl + cobj prog1.cbl +done + +for operation in "${PROGRAM2_OPERATIONS@<:@@@:>@}"; do + cat prog2.template.cbl | + sed -e "s/@OPERATION@/${operation}/" |\ + sed -e "s/@PROGRAM_ID@/${PROGRAM_ID_TABLE2@<:@${operation}@:>@}/" \ + > prog2.cbl + cobj prog2.cbl +done + + +function run_test() { + if test "$1" == "" -o "$2" == "" -o "$3" == "" -o "$4" == "" -o "$5" == "" -o "$6" == ""; then + echo empty strings are in arguments + echo "\$1: $1" + echo "\$2: $2" + echo "\$3: $3" + echo "\$4: $4" + echo "\$5: $5" + echo "\$6: $6" + return 1 + fi + OPERATION1=$1 + OPERATION2=$2 + PROG1_STATUS=$3 + PROG2_STATUS=$4 + PROG2_MESSAGE=$5 + FINAL_RECORD_STATE=$6 + + rm -f playground-record-lock-* f.dat pro1.log prog2.log + + java -Xlog:perf+memops=off ${PROGRAM_ID_TABLE1@<:@$OPERATION1@:>@} > prog1.log & + PID1=$! + java -Xlog:perf+memops=off ${PROGRAM_ID_TABLE2@<:@$OPERATION2@:>@} > prog2.log & + PID2=$! + + wait $PID1 $PID2 + + echo "$PROG1_STATUS" > prog1.expected.log + echo "$FINAL_RECORD_STATE" >> prog1.expected.log + + echo "$PROG2_STATUS" > prog2.expected.log + echo "$PROG2_MESSAGE" >> prog2.expected.log + + if ! diff prog1.log prog1.expected.log || ! diff prog2.log prog2.expected.log; then + echo "$OPERATION1, $OPERATION2, $PROG1_STATUS, $PROG2_STATUS, $PROG2_MESSAGE" + echo prog1.log === + cat prog1.log + echo prog1.expected.log === + cat prog1.expected.log + echo prog2.log === + cat prog2.log + echo prog2.expected.log === + cat prog2.expected.log + fi +} + +run_test "$OPERATION_READ" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_READ" "$OPERATION_DELETE" "00" "00" "not changed" "record deleted" + +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_REWRITE" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_DELETE" "00" "51" "not changed" "record not changed" + +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_DELETE" "00" "00" "not changed" "record deleted" + +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_DELETE" "00" "00" "not changed" "record deleted" + +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_REWRITE" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_DELETE" "00" "51" "not changed" "record not changed" + +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_DELETE" "00" "00" "not changed" "record deleted" + +# Compile programs with automatic locking +for operation in "${PROGRAM1_OPERATIONS@<:@@@:>@}"; do + cat prog1.template.cbl | + sed -e "s/@OPERATION@/${operation}/" |\ + sed -e "s/@LOCK-MODE@/AUTOMATIC/" |\ + sed -e "s/@PROGRAM_ID@/${PROGRAM_ID_TABLE1@<:@${operation}@:>@}/" \ + > prog1.cbl + cobj prog1.cbl +done + +run_test "$OPERATION_READ" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_WITH_LOCK" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_REWRITE" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ" "$OPERATION_DELETE" "00" "51" "not changed" "record not changed" + +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_REWRITE" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_DELETE" "00" "51" "not changed" "record not changed" + +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_DELETE" "00" "00" "not changed" "record deleted" + +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_WITH_LOCK" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_REWRITE" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_DELETE" "00" "51" "not changed" "record not changed" + +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_REWRITE" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_DELETE" "00" "51" "not changed" "record not changed" + +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_DELETE" "00" "00" "not changed" "record deleted" +]) + + +AT_CHECK([cp ../../file-lock.src/module-sync/wait.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/setValue.java .]) + +AT_DATA([prog1.template.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. @PROGRAM_ID@. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "f.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + LOCK MODE IS @LOCK-MODE@ + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 DUMMY PIC X(10) VALUE "DUMMY DATA". + PROCEDURE DIVISION. + MAIN-PROCEDURE. + OPEN OUTPUT f. + MOVE "AAAA1" TO REC-KEY. + MOVE "BBBB1" TO REC-KEY2. + MOVE "CCCC1" TO REC-DATA. + WRITE REC. + CLOSE f. + + OPEN I-O f. + + MOVE "AAAA1" TO REC-KEY. + @OPERATION@ + + DISPLAY FILE-STATUS. + + CALL "setValue" USING + "playground-record-lock-01" + "AAAA1 record is locked". + CALL "wait" USING + "playground-record-lock-02" + "end of prog2". + + CLOSE F. + + OPEN INPUT f. + MOVE "AAAA1" TO REC-KEY. + READ F. + + IF FILE-STATUS = "23" + DISPLAY "record deleted" + GO TO FINISH + END-IF. + + IF REC = "AAAA1_____*****" + DISPLAY "record rewritten" + GO TO FINISH + END-IF. + + IF REC = "AAAA1BBBB1CCCC1" + DISPLAY "record not changed" + ELSE + DISPLAY "unexpected: rec=" REC + END-IF. + + FINISH. + CLOSE f. + +]) + +AT_DATA([prog2.template.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. @PROGRAM_ID@. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "f.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + LOCK MODE IS MANUAL + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 REC-BACKUP PIC X(15). + PROCEDURE DIVISION. + MAIN-PROCEDURE. + CALL "wait" USING + "playground-record-lock-01" + "AAAA1 record is locked". + + OPEN I-O f. + + INITIALIZE REC. + MOVE "AAAA1_____*****" TO REC. + MOVE REC TO REC-BACKUP. + @OPERATION@ + + DISPLAY FILE-STATUS. + + IF REC = REC-BACKUP + DISPLAY "not changed" + ELSE + DISPLAY "changed" + END-IF. + + CLOSE f. + + CALL "setValue" USING + "playground-record-lock-02" + "end of prog2". +]) + +AT_CHECK([bash a.sh]) +AT_CLEANUP \ No newline at end of file diff --git a/tests/file-lock.src/module-sync/setValue.java b/tests/file-lock.src/module-sync/setValue.java new file mode 100644 index 00000000..716dda2e --- /dev/null +++ b/tests/file-lock.src/module-sync/setValue.java @@ -0,0 +1,48 @@ +import java.io.UnsupportedEncodingException; +import jp.osscons.opensourcecobol.libcobj.*; +import jp.osscons.opensourcecobol.libcobj.common.*; +import jp.osscons.opensourcecobol.libcobj.data.*; +import jp.osscons.opensourcecobol.libcobj.exceptions.*; +import jp.osscons.opensourcecobol.libcobj.termio.*; +import jp.osscons.opensourcecobol.libcobj.call.*; +import jp.osscons.opensourcecobol.libcobj.file.*; +import jp.osscons.opensourcecobol.libcobj.ui.*; +import java.util.Optional; +import java.io.BufferedWriter; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.util.HashMap; +import java.util.Map; +import java.io.FileNotFoundException; + +public class setValue implements CobolRunnable { + private static Map namedPipeWriters = new HashMap<>(); + @Override + public int run(CobolDataStorage... argStorages) { + AbstractCobolField NamedPipeField = CobolModule.getCurrentModule().cob_procedure_parameters.get(0); + AbstractCobolField valueField = CobolModule.getCurrentModule().cob_procedure_parameters.get(1); + String namedPipe = NamedPipeField.getString().trim(); + String value = valueField.getString().trim(); + + try(BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(namedPipe)))){ + writer.write(value); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + return -1; + } + + return 0; + } + + @Override + public void cancel() { + return; + } + + @Override + public boolean isActive() { + return false; + } +} \ No newline at end of file diff --git a/tests/file-lock.src/module-sync/wait.java b/tests/file-lock.src/module-sync/wait.java new file mode 100644 index 00000000..89471eca --- /dev/null +++ b/tests/file-lock.src/module-sync/wait.java @@ -0,0 +1,69 @@ +import java.io.UnsupportedEncodingException; +import jp.osscons.opensourcecobol.libcobj.*; +import jp.osscons.opensourcecobol.libcobj.common.*; +import jp.osscons.opensourcecobol.libcobj.data.*; +import jp.osscons.opensourcecobol.libcobj.exceptions.*; +import jp.osscons.opensourcecobol.libcobj.termio.*; +import jp.osscons.opensourcecobol.libcobj.call.*; +import jp.osscons.opensourcecobol.libcobj.file.*; +import jp.osscons.opensourcecobol.libcobj.ui.*; +import java.util.Optional; +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Map; +import java.io.FileNotFoundException; + +public class wait implements CobolRunnable { + private static Map namedPipeReaders = new HashMap<>(); + @Override + public int run(CobolDataStorage... argStorages) { + AbstractCobolField namedPipeField = CobolModule.getCurrentModule().cob_procedure_parameters.get(0); + AbstractCobolField valueField = CobolModule.getCurrentModule().cob_procedure_parameters.get(1); + String namedPipe = namedPipeField.getString().trim(); + String value = valueField.getString().trim(); + + while(true) { + try(BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(namedPipe)))) { + + String line; + while ((line = reader.readLine()) != null) { + if (line.equals(value)) { + return 0; + } else { + Thread.sleep(200); + continue; + } + } + } catch (FileNotFoundException e) { + try { + Thread.sleep(200); + } catch (InterruptedException ie) { + ie.printStackTrace(); + Thread.currentThread().interrupt(); + return -1; + } + continue; + } catch (IOException e) { + e.printStackTrace(); + return -1; + } catch (InterruptedException e) { + e.printStackTrace(); + Thread.currentThread().interrupt(); + return -1; + } + } + } + + @Override + public void cancel() { + return; + } + + @Override + public boolean isActive() { + return false; + } +} \ No newline at end of file diff --git a/tests/file-lock.src/old-file.at b/tests/file-lock.src/old-file.at new file mode 100644 index 00000000..8e2ab9e3 --- /dev/null +++ b/tests/file-lock.src/old-file.at @@ -0,0 +1,53 @@ +AT_SETUP([old file]) +AT_DATA([open_file_status.at], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. open_file_status. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "indexed_file.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + PROCEDURE DIVISION. + MAIN-PROCEDURE. + OPEN INPUT f. + DISPLAY FILE-STATUS. + CLOSE f. + + OPEN I-O f. + DISPLAY FILE-STATUS. + CLOSE f. + + OPEN EXTEND f. + DISPLAY FILE-STATUS. + CLOSE f. + + OPEN OUTPUT f. + DISPLAY FILE-STATUS. + CLOSE f. +]) + +AT_CHECK([${COBJ} open_file_status.at]) +AT_CHECK([cp ../../file-lock.src/indexed-file/old_indexed_file.dat indexed_file.dat]) +AT_CHECK([java -Xlog:perf+memops=off open_file_status], [0], +[92 +92 +92 +92 +]) +AT_CLEANUP \ No newline at end of file diff --git a/tests/file-lock.src/open-input.at b/tests/file-lock.src/open-input.at new file mode 100644 index 00000000..65941cb2 --- /dev/null +++ b/tests/file-lock.src/open-input.at @@ -0,0 +1,303 @@ +AT_SETUP([READ with OPEN INPUT cannot lock record]) +AT_DATA([a.sh], [ +javac wait.java setValue.java + +OPERATION_READ="READ F." +OPERATION_READ_WITH_LOCK="READ F WITH LOCK." +OPERATION_READ_WITH_NO_LOCK="READ F WITH NO LOCK." +OPERATION_START="START F KEY IS = REC-KEY." +OPERATION_READ_NEXT_RECORD="START F KEY IS = REC-KEY. READ F NEXT RECORD." +OPERATION_READ_NEXT_RECORD_WITH_LOCK="START F KEY IS = REC-KEY. READ F NEXT RECORD WITH LOCK." +OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK="START F KEY IS = REC-KEY. READ F NEXT RECORD WITH NO LOCK." +OPERATION_WRITE="WRITE REC." +OPERATION_REWRITE="REWRITE REC." +OPERATION_DELETE="DELETE F." +OPERATION_OPEN="INITIALIZE DUMMY." # dummy operation +OPERATION_CLOSE="CLOSE F." + +OPERATIONS=( + "OPERATION_READ" + "OPERATION_READ_WITH_LOCK" + "OPERATION_READ_WITH_NO_LOCK" + "OPERATION_START" + "OPERATION_READ_NEXT_RECORD" + "OPERATION_READ_NEXT_RECORD_WITH_LOCK" + "OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" + "OPERATION_WRITE" + "OPERATION_REWRITE" + "OPERATION_DELETE" + "OPERATION_OPEN" +) + + +declare -A PROGRAM_ID_TABLE1 + +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ"@:>@="id_read1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_WITH_LOCK"@:>@="id_read_with_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_WITH_NO_LOCK"@:>@="id_read_with_no_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_START"@:>@="id_start1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_NEXT_RECORD"@:>@="id_read_next_rec1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_NEXT_RECORD_WITH_LOCK"@:>@="id_read_next_rec_with_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK"@:>@="id_read_next_rec_with_no_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_WRITE"@:>@="id_write1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_REWRITE"@:>@="id_rewrite1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_DELETE"@:>@="id_delete1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_OPEN"@:>@="id_open1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_CLOSE"@:>@="id_close1" + +declare -A PROGRAM_ID_TABLE2 + +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ"@:>@="id_read2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_WITH_LOCK"@:>@="id_read_with_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_WITH_NO_LOCK"@:>@="id_read_with_no_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_START"@:>@="id_start2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_NEXT_RECORD"@:>@="id_read_next_rec2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_NEXT_RECORD_WITH_LOCK"@:>@="id_read_next_rec_with_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK"@:>@="id_read_next_rec_with_no_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_WRITE"@:>@="id_write2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_REWRITE"@:>@="id_rewrite2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_DELETE"@:>@="id_delete2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_OPEN"@:>@="id_open2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_CLOSE"@:>@="id_close2" + +PROGRAM1_OPERATIONS=( + "$OPERATION_READ_WITH_LOCK" + "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" +) + +PROGRAM2_OPERATIONS=( + "$OPERATION_READ" + "$OPERATION_READ_WITH_LOCK" + "$OPERATION_READ_WITH_NO_LOCK" + "$OPERATION_START" + "$OPERATION_READ_NEXT_RECORD" + "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" + "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" + "$OPERATION_WRITE" + "$OPERATION_REWRITE" + "$OPERATION_DELETE" +) + +for operation in "${PROGRAM1_OPERATIONS@<:@@@:>@}"; do + cat prog1.template.cbl | + sed -e "s/@OPERATION@/${operation}/" |\ + sed -e "s/@PROGRAM_ID@/${PROGRAM_ID_TABLE1@<:@${operation}@:>@}/" \ + > prog1.cbl + cobj prog1.cbl +done + +for operation in "${PROGRAM2_OPERATIONS@<:@@@:>@}"; do + cat prog2.template.cbl | + sed -e "s/@OPERATION@/${operation}/" |\ + sed -e "s/@PROGRAM_ID@/${PROGRAM_ID_TABLE2@<:@${operation}@:>@}/" \ + > prog2.cbl + cobj prog2.cbl +done + + +function run_test() { + if test "$1" == "" -o "$2" == "" -o "$3" == "" -o "$4" == "" -o "$5" == "" -o "$6" == ""; then + echo empty strings are in arguments + echo "\$1: $1" + echo "\$2: $2" + echo "\$3: $3" + echo "\$4: $4" + echo "\$5: $5" + echo "\$6: $6" + return 1 + fi + OPERATION1=$1 + OPERATION2=$2 + PROG1_STATUS=$3 + PROG2_STATUS=$4 + PROG2_MESSAGE=$5 + FINAL_RECORD_STATE=$6 + + rm -f playground-record-lock-* f.dat pro1.log prog2.log + + java -Xlog:perf+memops=off ${PROGRAM_ID_TABLE1@<:@$OPERATION1@:>@} > prog1.log & + PID1=$! + java -Xlog:perf+memops=off ${PROGRAM_ID_TABLE2@<:@$OPERATION2@:>@} > prog2.log & + PID2=$! + + wait $PID1 $PID2 + + echo "$PROG1_STATUS" > prog1.expected.log + echo "$FINAL_RECORD_STATE" >> prog1.expected.log + + echo "$PROG2_STATUS" > prog2.expected.log + echo "$PROG2_MESSAGE" >> prog2.expected.log + + if ! diff prog1.log prog1.expected.log || ! diff prog2.log prog2.expected.log; then + echo "$OPERATION1, $OPERATION2, $PROG1_STATUS, $PROG2_STATUS, $PROG2_MESSAGE" + echo prog1.log === + cat prog1.log + echo prog1.expected.log === + cat prog1.expected.log + echo prog2.log === + cat prog2.log + echo prog2.expected.log === + cat prog2.expected.log + fi +} + +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_DELETE" "00" "00" "not changed" "record deleted" + +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_DELETE" "00" "00" "not changed" "record deleted" +]) + + +AT_CHECK([cp ../../file-lock.src/module-sync/wait.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/setValue.java .]) + +AT_DATA([prog1.template.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. @PROGRAM_ID@. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "f.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + * LOCK MODE IS AUTOMATIC + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 DUMMY PIC X(10) VALUE "DUMMY DATA". + PROCEDURE DIVISION. + MAIN-PROCEDURE. + OPEN OUTPUT f. + MOVE "AAAA1" TO REC-KEY. + MOVE "BBBB1" TO REC-KEY2. + MOVE "CCCC1" TO REC-DATA. + WRITE REC. + CLOSE f. + + OPEN INPUT f. + + MOVE "AAAA1" TO REC-KEY. + @OPERATION@ + + DISPLAY FILE-STATUS. + + CALL "setValue" USING + "playground-record-lock-01" + "AAAA1 record is locked". + CALL "wait" USING + "playground-record-lock-02" + "end of prog2". + + CLOSE F. + + OPEN INPUT f. + MOVE "AAAA1" TO REC-KEY. + READ F. + + IF FILE-STATUS = "23" + DISPLAY "record deleted" + GO TO FINISH + END-IF. + + IF REC = "AAAA1_____*****" + DISPLAY "record rewritten" + GO TO FINISH + END-IF. + + IF REC = "AAAA1BBBB1CCCC1" + DISPLAY "record not changed" + ELSE + DISPLAY "unexpected: rec=" REC + END-IF. + + FINISH. + CLOSE f. + +]) + +AT_DATA([prog2.template.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. @PROGRAM_ID@. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "f.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 REC-BACKUP PIC X(15). + PROCEDURE DIVISION. + MAIN-PROCEDURE. + CALL "wait" USING + "playground-record-lock-01" + "AAAA1 record is locked". + + OPEN I-O f. + + INITIALIZE REC. + MOVE "AAAA1_____*****" TO REC. + MOVE REC TO REC-BACKUP. + @OPERATION@ + + DISPLAY FILE-STATUS. + + IF REC = REC-BACKUP + DISPLAY "not changed" + ELSE + DISPLAY "changed" + END-IF. + + CLOSE f. + + CALL "setValue" USING + "playground-record-lock-02" + "end of prog2". + +]) + +AT_CHECK([bash a.sh]) +AT_CLEANUP + diff --git a/tests/file-lock.src/open-start-write-rewrite.at b/tests/file-lock.src/open-start-write-rewrite.at new file mode 100644 index 00000000..aa5e9b16 --- /dev/null +++ b/tests/file-lock.src/open-start-write-rewrite.at @@ -0,0 +1,333 @@ +AT_SETUP([OPEN,START,WRITE,REWRITE cannot lock indexed file records]) +AT_DATA([a.sh], [ + +javac wait.java setValue.java + +OPERATION_READ="READ F." +OPERATION_READ_WITH_LOCK="READ F WITH LOCK." +OPERATION_READ_WITH_NO_LOCK="READ F WITH NO LOCK." +OPERATION_START="START F KEY IS = REC-KEY." +OPERATION_READ_NEXT_RECORD="START F KEY IS = REC-KEY. READ F NEXT RECORD." +OPERATION_READ_NEXT_RECORD_WITH_LOCK="START F KEY IS = REC-KEY. READ F NEXT RECORD WITH LOCK." +OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK="START F KEY IS = REC-KEY. READ F NEXT RECORD WITH NO LOCK." +OPERATION_WRITE="WRITE REC." +OPERATION_REWRITE="REWRITE REC." +OPERATION_DELETE="DELETE F." +OPERATION_OPEN="INITIALIZE DUMMY." # dummy operation + +OPERATIONS=( + "OPERATION_READ" + "OPERATION_READ_WITH_LOCK" + "OPERATION_READ_WITH_NO_LOCK" + "OPERATION_START" + "OPERATION_READ_NEXT_RECORD" + "OPERATION_READ_NEXT_RECORD_WITH_LOCK" + "OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" + "OPERATION_WRITE" + "OPERATION_REWRITE" + "OPERATION_DELETE" + "OPERATION_OPEN" +) + + +declare -A PROGRAM_ID_TABLE1 + +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ"@:>@="id_read1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_WITH_LOCK"@:>@="id_read_with_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_WITH_NO_LOCK"@:>@="id_read_with_no_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_START"@:>@="id_start1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_NEXT_RECORD"@:>@="id_read_next_rec1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_NEXT_RECORD_WITH_LOCK"@:>@="id_read_next_rec_with_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK"@:>@="id_read_next_rec_with_no_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_WRITE"@:>@="id_write1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_REWRITE"@:>@="id_rewrite1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_DELETE"@:>@="id_delete1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_OPEN"@:>@="id_open1" + +declare -A PROGRAM_ID_TABLE2 + +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ"@:>@="id_read2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_WITH_LOCK"@:>@="id_read_with_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_WITH_NO_LOCK"@:>@="id_read_with_no_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_START"@:>@="id_start2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_NEXT_RECORD"@:>@="id_read_next_rec2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_NEXT_RECORD_WITH_LOCK"@:>@="id_read_next_rec_with_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK"@:>@="id_read_next_rec_with_no_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_WRITE"@:>@="id_write2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_REWRITE"@:>@="id_rewrite2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_DELETE"@:>@="id_delete2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_OPEN"@:>@="id_open2" + + +PROGRAM1_OPERATIONS=( + "$OPERATION_OPEN" + "$OPERATION_START" + "$OPERATION_WRITE" + "$OPERATION_REWRITE" +) + +PROGRAM2_OPERATIONS=( + "$OPERATION_READ" + "$OPERATION_READ_WITH_LOCK" + "$OPERATION_READ_WITH_NO_LOCK" + "$OPERATION_READ_NEXT_RECORD" + "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" + "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" + "$OPERATION_START" + "$OPERATION_WRITE" + "$OPERATION_REWRITE" + "$OPERATION_DELETE" +) + +for operation in "${PROGRAM1_OPERATIONS@<:@@@:>@}"; do + if test "${operation}" == "$OPERATION_WRITE"; then + cat prog1.template.cbl | + sed -e "s/@WRITE_REC@//g" |\ + sed -e "s/@OPERATION@/${operation}/" |\ + sed -e "s/@PROGRAM_ID@/${PROGRAM_ID_TABLE1@<:@${operation}@:>@}/" \ + > prog1.cbl + else + cat prog1.template.cbl | + sed -e "s/@WRITE_REC@/WRITE REC./g" |\ + sed -e "s/@OPERATION@/${operation}/" |\ + sed -e "s/@PROGRAM_ID@/${PROGRAM_ID_TABLE1@<:@${operation}@:>@}/" \ + > prog1.cbl + fi + cobj prog1.cbl +done + +for operation in "${PROGRAM2_OPERATIONS@<:@@@:>@}"; do + cat prog2.template.cbl | + sed -e "s/@OPERATION@/${operation}/" |\ + sed -e "s/@PROGRAM_ID@/${PROGRAM_ID_TABLE2@<:@${operation}@:>@}/" \ + > prog2.cbl + cobj prog2.cbl +done + +function run_test() { + if test "$1" == "" -o "$2" == "" -o "$3" == "" -o "$4" == "" -o "$5" == "" -o "$6" == ""; then + echo empty strings are in arguments + echo "\$1: $1" + echo "\$2: $2" + echo "\$3: $3" + echo "\$4: $4" + echo "\$5: $5" + echo "\$6: $6" + return 1 + fi + OPERATION1=$1 + OPERATION2=$2 + PROG1_STATUS=$3 + PROG2_STATUS=$4 + PROG2_MESSAGE=$5 + FINAL_RECORD_STATE=$6 + + rm -f playground-record-lock-* f.dat pro1.log prog2.log + + java -Xlog:perf+memops=off ${PROGRAM_ID_TABLE1@<:@$OPERATION1@:>@} > prog1.log & + PID1=$! + java -Xlog:perf+memops=off ${PROGRAM_ID_TABLE2@<:@$OPERATION2@:>@} > prog2.log & + PID2=$! + + wait $PID1 $PID2 + + echo "$PROG1_STATUS" > prog1.expected.log + echo "$FINAL_RECORD_STATE" >> prog1.expected.log + + echo "$PROG2_STATUS" > prog2.expected.log + echo "$PROG2_MESSAGE" >> prog2.expected.log + + if ! diff prog1.log prog1.expected.log || ! diff prog2.log prog2.expected.log; then + echo "$OPERATION1, $OPERATION2, $PROG1_STATUS, $PROG2_STATUS, $PROG2_MESSAGE" + echo prog1.log === + cat prog1.log + echo prog1.expected.log === + cat prog1.expected.log + echo prog2.log === + cat prog2.log + echo prog2.expected.log === + cat prog2.expected.log + fi +} + +run_test "$OPERATION_OPEN" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_OPEN" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_OPEN" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_OPEN" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_OPEN" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_OPEN" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_OPEN" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_OPEN" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_OPEN" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_OPEN" "$OPERATION_DELETE" "00" "00" "not changed" "record deleted" + +run_test "$OPERATION_START" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_START" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_START" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_START" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_START" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_START" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_START" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_START" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_START" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_START" "$OPERATION_DELETE" "00" "00" "not changed" "record deleted" + +run_test "$OPERATION_WRITE" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_WRITE" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_WRITE" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_WRITE" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_WRITE" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_WRITE" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_WRITE" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_WRITE" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_WRITE" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_WRITE" "$OPERATION_DELETE" "00" "00" "not changed" "record deleted" + +run_test "$OPERATION_REWRITE" "$OPERATION_READ" "00" "00" "changed" "record not changed" +run_test "$OPERATION_REWRITE" "$OPERATION_READ_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_REWRITE" "$OPERATION_READ_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_REWRITE" "$OPERATION_START" "00" "00" "not changed" "record not changed" +run_test "$OPERATION_REWRITE" "$OPERATION_READ_NEXT_RECORD" "00" "00" "changed" "record not changed" +run_test "$OPERATION_REWRITE" "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_REWRITE" "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "00" "00" "changed" "record not changed" +run_test "$OPERATION_REWRITE" "$OPERATION_WRITE" "00" "22" "not changed" "record not changed" +run_test "$OPERATION_REWRITE" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_REWRITE" "$OPERATION_DELETE" "00" "00" "not changed" "record deleted" +]) + + +AT_CHECK([cp ../../file-lock.src/module-sync/wait.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/setValue.java .]) + +AT_DATA([prog1.template.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. @PROGRAM_ID@. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "f.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + * LOCK MODE IS AUTOMATIC + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 DUMMY PIC X(10) VALUE "DUMMY DATA". + PROCEDURE DIVISION. + MAIN-PROCEDURE. + OPEN OUTPUT f. + MOVE "AAAA1" TO REC-KEY. + MOVE "BBBB1" TO REC-KEY2. + MOVE "CCCC1" TO REC-DATA. + * WRITE REC. + @WRITE_REC@ + CLOSE f. + + OPEN I-O f. + + MOVE "AAAA1" TO REC-KEY. + @OPERATION@ + + DISPLAY FILE-STATUS. + + CALL "setValue" USING + "playground-record-lock-01" + "AAAA1 record is locked". + CALL "wait" USING + "playground-record-lock-02" + "end of prog2". + CLOSE f. + + OPEN INPUT f. + MOVE "AAAA1" TO REC-KEY. + READ F. + + IF FILE-STATUS = "23" + DISPLAY "record deleted" + GO TO FINISH + END-IF. + + IF REC = "AAAA1_____*****" + DISPLAY "record rewritten" + GO TO FINISH + END-IF. + + IF REC = "AAAA1BBBB1CCCC1" + DISPLAY "record not changed" + ELSE + DISPLAY "unexpected: rec=" REC + END-IF. + + FINISH. + CLOSE f. +]) + +AT_DATA([prog2.template.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. @PROGRAM_ID@. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "f.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 REC-BACKUP PIC X(15). + PROCEDURE DIVISION. + MAIN-PROCEDURE. + CALL "wait" USING + "playground-record-lock-01" + "AAAA1 record is locked". + + OPEN I-O f. + + INITIALIZE REC. + MOVE "AAAA1_____*****" TO REC. + MOVE REC TO REC-BACKUP. + + @OPERATION@ + + DISPLAY FILE-STATUS. + IF REC = REC-BACKUP + DISPLAY "not changed" + ELSE + DISPLAY "changed" + END-IF. + + CLOSE f. + + CALL "setValue" USING + "playground-record-lock-02" + "end of prog2". + + +]) + +AT_CHECK([bash a.sh]) +AT_CLEANUP diff --git a/tests/file-lock.src/release-lock.at b/tests/file-lock.src/release-lock.at new file mode 100644 index 00000000..cefde4f5 --- /dev/null +++ b/tests/file-lock.src/release-lock.at @@ -0,0 +1,596 @@ +AT_SETUP([Operations except for READ unlock previously locked records]) +AT_DATA([a.sh], [ +javac wait.java setValue.java + +OPERATION_READ="READ F." +OPERATION_READ_WITH_LOCK="READ F WITH LOCK." +OPERATION_READ_WITH_NO_LOCK="READ F WITH NO LOCK." +OPERATION_START="START F KEY IS = REC-KEY." +OPERATION_READ_NEXT_RECORD="START F KEY IS = REC-KEY. READ F NEXT RECORD." +OPERATION_READ_NEXT_RECORD_WITH_LOCK="START F KEY IS = REC-KEY. READ F NEXT RECORD WITH LOCK." +OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK="START F KEY IS = REC-KEY. READ F NEXT RECORD WITH NO LOCK." +OPERATION_WRITE="WRITE REC." +OPERATION_REWRITE="REWRITE REC." +OPERATION_DELETE="DELETE F." +OPERATION_OPEN="INITIALIZE DUMMY." # dummy operation +OPERATION_CLOSE="CLOSE F." + +OPERATIONS=( + "OPERATION_READ" + "OPERATION_READ_WITH_LOCK" + "OPERATION_READ_WITH_NO_LOCK" + "OPERATION_START" + "OPERATION_READ_NEXT_RECORD" + "OPERATION_READ_NEXT_RECORD_WITH_LOCK" + "OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" + "OPERATION_WRITE" + "OPERATION_REWRITE" + "OPERATION_DELETE" + "OPERATION_OPEN" + "OPERATION_CLOSE" +) + + +declare -A PROGRAM_ID_TABLE1 + +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ"@:>@="id_read1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_WITH_LOCK"@:>@="id_read_with_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_WITH_NO_LOCK"@:>@="id_read_with_no_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_START"@:>@="id_start1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_NEXT_RECORD"@:>@="id_read_next_rec1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_NEXT_RECORD_WITH_LOCK"@:>@="id_read_next_rec_with_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK"@:>@="id_read_next_rec_with_no_lock1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_WRITE"@:>@="id_write1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_REWRITE"@:>@="id_rewrite1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_DELETE"@:>@="id_delete1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_OPEN"@:>@="id_open1" +PROGRAM_ID_TABLE1@<:@"$OPERATION_CLOSE"@:>@="id_close1" + +declare -A PROGRAM_ID_TABLE2 + +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ"@:>@="id_read2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_WITH_LOCK"@:>@="id_read_with_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_WITH_NO_LOCK"@:>@="id_read_with_no_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_START"@:>@="id_start2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_NEXT_RECORD"@:>@="id_read_next_rec2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_NEXT_RECORD_WITH_LOCK"@:>@="id_read_next_rec_with_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK"@:>@="id_read_next_rec_with_no_lock2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_WRITE"@:>@="id_write2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_REWRITE"@:>@="id_rewrite2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_DELETE"@:>@="id_delete2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_OPEN"@:>@="id_open2" +PROGRAM_ID_TABLE2@<:@"$OPERATION_CLOSE"@:>@="id_close2" + +PROGRAM1_OPERATIONS=( + "$OPERATION_READ" + "$OPERATION_READ_WITH_LOCK" + "$OPERATION_READ_WITH_NO_LOCK" + "$OPERATION_START" + "$OPERATION_READ_NEXT_RECORD" + "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" + "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" + "$OPERATION_WRITE" + "$OPERATION_REWRITE" + "$OPERATION_DELETE" + "$OPERATION_CLOSE" +) + +PROGRAM2_OPERATIONS=( + "$OPERATION_REWRITE" +) + +for operation in "${PROGRAM1_OPERATIONS@<:@@@:>@}"; do + if test "${operation}" == "$OPERATION_CLOSE"; then + cat prog1.template.cbl | + sed -e "s/@OPERATION@/${operation}/" |\ + sed -e "s/@CLOSE_FILE@//" |\ + sed -e "s/@WRITE-REC@/AAAA2/" |\ + sed -e "s/@PROGRAM_ID@/${PROGRAM_ID_TABLE1@<:@${operation}@:>@}/" \ + > prog1.cbl + elif test "${operation}" == "$OPERATION_WRITE"; then + cat prog1.template.cbl | + sed -e "s/@OPERATION@/${operation}/" |\ + sed -e "s/@CLOSE_FILE@/CLOSE F./" |\ + sed -e "s/@WRITE-REC@/AAAA3/" |\ + sed -e "s/@PROGRAM_ID@/${PROGRAM_ID_TABLE1@<:@${operation}@:>@}/" \ + > prog1.cbl + else + cat prog1.template.cbl | + sed -e "s/@OPERATION@/${operation}/" |\ + sed -e "s/@CLOSE_FILE@/CLOSE F./" |\ + sed -e "s/@WRITE-REC@/AAAA2/" |\ + sed -e "s/@PROGRAM_ID@/${PROGRAM_ID_TABLE1@<:@${operation}@:>@}/" \ + > prog1.cbl + fi + cobj prog1.cbl +done + +for operation in "${PROGRAM2_OPERATIONS@<:@@@:>@}"; do + cat prog2.template.cbl | + sed -e "s/@PROGRAM_ID@/${PROGRAM_ID_TABLE2@<:@${operation}@:>@}/" \ + > prog2.cbl + cobj prog2.cbl +done + + +function run_test() { + if test "$1" == "" -o "$2" == "" -o "$3" == "" -o "$4" == "" -o "$5" == "" -o "$6" == ""; then + echo empty strings are in arguments + echo "\$1: $1" + echo "\$2: $2" + echo "\$3: $3" + echo "\$4: $4" + echo "\$5: $5" + echo "\$6: $6" + return 1 + fi + OPERATION1=$1 + OPERATION2=$2 + PROG1_STATUS=$3 + PROG2_STATUS=$4 + PROG2_MESSAGE=$5 + FINAL_RECORD_STATE=$6 + + rm -f playground-record-lock-* f.dat pro1.log prog2.log + + java -Xlog:perf+memops=off ${PROGRAM_ID_TABLE1@<:@$OPERATION1@:>@} > prog1.log & + PID1=$! + java -Xlog:perf+memops=off ${PROGRAM_ID_TABLE2@<:@$OPERATION2@:>@} > prog2.log & + PID2=$! + + wait $PID1 $PID2 + + echo "$PROG1_STATUS" > prog1.expected.log + echo "$FINAL_RECORD_STATE" >> prog1.expected.log + + echo "$PROG2_STATUS" > prog2.expected.log + echo "$PROG2_MESSAGE" >> prog2.expected.log + + if ! diff prog1.log prog1.expected.log || ! diff prog2.log prog2.expected.log; then + echo "$OPERATION1, $OPERATION2, $PROG1_STATUS, $PROG2_STATUS, $PROG2_MESSAGE" + echo prog1.log === + cat prog1.log + echo prog1.expected.log === + cat prog1.expected.log + echo prog2.log === + cat prog2.log + echo prog2.expected.log === + cat prog2.expected.log + fi +} + +run_test "$OPERATION_READ" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_READ_WITH_LOCK" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_READ_WITH_NO_LOCK" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_START" "$OPERATION_REWRITE" "00" "51" "not changed" "record not changed" +run_test "$OPERATION_READ_NEXT_RECORD" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_WRITE" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_REWRITE" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_DELETE" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" +run_test "$OPERATION_CLOSE" "$OPERATION_REWRITE" "00" "00" "not changed" "record rewritten" + +]) + + +AT_CHECK([cp ../../file-lock.src/module-sync/wait.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/setValue.java .]) + +AT_DATA([prog1.template.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. @PROGRAM_ID@. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "f.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + * LOCK MODE IS AUTOMATIC + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 DUMMY PIC X(10) VALUE "DUMMY DATA". + PROCEDURE DIVISION. + MAIN-PROCEDURE. + OPEN OUTPUT f. + MOVE "AAAA1" TO REC-KEY. + MOVE "BBBB1" TO REC-KEY2. + MOVE "CCCC1" TO REC-DATA. + WRITE REC. + MOVE "AAAA2" TO REC-KEY. + MOVE "BBBB2" TO REC-KEY2. + MOVE "CCCC2" TO REC-DATA. + WRITE REC. + CLOSE f. + + OPEN I-O f. + + MOVE "AAAA1" TO REC-KEY. + READ F WITH LOCK. + MOVE "@WRITE-REC@" TO REC-KEY. + @OPERATION@ + + DISPLAY FILE-STATUS. + + CALL "setValue" USING + "playground-record-lock-01" + "AAAA1 record is locked". + CALL "wait" USING + "playground-record-lock-02" + "end of prog2". + + @CLOSE_FILE@ + + OPEN INPUT f. + MOVE "AAAA1" TO REC-KEY. + READ F. + + IF FILE-STATUS = "23" + DISPLAY "record deleted" + GO TO FINISH + END-IF. + + IF REC = "AAAA1_____*****" + DISPLAY "record rewritten" + GO TO FINISH + END-IF. + + IF REC = "AAAA1BBBB1CCCC1" + DISPLAY "record not changed" + ELSE + DISPLAY "unexpected: rec=" REC + END-IF. + + FINISH. + CLOSE f. + +]) + +AT_DATA([prog2.template.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. @PROGRAM_ID@. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "f.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 REC-BACKUP PIC X(15). + PROCEDURE DIVISION. + MAIN-PROCEDURE. + CALL "wait" USING + "playground-record-lock-01" + "AAAA1 record is locked". + + OPEN I-O f. + + INITIALIZE REC. + MOVE "AAAA1_____*****" TO REC. + MOVE REC TO REC-BACKUP. + REWRITE REC. + + DISPLAY FILE-STATUS. + + IF REC = REC-BACKUP + DISPLAY "not changed" + ELSE + DISPLAY "changed" + END-IF. + + CLOSE f. + + CALL "setValue" USING + "playground-record-lock-02" + "end of prog2". + +]) + +AT_CHECK([bash a.sh]) +AT_CLEANUP + +AT_SETUP([unlock (READ)]) +AT_DATA([p1.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. p1. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "f.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + * LOCK MODE IS AUTOMATIC + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 DUMMY PIC X(10) VALUE "DUMMY DATA". + PROCEDURE DIVISION. + MAIN-PROCEDURE. + OPEN OUTPUT f. + MOVE "AAAA1" TO REC-KEY. + MOVE "BBBB1" TO REC-KEY2. + MOVE "CCCC1" TO REC-DATA. + WRITE REC. + MOVE "AAAA2" TO REC-KEY. + MOVE "BBBB2" TO REC-KEY2. + MOVE "CCCC2" TO REC-DATA. + WRITE REC. + CLOSE f. + + OPEN I-O f. + + MOVE "AAAA1" TO REC-KEY. + READ F WITH LOCK. + DISPLAY FILE-STATUS. + + + CALL "setValue" USING + "playground-record-lock-01" + "AAAA1 record is locked". + CALL "wait" USING + "playground-record-lock-02" + "AAAA2 record is released". + + MOVE "AAAA2" TO REC-KEY. + REWRITE REC. + DISPLAY FILE-STATUS. + CLOSE f. + CALL "setValue" USING + "playground-record-lock-03" + "end of p1". +]) + +AT_DATA([p2.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. p2. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "f.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 REC-EMPTY PIC X(15) VALUE "AAAA1 ". + 01 REC-BACKUP PIC X(15). + 01 DUMMY PIC X(15). + PROCEDURE DIVISION. + MAIN-PROCEDURE. + CALL "wait" USING + "playground-record-lock-01" + "AAAA1 record is locked". + + OPEN I-O f. + DISPLAY FILE-STATUS. + + INITIALIZE REC. + MOVE "AAAA2" TO REC. + READ F WITH LOCK. + + MOVE "AAAA1" TO REC-KEY. + READ F WITH LOCK. + DISPLAY FILE-STATUS. + + CALL "setValue" USING + "playground-record-lock-02" + "AAAA2 record is released". + + CALL "wait" USING + "playground-record-lock-03" + "end of p1". + + CLOSE f. +]) + +AT_DATA([run.sh], [ + java -Xlog:perf+memops=off p1 > p1.log & + PID1=$! + java -Xlog:perf+memops=off p2 > p2.log & + PID2=$! + wait $PID1 $PID2 +]) + +AT_CHECK([cp ../../file-lock.src/module-sync/wait.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/setValue.java .]) +AT_CHECK([cobj p1.cbl p2.cbl]) +AT_CHECK([javac wait.java setValue.java]) + +# run a test +AT_CHECK([bash run.sh] +) +AT_CHECK([cat p1.log], [0], +[00 +00 +]) + +AT_CHECK([cat p2.log], [0], +[00 +51 +]) + +AT_CLEANUP + +AT_SETUP([unlock (REWRITE)]) +AT_DATA([p1.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. p1. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "f.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS SEQUENTIAL + RECORD KEY IS REC-KEY + * LOCK MODE IS AUTOMATIC + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 DUMMY PIC X(10) VALUE "DUMMY DATA". + PROCEDURE DIVISION. + MAIN-PROCEDURE. + OPEN OUTPUT f. + MOVE "AAAA1" TO REC-KEY. + MOVE "BBBB1" TO REC-KEY2. + MOVE "CCCC1" TO REC-DATA. + WRITE REC. + MOVE "AAAA2" TO REC-KEY. + MOVE "BBBB2" TO REC-KEY2. + MOVE "CCCC2" TO REC-DATA. + WRITE REC. + CLOSE f. + + OPEN I-O f. + MOVE "AAAA1" TO REC-KEY. + START f KEY IS = REC-KEY. + READ F WITH LOCK. + MOVE "AAAA2" TO REC-KEY. + REWRITE REC. + DISPLAY FILE-STATUS. + + + CALL "setValue" USING + "playground-record-lock-01" + "AAAA1 record is released". + CALL "wait" USING + "playground-record-lock-02" + "end of p2". + + CLOSE f. +]) + +AT_DATA([p2.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. p2. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "f.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 REC-EMPTY PIC X(15) VALUE "AAAA1 ". + 01 REC-BACKUP PIC X(15). + 01 DUMMY PIC X(15). + PROCEDURE DIVISION. + MAIN-PROCEDURE. + CALL "wait" USING + "playground-record-lock-01" + "AAAA1 record is released". + + OPEN I-O f. + + INITIALIZE REC. + + MOVE "AAAA1" TO REC-KEY. + READ F WITH LOCK. + DISPLAY FILE-STATUS. + + CALL "setValue" USING + "playground-record-lock-02" + "end of p2". + + CLOSE f. +]) + +AT_DATA([run.sh], [ + java -Xlog:perf+memops=off p1 > p1.log & + PID1=$! + java -Xlog:perf+memops=off p2 > p2.log & + PID2=$! + wait $PID1 $PID2 +]) + +AT_CHECK([cp ../../file-lock.src/module-sync/wait.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/setValue.java .]) +AT_CHECK([cobj p1.cbl p2.cbl]) +AT_CHECK([javac wait.java setValue.java]) + +# run a test +AT_CHECK([bash run.sh]) + +AT_CHECK([cat p1.log], [0], +[21 +]) + +AT_CHECK([cat p2.log], [0], +[00 +]) + +AT_CLEANUP \ No newline at end of file diff --git a/tests/file-lock.src/same-process.at b/tests/file-lock.src/same-process.at new file mode 100644 index 00000000..807df9d5 --- /dev/null +++ b/tests/file-lock.src/same-process.at @@ -0,0 +1,124 @@ +AT_SETUP([Record locking of indexed files (same process)]) +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "f.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + * LOCK MODE IS AUTOMATIC + ALTERNATE RECORD KEY IS REC-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + 05 REC-KEY2 PIC X(5). + 05 REC-DATA PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 COMMAND-COUNTER-1 PIC 9(3) VALUE 0. + 01 COMMAND-COUNTER-2 PIC 9(3) VALUE 0. + + PROCEDURE DIVISION. + + OPERATIONS-TEST. + + PERFORM VARYING COMMAND-COUNTER-1 FROM 1 BY 1 + UNTIL COMMAND-COUNTER-1 > 1 + PERFORM VARYING COMMAND-COUNTER-2 FROM 1 BY 1 + UNTIL COMMAND-COUNTER-2 > 1 + * initialize file + OPEN OUTPUT f + MOVE "AAAA1" TO REC-KEY + MOVE "BBBB1" TO REC-KEY2 + MOVE "CCCC1" TO REC-DATA + WRITE REC + CLOSE f + * test read operations + OPEN I-O f + MOVE "AAAA1" TO REC-KEY + EVALUATE COMMAND-COUNTER-1 + WHEN 1 + READ f + WHEN 2 + READ f WITH LOCK + WHEN 3 + READ f WITH NO LOCK + WHEN 4 + START F KEY IS = REC-KEY + READ f NEXT RECORD + WHEN 5 + START F KEY IS = REC-KEY + READ f NEXT RECORD WITH LOCK + WHEN 6 + START F KEY IS = REC-KEY + READ f NEXT RECORD WITH NO LOCK + WHEN OTHER + CONTINUE + END-EVALUATE + + IF FILE-STATUS NOT = "00" + DISPLAY "COMMAND-COUNTER-1: " COMMAND-COUNTER-1 + DISPLAY "FILE-STATUS: " FILE-STATUS + END-IF + + MOVE "AAAA1" TO REC-KEY + EVALUATE COMMAND-COUNTER-2 + WHEN 1 + READ f + WHEN 2 + READ f WITH LOCK + WHEN 3 + READ f WITH NO LOCK + WHEN 4 + START F KEY IS = REC-KEY + WHEN 5 + START F KEY IS = REC-KEY + READ f NEXT RECORD + WHEN 6 + START F KEY IS = REC-KEY + READ f NEXT RECORD WITH LOCK + WHEN 7 + START F KEY IS = REC-KEY + READ f NEXT RECORD WITH NO LOCK + WHEN 8 + WRITE REC + WHEN 9 + REWRITE REC + WHEN 10 + DELETE F + WHEN OTHER + CONTINUE + END-EVALUATE + * WRITE operation fails + IF COMMAND-COUNTER-2 = 8 + IF FILE-STATUS NOT = "22" + DISPLAY "COMMAND-COUNTER-2: " + COMMAND-COUNTER-2 + DISPLAY "FILE-STATUS: " FILE-STATUS + END-IF + ELSE + * other operations succeed + IF FILE-STATUS NOT = "00" + DISPLAY "COMMAND-COUNTER-2: " + COMMAND-COUNTER-2 + DISPLAY "FILE-STATUS: " FILE-STATUS + END-IF + END-IF + CLOSE f + END-PERFORM + END-PERFORM. + STOP RUN. +]) + +AT_CHECK([cobj prog.cbl]) +AT_CHECK([java -Xlog:perf+memops=off prog]) +AT_CLEANUP diff --git a/tests/i18n_sjis.src/data/in-sjis.txt b/tests/i18n_sjis.src/data/in-sjis.txt new file mode 100644 index 00000000..4e36865c --- /dev/null +++ b/tests/i18n_sjis.src/data/in-sjis.txt @@ -0,0 +1,3 @@ +dH + +ŠH diff --git a/tests/i18n_sjis.src/data/in-utf8.txt b/tests/i18n_sjis.src/data/in-utf8.txt new file mode 100644 index 00000000..2904d1f1 --- /dev/null +++ b/tests/i18n_sjis.src/data/in-utf8.txt @@ -0,0 +1,3 @@ +重工業 +給水所 +洗濯板滑走路 diff --git a/tests/i18n_sjis.src/data/out-sjis.txt b/tests/i18n_sjis.src/data/out-sjis.txt new file mode 100644 index 00000000..5f6ced6d --- /dev/null +++ b/tests/i18n_sjis.src/data/out-sjis.txt @@ -0,0 +1,7 @@ +{ +R +㒆 +wZ +dH + + diff --git a/tests/i18n_sjis.src/data/out-utf8.txt b/tests/i18n_sjis.src/data/out-utf8.txt new file mode 100644 index 00000000..6d00de6c --- /dev/null +++ b/tests/i18n_sjis.src/data/out-utf8.txt @@ -0,0 +1,7 @@ +日本語 +山梨県 +上中下 +小学校 +重工業 +給水所 +洗濯板 diff --git a/tests/i18n_sjis.src/pic-x.at b/tests/i18n_sjis.src/pic-x.at index 3311d792..113c67bb 100644 --- a/tests/i18n_sjis.src/pic-x.at +++ b/tests/i18n_sjis.src/pic-x.at @@ -483,3 +483,102 @@ AT_CHECK([cobj prog.cob], [0]) AT_CHECK([java prog], [0], [02]) AT_CLEANUP + +AT_SETUP([Readable string literals]) +# Older compilers converts string literals "{" in COBOL source code +# to `CobolUtil.toBytes((byte)0x93, (byte)0xfa, (byte)0x96, (byte)0x7b, (byte)0x8c, (byte)0xea)` in Java source code. +# The following tests check that the compiler converts the string literals to readable ones. + +AT_DATA([prog1.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog1. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC X(30) VALUE "1". + PROCEDURE DIVISION. + MOVE "2" TO F0. + DISPLAY "3". +]) + +AT_CHECK([cobj prog1.cob]) +AT_CHECK([grep '1' < prog1.java > /dev/null]) +AT_CHECK([grep '2' < prog1.java > /dev/null]) +AT_CHECK([grep '3' < prog1.java > /dev/null]) + +# '@' is the first multi-byte Shift-JIS character with respect to the byte order +# see http://charset.7jp.net/sjis.html +AT_DATA([prog2.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog2. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC X(30) VALUE "@1". + PROCEDURE DIVISION. + MOVE "@2" TO F0. + DISPLAY "@3". +]) + +AT_CHECK([cobj prog2.cob]) +AT_CHECK([grep '@1' < prog2.java > /dev/null]) +AT_CHECK([grep '@2' < prog2.java > /dev/null]) +AT_CHECK([grep '@3' < prog2.java > /dev/null]) + +# '' is the last printable Shift-JIS character with respect to the byte order. +# See http://charset.7jp.net/sjis.html +AT_DATA([prog3.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog3. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F0 PIC X(30) VALUE "1". + PROCEDURE DIVISION. + MOVE "2" TO F0. + DISPLAY "3". +]) + +AT_CHECK([cobj prog3.cob]) +AT_CHECK([grep '1' < prog3.java > /dev/null]) +AT_CHECK([grep '2' < prog3.java > /dev/null]) +AT_CHECK([grep '3' < prog3.java > /dev/null]) + +AT_CLEANUP + +AT_SETUP([DISPLAY/ACCEPT encodings]) + +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + ENVIRONMENT DIVISION. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 X1 PIC X(6) VALUE "R". + 01 N1 PIC N(3) VALUE "㒆". + 01 G1. + 03 X2 PIC X(6) VALUE "wZ". + 01 N2 PIC N(3) VALUE "ؗ". + PROCEDURE DIVISION. + DISPLAY "{". + DISPLAY X1. + DISPLAY N1. + DISPLAY G1. + + ACCEPT X1. + DISPLAY X1. + ACCEPT N1. + DISPLAY N1. + ACCEPT G1. + DISPLAY G1. + STOP RUN. +]) + +AT_CHECK([cobj prog.cbl]) + +AT_CHECK([java prog < ../../i18n_sjis.src/data/in-sjis.txt > out-none.txt]) +AT_CHECK([COB_TERMINAL_ENCODING=SHIFT_JIS java prog < ../../i18n_sjis.src/data/in-sjis.txt > out-sjis.txt]) +AT_CHECK([COB_TERMINAL_ENCODING=UTF-8 java prog < ../../i18n_sjis.src/data/in-utf8.txt > out-utf8.txt]) + +AT_CHECK([diff out-none.txt ../../i18n_sjis.src/data/out-sjis.txt]) +AT_CHECK([diff out-sjis.txt ../../i18n_sjis.src/data/out-sjis.txt]) +AT_CHECK([diff out-utf8.txt ../../i18n_sjis.src/data/out-utf8.txt]) + +AT_CLEANUP diff --git a/tests/i18n_sjis.src/user-defined-word.at b/tests/i18n_sjis.src/user-defined-word.at index a4f78f33..0effdb2b 100644 --- a/tests/i18n_sjis.src/user-defined-word.at +++ b/tests/i18n_sjis.src/user-defined-word.at @@ -177,6 +177,77 @@ AT_CHECK([java prog], [0], [OK]) AT_CLEANUP + +AT_SETUP([Nihongo field name with SJIS hyphens]) + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 sdrs|c`s`P PIC X(10) VALUE "test-data1". + 01 sdrs|qdbnqcP. + 03 sdrs|c`s`Q PIC X(10) VALUE "test-data2". + 03 sdrs|qdbnqcQ. + 05 sdrs|c`s`R PIC X(10) VALUE "test-data3". + PROCEDURE DIVISION. + DISPLAY sdrs|c`s`P. + DISPLAY sdrs|c`s`Q. + DISPLAY sdrs|c`s`R. +]) + +AT_CHECK([cobj prog.cob]) +AT_CHECK([java prog], [0], +[test-data1 +test-data2 +test-data3 +]) +AT_CHECK([cat prog.java | grep 'f_sdrsQc`s`P' > /dev/null], [0]) +AT_CHECK([cat prog.java | grep 'f_sdrsQc`s`Q__sdrsQqdbnqcP' > /dev/null], [0]) +AT_CHECK([cat prog.java | grep 'f_sdrsQc`s`R__sdrsQqdbnqcQ__sdrsQqdbnqcP' > /dev/null], [0]) + +AT_CHECK([cat prog.java | grep 'f_sdrs|c`s`P' > /dev/null], [1]) +AT_CHECK([cat prog.java | grep 'f_sdrs|c`s`Q__sdrs|qdbnqcP' > /dev/null], [1]) +AT_CHECK([cat prog.java | grep 'f_sdrs|c`s`R__sdrs|qdbnqcQ__sdrs|qdbnqcP' > /dev/null], [1]) + +AT_CLEANUP + + +AT_SETUP([Nihongo field name with SJIS hyphens using -fshort-variable ]) + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 sdrs|c`s`P PIC X(10) VALUE "test-data1". + 01 sdrs|qdbnqcP. + 03 sdrs|c`s`Q PIC X(10) VALUE "test-data2". + 03 sdrs|qdbnqcQ. + 05 sdrs|c`s`R PIC X(10) VALUE "test-data3". + PROCEDURE DIVISION. + DISPLAY sdrs|c`s`P. + DISPLAY sdrs|c`s`Q. + DISPLAY sdrs|c`s`R. +]) + +AT_CHECK([cobj -fshort-variable prog.cob]) +AT_CHECK([java prog], [0], +[test-data1 +test-data2 +test-data3 +]) +AT_CHECK([cat prog.java | grep 'f_sdrsQc`s`P' > /dev/null], [0]) +AT_CHECK([cat prog.java | grep 'f_sdrsQc`s`Q' > /dev/null], [0]) +AT_CHECK([cat prog.java | grep 'f_sdrsQc`s`R' > /dev/null], [0]) + +AT_CHECK([cat prog.java | grep 'f_sdrs|c`s`P' > /dev/null], [1]) +AT_CHECK([cat prog.java | grep 'f_sdrs|c`s`Q' > /dev/null], [1]) +AT_CHECK([cat prog.java | grep 'f_sdrs|c`s`R' > /dev/null], [1]) + +AT_CLEANUP + + AT_SETUP([Nihongo field name in numeric test msg.]) AT_DATA([prog.cob], [ diff --git a/tests/jp-compat.src/job-date.at b/tests/jp-compat.src/job-date.at index a0f2026d..bf5a69c7 100644 --- a/tests/jp-compat.src/job-date.at +++ b/tests/jp-compat.src/job-date.at @@ -240,7 +240,7 @@ AT_DATA([prog.cob], [ ]) AT_CHECK([${COMPILE_JP_COMPAT} prog.cob]) -AT_CHECK([COB_DATE=`date +%Y/%m/%d` java prog], [0], [0 +AT_CHECK([COB_DATE=`date +%Y/%m/%d` java prog || true], [0], [0 ]) AT_CLEANUP diff --git a/tests/jp-compat.src/spl-registers.at b/tests/jp-compat.src/spl-registers.at index 27327097..602ba436 100644 --- a/tests/jp-compat.src/spl-registers.at +++ b/tests/jp-compat.src/spl-registers.at @@ -1,5 +1,4 @@ AT_SETUP([PROGRAM-STATUS]) -AT_CHECK([${SKIP_TEST}]) AT_DATA([prog.cob], [ IDENTIFICATION DIVISION. diff --git a/tests/misc.at b/tests/misc.at index b6a182bf..1db81ab4 100644 --- a/tests/misc.at +++ b/tests/misc.at @@ -46,3 +46,15 @@ m4_include([validate-indexed-file-keys.at]) m4_include([record-key-duplicates-error.at]) #m4_include([copy-comments.at]) m4_include([read_prev_after_start.at]) +m4_include([japanese-char-section-var.at]) +m4_include([evaluate-switch.at]) +m4_include([fserial-variable.at]) +m4_include([file-handler-japanese.at]) +m4_include([perform-until-div.at]) +m4_include([search-occurs-depending.at]) +m4_include([fix-subtract.at]) +m4_include([display-numeric-NUMERIC-class.at]) +m4_include([display-inspect-sign.at]) +m4_include([comp1-comp2.at]) +m4_include([variable-length-file.at]) +m4_include([convert-string-concat.at]) diff --git a/tests/misc.src/TEST_VAR_LENGTH.txt b/tests/misc.src/TEST_VAR_LENGTH.txt new file mode 100644 index 00000000..8ab1827b Binary files /dev/null and b/tests/misc.src/TEST_VAR_LENGTH.txt differ diff --git a/tests/misc.src/comp1-comp2.at b/tests/misc.src/comp1-comp2.at new file mode 100644 index 00000000..7459b88b --- /dev/null +++ b/tests/misc.src/comp1-comp2.at @@ -0,0 +1,21 @@ +AT_SETUP([COMP-1 COMP-2 error]) + +AT_DATA([prog.cbl], [ + identification division. + ****************************************************************** + program-id. prog. + ****************************************************************** + data division. + WORKING-STORAGE SECTION. + 01 H COMP-1. + 01 I COMP-2. + PROCEDURE DIVISION. + STOP RUN. +]) + +AT_CHECK([${COBJ} prog.cbl], [1], [], +[prog.cbl:8: Error: COMP-1 not implemented +prog.cbl:9: Error: COMP-2 not implemented +]) + +AT_CLEANUP \ No newline at end of file diff --git a/tests/misc.src/compare-9.at b/tests/misc.src/compare-9.at index 41499d7a..55f8118c 100644 --- a/tests/misc.src/compare-9.at +++ b/tests/misc.src/compare-9.at @@ -57,3 +57,34 @@ AT_CHECK([${COBJ} prog.cbl]) AT_CHECK([java prog]) AT_CLEANUP + +AT_SETUP([compare 9(n), S9(n) SEPARATE]) + +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 N10 PIC 9(10). + 01 S9-L PIC S9(9) SIGN LEADING SEPARATE. + 01 S9-T PIC S9(9) SIGN TRAILING SEPARATE. + PROCEDURE DIVISION. + MAIN-PROC. + ************************************************************* + MOVE 800 TO N10. + MOVE 900 TO S9-L. + MOVE 900 TO S9-T. + + IF N10 >= S9-L + DISPLAY "NG (N10 >= S9-L)" + END-IF. + + IF N10 >= S9-T + DISPLAY "NG (N10 >= S9-T)" + END-IF. +]) + +AT_CHECK([${COBJ} prog.cbl]) +AT_CHECK([java prog]) + +AT_CLEANUP \ No newline at end of file diff --git a/tests/misc.src/convert-string-concat.at b/tests/misc.src/convert-string-concat.at new file mode 100644 index 00000000..44926293 --- /dev/null +++ b/tests/misc.src/convert-string-concat.at @@ -0,0 +1,40 @@ +AT_SETUP([convert '&' concatenated strings to Java]) + +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 X-CONCAT PIC X(25) VALUE "abcde" + & "fghij" + & "klmno" + & "pqrst" + & "uvwxy". + 01 N-CONCAT PIC N(25) VALUE "" + & "" + & "" + & "‚Ă" + & "Ȃɂʂ˂". + PROCEDURE DIVISION. + MAIN-RTN. + DISPLAY X-CONCAT. + DISPLAY N-CONCAT. + STOP RUN. +]) + +AT_CHECK([${COMPILE} prog.cbl]) +AT_CHECK([java prog], [0], +[abcdefghijklmnopqrstuvwxy +‚ĂƂȂɂʂ˂ +]) +AT_CHECK([grep -q ' "abcde" +' prog.java]) +AT_CHECK([grep -q ' "fghij" +' prog.java]) +AT_CHECK([grep -q ' "klmno" +' prog.java]) +AT_CHECK([grep -q ' "pqrst" +' prog.java]) +AT_CHECK([grep -q ' "uvwxy"' prog.java]) +AT_CHECK([grep -q ' "" +' prog.java]) +AT_CHECK([grep -q ' "" +' prog.java]) +AT_CHECK([grep -q ' "" +' prog.java]) +AT_CHECK([grep -q ' "‚Ă" +' prog.java]) +AT_CHECK([grep -q ' "Ȃɂʂ˂"' prog.java]) +AT_CLEANUP diff --git a/tests/misc.src/display-inspect-sign.at b/tests/misc.src/display-inspect-sign.at new file mode 100644 index 00000000..562afae1 --- /dev/null +++ b/tests/misc.src/display-inspect-sign.at @@ -0,0 +1,53 @@ +AT_SETUP([DISPLAY values after INSPECT]) + +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 DATA1 + 02 DATA-SIGN PIC S9(5). + 01 DATA2 + 02 DATA-SIGN-LEADING PIC S9(5) SIGN IS LEADING. + 01 DATA3 + 02 DATA-SIGN-LEADING-SEPARATE PIC S9(5) SIGN LEADING SEPARATE. + 01 DATA4 + 02 DATA-SIGN-TRAILING-SEPARATE PIC S9(5) SIGN TRAILING SEPARATE. + PROCEDURE DIVISION. + MAIN-RTN. + MOVE -12345 TO DATA-SIGN. + DISPLAY DATA1. + INSPECT DATA-SIGN REPLACING ALL ' ' BY '0'. + DISPLAY DATA1. + + MOVE -12345 TO DATA-SIGN-LEADING. + DISPLAY DATA2. + INSPECT DATA-SIGN-LEADING REPLACING ALL ' ' BY '0'. + DISPLAY DATA2. + + MOVE -12345 TO DATA-SIGN-LEADING-SEPARATE. + DISPLAY DATA3. + INSPECT DATA-SIGN-LEADING-SEPARATE REPLACING ALL ' ' BY '0'. + DISPLAY DATA3. + + MOVE -12345 TO DATA-SIGN-TRAILING-SEPARATE. + DISPLAY DATA4. + INSPECT DATA-SIGN-TRAILING-SEPARATE REPLACING ALL ' ' BY '0'. + DISPLAY DATA4. + STOP RUN. +]) + + +AT_CHECK([${COMPILE} prog.cbl]) +AT_CHECK([${RUN_MODULE} prog], [0], +[1234u +1234u +q2345 +q2345 +-12345 +-12345 +12345- +12345- +]) + +AT_CLEANUP \ No newline at end of file diff --git a/tests/misc.src/display-numeric-NUMERIC-class.at b/tests/misc.src/display-numeric-NUMERIC-class.at new file mode 100644 index 00000000..b3273abf --- /dev/null +++ b/tests/misc.src/display-numeric-NUMERIC-class.at @@ -0,0 +1,32 @@ +AT_SETUP([DISPLAY numeric after NUMERIC class testing]) + +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 N-REC. + 03 N-VAL PIC 9. + PROCEDURE DIVISION. + MAIN-PROC. + ************************************************************* + MOVE SPACE TO N-REC. + DISPLAY "N-VAL: '" N-VAL "'". + + IF N-VAL NUMERIC + DISPLAY "N-VAL is numeric" + ELSE + DISPLAY "N-VAL is not numeric" + END-IF. + + DISPLAY "N-VAL: '" N-VAL "'". +]) + +AT_CHECK([${COBJ} prog.cbl]) +AT_CHECK([java prog], [0], +[N-VAL: ' ' +N-VAL is not numeric +N-VAL: ' ' +]) + +AT_CLEANUP \ No newline at end of file diff --git a/tests/misc.src/evaluate-switch.at b/tests/misc.src/evaluate-switch.at new file mode 100644 index 00000000..ac57e172 --- /dev/null +++ b/tests/misc.src/evaluate-switch.at @@ -0,0 +1,1034 @@ +AT_SETUP([Convert EVALUATE to switch]) + +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + + DATA DIVISION. + WORKING-STORAGE SECTION. + 78 STATUS-1 VALUE 1. + 78 STATUS--1 VALUE -1. + 78 STATUS-2 VALUE 2. + + 01 TEST-9-1 PIC 9(3) VALUE 1. + 01 TEST-9-2 PIC 9(3) VALUE 2. + 01 TEST-S9-1 PIC S9(3) VALUE 1. + 01 TEST-S9-2 PIC S9(3) VALUE 2. + 01 TEST-9-1-COMP3 PIC 9(3) COMP-3 VALUE 1. + 01 TEST-9-2-COMP3 PIC 9(3) COMP-3 VALUE 2. + 01 TEST-S9-1-COMP3 PIC S9(3) COMP-3 VALUE 1. + 01 TEST-S9-2-COMP3 PIC S9(3) COMP-3 VALUE 2. + 01 TEST-9-1-COMP5 PIC 9(3) COMP-5 VALUE 1. + 01 TEST-9-2-COMP5 PIC 9(3) COMP-5 VALUE 2. + 01 TEST-S9-1-COMP5 PIC 9(3) COMP-5 VALUE 1. + 01 TEST-S9-2-COMP5 PIC 9(3) COMP-5 VALUE 2. + PROCEDURE DIVISION. + MAIN-PROC SECTION. + + EVALUATE 1 + WHEN 1 + DISPLAY "OK". + + EVALUATE 1 + WHEN STATUS-1 + DISPLAY "OK". + + EVALUATE 1 + WHEN 1 + DISPLAY "OK" + WHEN OTHER + DISPLAY "NG". + + EVALUATE 1 + WHEN STATUS-1 + DISPLAY "OK" + WHEN OTHER + DISPLAY "NG". + + EVALUATE 1 + WHEN -1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE 1 + WHEN STATUS--1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE 2 + WHEN 1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE 2 + WHEN STATUS-1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE 1 + WHEN 1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG". + + EVALUATE 1 + WHEN STATUS-1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG". + + EVALUATE 1 + WHEN STATUS-1 + DISPLAY "OK" + WHEN STATUS-2 + DISPLAY "NG". + + EVALUATE 1 + WHEN 1 + DISPLAY "OK" + WHEN -1 + DISPLAY "NG". + + EVALUATE 1 + WHEN STATUS-1 + DISPLAY "OK" + WHEN -1 + DISPLAY "NG". + + EVALUATE 1 + WHEN STATUS-1 + DISPLAY "OK" + WHEN STATUS--1 + DISPLAY "NG". + + EVALUATE 1 + WHEN 1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG" + WHEN OTHER + DISPLAY "NG". + + EVALUATE 1 + WHEN STATUS-1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG" + WHEN OTHER + DISPLAY "NG". + + EVALUATE 1 + WHEN STATUS-1 + DISPLAY "OK" + WHEN STATUS-2 + DISPLAY "NG" + WHEN OTHER + DISPLAY "NG". + *************************** + + EVALUATE TEST-9-1 + WHEN 1 + DISPLAY "OK". + + EVALUATE TEST-9-1 + WHEN STATUS-1 + DISPLAY "OK". + + EVALUATE TEST-9-1 + WHEN 1 + DISPLAY "OK" + WHEN OTHER + DISPLAY "NG". + + EVALUATE TEST-9-1 + WHEN STATUS-1 + DISPLAY "OK" + WHEN OTHER + DISPLAY "NG". + + EVALUATE TEST-9-1 + WHEN -1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE TEST-9-1 + WHEN STATUS--1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE TEST-9-2 + WHEN 1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE TEST-9-2 + WHEN STATUS-1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE TEST-9-1 + WHEN 1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG". + + EVALUATE TEST-9-1 + WHEN STATUS-1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG". + + EVALUATE TEST-9-1 + WHEN STATUS-1 + DISPLAY "OK" + WHEN STATUS-2 + DISPLAY "NG". + + EVALUATE TEST-9-1 + WHEN 1 + DISPLAY "OK" + WHEN -1 + DISPLAY "NG". + + EVALUATE TEST-9-1 + WHEN STATUS-1 + DISPLAY "OK" + WHEN -1 + DISPLAY "NG". + + EVALUATE TEST-9-1 + WHEN STATUS-1 + DISPLAY "OK" + WHEN STATUS--1 + DISPLAY "NG". + + EVALUATE TEST-9-1 + WHEN 1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG" + WHEN OTHER + DISPLAY "NG". + + EVALUATE TEST-9-1 + WHEN STATUS-1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG" + WHEN OTHER + DISPLAY "NG". + + EVALUATE TEST-9-1 + WHEN STATUS-1 + DISPLAY "OK" + WHEN STATUS-2 + DISPLAY "NG" + WHEN OTHER + DISPLAY "NG". + *************************** + + EVALUATE TEST-S9-1 + WHEN 1 + DISPLAY "OK". + + EVALUATE TEST-S9-1 + WHEN STATUS-1 + DISPLAY "OK". + + EVALUATE TEST-S9-1 + WHEN 1 + DISPLAY "OK" + WHEN OTHER + DISPLAY "NG". + + EVALUATE TEST-S9-1 + WHEN STATUS-1 + DISPLAY "OK" + WHEN OTHER + DISPLAY "NG". + + EVALUATE TEST-S9-1 + WHEN -1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE TEST-S9-1 + WHEN STATUS--1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE TEST-S9-2 + WHEN 1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE TEST-S9-2 + WHEN STATUS-1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE TEST-S9-1 + WHEN 1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG". + + EVALUATE TEST-S9-1 + WHEN STATUS-1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG". + + EVALUATE TEST-S9-1 + WHEN STATUS-1 + DISPLAY "OK" + WHEN STATUS-2 + DISPLAY "NG". + + EVALUATE TEST-S9-1 + WHEN 1 + DISPLAY "OK" + WHEN -1 + DISPLAY "NG". + + EVALUATE TEST-S9-1 + WHEN STATUS-1 + DISPLAY "OK" + WHEN -1 + DISPLAY "NG". + + EVALUATE TEST-S9-1 + WHEN STATUS-1 + DISPLAY "OK" + WHEN STATUS--1 + DISPLAY "NG". + + EVALUATE TEST-S9-1 + WHEN 1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG" + WHEN OTHER + DISPLAY "NG". + + EVALUATE TEST-S9-1 + WHEN STATUS-1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG" + WHEN OTHER + DISPLAY "NG". + + EVALUATE TEST-S9-1 + WHEN STATUS-1 + DISPLAY "OK" + WHEN STATUS-2 + DISPLAY "NG" + WHEN OTHER + DISPLAY "NG". + *************************** + + EVALUATE TEST-9-1-COMP3 + WHEN 1 + DISPLAY "OK". + + EVALUATE TEST-9-1-COMP3 + WHEN STATUS-1 + DISPLAY "OK". + + EVALUATE TEST-9-1-COMP3 + WHEN 1 + DISPLAY "OK" + WHEN OTHER + DISPLAY "NG". + + EVALUATE TEST-9-1-COMP3 + WHEN STATUS-1 + DISPLAY "OK" + WHEN OTHER + DISPLAY "NG". + + EVALUATE TEST-9-1-COMP3 + WHEN -1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE TEST-9-1-COMP3 + WHEN STATUS--1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE TEST-9-2-COMP3 + WHEN 1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE TEST-9-2-COMP3 + WHEN STATUS-1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE TEST-9-1-COMP3 + WHEN 1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG". + + EVALUATE TEST-9-1-COMP3 + WHEN STATUS-1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG". + + EVALUATE TEST-9-1-COMP3 + WHEN STATUS-1 + DISPLAY "OK" + WHEN STATUS-2 + DISPLAY "NG". + + EVALUATE TEST-9-1-COMP3 + WHEN 1 + DISPLAY "OK" + WHEN -1 + DISPLAY "NG". + + EVALUATE TEST-9-1-COMP3 + WHEN STATUS-1 + DISPLAY "OK" + WHEN -1 + DISPLAY "NG". + + EVALUATE TEST-9-1-COMP3 + WHEN STATUS-1 + DISPLAY "OK" + WHEN STATUS--1 + DISPLAY "NG". + + EVALUATE TEST-9-1-COMP3 + WHEN 1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG" + WHEN OTHER + DISPLAY "NG". + + EVALUATE TEST-9-1-COMP3 + WHEN STATUS-1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG" + WHEN OTHER + DISPLAY "NG". + + EVALUATE TEST-9-1-COMP3 + WHEN STATUS-1 + DISPLAY "OK" + WHEN STATUS-2 + DISPLAY "NG" + WHEN OTHER + DISPLAY "NG". + *************************** + + EVALUATE TEST-S9-1-COMP3 + WHEN 1 + DISPLAY "OK". + + EVALUATE TEST-S9-1-COMP3 + WHEN STATUS-1 + DISPLAY "OK". + + EVALUATE TEST-S9-1-COMP3 + WHEN 1 + DISPLAY "OK" + WHEN OTHER + DISPLAY "NG". + + EVALUATE TEST-S9-1-COMP3 + WHEN STATUS-1 + DISPLAY "OK" + WHEN OTHER + DISPLAY "NG". + + EVALUATE TEST-S9-1-COMP3 + WHEN -1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE TEST-S9-1-COMP3 + WHEN STATUS--1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE TEST-S9-2-COMP3 + WHEN 1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE TEST-S9-2-COMP3 + WHEN STATUS-1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE TEST-S9-1-COMP3 + WHEN 1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG". + + EVALUATE TEST-S9-1-COMP3 + WHEN STATUS-1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG". + + EVALUATE TEST-S9-1-COMP3 + WHEN STATUS-1 + DISPLAY "OK" + WHEN STATUS-2 + DISPLAY "NG". + + EVALUATE TEST-S9-1-COMP3 + WHEN 1 + DISPLAY "OK" + WHEN -1 + DISPLAY "NG". + + EVALUATE TEST-S9-1-COMP3 + WHEN STATUS-1 + DISPLAY "OK" + WHEN -1 + DISPLAY "NG". + + EVALUATE TEST-S9-1-COMP3 + WHEN STATUS-1 + DISPLAY "OK" + WHEN STATUS--1 + DISPLAY "NG". + + EVALUATE TEST-S9-1-COMP3 + WHEN 1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG" + WHEN OTHER + DISPLAY "NG". + + EVALUATE TEST-S9-1-COMP3 + WHEN STATUS-1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG" + WHEN OTHER + DISPLAY "NG". + + EVALUATE TEST-S9-1-COMP3 + WHEN STATUS-1 + DISPLAY "OK" + WHEN STATUS-2 + DISPLAY "NG" + WHEN OTHER + DISPLAY "NG". + *************************** + + EVALUATE TEST-9-1-COMP5 + WHEN 1 + DISPLAY "OK". + + EVALUATE TEST-9-1-COMP5 + WHEN STATUS-1 + DISPLAY "OK". + + EVALUATE TEST-9-1-COMP5 + WHEN 1 + DISPLAY "OK" + WHEN OTHER + DISPLAY "NG". + + EVALUATE TEST-9-1-COMP5 + WHEN STATUS-1 + DISPLAY "OK" + WHEN OTHER + DISPLAY "NG". + + EVALUATE TEST-9-1-COMP5 + WHEN -1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE TEST-9-1-COMP5 + WHEN STATUS--1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE TEST-9-2-COMP5 + WHEN 1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK22222". + + EVALUATE TEST-9-2-COMP5 + WHEN STATUS-1 + DISPLAY "NG11111111" + WHEN OTHER + DISPLAY "OK". + + EVALUATE TEST-9-1-COMP5 + WHEN 1 + DISPLAY "OK" + WHEN 2 + DISPLAY "N". + + EVALUATE TEST-9-1-COMP5 + WHEN STATUS-1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG". + + EVALUATE TEST-9-1-COMP5 + WHEN STATUS-1 + DISPLAY "OK" + WHEN STATUS-2 + DISPLAY "NG". + + EVALUATE TEST-9-1-COMP5 + WHEN 1 + DISPLAY "OK" + WHEN -1 + DISPLAY "NG". + + EVALUATE TEST-9-1-COMP5 + WHEN STATUS-1 + DISPLAY "OK" + WHEN -1 + DISPLAY "NG". + + EVALUATE TEST-9-1-COMP5 + WHEN STATUS-1 + DISPLAY "OK" + WHEN STATUS--1 + DISPLAY "NG". + + EVALUATE TEST-9-1-COMP5 + WHEN 1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG" + WHEN OTHER + DISPLAY "NG". + + EVALUATE TEST-9-1-COMP5 + WHEN STATUS-1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG" + WHEN OTHER + DISPLAY "NG". + + EVALUATE TEST-9-1-COMP5 + WHEN STATUS-1 + DISPLAY "OK" + WHEN STATUS-2 + DISPLAY "NG" + WHEN OTHER + DISPLAY "NG". + *************************** + + EVALUATE TEST-S9-1-COMP5 + WHEN 1 + DISPLAY "OK". + + EVALUATE TEST-S9-1-COMP5 + WHEN STATUS-1 + DISPLAY "OK". + + EVALUATE TEST-S9-1-COMP5 + WHEN 1 + DISPLAY "OK" + WHEN OTHER + DISPLAY "NG". + + EVALUATE TEST-S9-1-COMP5 + WHEN STATUS-1 + DISPLAY "OK" + WHEN OTHER + DISPLAY "NG". + + EVALUATE TEST-S9-1-COMP5 + WHEN -1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE TEST-S9-1-COMP5 + WHEN STATUS--1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE TEST-S9-2-COMP5 + WHEN 1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE TEST-S9-2-COMP5 + WHEN STATUS-1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + EVALUATE TEST-S9-1-COMP5 + WHEN 1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG". + + EVALUATE TEST-S9-1-COMP5 + WHEN STATUS-1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG". + + EVALUATE TEST-S9-1-COMP5 + WHEN STATUS-1 + DISPLAY "OK" + WHEN STATUS-2 + DISPLAY "NG". + + EVALUATE TEST-S9-1-COMP5 + WHEN 1 + DISPLAY "OK" + WHEN -1 + DISPLAY "NG". + + EVALUATE TEST-S9-1-COMP5 + WHEN STATUS-1 + DISPLAY "OK" + WHEN -1 + DISPLAY "NG". + + EVALUATE TEST-S9-1-COMP5 + WHEN STATUS-1 + DISPLAY "OK" + WHEN STATUS--1 + DISPLAY "NG". + + EVALUATE TEST-S9-1-COMP5 + WHEN 1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG" + WHEN OTHER + DISPLAY "NG". + + EVALUATE TEST-S9-1-COMP5 + WHEN STATUS-1 + DISPLAY "OK" + WHEN 2 + DISPLAY "NG" + WHEN OTHER + DISPLAY "NG". + + EVALUATE TEST-S9-1-COMP5 + WHEN STATUS-1 + DISPLAY "OK" + WHEN STATUS-2 + DISPLAY "NG" + WHEN OTHER + DISPLAY "NG". + *************************** +]) + +AT_DATA([test.sh], +[#!/bin/bash +# Compile a COBOL source file +cobj prog.cbl +# The number of OK in the program output +OK_COUNT=$(java prog | tee result.txt | grep OK | wc -l) +# The number of EVALUATE statements in a COBOL source file +EVALUATE_COUNT=$(grep EVALUATE prog.cbl | wc -l) +# The number of switch statements corresponding to EVALUATE statements +SWITCH_COUNT=$(grep -A 2 '/\* prog.cbl:@<:@0-9@:>@*: EVALUATE \*/' prog.java | grep 'switch' | wc -l) +# Check the numbers +test "$OK_COUNT" = "$EVALUATE_COUNT" && test "$OK_COUNT" = "$SWITCH_COUNT" +]) + +AT_CHECK([chmod +x test.sh]) +AT_CHECK([./test.sh]) + +AT_DATA([prog2.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog2. + + DATA DIVISION. + WORKING-STORAGE SECTION. + PROCEDURE DIVISION. + MAIN-PROC SECTION. + + EVALUATE 1 + WHEN NOT 1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK". + + + EVALUATE 1 + WHEN 3 + DISPLAY "NG" + WHEN NOT 2 + DISPLAY "OK" + WHEN OTHER + DISPLAY "NG". +]) + +AT_DATA([test2.sh], +[#!/bin/bash +# Compile a COBOL source file +cobj prog2.cbl +# The number of OK in the program output +OK_COUNT=$(java prog2 | tee result.txt | grep OK | wc -l) +# The number of EVALUATE statements in a COBOL source file +EVALUATE_COUNT=$(grep EVALUATE prog2.cbl | wc -l) +# The number of switch statements corresponding to EVALUATE statements +SWITCH_COUNT=$(grep -A 2 '/\* prog2.cbl:@<:@0-9@:>@*: EVALUATE \*/' prog2.java | grep 'switch' | wc -l) +# Check the numbers +test "$OK_COUNT" = "$EVALUATE_COUNT" && test "$SWITCH_COUNT" = 0 +]) + +AT_CHECK([chmod +x test2.sh]) +AT_CHECK([./test2.sh]) + +AT_DATA([pp.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. pp. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 A PIC 9 VALUE 0. + PROCEDURE DIVISION. + EVALUATE A + WHEN 1 + WHEN 2 + DISPLAY "NG" + WHEN 3 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK" + END-EVALUATE. + EVALUATE A + WHEN 1 + WHEN 2 + WHEN 3 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK" + END-EVALUATE. + EVALUATE A + WHEN 1 + DISPLAY "NG" + WHEN 2 + WHEN 3 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK" + END-EVALUATE. + GOBACK. + +]) +AT_CHECK([cobj pp.cbl]) +AT_CHECK([java pp], [0], +[OK +OK +OK +]) + +AT_DATA([qq.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. qq. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 A PIC 9 VALUE 0. + PROCEDURE DIVISION. + EVALUATE A + WHEN 1 + WHEN 2 + DISPLAY "NG" + WHEN 3 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK" + END-EVALUATE. + EVALUATE A + WHEN 1 + WHEN 2 + WHEN 3 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK" + END-EVALUATE. + EVALUATE A + WHEN 1 + DISPLAY "NG" + WHEN 2 + WHEN 3 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK" + END-EVALUATE. + + EVALUATE A + WHEN 1 + WHEN 2 + WHEN 3 + WHEN OTHER + DISPLAY "OK" + END-EVALUATE. + + EVALUATE A + WHEN 1 + WHEN 2 + DISPLAY "NG" + WHEN 3 + WHEN OTHER + DISPLAY "OK" + END-EVALUATE. + + EVALUATE A + WHEN 1 + DISPLAY "NG" + WHEN 2 + WHEN 3 + WHEN OTHER + DISPLAY "OK" + END-EVALUATE. + + EVALUATE A + WHEN 1 + DISPLAY "NG" + WHEN 2 + DISPLAY "NG" + WHEN 3 + WHEN OTHER + DISPLAY "OK" + END-EVALUATE. + GOBACK. + +]) +AT_CHECK([cobj ${CONF_JP_COMPAT} qq.cbl]) +AT_CHECK([java qq], [0], +[OK +OK +OK +OK +OK +OK +OK +]) + +AT_DATA([rr.cbl], +[ IDENTIFICATION DIVISION. + PROGRAM-ID. rr. + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO 'sample-file' + ORGANIZATION IS SEQUENTIAL. + DATA DIVISION. + FILE SECTION. + FD F. + 01 REC PIC X. + WORKING-STORAGE SECTION. + 01 A PIC 9 VALUE 0. + 01 C PIC 9 VALUE 0. + PROCEDURE DIVISION. + EVALUATE A + WHEN 0 + DISPLAY "OK1" + IF 1 = 1 THEN + DISPLAY "OK2" + END-IF + PERFORM VARYING C FROM 3 BY 1 UNTIL C >= 4 + DISPLAY "OK" C + END-PERFORM + OPEN OUTPUT F + MOVE 'A' TO REC + WRITE REC + MOVE 'B' TO REC + WRITE REC + CLOSE F + OPEN INPUT F + PERFORM FOREVER + READ F + AT END + DISPLAY "READ END" + EXIT PERFORM + NOT AT END + DISPLAY "READ DATA:" REC + END-READ + END-PERFORM + CLOSE F + END-EVALUATE. + EVALUATE A + WHEN 1 + DISPLAY "NG" + WHEN OTHER + DISPLAY "OK1" + IF 1 = 1 THEN + DISPLAY "OK2" + END-IF + PERFORM VARYING C FROM 3 BY 1 UNTIL C >= 4 + DISPLAY "OK" C + END-PERFORM + OPEN INPUT F + PERFORM FOREVER + READ F + AT END + DISPLAY "READ END" + EXIT PERFORM + NOT AT END + DISPLAY "READ DATA:" REC + END-READ + END-PERFORM + CLOSE F + END-EVALUATE. + GOBACK. +]) + +AT_CHECK([cobj rr.cbl]) +AT_CHECK([java rr], [0], +[OK1 +OK2 +OK3 +READ DATA:A +READ DATA:B +READ END +OK1 +OK2 +OK3 +READ DATA:A +READ DATA:B +READ END +]) + +AT_CLEANUP diff --git a/tests/misc.src/fd-external.at b/tests/misc.src/fd-external.at index 78c01f25..59376c1e 100644 --- a/tests/misc.src/fd-external.at +++ b/tests/misc.src/fd-external.at @@ -66,3 +66,105 @@ AT_CHECK([java prog], [0], ]) AT_CLEANUP + +AT_SETUP([FD EXTERNAL nihongo]) + +AT_DATA([prog1.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog1. + environment division. + input-output section. + file-control. + select f assign to 'file.txt' + organization is line sequential + access mode is sequential. + DATA DIVISION. + file section. + fd f is external. + 01 ab|P pic x(5). + working-storage section. + 01 ab|Q pic x(5) external. + PROCEDURE DIVISION. + initialize ab|P. + initialize ab|Q. + + open output f. + call "sub". + close f. + + open input f. + read f. + close f. + + display ab|P. + display ab|Q. + STOP RUN. +]) + +AT_DATA([prog2.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog2 is initial. + + environment division. + input-output section. + file-control. + select f assign to 'file.txt' + organization is line sequential + access mode is sequential. + DATA DIVISION. + file section. + fd f is external. + 01 ab|P pic x(5). + working-storage section. + 01 ab|Q pic x(5) external. + PROCEDURE DIVISION. + initialize ab|P. + initialize ab|Q. + + open output f. + call "sub". + close f. + + open input f. + read f. + close f. + + display ab|P. + display ab|Q. + STOP RUN. +]) + +AT_DATA([sub.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. sub. + environment division. + input-output section. + file-control. + select f assign to "file.txt" + organization is line sequential + access mode is sequential. + DATA DIVISION. + file section. + fd f is external. + 01 ab|P pic x(5). + working-storage section. + 01 ab|Q pic x(5) external. + PROCEDURE DIVISION. + move "abcde" to ab|P. + write ab|P. + move "12345" to ab|Q. + goback. +]) + +AT_CHECK([${COBJ} prog1.cbl prog2.cbl sub.cbl]) +AT_CHECK([java prog1], [0], +[abcde +12345 +]) + +AT_CHECK([java prog2], [0], +[abcde +12345 +]) + +AT_CLEANUP diff --git a/tests/misc.src/file-handler-japanese.at b/tests/misc.src/file-handler-japanese.at new file mode 100644 index 00000000..6815c776 --- /dev/null +++ b/tests/misc.src/file-handler-japanese.at @@ -0,0 +1,25 @@ +AT_SETUP([file-handler-japanese]) + +# This test verifies that Issue 539 is fixed. + +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT eXgt@C + ORGANIZATION IS SEQUENTIAL. + DATA DIVISION. + FILE SECTION. + FD eXgt@C. + 01 REC PIC X(10). + PROCEDURE DIVISION. + STOP RUN. +]) + +AT_CHECK([${COBJ} prog.cbl]) +AT_CHECK([grep 'h_eXgt@C' prog.java > /dev/null]) +AT_CHECK([grep 'h_EXGT@C' prog.java], [1]) + +AT_CLEANUP \ No newline at end of file diff --git a/tests/misc.src/fix-subtract.at b/tests/misc.src/fix-subtract.at new file mode 100644 index 00000000..3824dfd9 --- /dev/null +++ b/tests/misc.src/fix-subtract.at @@ -0,0 +1,219 @@ +AT_SETUP([fix subtract]) + +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 NUM-REC. + 03 NUM-VAL PIC S9(2). + + PROCEDURE DIVISION. + MOVE -2 TO NUM-VAL. + ADD 1 TO NUM-VAL. + DISPLAY NUM-VAL. + + MOVE -2 TO NUM-VAL. + ADD 3 TO NUM-VAL. + DISPLAY NUM-VAL. + + MOVE -2 TO NUM-VAL. + SUBTRACT -1 FROM NUM-VAL. + DISPLAY NUM-VAL. + + MOVE -2 TO NUM-VAL. + SUBTRACT -3 FROM NUM-VAL. + DISPLAY NUM-VAL. + + MOVE -5 TO NUM-VAL. + ADD 4 TO NUM-VAL. + DISPLAY NUM-VAL. + + MOVE -5 TO NUM-VAL. + ADD 5 TO NUM-VAL. + DISPLAY NUM-VAL. + + MOVE -5 TO NUM-VAL. + ADD 6 TO NUM-VAL. + DISPLAY NUM-VAL. + + MOVE -5 TO NUM-VAL. + ADD -4 TO NUM-VAL. + DISPLAY NUM-VAL. + + MOVE -5 TO NUM-VAL. + ADD -5 TO NUM-VAL. + DISPLAY NUM-VAL. + + MOVE -5 TO NUM-VAL. + ADD -6 TO NUM-VAL. + DISPLAY NUM-VAL. + ****************************************************************** + MOVE -5 TO NUM-VAL. + SUBTRACT 4 FROM NUM-VAL. + DISPLAY NUM-VAL. + + MOVE -5 TO NUM-VAL. + SUBTRACT 5 FROM NUM-VAL. + DISPLAY NUM-VAL. + + MOVE -5 TO NUM-VAL. + SUBTRACT 6 FROM NUM-VAL. + DISPLAY NUM-VAL. + + MOVE -5 TO NUM-VAL. + SUBTRACT -4 FROM NUM-VAL. + DISPLAY NUM-VAL. + + MOVE -5 TO NUM-VAL. + SUBTRACT -5 FROM NUM-VAL. + DISPLAY NUM-VAL. + + MOVE -5 TO NUM-VAL. + SUBTRACT -6 FROM NUM-VAL. + DISPLAY NUM-VAL. + ****************************************************************** + MOVE 0 TO NUM-VAL. + ADD 4 TO NUM-VAL. + DISPLAY NUM-VAL. + + MOVE 0 TO NUM-VAL. + ADD 5 TO NUM-VAL. + DISPLAY NUM-VAL. + + MOVE 0 TO NUM-VAL. + ADD 6 TO NUM-VAL. + DISPLAY NUM-VAL. + + MOVE 0 TO NUM-VAL. + ADD -4 TO NUM-VAL. + DISPLAY NUM-VAL. + + MOVE 0 TO NUM-VAL. + ADD -5 TO NUM-VAL. + DISPLAY NUM-VAL. + + MOVE 0 TO NUM-VAL. + ADD -6 TO NUM-VAL. + DISPLAY NUM-VAL. + ****************************************************************** + MOVE 0 TO NUM-VAL. + SUBTRACT 4 FROM NUM-VAL. + DISPLAY NUM-VAL. + + MOVE 0 TO NUM-VAL. + SUBTRACT 5 FROM NUM-VAL. + DISPLAY NUM-VAL. + + MOVE 0 TO NUM-VAL. + SUBTRACT 6 FROM NUM-VAL. + DISPLAY NUM-VAL. + + MOVE 0 TO NUM-VAL. + SUBTRACT -4 FROM NUM-VAL. + DISPLAY NUM-VAL. + + MOVE 0 TO NUM-VAL. + SUBTRACT -5 FROM NUM-VAL. + DISPLAY NUM-VAL. + + MOVE 0 TO NUM-VAL. + SUBTRACT -6 FROM NUM-VAL. + DISPLAY NUM-VAL. + ****************************************************************** + MOVE 5 TO NUM-VAL. + ADD 4 TO NUM-VAL. + DISPLAY NUM-VAL. + + MOVE 5 TO NUM-VAL. + ADD 5 TO NUM-VAL. + DISPLAY NUM-VAL. + + MOVE 5 TO NUM-VAL. + ADD 6 TO NUM-VAL. + DISPLAY NUM-VAL. + + MOVE 5 TO NUM-VAL. + ADD -4 TO NUM-VAL. + DISPLAY NUM-VAL. + + MOVE 5 TO NUM-VAL. + ADD -5 TO NUM-VAL. + DISPLAY NUM-VAL. + + MOVE 5 TO NUM-VAL. + ADD -6 TO NUM-VAL. + DISPLAY NUM-VAL. + ****************************************************************** + MOVE 5 TO NUM-VAL. + SUBTRACT 4 FROM NUM-VAL. + DISPLAY NUM-VAL. + + MOVE 5 TO NUM-VAL. + SUBTRACT 5 FROM NUM-VAL. + DISPLAY NUM-VAL. + + MOVE 5 TO NUM-VAL. + SUBTRACT 6 FROM NUM-VAL. + DISPLAY NUM-VAL. + + MOVE 5 TO NUM-VAL. + SUBTRACT -4 FROM NUM-VAL. + DISPLAY NUM-VAL. + + MOVE 5 TO NUM-VAL. + SUBTRACT -5 FROM NUM-VAL. + DISPLAY NUM-VAL. + + MOVE 5 TO NUM-VAL. + SUBTRACT -6 FROM NUM-VAL. + DISPLAY NUM-VAL. + ****************************************************************** +]) + +AT_CHECK([${COBJ} prog.cbl]) +AT_CHECK([java prog], [0], +[-01 ++01 +-01 ++01 +-01 ++00 ++01 +-09 +-10 +-11 +-09 +-10 +-11 +-01 ++00 ++01 ++04 ++05 ++06 +-04 +-05 +-06 +-04 +-05 +-06 ++04 ++05 ++06 ++09 ++10 ++11 ++01 ++00 +-01 ++01 ++00 +-01 ++09 ++10 ++11 +]) + +AT_CLEANUP + diff --git a/tests/misc.src/fserial-variable.at b/tests/misc.src/fserial-variable.at new file mode 100644 index 00000000..55863736 --- /dev/null +++ b/tests/misc.src/fserial-variable.at @@ -0,0 +1,98 @@ +AT_SETUP([-fserial-variable]) + +AT_DATA([prog.cbl], [ IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 AAA PIC 9 VALUE 0. + 01 BBB PIC 9 COMP-3 VALUE 1. + 01 CCC PIC X VALUE "A". + 01 GRP. + 03 DDD PIC 9 VALUE 2. + 03 EEE PIC 9 COMP-3 VALUE 3. + 03 FFF PIC X VALUE "B". + PROCEDURE DIVISION. + MAIN SECTION. + DISPLAY AAA. + DISPLAY BBB. + DISPLAY CCC. + DISPLAY DDD. + DISPLAY EEE. + DISPLAY FFF. +]) + +AT_CHECK([${COMPILE} -fserial-variable prog.cbl]) +AT_CHECK([${RUN_MODULE} prog], [0], +[0 +1 +A +2 +3 +B +]) +AT_CHECK([grep 'b_5' prog.java > /dev/null], [0]) +AT_CHECK([grep 'b_6' prog.java > /dev/null], [0]) +AT_CHECK([grep 'b_7' prog.java > /dev/null], [0]) +AT_CHECK([grep 'b_8' prog.java > /dev/null], [0]) +AT_CHECK([grep 'b_9' prog.java > /dev/null], [0]) +AT_CHECK([grep 'b_10' prog.java > /dev/null], [0]) +AT_CHECK([grep 'b_11' prog.java > /dev/null], [0]) +AT_CHECK([grep 'f_5' prog.java > /dev/null], [0]) +AT_CHECK([grep 'f_6' prog.java > /dev/null], [0]) +AT_CHECK([grep 'f_7' prog.java > /dev/null], [0]) +AT_CHECK([grep 'f_9' prog.java > /dev/null], [0]) +AT_CHECK([grep 'f_10' prog.java > /dev/null], [0]) +AT_CHECK([grep 'f_11' prog.java > /dev/null], [0]) + +AT_CHECK([grep 'f_AAA' prog.java], [1]) +AT_CHECK([grep 'b_AAA' prog.java], [1]) +AT_CHECK([grep 'f_BBB' prog.java], [1]) +AT_CHECK([grep 'b_BBB' prog.java], [1]) +AT_CHECK([grep 'f_CCC' prog.java], [1]) +AT_CHECK([grep 'b_CCC' prog.java], [1]) +AT_CHECK([grep 'b_GRP' prog.java], [1]) +AT_CHECK([grep 'f_DDD__GRP' prog.java], [1]) +AT_CHECK([grep 'b_DDD__GRP' prog.java], [1]) +AT_CHECK([grep 'f_EEE__GRP' prog.java], [1]) +AT_CHECK([grep 'b_EEE__GRP' prog.java], [1]) +AT_CHECK([grep 'f_FFF__GRP' prog.java], [1]) +AT_CHECK([grep 'b_FFF__GRP' prog.java], [1]) + +AT_CHECK([${COMPILE} prog.cbl]) +AT_CHECK([${RUN_MODULE} prog], [0], +[0 +1 +A +2 +3 +B +]) +AT_CHECK([grep 'f_AAA' prog.java > /dev/null], [0]) +AT_CHECK([grep 'b_AAA' prog.java > /dev/null], [0]) +AT_CHECK([grep 'f_BBB' prog.java > /dev/null], [0]) +AT_CHECK([grep 'b_BBB' prog.java > /dev/null], [0]) +AT_CHECK([grep 'f_CCC' prog.java > /dev/null], [0]) +AT_CHECK([grep 'b_CCC' prog.java > /dev/null], [0]) +AT_CHECK([grep 'b_GRP' prog.java > /dev/null], [0]) +AT_CHECK([grep 'f_DDD__GRP' prog.java > /dev/null], [0]) +AT_CHECK([grep 'b_DDD__GRP' prog.java > /dev/null], [0]) +AT_CHECK([grep 'f_EEE__GRP' prog.java > /dev/null], [0]) +AT_CHECK([grep 'b_EEE__GRP' prog.java > /dev/null], [0]) +AT_CHECK([grep 'f_FFF__GRP' prog.java > /dev/null], [0]) +AT_CHECK([grep 'b_FFF__GRP' prog.java > /dev/null], [0]) + +AT_CHECK([grep 'b_5' prog.java], [1]) +AT_CHECK([grep 'b_6' prog.java], [1]) +AT_CHECK([grep 'b_7' prog.java], [1]) +AT_CHECK([grep 'b_8' prog.java], [1]) +AT_CHECK([grep 'b_9' prog.java], [1]) +AT_CHECK([grep 'b_10' prog.java], [1]) +AT_CHECK([grep 'b_11' prog.java], [1]) +AT_CHECK([grep 'f_5' prog.java], [1]) +AT_CHECK([grep 'f_6' prog.java], [1]) +AT_CHECK([grep 'f_7' prog.java], [1]) +AT_CHECK([grep 'f_9' prog.java], [1]) +AT_CHECK([grep 'f_10' prog.java], [1]) +AT_CHECK([grep 'f_11' prog.java], [1]) + +AT_CLEANUP diff --git a/tests/misc.src/japanese-char-section-var.at b/tests/misc.src/japanese-char-section-var.at new file mode 100644 index 00000000..9d4a4c2c --- /dev/null +++ b/tests/misc.src/japanese-char-section-var.at @@ -0,0 +1,47 @@ +AT_SETUP([japanese word section variable]) + +AT_DATA([prog.cbl], [ IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 Vh PIC x(5) VALUE "00000". + 01 l|P PIC x(5) VALUE "11111". + 01 b{|2 PIC x(5) VALUE "22222". + 01 Fs{P PIC x(5) VALUE "33333". + 01 2 PIC x(5) VALUE "44444". + PROCEDURE DIVISION. + x. + DISPLAY Vh. + _ސ|Px. + DISPLAY l|P. + R|2x. + DISPLAY b{|2. + Ȗ؂Px. + DISPLAY Fs{P. + {2x. + DISPLAY 2. +]) + + +AT_CHECK([${COMPILE} prog.cbl]) +AT_CHECK([${RUN_MODULE} prog], [0], +[00000 +11111 +22222 +33333 +44444 +]) +AT_CHECK([cat prog.java | grep "Vh" > /dev/null]) +AT_CHECK([cat prog.java | grep "l|P" > /dev/null]) +AT_CHECK([cat prog.java | grep "b{|2" > /dev/null]) +AT_CHECK([cat prog.java | grep "Fs{P" > /dev/null]) +AT_CHECK([cat prog.java | grep "2" > /dev/null]) + +AT_CHECK([cat prog.java | grep "x" > /dev/null]) +AT_CHECK([cat prog.java | grep "_ސ|Px" > /dev/null]) +AT_CHECK([cat prog.java | grep "R|2x" > /dev/null]) +AT_CHECK([cat prog.java | grep "Ȗ؂Px" > /dev/null]) +AT_CHECK([cat prog.java | grep "{2x" > /dev/null]) + +AT_CLEANUP diff --git a/tests/misc.src/perform-until-div.at b/tests/misc.src/perform-until-div.at new file mode 100644 index 00000000..db986153 --- /dev/null +++ b/tests/misc.src/perform-until-div.at @@ -0,0 +1,25 @@ +AT_SETUP([PERFORM UNTIL whose condition contains division]) + +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 CNT PIC 9(4) VALUE 1000. + 01 I PIC 9(4) VALUE 1. + PROCEDURE DIVISION. + MAIN. + PERFORM + VARYING I + FROM 1 BY 1 + UNTIL I > (CNT + 743) / 744 + PERFORM SUB + END-PERFORM + STOP RUN. + SUB. + DISPLAY "HELLO". +]) + +AT_CHECK([${COBJ} prog.cbl]) + +AT_CLEANUP diff --git a/tests/misc.src/record-key-duplicates-error.at b/tests/misc.src/record-key-duplicates-error.at index 695e69f2..3b04dc0d 100644 --- a/tests/misc.src/record-key-duplicates-error.at +++ b/tests/misc.src/record-key-duplicates-error.at @@ -26,3 +26,80 @@ AT_CHECK([${COBJ} prog.cbl], [1], [], [prog.cbl:8: Error: Record keys with duplicates are not yet supported ]) AT_CLEANUP + +AT_SETUP([Error on rewriting record keys with duplicates]) + +AT_DATA([prog.cbl], +[ IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT DUP-FILE ASSIGN TO "dupfile.dat" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS DUP-KEY + ALTERNATE RECORD KEY IS DUP-KEY2 WITH DUPLICATES + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD DUP-FILE. + 01 DUP-RECORD. + 05 DUP-KEY PIC X(5). + 05 DUP-KEY2 PIC X(5). + 05 DUP-DATA PIC X(10). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + 01 WS-END-OF-FILE PIC X VALUE 'N'. + + PROCEDURE DIVISION. + MAIN-PROCEDURE. + OPEN OUTPUT DUP-FILE. + MOVE "11111AAAAAaaaaaaaaaa" TO DUP-RECORD. + WRITE DUP-RECORD. + MOVE "22222BBBBBbbbbbbbbbb" TO DUP-RECORD. + WRITE DUP-RECORD. + MOVE "33333BBBBBcccccccccc" TO DUP-RECORD. + WRITE DUP-RECORD. + MOVE "44444AAAAAdddddddddd" TO DUP-RECORD. + WRITE DUP-RECORD. + MOVE "55555CCCCCeeeeeeeeee" TO DUP-RECORD. + WRITE DUP-RECORD. + CLOSE DUP-FILE. + + OPEN I-O DUP-FILE + IF FILE-STATUS NOT = "00" + DISPLAY "Error opening file: " FILE-STATUS + STOP RUN + END-IF. + + MOVE "BBBBB" TO DUP-KEY2. + START DUP-FILE KEY IS >= DUP-KEY2. + IF FILE-STATUS = "00" + MOVE 'N' TO WS-END-OF-FILE + PERFORM UNTIL WS-END-OF-FILE = 'Y' + READ DUP-FILE NEXT + AT END + MOVE 'Y' TO WS-END-OF-FILE + NOT AT END + REWRITE DUP-RECORD + DISPLAY DUP-RECORD + END-PERFORM + ELSE + DISPLAY "Key not found" + END-IF. + CLOSE DUP-FILE. + STOP RUN. +]) + +AT_CHECK([${COBJ} prog.cbl]) +AT_CHECK([java prog], [0], +[22222BBBBBbbbbbbbbbb +33333BBBBBcccccccccc +55555CCCCCeeeeeeeeee +]) + +AT_CLEANUP \ No newline at end of file diff --git a/tests/misc.src/search-occurs-depending.at b/tests/misc.src/search-occurs-depending.at new file mode 100644 index 00000000..d14d273d --- /dev/null +++ b/tests/misc.src/search-occurs-depending.at @@ -0,0 +1,32 @@ +AT_SETUP([SEARCH OCCURS DEPENDING]) + +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 AAA. + 02 AAA1 PIC X(04) VALUE "HOGE". + 02 FILLER PIC X(18) VALUE SPACE. + 02 AAA2 PIC S9(4) COMP. + 01 BBB. + 02 AAA-1 OCCURS 1 TO 11 DEPENDING ON AAA2 + ASCENDING KEY KEY-A INDEXED BY K1. + 03 KEY-A PIC X(05). + 03 BBB1 PIC X(05). + 03 FILLER PIC X(02). + 01 CCC PIC X(05). + PROCEDURE DIVISION. + SEARCH ALL AAA-1 + AT END + MOVE "ERROR" TO CCC + WHEN KEY-A (K1) = "00001" + MOVE BBB1 (K1) TO CCC + END-SEARCH. + DISPLAY CCC. + STOP RUN. +]) + +AT_CHECK([${COBJ} prog.cbl], [0]) + +AT_CLEANUP diff --git a/tests/misc.src/variable-length-file.at b/tests/misc.src/variable-length-file.at new file mode 100644 index 00000000..9192fc1f --- /dev/null +++ b/tests/misc.src/variable-length-file.at @@ -0,0 +1,51 @@ +AT_SETUP([READING VARIABLE LENGTH FILE]) + +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT TEST-FILE + ASSIGN TO "../../misc.src/TEST_VAR_LENGTH.txt". + DATA DIVISION. + FILE SECTION. + FD TEST-FILE. + 01 REC-1 PIC X(18). + 01 REC-2 PIC X(54). + PROCEDURE DIVISION. + MAIN-PARA. + MOVE SPACES TO REC-1 REC-2. + PERFORM OPEN-FILE. + PERFORM READ-REC. + PERFORM CLOSE-FILE. + STOP RUN. + + OPEN-FILE. + OPEN INPUT TEST-FILE. + + READ-REC. + DISPLAY "REC-1: " REC-1. + DISPLAY "REC-2: " REC-2. + READ TEST-FILE. + DISPLAY "REC-1: " REC-1. + DISPLAY "REC-2: " REC-2. + + CLOSE-FILE. + CLOSE TEST-FILE. +]) + +// Checking the number of bytes +AT_CHECK([od -N 4 -t x1 -An ../../misc.src/TEST_VAR_LENGTH.txt], [0], +[ 00 00 03 0e +]) + +AT_CHECK([${COMPILE} prog.cbl], [0]) +AT_CHECK([${RUN_MODULE} prog], [0], +[REC-1: @&t@ +REC-2: @&t@ +REC-1: LLL5555555555555 5 +REC-2: LLL5555555555555 555555555555L555555555555555555555555 +]) + +AT_CLEANUP \ No newline at end of file diff --git a/tests/package.m4 b/tests/package.m4 index 4b0b60db..e4e96494 100644 --- a/tests/package.m4 +++ b/tests/package.m4 @@ -1,6 +1,6 @@ # Signature of the current package. m4_define([AT_PACKAGE_NAME], [opensource COBOL 4J]) -m4_define([AT_PACKAGE_TARNAME], [opensource-cobol-4j-1.1.2]) -m4_define([AT_PACKAGE_VERSION], [1.1.2]) -m4_define([AT_PACKAGE_STRING], [opensource COBOL 4J 1.1.2]) +m4_define([AT_PACKAGE_TARNAME], [opensource-cobol-4j-1.1.14]) +m4_define([AT_PACKAGE_VERSION], [1.1.14]) +m4_define([AT_PACKAGE_STRING], [opensource COBOL 4J 1.1.14]) m4_define([AT_PACKAGE_BUGREPORT], [ws-opensource-cobol-contact@osscons.jp]) diff --git a/tests/run.at b/tests/run.at index 1b63ecfa..76ec8cd1 100644 --- a/tests/run.at +++ b/tests/run.at @@ -33,3 +33,4 @@ m4_include([miscellaneous.at]) m4_include([extensions.at]) m4_include([return-code.at]) m4_include([functions.at]) +m4_include([system-routines.at]) diff --git a/tests/run.src/miscellaneous.at b/tests/run.src/miscellaneous.at index 2bedb199..4e2eee58 100644 --- a/tests/run.src/miscellaneous.at +++ b/tests/run.src/miscellaneous.at @@ -88,7 +88,6 @@ AT_CLEANUP AT_SETUP([EXTERNAL data item]) -AT_CHECK([${SKIP_TEST}]) AT_DATA([callee.cob], [ IDENTIFICATION DIVISION. @@ -122,7 +121,7 @@ AT_DATA([caller.cob], [ AT_CHECK([${COMPILE_MODULE} callee.cob]) AT_CHECK([${COMPILE} caller.cob]) -AT_CHECK([java prog], [0], +AT_CHECK([${RUN_MODULE} caller], [0], [Hello World ]) @@ -131,7 +130,6 @@ AT_CLEANUP AT_SETUP([EXTERNAL AS data item]) -AT_CHECK([${SKIP_TEST}]) AT_DATA([callee.cob], [ IDENTIFICATION DIVISION. @@ -168,7 +166,7 @@ AT_DATA([caller.cob], [ AT_CHECK([${COMPILE_MODULE} callee.cob]) AT_CHECK([${COMPILE} caller.cob]) -AT_CHECK([java prog], [0], +AT_CHECK([${RUN_MODULE} caller], [0], [Extrn Hello World @@ -176,6 +174,73 @@ World AT_CLEANUP +AT_SETUP([EXTERNAL group data item]) + +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 A EXTERNAL. + 03 A1 PIC X(5). + 03 A2 PIC X(3). + 03 A3. + 05 A3-1 PIC 9(1). + 05 A3-2 PIC 9(1). + PROCEDURE DIVISION. + MOVE "HELLO" TO A1. + MOVE "ABC" TO A2. + MOVE 12 TO A3. + + DISPLAY A. + DISPLAY A1. + DISPLAY A2. + DISPLAY A3. + + MOVE "DEF" TO A2. + DISPLAY A. + + CALL "sub". + + MOVE 5 TO A3-2. + + DISPLAY A. + + STOP RUN. +]) + +AT_DATA([sub.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. sub. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 A EXTERNAL. + 03 A1 PIC X(5). + 03 A2 PIC X(3). + 03 A3. + 05 A3-1 PIC 9(1). + 05 A3-2 PIC 9(1). + PROCEDURE DIVISION. + DISPLAY A. + MOVE 34 TO A3. + MOVE "WORLD" TO A1. + GOBACK. +]) + +AT_CHECK([${COBJ} prog.cbl]) +AT_CHECK([${COBJ} sub.cbl]) +AT_CHECK([java prog], [0], +[HELLOABC12 +HELLO +ABC +12 +HELLODEF12 +HELLODEF12 +WORLDDEF35 +]) + +AT_CLEANUP + AT_SETUP([java command validation]) @@ -602,7 +667,7 @@ AT_CHECK([test $SHREXT != "dll" || exit 77]) AT_DATA([test.conf], [ include "default.conf" -binary-byteorder: native +binary-byteorder: little-endian ]) AT_DATA([dump.c], [ @@ -656,7 +721,7 @@ AT_CHECK([test $SHREXT = "dll" || exit 77]) AT_DATA([test.conf], [ include "default.conf" -binary-byteorder: native +binary-byteorder: little-endian ]) AT_DATA([dump.c], [ @@ -2095,3 +2160,83 @@ AT_CHECK([java prog], [1], [], ]) AT_CLEANUP + +AT_SETUP([Open an invalid formatted indexed file]) + +AT_CHECK([echo invalid-data > invalid-formatted-file]) + +AT_DATA([prog.cbl], +[ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "invalid-formatted-file" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + PROCEDURE DIVISION. + MAIN-PROCEDURE. + + OPEN INPUT f. + DISPLAY FILE-STATUS. + CLOSE f. +]) + +AT_CHECK([${COMPILE} prog.cbl]) +AT_CHECK([java prog], [0], +[30 +]) +AT_CLEANUP + +AT_SETUP([Open an invalid formatted indexed file]) + +AT_CHECK([echo invalid-data > invalid-formatted-file]) + +AT_DATA([prog.cbl], +[ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + + ENVIRONMENT DIVISION. + INPUT-OUTPUT SECTION. + FILE-CONTROL. + SELECT F ASSIGN TO "invalid-formatted-file" + ORGANIZATION IS INDEXED + ACCESS MODE IS DYNAMIC + RECORD KEY IS REC-KEY + FILE STATUS IS FILE-STATUS. + + DATA DIVISION. + FILE SECTION. + FD f. + 01 REC. + 05 REC-KEY PIC X(5). + + WORKING-STORAGE SECTION. + 01 FILE-STATUS PIC XX. + PROCEDURE DIVISION. + MAIN-PROCEDURE. + + OPEN INPUT f. + DISPLAY FILE-STATUS. + CLOSE f. +]) + +AT_CHECK([${COMPILE} prog.cbl]) +AT_CHECK([java prog], [0], +[30 +]) +AT_CLEANUP diff --git a/tests/run.src/system-routines.at b/tests/run.src/system-routines.at new file mode 100644 index 00000000..25e7ca65 --- /dev/null +++ b/tests/run.src/system-routines.at @@ -0,0 +1,53 @@ +AT_SETUP([C$SLEEP]) + +AT_DATA([prog1.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog1. + PROCEDURE DIVISION. + DISPLAY "Start". + CALL "C$SLEEP" USING 4. + DISPLAY "End". + STOP RUN. +]) + +AT_CHECK([${COMPILE} prog1.cbl]) + +# Test that the prog1ram takes at least 2 seconds to execute +AT_CHECK([ +start_time=$(date +%s); +java prog1; +end_time=$(date +%s); +duration=$((end_time - start_time)); +test $duration -ge 2], [0], +[Start +End +]) + + +AT_DATA([prog2.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog2. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 WS-TIMEOUT PIC 9(4) COMP-3 VALUE 4. + PROCEDURE DIVISION. + DISPLAY "Start". + CALL "C$SLEEP" USING WS-TIMEOUT. + DISPLAY "End". + STOP RUN. +]) + +AT_CHECK([${COMPILE} prog2.cbl]) + +# Test that the prog2ram takes at least 2 seconds to execute +AT_CHECK([ +start_time=$(date +%s); +java prog2; +end_time=$(date +%s); +duration=$((end_time - start_time)); +test $duration -ge 2], [0], +[Start +End +]) + +AT_CLEANUP \ No newline at end of file diff --git a/update-version.sh b/update-version.sh index 555e6b81..fb52f85f 100755 --- a/update-version.sh +++ b/update-version.sh @@ -26,6 +26,7 @@ update_versions_in_file libcobj/app/src/main/java/jp/osscons/opensourcecobol/lib update_versions_in_file win/config.h # Rebuild +automake --add-missing autoreconf ./configure --prefix=/usr/ make diff --git a/win/cobj/cobj.vcxproj b/win/cobj/cobj.vcxproj index c74ea73b..2e1d9ef6 100644 --- a/win/cobj/cobj.vcxproj +++ b/win/cobj/cobj.vcxproj @@ -10,7 +10,7 @@ {d69ade50-ab78-4311-95a7-a9676e9bac36} Win32Proj cobj - 10.0.22621.0 + 10.0 10.0.17134.0 diff --git a/win/config.h b/win/config.h index 98802e06..fb43990b 100644 --- a/win/config.h +++ b/win/config.h @@ -299,7 +299,7 @@ #define ICONV_CONST /* Name of package */ -#define PACKAGE "opensource-cobol4j-1.1.2" +#define PACKAGE "opensource-cobol4j-1.1.14" /* Define to the address where bug reports for this package should be sent. */ #define PACKAGE_BUGREPORT "ws-opensource-cobol-contact@osscons.jp" @@ -308,13 +308,13 @@ #define PACKAGE_NAME "opensource COBOL 4J" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "opensource COBOL 4J 1.1.2" +#define PACKAGE_STRING "opensource COBOL 4J 1.1.14" /* Define to the one symbol short name of this package. */ -#define PACKAGE_TARNAME "opensource-cobol4j-1.1.2" +#define PACKAGE_TARNAME "opensource-cobol4j-1.1.14" /* Define to the version of this package. */ -#define PACKAGE_VERSION "1.1.2" +#define PACKAGE_VERSION "1.1.14" /* Define a patch level */ #define PATCH_LEVEL 0 diff --git a/win/x64/Release/cobj.exe b/win/x64/Release/cobj.exe deleted file mode 100644 index bea24018..00000000 Binary files a/win/x64/Release/cobj.exe and /dev/null differ