- Set a default PCM volume so that something can be heard when driver is
[AROS.git] / compiler / alib / setrexxvar.c
blob98da9236464032b44daff8f4274b44a4c6513374
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 SetRexxVar(
21 /* SYNOPSIS */
22 struct RexxMsg *msg,
23 char *varname,
24 char * value,
25 ULONG length)
27 /* FUNCTION
28 Set a the value of the name rexx variable.
30 INPUTS
31 msg - A rexx message generated from a running rexx script
32 varname - The name of the variable to set the value
33 value - a pointer to the beginning of the value to set
34 length - the length of the value argument
36 RESULT
37 0 when succes, otherwise a rexx error value is returned.
39 NOTES
41 EXAMPLE
43 BUGS
45 SEE ALSO
46 CheckRexxMsg(), GetRexxVar()
48 INTERNALS
49 This function creates a rexx message that is sent to the AREXX
50 port with a RXSETVAR command.
53 *****************************************************************************/
55 struct Library *RexxSysBase = NULL;
56 struct RexxMsg *msg2 = NULL, *msg3;
57 struct MsgPort *port = NULL, *rexxport;
58 LONG retval = ERR10_003;
60 RexxSysBase = OpenLibrary("rexxsyslib.library", 0);
61 if (RexxSysBase==NULL) goto cleanup;
63 if (!IsRexxMsg(msg))
65 retval = ERR10_010;
66 goto cleanup;
69 rexxport = FindPort("REXX");
70 if (rexxport==NULL)
72 retval = ERR10_013;
73 goto cleanup;
76 port = CreateMsgPort();
77 if (port == NULL) goto cleanup;
78 msg2 = CreateRexxMsg(port, NULL, NULL);
79 if (msg2==NULL) goto cleanup;
80 msg2->rm_Private1 = msg->rm_Private1;
81 msg2->rm_Private2 = msg->rm_Private2;
82 msg2->rm_Action = RXSETVAR | 2;
83 msg2->rm_Args[0] = (IPTR)CreateArgstring(varname, strlen(varname));
84 msg2->rm_Args[1] = (IPTR)CreateArgstring(value, length);
85 if (msg2->rm_Args[0]==0 || msg2->rm_Args[1]==0) goto cleanup;
87 PutMsg(rexxport, (struct Message *)msg2);
88 msg3 = NULL;
89 while (msg3!=msg2)
91 WaitPort(port);
92 msg3 = (struct RexxMsg *)GetMsg(port);
93 if (msg3!=msg2) ReplyMsg((struct Message *)msg3);
96 if (msg3->rm_Result1==RC_OK) retval = 0;
97 else retval = (LONG)msg3->rm_Result2;
99 cleanup:
100 if (msg2!=NULL)
102 if (msg2->rm_Args[0]!=0) DeleteArgstring((UBYTE *)msg2->rm_Args[0]);
103 if (msg2->rm_Args[1]!=0) DeleteArgstring((UBYTE *)msg2->rm_Args[1]);
104 DeleteRexxMsg(msg2);
106 if (port!=NULL) DeletePort(port);
107 if (RexxSysBase!=NULL) CloseLibrary(RexxSysBase);
109 return retval;
110 } /* SetRexxVar */