Skip to content

Commit ae2469f

Browse files
Fix variable length SEQUENTIAL files (#722)
* fix: set limits of sequential file records * test: add tests for variable length files * chore: remove unnecessary spaces * fix: check that the record size is not less than record_min
1 parent c302ca2 commit ae2469f

File tree

7 files changed

+59
-3
lines changed

7 files changed

+59
-3
lines changed

libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolRelativeFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public int open_(String filename, int mode, int sharing) throws IOException {
192192
}
193193
}
194194

195-
if(mode == COB_OPEN_OUTPUT) {
195+
if (mode == COB_OPEN_OUTPUT) {
196196
this.fp.setLength(0);
197197
this.fp.seek(0);
198198
}

libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolSequentialFile.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ public int readNext(int readOpts) {
135135
}
136136
}
137137
int size = ByteBuffer.wrap(sbuff).getInt();
138+
size = Math.max(size, this.record_min);
139+
size = Math.min(size, this.record_max);
138140
this.record.setSize(size);
139141
}
140142

tests/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ misc_DEPENDENCIES = \
261261
misc.src/fix-subtract.at \
262262
misc.src/display-numeric-NUMERIC-class.at \
263263
misc.src/display-inspect-sign.at \
264-
misc.src/comp1-comp2.at
264+
misc.src/comp1-comp2.at \
265+
misc.src/variable-length-file.at
265266

266267
EXTRA_DIST = $(srcdir)/package.m4 \
267268
$(TESTS) \

tests/Makefile.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,8 @@ misc_DEPENDENCIES = \
800800
misc.src/fix-subtract.at \
801801
misc.src/display-numeric-NUMERIC-class.at \
802802
misc.src/display-inspect-sign.at \
803-
misc.src/comp1-comp2.at
803+
misc.src/comp1-comp2.at \
804+
misc.src/variable-length-file.at
804805

805806
EXTRA_DIST = $(srcdir)/package.m4 \
806807
$(TESTS) \

tests/misc.at

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,4 @@ m4_include([fix-subtract.at])
5656
m4_include([display-numeric-NUMERIC-class.at])
5757
m4_include([display-inspect-sign.at])
5858
m4_include([comp1-comp2.at])
59+
m4_include([variable-length-file.at])

tests/misc.src/TEST_VAR_LENGTH.txt

787 Bytes
Binary file not shown.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
AT_SETUP([READING VARIABLE LENGTH FILE])
2+
3+
AT_DATA([prog.cbl], [
4+
IDENTIFICATION DIVISION.
5+
PROGRAM-ID. prog.
6+
ENVIRONMENT DIVISION.
7+
INPUT-OUTPUT SECTION.
8+
FILE-CONTROL.
9+
SELECT TEST-FILE
10+
ASSIGN TO "../../misc.src/TEST_VAR_LENGTH.txt".
11+
DATA DIVISION.
12+
FILE SECTION.
13+
FD TEST-FILE.
14+
01 REC-1 PIC X(18).
15+
01 REC-2 PIC X(54).
16+
PROCEDURE DIVISION.
17+
MAIN-PARA.
18+
MOVE SPACES TO REC-1 REC-2.
19+
PERFORM OPEN-FILE.
20+
PERFORM READ-REC.
21+
PERFORM CLOSE-FILE.
22+
STOP RUN.
23+
24+
OPEN-FILE.
25+
OPEN INPUT TEST-FILE.
26+
27+
READ-REC.
28+
DISPLAY "REC-1: " REC-1.
29+
DISPLAY "REC-2: " REC-2.
30+
READ TEST-FILE.
31+
DISPLAY "REC-1: " REC-1.
32+
DISPLAY "REC-2: " REC-2.
33+
34+
CLOSE-FILE.
35+
CLOSE TEST-FILE.
36+
])
37+
38+
// Checking the number of bytes
39+
AT_CHECK([od -N 4 -t x1 -An ../../misc.src/TEST_VAR_LENGTH.txt], [0],
40+
[ 00 00 03 0e
41+
])
42+
43+
AT_CHECK([${COMPILE} prog.cbl], [0])
44+
AT_CHECK([${RUN_MODULE} prog], [0],
45+
[REC-1: @&t@
46+
REC-2: @&t@
47+
REC-1: LLL5555555555555 5
48+
REC-2: LLL5555555555555 555555555555L555555555555555555555555
49+
])
50+
51+
AT_CLEANUP

0 commit comments

Comments
 (0)