Skip to content

Commit

Permalink
Implement SIGNAL ON FAILURE (#76)
Browse files Browse the repository at this point in the history
* Implement SIGNAL ON FAILURE

* Typo for condition mask.
  • Loading branch information
RossPatterson authored Jun 9, 2024
1 parent 0053c2a commit 94b9beb
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 6 deletions.
10 changes: 7 additions & 3 deletions address.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ RxExecuteCmd(PLstr cmd, PLstr env) {

RxSetSpecialVar(RCVAR,
(context->rexxrxReturnCode)); // set the returncode variable
if (((context->rexxrxReturnCode) < 0) &&
if (((context->rexxrxReturnCode) != 0) &&
!((context->rexx_proc)[(context->rexx_rx_proc)].trace &
off_trace)) { // do the right thing for tracing
if ((context->rexx_proc)[(context->rexx_rx_proc)].trace &
Expand All @@ -299,9 +299,13 @@ RxExecuteCmd(PLstr cmd, PLstr env) {
if ((context->rexx_proc)[(context->rexx_rx_proc)].interactive_trace)
TraceInteractive(FALSE);
}
if ((context->rexx_proc)[(context->rexx_rx_proc)].condition & SC_ERROR)
RxSignalCondition(SC_ERROR);
}
if (((context->rexxrxReturnCode) < 0) &&
((context->rexx_proc)[(context->rexx_rx_proc)].condition & SC_FAILURE))
RxSignalCondition(SC_FAILURE);
if (((context->rexxrxReturnCode) != 0) &&
((context->rexx_proc)[(context->rexx_rx_proc)].condition & SC_ERROR))
RxSignalCondition(SC_ERROR);
#elif defined(__MVS__)
(context->rexxrxReturnCode) = system(LSTR(* cmd));
#else
Expand Down
6 changes: 4 additions & 2 deletions compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,7 @@ C_select(void) {
/* SIGNAL [name] | */
/* [VALUE] expr | */
/* <ON | OFF> + ERROR + [NAME name] ; */
/* | FAILURE | */
/* | HALT | */
/* | NOVALUE | */
/* | NOTREADY | */
Expand All @@ -1628,9 +1629,9 @@ C_select(void) {
/* are terminated. */
/* o VALUE, may be used for an evaluated label name. */
/* o ON|OFF, enable or disable exception traps. CONDITION */
/* must be ERROR, HALT, NOVALUE, NOTREADY or SYNTAX. */
/* must be ERROR, FAILURE, HALT, NOVALUE, NOTREADY or SYNTAX.*/
/* Control passes to the label of the condition name */
/* if the event occurs while ON */
/* if the event occurs while ON. */
/* -------------------------------------------------------------- */
static void
C_signal(void) {
Expand All @@ -1645,6 +1646,7 @@ C_signal(void) {
if (!CMP("ON")) value = 1;
nextsymbol();
if (identCMP("ERROR") ||
identCMP("FAILURE") ||
identCMP("HALT") ||
identCMP("NOVALUE") ||
identCMP("NOTREADY") ||
Expand Down
1 change: 1 addition & 0 deletions context.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ struct Context {
BinLeaf *rexxsiglStr;
BinLeaf *rexxRCStr;
BinLeaf *rexxerrorStr;
BinLeaf *rexxfailureStr;
BinLeaf *rexxhaltStr;
BinLeaf *rexxsyntaxStr;
BinLeaf *rexxsystemStr;
Expand Down
3 changes: 3 additions & 0 deletions error.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ RxSignalCondition(int cnd) {
case SC_ERROR:
cndstr = (context->rexx_proc)[(context->rexx_rx_proc)].lbl_error;
break;
case SC_FAILURE:
cndstr = (context->rexx_proc)[(context->rexx_rx_proc)].lbl_failure;
break;
case SC_HALT:
cndstr = (context->rexx_proc)[(context->rexx_rx_proc)].lbl_halt;
break;
Expand Down
15 changes: 15 additions & 0 deletions interpre.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,17 @@ I_StoreOption(const PLstr value, const int opt) {
(context->rexx_proc)[(context->rexx_rx_proc)]
.lbl_error = &((context->rexxerrorStr)->key);
break;
case 'F':
(context->rexx_proc)[(context->rexx_rx_proc)].condition |=
SC_FAILURE;
if (opt == set_signal_name_opt)
(context->rexx_proc)[(context->rexx_rx_proc)]
.lbl_failure = STACKP(
1);
else
(context->rexx_proc)[(context->rexx_rx_proc)]
.lbl_failure = &((context->rexxfailureStr)->key);
break;
case 'H':
(context->rexx_proc)[(context->rexx_rx_proc)].condition |=
SC_HALT;
Expand Down Expand Up @@ -426,6 +437,10 @@ I_StoreOption(const PLstr value, const int opt) {
(context->rexx_proc)[(context->rexx_rx_proc)].condition &=
~SC_ERROR;
break;
case 'F':
(context->rexx_proc)[(context->rexx_rx_proc)].condition &=
~SC_FAILURE;
break;
case 'H':
(context->rexx_proc)[(context->rexx_rx_proc)].condition &=
~SC_HALT;
Expand Down
3 changes: 2 additions & 1 deletion rexx.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ RxInitialize(char *prorgram_name) {
(context->rexxzeroStr) = _Add2Lits(&str, FALSE);
Lscpy(&str, "ERROR");
(context->rexxerrorStr) = _Add2Lits(&str, FALSE);

Lscpy(&str, "FAILURE");
(context->rexxfailureStr) = _Add2Lits(&str, FALSE);
Lscpy(&str, "RESULT");
(context->rexxresultStr) = _Add2Lits(&str, FALSE);
Lscpy(&str, "NOVALUE");
Expand Down
2 changes: 2 additions & 0 deletions rexx.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
#define SC_NOVALUE 0x04
#define SC_NOTREADY 0x08
#define SC_SYNTAX 0x10
#define SC_FAILURE 0x20

/* long jmp values */
#define JMP_CONTINUE 2
Expand Down Expand Up @@ -174,6 +175,7 @@ struct trxproc {
int form; /* numeric form */
int condition; /* signal on condition */
PLstr lbl_error; /* labels */
PLstr lbl_failure; /* */
PLstr lbl_halt; /* */
PLstr lbl_novalue; /* */
PLstr lbl_notready; /* */
Expand Down

0 comments on commit 94b9beb

Please sign in to comment.