revert between 56095 -> 55830 in arch
[AROS.git] / workbench / rexxc / RXLIB.c
blob61cb44585eab50b16413edcb0f7f4c49bdf3236a
1 /*
2 Copyright © 2007-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Manipulate ARexx lib list
6 */
8 #include <rexx/errors.h>
9 #include <rexx/storage.h>
10 #include <rexx/rxslib.h>
12 #include <proto/alib.h>
13 #include <proto/exec.h>
14 #include <proto/dos.h>
15 #include <proto/rexxsyslib.h>
17 static struct RexxMsg *msg = NULL;
18 static struct MsgPort *rexxport = NULL, *replyport = NULL;
19 BPTR out = (BPTR)NULL;
20 static BOOL closeout = FALSE;
22 static BOOL init(void)
24 #ifdef __AROS__
25 out = ErrorOutput();
26 #else
27 out = Output();
28 #endif
30 rexxport = FindPort("REXX");
31 if (rexxport == NULL)
33 FPuts(out, "Could not start RexxMast\n");
34 return FALSE;
37 replyport = CreatePort(NULL, 0);
38 if (replyport == NULL)
40 FPuts(out, "Could not create a port\n");
41 return FALSE;
44 msg = CreateRexxMsg(replyport, NULL, NULL);
45 if (msg == NULL)
47 FPuts(out, "Could not create RexxMsg\n");
48 return FALSE;
51 return TRUE;
54 void cleanup(void)
56 if (closeout)
57 Close(out);
58 if (msg)
59 DeleteRexxMsg(msg);
60 if (replyport)
61 DeletePort(replyport);
64 int main(int argc, char **argv)
66 struct RexxMsg *reply;
67 int ret, i;
68 struct RexxRsrc *rsrc;
70 init();
72 switch (argc)
74 case 0:
75 /* Started from WB */
76 out = Open("CON:////RXLIB Output/CLOSE/WAIT", MODE_READWRITE);
77 closeout = TRUE;
78 Close(SelectOutput(out));
79 /* Fall through */
80 case 1:
81 LockRexxBase(0);
82 ForeachNode(&RexxSysBase->rl_LibList, rsrc)
84 FPrintf(out, "%s (%s)\n", rsrc->rr_Node.ln_Name,
85 rsrc->rr_Node.ln_Type == RRT_LIB ?
86 "library" : "host"
89 UnlockRexxBase(0);
90 cleanup();
91 return RC_OK;
93 case 2:
94 msg->rm_Action = RXREMLIB | 1;
95 msg->rm_Args[0] = (IPTR)argv[1];
96 break;
98 case 3:
99 msg->rm_Action = RXADDFH | 2;
100 msg->rm_Args[0] = (IPTR)argv[1];
101 msg->rm_Args[1] = (IPTR)argv[2];
102 break;
104 case 4:
105 case 5:
106 msg->rm_Action = RXADDLIB | (argc-1);
107 for (i=1; i<argc; i++)
108 msg->rm_Args[i-1] = (IPTR)argv[i];
109 break;
111 default:
112 FPuts(out, "Wrong number of arguments\n");
113 cleanup();
114 return RC_ERROR;
117 if (!FillRexxMsg(msg, msg->rm_Action & RXARGMASK, 0))
119 FPuts(out, "Not enough memory\n");
120 cleanup();
121 return RC_ERROR;
124 PutMsg(rexxport, (struct Message *)msg);
125 do {
126 reply = (struct RexxMsg *)WaitPort(replyport);
127 } while (reply != msg);
129 ret = msg->rm_Result1;
130 ClearRexxMsg(msg, msg->rm_Action & RXARGMASK);
131 cleanup();
133 return ret;