diff --git a/cobc/tree.c b/cobc/tree.c index 4882cb1b6..64c1c30b6 100644 --- a/cobc/tree.c +++ b/cobc/tree.c @@ -2904,13 +2904,12 @@ is_simple_insertion_char (const char c) /* Returns the first and last characters of a floating insertion string. - Returns a zero if no errors encountered or a 1 if an error is encountered. + Returns a zero if no errors encountered or a 1 if an error is encountered. - A floating insertion string is made up of two or more +'s, -'s or currency - symbols, optionally with simple insertion characters between them. - - Note that the non punctuation characters are '.', ',', '/', V, B , 0 - + A floating insertion string is made up of two or more +'s, -'s or currency + symbols, optionally with simple insertion characters between them. + + Note that the non punctuation characters are '.', ',', '/', V, B , 0 */ static int find_floating_insertion_str (const cob_pic_symbol *str, @@ -2919,7 +2918,7 @@ find_floating_insertion_str (const cob_pic_symbol *str, const unsigned char float_char) { - int non_punctuation_found = 0; + int non_punctuation_found = 0; unsigned char non_punctuation_char; for (; str->symbol != '\0'; ++str) { @@ -2935,13 +2934,13 @@ find_floating_insertion_str (const cob_pic_symbol *str, } } *last = str; - } else if ( *first - && str->symbol != '.' - && str->symbol != ',' - && str->symbol != 'V' - && str->symbol != 'B' - && str->symbol != '/' - && str->symbol != '0') { + } else if (*first + && str->symbol != '.' + && str->symbol != ',' + && str->symbol != 'V' + && str->symbol != 'B' + && str->symbol != '/' + && str->symbol != '0') { non_punctuation_found = 1; non_punctuation_char = str->symbol; } @@ -3622,7 +3621,7 @@ cb_build_picture (const char *str) case 'N': if (!(category & PIC_NATIONAL)) { - category |= PIC_NATIONAL; + category |= PIC_NATIONAL; CB_UNFINISHED ("USAGE NATIONAL"); } x_digits += n * 2; @@ -3759,10 +3758,11 @@ cb_build_picture (const char *str) case '+': case '-': - if (c == '+') + if (c == '+') { pos_count += n; - else + } else { neg_count += n; + } category |= PIC_NUMERIC_EDITED; digits += n; if (s_edit_count == 0) { @@ -3871,7 +3871,7 @@ cb_build_picture (const char *str) } if (digits == 0 && x_digits == 0) { cb_error (_("PICTURE string must contain at least one of the set A, N, U, X, Z, 1, 9 and *; " - "or at least two of the set +, - and the currency symbol")); + "or at least two of the set +, - and the currency symbol")); error_detected = 1; } @@ -3880,8 +3880,8 @@ cb_build_picture (const char *str) if (pos_count > 1) { float_char = '+'; float_count++; - } - + } + if (neg_count > 1) { float_char = '-'; float_count++; @@ -3890,10 +3890,11 @@ cb_build_picture (const char *str) if (curency_count > 1) { float_char = currency_symbol; float_count++; - } + } - if (float_count > 1) + if (float_count > 1) { float_char = 0xFF; + } if (!valid_char_order (pic_buff, s_char_seen, float_char)) { error_detected = 1; diff --git a/libcob/fileio.c b/libcob/fileio.c index 36d640f5d..0da80ae69 100644 --- a/libcob/fileio.c +++ b/libcob/fileio.c @@ -1,21 +1,21 @@ /* - Copyright (C) 2002-2012, 2014-2025 Free Software Foundation, Inc. - Written by Keisuke Nishida, Roger While, Simon Sobisch, Ron Norman + Copyright (C) 2002-2012, 2014-2025 Free Software Foundation, Inc. + Written by Keisuke Nishida, Roger While, Simon Sobisch, Ron Norman - This file is part of GnuCOBOL. + This file is part of GnuCOBOL. - The GnuCOBOL runtime library is free software: you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public License - as published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. + The GnuCOBOL runtime library is free software: you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public License + as published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. - GnuCOBOL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. + GnuCOBOL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License - along with GnuCOBOL. If not, see . + You should have received a copy of the GNU Lesser General Public License + along with GnuCOBOL. If not, see . */ @@ -251,7 +251,7 @@ indexed_keylen (const struct keydesc *key) } /* Save key for given index into 'savekey' - Return total length of the key */ + Return total length of the key */ static int indexed_savekey (struct indexfile *fh, unsigned char *data, int idx) { @@ -270,7 +270,7 @@ indexed_savekey (struct indexfile *fh, unsigned char *data, int idx) } /* Copy key for given index from 'savekey' back to recwrk - Return total length of the key */ + Return total length of the key */ static int indexed_restorekey (struct indexfile *fh, unsigned char *data, int idx) { @@ -289,7 +289,7 @@ indexed_restorekey (struct indexfile *fh, unsigned char *data, int idx) } /* Compare key for given index 'savekey' to recwrk - Return compare status */ + Return compare status */ static int indexed_cmpkey (struct indexfile *fh, unsigned char *data, int idx, int partlen) { @@ -313,7 +313,7 @@ indexed_cmpkey (struct indexfile *fh, unsigned char *data, int idx, int partlen) } /* Build 'keydesc' from 'cob_file_key' - Return total length of the key */ + Return total length of the key */ static int indexed_keydesc (cob_file *f, struct keydesc *kd, cob_file_key *key) { @@ -377,7 +377,7 @@ indexed_keydesc (cob_file *f, struct keydesc *kd, cob_file_key *key) } /* Compare 'keydesc' to 'keydesc' - Return 0 if equal, else 1 */ + Return 0 if equal, else 1 */ static int indexed_keycmp (struct keydesc *k1, struct keydesc *k2) { @@ -777,7 +777,7 @@ struct indexed_file { }; /* collation aware key comparision, - currently only used for BDB, likely used in general later */ + currently only used for BDB, likely used in general later */ static int indexed_key_compare (const unsigned char *k1, const unsigned char *k2, size_t sz, const unsigned char *col) @@ -808,7 +808,7 @@ bdb_keylen (cob_file *f, int idx) } /* Save key for given index from 'record' into 'keyarea', - returns total length of the key */ + returns total length of the key */ static int bdb_savekey (cob_file *f, unsigned char *keyarea, unsigned char *record, int idx) { @@ -848,7 +848,7 @@ bdb_setkey (cob_file *f, int idx) } /* Compare key for given index 'keyarea' to 'record'. - returns compare status */ + returns compare status */ static int bdb_cmpkey (cob_file *f, unsigned char *keyarea, unsigned char *record, int idx, int partlen) { @@ -884,7 +884,7 @@ bdb_cmpkey (cob_file *f, unsigned char *keyarea, unsigned char *record, int idx, } /* Is given key data all SUPPRESS char, - returns 1 if key has all SUPPRESS char */ + returns 1 if key has all SUPPRESS char */ static int bdb_suppresskey (cob_file *f, int idx) { @@ -964,7 +964,7 @@ bdb_close_index (cob_file *f, int index) static int bdb_bt_compare (DB *db, const DBT *k1, const DBT *k2 #if DB_VERSION_MAJOR >= 6 /* ABI break in DB_VERSION_FAMILY 12 ... */ - , size_t *locp + , size_t *locp #endif ) { @@ -1035,10 +1035,10 @@ dummy_start (cob_file *f, const int cond, cob_field *key) } /* Check for DD_xx, dd_xx, xx environment variables for a filename - or a part specified with 'src'; - returns either the value or NULL if not found in the environment - Note: MF only checks for xx if the variable started with a $, - ACUCOBOL only checks for xx in general ... */ + or a part specified with 'src'; + returns either the value or NULL if not found in the environment + Note: MF only checks for xx if the variable started with a $, + ACUCOBOL only checks for xx in general ... */ static char * cob_chk_file_env (const char *src) { @@ -1151,7 +1151,7 @@ looks_absolute (char *src) } /* checks for special ACUCOBOL-case: file that start with hyphen [note: -P not supported] - no translation at all, name starts after first non-space */ + no translation at all, name starts after first non-space */ static int has_acu_hyphen (char *src) { @@ -1492,7 +1492,7 @@ save_status (cob_file *f, cob_field *fnstatus, const int status) cobglobptr->cob_exception_code = 0; } else { #if 0 /* correct thing to do, but then also needs to have codegen adjusted - --> module-incompatibility --> 4.x */ + --> module-incompatibility --> 4.x */ cob_set_exception (eop_status); #else cob_set_exception (COB_EC_I_O_EOP); @@ -1515,7 +1515,7 @@ save_status (cob_file *f, cob_field *fnstatus, const int status) /* Regular file */ /* Translate errno status to COBOL status, - Note: always sets either an error or the given default value */ + Note: always sets either an error or the given default value */ static int errno_cob_sts (const int default_status) { @@ -2270,7 +2270,7 @@ open_next (cob_file *f) int fmode = O_BINARY; /* without this ftell does not work on some systems */ #ifdef _WIN32 /* win32 seems to resolve the file descriptor from the file handler - on fclose - and then aborts because it was closed directly before */ + on fclose - and then aborts because it was closed directly before */ if (f->file) { fclose (f->file); } else { @@ -2328,8 +2328,8 @@ open_next (cob_file *f) /* Read record size into f->record->size - returns -1 if no data was read, zero for success and - and an io status otherwise */ + returns -1 if no data was read, zero for success and + and an io status otherwise */ static int set_sequential_variable_length (cob_file *f) { int bytesread; @@ -2694,7 +2694,7 @@ lineseq_read (cob_file *f, const int read_opts) } } #if 0 /* From trunk - CHECKME: When should this be done? - Only for LS_VALIDATE / LS_NULLS? */ + Only for LS_VALIDATE / LS_NULLS? */ /* Skip NEW PAGE on reading */ if (n == '\f') { continue; @@ -3816,7 +3816,7 @@ get_dupno (cob_file *f, const cob_u32_t i) } /* read file with all alternate keys that don't allow duplicates - to check if records exist already, returns 1 if true */ + to check if records exist already, returns 1 if true */ static int check_alt_keys (cob_file *f, const int rewrite) { @@ -4680,7 +4680,7 @@ indexed_open (cob_file *f, char *filename, maxsize = p->primekeylen = bdb_keylen(f, 0); for (i = 1; i < f->nkeys; ++i) { j = bdb_keylen(f, i); - if( j > maxsize) + if (j > maxsize) maxsize = j; } p->maxkeylen = maxsize; @@ -4999,22 +4999,23 @@ indexed_start (cob_file *f, const int cond, cob_field *key) } k = cob_findkey_attr (f, key, &fullkeylen, &partlen); - /************************************************************/ - /* */ - /* here we are storing the partial key length in the */ - /* indexfile structure so that the indexed read next */ - /* functions can position the file based on the partial */ - /* key length. */ - /* */ - /* note the indexed_cmpkey function expects a partial key */ - /* length of zero if it is to use the full key length. */ - /* */ - /************************************************************/ - - if (fullkeylen == partlen) + /************************************************************/ + /* */ + /* here we are storing the partial key length in the */ + /* indexfile structure so that the indexed read next */ + /* functions can position the file based on the partial */ + /* key length. */ + /* */ + /* note the indexed_cmpkey function expects a partial key */ + /* length of zero if it is to use the full key length. */ + /* */ + /************************************************************/ + + if (fullkeylen == partlen) { fh->partial_key_length = 0; - else + } else { fh->partial_key_length = partlen; + } if (k < 0) { return COB_STATUS_23_KEY_NOT_EXISTS; @@ -5309,7 +5310,7 @@ indexed_read_next (cob_file *f, const int read_opts) case COB_GE: domoveback = 0; while (ISERRNO == 0 - && indexed_cmpkey(fh, f->record->data, f->curkey, fh->partial_key_length) == 0) { + && indexed_cmpkey(fh, f->record->data, f->curkey, fh->partial_key_length) == 0) { isread (fh->isfd, (void *)f->record->data, ISPREV); domoveback = 1; } @@ -5320,7 +5321,7 @@ indexed_read_next (cob_file *f, const int read_opts) case COB_LE: domoveback = 0; while (ISERRNO == 0 - && indexed_cmpkey(fh, f->record->data, f->curkey, fh->partial_key_length) == 0) { + && indexed_cmpkey(fh, f->record->data, f->curkey, fh->partial_key_length) == 0) { isread (fh->isfd, (void *)f->record->data, ISNEXT); domoveback = 1; } @@ -5333,13 +5334,13 @@ indexed_read_next (cob_file *f, const int read_opts) isread (fh->isfd, (void *)f->record->data, ISPREV); #endif while (ISERRNO == 0 - && indexed_cmpkey(fh, f->record->data, f->curkey, fh->partial_key_length) >= 0) { + && indexed_cmpkey(fh, f->record->data, f->curkey, fh->partial_key_length) >= 0) { isread (fh->isfd, (void *)f->record->data, ISPREV); } break; case COB_GT: while (ISERRNO == 0 - && indexed_cmpkey(fh, f->record->data, f->curkey, fh->partial_key_length) <= 0) { + && indexed_cmpkey(fh, f->record->data, f->curkey, fh->partial_key_length) <= 0) { isread (fh->isfd, (void *)f->record->data, ISNEXT); } break; @@ -5389,12 +5390,12 @@ indexed_read_next (cob_file *f, const int read_opts) } else { switch (fh->startcond) { case COB_LE: - if(indexed_cmpkey(fh, f->record->data, f->curkey, fh->partial_key_length) > 0) + if (indexed_cmpkey(fh, f->record->data, f->curkey, fh->partial_key_length) > 0) domoveback = 1; else domoveback = 0; while (ISERRNO == 0 - && indexed_cmpkey(fh, f->record->data, f->curkey, fh->partial_key_length) == 0) { + && indexed_cmpkey(fh, f->record->data, f->curkey, fh->partial_key_length) == 0) { isread (fh->isfd, (void *)f->record->data, ISNEXT); domoveback = 1; } @@ -5404,19 +5405,19 @@ indexed_read_next (cob_file *f, const int read_opts) break; case COB_LT: while (ISERRNO == 0 - && indexed_cmpkey(fh, f->record->data, f->curkey, fh->partial_key_length) >= 0) { + && indexed_cmpkey(fh, f->record->data, f->curkey, fh->partial_key_length) >= 0) { isread (fh->isfd, (void *)f->record->data, ISPREV); } break; case COB_GT: while (ISERRNO == 0 - && indexed_cmpkey(fh, f->record->data, f->curkey, fh->partial_key_length) <= 0) { + && indexed_cmpkey(fh, f->record->data, f->curkey, fh->partial_key_length) <= 0) { isread (fh->isfd, (void *)f->record->data, ISNEXT); } break; case COB_GE: while (ISERRNO == 0 - && indexed_cmpkey(fh, f->record->data, f->curkey, fh->partial_key_length) < 0) { + && indexed_cmpkey(fh, f->record->data, f->curkey, fh->partial_key_length) < 0) { isread (fh->isfd, (void *)f->record->data, ISNEXT); } break; @@ -7117,7 +7118,7 @@ cob_delete_file (cob_file *f, cob_field *fnstatus) } /* Return index number for given key and set length attributes, - storing resulting key field in file's last_key */ + storing resulting key field in file's last_key */ int cob_findkey (cob_file *f, cob_field *kf, int *fullkeylen, int *partlen) { @@ -7431,7 +7432,7 @@ cob_sys_close_file (unsigned char *file_handle) } /* entry point and processing for library routine CBL_FLUSH_FILE - (flush bytestream file handle, got from CBL_OPEN_FILE) */ + (flush bytestream file handle, got from CBL_OPEN_FILE) */ int cob_sys_flush_file (unsigned char *file_handle) { @@ -7467,7 +7468,7 @@ cob_sys_delete_file (unsigned char *fname) } /* entry point and processing for library routine CBL_COPY_FILE, - does a direct read + write of the complete file */ + does a direct read + write of the complete file */ int cob_sys_copy_file (unsigned char *fname1, unsigned char *fname2) { @@ -8477,7 +8478,7 @@ cob_file_sort_using (cob_file *sort_file, cob_file *data_file) } /* SORT/MERGE: add all records from GIVING file 'data_file' to 'sort_file', - with optional external file handler 'callfh' */ + with optional external file handler 'callfh' */ void cob_file_sort_using_extfh (cob_file *sort_file, cob_file *data_file, int (*callfh)(unsigned char *opcode, FCD3 *fcd)) @@ -8527,7 +8528,7 @@ cob_file_sort_using_extfh (cob_file *sort_file, cob_file *data_file, /* SORT/MERGE: WRITE all records from 'sort_file' to all USING files 'fbase', - with using their optional external file handlers 'callfh' */ + with using their optional external file handlers 'callfh' */ static void cob_file_sort_giving_internal (cob_file *sort_file, const size_t giving_cnt, cob_file **fbase, int (**callfh)(unsigned char *opcode, FCD3 *fcd)) @@ -8676,7 +8677,7 @@ cob_file_sort_giving (cob_file *sort_file, const size_t varcnt, ...) } /* SORT: WRITE all records from 'sort_file' to all passed USING files, - with using their optional external file handlers */ + with using their optional external file handlers */ void cob_file_sort_giving_extfh (cob_file *sort_file, const size_t varcnt, ...) { @@ -8698,7 +8699,7 @@ cob_file_sort_giving_extfh (cob_file *sort_file, const size_t varcnt, ...) } /* SORT: close of internal sort file 'f' and deallocation - of temporary storage */ + of temporary storage */ void cob_file_sort_close (cob_file *f) { @@ -8813,8 +8814,8 @@ cob_get_filename_print (cob_file* file, const int show_resolved_name) } /* Initialization/Termination - cobsetpr-values with type ENV_PATH or ENV_STR - like bdb_home and cob_file_path are taken care in cob_exit_common()! + cobsetpr-values with type ENV_PATH or ENV_STR + like bdb_home and cob_file_path are taken care in cob_exit_common()! */ const char *implicit_close_of_msgid = NULL; @@ -9020,7 +9021,7 @@ update_file_to_fcd (cob_file *f, FCD3 *fcd, unsigned char *fnstatus) if (f->open_mode == COB_OPEN_CLOSED || f->open_mode == COB_OPEN_LOCKED) fcd->openMode = OPEN_NOT_OPEN; - else if( f->open_mode == COB_OPEN_INPUT) + else if (f->open_mode == COB_OPEN_INPUT) fcd->openMode = OPEN_INPUT; else if (f->open_mode == COB_OPEN_OUTPUT) fcd->openMode = OPEN_OUTPUT; @@ -9046,18 +9047,18 @@ update_file_to_fcd (cob_file *f, FCD3 *fcd, unsigned char *fnstatus) fcd->fileOrg = ORG_LINE_SEQ; STCOMPX2(0, fcd->refKey); #if 0 /* Note: file specific features are 4.x only ... */ - if((f->file_features & COB_FILE_LS_CRLF)) + if ((f->file_features & COB_FILE_LS_CRLF)) fcd->fstatusType |= MF_FST_CRdelim; - if((f->file_features & COB_FILE_LS_NULLS)) + if ((f->file_features & COB_FILE_LS_NULLS)) fcd->fstatusType |= MF_FST_InsertNulls; - if((f->file_features & COB_FILE_LS_FIXED)) + if ((f->file_features & COB_FILE_LS_FIXED)) fcd->fstatusType |= MF_FST_NoStripSpaces; #else /* ... so we use the current global setting as info only */ - if((cobsetptr->cob_ls_uses_cr)) + if ((cobsetptr->cob_ls_uses_cr)) fcd->fstatusType |= MF_FST_CRdelim; - if((cobsetptr->cob_ls_nulls)) + if ((cobsetptr->cob_ls_nulls)) fcd->fstatusType |= MF_FST_InsertNulls; - if((cobsetptr->cob_ls_fixed)) + if ((cobsetptr->cob_ls_fixed)) fcd->fstatusType |= MF_FST_NoStripSpaces; #endif } else if (f->organization == COB_ORG_RELATIVE) { @@ -9130,10 +9131,10 @@ copy_file_to_fcd (cob_file *f, FCD3 *fcd) if ((f->lock_mode & COB_LOCK_EXCLUSIVE) || (f->lock_mode & COB_LOCK_OPEN_EXCLUSIVE)) fcd->lockMode = FCD_LOCK_EXCL_LOCK; - else if(f->lock_mode == COB_LOCK_MANUAL) - fcd->lockMode = FCD_LOCK_MANU_LOCK; - else if(f->lock_mode == COB_LOCK_AUTOMATIC) - fcd->lockMode = FCD_LOCK_AUTO_LOCK; + else if (f->lock_mode == COB_LOCK_MANUAL) + fcd->lockMode = FCD_LOCK_MANU_LOCK; + else if (f->lock_mode == COB_LOCK_AUTOMATIC) + fcd->lockMode = FCD_LOCK_AUTO_LOCK; fcd->recPtr = f->record->data; if (f->organization == COB_ORG_INDEXED) { unsigned int kdblen,idx,keypos,keycomp,k,nkeys; @@ -9182,18 +9183,18 @@ copy_file_to_fcd (cob_file *f, FCD3 *fcd) } keypos = (sizeof (KDB_KEY) * nkeys) + sizeof (KDB) - sizeof (kdb->key); STCOMPX2(nkeys, kdb->nkeys); - for(idx=0; idx < nkeys; idx++) { + for (idx=0; idx < nkeys; idx++) { key = (EXTKEY*)((char*)((char*)kdb) + keypos); STCOMPX2(keypos, kdb->key[idx].offset); kdb->key[idx].keyFlags = 0; kdb->key[idx].sparse = 0; - if(f->keys[idx].tf_duplicates) + if (f->keys[idx].tf_duplicates) kdb->key[idx].keyFlags |= KEY_DUPS; - if(f->keys[idx].tf_suppress) { + if (f->keys[idx].tf_suppress) { kdb->key[idx].keyFlags |= KEY_SPARSE; kdb->key[idx].sparse = (unsigned char)f->keys[idx].char_suppress; } - if(f->keys[idx].count_components <= 1) { + if (f->keys[idx].count_components <= 1) { if (f->keys[idx].field == NULL) continue; STCOMPX2(1,kdb->key[idx].count); @@ -9202,7 +9203,7 @@ copy_file_to_fcd (cob_file *f, FCD3 *fcd) keypos = keypos + sizeof (EXTKEY); } else { STCOMPX2(f->keys[idx].count_components, kdb->key[idx].count); - for(k=0; k < (int)f->keys[idx].count_components; k++) { + for (k=0; k < (int)f->keys[idx].count_components; k++) { key = (EXTKEY*)((char*)((char*)kdb) + keypos); key->desc = 0; key->type = 0; @@ -9243,15 +9244,15 @@ update_fcd_to_file (FCD3* fcd, cob_file *f, cob_field *fnstatus, int wasOpen) } } if (wasOpen > 0) { - if((fcd->openMode & OPEN_NOT_OPEN)) + if ((fcd->openMode & OPEN_NOT_OPEN)) f->open_mode = 0; - else if((fcd->openMode & 0x7f) == OPEN_INPUT) + else if ((fcd->openMode & 0x7f) == OPEN_INPUT) f->open_mode = COB_OPEN_INPUT; - else if((fcd->openMode & 0x7f) == OPEN_OUTPUT) + else if ((fcd->openMode & 0x7f) == OPEN_OUTPUT) f->open_mode = COB_OPEN_OUTPUT; - else if((fcd->openMode & 0x7f) == OPEN_EXTEND) + else if ((fcd->openMode & 0x7f) == OPEN_EXTEND) f->open_mode = COB_OPEN_EXTEND; - else if((fcd->openMode & 0x7f) == OPEN_IO) + else if ((fcd->openMode & 0x7f) == OPEN_IO) f->open_mode = COB_OPEN_I_O; } f->record_min = LDCOMPX4(fcd->minRecLen); @@ -9277,11 +9278,11 @@ update_fcd_to_file (FCD3* fcd, cob_file *f, cob_field *fnstatus, int wasOpen) } } - if((fcd->lockMode & FCD_LOCK_EXCL_LOCK)) + if ((fcd->lockMode & FCD_LOCK_EXCL_LOCK)) f->lock_mode = COB_LOCK_EXCLUSIVE; - else if((fcd->lockMode & FCD_LOCK_MANU_LOCK)) + else if ((fcd->lockMode & FCD_LOCK_MANU_LOCK)) f->lock_mode = COB_LOCK_MANUAL; - else if((fcd->lockMode & FCD_LOCK_AUTO_LOCK)) + else if ((fcd->lockMode & FCD_LOCK_AUTO_LOCK)) f->lock_mode = COB_LOCK_AUTOMATIC; } @@ -9369,20 +9370,20 @@ copy_fcd_to_file (FCD3* fcd, cob_file *f, struct fcd_file *fcd_list_entry) { int k, min, max; - if((fcd->accessFlags & 0x7F) == ACCESS_SEQ) + if ((fcd->accessFlags & 0x7F) == ACCESS_SEQ) f->access_mode = COB_ACCESS_SEQUENTIAL; - else if((fcd->accessFlags & 0x7F) == ACCESS_RANDOM) + else if ((fcd->accessFlags & 0x7F) == ACCESS_RANDOM) f->access_mode = COB_ACCESS_RANDOM; - else if((fcd->accessFlags & 0x7F) == ACCESS_DYNAMIC) + else if ((fcd->accessFlags & 0x7F) == ACCESS_DYNAMIC) f->access_mode = COB_ACCESS_DYNAMIC; - if((fcd->otherFlags & OTH_EXTERNAL)) + if ((fcd->otherFlags & OTH_EXTERNAL)) f->flag_select_features |= COB_SELECT_EXTERNAL; f->flag_optional = 0; - if((fcd->otherFlags & OTH_OPTIONAL)) + if ((fcd->otherFlags & OTH_OPTIONAL)) f->flag_optional = 1; - if((fcd->otherFlags & OTH_NOT_OPTIONAL)) + if ((fcd->otherFlags & OTH_NOT_OPTIONAL)) f->flag_optional = 0; - if((fcd->otherFlags & OTH_LINE_ADVANCE)) + if ((fcd->otherFlags & OTH_LINE_ADVANCE)) f->flag_line_adv = 1; else f->flag_line_adv = 0; @@ -9395,11 +9396,11 @@ copy_fcd_to_file (FCD3* fcd, cob_file *f, struct fcd_file *fcd_list_entry) } #endif - if(fcd->fileOrg == ORG_INDEXED) { + if (fcd->fileOrg == ORG_INDEXED) { f->organization = COB_ORG_INDEXED; - } else if(fcd->fileOrg == ORG_SEQ) { + } else if (fcd->fileOrg == ORG_SEQ) { f->organization = COB_ORG_SEQUENTIAL; - } else if(fcd->fileOrg == ORG_LINE_SEQ) { + } else if (fcd->fileOrg == ORG_LINE_SEQ) { f->organization = COB_ORG_LINE_SEQUENTIAL; #if 0 /* note file_features are a 4.x-only feature */ #ifdef _WIN32 @@ -9416,12 +9417,12 @@ copy_fcd_to_file (FCD3* fcd, cob_file *f, struct fcd_file *fcd_list_entry) f->file_features |= COB_FILE_LS_LF; } #endif - if((fcd->fstatusType & MF_FST_InsertNulls)) + if ((fcd->fstatusType & MF_FST_InsertNulls)) f->file_features |= COB_FILE_LS_NULLS; - if((fcd->fstatusType & MF_FST_NoStripSpaces)) + if ((fcd->fstatusType & MF_FST_NoStripSpaces)) f->file_features |= COB_FILE_LS_FIXED; #endif - } else if(fcd->fileOrg == ORG_RELATIVE) { + } else if (fcd->fileOrg == ORG_RELATIVE) { f->organization = COB_ORG_RELATIVE; if (f->keys == NULL) { f->keys = cob_cache_malloc(sizeof (cob_file_key)); @@ -9625,7 +9626,7 @@ free_fcd2 (FCD2 *fcd2) } /* Convert FCD2 into FCD3 format, note: explicit no checks here - as those have to be in EXTFH3 / fileio later */ + as those have to be in EXTFH3 / fileio later */ static FCD3 * fcd2_to_fcd3 (FCD2 *fcd2) { @@ -9970,25 +9971,25 @@ cob_extfh_read (EXTFH_FUNC callfh, cob_file *f, fcd = find_fcd (f, 1); STCOMPX4 (read_opts, fcd->opt); - if(key == NULL) { - if((read_opts & COB_READ_PREVIOUS)) { + if (key == NULL) { + if ((read_opts & COB_READ_PREVIOUS)) { STCOMPX2(OP_READ_PREV, opcode); } else { STCOMPX2(OP_READ_SEQ, opcode); } - if(f->organization == COB_ORG_RELATIVE) { + if (f->organization == COB_ORG_RELATIVE) { memset (fcd->relKey, 0, sizeof (fcd->relKey)); recn = cob_get_int (f->keys[0].field); STCOMPX4(recn, LSUCHAR(fcd->relKey+4)); if (f->access_mode != COB_ACCESS_SEQUENTIAL) STCOMPX2(OP_READ_RAN, opcode); } - } else if(f->organization == COB_ORG_INDEXED) { + } else if (f->organization == COB_ORG_INDEXED) { keyn = cob_findkey (f, key, &keylen, &partlen); STCOMPX2(keyn, fcd->refKey); STCOMPX2(keylen, fcd->effKeyLen); STCOMPX2(OP_READ_RAN, opcode); - } else if(f->organization == COB_ORG_RELATIVE) { + } else if (f->organization == COB_ORG_RELATIVE) { memset (fcd->relKey, 0, sizeof (fcd->relKey)); recn = cob_get_int (key); STCOMPX4(recn, LSUCHAR(fcd->relKey+4)); @@ -10014,12 +10015,12 @@ cob_extfh_read_next (EXTFH_FUNC callfh, cob_file *f, fcd = find_fcd (f, 1); STCOMPX4(read_opts, fcd->opt); - if((read_opts & COB_READ_PREVIOUS)) { + if ((read_opts & COB_READ_PREVIOUS)) { STCOMPX2(OP_READ_PREV, opcode); } else { STCOMPX2(OP_READ_SEQ, opcode); } - if(f->organization == COB_ORG_RELATIVE) { + if (f->organization == COB_ORG_RELATIVE) { memset (fcd->relKey, 0, sizeof (fcd->relKey)); recn = cob_get_int (f->keys[0].field); STCOMPX4(recn, LSUCHAR(fcd->relKey+4)); @@ -10085,7 +10086,7 @@ cob_extfh_rewrite (EXTFH_FUNC callfh, cob_file *f, } STCOMPX4(rec->size,fcd->curRecLen); fcd->recPtr = rec->data; - if(f->organization == COB_ORG_RELATIVE) { + if (f->organization == COB_ORG_RELATIVE) { memset (fcd->relKey, 0, sizeof (fcd->relKey)); recn = cob_get_int (f->keys[0].field); STCOMPX4(recn, LSUCHAR(fcd->relKey+4)); @@ -10124,7 +10125,7 @@ cob_extfh_delete (EXTFH_FUNC callfh, cob_file *f, } /* COBOL wrapper for EXTFH call to prevent warnings about FCD3 structure - with additional checks */ + with additional checks */ int cob_sys_extfh (const void *opcode_ptr, void *fcd_ptr) { @@ -10297,8 +10298,8 @@ update_key_from_fcd (cob_file *f, FCD3 *fcd, cob_field *kf) && f->keys[k].field) { cob_field *key = f->keys[k].field; #if 0 /* the following sets up the _real_ key data, - but the functions called afterwards look out for - the "intermediate" key field; therefore leave as-is */ + but the functions called afterwards look out for + the "intermediate" key field; therefore leave as-is */ kf->size = key->size; kf->attr = key->attr; if (f->keys[k].count_components <= 1) { @@ -10479,8 +10480,8 @@ EXTFH3 (unsigned char *opcode, FCD3 *fcd) } #if 0 /* this disables some expected status 44 - and SIGSEGV if the actual data is only - record_min long (+ accessed longer) */ + and SIGSEGV if the actual data is only + record_min long (+ accessed longer) */ if (f->record && f->record->size < f->record_min) { f->record->size = f->record_min; @@ -10503,8 +10504,8 @@ EXTFH3 (unsigned char *opcode, FCD3 *fcd) STCOMPX4(f->record_max,fcd->curRecLen); update_file_to_fcd (f, fcd, fnstatus); #if 0 /* Simon: general mapping needed, depending - on a compile time switch (also for other dialects) - --> no "single place extension" here */ + on a compile time switch (also for other dialects) + --> no "single place extension" here */ if (f->organization == COB_ORG_INDEXED && memcmp (f->file_status, "61", 2) == 0) {/* 61 --> 9A for MF */ memcpy (fcd->fileStatus,"9A", 2); @@ -10521,8 +10522,8 @@ EXTFH3 (unsigned char *opcode, FCD3 *fcd) } update_file_to_fcd (f, fcd, fnstatus); #if 0 /* Simon: general mapping needed, depending - on a compile time switch (also for other dialects) - --> no "single place extension" here */ + on a compile time switch (also for other dialects) + --> no "single place extension" here */ if (f->organization == COB_ORG_INDEXED && memcmp (f->file_status, "61", 2) == 0) {/* 61 --> 9A for MF */ memcpy (fcd->fileStatus,"9A", 2); @@ -10540,8 +10541,8 @@ EXTFH3 (unsigned char *opcode, FCD3 *fcd) } update_file_to_fcd (f, fcd, fnstatus); #if 0 /* Simon: general mapping needed, depending - on a compile time switch (also for other dialects) - --> no "single place extension" here */ + on a compile time switch (also for other dialects) + --> no "single place extension" here */ if (f->organization == COB_ORG_INDEXED && memcmp (f->file_status, "61", 2) == 0) {/* 61 --> 9A for MF */ memcpy (fcd->fileStatus,"9A", 2); @@ -10557,8 +10558,8 @@ EXTFH3 (unsigned char *opcode, FCD3 *fcd) } update_file_to_fcd (f, fcd, fnstatus); #if 0 /* Simon: general mapping needed, depending - on a compile time switch (also for other dialects) - --> no "single place extension" here */ + on a compile time switch (also for other dialects) + --> no "single place extension" here */ if (f->organization == COB_ORG_INDEXED && memcmp (f->file_status, "61", 2) == 0) {/* 61 --> 9A for MF */ memcpy (fcd->fileStatus,"9A", 2); @@ -10738,8 +10739,8 @@ EXTFH3 (unsigned char *opcode, FCD3 *fcd) } #endif #if 1 /* Simon: breaks status 44 and - can lead to SIGSEGV if there's only curRecLen - data available */ + can lead to SIGSEGV if there's only curRecLen + data available */ if (rec->size < f->record_min) { rec->size = f->record_min; } @@ -10765,8 +10766,8 @@ EXTFH3 (unsigned char *opcode, FCD3 *fcd) } #endif #if 1 /* Simon: breaks status 44 and - can lead to SIGSEGV if there's only curRecLen - data available */ + can lead to SIGSEGV if there's only curRecLen + data available */ if (rec->size < f->record_min) { rec->size = f->record_min; } @@ -10835,7 +10836,7 @@ EXTFH3 (unsigned char *opcode, FCD3 *fcd) default: fcd->fileStatus[0] = '9'; #if 0 /* MF seems to return 142 file not open, possibly only until opened; - we use 100->invalid file operation */ + we use 100->invalid file operation */ fcd->fileStatus[1] = 142; #else fcd->fileStatus[1] = 100; @@ -10881,7 +10882,7 @@ cob_path_to_absolute (const char *path) /* ============================================ */ -static int +static int create_first_segment (PHEAP_ENTRY ptr_heap) { const unsigned int data_size = ptr_heap->alloc_size - sizeof(SEG_HDR); @@ -10963,7 +10964,7 @@ open_vfile (cob_u16_ptr heap_id, unsigned char status[2], const int gc_ext) *heap_id = heap + 1; ptr_heap->alloc_size = gc_ext ? cobsetptr->cob_heap_memory_64 : cobsetptr->cob_heap_memory; - + return_code = create_first_segment (ptr_heap); if (return_code == 0) { memcpy (status, "00", 2); @@ -10992,7 +10993,7 @@ cob_sys_open_vfile2 (unsigned char *heap_id, unsigned char *status) return open_vfile ((cob_u16_ptr)heap_id, status, 1); } -static int +static int get_new_segment (PHEAP_ENTRY ptr_heap, PSEG_HDR ptr_seg_curr) { const unsigned int data_size = ptr_heap->alloc_size - sizeof(SEG_HDR); @@ -11024,8 +11025,8 @@ get_new_segment (PHEAP_ENTRY ptr_heap, PSEG_HDR ptr_seg_curr) return 0; } - -static int + +static int locate_segment (cob_u16_t heap, cob_u64_t data_loc, cob_u32_t size, void *data_buffer, const int for_read) { void *ptr_data; @@ -11050,7 +11051,7 @@ locate_segment (cob_u16_t heap, cob_u64_t data_loc, cob_u32_t size, void *data_b cob_runtime_warning ("heap out of bounds %u", heap); return HEAP_OUT_BOUNDS; } - + ptr_heap = &heap_array[heap - 1]; /* verify that we actually initialized that heap */ @@ -11071,7 +11072,7 @@ locate_segment (cob_u16_t heap, cob_u64_t data_loc, cob_u32_t size, void *data_b front of the linked list or the end of it */ data_middle = ptr_heap->total_data_alloc>>2; - + if (data_loc < data_middle) { ptr_seg = ptr_heap->ptr_seg_first; } else { @@ -11188,7 +11189,7 @@ cob_sys_write_vfile2 (cob_u16_t heap, cob_u64_t offset, cob_u32_t size, unsigned int cob_sys_close_vfile (const cob_u16_t heap) -{ +{ PHEAP_ENTRY ptr_heap; PSEG_HDR ptr_seg; @@ -11201,7 +11202,7 @@ cob_sys_close_vfile (const cob_u16_t heap) ptr_heap = &heap_array[heap - 1]; ptr_seg = ptr_heap->ptr_seg_first; - + while (ptr_seg != NULL) { PSEG_HDR ptr_seg_delete = ptr_seg; diff --git a/libcob/mlio.c b/libcob/mlio.c index 26f66600b..1eec8afb7 100644 --- a/libcob/mlio.c +++ b/libcob/mlio.c @@ -505,7 +505,7 @@ is_empty (const cob_field * const f) } /* strdup-like wrapper for get_trimmed_data, returns a pointer to - fresh allocated memory pointing to a copy of the specified + fresh allocated memory pointing to a copy of the specified data with specified size as string (+ trailing NULL) */ static void * copy_data_as_string (const char* data, const size_t size) @@ -630,9 +630,9 @@ static void * get_num (cob_field * const f, void * (*strndup_func)(const char *, size_t), const char decimal_point) { - const size_t num_integer_digits + const size_t num_integer_digits = cob_max_int (0, COB_FIELD_DIGITS (f) - COB_FIELD_SCALE (f)); - const size_t num_decimal_digits + const size_t num_decimal_digits = cob_max_int (0, COB_FIELD_SCALE (f)); cob_field_attr attr; cob_field edited_field; diff --git a/libcob/move.c b/libcob/move.c index 25dccfc2a..4e75edbfb 100644 --- a/libcob/move.c +++ b/libcob/move.c @@ -1,22 +1,22 @@ /* - Copyright (C) 2002-2012, 2014-2020, 2022-2024 Free Software Foundation, Inc. - Written by Keisuke Nishida, Roger While, Simon Sobisch, Ron Norman, - Edwart Hard + Copyright (C) 2002-2012, 2014-2020, 2022-2024 Free Software Foundation, Inc. + Written by Keisuke Nishida, Roger While, Simon Sobisch, Ron Norman, + Edwart Hard - This file is part of GnuCOBOL. + This file is part of GnuCOBOL. - The GnuCOBOL runtime library is free software: you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public License - as published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. + The GnuCOBOL runtime library is free software: you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public License + as published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. - GnuCOBOL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. + GnuCOBOL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License - along with GnuCOBOL. If not, see . + You should have received a copy of the GNU Lesser General Public License + along with GnuCOBOL. If not, see . */ @@ -61,7 +61,7 @@ static const cob_field_attr all_numeric_display_attr = 0, NULL}; static unsigned char all_numeric_data[COB_MAX_DIGITS]; -static const cob_field all_numeric_field = +static const cob_field all_numeric_field = {COB_MAX_DIGITS, all_numeric_data, &all_numeric_display_attr}; @@ -102,42 +102,42 @@ static const cob_s64_t cob_exp10_ll[19] = { /* translation table for BCD byte (2 digits) to integer; - identical defined in numeric.c */ + identical defined in numeric.c */ static const unsigned char pack_to_bin [] = { #if 0 /* invalid BCD nibbles as zero */ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, - 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 0, 0, 0, 0, 0, - 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 0, 0, 0, 0, 0, 0, - 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 0, 0, 0, 0, 0, 0, - 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 0, 0, 0, 0, 0, 0, - 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 0, 0, 0, 0, 0, 0, - 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 0, 0, 0, 0, 0, 0, - 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 0, 0, 0, 0, 0, 0, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 0, 0, 0, 0, 0, 0, - 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 0, 0, 0, 0, 0, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 0, 0, 0, 0, 0, 0, + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 0, 0, 0, 0, 0, 0, + 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 0, 0, 0, 0, 0, 0, + 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 0, 0, 0, 0, 0, 0, + 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 0, 0, 0, 0, 0, 0, + 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 0, 0, 0, 0, 0, 0, + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 0, 0, 0, 0, 0, 0, + 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 #else /* invalid BCD nibbles as translated since at least OC 1.1 */ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, - 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 25, - 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, - 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, - 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, - 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, - 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, - 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, - 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, - 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, - 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, - 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, - 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165 + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 25, + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, + 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, + 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, + 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, + 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, + 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, + 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, + 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, + 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, + 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165 #endif }; @@ -487,7 +487,6 @@ cob_move_alphanum_to_alphanum (cob_field *f1, cob_field *f2) void cob_move_display_to_packed (cob_field *f1, cob_field *f2) { - /************************************************************/ /* */ /* The logic used by this function is to find the offset */ @@ -534,141 +533,137 @@ cob_move_display_to_packed (cob_field *f1, cob_field *f2) /* */ /************************************************************/ - const int sign = COB_GET_SIGN_ADJUST (f1); - const short scale1 = COB_FIELD_SCALE (f1); - const short scale2 = COB_FIELD_SCALE (f2); - const int target_no_sign_nibble = COB_FIELD_NO_SIGN_NIBBLE (f2); - unsigned int f1_digits, f2_digits; - unsigned int start_in_low_nibble = 0; - int f1_offset, f2_offset; - - register unsigned char *p, *p_end, *q, *q_end; - - - /************************************************************/ - /* */ - /* Note that when calculating the offsets of the first */ - /* position in each field we need to use the number of */ - /* digits in the actual data field not the number of */ - /* digits returned by the COB_FIELD_DIGITS function. */ - /* */ - /* Note that this logic works whether or not there is a */ - /* "P" any where in the PICTURE clause. */ - /* */ - /************************************************************/ - - if (COB_FIELD_SIGN_SEPARATE (f1)) - f1_digits = f1->size - 1; - else - f1_digits = f1->size; + const int sign = COB_GET_SIGN_ADJUST (f1); + const short scale1 = COB_FIELD_SCALE (f1); + const short scale2 = COB_FIELD_SCALE (f2); + const int target_no_sign_nibble = COB_FIELD_NO_SIGN_NIBBLE (f2); + unsigned int f1_digits, f2_digits; + unsigned int start_in_low_nibble = 0; + int f1_offset, f2_offset; + + register unsigned char *p, *p_end, *q, *q_end; + + /************************************************************/ + /* */ + /* Note that when calculating the offsets of the first */ + /* position in each field we need to use the number of */ + /* digits in the actual data field not the number of */ + /* digits returned by the COB_FIELD_DIGITS function. */ + /* */ + /* Note that this logic works whether or not there is a */ + /* "P" any where in the PICTURE clause. */ + /* */ + /************************************************************/ + + if (COB_FIELD_SIGN_SEPARATE (f1)) { + f1_digits = f1->size - 1; + } else { + f1_digits = f1->size; + } p = COB_FIELD_DATA (f1); p_end = p + f1_digits - 1; f1_offset = f1_digits - scale1 - 1; - - if (target_no_sign_nibble) - f2_digits = f2->size << 1; - else - f2_digits = (f2->size << 1) - 1; + if (target_no_sign_nibble) { + f2_digits = f2->size << 1; + } else { + f2_digits = (f2->size << 1) - 1; + } q = f2->data; q_end = q + f2->size - 1; f2_offset = f2_digits - scale2 - 1; - /************************************************************/ - /* */ - /* if the packed field has a sign nibble then the offset */ - /* has to be one greater than the number of digits in */ - /* both fields since the offset is the position in */ - /* the receiving field */ - /* */ - /************************************************************/ - - /************************************************************/ - /* */ - /* At this point we are ready to position the pointers to */ - /* the sending and receiving fields. Note that if the */ - /* offsets are equal then no positioning is needed and we */ - /* can just start packing data */ - /* */ + /************************************************************/ + /* */ + /* if the packed field has a sign nibble then the offset */ + /* has to be one greater than the number of digits in */ + /* both fields since the offset is the position in */ + /* the receiving field */ + /* */ + /************************************************************/ + + /************************************************************/ + /* */ + /* At this point we are ready to position the pointers to */ + /* the sending and receiving fields. Note that if the */ + /* offsets are equal then no positioning is needed and we */ + /* can just start packing data */ + /* */ /* zero out target, then transfer data */ - /* */ - /************************************************************/ + /* */ + /************************************************************/ memset (f2->data, 0, f2->size); - if (f1_offset > f2_offset) - p = p + (f1_offset - f2_offset); - else if (f1_offset < f2_offset) - { - /************************************************************/ - /* if the difference in offsets is odd then the first */ - /* digit will need to pack into the low order nibble */ - /* otherwise it can start packing into the high order */ - /* nibble */ - /************************************************************/ - if ((f2_offset - f1_offset) & 1) - start_in_low_nibble = 1; - q = q + ((f2_offset - f1_offset ) >> 1); - } - - /************************************************************/ - /* */ - /* Now both pointers have been set to start the packing */ - /* of digits. Note that first we have to check to see if */ - /* the first digit to be packed has to be positioned in */ - /* the lower order nibble before we can start the packing */ - /* loop */ - /* */ - /************************************************************/ - - if (start_in_low_nibble && (p <= p_end) && (q <= q_end)) - { - *q = (*p) & 0x0F; - q++; - p++; - } + if (f1_offset > f2_offset) { + p = p + (f1_offset - f2_offset); + } else if (f1_offset < f2_offset) { + /************************************************************/ + /* if the difference in offsets is odd then the first */ + /* digit will need to pack into the low order nibble */ + /* otherwise it can start packing into the high order */ + /* nibble */ + /************************************************************/ + if ((f2_offset - f1_offset) & 1) { + start_in_low_nibble = 1; + } + q = q + ((f2_offset - f1_offset ) >> 1); + } - /************************************************************/ - /* */ - /* Now we can start the packing loop !! */ - /* */ - /* Note that we exit when the display pointer NOT LESS */ - /* than the last digit in the sending field. */ - /* */ - /************************************************************/ + /************************************************************/ + /* */ + /* Now both pointers have been set to start the packing */ + /* of digits. Note that first we have to check to see if */ + /* the first digit to be packed has to be positioned in */ + /* the lower order nibble before we can start the packing */ + /* loop */ + /* */ + /************************************************************/ - while ((p < p_end) && (q <= q_end)) - { - *q = (unsigned char) ((*p << 4) & 0xF0) /* -> dropping the higher bits = no use in COB_D2I */ - + COB_D2I (*(p + 1)); - p = p + 2; - q++; + if (start_in_low_nibble && (p <= p_end) && (q <= q_end)) { + *q = (*p) & 0x0F; + q++; + p++; } - /************************************************************/ - /* */ - /* Now we need to check if there is 1 digit left to pack */ - /* */ - /************************************************************/ + /************************************************************/ + /* */ + /* Now we can start the packing loop !! */ + /* */ + /* Note that we exit when the display pointer NOT LESS */ + /* than the last digit in the sending field. */ + /* */ + /************************************************************/ - if ((p == p_end) && (q <= q_end)) - { - *q = (unsigned char) ((*p << 4) & 0xF0); + while ((p < p_end) && (q <= q_end)) { + *q = (unsigned char) ((*p << 4) & 0xF0) /* -> dropping the higher bits = no use in COB_D2I */ + + COB_D2I (*(p + 1)); + p = p + 2; + q++; + } + + /************************************************************/ + /* */ + /* Now we need to check if there is 1 digit left to pack */ + /* */ + /************************************************************/ + + if ((p == p_end) && (q <= q_end)) { + *q = (unsigned char) ((*p << 4) & 0xF0); } COB_PUT_SIGN_ADJUSTED (f1, sign); - if (COB_FIELD_DIGITS(f2) < f2_digits) - { - *(f2->data) &= 0x0f; + if (COB_FIELD_DIGITS(f2) < f2_digits) { + *(f2->data) &= 0x0f; } if (target_no_sign_nibble) { - return; + return; } if (!COB_FIELD_HAVE_SIGN (f2)) { @@ -685,11 +680,11 @@ cob_move_display_to_packed (cob_field *f1, cob_field *f2) void cob_move_packed_to_display (cob_field *f1, cob_field *f2) { - unsigned char buff[COB_MAX_DIGITS + 1]; + unsigned char buff[COB_MAX_DIGITS + 1]; register unsigned char *b = buff; register unsigned char *d = f1->data; - unsigned char *d_end = d + f1->size - 1; - const short scale = COB_FIELD_SCALE (f1); + unsigned char *d_end = d + f1->size - 1; + const short scale = COB_FIELD_SCALE (f1); unsigned short digits; if (scale >= 0) { @@ -809,7 +804,7 @@ cob_move_fp_to_fp (cob_field *src, cob_field *dst) /* move from one to the other binary field ignoring the scale - --> these must match */ + --> these must match */ static void cob_move_binary_to_binary (cob_field *f1, cob_field *f2) { @@ -874,7 +869,7 @@ cob_move_display_to_binary (cob_field *f1, cob_field *f2) size_t i; int sign; unsigned short target_digits; - + /* truncate on request - by adjusting start position */ if (COB_FIELD_BINARY_TRUNC (f2)) { const short scale = COB_FIELD_SCALE (f2) ; @@ -981,55 +976,55 @@ cob_move_binary_to_display (cob_field *f1, cob_field *f2) static void optimized_move_display_to_edited (cob_field *f1, cob_field *f2) { - /************************************************************/ - /* this is a special "optimized" version of the */ - /* cob_move_display_to_edited function. The scale and */ - /* digits of the f2 field must be the same as the f1 */ - /* field. */ - /* */ - /* it is only called from the indirect_move function when */ - /* the destination field is type */ - /* COB_TYPE_NUMERIC_EDITED */ - /* */ - /* create numeric edited field, note: non-display fields */ - /* get "unpacked" first via indirect_move, then be edited */ - /* from display using this function */ - /* */ - /* This requires that the input field MUST be signed */ - /* separate (which is trailing). Also the source field */ - /* must contain the exact same number of digits as the */ - /* destination.. */ - /* */ - /* This ensures that we can make a single pass thru the */ - /* picture symbols and not have to worry about padding or */ - /* insertation after the loop thru the picture symbols. */ - /* */ - /* The reason for this change has more to do with */ - /* reducing the complexity of the code than performance. */ - /* Although it may result in a slight performance gain as */ - /* well. */ - /* */ - /************************************************************/ + /************************************************************/ + /* this is a special "optimized" version of the */ + /* cob_move_display_to_edited function. The scale and */ + /* digits of the f2 field must be the same as the f1 */ + /* field. */ + /* */ + /* it is only called from the indirect_move function when */ + /* the destination field is type */ + /* COB_TYPE_NUMERIC_EDITED */ + /* */ + /* create numeric edited field, note: non-display fields */ + /* get "unpacked" first via indirect_move, then be edited */ + /* from display using this function */ + /* */ + /* This requires that the input field MUST be signed */ + /* separate (which is trailing). Also the source field */ + /* must contain the exact same number of digits as the */ + /* destination.. */ + /* */ + /* This ensures that we can make a single pass thru the */ + /* picture symbols and not have to worry about padding or */ + /* insertation after the loop thru the picture symbols. */ + /* */ + /* The reason for this change has more to do with */ + /* reducing the complexity of the code than performance. */ + /* Although it may result in a slight performance gain as */ + /* well. */ + /* */ + /************************************************************/ - register unsigned char *dst = f2->data; - register unsigned char *src = f1->data; - const cob_pic_symbol *p; - unsigned char *src_last = src + f1->size - 1; - unsigned char *dst_end = f2->data + f2->size; - const int sign = COB_GET_SIGN (f1); + register unsigned char *dst = f2->data; + register unsigned char *src = f1->data; + const cob_pic_symbol *p; + unsigned char *src_last = src + f1->size - 1; + unsigned char *dst_end = f2->data + f2->size; + const int sign = COB_GET_SIGN (f1); - unsigned char *prev_float_char = NULL; - unsigned char *sign_position = NULL; - const int neg = (sign < 0) ? 1 : 0; - int is_zero = 1; - int suppress_zero = 1; - int have_decimal_point = 0; - int have_check_protect = 0; - int cntr_currency = 0; - int cntr_sign = 0; - unsigned char pad = ' '; - unsigned char c; - unsigned char float_char = 0x00; + unsigned char *prev_float_char = NULL; + unsigned char *sign_position = NULL; + const int neg = (sign < 0) ? 1 : 0; + int is_zero = 1; + int suppress_zero = 1; + int have_decimal_point = 0; + int have_check_protect = 0; + int cntr_currency = 0; + int cntr_sign = 0; + unsigned char pad = ' '; + unsigned char c; + unsigned char float_char = 0x00; const unsigned char dec_symbol = COB_MODULE_PTR->decimal_point == ',' ? ',' : '.'; const unsigned char currency = COB_MODULE_PTR->currency_symbol; @@ -1042,15 +1037,14 @@ optimized_move_display_to_edited (cob_field *f1, cob_field *f2) } #endif - - /************************************************************/ - /* Currently this will require two passes of the symbol */ - /* table to find the float char.... */ - /* */ - /* this logic to find the floating char if one exits */ - /* should be moved to COBC in GC40. This would require */ - /* some structure changes so for now it is needed here. */ - /************************************************************/ + /************************************************************/ + /* Currently this will require two passes of the symbol */ + /* table to find the float char.... */ + /* */ + /* this logic to find the floating char if one exits */ + /* should be moved to COBC in GC40. This would require */ + /* some structure changes so for now it is needed here. */ + /************************************************************/ c = 0x00; @@ -1082,7 +1076,9 @@ optimized_move_display_to_edited (cob_field *f1, cob_field *f2) } } - if (COB_FIELD_HAVE_SIGN (f1) && COB_FIELD_SIGN_SEPARATE (f1) && COB_FIELD_SIGN_LEADING (f1)) { + if (COB_FIELD_HAVE_SIGN (f1) + && COB_FIELD_SIGN_SEPARATE (f1) + && COB_FIELD_SIGN_LEADING (f1)) { src++; } @@ -1506,8 +1502,8 @@ indirect_move (void (*func) (cob_field *src, cob_field *dst), cob_field field; cob_field_attr attr; - size_t temp_size; - unsigned short digits; + size_t temp_size; + unsigned short digits; if (COB_FIELD_TYPE(dst) == COB_TYPE_NUMERIC_EDITED) { unsigned char buff[COB_MAX_DIGITS + 1] = { 0 }; @@ -1516,17 +1512,17 @@ indirect_move (void (*func) (cob_field *src, cob_field *dst), if (COB_FIELD_HAVE_SIGN(dst)) { COB_FIELD_INIT (temp_size, buff, &attr); COB_ATTR_INIT (COB_TYPE_NUMERIC_DISPLAY, - digits, - COB_FIELD_SCALE(dst), - (COB_FLAG_HAVE_SIGN | COB_FLAG_SIGN_SEPARATE), - NULL); + digits, + COB_FIELD_SCALE(dst), + (COB_FLAG_HAVE_SIGN | COB_FLAG_SIGN_SEPARATE), + NULL); } else { COB_FIELD_INIT (temp_size - 1, buff, &attr); COB_ATTR_INIT (COB_TYPE_NUMERIC_DISPLAY, - digits, - COB_FIELD_SCALE(dst), - 0, - NULL); + digits, + COB_FIELD_SCALE(dst), + 0, + NULL); } func (src, &field); optimized_move_display_to_edited (&field, dst); @@ -1534,13 +1530,13 @@ indirect_move (void (*func) (cob_field *src, cob_field *dst), unsigned char buff[2 * COB_MAX_DIGITS] = { 0 }; COB_FIELD_INIT (size, buff, &attr); COB_ATTR_INIT (COB_TYPE_NUMERIC_DISPLAY, (unsigned short) size, (short) scale, - COB_FLAG_HAVE_SIGN, NULL); + COB_FLAG_HAVE_SIGN, NULL); func (src, &field); cob_move (&field, dst); } else { COB_FIELD_INIT (size, cob_malloc (size), &attr); COB_ATTR_INIT (COB_TYPE_NUMERIC_DISPLAY, (unsigned short) size, (short) scale, - COB_FLAG_HAVE_SIGN, NULL); + COB_FLAG_HAVE_SIGN, NULL); func (src, &field); cob_move (&field, dst); cob_free (field.data); @@ -1554,8 +1550,8 @@ cob_move_all (cob_field *src, cob_field *dst) size_t digcount; cob_field temp; - if (likely(COB_FIELD_IS_ALNUM (dst))) { - if (likely(src->size == 1)) { + if (likely (COB_FIELD_IS_ALNUM (dst))) { + if (likely (src->size == 1)) { memset (dst->data, src->data[0], dst->size); } else { size_t i; @@ -1571,7 +1567,7 @@ cob_move_all (cob_field *src, cob_field *dst) has to be an alphanumeric MOVE */ temp.attr = &all_display_attr; digcount = dst->size; - } else if (likely(src->size == 1)) { + } else if (likely (src->size == 1)) { memset (all_numeric_data, src->data[0], COB_MAX_DIGITS); cob_move ((cob_field *)&all_numeric_field, dst); return; @@ -1582,7 +1578,7 @@ cob_move_all (cob_field *src, cob_field *dst) p = cob_malloc (digcount); temp.size = digcount; temp.data = p; - if (likely(src->size == 1)) { + if (likely (src->size == 1)) { /* most common: ALL 0 (or 9 or ...) -> fill data */ memset (p, src->data[0], digcount); } else { @@ -1708,8 +1704,8 @@ cob_move (cob_field *src, cob_field *dst) optimized_move_display_to_edited (src, dst); } else { indirect_move (cob_move_display_to_display, src, dst, - (size_t)(COB_FIELD_DIGITS (src)), - COB_FIELD_SCALE (src)); + (size_t)(COB_FIELD_DIGITS (src)), + COB_FIELD_SCALE (src)); } return; case COB_TYPE_ALPHANUMERIC_EDITED: @@ -1717,8 +1713,8 @@ cob_move (cob_field *src, cob_field *dst) || COB_FIELD_SCALE (src) > COB_FIELD_DIGITS (src)) { /* Expand P's */ indirect_move (cob_move_display_to_display, src, dst, - (size_t)cob_max_int (COB_FIELD_DIGITS (src), COB_FIELD_SCALE (src)), - cob_max_int (0, COB_FIELD_SCALE (src))); + (size_t)cob_max_int (COB_FIELD_DIGITS (src), COB_FIELD_SCALE (src)), + cob_max_int (0, COB_FIELD_SCALE (src))); return; } else { cob_move_alphanum_to_edited (src, dst); @@ -1740,10 +1736,10 @@ cob_move (cob_field *src, cob_field *dst) if (opt == COB_STORE_TRUNC_ON_OVERFLOW) { /* note: "dst" is only possible when binary-trunc */ indirect_move (cob_move_packed_to_display, src, dst, - COB_FIELD_DIGITS (dst), COB_FIELD_SCALE (dst)); + COB_FIELD_DIGITS (dst), COB_FIELD_SCALE (dst)); } else { indirect_move (cob_move_packed_to_display, src, dst, - COB_FIELD_DIGITS (src), COB_FIELD_SCALE (src)); + COB_FIELD_DIGITS (src), COB_FIELD_SCALE (src)); } #else cob_decimal_setget_fld (src, dst, opt); @@ -1768,8 +1764,8 @@ cob_move (cob_field *src, cob_field *dst) return; default: indirect_move (cob_move_packed_to_display, src, dst, - (size_t)(COB_FIELD_DIGITS(src)), - COB_FIELD_SCALE (src)); + (size_t)(COB_FIELD_DIGITS(src)), + COB_FIELD_SCALE (src)); return; } @@ -1816,10 +1812,10 @@ cob_move (cob_field *src, cob_field *dst) if (opt == COB_STORE_TRUNC_ON_OVERFLOW) { /* note: "dst" is only possible when binary-trunc */ indirect_move (cob_move_binary_to_display, src, dst, - COB_FIELD_DIGITS (dst), COB_FIELD_SCALE (dst)); + COB_FIELD_DIGITS (dst), COB_FIELD_SCALE (dst)); } else { indirect_move (cob_move_binary_to_display, src, dst, - COB_FIELD_DIGITS (src), COB_FIELD_SCALE (src)); + COB_FIELD_DIGITS (src), COB_FIELD_SCALE (src)); } #endif } @@ -1865,13 +1861,13 @@ cob_move (cob_field *src, cob_field *dst) return; case COB_TYPE_NUMERIC_EDITED: indirect_move (cob_move_binary_to_display, src, dst, - (size_t)COB_MAX_DIGITS, - COB_FIELD_SCALE (src)); + (size_t)COB_MAX_DIGITS, + COB_FIELD_SCALE (src)); return; default: indirect_move (cob_move_binary_to_display, src, dst, - (size_t)(COB_FIELD_DIGITS(src)), - COB_FIELD_SCALE (src)); + (size_t)(COB_FIELD_DIGITS(src)), + COB_FIELD_SCALE (src)); return; } @@ -1885,8 +1881,8 @@ cob_move (cob_field *src, cob_field *dst) case COB_TYPE_NUMERIC_COMP5: case COB_TYPE_NUMERIC_EDITED: indirect_move (cob_move_edited_to_display, src, dst, - (size_t)(2 * COB_MAX_DIGITS), - COB_MAX_DIGITS); + (size_t)(2 * COB_MAX_DIGITS), + COB_MAX_DIGITS); return; case COB_TYPE_NUMERIC_FLOAT: case COB_TYPE_NUMERIC_DOUBLE: @@ -2044,8 +2040,8 @@ cob_move (cob_field *src, cob_field *dst) case COB_TYPE_NUMERIC_COMP5: case COB_TYPE_NUMERIC_EDITED: indirect_move (cob_move_alphanum_to_display, src, dst, - (size_t)(2 * COB_MAX_DIGITS), - COB_MAX_DIGITS); + (size_t)(2 * COB_MAX_DIGITS), + COB_MAX_DIGITS); return; case COB_TYPE_NUMERIC_FLOAT: case COB_TYPE_NUMERIC_DOUBLE: @@ -2072,7 +2068,7 @@ cob_move (cob_field *src, cob_field *dst) static int cob_packed_get_int (cob_field *field) { - register int val; + register int val; register unsigned char *d = field->data; const unsigned char *d_end = d + field->size - 1; @@ -2124,33 +2120,31 @@ cob_packed_get_int (cob_field *field) static cob_s64_t packed_get_long_long (cob_field *field) { - const short scale = COB_FIELD_SCALE (field); - register cob_s64_t val; + const short scale = COB_FIELD_SCALE (field); + register cob_s64_t val; register unsigned char *d = field->data; const unsigned char *d_end = d + field->size - 1; if (COB_FIELD_NO_SIGN_NIBBLE (field)) { /* Unpack COMP-6 to integer */ - /************************************************************/ - /* if the scale is negative we need to determine if the */ - /* number of digits in the data plus the number of P's is */ - /* greater than the number of digits in the field. */ - /************************************************************/ - if (scale < 0) - { - if (((field->size * 2) - scale) > COB_FIELD_DIGITS (field)) - val = *d++ & 0x0F; - else - val = 0; - } - else - { - const size_t offset = COB_FIELD_DIGITS (field) % 2; - if (offset == 1) { - val = *d++ & 0x0F; + /************************************************************/ + /* if the scale is negative we need to determine if the */ + /* number of digits in the data plus the number of P's is */ + /* greater than the number of digits in the field. */ + /************************************************************/ + if (scale < 0) { + if (((field->size * 2) - scale) > COB_FIELD_DIGITS (field)) { + val = *d++ & 0x0F; + } else { + val = 0; + } } else { - val = 0; - } + const size_t offset = COB_FIELD_DIGITS (field) % 2; + if (offset == 1) { + val = *d++ & 0x0F; + } else { + val = 0; + } } if (val == 0) { /* Skip leading ZEROs */ @@ -2163,27 +2157,25 @@ packed_get_long_long (cob_field *field) val = val * 100 + pack_to_bin[*d++]; } } else { - /************************************************************/ - /* if the scale is negative we need to determine if the */ - /* number of digits in the data plus the number of P's is */ - /* greater than the number of digits in the field. */ - /************************************************************/ - if (scale < 0) - { - if (((field->size * 2) - 1 - scale) > COB_FIELD_DIGITS (field)) - val = *d++ & 0x0F; - else - val = 0; - } - else - { - /* Unpack PACKED-DECIMAL / COMP-3 to integer */ - const size_t offset = 1 - COB_FIELD_DIGITS (field) % 2; - if (offset == 1) { - val = *d++ & 0x0F; + /************************************************************/ + /* if the scale is negative we need to determine if the */ + /* number of digits in the data plus the number of P's is */ + /* greater than the number of digits in the field. */ + /************************************************************/ + if (scale < 0) { + if (((field->size * 2) - 1 - scale) > COB_FIELD_DIGITS (field)) { + val = *d++ & 0x0F; + } else { + val = 0; + } } else { - val = 0; - } + /* Unpack PACKED-DECIMAL / COMP-3 to integer */ + const size_t offset = 1 - COB_FIELD_DIGITS (field) % 2; + if (offset == 1) { + val = *d++ & 0x0F; + } else { + val = 0; + } } if (val == 0) { /* Skip leading ZEROs */ @@ -2384,7 +2376,7 @@ cob_put_u64_compx (cob_u64_t val, void *mem, int len) #endif cob_u32_t uint; cob_u16_t ushort; - + #ifdef WORDS_BIGENDIAN switch (len) { case sizeof(int): @@ -2482,15 +2474,15 @@ cob_put_s64_compx (cob_s64_t val, void *mem, int len) switch (len) { case sizeof(int): sint = ((cob_s32_t)val); - memcpy(mem,((cob_u8_t*)&sint),sizeof(int)); + memcpy (mem, ((cob_u8_t*)&sint), sizeof(int)); return; default: /* Assume 64 bit value */ case sizeof(cob_s64_t): - memcpy(mem,((cob_u8_t*)&val),sizeof(cob_s64_t)); + memcpy (mem, ((cob_u8_t*)&val), sizeof(cob_s64_t)); return; case sizeof(short): sshort = ((cob_s16_t)val); - memcpy(mem,((cob_u8_t*)&sshort),sizeof(short)); + memcpy (mem, ((cob_u8_t*)&sshort), sizeof(short)); return; case 1: *((cob_s8_t*)mem) = ((cob_s8_t)val); @@ -2499,22 +2491,22 @@ cob_put_s64_compx (cob_s64_t val, void *mem, int len) case 5: case 6: case 7: - memcpy(mem,((cob_u8_t*)&val)+(sizeof(cob_s64_t)-len),len); + memcpy (mem, ((cob_u8_t*)&val) + (sizeof(cob_s64_t) - len), len); } #else switch (len) { case sizeof(int): sint = COB_BSWAP_32 ((cob_s32_t)val); - memcpy(mem,((cob_u8_t*)&sint),sizeof(int)); + memcpy (mem, ((cob_u8_t*)&sint), sizeof(int)); return; default: /* Assume 64 bit value */ case sizeof(cob_s64_t): slong = COB_BSWAP_64 ((cob_s64_t)val); - memcpy(mem,((cob_u8_t*)&slong),sizeof(cob_s64_t)); + memcpy (mem, ((cob_u8_t*)&slong), sizeof(cob_s64_t)); return; case sizeof(short): sshort = COB_BSWAP_16 ((cob_s16_t)val); - memcpy(mem,((cob_u8_t*)&sshort),sizeof(short)); + memcpy (mem, ((cob_u8_t*)&sshort), sizeof(short)); return; case 1: *((cob_s8_t*)mem) = ((cob_s8_t)val); @@ -2524,7 +2516,7 @@ cob_put_s64_compx (cob_s64_t val, void *mem, int len) case 6: case 7: slong = COB_BSWAP_64 (val); - memcpy(mem,((cob_u8_t*)&slong)+(sizeof(cob_s64_t)-len),len); + memcpy (mem, ((cob_u8_t*)&slong) + (sizeof(cob_s64_t) - len), len); } #endif return; @@ -2699,7 +2691,7 @@ cob_get_s64_compx (void *mem, int len) cob_s64_t slong; int sint; short sshort; - + #if defined(WORDS_BIGENDIAN) switch (len) { case sizeof(int): @@ -2938,7 +2930,7 @@ cob_get_s64_pic9 (void *mem, int len) sign = 1; } else if (COB_MODULE_PTR->ebcdic_sign) { #ifndef COB_EBCDIC_MACHINE - switch(*p) { + switch (*p) { case '{': val = val * 10 + 0; sign = 1; break; case 'A': val = val * 10 + 1; sign = 1; break; case 'B': val = val * 10 + 2; sign = 1; break; @@ -3052,11 +3044,11 @@ cob_get_picx (void *cbl_data, size_t len, void *char_field, size_t num_chars) num_chars = i + 1; char_field = cob_malloc (num_chars); } - + if (i > num_chars - 1) { i = num_chars - 1; } - + memcpy (char_field, cbl_data, i); ((char*)char_field)[i] = 0; return char_field; diff --git a/libcob/screenio.c b/libcob/screenio.c index a1a06cef2..1bc1eb068 100644 --- a/libcob/screenio.c +++ b/libcob/screenio.c @@ -172,15 +172,15 @@ static cob_settings *cobsetptr; static const cob_field_attr const_alpha_attr = {COB_TYPE_ALPHANUMERIC, 0, 0, 0, NULL}; static struct cob_inp_struct *cob_base_inp; -static size_t totl_index; -static size_t cob_has_color; +static size_t totl_index; +static size_t cob_has_color; static int global_return; static int cob_current_y; static int cob_current_x; -static short fore_color /* "const" default foreground (pair 0 on init) */; -static short back_color /* "const" default background (pair 0 on init) */; -static short stdscr_fore_color /* "const" default foreground (pair 0 on init) */; -static short stdscr_back_color /* "const" default background (pair 0 on init) */; +static short fore_color /* "const" default foreground (pair 0 on init) */; +static short back_color /* "const" default background (pair 0 on init) */; +static short stdscr_fore_color /* "const" default foreground (pair 0 on init) */; +static short stdscr_back_color /* "const" default background (pair 0 on init) */; static int origin_y; static int origin_x; static int display_cursor_y; @@ -191,22 +191,22 @@ static int pending_accept; static int got_sys_char; static int save_cursor_x = 0; static int save_cursor_y = 0; -static WINDOW *mywin; +static WINDOW *mywin; #ifdef WITH_PANELS -#define MAX_PANELS 20 +#define MAX_PANELS 20 enum sys_win_mode { - SYS_WIN_NEW = 'N', + SYS_WIN_NEW = 'N', SYS_WIN_DELETE = 'D', - SYS_WIN_ATTR_GET = 'G', - SYS_WIN_ATTR_CHANGE = 'S', - SYS_WIN_MOVE = 'M', - SYS_WIN_SHOW = 'V', - SYS_WIN_HIDE = 'I', - SYS_WIN_TOP = 'T', + SYS_WIN_ATTR_GET = 'G', + SYS_WIN_ATTR_CHANGE = 'S', + SYS_WIN_MOVE = 'M', + SYS_WIN_SHOW = 'V', + SYS_WIN_HIDE = 'I', + SYS_WIN_TOP = 'T', SYS_WIN_BOTTOM = 'B', - SYS_WIN_LIST = 'L' + SYS_WIN_LIST = 'L' }; #define SYS_WIN_FLAG_HIDDEN (1 << 0) @@ -5895,4 +5895,4 @@ cob_sys_window (unsigned char *mode_ext, unsigned char *fld) return -2; #endif -} \ No newline at end of file +} diff --git a/libcob/termio.c b/libcob/termio.c index 83ecba978..b8b21d0d0 100644 --- a/libcob/termio.c +++ b/libcob/termio.c @@ -108,10 +108,10 @@ display_numeric (cob_field *f, FILE *fp) static void pretty_display_numeric (cob_field *f, FILE *fp) { - unsigned short digits; - signed short scale = COB_FIELD_SCALE (f); + unsigned short digits; + signed short scale = COB_FIELD_SCALE (f); const int has_sign = COB_FIELD_HAVE_SIGN (f) ? 1 : 0; - int size; + int size; /* Note: while we only need one pair, the double one works around a bug in old GCC versions https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119 */ cob_pic_symbol pic[6] = {{ 0 }}; @@ -187,7 +187,7 @@ pretty_display_numeric (cob_field *f, FILE *fp) cob_move (f, &field); } - + /* output of data to viewport */ { register unsigned char *q = COB_TERM_BUFF; diff --git a/tests/testsuite.src/data_display.at b/tests/testsuite.src/data_display.at index fe8909fd8..3c08c2506 100644 --- a/tests/testsuite.src/data_display.at +++ b/tests/testsuite.src/data_display.at @@ -78,6 +78,7 @@ q2340 AT_CLEANUP + AT_SETUP([DISPLAY: Sign ASCII (2)]) AT_KEYWORDS([display]) @@ -169,6 +170,7 @@ AT_CHECK([$COBCRUN_DIRECT ./prog], [0], [{ABCDEFGHI}JKLMNOPQR]) AT_CLEANUP + AT_SETUP([DISPLAY: unsigned]) AT_KEYWORDS([display]) diff --git a/tests/testsuite.src/run_accept.at b/tests/testsuite.src/run_accept.at index 12fc3c4a6..68fd81997 100644 --- a/tests/testsuite.src/run_accept.at +++ b/tests/testsuite.src/run_accept.at @@ -317,6 +317,8 @@ AT_CHECK([$COMPILE prog.cob], [0], [], []) AT_CHECK([$COBCRUN_DIRECT ./prog], [0], [], []) AT_CLEANUP + + AT_SETUP([ACCEPT DATE / DAY and intrinsic functions (2)]) AT_KEYWORDS([configuration FUNCTION INTEGER-OF-DATE DAY-OF-INTEGER COB_CURRENT_DATE]) diff --git a/tests/testsuite.src/run_extensions.at b/tests/testsuite.src/run_extensions.at index 95e34f256..ceef0c943 100644 --- a/tests/testsuite.src/run_extensions.at +++ b/tests/testsuite.src/run_extensions.at @@ -479,7 +479,7 @@ AT_DATA([prog.cob], [ STOP RUN. ]) -AT_CHECK([$COMPILE prog.cob ], [0], [], []) +AT_CHECK([$COMPILE prog.cob], [0], [], []) AT_CHECK([$COBCRUN_DIRECT ./prog], [0], [], []) AT_CLEANUP @@ -5401,6 +5401,7 @@ SORT-RETURN = +000000000 TALLY = 00000 AT_CLEANUP + AT_SETUP([Bit Operations]) AT_KEYWORDS([BIT-WISE]) diff --git a/tests/testsuite.src/run_file.at b/tests/testsuite.src/run_file.at index c20d5715c..ce522eafa 100644 --- a/tests/testsuite.src/run_file.at +++ b/tests/testsuite.src/run_file.at @@ -2548,7 +2548,7 @@ AT_DATA([prog.cob], [ Exit. ]) -AT_CHECK([$COMPILE prog.cob ], [0], [], []) +AT_CHECK([$COMPILE prog.cob], [0], [], []) AT_CHECK([$COBCRUN_DIRECT ./prog], [0], [delete file @@ -14123,7 +14123,7 @@ AT_DATA([prog.cob], [ . ]) -AT_CHECK([$COMPILE prog.cob ], [0], [], []) +AT_CHECK([$COMPILE prog.cob], [0], [], []) AT_CHECK([$COBCRUN_DIRECT ./prog], [1], [a a @@ -15557,8 +15557,10 @@ TRYING TO WRITE ERROR ON FILE-EXT EXITING NESTED-PROGRAM-1-2 ], []) + AT_CLEANUP + AT_SETUP([OPEN / CLOSE with multiple filenames]) AT_KEYWORDS([DECLARATIVES file error]) diff --git a/tests/testsuite.src/run_manual_screen.at b/tests/testsuite.src/run_manual_screen.at index 94d5c5e1e..240da30c2 100644 --- a/tests/testsuite.src/run_manual_screen.at +++ b/tests/testsuite.src/run_manual_screen.at @@ -3538,6 +3538,7 @@ MANUAL_CHECK([$COBCRUN_DIRECT ./prog], [0], [], []) AT_CLEANUP + AT_SETUP([simple ACCEPT field WITH UPDATE]) AT_KEYWORDS([screen]) diff --git a/tests/testsuite.src/run_misc.at b/tests/testsuite.src/run_misc.at index ab6190f5a..d99706087 100644 --- a/tests/testsuite.src/run_misc.at +++ b/tests/testsuite.src/run_misc.at @@ -12505,7 +12505,7 @@ AT_DATA([prog.cob], [ DBX-RECORD-CODE (REC-NAME-DBX) '.'. ]) -AT_CHECK([$COMPILE -frelax-syntax-checks prog.cob ], [0], [], +AT_CHECK([$COMPILE -frelax-syntax-checks prog.cob], [0], [], [prog.cob:26: warning: INDEXED should follow ASCENDING/DESCENDING ]) diff --git a/tests/testsuite.src/run_returncode.at b/tests/testsuite.src/run_returncode.at index 33c19cce1..f81452865 100644 --- a/tests/testsuite.src/run_returncode.at +++ b/tests/testsuite.src/run_returncode.at @@ -46,6 +46,7 @@ AT_CHECK([$COBCRUN_DIRECT ./prog], [1]) AT_CLEANUP + AT_SETUP([RETURN-CODE passing]) AT_KEYWORDS([returncode]) @@ -98,6 +99,7 @@ AT_CHECK([$COBCRUN_DIRECT ./prog], [0], [], []) AT_CLEANUP + AT_SETUP([RETURN-CODE nested]) AT_KEYWORDS([returncode]) diff --git a/tests/testsuite.src/syn_definition.at b/tests/testsuite.src/syn_definition.at index 5e54358ea..20c1affbd 100644 --- a/tests/testsuite.src/syn_definition.at +++ b/tests/testsuite.src/syn_definition.at @@ -2871,7 +2871,7 @@ AT_DATA([prog.cob], [ USE BEFORE REPORTING DEPTHDR. ]) -AT_CHECK([$COMPILE_ONLY -std=default prog.cob ], [1], [], +AT_CHECK([$COMPILE_ONLY prog.cob], [1], [], [prog.cob: in section 'DEPTHDRUSE': prog.cob:6: error: 'DEPTHDR' is not defined ]) diff --git a/tests/testsuite.src/syn_functions.at b/tests/testsuite.src/syn_functions.at index 27f3e2773..6f4c9a376 100644 --- a/tests/testsuite.src/syn_functions.at +++ b/tests/testsuite.src/syn_functions.at @@ -511,6 +511,7 @@ prog.cob:53: error: FUNCTION 'FORMATTED-TIME' has invalid date/time format AT_CLEANUP + AT_SETUP([invalid formats w/ DECIMAL-POINT IS COMMA]) AT_KEYWORDS([functions FORMATTED-TIME FORMATTED-DATETIME]) diff --git a/tests/testsuite.src/syn_misc.at b/tests/testsuite.src/syn_misc.at index 02e26b227..2c89046dd 100644 --- a/tests/testsuite.src/syn_misc.at +++ b/tests/testsuite.src/syn_misc.at @@ -3583,6 +3583,7 @@ prog.cob:31: error: wrong number of WHEN parameters AT_CLEANUP + AT_SETUP([COBOL-WORDS directive]) AT_KEYWORDS([misc reserved words]) @@ -3920,7 +3921,7 @@ AT_DATA([prog.cob], [ STOP RUN. ]) -AT_CHECK([$COMPILE -x -std=mf -debug -Wall prog.cob ], [1], [], +AT_CHECK([$COMPILE -x -std=mf -debug -Wall prog.cob], [1], [], [prog.cob: in paragraph 'MAIN-10': prog.cob:19: error: STRING item 'I-X' must be USAGE DISPLAY or NATIONAL prog.cob:19: error: STRING item 'I-B' must be USAGE DISPLAY or NATIONAL @@ -4993,7 +4994,7 @@ prog.cob:9: error: missing left parenthesis prog.cob:10: error: '/' operator misplaced ]) -AT_CHECK([$COMPILE_ONLY -std=ibm-strict prog.cob ], [1], [], +AT_CHECK([$COMPILE_ONLY -std=ibm-strict prog.cob], [1], [], [prog.cob:6: error: 78 VALUE does not conform to IBM COBOL prog.cob:7: error: 78 VALUE does not conform to IBM COBOL prog.cob:8: error: 78 VALUE does not conform to IBM COBOL @@ -5289,7 +5290,7 @@ AT_DATA([prog.cob], [ STOP RUN. ]) -AT_CHECK([$COMPILE_ONLY prog.cob ], [0], [], +AT_CHECK([$COMPILE_ONLY prog.cob], [0], [], [prog.cob:15: warning: expression '115' EQUALS '200' is always FALSE prog.cob:16: warning: expression '200' EQUALS '115' is always FALSE prog.cob:17: warning: expression '200' EQUALS '315' is always FALSE @@ -5658,6 +5659,7 @@ AT_CHECK([$COMPILE_ONLY -frelax-syntax-checks prog.cob], [1], [], AT_CLEANUP + AT_SETUP([CONSTANT LENGTH / BYTE-LENGTH]) AT_KEYWORDS([misc]) @@ -8096,6 +8098,7 @@ prog.cob:15: warning: start of statement in Area A AT_CLEANUP + AT_SETUP([AREACHECK / NOAREACHECK directives (2)]) AT_KEYWORDS([misc directive missing-periods]) @@ -8280,6 +8283,7 @@ pgm1.cob:18: error: start of statement in Area A AT_CLEANUP + AT_SETUP([autodetect format]) AT_KEYWORDS([cobc free fixed format]) @@ -8354,6 +8358,7 @@ AT_CHECK([$COMPILE_ONLY -fformat=fixed domfixed.cob], [0], [], []) AT_CLEANUP + AT_SETUP([context sensitive alias]) AT_KEYWORDS([misc context alias]) diff --git a/tests/testsuite.src/syn_redefines.at b/tests/testsuite.src/syn_redefines.at index ad03a623e..470727640 100644 --- a/tests/testsuite.src/syn_redefines.at +++ b/tests/testsuite.src/syn_redefines.at @@ -71,6 +71,7 @@ AT_CHECK([$COMPILE_ONLY prog.cob], [1], [], AT_CLEANUP + AT_SETUP([REDEFINES: level 03 by 02]) AT_KEYWORDS([redefines]) @@ -93,6 +94,7 @@ AT_CHECK([$COMPILE_ONLY prog.cob], [1], [], AT_CLEANUP + AT_SETUP([REDEFINES: level 66]) AT_KEYWORDS([redefines]) @@ -115,6 +117,7 @@ AT_CHECK([$COMPILE_ONLY prog.cob], [1], [], AT_CLEANUP + AT_SETUP([REDEFINES: level 88]) AT_KEYWORDS([redefines]) diff --git a/tests/testsuite.src/syn_refmod.at b/tests/testsuite.src/syn_refmod.at index 71553d1fd..ecec48b5a 100644 --- a/tests/testsuite.src/syn_refmod.at +++ b/tests/testsuite.src/syn_refmod.at @@ -52,6 +52,7 @@ prog.cob:16: warning: suspicious reference-modification: always using max. posit AT_CLEANUP + AT_SETUP([invalid reference-modification]) AT_KEYWORDS([refmod condition-name])