disable debug
[AROS.git] / workbench / libs / rexxsupport / showlist.c
blob751e4e0c42b424cfbe03138a5b8543ab47abab28
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Rexx stub for AllocMem system function
6 Lang: English
7 */
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>
14 #include <dos/dos.h>
15 #include <dos/dosextens.h>
16 #include <rexx/storage.h>
17 #include <rexx/errors.h>
19 #include <ctype.h>
20 #include <string.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)
27 #endif
29 #if defined(__AROSPLATFORM_SMP__)
30 #include <aros/types/spinlock_s.h>
31 #include <proto/execlock.h>
32 #include <resources/execlock.h>
33 #endif
35 LONG rxsupp_showlist(struct Library *RexxSupportBase, struct RexxMsg *msg, UBYTE **argstring)
37 UBYTE argc = msg->rm_Action & RXARGMASK;
38 BOOL isexec;
39 char delim = 0;
40 struct List *execl = NULL;
41 ULONG dosflags = 0L;
42 UBYTE *string, *name = NULL;
43 ULONG ssize;
45 #if defined(__AROSPLATFORM_SMP__)
46 void *ExecLockBase = OpenResource("execlock.resource");
47 #endif
49 if (RXARG(msg, 1) == NULL || LengthArgstring(RXARG(msg, 1)) == 0)
51 *argstring = NULL;
52 return ERR10_018;
54 switch (tolower(RXARG(msg, 1)[0]))
56 case 'a':
57 isexec = FALSE;
58 dosflags = LDF_READ | LDF_ASSIGNS;
59 break;
61 case 'd':
62 isexec = TRUE;
63 execl = &SysBase->DeviceList;
64 break;
66 case 'h':
67 isexec = FALSE;
68 dosflags = LDF_READ | LDF_DEVICES;
69 break;
71 case 'i':
72 isexec = TRUE;
73 execl = &SysBase->IntrList;
74 break;
76 case 'l':
77 isexec = TRUE;
78 execl = &SysBase->LibList;
79 break;
81 case 'm':
82 isexec = TRUE;
83 execl= &SysBase->MemList;
84 break;
86 case 'p':
87 isexec = TRUE;
88 execl = &SysBase->PortList;
89 break;
91 case 'r':
92 isexec = TRUE;
93 execl = &SysBase->ResourceList;
94 break;
96 case 's':
97 isexec = TRUE;
98 execl = &SysBase->SemaphoreList;
99 break;
101 case 't':
102 isexec = TRUE;
103 execl = &SysBase->TaskReady;
104 break;
106 case 'v':
107 isexec = FALSE;
108 dosflags = LDF_READ | LDF_VOLUMES;
109 break;
111 case 'w':
112 isexec = TRUE;
113 execl = &SysBase->TaskWait;
114 break;
116 default:
117 *argstring = NULL;
118 return ERR10_018;
121 if (argc < 2 || RXARG(msg, 2) == NULL)
122 name = NULL;
123 else
124 name = RXARG(msg, 2);
126 if (argc < 3 || RXARG(msg, 3) == NULL || LengthArgstring(RXARG(msg, 3)) == 0)
127 delim = ' ';
128 else
129 delim = RXARG(msg, 3)[0];
131 if (name == NULL)
133 ssize = 1024;
134 string = AllocMem(ssize, MEMF_ANY);
135 string[0] = 0;
136 if (isexec)
138 struct Node *n;
139 ULONG slen, totlen;
141 #if defined(__AROSPLATFORM_SMP__)
142 if (ExecLockBase)
143 ObtainSystemLock(execl, SPINLOCK_MODE_READ, LOCKF_DISABLE);
144 else
145 Disable();
146 #else
147 Disable();
148 #endif
149 ForeachNode(execl, n)
151 slen = strlen(string);
152 totlen = slen + strlen(n->ln_Name) + 2;
153 if (totlen > ssize)
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);
163 if (slen > 0)
165 string[slen] = delim;
166 string[slen+1] = 0;
168 strcat(string, n->ln_Name);
170 #if defined(__AROSPLATFORM_SMP__)
171 if (ExecLockBase)
172 ReleaseSystemLock(execl, LOCKF_DISABLE);
173 else
174 Enable();
175 #else
176 Enable();
177 #endif
179 else
181 struct DosList *dosl = LockDosList(dosflags);
182 UBYTE *name;
183 ULONG slen, totlen;
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;
190 if (totlen > ssize)
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);
200 if (slen > 0)
202 string[slen] = delim;
203 string[slen+1] = 0;
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 */
214 BOOL found = FALSE;
216 if (isexec)
218 struct Node *n;
220 #if defined(__AROSPLATFORM_SMP__)
221 if (ExecLockBase)
222 ObtainSystemLock(execl, SPINLOCK_MODE_READ, LOCKF_DISABLE);
223 else
224 Disable();
225 #else
226 Disable();
227 #endif
228 ForeachNode(execl, n)
230 found = strcmp(name, n->ln_Name)==0;
231 if (found)
232 break;
234 #if defined(__AROSPLATFORM_SMP__)
235 if (ExecLockBase)
236 ReleaseSystemLock(execl, LOCKF_DISABLE);
237 else
238 Enable();
239 #else
240 Enable();
241 #endif
243 else
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);
252 if (found)
253 *argstring = CreateArgstring("1",1);
254 else
255 *argstring = CreateArgstring("0",1);
258 return RC_OK;