From fc2295c48e8813818e7427a361fab4b9e0720abf Mon Sep 17 00:00:00 2001 From: Fabrice Le Fessant Date: Wed, 11 Oct 2023 15:46:19 +0200 Subject: [PATCH] New option --copy COPYBOOK, to include a COPYBOOK before reading the source file --- cobc/ChangeLog | 5 +++++ cobc/cobc.c | 15 +++++++++++++-- cobc/cobc.h | 1 + cobc/pplex.l | 8 +++++++- tests/testsuite.src/syn_copy.at | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 3 deletions(-) diff --git a/cobc/ChangeLog b/cobc/ChangeLog index 0c5659e71..cc9c5c5bd 100644 --- a/cobc/ChangeLog +++ b/cobc/ChangeLog @@ -1,4 +1,9 @@ +2023-10-11 Fabrice Le Fessant + + * cobc.c, pplex.l: new option --copy COPYBOOK, to include a COPYBOOK + before reading the source file + 2023-07-26 Simon Sobisch * typeck.c (search_set_keys): improving SEARCH ALL syntax checks diff --git a/cobc/cobc.c b/cobc/cobc.c index b3a52303c..ed4389dd1 100644 --- a/cobc/cobc.c +++ b/cobc/cobc.c @@ -106,6 +106,7 @@ enum compile_level { #define CB_FLAG_GETOPT_EBCDIC_TABLE 14 #define CB_FLAG_GETOPT_DEFAULT_COLSEQ 15 #define CB_FLAG_MEMORY_CHECK 16 +#define CB_FLAG_COPY_FILE 17 /* Info display limits */ @@ -171,8 +172,8 @@ enum compile_level { #define GC_C_VERSION _("unknown") #endif -#define CB_TEXT_LIST_ADD(y,z) y = cb_text_list_add (y, z) -#define CB_TEXT_LIST_CHK(y,z) y = cb_text_list_chk (y, z) +#define CB_TEXT_LIST_ADD(list,z) list = cb_text_list_add (list, z) +#define CB_TEXT_LIST_CHK(list,z) list = cb_text_list_chk (list, z) #ifdef _MSC_VER #define CB_COPT_0 " /Od" @@ -232,6 +233,7 @@ const char *cb_cobc_build_stamp = NULL; const char *demangle_name = NULL; const char *cb_storage_file_name = NULL; const char *cb_call_extfh = NULL; +struct cb_text_list *cb_copy_list = NULL; struct cb_text_list *cb_include_list = NULL; struct cb_text_list *cb_depend_list = NULL; struct cb_text_list *cb_intrinsic_list = NULL; @@ -595,6 +597,7 @@ static const struct option long_options[] = { {"save-temps", CB_OP_ARG, NULL, '_'}, {"std", CB_RQ_ARG, NULL, '$'}, {"conf", CB_RQ_ARG, NULL, '&'}, + {"copy", CB_RQ_ARG, NULL, CB_FLAG_COPY_FILE}, {"debug", CB_NO_ARG, NULL, 'd'}, {"ext", CB_RQ_ARG, NULL, 'e'}, /* note: kept *undocumented* until GC4, will be changed to '.' */ {"free", CB_NO_ARG, NULL, 'F'}, /* note: not assigned directly as this is only valid for */ @@ -3887,6 +3890,14 @@ process_command_line (const int argc, char **argv) } break; + case CB_FLAG_COPY_FILE: /* 17 */ + /* -copy= : COPY file at beginning */ + { + char *file = cobc_strdup (cob_optarg); + CB_TEXT_LIST_ADD (cb_copy_list, file); + break; + } + case 'A': /* -A : Add options to C compile phase */ COBC_ADD_STR (cobc_cflags, " ", cob_optarg, NULL); diff --git a/cobc/cobc.h b/cobc/cobc.h index 73f3d7a23..74b1aee42 100644 --- a/cobc/cobc.h +++ b/cobc/cobc.h @@ -473,6 +473,7 @@ extern FILE *cb_listing_file; extern FILE *cb_src_list_file; extern FILE *cb_depend_file; extern struct cb_text_list *cb_depend_list; +extern struct cb_text_list *cb_copy_list; extern struct cb_text_list *cb_include_list; extern struct cb_text_list *cb_intrinsic_list; extern struct cb_text_list *cb_extension_list; diff --git a/cobc/pplex.l b/cobc/pplex.l index 623b2e5d4..d08f8ba71 100644 --- a/cobc/pplex.l +++ b/cobc/pplex.l @@ -71,7 +71,13 @@ static int ppwrap (void) { plexbuff2 = cobc_malloc ((size_t)COB_SMALL_BUFF); \ } \ requires_listing_line = 1; \ - comment_allowed = 1; + comment_allowed = 1; \ + { \ + struct cb_text_list *l; \ + for (l=cb_copy_list ; l ; l = l->next){ \ + ppcopy (l->text, NULL, NULL); \ + } \ + } #include "config.h" diff --git a/tests/testsuite.src/syn_copy.at b/tests/testsuite.src/syn_copy.at index 0ac0784b2..c4d71c65c 100644 --- a/tests/testsuite.src/syn_copy.at +++ b/tests/testsuite.src/syn_copy.at @@ -1072,3 +1072,36 @@ AT_DATA([prog.cob], [ AT_CHECK([$COMPILE_ONLY prog.cob], [0], [], []) AT_CLEANUP + + +AT_SETUP([Option --copy COPYBOOK]) +AT_KEYWORDS([argument]) + +AT_DATA([copybook.cpy], [ + REPLACE ==BEGIN PROGRAM== BY ==IDENTIFICATION DIVISION. + PROGRAM-ID.== + ==output== BY =="Hello world"==. +]) +AT_DATA([prog.cob], [ + BEGIN PROGRAM prog. + PROCEDURE DIVISION. + DISPLAY output + STOP RUN. +]) + +AT_CHECK([$COMPILE_ONLY prog.cob], [1], [], +[prog.cob:2: error: PROGRAM-ID header missing +prog.cob:2: error: ENVIRONMENT DIVISION header missing +prog.cob:2: error: CONFIGURATION SECTION header missing +prog.cob:2: error: SPECIAL-NAMES header missing +prog.cob:2: error: invalid system-name 'BEGIN' +prog.cob:2: error: syntax error, unexpected PROGRAM, expecting CRT or Identifier +prog.cob:2: error: invalid system-name 'prog' +prog.cob:2: error: syntax error, unexpected ., expecting CRT or Identifier +prog.cob:3: error: syntax error, unexpected PROCEDURE +prog.cob:4: error: PROCEDURE DIVISION header missing +]) + +AT_CHECK([$COMPILE_ONLY --copy copybook prog.cob]) + +AT_CLEANUP