Skip to content

Commit 86905d1

Browse files
Fix INSPECT statement (#268)
1 parent b42d8e1 commit 86905d1

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1717
### Fixed
1818
* Fix the message of COB_VERBOSE file sort (#260)
1919
* Fix the process that checks MOVE statements (#266, #267)
20+
* Fix `INSPECT` statement (#268)
2021
### Optimized
2122
* Optimize the file reading process (#257)
2223

libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolInspect.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,17 @@ private static void common(AbstractCobolField f1, AbstractCobolField f2, int typ
107107
int n = 0;
108108
if (type == INSPECT_TRAILING) {
109109
for (int i = len - f2.getSize(); i >= 0; i--) {
110-
if (inspectData
111-
.getSubDataStorage(inspectStart + i)
112-
.memcmp(f2.getDataStorage(), f2.getSize())
113-
== 0) {
110+
if (inspectData.memcmp(inspectStart + i, f2.getDataStorage(), f2.getSize()) == 0) {
114111
int j;
115112
for (j = 0; j < f2.getSize(); ++j) {
116113
if (inspectMark[mark + i + j] != -1) {
117114
break;
118115
}
119116
}
120117
if (j == f2.getSize()) {
118+
CobolDataStorage f1Storage = f1.getDataStorage();
121119
for (j = 0; j < f2.getSize(); ++j) {
122-
inspectMark[mark + i + j] =
123-
inspectReplacing != 0 ? f1.getDataStorage().getByte(i) : 1;
120+
inspectMark[mark + i + j] = inspectReplacing != 0 ? f1Storage.getByte(j) : 1;
124121
}
125122
i -= f2.getSize() - 1;
126123
n++;
@@ -131,20 +128,17 @@ private static void common(AbstractCobolField f1, AbstractCobolField f2, int typ
131128
}
132129
} else {
133130
for (int i = 0; i < (len - f2.getSize() + 1); ++i) {
134-
if (inspectData
135-
.getSubDataStorage(inspectStart + i)
136-
.memcmp(f2.getDataStorage(), f2.getSize())
137-
== 0) {
131+
if (inspectData.memcmp(inspectStart + i, f2.getDataStorage(), f2.getSize()) == 0) {
138132
int j;
139133
for (j = 0; j < f2.getSize(); ++j) {
140134
if (inspectMark[mark + i + j] != -1) {
141135
break;
142136
}
143137
}
144138
if (j == f2.getSize()) {
139+
CobolDataStorage f1Storage = f1.getDataStorage();
145140
for (j = 0; j < f2.getSize(); ++j) {
146-
inspectMark[mark + i + j] =
147-
inspectReplacing != 0 ? f1.getDataStorage().getByte(j) : 1;
141+
inspectMark[mark + i + j] = inspectReplacing != 0 ? f1Storage.getByte(j) : 1;
148142
}
149143
i += f2.getSize() - 1;
150144
n++;

libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolDataStorage.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,17 @@ public int memcmp(CobolDataStorage buf, int size) {
329329
return 0;
330330
}
331331

332+
public int memcmp(int offset, CobolDataStorage buf, int size) {
333+
for (int i = 0; i < size; ++i) {
334+
byte x = this.getByte(offset + i);
335+
byte y = buf.getByte(i);
336+
if (x != y) {
337+
return Byte.toUnsignedInt(x) - Byte.toUnsignedInt(y);
338+
}
339+
}
340+
return 0;
341+
}
342+
332343
/**
333344
* 引数で与えられたバイト配列をthis.dataの先頭からコピーする
334345
*

tests/run.src/miscellaneous.at

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,6 @@ AT_CHECK([java prog], [0], [000003])
874874
AT_CLEANUP
875875

876876
AT_SETUP([INSPECT REPLACING TRAILING ZEROS BY SPACES])
877-
AT_CHECK([${SKIP_TEST}])
878877

879878
AT_DATA([prog.cob], [
880879
IDENTIFICATION DIVISION.
@@ -895,7 +894,6 @@ AT_CHECK([java prog], [0], [1 ])
895894
AT_CLEANUP
896895

897896
AT_SETUP([INSPECT REPLACING complex])
898-
AT_CHECK([${SKIP_TEST}])
899897

900898
AT_DATA([prog.cob], [
901899
IDENTIFICATION DIVISION.

0 commit comments

Comments
 (0)