Skip to content

Commit

Permalink
New option --copy COPYBOOK, to include a COPYBOOK before reading the …
Browse files Browse the repository at this point in the history
…source file
  • Loading branch information
lefessan committed Oct 11, 2023
1 parent c0d64ad commit fc2295c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
5 changes: 5 additions & 0 deletions cobc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

2023-10-11 Fabrice Le Fessant <fabrice.le_fessant@ocamlpro.com>

* cobc.c, pplex.l: new option --copy COPYBOOK, to include a COPYBOOK
before reading the source file

2023-07-26 Simon Sobisch <simonsobisch@gnu.org>

* typeck.c (search_set_keys): improving SEARCH ALL syntax checks
Expand Down
15 changes: 13 additions & 2 deletions cobc/cobc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -3887,6 +3890,14 @@ process_command_line (const int argc, char **argv)
}
break;

case CB_FLAG_COPY_FILE: /* 17 */
/* -copy=<file> : COPY file at beginning */
{
char *file = cobc_strdup (cob_optarg);
CB_TEXT_LIST_ADD (cb_copy_list, file);
break;
}

case 'A':
/* -A <xx> : Add options to C compile phase */
COBC_ADD_STR (cobc_cflags, " ", cob_optarg, NULL);
Expand Down
1 change: 1 addition & 0 deletions cobc/cobc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion cobc/pplex.l
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
33 changes: 33 additions & 0 deletions tests/testsuite.src/syn_copy.at
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fc2295c

Please sign in to comment.