-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dialect option: normalize BCD "on-the-fly" when moving from ALPHANUMERIC to NUMERIC #200
base: gcos4gnucobol-3.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,11 @@ | |
|
||
* cobc.c (process_command_line): fix leak for --copy and -include parsing | ||
|
||
2024-12-05 David Declerck <[email protected]> | ||
|
||
* config.def: new normalize-bcd dialect option | ||
* codegen.c (output_module_init_function): initialize flag_normalize_bcd | ||
|
||
2024-10-30 Chuck Haatvedt <[email protected]> | ||
|
||
* typeck.c: define [WITH_EXTENDED_SCREENIO] for any curses headers | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,10 @@ | |
|
||
* gcos-strict.conf: set init-justify to no after testing on GCOS | ||
|
||
2024-12-05 David Declerck <[email protected]> | ||
|
||
* general: add the normalize-bcd dialect option (active only for GCOS) | ||
|
||
2024-08-17 Ammar Almoris <[email protected]> | ||
|
||
FR #474: add runtime configuration to hide cursor for extended screenio | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,15 @@ | |
* screenio.c [WITH_PANELS]: replace use of ncurses extension ceiling_panel() | ||
with X/Open Curses function panel_below() | ||
|
||
2024-12-05 David Declerck <[email protected]> | ||
|
||
* common.h: new flag_normalize_bcd field in cob_module | ||
* common.c, coblocal.h (cob_get_sign_from_alnum): new function | ||
to retrieve the "sign" of an ALPHANUMERIC field | ||
* move.c (cob_move_alphanum_to_display), | ||
numeric.c (cob_decimal_set_display): perform BCD | ||
normalization when flag_normalize_bcd is set | ||
|
||
2024-11-22 David Declerck <[email protected]> | ||
|
||
* move.c (optimized_move_display_to_edited): minor refactoring | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -309,6 +309,7 @@ cob_move_alphanum_to_display (cob_field *f1, cob_field *f2) | |
const unsigned char *e2 = s2 + COB_FIELD_SIZE (f2); | ||
const unsigned char dec_pt = COB_MODULE_PTR->decimal_point; | ||
const unsigned char num_sep = COB_MODULE_PTR->numeric_separator; | ||
unsigned char last; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do we need that for? The called function doesn't change the data, does it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this function (indirectly) calls There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we drop the "normalize bcd function" and get the sign "directly", then we don't need to "unpunch" anything and therefore don't need to store/reset that position, do we? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, probably. I'll dive further into this. |
||
int sign; | ||
int count; | ||
int size; | ||
|
@@ -325,21 +326,35 @@ cob_move_alphanum_to_display (cob_field *f1, cob_field *f2) | |
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. directly above this code there is a skipping of leading spaces; if we always check the half-byte only, then this should be checked via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The thing is, something like |
||
/* Check for sign */ | ||
sign = 0; | ||
if (s1 != e1) { | ||
if (*s1 == '+' || *s1 == '-') { | ||
sign = (*s1++ == '+') ? 1 : -1; | ||
if (!COB_MODULE_PTR->flag_normalize_bcd) { | ||
if (s1 != e1) { | ||
if (*s1 == '+' || *s1 == '-') { | ||
sign = (*s1++ == '+') ? 1 : -1; | ||
} | ||
} | ||
} else { | ||
last = f1->data[f1->size - 1]; | ||
sign = cob_get_sign_from_alnum (f1); | ||
} | ||
|
||
/* Count the number of digits before decimal point */ | ||
count = 0; | ||
{ | ||
register unsigned char *p; | ||
for (p = s1; p < e1 && *p != dec_pt; ++p) { | ||
if (!COB_MODULE_PTR->flag_normalize_bcd) { | ||
for (p = s1; p < e1 && *p != dec_pt; ++p) { | ||
/* note: as isdigit is locale-aware (slower and not what we want), | ||
we use a range check instead */ | ||
if (*p >= '0' && *p <= '9') { | ||
++count; | ||
if (*p >= '0' && *p <= '9') { | ||
++count; | ||
} | ||
} | ||
} else { | ||
for (p = s1; p < e1 && *p != dec_pt; ++p) { | ||
const char d = COB_D2I (*p); | ||
if (d >= 0 && d <= 9) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code also counts (not skip) spaces that way - does this match the expected result? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually what happens on GCOS is very different. I had not taken into account what happens when there is a decimal point... While the current GnuCOBOL only moves digits that are before the decimal point, GCOS tries to move and normalize all digits. If it encounters a decimal point, it raises an exception because the decimal point - no matter if it is a comma (0x6B) or a dot (0x4B) - does not normalize to a valid digit... In fact, GnuCOBOL tries to be smart - skips leading spaces, interprets the sign and the decimal point, while GCOS (and others) more or less boldly convert whatever is there. But how much do we want to keep the original GnuCOBOL behavior ? If we do want to keep it (to not break existing programs), we might as well just have two different normalization functions. |
||
++count; | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -349,34 +364,70 @@ cob_move_alphanum_to_display (cob_field *f1, cob_field *f2) | |
if (count < size) { | ||
s2 += size - count; | ||
} else { | ||
while (count-- > size) { | ||
while (*s1 < '0' || *s1 > '9') { | ||
if (!COB_MODULE_PTR->flag_normalize_bcd) { | ||
while (count-- > size) { | ||
while (*s1 < '0' || *s1 > '9') { | ||
s1++; | ||
} | ||
s1++; | ||
} | ||
s1++; | ||
} else { | ||
while (count-- > size) { | ||
char d; | ||
do { | ||
d = COB_D2I (*s1++); | ||
} while (d < 0 || d > 9); | ||
} | ||
} | ||
} | ||
|
||
/* Move */ | ||
count = 0; | ||
for (; s1 < e1 && s2 < e2; ++s1) { | ||
if (*s1 >= '0' && *s1 <= '9') { | ||
*s2++ = *s1; | ||
} else if (*s1 == dec_pt) { | ||
if (count++ > 0) { | ||
if (!COB_MODULE_PTR->flag_normalize_bcd) { | ||
for (; s1 < e1 && s2 < e2; ++s1) { | ||
if (*s1 >= '0' && *s1 <= '9') { | ||
*s2++ = *s1; | ||
} else if (*s1 == dec_pt) { | ||
if (count++ > 0) { | ||
goto error; | ||
} | ||
} else if (!(isspace (*s1) || *s1 == num_sep)) { | ||
goto error; | ||
} | ||
} | ||
} else { | ||
for (; s1 < e1 && s2 < e2; ++s1) { | ||
const char d = COB_D2I (*s1); | ||
if (d >= 0 && d <= 9) { | ||
#ifndef COB_EBCDIC_MACHINE | ||
*s2++ = (d | 0x30); | ||
#else | ||
*s2++ = (d | 0xF0); | ||
#endif | ||
Comment on lines
+402
to
+406
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not using COB_I2D here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, |
||
} else if (*s1 == dec_pt) { | ||
if (count++ > 0) { | ||
goto error; | ||
} | ||
} else if (!(isspace (*s1) || *s1 == num_sep)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we will never get into the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True indeed. |
||
goto error; | ||
} | ||
} else if (!(isspace (*s1) || *s1 == num_sep)) { | ||
goto error; | ||
} | ||
} | ||
|
||
COB_PUT_SIGN (f2, sign); | ||
if (COB_MODULE_PTR->flag_normalize_bcd | ||
&& !COB_FIELD_CONSTANT (f1)) { | ||
f1->data[f1->size - 1] = last; | ||
} | ||
return; | ||
|
||
error: | ||
memset (f2->data, '0', f2->size); | ||
COB_PUT_SIGN (f2, 0); | ||
if (COB_MODULE_PTR->flag_normalize_bcd | ||
&& !COB_FIELD_CONSTANT (f1)) { | ||
f1->data[f1->size - 1] = last; | ||
} | ||
} | ||
|
||
static void | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be more reasonable to duplicate the code of the called functions here? This way we don't need an intermediate field definition, just getting
const char *p last_data = f->data + f->size - 1;
and checkp
as in the function above?