revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / rexxsupport / forbid.c
blobfcf636c69fd8e5f9b741a12a39ff0e53f5376bfa
1 /*
2 Copyright © 1995-2018, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Disable task switching
6 Lang: English
7 */
9 #include <proto/alib.h>
10 #include <proto/exec.h>
11 #include <proto/rexxsyslib.h>
12 #include <exec/types.h>
13 #include <exec/memory.h>
14 #include <rexx/storage.h>
15 #include <rexx/errors.h>
17 #include <ctype.h>
18 #include <stdlib.h>
19 #include <stdio.h>
21 #include "rexxsupport_intern.h"
22 #include "rxfunctions.h"
24 /* If not in forbid state keep the Permit() count in a RexxVar from the script,
25 * when in forbid state use local forbid_nest variable to count the Forbid() nesting
26 * this is to avoid calling SetRexxVar when in forbid state
28 static BOOL inforbid = FALSE;
29 static int forbid_nest = 0;
31 /* maximum size of a string that represents a signed decimal integer */
32 #define REXXVAR_MAXSTR 11
34 LONG rxsupp_forbid(struct Library *RexxSupportBase, struct RexxMsg *msg, UBYTE **argstring)
36 char val[REXXVAR_MAXSTR + 1];
38 if (!inforbid)
40 char *s;
41 int permit_nest;
43 if (GetRexxVar(msg, NEST_VAR, &s) == RC_OK)
44 permit_nest = *(int *)s;
45 else
46 permit_nest = -1;
48 permit_nest++;
49 sprintf(val, "%d", permit_nest);
51 if (permit_nest == 0)
53 Forbid();
54 inforbid = TRUE;
55 forbid_nest = 0;
57 else
58 if (SetRexxVar(msg, NEST_VAR, (char *)&permit_nest, sizeof(int)) != RC_OK)
60 *argstring = NULL;
61 return ERR10_012;
64 else /* inforbid == TRUE */
66 forbid_nest++;
67 sprintf(val, "%d", forbid_nest);
70 *argstring = CreateArgstring(val, strlen(val));
71 return RC_OK;
74 LONG rxsupp_permit(struct Library *RexxSupportBase, struct RexxMsg *msg, UBYTE **argstring)
76 char val[REXXVAR_MAXSTR + 1];
78 if (!inforbid)
80 char *s;
81 int permit_nest;
83 if (GetRexxVar(msg, NEST_VAR, &s) == RC_OK)
84 permit_nest = *(int *)s;
85 else
86 permit_nest = -1;
88 permit_nest--;
89 sprintf(val, "%d", permit_nest);
91 if (SetRexxVar(msg, NEST_VAR, (char *)&permit_nest, sizeof(int)) != RC_OK)
93 *argstring = NULL;
94 return ERR10_012;
97 else /* inforbid == TRUE */
99 forbid_nest--;
100 sprintf(val, "%d", forbid_nest);
102 if (forbid_nest < 0)
104 Permit();
105 inforbid = FALSE;
109 *argstring = CreateArgstring(val, strlen(val));
110 return RC_OK;