revert between 56095 -> 55830 in arch
[AROS.git] / compiler / alib / getrexxvar.c
blobda2c8ec2de507ab613e12abadf0580bf9169f41d
1 /*
2 Copyright © 1995-2007, 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 CONST_STRPTR 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 struct Library *RexxSysBase = NULL;
60 struct RexxMsg *msg2 = NULL, *msg3;
61 struct MsgPort *port = NULL, *rexxport;
62 LONG retval = ERR10_003;
64 RexxSysBase = OpenLibrary("rexxsyslib.library", 0);
65 if (RexxSysBase==NULL) goto cleanup;
67 if (!IsRexxMsg(msg))
69 retval = ERR10_010;
70 goto cleanup;
73 rexxport = FindPort("REXX");
74 if (rexxport==NULL)
76 retval = ERR10_013;
77 goto cleanup;
80 port = CreateMsgPort();
81 if (port == NULL) goto cleanup;
82 msg2 = CreateRexxMsg(port, NULL, NULL);
83 if (msg2==NULL) goto cleanup;
84 msg2->rm_Private1 = msg->rm_Private1;
85 msg2->rm_Private2 = msg->rm_Private2;
86 msg2->rm_Action = RXGETVAR | 1;
87 msg2->rm_Args[0] = (IPTR)CreateArgstring(varname, strlen(varname));
88 if (msg2->rm_Args[0]==0) goto cleanup;
90 PutMsg(rexxport, (struct Message *)msg2);
91 msg3 = NULL;
92 while (msg3!=msg2)
94 WaitPort(port);
95 msg3 = (struct RexxMsg *)GetMsg(port);
96 if (msg3!=msg2) ReplyMsg((struct Message *)msg3);
99 if (msg3->rm_Result1==RC_OK)
101 *value = (char *)msg3->rm_Result2;
102 retval = RC_OK;
104 else retval = (LONG)msg3->rm_Result2;
106 cleanup:
107 if (msg2!=NULL)
109 if (msg2->rm_Args[0]!=0) DeleteArgstring((UBYTE *)msg2->rm_Args[0]);
110 DeleteRexxMsg(msg2);
112 if (port!=NULL) DeletePort(port);
113 if (RexxSysBase!=NULL) CloseLibrary(RexxSysBase);
115 return retval;
116 } /* SetRexxVar */