Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 14 additions & 1 deletion cobc/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,9 @@ output_data (cb_tree x)
/* Offset */
if (r->offset) {
output (" + ");
if (CB_TREE_CLASS (x) == CB_CLASS_NATIONAL) {
output ("%d * ", COB_NATIONAL_SIZE);
}
output_index (r->offset);
}

Expand Down Expand Up @@ -1317,6 +1320,9 @@ output_size (const cb_tree x)
break;
}
if (r->length) {
if (CB_TREE_CLASS (x) == CB_CLASS_NATIONAL) {
output ("%d * ", COB_NATIONAL_SIZE);
}
output_integer (r->length);
} else if (r->offset && f->flag_any_length) {
output ("%s%d.size - ", CB_PREFIX_FIELD, f->id);
Expand Down Expand Up @@ -1358,6 +1364,9 @@ output_size (const cb_tree x)
}
if (r->offset) {
output (" - ");
if (CB_TREE_CLASS (x) == CB_CLASS_NATIONAL) {
output ("%d * ", COB_NATIONAL_SIZE);
}
output_index (r->offset);
}
}
Expand Down Expand Up @@ -1600,7 +1609,11 @@ output_attr (const cb_tree x)
struct cb_field *f = CB_FIELD (r->value);
flags = 0;
if (r->offset) {
id = lookup_attr (COB_TYPE_ALPHANUMERIC, 0, 0, 0, NULL, 0);
if (CB_TREE_CLASS (x) == CB_CLASS_NATIONAL) {
id = lookup_attr (COB_TYPE_NATIONAL, 0, 0, 0, NULL, 0);
} else {
id = lookup_attr (COB_TYPE_ALPHANUMERIC, 0, 0, 0, NULL, 0);
}
Comment on lines +1612 to +1616
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct. Something similar may be needed for the national literals (then to be added directly above).

} else {
int type = cb_tree_type (x, f);
switch (type) {
Expand Down
10 changes: 10 additions & 0 deletions libcob/termio.c
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as this file had no 2025 changes and yours are the first in 2026: please add , 2026 the the years in the header

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for data_display.at

Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,16 @@ cob_display_common (const cob_field *f, FILE *fp)
display_numeric ((cob_field *)f, fp);
Comment on lines 330 to 334
Copy link
Collaborator Author

@GitMensch GitMensch Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you also can have national numeric data:

01 SOME-NUM-NAT PIC 9(6)v99 USAGE NATIONAL VALUE 12.34.

Therefore those two functions will possibly need handling of the national attribute as well (all data would be expected to be 0x00 = ISO8859-1 in the first byte ... but in this case it would be best to do a conversion to an internal alphanumeric field by skipping the low-value in the lower nibble and display it afterwards [for numerics that's fine as we can use a small fixed buffer - in case of national "text" we may get 2 GB fields so definitely don't want to do a conversion with a temporary field on that),
With the temporary alpahnumeric field we can simple call the normal display_numeric functions.

Can you please add a test of

DISPLAY SOME-NUM-NAT. (compiled with -fpretty-display/-fno-pretty-display)

(either fix the failing result with the approach above or mark it as expected fail)

return;
}
/* poor man's conversion */
if (COB_FIELD_IS_NATIONAL (f)) {
size_t i;
for (i = 0; i < f->size; i += 2) {
if (f->data[i] == 0x00) {
putc (f->data[i + 1], fp);
}
}
return;
}
display_alnum (f, fp);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a new display_national function and use an if/else to get the right one

}

Expand Down
104 changes: 104 additions & 0 deletions tests/testsuite.src/run_refmod.at
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,110 @@ d:d
AT_CLEANUP


AT_SETUP([Static reference-modification national])
AT_KEYWORDS([refmod])

AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 X PIC N(4) VALUE N"abcd".
PROCEDURE DIVISION.
DISPLAY X(1:1) ":" X(1:2) ":" X(1:3) ":" X(1:4) ":" X(1:)
END-DISPLAY.
DISPLAY X(2:1) ":" X(2:2) ":" X(2:3) ":" X(2:)
END-DISPLAY.
DISPLAY X(3:1) ":" X(3:2) ":" X(3:)
END-DISPLAY.
DISPLAY X(4:1) ":" X(4:)
END-DISPLAY.
STOP RUN.
])

AT_CHECK([$COMPILE -Wno-unfinished prog.cob], [0], [], [])
AT_CHECK([$COBCRUN_DIRECT ./prog], [0],
[a:ab:abc:abcd:abcd
b:bc:bcd:bcd
c:cd:cd
d:d
])

AT_CLEANUP


AT_SETUP([Static reference-modification UTF-8])
AT_KEYWORDS([refmod])

AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 X PIC U(4) VALUE U"aǭcde".
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a single-byte here - that should pass (we have the mixed-width test below)

PROCEDURE DIVISION.
DISPLAY X(1:1) ":" X(1:2) ":" X(1:3) ":" X(1:4) ":" X(1:)
END-DISPLAY.
DISPLAY X(2:1) ":" X(2:2) ":" X(2:3) ":" X(2:)
END-DISPLAY.
DISPLAY X(3:1) ":" X(3:2) ":" X(3:)
END-DISPLAY.
DISPLAY X(4:1) ":" X(4:)
END-DISPLAY.
STOP RUN.
])

# FIXME: currently single byte instead of single character

AT_XFAIL_IF([true])

AT_CHECK([$COMPILE -Wno-unfinished prog.cob], [0], [], [])
AT_CHECK([$COBCRUN_DIRECT ./prog], [0],
[a:aǭ:aǭc:aǭcd:aǭcd
ǭ:ǭc:ǭcd:ǭcd
c:cd:cd
d:d
])

AT_CLEANUP

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use two empty lines before a new test


AT_SETUP([Static reference-modification UTF-8 mixed byte-widths])
AT_KEYWORDS([refmod])

AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 X PIC U(4) VALUE U"aé日𝄞".
PROCEDURE DIVISION.
DISPLAY X(1:1) ":" X(1:2) ":" X(1:3) ":" X(1:4) ":" X(1:)
END-DISPLAY.
DISPLAY X(2:1) ":" X(2:2) ":" X(2:3) ":" X(2:)
END-DISPLAY.
DISPLAY X(3:1) ":" X(3:2) ":" X(3:)
END-DISPLAY.
DISPLAY X(4:1) ":" X(4:)
END-DISPLAY.
STOP RUN.
])

# FIXME: currently uses byte offset/length instead of character offset/length

AT_XFAIL_IF([true])

AT_CHECK([$COMPILE -Wno-unfinished prog.cob], [0], [], [])
AT_CHECK([$COBCRUN_DIRECT ./prog], [0],
[a:aé:aé日:aé日𝄞:aé日𝄞
é:é日:é日𝄞:é日𝄞
日:日𝄞:日𝄞
𝄞:𝄞
])

AT_CLEANUP


AT_SETUP([Dynamic reference-modification])
AT_KEYWORDS([refmod])

Expand Down
Loading