Don't call ReadArgs() if started from WB.
[tangerine.git] / compiler / alib / getrexxvar.c
blob873a02d0df1aef399158b593ed6b0e098d0c11f4
1 /*
2 Copyright © 1995-2002, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
8 #include <proto/alib.h>
9 #include <proto/exec.h>
10 #include <proto/rexxsyslib.h>
11 #include <rexx/storage.h>
12 #include <rexx/errors.h>
14 #include <string.h>
16 /*****************************************************************************
18 NAME */
19 LONG GetRexxVar(
21 /* SYNOPSIS */
22 struct RexxMsg *msg,
23 char *varname,
24 char **value)
26 /* FUNCTION
27 Get a the value of the name rexx variable.
29 INPUTS
30 msg - A rexx message generated from a running rexx script
31 varname - The name of the variable to get the value from
32 value - a pointer to a string pointer that will be filled with
33 a pointer to the value of the variable. This value
34 not be changed. On AROS this pointer will also be an
35 argstring so you can get the length with LengthArgstring.
36 length - the length of the value argument
38 RESULT
39 0 when succes, otherwise a rexx error value is returned.
41 NOTES
42 On AROS the pointer returned in value is only valid until the next
43 getrexxvar call on the same running script.
45 EXAMPLE
47 BUGS
49 SEE ALSO
50 CheckRexxMsg, GetRexxVar
52 INTERNALS
53 This function creates a rexx message that is sent to the AREXX
54 port with a RXSETVAR command.
57 *****************************************************************************/
59 AROS_GET_SYSBASE_OK
60 struct Library *RexxSysBase = NULL;
61 struct RexxMsg *msg2 = NULL, *msg3;
62 struct MsgPort *port = NULL, *rexxport;
63 LONG retval = ERR10_003;
65 RexxSysBase = OpenLibrary("rexxsyslib.library", 0);
66 if (RexxSysBase==NULL) goto cleanup;
68 if (!IsRexxMsg(msg))
70 retval = ERR10_010;
71 goto cleanup;
74 rexxport = FindPort("REXX");
75 if (rexxport==NULL)
77 retval = ERR10_013;
78 goto cleanup;
81 port = CreateMsgPort();
82 if (port == NULL) goto cleanup;
83 msg2 = CreateRexxMsg(port, NULL, NULL);
84 if (msg2==NULL) goto cleanup;
85 msg2->rm_Private1 = msg->rm_Private1;
86 msg2->rm_Private2 = msg->rm_Private2;
87 msg2->rm_Action = RXGETVAR | 1;
88 msg2->rm_Args[0] = (IPTR)CreateArgstring(varname, strlen(varname));
89 if (msg2->rm_Args[0]==NULL) goto cleanup;
91 PutMsg(rexxport, (struct Message *)msg2);
92 msg3 = NULL;
93 while (msg3!=msg2)
95 WaitPort(port);
96 msg3 = (struct RexxMsg *)GetMsg(port);
97 if (msg3!=msg2) ReplyMsg((struct Message *)msg3);
100 if (msg3->rm_Result1==RC_OK)
102 *value = (char *)msg3->rm_Result2;
103 retval = RC_OK;
105 else retval = (LONG)msg3->rm_Result2;
107 cleanup:
108 if (msg2!=NULL)
110 if (msg2->rm_Args[0]!=NULL) DeleteArgstring((UBYTE *)msg2->rm_Args[0]);
111 DeleteRexxMsg(msg2);
113 if (port!=NULL) DeletePort(port);
114 if (RexxSysBase!=NULL) CloseLibrary(RexxSysBase);
116 return retval;
117 } /* SetRexxVar */