grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / rexxsupport / forbid.c
blob97cfbee543d7ebdc6fdd30d661fb1ad5e54a27fd
1 /*
2 Copyright © 1995-2006, 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 LONG rxsupp_forbid(struct Library *RexxSupportBase, struct RexxMsg *msg, UBYTE **argstring)
33 char val[5];
35 if (!inforbid)
37 char *s;
38 int permit_nest;
40 if (GetRexxVar(msg, NEST_VAR, &s) == RC_OK)
41 permit_nest = *(int *)s;
42 else
43 permit_nest = -1;
45 permit_nest++;
46 snprintf(val, 5, "%d", permit_nest);
48 if (permit_nest == 0)
50 Forbid();
51 inforbid = TRUE;
52 forbid_nest = 0;
54 else
55 if (SetRexxVar(msg, NEST_VAR, (char *)&permit_nest, sizeof(int)) != RC_OK)
57 *argstring = NULL;
58 return ERR10_012;
61 else /* inforbid == TRUE */
63 forbid_nest++;
64 snprintf(val, 5, "%d", forbid_nest);
67 *argstring = CreateArgstring(val, strlen(val));
68 return RC_OK;
71 LONG rxsupp_permit(struct Library *RexxSupportBase, struct RexxMsg *msg, UBYTE **argstring)
73 char val[5];
75 if (!inforbid)
77 char *s;
78 int permit_nest;
80 if (GetRexxVar(msg, NEST_VAR, &s) == RC_OK)
81 permit_nest = *(int *)s;
82 else
83 permit_nest = -1;
85 permit_nest--;
86 snprintf(val, 5, "%d", permit_nest);
88 if (SetRexxVar(msg, NEST_VAR, (char *)&permit_nest, sizeof(int)) != RC_OK)
90 *argstring = NULL;
91 return ERR10_012;
94 else /* inforbid == TRUE */
96 forbid_nest--;
97 snprintf(val, 5, "%d", forbid_nest);
99 if (forbid_nest < 0)
101 Permit();
102 inforbid = FALSE;
106 *argstring = CreateArgstring(val, strlen(val));
107 return RC_OK;