Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeclerck committed Nov 5, 2024
1 parent e88347b commit 05c662f
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 56 deletions.
4 changes: 4 additions & 0 deletions cobc/cobc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4218,6 +4218,10 @@ process_command_line (const int argc, char **argv)
cb_flag_alt_ebcdic ? "alternate" : "default");
}

if (cob_load_collation (cb_ebcdic_table, ebcdic_to_ascii, ascii_to_ebcdic) < 0) {
cobc_err_exit (_("invalid parameter: %s"), "-febcdic-table");
}

/* Exit on missing options */
#ifdef COB_INTERNAL_XREF
if (cb_listing_xref && !cb_listing_outputfile) {
Expand Down
6 changes: 0 additions & 6 deletions cobc/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2652,12 +2652,6 @@ output_colseq_table_field (const char * field_name, const char * table_name)
static void
output_collating_tables (void)
{

/* Load the collating tables if needed */
if (gen_ascii_ebcdic || gen_ebcdic_ascii) {
load_collating_tables ();
}

if (gen_native) {
output_storage ("\n/* NATIVE table */\n");
output_colseq_table ("cob_native", NULL);
Expand Down
19 changes: 1 addition & 18 deletions cobc/scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -1347,10 +1347,6 @@ static cob_u8_t
scan_ebcdic_char (int c)
{
char buff[10]; /* Arbitrary limit, mostly for error-reporting */
#ifndef COB_EBCDIC_MACHINE
static cob_u8_t ebcdic_to_ascii[256] ;
static int ebcdic_to_ascii_initialized = 0 ;
#endif
unsigned int j = 0;
do {
buff[j++] = (char)c;
Expand All @@ -1367,20 +1363,7 @@ scan_ebcdic_char (int c)
#ifdef COB_EBCDIC_MACHINE
return (cob_u8_t) c;
#else
if (!ebcdic_to_ascii_initialized ) {
if (cob_load_collation (cb_ebcdic_table, ebcdic_to_ascii, NULL) < 0) {
cb_error (_("invalid parameter: %s"), "-febcdic-table");
ebcdic_to_ascii_initialized = -1;
} else {
ebcdic_to_ascii_initialized = 1;
}
}

if (ebcdic_to_ascii_initialized > 0) {
return ebcdic_to_ascii[c];
} else {
return '?';
}
return ebcdic_to_ascii[c];
#endif
}

Expand Down
4 changes: 2 additions & 2 deletions cobc/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -2193,8 +2193,8 @@ cb_build_program (struct cb_program *last_program, const int nest_level)
p->decimal_point = '.';
p->currency_symbol = '$';
p->numeric_separator = ',';
p->low_value = '\0';
p->high_value = '\xff';
p->low_value = 0;
p->high_value = 255;
if (cb_call_extfh) {
p->extfh = cobc_parse_strdup (cb_call_extfh);
}
Expand Down
48 changes: 20 additions & 28 deletions cobc/typeck.c
Original file line number Diff line number Diff line change
Expand Up @@ -3745,19 +3745,6 @@ get_value (cb_tree x)
}
}

void
load_collating_tables (void)
{
static int coltab_loaded = 0;
if (coltab_loaded) {
return;
}
if (cob_load_collation (cb_ebcdic_table, ebcdic_to_ascii, ascii_to_ebcdic) < 0) {
cobc_err_exit (_("invalid parameter: %s"), "-febcdic-table");
}
coltab_loaded = 1;
}

static int
cb_validate_collating (struct cb_program *prog, cb_tree collating_sequence)
{
Expand All @@ -3776,33 +3763,40 @@ cb_validate_collating (struct cb_program *prog, cb_tree collating_sequence)

#ifdef COB_EBCDIC_MACHINE
if (CB_ALPHABET_NAME (x)->alphabet_type == CB_ALPHABET_ASCII) {
load_collating_tables ();
prog->low_value = ascii_to_ebcdic[0x00];
prog->high_value = ascii_to_ebcdic[0xff];
#else
if (CB_ALPHABET_NAME (x)->alphabet_type == CB_ALPHABET_EBCDIC) {
load_collating_tables ();
prog->low_value = ebcdic_to_ascii[0x00];
prog->high_value = ebcdic_to_ascii[0xff];
#endif
} else if (CB_ALPHABET_NAME (x)->alphabet_type == CB_ALPHABET_CUSTOM) {
prog->low_value = (unsigned char)CB_ALPHABET_NAME (x)->low_val_char;
prog->high_value = (unsigned char)CB_ALPHABET_NAME (x)->high_val_char;
if (CB_ALPHABET_NAME (x)->alphabet_target == CB_ALPHABET_ALPHANUMERIC) {
prog->low_value = (unsigned char)CB_ALPHABET_NAME (x)->low_val_char;
prog->high_value = (unsigned char)CB_ALPHABET_NAME (x)->high_val_char;
} else {
/* TODO: LOW/HIGH-VALUE for national */
}
} else {
return 0;
}

if (prog->low_value) {
cb_low = cb_build_alphanumeric_literal ("\0", (size_t)1);
CB_LITERAL(cb_low)->data[0] = prog->low_value;
CB_LITERAL(cb_low)->all = 1;
}
if (CB_ALPHABET_NAME (x)->alphabet_target == CB_ALPHABET_ALPHANUMERIC) {
if (prog->low_value) {
cb_low = cb_build_alphanumeric_literal ("\0", (size_t)1);
CB_LITERAL(cb_low)->data[0] = prog->low_value;
CB_LITERAL(cb_low)->all = 1;
}

if (prog->high_value != 255){
cb_high = cb_build_alphanumeric_literal ("\0", (size_t)1);
CB_LITERAL(cb_high)->data[0] = prog->high_value;
CB_LITERAL(cb_high)->all = 1;
if (prog->high_value != 255){
cb_high = cb_build_alphanumeric_literal ("\0", (size_t)1);
CB_LITERAL(cb_high)->data[0] = prog->high_value;
CB_LITERAL(cb_high)->all = 1;
}
} else {
/* TODO: LOW/HIGH-VALUE for national */
}

return 0;
}

Expand Down Expand Up @@ -3855,7 +3849,6 @@ validate_alphabet (cb_tree alphabet)
register int *entry = ap->values;
for (n = 0; n < COB_MAX_CHAR_ALPHANUMERIC + 1; n++) {
#ifdef COB_EBCDIC_MACHINE
load_collating_tables ();
*entry = (int)ascii_to_ebcdic[n];
#else
*entry = n;
Expand All @@ -3880,7 +3873,6 @@ validate_alphabet (cb_tree alphabet)
#ifdef COB_EBCDIC_MACHINE
*entry = n;
#else
load_collating_tables ();
*entry = (int)ebcdic_to_ascii[n];
#endif
entry++;
Expand Down
8 changes: 7 additions & 1 deletion tests/testsuite.src/run_misc.at
Original file line number Diff line number Diff line change
Expand Up @@ -4009,6 +4009,12 @@ AT_KEYWORDS([runmisc default-colseq])
AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
OBJECT-COMPUTER. x86,
PROGRAM COLLATING SEQUENCE IS alpha-ebcdic.
SPECIAL-NAMES.
ALPHABET alpha-ebcdic IS EBCDIC.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 TAB.
Expand All @@ -4029,7 +4035,7 @@ AT_DATA([prog.cob], [
STOP RUN.
])

AT_CHECK([$COMPILE -febcdic-table=ebcdic500_latin1 -fdefault-colseq=EBCDIC prog.cob], [0], [], [])
AT_CHECK([$COMPILE -febcdic-table=ebcdic500_latin1 prog.cob], [0], [], [])
AT_CHECK([$COBCRUN_DIRECT ./prog], [0], [], [])

AT_CLEANUP
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite.src/syn_literals.at
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@ AT_CHECK([$COMPILE prog2.cob], [0], [],
])
AT_CHECK([$COMPILE -febcdic-symbolic-characters -febcdic-table=dummyNotThere prog2.cob], [1], [],
[libcob: error: can't open translation table 'dummyNotThere'
prog2.cob:5: error: invalid parameter: -febcdic-table
cobc: error: invalid parameter: -febcdic-table
])

AT_CLEANUP

0 comments on commit 05c662f

Please sign in to comment.