Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cobc/config.def
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,6 @@ CB_CONFIG_SUPPORT (cb_record_contains_depending_clause, "record-contains-dependi

CB_CONFIG_SUPPORT (cb_picture_l, "picture-l",
_("PICTURE string with 'L' character"))

CB_CONFIG_SUPPORT (cb_inspect_or, "inspect-with-or",
_("INSPECT with OR conditions"))
20 changes: 20 additions & 0 deletions cobc/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -15239,15 +15239,35 @@ inspect_before:
{
$$ = CB_BUILD_FUNCALL_1 ("cob_inspect_before", $3);
}
| BEFORE _initial inspect_or_list
{
cb_verify(cb_inspect_or, _("INSPECT or"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that string does not need a translation as both INSPECT and OR reference keywords; you possibly can improve that string in any case

$$ = cb_build_inspect_or_before($3);
}
;

inspect_after:
AFTER _initial x
{
$$ = CB_BUILD_FUNCALL_1 ("cob_inspect_after", $3);
}
| AFTER _initial inspect_or_list
{
cb_verify(cb_inspect_or, _("INSPECT or"));
$$ = cb_build_inspect_or_after($3);
}
;

inspect_or_list:
x OR x
{
$$ = cb_list_add (CB_LIST_INIT ($1), $3);
}
| inspect_or_list OR x
{
$$ = cb_list_add ($1, $3);
}

/* JSON GENERATE statement */

json: JSON { check_non_area_a ($1); };
Expand Down
2 changes: 2 additions & 0 deletions cobc/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -2510,6 +2510,8 @@ extern cb_tree cb_build_replacing_first (cb_tree, cb_tree, cb_tree);
extern cb_tree cb_build_replacing_trailing (cb_tree, cb_tree, cb_tree);
extern cb_tree cb_build_converting (cb_tree, cb_tree, cb_tree);
extern cb_tree cb_build_inspect_region_start (void);
extern cb_tree cb_build_inspect_or_before (cb_tree);
extern cb_tree cb_build_inspect_or_after (cb_tree);

extern int validate_move (cb_tree, cb_tree, const unsigned int, int *);
extern cb_tree cb_build_move (cb_tree, cb_tree);
Expand Down
25 changes: 25 additions & 0 deletions cobc/typeck.c
Original file line number Diff line number Diff line change
Expand Up @@ -10732,6 +10732,31 @@ cb_build_inspect_region_start (void)
return CB_LIST_INIT (CB_BUILD_FUNCALL_0 ("cob_inspect_start"));
}

cb_tree
cb_build_inspect_or_before (cb_tree candidates)
{
cb_tree l = candidates;
cb_tree res = CB_LIST_INIT (CB_BUILD_FUNCALL_1 ("cob_inspect_or_before", CB_VALUE(l)));
for (l = CB_CHAIN (l); l; l = CB_CHAIN(l)) {
res = cb_list_add(res, CB_BUILD_FUNCALL_1 ("cob_inspect_or_before", CB_VALUE(l)));
}

return res;
}

cb_tree
cb_build_inspect_or_after (cb_tree candidates)
{
cb_tree l = candidates;
cb_tree res = CB_LIST_INIT (CB_BUILD_FUNCALL_1 ("cob_inspect_or_after", CB_VALUE(l)));
for (l = CB_CHAIN (l); l; l = CB_CHAIN(l)) {
res = cb_list_add(res, CB_BUILD_FUNCALL_1 ("cob_inspect_or_after", CB_VALUE(l)));
}


return res;
}

/* MOVE statement */

static void
Expand Down
2 changes: 2 additions & 0 deletions libcob/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1948,7 +1948,9 @@ COB_EXPIMP void cob_inspect_init (cob_field *, const cob_u32_t);
COB_EXPIMP void cob_inspect_init_converting (cob_field *);
COB_EXPIMP void cob_inspect_start (void);
COB_EXPIMP void cob_inspect_before (const cob_field *);
COB_EXPIMP void cob_inspect_or_before (const cob_field *);
COB_EXPIMP void cob_inspect_after (const cob_field *);
COB_EXPIMP void cob_inspect_or_after (const cob_field *);
COB_EXPIMP void cob_inspect_characters (cob_field *);
COB_EXPIMP void cob_inspect_all (cob_field *, cob_field *);
COB_EXPIMP void cob_inspect_leading (cob_field *, cob_field *);
Expand Down
20 changes: 20 additions & 0 deletions libcob/strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,16 @@ cob_inspect_before (const cob_field *str)
cob_inspect_before_intern (&share_inspect_state, str);
}

void
cob_inspect_or_before (const cob_field *str) {
unsigned char *end = share_inspect_state.end;
cob_inspect_before_intern (&share_inspect_state, str);
if (end < share_inspect_state.end) {
/* We found two matches, so we choose the first one in the inspected string */
share_inspect_state.end = end;
}
}

static void
cob_inspect_after_intern (struct cob_inspect_state *st, const cob_field *str)
{
Expand All @@ -632,6 +642,16 @@ cob_inspect_after (const cob_field *str)
cob_inspect_after_intern (&share_inspect_state, str);
}

void
cob_inspect_or_after (const cob_field *str) {
unsigned char *start = share_inspect_state.start;
cob_inspect_after_intern (&share_inspect_state, str);
if (share_inspect_state.start > start) {
/* We found two matches, so we choose the first one in the inspected string */
share_inspect_state.start = start;
}
}

static void
cob_inspect_characters_intern (struct cob_inspect_state *st, cob_field *f1)
{
Expand Down