Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cobc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

2025-10-21 Roger Bowler <rbowler@snipix.net>

* field.c (setup_parameters): set flag_binary_swap for COMP-5 fields
when comp-5-uses-binary-byteorder dialect option is set

2025-07-30 Simon Sobisch <simonsobisch@gnu.org>

* scanner.l, parser.y, reserved.c: use yyless to push part of scanned
Expand Down
3 changes: 3 additions & 0 deletions cobc/config.def
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ CB_CONFIG_BOOLEAN (cb_pretty_display, "pretty-display",
CB_CONFIG_BOOLEAN (cb_binary_truncate, "binary-truncate",
_("numeric truncation according to ANSI"))

CB_CONFIG_BOOLEAN (cb_comp_5_uses_binary_byteorder, "comp-5-uses-binary-byteorder",
_("COMP-5 uses the same byte order as BINARY"))

CB_CONFIG_BOOLEAN (cb_complex_odo, "complex-odo",
_("allow non-standard OCCURS DEPENDING ON syntax"))

Expand Down
5 changes: 5 additions & 0 deletions cobc/field.c
Original file line number Diff line number Diff line change
Expand Up @@ -2530,6 +2530,11 @@ setup_parameters (struct cb_field *f)
}
}
#ifndef WORDS_BIGENDIAN
if (f->usage == CB_USAGE_COMP_5 &&
cb_comp_5_uses_binary_byteorder &&
cb_binary_byteorder == CB_BYTEORDER_BIG_ENDIAN) {
f->flag_binary_swap = 1;
}
if (f->usage == CB_USAGE_COMP_X &&
cb_binary_byteorder == CB_BYTEORDER_BIG_ENDIAN) {
f->flag_binary_swap = 1;
Expand Down
4 changes: 4 additions & 0 deletions config/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

2025-10-21 Roger Bowler <rbowler@snipix.net>

* general: add option comp-5-uses-binary-byteorder

2025-04-22 Chuck Haatvedt <chuck.haatvedt+cobol@gmail.com>

* runtime.cfg: add runtime configuration COB_HEAP_MEMORY and
Expand Down
3 changes: 3 additions & 0 deletions config/acu-strict.conf
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ binary-truncate: yes
# Value: 'native', 'big-endian'
binary-byteorder: big-endian

# COMP-5 uses binary byte order instead of native byte order
comp-5-uses-binary-byteorder: no

# Allow larger REDEFINES items other than 01 non-external
larger-redefines: ok # not verified yet

Expand Down
3 changes: 3 additions & 0 deletions config/bs2000-strict.conf
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ binary-truncate: yes # TO-DO: For BINARY, *not* for COMP or COMP-5!
# Value: 'native', 'big-endian'
binary-byteorder: big-endian

# COMP-5 uses binary byte order instead of native byte order
comp-5-uses-binary-byteorder: no

# Allow larger REDEFINES items other than 01 non-external
larger-redefines: error

Expand Down
3 changes: 3 additions & 0 deletions config/cobol2002.conf
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ binary-truncate: yes
# Value: 'native', 'big-endian'
binary-byteorder: big-endian

# COMP-5 uses binary byte order instead of native byte order
comp-5-uses-binary-byteorder: no

# Allow larger REDEFINES items other than 01 non-external
larger-redefines: error

Expand Down
3 changes: 3 additions & 0 deletions config/cobol2014.conf
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ binary-truncate: yes
# Value: 'native', 'big-endian'
binary-byteorder: big-endian

# COMP-5 uses binary byte order instead of native byte order
comp-5-uses-binary-byteorder: no

# Allow larger REDEFINES items other than 01 non-external
larger-redefines: error

Expand Down
3 changes: 3 additions & 0 deletions config/cobol85.conf
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ binary-truncate: yes
# Value: 'native', 'big-endian'
binary-byteorder: big-endian

# COMP-5 uses binary byte order instead of native byte order
comp-5-uses-binary-byteorder: no

# Allow larger REDEFINES items other than 01 non-external
larger-redefines: error

Expand Down
3 changes: 3 additions & 0 deletions config/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ binary-truncate: yes
# Value: 'native', 'big-endian'
binary-byteorder: big-endian

# COMP-5 uses binary byte order instead of native byte order
comp-5-uses-binary-byteorder: no

# Allow larger REDEFINES items other than 01 non-external
larger-redefines: error

Expand Down
3 changes: 3 additions & 0 deletions config/gcos-strict.conf
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ binary-truncate: yes
# Value: 'native', 'big-endian'
binary-byteorder: big-endian

# COMP-5 uses binary byte order instead of native byte order
comp-5-uses-binary-byteorder: no

# Allow larger REDEFINES items
larger-redefines: error

Expand Down
3 changes: 3 additions & 0 deletions config/ibm-strict.conf
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ binary-truncate: no
# Value: 'native', 'big-endian'
binary-byteorder: big-endian

# COMP-5 uses binary byte order instead of native byte order
comp-5-uses-binary-byteorder: no

# Allow larger REDEFINES items other than 01 non-external
larger-redefines: error

Expand Down
3 changes: 3 additions & 0 deletions config/mf-strict.conf
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ binary-truncate: no
# Value: 'native', 'big-endian'
binary-byteorder: big-endian

# COMP-5 uses binary byte order instead of native byte order
comp-5-uses-binary-byteorder: no

# Allow larger REDEFINES items other than 01 non-external
larger-redefines: ok

Expand Down
3 changes: 3 additions & 0 deletions config/mvs-strict.conf
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ binary-truncate: no
# Value: 'native', 'big-endian'
binary-byteorder: big-endian

# COMP-5 uses binary byte order instead of native byte order
comp-5-uses-binary-byteorder: no

# Allow larger REDEFINES items other than 01 non-external
larger-redefines: error

Expand Down
3 changes: 3 additions & 0 deletions config/realia-strict.conf
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ binary-truncate: no # to check
# Value: 'native', 'big-endian'
binary-byteorder: big-endian # to check

# COMP-5 uses binary byte order instead of native byte order
comp-5-uses-binary-byteorder: no

# Allow larger REDEFINES items other than 01 non-external
larger-redefines: error # not verified yet

Expand Down
3 changes: 3 additions & 0 deletions config/rm-strict.conf
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ binary-truncate: yes
# Value: 'native', 'big-endian'
binary-byteorder: big-endian

# COMP-5 uses binary byte order instead of native byte order
comp-5-uses-binary-byteorder: no

# Allow larger REDEFINES items other than 01 non-external
larger-redefines: ok # (see p. 134)

Expand Down
3 changes: 3 additions & 0 deletions config/xopen.conf
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ binary-truncate: yes
# Value: 'native', 'big-endian'
binary-byteorder: big-endian

# COMP-5 uses binary byte order instead of native byte order
comp-5-uses-binary-byteorder: no

# Allow larger REDEFINES items other than 01 non-external
larger-redefines: error

Expand Down
1 change: 1 addition & 0 deletions tests/testsuite.src/configuration.at
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ test.conf: missing definitions:
no definition of 'filename-mapping'
no definition of 'pretty-display'
no definition of 'binary-truncate'
no definition of 'comp-5-uses-binary-byteorder'
no definition of 'complex-odo'
no definition of 'odoslide'
no definition of 'init-justify'
Expand Down
90 changes: 90 additions & 0 deletions tests/testsuite.src/data_binary.at
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,96 @@ DISPLAY: 85 != BINARY : 217
AT_CLEANUP


# comp-5 byteorder

AT_SETUP([COMP-5 byteorder])
AT_KEYWORDS([binary comp-5 byteorder])

AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 X-P2 BINARY-SHORT UNSIGNED VALUE 23456.
01 X-P3 BINARY-LONG UNSIGNED VALUE 2345678901.
01 X-P4 BINARY-DOUBLE UNSIGNED VALUE 2345678901234567891.
01 X-P6 PIC 9(4) COMP-5 VALUE 23456.
01 X-P7 PIC 9(8) COMP-5 VALUE 2345678901.
01 X-P8 PIC 9(18) COMP-5 VALUE 2345678901234567891.
01 X-N2 BINARY-SHORT VALUE -12345.
01 X-N3 BINARY-LONG VALUE -1234567890.
01 X-N4 BINARY-DOUBLE VALUE -1234567890123456789.
01 X-N6 PIC S9(4) COMP-5 VALUE -12345.
01 X-N7 PIC S9(8) COMP-5 VALUE -1234567890.
01 X-N8 PIC S9(18) COMP-5 VALUE -1234567890123456789.
PROCEDURE DIVISION.
DISPLAY 'BINARY-SHORT UNSIGNED ' FUNCTION HEX-OF(X-P2)
DISPLAY 'BINARY-LONG UNSIGNED ' FUNCTION HEX-OF(X-P3)
DISPLAY 'BINARY-DOUBLE UNSIGNED ' FUNCTION HEX-OF(X-P4)
DISPLAY 'PIC 9(4) COMP-5 ' FUNCTION HEX-OF(X-P6)
DISPLAY 'PIC 9(8) COMP-5 ' FUNCTION HEX-OF(X-P7)
DISPLAY 'PIC 9(18) COMP-5 ' FUNCTION HEX-OF(X-P8)
DISPLAY 'BINARY-SHORT ' FUNCTION HEX-OF(X-N2)
DISPLAY 'BINARY-LONG ' FUNCTION HEX-OF(X-N3)
DISPLAY 'BINARY-DOUBLE ' FUNCTION HEX-OF(X-N4)
DISPLAY 'PIC S9(4) COMP-5 ' FUNCTION HEX-OF(X-N6)
DISPLAY 'PIC S9(8) COMP-5 ' FUNCTION HEX-OF(X-N7)
DISPLAY 'PIC S9(18) COMP-5 ' FUNCTION HEX-OF(X-N8)
STOP RUN.
])

