Skip to content

NATIONAL + UTF8 tests, ref-mod: fix byte offset/size with poor man's display conversion#280

Draft
GitMensch wants to merge 2 commits intoOCamlPro:gitside-gnucobol-3.xfrom
hornepm:gitside-gnucobol-3.x
Draft

NATIONAL + UTF8 tests, ref-mod: fix byte offset/size with poor man's display conversion#280
GitMensch wants to merge 2 commits intoOCamlPro:gitside-gnucobol-3.xfrom
hornepm:gitside-gnucobol-3.x

Conversation

@GitMensch
Copy link
Collaborator

PR to review and discuss @hornepm's changes which serves also as a way to get a better picture what the GSoC proposal need to cover / the project will look like

Copy link
Collaborator Author

@GitMensch GitMensch left a comment

Choose a reason for hiding this comment

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

Thank you for this first iteration - looks good!

We definitely need a Changelog entry in cobc and libcob, so please add those in your next commit.

Comment on lines +1612 to +1616
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);
}
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).

libcob/termio.c Outdated
Comment on lines 326 to 336
/* 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

Comment on lines 319 to 323
if (COB_MODULE_PTR->flag_pretty_display) {
pretty_display_numeric ((cob_field *)f, fp);
return;
}
display_numeric ((cob_field *)f, fp);
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)

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)

Copy link
Collaborator Author

@GitMensch GitMensch left a comment

Choose a reason for hiding this comment

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

This is nearly ready for commit (with expected failures); do you want to go on with this PR handling (part of) the NATIONAL failures or should we upstream it before?

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

Comment on lines +221 to +226
size_t i;
for (i = 0; i < f->size; i += 2) {
if (f->data[i] == 0x00) {
putc (f->data[i + 1], 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.

please use the same pointer arithmetic (just with p += 2) and the temporary const int as well as the check we have in display_alnum; background: putc may return an error in which case we should break out of the loop instead of creating more errrors

static void
display_national (const cob_field *f, FILE *fp)
{
size_t i;
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 add a /* TODO */ marker here outlining that we currently only display national data that overlaps ISO8859-1 and will need an iconv approach later on

@@ -1 +1 @@
## Copyright (C) 2003-2012, 2014-2015, 2017-2020, 2013 Free Software Foundation, Inc.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should be
2003-2012, 2014-2015, 2017-2020, 2023, 2026 here

])

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

Comment on lines +2 to +8
2026-03-23 Preston Horne <preston.m.horne@vanderbilt.edu>

* testsuite.src/run_refmod.at: add static and dynamic
reference-modification tests for NATIONAL and UTF-8 fields
* testsuite.src/data_display.at: add DISPLAY test for NATIONAL
fields and literals with HEX-OF

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not obvious:
this file is actually only adjusted for testcases if we heavily refactor them, otherwise this is left to "infrastucture" changes

--> nice (but not enforeced) to be part of the log message

Comment on lines +159 to +167
AT_CHECK([$COMPILE -Wno-unfinished prog.cob], [0], [], [])
AT_CHECK([$COBCRUN_DIRECT ./prog], [0],
[1234
0031003200330034
00001234
00300030003000300031003200330034
abcd
0061006200630064
])
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 well, as this is displaying numerics, you may compile and run it twice: (with -fpretty-display/-fno-pretty-display) as this will go into different functions

(either fix the failing result with the approach mentioned in termio.c or keep it marked as expected fail)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants