Skip to content

Commit

Permalink
Merge SVN 5257
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeclerck committed Feb 16, 2025
1 parent 14f2974 commit c97ba6f
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 75 deletions.
2 changes: 1 addition & 1 deletion build_windows/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@
version_libcob.rc, version_cobcrun.rc provided by Simon)


Copyright 2014-2023 Free Software Foundation, Inc.
Copyright 2014-2024 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification, are
permitted provided the copyright notice and this notice are preserved.
92 changes: 48 additions & 44 deletions cobc/cobc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2990,18 +2990,15 @@ static int
process_command_line (const int argc, char **argv)
{
struct cb_define_struct *p;
size_t osize;
int c;
int idx;
int n;
int exit_option = 0;
int list_reserved = 0;
int list_registers = 0;
int list_intrinsics = 0;
int list_system_names = 0;
int list_exceptions = 0;
int list_system_routines = 0;
enum cob_exception_id i;
char ext[COB_MINI_BUFF];
char *conf_label; /* we want a dynamic address for error.c, not a static one */
char *conf_entry;
Expand Down Expand Up @@ -3055,14 +3052,15 @@ process_command_line (const int argc, char **argv)
long_options, &idx, 1)) >= 0) {
switch (c) {

case 7:
case CB_FLAG_GETOPT_MAX_ERRORS: {
/* -fmax-errors=<xx> : Maximum errors until abort */
n = cobc_deciph_optarg (cob_optarg, 0);
const int n = cobc_deciph_optarg (cob_optarg, 0);
if (n < 0) {
cobc_err_exit (COBC_INV_PAR, "-fmax-errors");
}
cb_max_errors = n;
break;
}

case '?':
/* Unknown option or ambiguous,
Expand Down Expand Up @@ -3209,7 +3207,7 @@ process_command_line (const int argc, char **argv)
/* output version information when running very verbose -vv */
/* pass verbose switch to invoked commands when running very very verbose -vvv */
if (cob_optarg) {
n = cobc_deciph_optarg (cob_optarg, 0);
const int n = cobc_deciph_optarg (cob_optarg, 0);
if (n == -1) {
cobc_err_exit (COBC_INV_PAR, "--verbose");
}
Expand All @@ -3219,8 +3217,9 @@ process_command_line (const int argc, char **argv)
}
break;

case '$':
case '$': {
/* -std=<xx> : Specify dialect */
int n;
if (strlen (cob_optarg) > (COB_MINI_MAX - 6)) {
cobc_err_exit (COBC_INV_PAR, "-std");
}
Expand All @@ -3231,6 +3230,7 @@ process_command_line (const int argc, char **argv)
snprintf (cob_std_conf, sizeof(cob_std_conf), "%s.conf", cob_optarg);
num_std++;
break;
}

case '&':
/* -conf=<xx> : Specify dialect configuration file */
Expand Down Expand Up @@ -3323,12 +3323,12 @@ process_command_line (const int argc, char **argv)
cobc_wants_debug = 1;
break;

case CB_FLAG_GETOPT_DUMP: /* 8 */
case CB_FLAG_GETOPT_DUMP:
/* -fdump=<scope> : Add sections for dump code generation */
cobc_def_dump_opts (cob_optarg, 1);
break;

case CB_FLAG_GETOPT_NO_DUMP: /* 13 */
case CB_FLAG_GETOPT_NO_DUMP:
/* -fno-dump=<scope> : Suppress sections in dump code generation */
if (cob_optarg) {
cobc_def_dump_opts (cob_optarg, 0);
Expand Down Expand Up @@ -3357,6 +3357,7 @@ process_command_line (const int argc, char **argv)
} else
if (cb_config_name == NULL) {
#ifdef WITH_STD
int n;
strcpy(ext, WITH_STD);
for (n=0; ext[n] != 0; n++)
ext[n] = toupper(ext[n]);
Expand All @@ -3382,6 +3383,7 @@ process_command_line (const int argc, char **argv)

/* debug: Turn on all exception conditions */
if (cobc_wants_debug) {
enum cob_exception_id i;
for (i = (enum cob_exception_id)1; i < COB_EC_MAX; ++i) {
CB_EXCEPTION_ENABLE (i) = 1;
}
Expand Down Expand Up @@ -3534,9 +3536,9 @@ process_command_line (const int argc, char **argv)
/* these options were processed in the first getopt-run */
break;

case 'o':
case 'o': {
/* -o : Output file */
osize = strlen (cob_optarg);
const size_t osize = strlen (cob_optarg);
if (osize > COB_SMALL_MAX) {
cobc_err_exit (_("invalid output file name"));
}
Expand All @@ -3548,6 +3550,7 @@ process_command_line (const int argc, char **argv)
/* Allocate buffer plus extension reserve */
output_name_buff = cobc_main_malloc (osize + 32U);
break;
}

case '0':
/* -O0 : disable optimizations (or at least minimize them) */
Expand Down Expand Up @@ -3834,16 +3837,17 @@ process_command_line (const int argc, char **argv)
CB_TEXT_LIST_ADD (cb_early_exit_list, cob_optarg);
break;

case CB_FLAG_GETOPT_STACK_SIZE: /* 1 */
case CB_FLAG_GETOPT_STACK_SIZE: {
/* -fstack-size=<xx> : Specify stack (perform) size */
n = cobc_deciph_optarg (cob_optarg, 0);
const int n = cobc_deciph_optarg (cob_optarg, 0);
if (n < 16 || n > 512) {
cobc_err_exit (COBC_INV_PAR, "-fstack-size");
}
cb_stack_size = n;
break;
}

case CB_FLAG_GETOPT_SIGN: /* 3 */
case CB_FLAG_GETOPT_SIGN:
/* -fsign=<ASCII/EBCDIC> : Specify display sign */
if (!cb_strcasecmp (cob_optarg, "EBCDIC")) {
cb_ebcdic_sign = 1;
Expand All @@ -3854,26 +3858,26 @@ process_command_line (const int argc, char **argv)
}
break;

case CB_FLAG_GETOPT_EBCDIC_TABLE: /* 14 */
case CB_FLAG_GETOPT_EBCDIC_TABLE:
/* -febcdic-table=<cconv-table> */
cb_ebcdic_table = cobc_main_strdup (cob_optarg);
break;

case CB_FLAG_GETOPT_DEFAULT_COLSEQ: /* 15 */
case CB_FLAG_GETOPT_DEFAULT_COLSEQ:
/* -fdefault-colseq=<ASCII/EBCDIC/NATIVE> */
if (cb_deciph_default_colseq_name (cob_optarg)) {
cobc_err_exit (COBC_INV_PAR, "-fdefault-colseq");
}
break;

case CB_FLAG_GETOPT_DEFAULT_FILE_COLSEQ: /* 16 */
case CB_FLAG_GETOPT_DEFAULT_FILE_COLSEQ:
/* -fdefault-file-colseq=<ASCII/EBCDIC/NATIVE> */
if (cb_deciph_default_file_colseq_name (cob_optarg)) {
cobc_err_exit (COBC_INV_PAR, "-fdefault-file-colseq");
}
break;

case CB_FLAG_GETOPT_FOLD_COPY: /* 4 */
case CB_FLAG_GETOPT_FOLD_COPY:
/* -ffold-copy=<UPPER/LOWER> : COPY fold case */
if (!cb_strcasecmp (cob_optarg, "UPPER")) {
cb_fold_copy = COB_FOLD_UPPER;
Expand All @@ -3884,7 +3888,7 @@ process_command_line (const int argc, char **argv)
}
break;

case CB_FLAG_GETOPT_FOLD_CALL: /* 5 */
case CB_FLAG_GETOPT_FOLD_CALL:
/* -ffold-call=<UPPER/LOWER> : CALL/PROG-ID fold case */
if (!cb_strcasecmp (cob_optarg, "UPPER")) {
cb_fold_call = COB_FOLD_UPPER;
Expand All @@ -3895,44 +3899,43 @@ process_command_line (const int argc, char **argv)
}
break;

case CB_FLAG_GETOPT_TTITLE: /* 6 */
case CB_FLAG_GETOPT_TTITLE: {
/* -fttitle=<title> : Title for listing */
{
const size_t len = strlen (cob_optarg);
size_t i;
if (cb_listing_with_title)
cobc_main_free (cb_listing_with_title);
cb_listing_with_title = cobc_main_strdup (cob_optarg);
for (i = 0; i < len; i++) {
if (cb_listing_with_title[i] == '_')
cb_listing_with_title[i] = ' ';
}
const size_t len = strlen (cob_optarg);
size_t i;
if (cb_listing_with_title)
cobc_main_free (cb_listing_with_title);
cb_listing_with_title = cobc_main_strdup (cob_optarg);
for (i = 0; i < len; i++) {
if (cb_listing_with_title[i] == '_')
cb_listing_with_title[i] = ' ';
}
break;
}

case CB_FLAG_GETOPT_MAX_ERRORS: /* 7 */
case CB_FLAG_GETOPT_MAX_ERRORS:
/* -fmax-errors=<xx> : Maximum errors until abort */
/* This option was processed in the first getopt-run */
break;

case CB_FLAG_GETOPT_DUMP: /* 8 */
case CB_FLAG_GETOPT_DUMP:
/* -fdump=<scope> : Add sections for dump code generation */
case CB_FLAG_GETOPT_NO_DUMP: /* 13 */
case CB_FLAG_GETOPT_NO_DUMP:
/* -fno-dump=<scope> : Suppress sections in dump code generation */
/* These options were all processed in the first getopt-run */
break;

case CB_FLAG_GETOPT_CALLFH: /* 9 */
case CB_FLAG_GETOPT_CALLFH:
/* -fcallfh=<func> : Function-name for EXTFH */
cb_call_extfh = cobc_main_strdup (cob_optarg);
break;

case CB_FLAG_GETOPT_INTRINSICS: /* 10 */
case CB_FLAG_GETOPT_INTRINSICS:
/* -fintrinsics=<xx> : Intrinsic name or ALL */
cobc_deciph_funcs (cob_optarg);
break;

case CB_FLAG_GETOPT_SQLSCHEMA: /* 20 */
case CB_FLAG_GETOPT_SQLSCHEMA:
/* -fsqlschema=<name> : Database schema name for XFD */
cb_sqldb_schema = cobc_main_strdup (cob_optarg);
cb_flag_sql_xfd = 1;
Expand All @@ -3955,7 +3958,7 @@ process_command_line (const int argc, char **argv)
#endif
break;

case CB_FLAG_GETOPT_FILE_FORMAT: /* 21 */
case CB_FLAG_GETOPT_FILE_FORMAT:
/* -ffile-format=<name> : Default file format */
if (cb_strcasecmp (cob_optarg, "mf") == 0) {
cb_mf_files = 1;
Expand All @@ -3967,39 +3970,39 @@ process_command_line (const int argc, char **argv)
}
break;

case CB_FLAG_GETOPT_EC: /* 11 */
case CB_FLAG_GETOPT_EC:
/* -fec=<xx> : COBOL exception-name, e.g. EC-BOUND-OVERFLOW,
also allows to skip the prefix e.g. BOUND-OVERFLOW */
if (cobc_deciph_ec (cob_optarg, 1U)) {
cobc_err_exit (COBC_INV_PAR, "-fec");
};
break;

case CB_FLAG_GETOPT_NO_EC: /* 12 */
case CB_FLAG_GETOPT_NO_EC:
/* -fno-ec=<xx> : COBOL exception-name, e.g. EC-BOUND-OVERFLOW */
if (cobc_deciph_ec (cob_optarg, 0)) {
cobc_err_exit (COBC_INV_PAR, "-fno-ec");
};
break;

case CB_FLAG_GETOPT_MEMORY_CHECK: /* 17 */
/* -fmemory-check=<scope> : */
case CB_FLAG_GETOPT_MEMORY_CHECK:
/* -fmemory-check=<scope> : extra memcmp for memory-guard */
if (!cob_optarg) {
cb_flag_memory_check = CB_MEMCHK_ALL;
} else if (cobc_deciph_memory_check (cob_optarg)) {
cobc_err_exit (COBC_INV_PAR, "-fmemory-check");
}
break;

case CB_FLAG_GETOPT_COPY_FILE: /* 18 */
case CB_FLAG_GETOPT_COPY_FILE:
/* --copy=<file> : COPY file at beginning */
if (strlen (cob_optarg) > (COB_MINI_MAX)) {
cobc_err_exit (COBC_INV_PAR, "--copy");
}
CB_TEXT_LIST_ADD (cb_copy_list, cobc_strdup (cob_optarg));
break;

case CB_FLAG_GETOPT_INCLUDE_FILE: /* 19 */
case CB_FLAG_GETOPT_INCLUDE_FILE:
/* -include=<file.h> : add #include "file.h" to
generated C file */
if (strlen (cob_optarg) > (COB_MINI_MAX)) {
Expand Down Expand Up @@ -4125,7 +4128,8 @@ process_command_line (const int argc, char **argv)

/* LCOV_EXCL_START */
default:
cobc_err_msg ("missing evaluation of command line option '%c'", c); /* not translated as unlikely */
/* not translated as unlikely */
cobc_err_msg ("missing evaluation of command line option '%c'", c);
COBC_ABORT ();
/* LCOV_EXCL_STOP */

Expand Down
4 changes: 1 addition & 3 deletions cobc/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -14948,8 +14948,6 @@ codegen_internal (struct cb_program *prog, const int subsequent_call)
cb_tree l;
int i;

int comment_gen;

struct cb_report *rep;

/* skip prototypes */
Expand Down Expand Up @@ -15085,7 +15083,7 @@ codegen_internal (struct cb_program *prog, const int subsequent_call)

/* Report data fields */
if (prog->report_storage) {
comment_gen = 0;
int comment_gen = 0;
for (l = prog->report_list; l; l = CB_CHAIN (l)) {
if (!CB_VALUE (l)) {
continue;
Expand Down
9 changes: 5 additions & 4 deletions cobc/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,13 @@ diagnostics_show_caret (FILE *fd, const int line)
const int line_start = line > CARET_CONTEXT_LINES ? line - CARET_CONTEXT_LINES : 1;
const int line_end = line + CARET_CONTEXT_LINES;
const int max_pos = cb_diagnostics_show_line_numbers ? CARET_MAX_COLS - 5 : CARET_MAX_COLS;
char buffer[ CARET_MAX_COLS + 1 ];
unsigned char buffer[ CARET_MAX_COLS + 1 ];
int line_pos = 1;
int char_pos = 0;
int c = 0;
while (c != EOF) {
buffer[char_pos] = c = fgetc (fd);;
c = fgetc (fd);
buffer[char_pos] = c;
if (c == '\n' || c == EOF || char_pos == max_pos) {
if (line_pos >= line_start) {
/* prefix */
Expand All @@ -143,8 +144,8 @@ diagnostics_show_caret (FILE *fd, const int line)
|| buffer[char_pos] == '\t'
|| buffer[char_pos] == '\r'
|| buffer[char_pos] == '\n'
|| buffer[char_pos] == EOF
|| char_pos == max_pos)) {
|| buffer[char_pos] == (unsigned char)EOF
|| char_pos == max_pos)) {
buffer[char_pos--] = 0;
}
/* print it */
Expand Down
6 changes: 4 additions & 2 deletions cobc/replace.c
Original file line number Diff line number Diff line change
Expand Up @@ -879,14 +879,16 @@ cb_ppecho_copy_replace (const char *text, const char *token)
&& token_queue_is_empty(copy_repls->token_queue)
&& replace_repls->text_prequeue == NULL
&& token_queue_is_empty(replace_repls->token_queue)) {
return cb_ppecho_direct (text, token);
cb_ppecho_direct (text, token);
return;
}

if (copy_repls->replace_list == NULL
&& copy_repls->current_list == NULL
&& replace_repls->replace_list == NULL
&& replace_repls->current_list == NULL) {
return cb_ppecho_direct (text, token);
cb_ppecho_direct (text, token);
return;
}

add_text_to_replace (INIT_DEPTH copy_repls, 0, text, token);
Expand Down
Loading

0 comments on commit c97ba6f

Please sign in to comment.