tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / workbench / network / stacks / AROSTCP / bsdsocket / kern / amiga_rexx.c
blob18e2289bf8ce63adfcc1fc5c5d03a579fbfbebdd
1 /*
2 * Copyright (C) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
3 * Helsinki University of Technology, Finland.
4 * All rights reserved.
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,
19 * MA 02111-1307, USA.
23 #include <conf.h>
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
41 * TCP/IP task running
42 */
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>
59 #ifdef __MORPHOS__
60 struct Library *UtilityBase = NULL;
61 struct Library *RexxSysBase = NULL;
62 #else
63 struct UtilityBase *UtilityBase = NULL;
64 struct RxsLib *RexxSysBase = NULL;
65 #endif
67 struct MsgPort *ARexxPort = NULL;
69 ULONG
70 rexx_init(void)
72 if (
73 #ifdef DEBUG
74 (REXX_PORT_NAME =
75 bsd_malloc(sizeof(D_REXX_PORT_NAME) + 3, M_CFGVAR, M_WAITOK)) &&
76 (REXX_ERROR_NAME =
77 bsd_malloc(sizeof(D_REXX_ERROR_NAME) + 3, M_CFGVAR, M_WAITOK)) &&
78 #endif
79 (UtilityBase = (struct UtilityBase *)OpenLibrary("utility.library", 37)) &&
80 (RexxSysBase = (APTR)OpenLibrary("rexxsyslib.library", 0L))) {
81 ARexxPort = CreateMsgPort();
82 if (ARexxPort) {
83 #ifdef DEBUG
84 strcpy(REXX_PORT_NAME, D_REXX_PORT_NAME);
85 strcpy(REXX_ERROR_NAME, D_REXX_PORT_NAME);
86 if (nthLibrary) {
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);
95 #endif
97 ARexxPort->mp_Node.ln_Name = REXX_PORT_NAME;
98 return (ULONG)1 << ARexxPort->mp_SigBit;
101 rexx_deinit();
102 return (0);
105 static BOOL rexx_shown = FALSE;
107 BOOL
108 rexx_show(void)
110 if (!rexx_shown && ARexxPort) {
111 AddPort(ARexxPort); /* No return value! */
112 rexx_shown = TRUE;
113 return TRUE;
115 return FALSE;
118 BOOL
119 rexx_hide(void)
121 if (rexx_shown) {
122 if (ARexxPort) {
124 * Remove the port from the system's message port list so that the
125 * port cannot be found any more
127 RemPort(ARexxPort);
129 rexx_shown = FALSE;
131 return TRUE;
134 void rexx_deinit(void)
136 struct RexxMsg *rmsg;
137 static STRPTR errstr = "99: Port Closed!";
139 if (RexxSysBase) {
140 if (ARexxPort) {
141 rexx_hide();
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);
155 ARexxPort = NULL;
157 CloseLibrary((APTR)RexxSysBase);
158 RexxSysBase = NULL;
160 if (UtilityBase) {
161 CloseLibrary((APTR)UtilityBase);
162 UtilityBase = NULL;
166 BOOL rexx_poll(void)
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;
177 LONG error = 0;
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;
185 csarg.CS_CurChr = 0;
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;
194 } else {
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);
208 return TRUE;
210 return FALSE;