2 * Copyright (C) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
3 * Helsinki University of Technology, Finland.
5 * Copyright (C) 2005 - 2007 The AROS Dev Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24 #include <sys/param.h>
25 #include <sys/systm.h>
26 #include <sys/malloc.h>
28 #include <kern/amiga_config.h>
29 #include <kern/amiga_includes.h>
30 #include <dos/rdargs.h>
32 #include <rexx/storage.h>
33 #include <rexx/rxslib.h>
35 #include <proto/rexxsyslib.h>
36 #include <proto/utility.h>
37 #include <clib/alib_protos.h>
40 * The rexx port and error name may change, if there is already an
43 #define D_REXX_PORT_NAME "AROSTCP"
44 #define REXX_ERROR_POSTFIX ".LASTERROR"
45 #define D_REXX_ERROR_NAME D_REXX_PORT_NAME REXX_ERROR_POSTFIX
47 UBYTE T_REXX_PORT_NAME
[] = D_REXX_PORT_NAME
;
48 UBYTE
*REXX_PORT_NAME
= T_REXX_PORT_NAME
;
50 UBYTE T_REXX_ERROR_NAME
[] = D_REXX_ERROR_NAME
;
51 UBYTE
*REXX_ERROR_NAME
= T_REXX_ERROR_NAME
;
53 #define REXX_RETURN_ERROR ((struct RexxMsg *)-1L)
55 extern LONG nthLibrary
;
57 #include <kern/amiga_rexx.h>
60 struct Library
*UtilityBase
= NULL
;
61 struct Library
*RexxSysBase
= NULL
;
63 struct UtilityBase
*UtilityBase
= NULL
;
64 struct RxsLib
*RexxSysBase
= NULL
;
67 struct MsgPort
*ARexxPort
= NULL
;
75 bsd_malloc(sizeof(D_REXX_PORT_NAME
) + 3, M_CFGVAR
, M_WAITOK
)) &&
77 bsd_malloc(sizeof(D_REXX_ERROR_NAME
) + 3, M_CFGVAR
, M_WAITOK
)) &&
79 (UtilityBase
= (struct UtilityBase
*)OpenLibrary("utility.library", 37)) &&
80 (RexxSysBase
= (APTR
)OpenLibrary("rexxsyslib.library", 0L))) {
81 ARexxPort
= CreateMsgPort();
84 strcpy(REXX_PORT_NAME
, D_REXX_PORT_NAME
);
85 strcpy(REXX_ERROR_NAME
, D_REXX_PORT_NAME
);
87 REXX_PORT_NAME
[sizeof(D_REXX_PORT_NAME
)-1] = '.';
88 REXX_PORT_NAME
[sizeof(D_REXX_PORT_NAME
)] = '0' + nthLibrary
;
89 REXX_PORT_NAME
[sizeof(D_REXX_PORT_NAME
)+1] = '\0';
90 REXX_ERROR_NAME
[sizeof(D_REXX_PORT_NAME
)-1] = '.';
91 REXX_ERROR_NAME
[sizeof(D_REXX_PORT_NAME
)] = '0' + nthLibrary
;
92 REXX_ERROR_NAME
[sizeof(D_REXX_PORT_NAME
)+1] = '\0';
94 strcat(REXX_ERROR_NAME
, REXX_ERROR_POSTFIX
);
97 ARexxPort
->mp_Node
.ln_Name
= REXX_PORT_NAME
;
98 return (ULONG
)1 << ARexxPort
->mp_SigBit
;
105 static BOOL rexx_shown
= FALSE
;
110 if (!rexx_shown
&& ARexxPort
) {
111 AddPort(ARexxPort
); /* No return value! */
124 * Remove the port from the system's message port list so that the
125 * port cannot be found any more
134 void rexx_deinit(void)
136 struct RexxMsg
*rmsg
;
137 static STRPTR errstr
= "99: Port Closed!";
143 * Reply to all messages received with error code set.
145 while(rmsg
= (struct RexxMsg
*)GetMsg(ARexxPort
)){
146 SetRexxVar(rmsg
, REXX_ERROR_NAME
,
147 errstr
, strlen(errstr
));
148 if (rmsg
!= REXX_RETURN_ERROR
){
149 rmsg
->rm_Result2
= 0;
150 rmsg
->rm_Result1
= 100;
151 ReplyMsg((struct Message
*)rmsg
);
154 DeleteMsgPort(ARexxPort
);
157 CloseLibrary((APTR
)RexxSysBase
);
161 CloseLibrary((APTR
)UtilityBase
);
168 struct RexxMsg
*rmsg
;
170 if ((rmsg
= (struct RexxMsg
*)GetMsg(ARexxPort
))
171 && rmsg
!= REXX_RETURN_ERROR
172 && IsRexxMsg(rmsg
)) {
173 UBYTE rbuf
[REPLYBUFLEN
];
174 struct CSource result
;
175 struct CSource csarg
;
176 UBYTE
*errstr
= NULL
;
179 result
.CS_Buffer
= rbuf
;
180 result
.CS_Length
= REPLYBUFLEN
- 1;
181 result
.CS_CurChr
= 0;
183 csarg
.CS_Buffer
= ARG0(rmsg
);
184 csarg
.CS_Length
= LengthArgstring(ARG0(rmsg
)) + 1;
186 csarg
.CS_Buffer
[csarg
.CS_Length
- 1] = '\n'; /* Sentinel */
188 rmsg
->rm_Result1
= rmsg
->rm_Result2
= 0;
190 if (error
= parseline(&csarg
, &errstr
, &result
)) {
191 SetRexxVar(rmsg
, REXX_ERROR_NAME
,
192 errstr
, (long)strlen(errstr
));
193 rmsg
->rm_Result1
= error
;
195 if (rmsg
->rm_Action
& (1L << RXFB_RESULT
)) {
196 rmsg
->rm_Result2
= (IPTR
)
197 CreateArgstring(result
.CS_Buffer
, (LONG
)strlen(result
.CS_Buffer
));
201 csarg
.CS_Buffer
[csarg
.CS_Length
- 1] = '\0';
203 ReplyMsg((struct Message
*)rmsg
);
205 if (result
.CS_Buffer
!= rbuf
) /* We've allocated memory */
206 bsd_free(result
.CS_Buffer
, M_TEMP
);