2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: Rexx stub for AllocMem system function
9 #include <proto/exec.h>
10 #include <proto/dos.h>
11 #include <proto/rexxsyslib.h>
12 #include <exec/types.h>
13 #include <exec/memory.h>
15 #include <dos/dosextens.h>
16 #include <rexx/storage.h>
17 #include <rexx/errors.h>
22 #include "rexxsupport_intern.h"
23 #include "rxfunctions.h"
25 #ifndef AROS_BSTR_ADDR
26 # define AROS_BSTR_ADDR(s) (((STRPTR)BADDR(s))+1)
29 #if defined(__AROSPLATFORM_SMP__)
30 #include <aros/types/spinlock_s.h>
31 #include <proto/execlock.h>
32 #include <resources/execlock.h>
35 LONG
rxsupp_showlist(struct Library
*RexxSupportBase
, struct RexxMsg
*msg
, UBYTE
**argstring
)
37 UBYTE argc
= msg
->rm_Action
& RXARGMASK
;
40 struct List
*execl
= NULL
;
42 UBYTE
*string
, *name
= NULL
;
45 #if defined(__AROSPLATFORM_SMP__)
46 void *ExecLockBase
= OpenResource("execlock.resource");
49 if (RXARG(msg
, 1) == NULL
|| LengthArgstring(RXARG(msg
, 1)) == 0)
54 switch (tolower(RXARG(msg
, 1)[0]))
58 dosflags
= LDF_READ
| LDF_ASSIGNS
;
63 execl
= &SysBase
->DeviceList
;
68 dosflags
= LDF_READ
| LDF_DEVICES
;
73 execl
= &SysBase
->IntrList
;
78 execl
= &SysBase
->LibList
;
83 execl
= &SysBase
->MemList
;
88 execl
= &SysBase
->PortList
;
93 execl
= &SysBase
->ResourceList
;
98 execl
= &SysBase
->SemaphoreList
;
103 execl
= &SysBase
->TaskReady
;
108 dosflags
= LDF_READ
| LDF_VOLUMES
;
113 execl
= &SysBase
->TaskWait
;
121 if (argc
< 2 || RXARG(msg
, 2) == NULL
)
124 name
= RXARG(msg
, 2);
126 if (argc
< 3 || RXARG(msg
, 3) == NULL
|| LengthArgstring(RXARG(msg
, 3)) == 0)
129 delim
= RXARG(msg
, 3)[0];
134 string
= AllocMem(ssize
, MEMF_ANY
);
141 #if defined(__AROSPLATFORM_SMP__)
143 ObtainSystemLock(execl
, SPINLOCK_MODE_READ
, LOCKF_DISABLE
);
149 ForeachNode(execl
, n
)
151 slen
= strlen(string
);
152 totlen
= slen
+ strlen(n
->ln_Name
) + 2;
155 ULONG oldsize
= ssize
;
156 UBYTE
*oldstring
= string
;
158 ssize
= ((totlen
/1024)+1)*1024;
159 string
= AllocMem(ssize
, MEMF_ANY
);
160 strcpy(string
, oldstring
);
161 FreeMem(oldstring
, oldsize
);
165 string
[slen
] = delim
;
168 strcat(string
, n
->ln_Name
);
170 #if defined(__AROSPLATFORM_SMP__)
172 ReleaseSystemLock(execl
, LOCKF_DISABLE
);
181 struct DosList
*dosl
= LockDosList(dosflags
);
185 while ((dosl
= NextDosEntry(dosl
, dosflags
)) != NULL
)
187 name
= (STRPTR
)AROS_BSTR_ADDR(dosl
->dol_Name
);
188 slen
= strlen(string
);
189 totlen
= slen
+ strlen(name
) + 2;
192 ULONG oldsize
= ssize
;
193 UBYTE
*oldstring
= string
;
195 ssize
= ((totlen
/1024)+1)*1024;
196 string
= AllocMem(ssize
, MEMF_ANY
);
197 strcpy(string
, oldstring
);
198 FreeMem(oldstring
, oldsize
);
202 string
[slen
] = delim
;
205 strncat(string
, name
, *(UBYTE
*)dosl
->dol_Name
);
207 UnLockDosList(dosflags
);
209 *argstring
= CreateArgstring(string
, strlen(string
));
210 FreeMem(string
, ssize
);
212 else /* name != NULL */
220 #if defined(__AROSPLATFORM_SMP__)
222 ObtainSystemLock(execl
, SPINLOCK_MODE_READ
, LOCKF_DISABLE
);
228 ForeachNode(execl
, n
)
230 found
= strcmp(name
, n
->ln_Name
)==0;
234 #if defined(__AROSPLATFORM_SMP__)
236 ReleaseSystemLock(execl
, LOCKF_DISABLE
);
245 struct DosList
*dosl
= LockDosList(dosflags
);
247 while(!found
&& (dosl
= NextDosEntry(dosl
, dosflags
))!=NULL
)
248 found
= strncmp(name
, (STRPTR
)BADDR(dosl
->dol_Name
)+1, *(UBYTE
*)dosl
->dol_Name
)==0;
250 UnLockDosList(dosflags
);
253 *argstring
= CreateArgstring("1",1);
255 *argstring
= CreateArgstring("0",1);