grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / rexxsupport / showlist.c
blobad64fa05ca7a618b03a9dbc182df5d94779f1599
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 LONG rxsupp_showlist(struct Library *RexxSupportBase, struct RexxMsg *msg, UBYTE **argstring)
31 UBYTE argc = msg->rm_Action & RXARGMASK;
32 BOOL isexec;
33 char delim = 0;
34 struct List *execl = NULL;
35 ULONG dosflags = 0L;
36 UBYTE *string, *name = NULL;
37 ULONG ssize;
39 if (RXARG(msg, 1) == NULL || LengthArgstring(RXARG(msg, 1)) == 0)
41 *argstring = NULL;
42 return ERR10_018;
44 switch (tolower(RXARG(msg, 1)[0]))
46 case 'a':
47 isexec = FALSE;
48 dosflags = LDF_READ | LDF_ASSIGNS;
49 break;
51 case 'd':
52 isexec = TRUE;
53 execl = &SysBase->DeviceList;
54 break;
56 case 'h':
57 isexec = FALSE;
58 dosflags = LDF_READ | LDF_DEVICES;
59 break;
61 case 'i':
62 isexec = TRUE;
63 execl = &SysBase->IntrList;
64 break;
66 case 'l':
67 isexec = TRUE;
68 execl = &SysBase->LibList;
69 break;
71 case 'm':
72 isexec = TRUE;
73 execl= &SysBase->MemList;
74 break;
76 case 'p':
77 isexec = TRUE;
78 execl = &SysBase->PortList;
79 break;
81 case 'r':
82 isexec = TRUE;
83 execl = &SysBase->ResourceList;
84 break;
86 case 's':
87 isexec = TRUE;
88 execl = &SysBase->SemaphoreList;
89 break;
91 case 't':
92 isexec = TRUE;
93 execl = &SysBase->TaskReady;
94 break;
96 case 'v':
97 isexec = FALSE;
98 dosflags = LDF_READ | LDF_VOLUMES;
99 break;
101 case 'w':
102 isexec = TRUE;
103 execl = &SysBase->TaskWait;
104 break;
106 default:
107 *argstring = NULL;
108 return ERR10_018;
111 if (argc < 2 || RXARG(msg, 2) == NULL)
112 name = NULL;
113 else
114 name = RXARG(msg, 2);
116 if (argc < 3 || RXARG(msg, 3) == NULL || LengthArgstring(RXARG(msg, 3)) == 0)
117 delim = ' ';
118 else
119 delim = RXARG(msg, 3)[0];
121 if (name == NULL)
123 ssize = 1024;
124 string = AllocMem(ssize, MEMF_ANY);
125 string[0] = 0;
126 if (isexec)
128 struct Node *n;
129 ULONG slen, totlen;
131 Forbid();
132 ForeachNode(execl, n)
134 slen = strlen(string);
135 totlen = slen + strlen(n->ln_Name) + 2;
136 if (totlen > ssize)
138 ULONG oldsize = ssize;
139 UBYTE *oldstring = string;
141 ssize = ((totlen/1024)+1)*1024;
142 string = AllocMem(ssize, MEMF_ANY);
143 strcpy(string, oldstring);
144 FreeMem(oldstring, oldsize);
146 if (slen > 0)
148 string[slen] = delim;
149 string[slen+1] = 0;
151 strcat(string, n->ln_Name);
153 Enable();
155 else
157 struct DosList *dosl = LockDosList(dosflags);
158 UBYTE *name;
159 ULONG slen, totlen;
161 while ((dosl = NextDosEntry(dosl, dosflags)) != NULL)
163 name = (STRPTR)AROS_BSTR_ADDR(dosl->dol_Name);
164 slen = strlen(string);
165 totlen = slen + strlen(name) + 2;
166 if (totlen > ssize)
168 ULONG oldsize = ssize;
169 UBYTE *oldstring = string;
171 ssize = ((totlen/1024)+1)*1024;
172 string = AllocMem(ssize, MEMF_ANY);
173 strcpy(string, oldstring);
174 FreeMem(oldstring, oldsize);
176 if (slen > 0)
178 string[slen] = delim;
179 string[slen+1] = 0;
181 strncat(string, name, *(UBYTE *)dosl->dol_Name);
183 UnLockDosList(dosflags);
185 *argstring = CreateArgstring(string, strlen(string));
186 FreeMem(string, ssize);
188 else /* name != NULL */
190 BOOL found = FALSE;
192 if (isexec)
194 struct Node *n;
196 Forbid();
197 ForeachNode(execl, n)
199 found = strcmp(name, n->ln_Name)==0;
200 if (found)
201 break;
203 Enable();
205 else
207 struct DosList *dosl = LockDosList(dosflags);
209 while(!found && (dosl = NextDosEntry(dosl, dosflags))!=NULL)
210 found = strncmp(name, (STRPTR)BADDR(dosl->dol_Name)+1, *(UBYTE *)dosl->dol_Name)==0;
212 UnLockDosList(dosflags);
214 if (found)
215 *argstring = CreateArgstring("1",1);
216 else
217 *argstring = CreateArgstring("0",1);
220 return RC_OK;