if test "x$COB_BIGENDIAN" = "xyes"; then
AT_CHECK([true])
else

# COMP-5 BINARY-SHORT BINARY-LONG and BINARY-DOUBLE
# are stored in native (little-endian) format,
# even when binary-byteorder=big-endian is specified,
# unless comp-5-uses-binary-byteorder is also specified
AT_CHECK([$COMPILE -fbinary-size=2-4-8 \
-fbinary-byteorder=big-endian \
prog.cob -o prog3], [0], [], [])
AT_CHECK([$COBCRUN_DIRECT ./prog3], [0],
[BINARY-SHORT UNSIGNED A05B
BINARY-LONG UNSIGNED 3538D08B
BINARY-DOUBLE UNSIGNED D30A376188868D20
PIC 9(4) COMP-5 A05B
PIC 9(8) COMP-5 3538D08B
PIC 9(18) COMP-5 D30A376188868D20
BINARY-SHORT C7CF
BINARY-LONG 2EFD69B6
BINARY-DOUBLE EB7E16820BEFDDEE
PIC S9(4) COMP-5 C7CF
PIC S9(8) COMP-5 2EFD69B6
PIC S9(18) COMP-5 EB7E16820BEFDDEE
])
fi

# COMP-5 BINARY-SHORT BINARY-LONG and BINARY-DOUBLE
# are stored in big-endian format only when specifying both
# binary-byteorder=big-endian and comp-5-uses-binary-byteorder
AT_CHECK([$COMPILE -fbinary-size=2-4-8 \
-fbinary-byteorder=big-endian \
-fcomp-5-uses-binary-byteorder \
prog.cob -o prog4], [0], [], [])
AT_CHECK([$COBCRUN_DIRECT ./prog4], [0],
[BINARY-SHORT UNSIGNED 5BA0
BINARY-LONG UNSIGNED 8BD03835
BINARY-DOUBLE UNSIGNED 208D868861370AD3
PIC 9(4) COMP-5 5BA0
PIC 9(8) COMP-5 8BD03835
PIC 9(18) COMP-5 208D868861370AD3
BINARY-SHORT CFC7
BINARY-LONG B669FD2E
BINARY-DOUBLE EEDDEF0B82167EEB
PIC S9(4) COMP-5 CFC7
PIC S9(8) COMP-5 B669FD2E
PIC S9(18) COMP-5 EEDDEF0B82167EEB
])

AT_CLEANUP


AT_SETUP([MOVE DISPLAY to BINARY])
AT_KEYWORDS([fundamental PPP])

Expand Down