Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / rexxsupport / showdir.c
blob19b97ac9e8d056ecfd7a942feb7484fb1613566d
1 /*
2 Copyright © 1995-2006, 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/exall.h>
15 #include <rexx/storage.h>
16 #include <rexx/errors.h>
18 #include <ctype.h>
19 #include <string.h>
21 #include "rexxsupport_intern.h"
22 #include "rxfunctions.h"
24 LONG rxsupp_showdir(struct Library *RexxSupportBase, struct RexxMsg *msg, UBYTE **argstring)
26 UBYTE argc = msg->rm_Action & RXARGMASK;
27 UBYTE type = 0; /* 0 == all, 1 == file, 2 == dir */
28 char delim = 0;
29 BPTR lock;
30 UBYTE *string;
31 ULONG ssize;
32 struct ExAllData *buffer, *exalldata;
33 struct ExAllControl *exallctrl;
34 BOOL done;
36 switch (argc)
38 case 1:
39 type = 0;
40 delim = ' ';
41 break;
43 case 3:
44 if (RXARG(msg,3) == NULL || LengthArgstring(RXARG(msg,3)) != 0)
45 delim = RXARG(msg,3)[0];
46 case 2:
47 if (RXARG(msg,2) == NULL || LengthArgstring(RXARG(msg,2)) == 0)
48 type = 0;
49 else
50 switch (tolower(RXARG(msg,2)[0]))
52 case 'a':
53 type = 0;
54 break;
56 case 'f':
57 type = 1;
58 break;
60 case 'd':
61 type = 2;
62 break;
64 default:
65 *argstring = NULL;
66 return ERR10_018;
68 if (delim == 0)
69 delim = ' ';
70 break;
73 lock = Lock(RXARG(msg,1), ACCESS_READ);
74 if (lock == NULL)
76 *argstring = CreateArgstring("", 0);
77 return RC_OK;
79 else
81 struct FileInfoBlock *fib = AllocDosObject(DOS_FIB, NULL);
82 if (fib == NULL)
84 *argstring = NULL;
85 return ERR10_003;
87 Examine(lock, fib);
88 if (fib->fib_DirEntryType<0)
90 FreeDosObject(DOS_FIB, fib);
91 *argstring = CreateArgstring("", 0);
92 return RC_OK;
94 FreeDosObject(DOS_FIB, fib);
97 buffer = AllocMem(1024, MEMF_ANY);
98 ssize = 1024;
99 string = AllocMem(ssize, MEMF_ANY);
100 string[0] = 0;
101 exallctrl = AllocDosObject(DOS_EXALLCONTROL, NULL);
102 exallctrl->eac_LastKey = 0;
103 do {
104 done = ExAll(lock, buffer, 1024, ED_TYPE, exallctrl);
105 if (exallctrl->eac_Entries>0)
107 exalldata = (struct ExAllData *)buffer;
108 while (exalldata != NULL)
110 if (type == 0 ||
111 (type == 1 && exalldata->ed_Type < 0) ||
112 (type == 2 && exalldata->ed_Type >= 0))
114 ULONG newlen = strlen(string) + strlen(exalldata->ed_Name) + 2, len = strlen(string);
115 if (newlen > ssize)
117 UBYTE *oldstring = string;
118 ULONG oldsize = ssize;
119 ssize = ((newlen/1024)+1)*1024;
120 string = AllocMem(ssize, MEMF_ANY);
121 strcpy(string, oldstring);
122 FreeMem(oldstring, oldsize);
124 if (len>0)
126 string[len] = delim;
127 string[len+1] = 0;
129 strcat(string, exalldata->ed_Name);
131 exalldata = exalldata->ed_Next;
134 } while(!done);
136 *argstring = CreateArgstring(string, strlen(string));
137 FreeMem(buffer, 1024);
138 FreeMem(string, ssize);
139 FreeDosObject(DOS_EXALLCONTROL, exallctrl);
140 return RC_OK;