static void display_numeric (cob_field *f, FILE *fp) { int i; int digits; int scale; int size; cob_field_attr attr; cob_field temp; unsigned char data[128]; digits = COB_FIELD_DIGITS (f); scale = COB_FIELD_SCALE (f); size = digits + (COB_FIELD_HAVE_SIGN (f) ? 1 : 0); COB_ATTR_INIT (COB_TYPE_NUMERIC_DISPLAY, digits, scale, 0, NULL); temp.size = size; temp.data = data; temp.attr = &attr; if (COB_FIELD_HAVE_SIGN (f)) { attr.flags = COB_FLAG_HAVE_SIGN | COB_FLAG_SIGN_SEPARATE; if (COB_FIELD_SIGN_LEADING (f) || COB_FIELD_TYPE (f) == COB_TYPE_NUMERIC_BINARY) { attr.flags |= COB_FLAG_SIGN_LEADING; } } cob_move (f, &temp); for (i = 0; i < size; i++) { putc (data[i], fp); } }
int cob_is_numeric (cob_field *f) { unsigned char *data; size_t size; size_t i; int sign; switch (COB_FIELD_TYPE (f)) { case COB_TYPE_NUMERIC_BINARY: case COB_TYPE_NUMERIC_FLOAT: case COB_TYPE_NUMERIC_DOUBLE: return 1; case COB_TYPE_NUMERIC_PACKED: /* check digits */ for (i = 0; i < f->size - 1; ++i) { if ((f->data[i] & 0xf0) > 0x90 || (f->data[i] & 0x0f) > 0x09) { return 0; } } if ((f->data[i] & 0xf0) > 0x90) { return 0; } /* check sign */ sign = f->data[i] & 0x0f; if (sign == 0x0f) { return 1; } if (COB_FIELD_HAVE_SIGN (f)) { if (sign == 0x0c || sign == 0x0d) { return 1; } } return 0; case COB_TYPE_NUMERIC_DISPLAY: data = COB_FIELD_DATA (f); size = COB_FIELD_SIZE (f); sign = cob_get_sign (f); for (i = 0; i < size; ++i) { if (!isdigit (data[i])) { cob_put_sign (f, sign); return 0; } } cob_put_sign (f, sign); return 1; default: for (i = 0; i < f->size; ++i) { if (!isdigit (f->data[i])) { return 0; } } return 1; } }
static void pretty_display_numeric (cob_field *f, FILE *fp) { unsigned char *p; int i; int digits; int scale; int size; cob_field_attr attr; cob_field temp; unsigned char pic[64]; unsigned char data[256]; /* RXW if (COB_FIELD_TYPE(f) == COB_TYPE_NUMERIC_BINARY) { digits = bin_digits[f->size]; } else { */ digits = COB_FIELD_DIGITS (f); /* RXW } */ scale = COB_FIELD_SCALE (f); size = (digits + (COB_FIELD_HAVE_SIGN (f) ? 1 : 0) + (scale > 0 ? 1 : 0)); p = pic; temp.size = size; temp.data = data; temp.attr = &attr; COB_ATTR_INIT (COB_TYPE_NUMERIC_EDITED, digits, scale, 0, (char *)pic); memset (pic, 0, sizeof (pic)); memset (data, 0, sizeof (data)); if (COB_FIELD_HAVE_SIGN (f)) { *p++ = '+'; i = 1; memcpy (p, (unsigned char *)&i, sizeof(int)); p += sizeof(int); } if (scale > 0) { *p++ = '9'; i = digits - scale; memcpy (p, (unsigned char *)&i, sizeof(int)); p += sizeof(int); *p++ = cob_current_module->decimal_point; i = 1; memcpy (p, (unsigned char *)&i, sizeof(int)); p += sizeof(int); *p++ = '9'; i = scale; memcpy (p, (unsigned char *)&i, sizeof(int)); p += sizeof(int); } else { *p++ = '9'; i = digits; memcpy (p, (unsigned char *)&i, sizeof(int)); p += sizeof(int); } cob_move (f, &temp); for (i = 0; i < size; i++) { putc (data[i], fp); } }