diff --git a/cobc/reserved.c b/cobc/reserved.c index 1e126aaf..acca5f4a 100644 --- a/cobc/reserved.c +++ b/cobc/reserved.c @@ -3964,30 +3964,32 @@ struct list_reserved_line { /* Upper-casing for reserved words. - We use cob_lower_tab (C locale table) instead of toupper for efficiency. + We use cob_lower_tab (7bit C locale table) instead of toupper for efficiency. */ static COB_INLINE COB_A_INLINE unsigned char res_toupper (unsigned char c) { - if (cob_lower_tab[c]) { - return cob_lower_tab[c]; + const unsigned char tab_entry = cob_lower_tab[c]; + if (tab_entry) { + return tab_entry; } return c; } -/* Upper-casing for reserved words using efficient C locale table lookup. */ +/* Upper-casing for reserved words using efficient 7bit C locale table lookup. */ unsigned char cb_toupper (const unsigned char c) { return res_toupper (c); } -/* Lower-casing for reserved words using efficient C locale table lookup. */ +/* Lower-casing for reserved words using efficient 7bit C locale table lookup. */ unsigned char cb_tolower (const unsigned char c) { - if (cob_upper_tab[c]) { - return cob_upper_tab[c]; + const unsigned char tab_entry = cob_upper_tab[c]; + if (tab_entry) { + return tab_entry; } return c; } diff --git a/libcob/ChangeLog b/libcob/ChangeLog index b9f53328..f8728782 100644 --- a/libcob/ChangeLog +++ b/libcob/ChangeLog @@ -83,6 +83,25 @@ * fileio.c (cob_file_sort_options), common.h: new function to pass more options, so far only used to set flag_merge +2023-05-09 Simon Sobisch + + * cconv.c (cob_field_to_string): moved from common.c + * cconv.c (cob_init_cconv), coblocal.h, common.c: added + * cconv.c (cob_toupper, cob_tolower, cob_init_cconv), coblocal.h: + included (copy from cobc/reserved.c) + * coblocal.h (enum cob_case_modifier): new enum to select case-adjustment + * cconv.c (cob_field_to_string), coblocal.h: adjusted function signature, + allowing for optional change of case during copy and returning the size + to process or negative error values in case of "no data to process" + * cconv.c (cob_field_to_string): return error if truncating would be + necessary + * reportio.c, intrinsic.c, fileio.c->fextfh.c,fsqlxfd.c, common.c, call.c: adjusted for new + signature of cob_field_to_string + * intrinsic.c (locale_time, cob_intr_locale_date, cob_intr_locale_compare): + always use full locale string passed, error handling improved + * common.c (cob_set_locale, cob_get_environment, cob_display_env_value): + use local buffer, error handling improved + 2023-04-28 Simon Sobisch * common.c (explain_field_type): distinguish COMP-6 and unsigned packed diff --git a/libcob/call.c b/libcob/call.c index 0f39040f..d5c51b88 100644 --- a/libcob/call.c +++ b/libcob/call.c @@ -1204,7 +1204,7 @@ void * cob_call_field (const cob_field *f, const struct cob_call_struct *cs, const unsigned int errind, const int fold_case) { - char *buff, *entry, *dirent; + char *name, *entry, *dirent; void *p; /* LCOV_EXCL_START */ @@ -1213,23 +1213,23 @@ cob_call_field (const cob_field *f, const struct cob_call_struct *cs, } /* LCOV_EXCL_STOP */ - buff = cob_get_buff (f->size + 1); - cob_field_to_string (f, buff, f->size); + name = cob_get_buff (f->size + 1); + cob_field_to_string (f, name, f->size, CCM_NONE); /* check for uncommon leading space - trim it */ - if (*buff == ' ') { + if (*name == ' ') { size_t len; /* same warning as in cobc/typeck.c */ cob_runtime_warning ( - _("'%s' literal includes leading spaces which are omitted"), buff); - len = strlen (buff); - while (*buff == ' ') { - memmove (buff, buff + 1, --len); + _("'%s' literal includes leading spaces which are omitted"), name); + len = strlen (name); + while (*name == ' ') { + memmove (name, name + 1, --len); } - buff[len] = 0; + name[len] = 0; } - entry = cob_chk_call_path (buff, &dirent); + entry = cob_chk_call_path (name, &dirent); cobglobptr->cob_call_name_hash = cob_get_name_hash (entry); /* Check if contained program - which may override otherwise @@ -1367,7 +1367,7 @@ cob_cancel_field (const cob_field *f, const struct cob_call_struct *cs) return; } name = cob_get_buff (f->size + 1); - cob_field_to_string (f, name, f->size); + cob_field_to_string (f, name, f->size, CCM_NONE); entry = cob_chk_dirp (name); /* Check if contained program */ diff --git a/libcob/cconv.c b/libcob/cconv.c index 2f91fcf4..a67c3605 100644 --- a/libcob/cconv.c +++ b/libcob/cconv.c @@ -31,12 +31,76 @@ #include "sysdefines.h" #include "coblocal.h" +#ifdef HAVE_DESIGNATED_INITS +static const unsigned char lower_tab[256] = { + ['a'] = 'A', + ['b'] = 'B', + ['c'] = 'C', + ['d'] = 'D', + ['e'] = 'E', + ['f'] = 'F', + ['g'] = 'G', + ['h'] = 'H', + ['i'] = 'I', + ['j'] = 'J', + ['k'] = 'K', + ['l'] = 'L', + ['m'] = 'M', + ['n'] = 'N', + ['o'] = 'O', + ['p'] = 'P', + ['q'] = 'Q', + ['r'] = 'R', + ['s'] = 'S', + ['t'] = 'T', + ['u'] = 'U', + ['v'] = 'V', + ['w'] = 'W', + ['x'] = 'X', + ['y'] = 'Y', + ['z'] = 'Z' +}; +static const unsigned char upper_tab[256] = { + ['A'] = 'a', + ['B'] = 'b', + ['C'] = 'c', + ['D'] = 'd', + ['E'] = 'e', + ['F'] = 'f', + ['G'] = 'g', + ['H'] = 'h', + ['I'] = 'i', + ['J'] = 'j', + ['K'] = 'k', + ['L'] = 'l', + ['M'] = 'm', + ['N'] = 'n', + ['O'] = 'o', + ['P'] = 'p', + ['Q'] = 'q', + ['R'] = 'r', + ['S'] = 's', + ['T'] = 't', + ['U'] = 'u', + ['V'] = 'v', + ['W'] = 'w', + ['X'] = 'x', + ['Y'] = 'y', + ['Z'] = 'z' +}; +#else +static unsigned char lower_tab[256]; +static unsigned char upper_tab[256]; +static const unsigned char plower_tab[] = "abcdefghijklmnopqrstuvwxyz"; +static const unsigned char plower_val[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +#endif + static int cob_convert_hex_digit (char h) { - if (h >= '0' && h <= '9') return h - '0'; - else if (h >= 'A' && h <= 'F') return 10 + h - 'A'; - else if (h >= 'a' && h <= 'f') return 10 + h - 'a'; + if (h >= '0' && h <= '9') return COB_D2I (h); + h = cob_toupper (h); + if (h >= 'A' && h <= 'F') return 10 + h - 'A'; else return -1; } @@ -171,3 +235,133 @@ cob_load_collation (const char *col_name, return 0; } + +/* Upper-casing for internal words using efficient 7bit C locale table lookup. */ +unsigned char +cob_toupper (const unsigned char c) +{ + const unsigned char tab_entry = lower_tab[c]; + if (tab_entry) { + return tab_entry; + } + return c; +} + +/* Lower-casing for internal words using efficient 7bit C locale table lookup. */ +unsigned char +cob_tolower (const unsigned char c) +{ + const unsigned char tab_entry = upper_tab[c]; + if (tab_entry) { + return tab_entry; + } + return c; +} + +/* stores the field's rtrimmed string content into the given buffer + with maxlength, optionally doing upper-/lowercasing on the fly, + returns negative values on error, otherwise size of the data + processed */ +int +cob_field_to_string (const cob_field *f, void *str, const size_t maxsize, + const enum cob_case_modifier target_case) +{ + register unsigned char *end, *data, *s; + + if (f == NULL) { + snprintf (str, maxsize, "%s", ("NULL field")); + return -1; + } + + if (f->size == 0) { + return -2; + } + data = f->data; + /* check if field has data assigned (may be a BASED / LINKAGE item) */ + if (data == NULL) { + snprintf (str, maxsize, "%s", ("field with NULL address")); + return -3; + } + end = data + f->size - 1; + while (end > data) { + if (*end != ' ' && *end) { + break; + } + end--; + } + s = (unsigned char *)str; + if (*end == ' ' || *end == 0) { + *s = 0; + return 0; + } + + /* note: the specified max does not contain the low-value */ + if ((size_t)(end - data) > maxsize) { +#if 0 /* Simon: it is likely not a good idea to just ignore the data */ + end = data + maxsize; +#else + return -4; +#endif + } + switch (target_case) { + case CCM_NONE: + while (data <= end) { + *s++ = *data++; + } + break; + case CCM_LOWER: + while (data <= end) { + *s++ = cob_tolower (*data++); + } + break; + case CCM_UPPER: + while (data <= end) { + *s++ = cob_toupper (*data++); + } + break; + case CCM_LOWER_LOCALE: + while (data <= end) { + *s++ = tolower (*data++); + } + break; + case CCM_UPPER_LOCALE: + while (data <= end) { + *s++ = toupper (*data++); + } + break; + } + *s = 0; + return end + 1 - f->data; +} + + +#ifndef HAVE_DESIGNATED_INITS +/* initialize the 7bit upper/lower table */ +static void +init_upper_lower (void) +{ + const unsigned char *p, *v; + + memset (lower_tab, 0, sizeof (lower_tab)); + v = plower_val; + p = plower_tab; + for (; *p; ++p, ++v) { + lower_tab[*p] = *v; + } + memset (upper_tab, 0, sizeof (upper_tab)); + p = plower_val; + v = plower_tab; + for (; *p; ++p, ++v) { + upper_tab[*p] = *v; + } +} +#endif + + +void +cob_init_cconv (cob_global *lptr) +{ +#ifndef HAVE_DESIGNATED_INITS + init_upper_lower (); +#endif +} diff --git a/libcob/coblocal.h b/libcob/coblocal.h index 5799f229..bf43a375 100644 --- a/libcob/coblocal.h +++ b/libcob/coblocal.h @@ -395,6 +395,7 @@ struct config_tbl { COB_EXPIMP const char * cob_io_version (const int, const int); COB_EXPIMP const char * cob_io_name (const int); COB_HIDDEN void cob_init_numeric (cob_global *); +COB_HIDDEN void cob_init_cconv (cob_global *); COB_HIDDEN void cob_init_termio (cob_global *, cob_settings *); COB_HIDDEN void cob_init_fileio (cob_global *, cob_settings *); COB_HIDDEN void cob_init_reportio (cob_global *, cob_settings *); @@ -460,10 +461,20 @@ COB_HIDDEN void cob_add_exception (const int); COB_HIDDEN int cob_check_env_true (char*); COB_HIDDEN int cob_check_env_false (char*); COB_HIDDEN const char *cob_get_last_exception_name (void); -COB_EXPIMP void cob_field_to_string (const cob_field *, void *, - const size_t); COB_HIDDEN void cob_parameter_check (const char *, const int); +enum cob_case_modifier { + CCM_NONE, + CCM_LOWER, + CCM_UPPER, + CCM_LOWER_LOCALE, + CCM_UPPER_LOCALE +}; +COB_HIDDEN unsigned char cob_toupper (const unsigned char); +COB_HIDDEN unsigned char cob_tolower (const unsigned char); +COB_EXPIMP int cob_field_to_string (const cob_field *, void *, + const size_t, const enum cob_case_modifier target_case); + COB_HIDDEN cob_settings *cob_get_settings_ptr (void); COB_HIDDEN char *cob_strndup (const char *, const size_t); diff --git a/libcob/common.c b/libcob/common.c index 0010ac34..bd31a064 100644 --- a/libcob/common.c +++ b/libcob/common.c @@ -3290,50 +3290,6 @@ cob_get_pointer (const void *srcptr) return (cob_u8_ptr)tmptr; } -/* stores the field's rtrimmed string content into the given buffer - with maxlength */ -void -cob_field_to_string (const cob_field *f, void *str, const size_t maxsize) -{ - register unsigned char *end, *data, *s; - - if (f == NULL) { - snprintf (str, maxsize, "%s", ("NULL field")); - return; - } - - if (f->size == 0) { - return; - } - data = f->data; - /* check if field has data assigned (may be a BASED / LINKAGE item) */ - if (data == NULL) { - snprintf (str, maxsize, "%s", ("field with NULL address")); - return; - } - end = data + f->size - 1; - while (end > data) { - if (*end != ' ' && *end) { - break; - } - end--; - } - s = (unsigned char *)str; - if (*end == ' ' || *end == 0) { - *s = 0; - return; - } - - /* note: the specified max does not contain the low-value */ - if ((size_t)(end - data) > maxsize) { - end = data + maxsize; - } - while (data <= end) { - *s++ = *data++; - } - *s = 0; -} - static void call_exit_handlers_and_terminate (void) { @@ -5822,7 +5778,7 @@ cob_putenv (char *name) void cob_display_environment (const cob_field *f) { - size_t i; + int ret; if (cob_local_env_size < f->size) { cob_local_env_size = f->size; @@ -5831,9 +5787,13 @@ cob_display_environment (const cob_field *f) } cob_local_env = cob_malloc (cob_local_env_size + 1U); } - cob_field_to_string (f, cob_local_env, cob_local_env_size); + ret = cob_field_to_string (f, cob_local_env, cob_local_env_size, CCM_NONE); + if (ret < 0) { + return; + } if (cobsetptr->cob_env_mangle) { - const size_t len = strlen (cob_local_env); + const size_t len = ret; + size_t i; for (i = 0; i < len; ++i) { if (!isalnum ((int)cob_local_env[i])) { cob_local_env[i] = '_'; @@ -5842,24 +5802,27 @@ cob_display_environment (const cob_field *f) } } +/* DISPLAY ... UPON ENVIRONMENT VALUE */ void cob_display_env_value (const cob_field *f) { - char *env2; int ret; - if (!cob_local_env) { + if (!cob_local_env + || !cob_local_env[0]) { cob_set_exception (COB_EC_IMP_DISPLAY); return; } - if (!*cob_local_env) { - cob_set_exception (COB_EC_IMP_DISPLAY); - return; + { + char buff[COB_MEDIUM_BUFF]; + int flen = cob_field_to_string (f, buff, + COB_MEDIUM_MAX, CCM_NONE); + if (flen < 0) { + cob_set_exception (COB_EC_IMP_DISPLAY); + return; + } + ret = cob_setenv (cob_local_env, buff, 1); } - env2 = cob_malloc (f->size + 1U); - cob_field_to_string (f, env2, f->size); - ret = cob_setenv (cob_local_env, env2, 1); - cob_free (env2); if (ret != 0) { cob_set_exception (COB_EC_IMP_DISPLAY); return; @@ -5879,7 +5842,8 @@ void cob_get_environment (const cob_field *envname, cob_field *envval) { const char *p; - char *buff; + char buff[COB_MEDIUM_BUFF]; + int flen; size_t size; if (envname->size == 0 || envval->size == 0) { @@ -5887,11 +5851,15 @@ cob_get_environment (const cob_field *envname, cob_field *envval) return; } - buff = cob_malloc (envname->size + 1U); - cob_field_to_string (envname, buff, envname->size); + flen = cob_field_to_string (envname, buff, + COB_MEDIUM_MAX, CCM_NONE); + if (flen < 1) { + cob_set_exception (COB_EC_IMP_ACCEPT); + return; + } + if (cobsetptr->cob_env_mangle) { - const size_t len = strlen (buff); - for (size = 0; size < len; ++size) { + for (size = 0; size < flen; ++size) { if (!isalnum ((int)buff[size])) { buff[size] = '_'; } @@ -5903,7 +5871,6 @@ cob_get_environment (const cob_field *envname, cob_field *envval) p = " "; } cob_move_intermediate (envval, p, strlen (p)); - cob_free (buff); } void @@ -5924,13 +5891,11 @@ cob_accept_environment (cob_field *f) void cob_chain_setup (void *data, const size_t parm, const size_t size) { - size_t len; - /* only set if given on command-line, otherwise use normal program internal initialization */ if (parm <= (size_t)cob_argc - 1) { + const size_t len = strlen (cob_argv[parm]); memset (data, ' ', size); - len = strlen (cob_argv[parm]); if (len <= size) { memcpy (data, cob_argv[parm], len); } else { @@ -7481,7 +7446,8 @@ cob_sys_getopt_long_long (void *so, void *lo, void *idx, const int long_only, vo /* add 0-termination to strings */ shortoptions = cob_malloc (so_size + 1U); if (COB_MODULE_PTR->cob_procedure_params[0]) { - cob_field_to_string (COB_MODULE_PTR->cob_procedure_params[0], shortoptions, so_size); + cob_field_to_string (COB_MODULE_PTR->cob_procedure_params[0], + shortoptions, so_size, CCM_NONE); } if (COB_MODULE_PTR->cob_procedure_params[1]) { @@ -7701,43 +7667,43 @@ void cob_set_locale (cob_field *locale, const int category) { #ifdef HAVE_SETLOCALE + char buff[COB_MINI_BUFF]; char *p; - char *buff; - p = NULL; if (locale) { - if (locale->size == 0) { + int flen = cob_field_to_string (locale, buff, + COB_MINI_MAX, CCM_NONE); + if (flen < 1) { return; } - buff = cob_malloc (locale->size + 1U); - cob_field_to_string (locale, buff, locale->size); + p = buff; } else { - buff = NULL; + p = NULL; } switch (category) { case COB_LC_COLLATE: - p = setlocale (LC_COLLATE, buff); + p = setlocale (LC_COLLATE, p); break; case COB_LC_CTYPE: - p = setlocale (LC_CTYPE, buff); + p = setlocale (LC_CTYPE, p); break; #ifdef LC_MESSAGES case COB_LC_MESSAGES: - p = setlocale (LC_MESSAGES, buff); + p = setlocale (LC_MESSAGES, p); break; #endif case COB_LC_MONETARY: - p = setlocale (LC_MONETARY, buff); + p = setlocale (LC_MONETARY, p); break; case COB_LC_NUMERIC: - p = setlocale (LC_NUMERIC, buff); + p = setlocale (LC_NUMERIC, p); break; case COB_LC_TIME: - p = setlocale (LC_TIME, buff); + p = setlocale (LC_TIME, p); break; case COB_LC_ALL: - p = setlocale (LC_ALL, buff); + p = setlocale (LC_ALL, p); break; case COB_LC_USER: if (cobglobptr->cob_locale_orig) { @@ -7751,9 +7717,6 @@ cob_set_locale (cob_field *locale, const int category) } break; } - if (buff) { - cob_free (buff); - } if (!p) { cob_set_exception (COB_EC_LOCALE_MISSING); return; @@ -10420,6 +10383,7 @@ cob_init (const int argc, char **argv) /* Call inits with cobsetptr to get the addresses of all */ /* Screen-IO might be needed for error outputs */ cob_init_screenio (cobglobptr, cobsetptr); + cob_init_cconv (cobglobptr); cob_init_numeric (cobglobptr); cob_init_strings (cobglobptr); cob_init_move (cobglobptr, cobsetptr); diff --git a/libcob/fextfh.c b/libcob/fextfh.c index a7cfec3e..63a7e1d1 100644 --- a/libcob/fextfh.c +++ b/libcob/fextfh.c @@ -204,7 +204,7 @@ copy_file_to_fcd (cob_file *f, FCD3 *fcd) char assign_to[COB_FILE_BUFF]; size_t fnlen; if (f->assign) { - cob_field_to_string (f->assign, assign_to, COB_FILE_MAX); + cob_field_to_string (f->assign, assign_to, COB_FILE_MAX, CCM_NONE); } else if (f->select_name) { strncpy (assign_to, f->select_name, COB_FILE_MAX); assign_to[COB_FILE_MAX] = 0; diff --git a/libcob/fileio.c b/libcob/fileio.c index fdf7e7d8..512ee990 100644 --- a/libcob/fileio.c +++ b/libcob/fileio.c @@ -6917,7 +6917,7 @@ cob_pre_open (cob_file *f) /* Obtain the file name */ if (f->assign != NULL && f->assign->data != NULL) { - cob_field_to_string (f->assign, file_open_name, (size_t)COB_FILE_MAX); + cob_field_to_string (f->assign, file_open_name, (size_t)COB_FILE_MAX, CCM_NONE); f->flag_file_map = 1; cob_chk_file_mapping (f, NULL); @@ -6969,7 +6969,7 @@ cob_pre_open_def (cob_file *f, char *setdef, char *isdef, int checkfile) f->cur_rec_num = 0; if (f->assign != NULL && f->assign->data != NULL) { - cob_field_to_string (f->assign, file_open_name, (size_t)COB_FILE_MAX); + cob_field_to_string (f->assign, file_open_name, COB_FILE_MAX, CCM_NONE); } cob_set_file_defaults (f); @@ -8132,7 +8132,7 @@ cob_delete_file (cob_file *f, cob_field *fnstatus, const int override) } /* Obtain the file name */ - cob_field_to_string (f->assign, file_open_name, (size_t)COB_FILE_MAX); + cob_field_to_string (f->assign, file_open_name, COB_FILE_MAX, CCM_NONE); cob_chk_file_mapping (f, NULL); if (f->file_status[0] > '0') { cob_file_save_status (f, fnstatus, @@ -9707,9 +9707,9 @@ cob_get_filename_print (cob_file* file, const int show_resolved_name) { size_t offset = 0, len; /* Obtain the file name */ - cob_field_to_string (file->assign, file_open_env, (size_t)COB_FILE_MAX); + cob_field_to_string (file->assign, file_open_env, COB_FILE_MAX, CCM_NONE); if (show_resolved_name) { - strncpy (file_open_name, file_open_env, (size_t)COB_FILE_MAX); + strncpy (file_open_name, file_open_env, COB_FILE_MAX); file_open_name[COB_FILE_MAX] = 0; cob_chk_file_mapping (file, NULL); } diff --git a/libcob/fsqlxfd.c b/libcob/fsqlxfd.c index 225381f6..38f920bf 100644 --- a/libcob/fsqlxfd.c +++ b/libcob/fsqlxfd.c @@ -1062,7 +1062,7 @@ cob_load_xfd (struct db_state *db, cob_file *fl, char *alt_name, int indsize, in && fl->xfdname[0] > ' ') { fname = (char*)fl->xfdname; } else if (fl->assign) { - cob_field_to_string (fl->assign, asgname, (size_t)255); + cob_field_to_string (fl->assign, asgname, (size_t)255, CCM_NONE); if ((p = strrchr(asgname, SLASH_CHAR)) != NULL) fname = p + 1; else diff --git a/libcob/intrinsic.c b/libcob/intrinsic.c index 7cdbcf8f..40e282b4 100644 --- a/libcob/intrinsic.c +++ b/libcob/intrinsic.c @@ -1795,10 +1795,9 @@ static int locale_time (const int hours, const int minutes, const int seconds, cob_field *locale_field, char *buff) { - char *deflocale = NULL; + int deflocale = 0; struct tm tstruct; char buff2[LOCTIME_BUFSIZE] = { '\0' }; - char locale_buff[COB_SMALL_BUFF] = { '\0' }; /* Initialize tstruct to given time */ memset ((void *)&tstruct, 0, sizeof(struct tm)); @@ -1807,18 +1806,18 @@ locale_time (const int hours, const int minutes, const int seconds, tstruct.tm_sec = seconds; if (locale_field) { - if (locale_field->size >= COB_SMALL_BUFF) { + char locale_buff[COB_MINI_BUFF]; + deflocale = cob_field_to_string (locale_field, locale_buff, + COB_MINI_MAX, CCM_NONE); + if (deflocale < 1) { return 1; } - cob_field_to_string (locale_field, locale_buff, - (size_t)COB_SMALL_MAX); - deflocale = locale_buff; - (void) setlocale (LC_TIME, deflocale); + (void) setlocale (LC_TIME, locale_buff); } /* Get strftime format string for locale */ memset (buff2, 0, LOCTIME_BUFSIZE); - snprintf(buff2, LOCTIME_BUFSIZE - 1, "%s", nl_langinfo(T_FMT)); + snprintf (buff2, LOCTIME_BUFSIZE - 1, "%s", nl_langinfo (T_FMT)); /* Set locale if not done yet */ if (deflocale) { @@ -1835,10 +1834,8 @@ locale_time (const int hours, const int minutes, const int seconds, cob_field *locale_field, char *buff) { size_t len; - unsigned char *p; LCID localeid = LOCALE_USER_DEFAULT; SYSTEMTIME syst; - char locale_buff[COB_SMALL_BUFF] = { '\0' }; /* Initialize syst with given time */ memset ((void *)&syst, 0, sizeof(syst)); @@ -1848,13 +1845,13 @@ locale_time (const int hours, const int minutes, const int seconds, /* Get specified locale */ if (locale_field) { - if (locale_field->size >= COB_SMALL_BUFF) { - return 1; - } - cob_field_to_string (locale_field, locale_buff, - COB_SMALL_MAX); - - /* Null-terminate last char of the locale string */ + char locale_buff[COB_MINI_BUFF]; + int flen = cob_field_to_string (locale_field, locale_buff, + COB_MINI_MAX, CCM_NONE); +#if 0 /* re-null-terminate last char (first space/comma/...) + of the locale string + -> Simon: Why? We already have it rtrimmed */ + unsigned char *p; for (p = (unsigned char *)locale_buff; *p; ++p) { if (isalnum((int)*p) || *p == '_') { continue; @@ -1862,10 +1859,14 @@ locale_time (const int hours, const int minutes, const int seconds, break; } *p = 0; +#endif + if (flen < 1) { + return 1; + } /* Find locale ID */ for (len = 0; len < WINLOCSIZE; ++len) { - if (!strcmp(locale_buff, wintable[len].winlocalename)) { + if (!strcmp (locale_buff, wintable[len].winlocalename)) { localeid = wintable[len].winlocaleid; break; } @@ -5912,17 +5913,15 @@ cob_intr_locale_date (const int offset, const int length, int month; int year; #ifdef HAVE_LANGINFO_CODESET - unsigned char *p; - char *deflocale = NULL; + int deflocale = 0; struct tm tstruct; char buff2[128]; #else - unsigned char *p; LCID localeid = LOCALE_USER_DEFAULT; SYSTEMTIME syst; #endif char buff[128]; - char locale_buff[COB_SMALL_BUFF]; + char locale_buff[COB_MINI_BUFF]; #endif cobglobptr->cob_exception_code = 0; @@ -5931,6 +5930,7 @@ cob_intr_locale_date (const int offset, const int length, if (COB_FIELD_IS_NUMERIC (srcfield)) { indate = cob_get_int (srcfield); } else { + unsigned char *p; if (srcfield->size < 8) { goto derror; } @@ -5967,16 +5967,15 @@ cob_intr_locale_date (const int offset, const int length, tstruct.tm_mon = month; tstruct.tm_mday = days; if (locale_field) { - if (locale_field->size >= COB_SMALL_BUFF) { + deflocale = cob_field_to_string (locale_field, locale_buff, + COB_MINI_MAX, CCM_NONE); + if (deflocale < 1) { goto derror; } - cob_field_to_string (locale_field, locale_buff, - (size_t)COB_SMALL_MAX); - deflocale = locale_buff; - (void) setlocale (LC_TIME, deflocale); + (void) setlocale (LC_TIME, locale_buff); } memset (buff2, 0, sizeof(buff2)); - snprintf(buff2, sizeof(buff2) - 1, "%s", nl_langinfo(D_FMT)); + snprintf(buff2, sizeof(buff2) - 1, "%s", nl_langinfo (D_FMT)); if (deflocale) { (void) setlocale (LC_ALL, cobglobptr->cob_locale); } @@ -5987,21 +5986,25 @@ cob_intr_locale_date (const int offset, const int length, syst.wMonth = (WORD)month; syst.wDay = (WORD)days; if (locale_field) { - if (locale_field->size >= COB_SMALL_BUFF) { - goto derror; - } - cob_field_to_string (locale_field, locale_buff, - COB_SMALL_MAX); - locale_buff[COB_SMALL_MAX] = 0; /* silence warnings */ + int flen = cob_field_to_string (locale_field, locale_buff, + COB_MINI_MAX, CCM_NONE); +#if 0 /* re-null-terminate last char (first space/comma/...) + of the locale string + -> Simon: Why? We already have it rtrimmed */ + unsigned char *p; for (p = (unsigned char *)locale_buff; *p; ++p) { - if (isalnum(*p) || *p == '_') { + if (isalnum((int)*p) || *p == '_') { continue; } break; } *p = 0; +#endif + if (flen < 1) { + goto derror; + } for (len = 0; len < WINLOCSIZE; ++len) { - if (!strcmp(locale_buff, wintable[len].winlocalename)) { + if (!strcmp (locale_buff, wintable[len].winlocalename)) { localeid = wintable[len].winlocaleid; break; } @@ -6470,7 +6473,7 @@ cob_intr_locale_compare (const int params, ...) unsigned char *p; unsigned char *p1; unsigned char *p2; - char *deflocale; + int deflocale = 0; size_t size; size_t size2; int ret; @@ -6493,8 +6496,6 @@ cob_intr_locale_compare (const int params, ...) make_field_entry (&field); #ifdef HAVE_STRCOLL - deflocale = NULL; - size = f1->size; size2 = size; for (p = f1->data + size - 1U; p != f1->data; --p) { @@ -6518,14 +6519,14 @@ cob_intr_locale_compare (const int params, ...) memcpy (p2, f2->data, size2); if (locale_field) { - if (!locale_field->size) { + char locale_buff[COB_MINI_BUFF]; + deflocale = cob_field_to_string (locale_field, locale_buff, + COB_MINI_MAX, CCM_NONE); + if (deflocale < 1) { goto derror; } #ifdef HAVE_SETLOCALE - deflocale = cob_malloc (locale_field->size + 1U); - cob_field_to_string (locale_field, deflocale, - (size_t)(locale_field->size + 1U)); - (void) setlocale (LC_COLLATE, deflocale); + (void) setlocale (LC_COLLATE, locale_buff); #else goto derror; #endif @@ -6545,7 +6546,6 @@ cob_intr_locale_compare (const int params, ...) #ifdef HAVE_SETLOCALE if (deflocale) { (void) setlocale (LC_ALL, cobglobptr->cob_locale); - cob_free (deflocale); } #endif diff --git a/libcob/reportio.c b/libcob/reportio.c index 22d41f23..6ffdf92f 100644 --- a/libcob/reportio.c +++ b/libcob/reportio.c @@ -287,11 +287,9 @@ cob_add_fields (cob_field *op1, cob_field *op2, cob_field *rslt) cob_move(op1, &fld1); #ifdef COB_DEBUG_LOG - if(DEBUG_ISON("rw")) { - cob_field_to_string(op1, wrk, sizeof(wrk)-1); + if (DEBUG_ISON("rw")) { + (void)cob_field_to_string (op1, wrk, sizeof(wrk)-1, CCM_NONE); DEBUG_LOG("rw",("'%s' ",wrk)); - cob_field_to_string(op2, wrk, sizeof(wrk)-1); - DEBUG_LOG("rw",("to '%s' ",wrk)); } #endif @@ -302,13 +300,21 @@ cob_add_fields (cob_field *op1, cob_field *op2, cob_field *rslt) fld2.data = (unsigned char*)data2; memset(data2,'0',fld2.size); cob_move(op2, &fld2); + +#ifdef COB_DEBUG_LOG + if (DEBUG_ISON ("rw")) { + (void)cob_field_to_string (op2, wrk, sizeof(wrk) - 1, CCM_NONE); + DEBUG_LOG("rw",("to '%s' ",wrk)); + } +#endif + cob_add(&fld1,&fld2,0); cob_move(&fld1, rslt); /* Copy SUM back to result field */ #ifdef COB_DEBUG_LOG - if(DEBUG_ISON("rw")) { - cob_field_to_string(&fld1, wrk, sizeof(wrk)-1); + if (DEBUG_ISON("rw")) { + (void)cob_field_to_string (&fld1, wrk, sizeof(wrk)-1, CCM_NONE); DEBUG_LOG("rw",("--> '%s' ",wrk)); DEBUG_LOG("rw",("\n")); } @@ -323,48 +329,48 @@ dumpFlags(int flags, int ln, char *name) return; } - if(name == NULL) + if (name == NULL) name = (char*)""; - if(flags & COB_REPORT_HEADING) DEBUG_LOG("rw",("REPORT HEADING ")); - if(flags & COB_REPORT_FOOTING) DEBUG_LOG("rw",("REPORT FOOTING ")); - if(flags & COB_REPORT_PAGE_HEADING) DEBUG_LOG("rw",("PAGE HEADING ")); - if(flags & COB_REPORT_PAGE_FOOTING) DEBUG_LOG("rw",("PAGE FOOTING ")); - if(flags & COB_REPORT_CONTROL_HEADING) + if (flags & COB_REPORT_HEADING) DEBUG_LOG("rw",("REPORT HEADING ")); + if (flags & COB_REPORT_FOOTING) DEBUG_LOG("rw",("REPORT FOOTING ")); + if (flags & COB_REPORT_PAGE_HEADING) DEBUG_LOG("rw",("PAGE HEADING ")); + if (flags & COB_REPORT_PAGE_FOOTING) DEBUG_LOG("rw",("PAGE FOOTING ")); + if (flags & COB_REPORT_CONTROL_HEADING) DEBUG_LOG("rw",("CONTROL HEADING %s ",(flags & COB_REPORT_ALL)?"ALL":name)); - if(flags & COB_REPORT_CONTROL_HEADING_FINAL) DEBUG_LOG("rw",("CONTROL HEADING FINAL ")); - if(flags & COB_REPORT_CONTROL_FOOTING) + if (flags & COB_REPORT_CONTROL_HEADING_FINAL) DEBUG_LOG("rw",("CONTROL HEADING FINAL ")); + if (flags & COB_REPORT_CONTROL_FOOTING) DEBUG_LOG("rw",("CONTROL FOOTING %s ",(flags & COB_REPORT_ALL)?"ALL":name)); - if(flags & COB_REPORT_CONTROL_FOOTING_FINAL) DEBUG_LOG("rw",("CONTROL FOOTING FINAL ")); - if(flags & COB_REPORT_DETAIL) DEBUG_LOG("rw",("DETAIL ")); - if(flags & COB_REPORT_LINE_PLUS) {if(ln > 0) DEBUG_LOG("rw",("LINE PLUS %d ",ln));} - else if(flags & COB_REPORT_LINE) DEBUG_LOG("rw",("LINE %d ",ln)); - if(flags & COB_REPORT_LINE_NEXT_PAGE) DEBUG_LOG("rw",("LINE NEXT PAGE ")); - if(flags & COB_REPORT_NEXT_PAGE) DEBUG_LOG("rw",("NEXT PAGE ")); - if(flags & COB_REPORT_GROUP_INDICATE) DEBUG_LOG("rw",("GROUP INDICATE ")); - if(flags & COB_REPORT_COLUMN_PLUS) DEBUG_LOG("rw",("COLUMN PLUS ")); - if(flags & COB_REPORT_RESET_FINAL) DEBUG_LOG("rw",("RESET FINAL ")); - if(flags & COB_REPORT_COLUMN_LEFT) DEBUG_LOG("rw",("LEFT ")); - if(flags & COB_REPORT_COLUMN_RIGHT) DEBUG_LOG("rw",("RIGHT ")); - if(flags & COB_REPORT_COLUMN_CENTER) DEBUG_LOG("rw",("CENTER ")); - if(flags & COB_REPORT_GROUP_ITEM) DEBUG_LOG("rw",("GROUP ")); - if(flags & COB_REPORT_PRESENT) { - if(flags & COB_REPORT_NEGATE) { - if(flags & COB_REPORT_BEFORE) { + if (flags & COB_REPORT_CONTROL_FOOTING_FINAL) DEBUG_LOG("rw",("CONTROL FOOTING FINAL ")); + if (flags & COB_REPORT_DETAIL) DEBUG_LOG("rw",("DETAIL ")); + if (flags & COB_REPORT_LINE_PLUS) {if(ln > 0) DEBUG_LOG("rw",("LINE PLUS %d ",ln));} + else if (flags & COB_REPORT_LINE) DEBUG_LOG("rw",("LINE %d ",ln)); + if (flags & COB_REPORT_LINE_NEXT_PAGE) DEBUG_LOG("rw",("LINE NEXT PAGE ")); + if (flags & COB_REPORT_NEXT_PAGE) DEBUG_LOG("rw",("NEXT PAGE ")); + if (flags & COB_REPORT_GROUP_INDICATE) DEBUG_LOG("rw",("GROUP INDICATE ")); + if (flags & COB_REPORT_COLUMN_PLUS) DEBUG_LOG("rw",("COLUMN PLUS ")); + if (flags & COB_REPORT_RESET_FINAL) DEBUG_LOG("rw",("RESET FINAL ")); + if (flags & COB_REPORT_COLUMN_LEFT) DEBUG_LOG("rw",("LEFT ")); + if (flags & COB_REPORT_COLUMN_RIGHT) DEBUG_LOG("rw",("RIGHT ")); + if (flags & COB_REPORT_COLUMN_CENTER) DEBUG_LOG("rw",("CENTER ")); + if (flags & COB_REPORT_GROUP_ITEM) DEBUG_LOG("rw",("GROUP ")); + if (flags & COB_REPORT_PRESENT) { + if (flags & COB_REPORT_NEGATE) { + if (flags & COB_REPORT_BEFORE) { DEBUG_LOG("rw",("ABSENT BEFORE ")); } else { DEBUG_LOG("rw",("ABSENT AFTER ")); } } else { - if(flags & COB_REPORT_BEFORE) { + if (flags & COB_REPORT_BEFORE) { DEBUG_LOG("rw",("PRESENT BEFORE ")); } else { DEBUG_LOG("rw",("PRESENT AFTER ")); } } - if(flags & COB_REPORT_PAGE) DEBUG_LOG("rw",("PAGE ")); - if(flags & COB_REPORT_ALL) DEBUG_LOG("rw",("ALL ")); + if (flags & COB_REPORT_PAGE) DEBUG_LOG("rw",("PAGE ")); + if (flags & COB_REPORT_ALL) DEBUG_LOG("rw",("ALL ")); } - else if(flags & COB_REPORT_HAD_WHEN) DEBUG_LOG("rw",("WHEN ")); + else if (flags & COB_REPORT_HAD_WHEN) DEBUG_LOG("rw",("WHEN ")); } #endif @@ -412,25 +418,25 @@ reportDumpOneLine(const cob_report *r, cob_report_line *fl, int indent, int dump if(fl->report_flags & COB_REPORT_NEXT_GROUP_PAGE) DEBUG_LOG("rw",("NEXT GROUP PAGE ")); } if(fl->control) { - cob_field_to_string(fl->control, wrk, sizeof(wrk)-1); - if(wrk[0] >= ' ') + (void)cob_field_to_string (fl->control, wrk, sizeof(wrk) - 1, CCM_NONE); + if (wrk[0] >= ' ') DEBUG_LOG("rw",("Line Control %d is '%s' ",sequence,wrk)); } DEBUG_LOG("rw",("\n")); if(!(fl->flags & COB_REPORT_DETAIL)) dumpdata = 1; for(rf = fl->fields; rf; rf = rf->next) { DEBUG_LOG("rw",("%s %02d Field ",idnt,rf->level)); - if(rf->line) DEBUG_LOG("rw",("Line %2d ",rf->line)); - if(rf->column) DEBUG_LOG("rw",("Col %3d ",rf->column)); - if(rf->step_count) DEBUG_LOG("rw",("Step %3d ",rf->step_count)); - if(rf->next_group_line) DEBUG_LOG("rw",("NextGrp %d ",rf->next_group_line)); - if(dumpdata) { - if(!(rf->flags & COB_REPORT_GROUP_ITEM)) { - if(rf->f) { - if(rf->litval) { + if (rf->line) DEBUG_LOG("rw",("Line %2d ",rf->line)); + if (rf->column) DEBUG_LOG("rw",("Col %3d ",rf->column)); + if (rf->step_count) DEBUG_LOG("rw",("Step %3d ",rf->step_count)); + if (rf->next_group_line) DEBUG_LOG("rw",("NextGrp %d ",rf->next_group_line)); + if (dumpdata) { + if (!(rf->flags & COB_REPORT_GROUP_ITEM)) { + if (rf->f) { + if (rf->litval) { DEBUG_LOG("rw",(" \"%s\" ",rf->litval)); } else { - cob_field_to_string(rf->f, wrk, sizeof(wrk)-1); + (void)cob_field_to_string (rf->f, wrk, sizeof (wrk) - 1, CCM_NONE); if (wrk[0] >= ' ') { DEBUG_LOG("rw",(" '%s' ",wrk)); } @@ -445,7 +451,7 @@ reportDumpOneLine(const cob_report *r, cob_report_line *fl, int indent, int dump DEBUG_LOG("rw",("ABSENT")); else DEBUG_LOG("rw",("Not PRESENT")); - } else + } else if((rf->flags & COB_REPORT_GROUP_ITEM) && rf->suppress) { dumpFlags(rf->flags& ~(COB_REPORT_GROUP_ITEM|COB_REPORT_HAD_WHEN),rf->line,NULL); @@ -457,7 +463,7 @@ reportDumpOneLine(const cob_report *r, cob_report_line *fl, int indent, int dump && (!(rf->flags & COB_REPORT_PRESENT) || rf->present_now || !r->initiate_done) ) { strcpy(wrk,""); for(rc = r->controls; rc; rc = rc->next) { - if(rc->f == rf->control) { + if(rc->f == rf->control) { strcpy(wrk,rc->name); break; } @@ -467,7 +473,7 @@ reportDumpOneLine(const cob_report *r, cob_report_line *fl, int indent, int dump } } if(!(rf->flags & COB_REPORT_GROUP_ITEM) - && rf->suppress) + && rf->suppress) DEBUG_LOG("rw",("Suppress field")); DEBUG_LOG("rw",("\n")); } @@ -557,13 +563,13 @@ reportDump(const cob_report *r, const char *msg) for(c=r->controls; c; c = c->next) { DEBUG_LOG("rw",(" Control %d %s ",c->sequence,c->name)); if(c->f) { - cob_field_to_string(c->f, wrk, sizeof(wrk)-1); - if(wrk[0] >= ' ') + (void)cob_field_to_string (c->f, wrk, sizeof (wrk) - 1, CCM_NONE); + if (wrk[0] >= ' ') DEBUG_LOG("rw",("has '%s' ",wrk)); } if(c->val) { - cob_field_to_string(c->val, wrk, sizeof(wrk)-1); - if(wrk[0] >= ' ') + (void)cob_field_to_string (c->val, wrk, sizeof (wrk) - 1, CCM_NONE); + if (wrk[0] >= ' ') DEBUG_LOG("rw",("Value '%s' ",wrk)); } DEBUG_LOG("rw",("\n")); @@ -775,9 +781,9 @@ write_rec (cob_report *r, int opt) static void write_to_line (cob_report *r, int linen) { - if(r->curr_line <= linen) { + if (r->curr_line <= linen) { int adv = (linen - r->curr_line + 1); - write_rec (r, COB_WRITE_BEFORE|COB_WRITE_LINES|adv); + write_rec (r, COB_WRITE_BEFORE | COB_WRITE_LINES | adv); r->curr_line = linen + 1; r->incr_line = FALSE; if (r->curr_line > r->def_lines) { @@ -879,38 +885,40 @@ do_page_heading(cob_report *r) * Format one field into print line */ static void -print_field(cob_report_field *rf, char *rec) +print_field (cob_report_field *rf, char *rec) { char wrk[COB_SMALL_BUFF]; - int ln, k, i; - int dest_pos = (size_t)rf->column - 1; + size_t ln = 0, k, i; + size_t dest_pos = (size_t)rf->column - 1; + int ret; - cob_field_to_string(rf->f, wrk, sizeof(wrk)-1); - wrk[COB_SMALL_MAX] = 0; /* keep analyzer happy */ - ln = strlen(wrk); + ret = cob_field_to_string (rf->f, wrk, COB_SMALL_MAX, CCM_NONE); + if (ret > 0) { + ln = ret; + } if (rf->step_count > 0) memset (&rec[dest_pos], ' ', rf->step_count); - if(cobrpsetptr - && !cobrpsetptr->cob_col_just_lrc) { + if (cobrpsetptr + && !cobrpsetptr->cob_col_just_lrc) { /* Data justify is turned off, no adjustment */ } else - if((rf->flags & COB_REPORT_COLUMN_RIGHT) - && ln < rf->f->size) { + if ((rf->flags & COB_REPORT_COLUMN_RIGHT) + && ln < rf->f->size) { dest_pos += rf->f->size - ln; - } else - if((rf->flags & COB_REPORT_COLUMN_CENTER)) { - for(k=0; k < rf->f->size && wrk[0] == ' ' && ln > 0; k++) { /* remove leading spaces */ - memmove(wrk,&wrk[1],ln); + } else + if ((rf->flags & COB_REPORT_COLUMN_CENTER)) { + for (k=0; k < rf->f->size && wrk[0] == ' ' && ln > 0; k++) { /* remove leading spaces */ + memmove (wrk,&wrk[1],ln); ln--; } i = 1- (ln & 1); if (ln < rf->f->size) { dest_pos += (rf->f->size - ln - i) / 2; } - } else - if((rf->flags & COB_REPORT_COLUMN_LEFT)) { - for(k=0; k < rf->f->size && wrk[0] == ' ' && ln > 0; k++) { /* remove leading spaces */ - memmove(wrk,&wrk[1],ln); + } else + if ((rf->flags & COB_REPORT_COLUMN_LEFT)) { + for (k=0; k < rf->f->size && wrk[0] == ' ' && ln > 0; k++) { /* remove leading spaces */ + memmove (wrk,&wrk[1],ln); ln--; } } @@ -936,9 +944,9 @@ copy_line_fields (cob_report *r, cob_report_line *l, int doset) /* * Copy fields to print line area */ - for(rf = l->fields; rf; rf = rf->next) { - if((rf->flags & COB_REPORT_GROUP_ITEM)) { - if(rf->suppress) { + for (rf = l->fields; rf; rf = rf->next) { + if ((rf->flags & COB_REPORT_GROUP_ITEM)) { + if (rf->suppress) { /* group item SUPPRESSed printing, so skip to next field */ if (doset) rf->suppress = FALSE; @@ -958,19 +966,19 @@ copy_line_fields (cob_report *r, cob_report_line *l, int doset) && !rf->present_now) { continue; } - if(rf->suppress - || rf->group_indicate) { + if (rf->suppress + || rf->group_indicate) { if (rf->step_count > 0) memset (&rec[rf->column-1], ' ', rf->step_count); continue; } - if(rf->from.data) { /* Copy source field in */ - cob_move(&rf->from,rf->f); - print_field(rf, rec); - } else if(rf->sum) { /* Copy SUM field in */ - cob_move(rf->sum,rf->f); - print_field(rf, rec); - } else if(rf->litval) { /* Refresh literal value */ + if (rf->from.data) { /* Copy source field in */ + cob_move (&rf->from, rf->f); + print_field (rf, rec); + } else if (rf->sum) { /* Copy SUM field in */ + cob_move (rf->sum, rf->f); + print_field (rf, rec); + } else if (rf->litval) { /* Refresh literal value */ if (rf->f && COB_FIELD_IS_NUMERIC (rf->f)) { cob_field temp; @@ -983,7 +991,7 @@ copy_line_fields (cob_report *r, cob_report_line *l, int doset) } else { memcpy(&rec[rf->column-1], rf->litval, rf->litlen); } - } else if(rf->f) { + } else if (rf->f) { print_field(rf, rec); } if (doset @@ -999,7 +1007,7 @@ copy_fields (cob_report *r, cob_report_line *l, int doset) if (l == NULL || l->suppress) return; - + if((l->flags & COB_REPORT_LINE) || l->child == NULL) { copy_line_fields (r,l,doset); @@ -1022,24 +1030,29 @@ report_line (cob_report *r, cob_report_line *l) { cob_report_field *rf; cob_file *f = r->report_file; - char *rec,wrk[COB_SMALL_BUFF]; + char *rec; +#if 0 /* unused */ + char wrk[COB_SMALL_BUFF]; +#endif int bChkLinePlus = FALSE; rec = (char *)f->record->data; - if(rec) { - memset(rec,' ',f->record_max); - memset(wrk,0,sizeof(wrk)); + if (rec) { + memset (rec, ' ', f->record_max); +#if 0 /* unused */ + memset (wrk, 0, COB_SMALL_BUFF); +#endif if(r->curr_line > r->def_last_detail && !r->in_report_footing && !r->in_page_footing) { /* Page overflow */ r->incr_page = TRUE; - do_page_footing(r); - do_page_heading(r); + do_page_footing (r); + do_page_heading (r); } while( !(l->flags & COB_REPORT_LINE_PLUS) && !(l->flags & COB_REPORT_LINE) && l->child - && ((l->flags & COB_REPORT_CONTROL_FOOTING_FINAL) + && ((l->flags & COB_REPORT_CONTROL_FOOTING_FINAL) || (l->flags & COB_REPORT_CONTROL_HEADING_FINAL) )) { l = l->child; } @@ -1151,18 +1164,18 @@ report_line (cob_report *r, cob_report_line *l) return; } #ifdef COB_DEBUG_LOG - if(DEBUG_ISON("rw")) { - reportDumpOneLine(r,l,0,1); + if (DEBUG_ISON ("rw")) { + reportDumpOneLine (r, l, 0, 1); } #endif - for(rf = l->fields; rf; rf = rf->next) { + for (rf = l->fields; rf; rf = rf->next) { rf->present_now = (rf->flags & COB_REPORT_NEGATE)?1:0; } - if(rec) { + if (rec) { write_to_line (r, r->curr_line); } - set_next_info(r,l); + set_next_info (r,l); } /* @@ -1181,7 +1194,7 @@ report_line_and(cob_report *r, cob_report_line *l, int type) report_line_type(r,l->child,COB_REPORT_LINE); } return; - } + } l = l->child; } report_line_type(r,l,type); @@ -1789,12 +1802,12 @@ static int maxctl,ln,num,gengrp,last_use,ctlidx; for(rc = r->controls; rc; rc = rc->next) { rc->data_change = (cob_cmp(rc->f,rc->val) != 0); if(rc->data_change) { /* Data change, implies control break at lower levels */ -#if defined(COB_DEBUG_LOG) +#if defined(COB_DEBUG_LOG) DEBUG_LOG("rw",(" Control Break %s order %d changed from ", rc->name,rc->sequence)); - cob_field_to_string(rc->val, wrk, sizeof(wrk)-1); + (void)cob_field_to_string (rc->val, wrk, sizeof(wrk)-1, CCM_NONE); DEBUG_LOG("rw",("'%s' to ",wrk)); - cob_field_to_string(rc->f, wrk, sizeof(wrk)-1); + (void)cob_field_to_string (rc->f, wrk, sizeof(wrk)-1, CCM_NONE); DEBUG_LOG("rw",("'%s'\n",wrk)); #endif cob_move(rc->f, rc->sf); /* Save new CONTROL value */ @@ -1808,12 +1821,12 @@ static int maxctl,ln,num,gengrp,last_use,ctlidx; if(rc->sequence < maxctl && !rc->data_change) { rc->data_change = TRUE; -#if defined(COB_DEBUG_LOG) +#if defined(COB_DEBUG_LOG) DEBUG_LOG("rw",(" Control Break %s order %d also ", rc->name,rc->sequence)); - cob_field_to_string(rc->val, wrk, sizeof(wrk)-1); + cob_field_to_string(rc->val, wrk, sizeof(wrk)-1, CCM_NONE); DEBUG_LOG("rw",("'%s' to ",wrk)); - cob_field_to_string(rc->f, wrk, sizeof(wrk)-1); + cob_field_to_string(rc->f, wrk, sizeof(wrk)-1, CCM_NONE); DEBUG_LOG("rw",("'%s'\n",wrk)); #endif cob_move(rc->f, rc->sf); /* Save CONTROL value */