Skip to content

Commit 511d25e

Browse files
committed
Use file collating sequence for any key of alphanumeric class
Before this change, only keys that were alphanumeric elementary items or numeric display were supported.
1 parent 8ae3b07 commit 511d25e

File tree

3 files changed

+102
-3
lines changed

3 files changed

+102
-3
lines changed

cobc/ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* tree.c (validate_indexed_key_field): warn about ignored collating
55
sequence for non-alphanumeric keys (considers only primary keys and file
66
collating sequence for now)
7+
* codegen.c (output_indexed_file_key_colseq): assign collating sequence
8+
for any key of alphanumeric class
79

810
2024-08-28 David Declerck <[email protected]>
911

cobc/codegen.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9341,11 +9341,11 @@ output_indexed_file_key_colseq (const struct cb_file *f, const struct cb_alt_key
93419341
{
93429342
const cb_tree key = ak ? ak->key : f->key;
93439343
const cb_tree key_col = ak ? ak->collating_sequence_key : f->collating_sequence_key;
9344-
const int type = cb_tree_type (key, cb_code_field (key));
93459344
cb_tree col = NULL;
93469345

9347-
/* We only apply a collating sequence if the key is alphanumeric / display */
9348-
if ((type & COB_TYPE_ALNUM) || (type == COB_TYPE_NUMERIC_DISPLAY)) {
9346+
/* We only apply a collating sequence if the key is of class alphanumeric;
9347+
Warned in `validate_indexed_key_field`. */
9348+
if (CB_TREE_CLASS (key) == CB_CLASS_ALPHANUMERIC) {
93499349
col = key_col ? key_col : f->collating_sequence;
93509350
#if 0 /* TODO: this should be done for national, when available */
93519351
} else if (type & COB_TYPE_NATIONAL) {

tests/testsuite.src/run_file.at

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12781,6 +12781,103 @@ AT_CHECK([diff reference_ebcdic_ascii prog8.out], [0], [], [])
1278112781
AT_CLEANUP
1278212782

1278312783

12784+
12785+
AT_SETUP([INDEXED file with collation on group key])
12786+
AT_KEYWORDS([runfile WRITE READ EBCDIC])
12787+
12788+
AT_SKIP_IF([test "$COB_HAS_ISAM" = "no"])
12789+
12790+
AT_DATA([prog.cob], [
12791+
IDENTIFICATION DIVISION.
12792+
PROGRAM-ID. prog.
12793+
ENVIRONMENT DIVISION.
12794+
INPUT-OUTPUT SECTION.
12795+
FILE-CONTROL.
12796+
SELECT MY-FILE ASSIGN TO "testfile"
12797+
ORGANIZATION IS INDEXED
12798+
ACCESS IS DYNAMIC
12799+
RECORD KEY IS MY-KEY.
12800+
DATA DIVISION.
12801+
FILE SECTION.
12802+
FD MY-FILE.
12803+
01 MY-REC.
12804+
05 MY-KEY.
12805+
10 MY-KEY-1 PIC X.
12806+
10 MY-KEY-2 PIC X.
12807+
05 MY-DATA PIC 9.
12808+
PROCEDURE DIVISION.
12809+
12810+
OPEN OUTPUT MY-FILE
12811+
MOVE "111" TO MY-REC WRITE MY-REC
12812+
MOVE "AA2" TO MY-REC WRITE MY-REC
12813+
MOVE "223" TO MY-REC WRITE MY-REC
12814+
MOVE "BB4" TO MY-REC WRITE MY-REC
12815+
MOVE "335" TO MY-REC WRITE MY-REC
12816+
MOVE "CC6" TO MY-REC WRITE MY-REC
12817+
MOVE "447" TO MY-REC WRITE MY-REC
12818+
MOVE "DD8" TO MY-REC WRITE MY-REC
12819+
CLOSE MY-FILE
12820+
12821+
OPEN INPUT MY-FILE
12822+
MOVE LOW-VALUES TO MY-KEY
12823+
START MY-FILE KEY >= MY-KEY
12824+
INVALID KEY
12825+
DISPLAY "INVALID KEY"
12826+
NOT INVALID KEY
12827+
PERFORM UNTIL EXIT
12828+
READ MY-FILE NEXT
12829+
AT END
12830+
EXIT PERFORM
12831+
NOT AT END
12832+
DISPLAY MY-REC
12833+
END-READ
12834+
END-PERFORM
12835+
END-START.
12836+
CLOSE MY-FILE
12837+
12838+
STOP RUN.
12839+
])
12840+
12841+
AT_DATA([expout],
12842+
[ASCII:
12843+
111
12844+
223
12845+
335
12846+
447
12847+
AA2
12848+
BB4
12849+
CC6
12850+
DD8
12851+
EBCDIC:
12852+
AA2
12853+
BB4
12854+
CC6
12855+
DD8
12856+
111
12857+
223
12858+
335
12859+
447
12860+
])
12861+
12862+
# Note: ignore any unfinished warning as the test is about the runtime behavior:
12863+
AT_CHECK([$COMPILE -Wno-unfinished -fdefault-file-colseq=ASCII prog.cob -o ascii], [0])
12864+
AT_CHECK([$COMPILE -Wno-unfinished -fdefault-file-colseq=EBCDIC prog.cob -o ebcdic], [0])
12865+
12866+
# This is, so far, only supported by the BDB backend
12867+
AT_CHECK([test "$COB_HAS_ISAM" = "db"], [0], [], [],
12868+
# Previous test "failed" --> other ISAM, skip the test
12869+
[AT_CHECK([true])],
12870+
12871+
# Previous test "passed" --> using BDB, perform the actual test
12872+
[AT_CHECK([
12873+
echo "ASCII:" && $COBCRUN_DIRECT ./ascii && \
12874+
echo "EBCDIC:" && $COBCRUN_DIRECT ./ebcdic
12875+
], [0], [expout]) # <- compare stdout with exiting `expout`
12876+
])
12877+
12878+
AT_CLEANUP
12879+
12880+
1278412881
AT_SETUP([INDEXED file numeric keys ordering])
1278512882
AT_KEYWORDS([runfile])
1278612883

0 commit comments

Comments
 (0)