add casts to zune macros to silence some warnings
[tangerine.git] / workbench / system / Wanderer / Tools / Delete / main.c
blob79e6f04b264006798b4222977f45dbf4fdce4835
1 /*
2 Copyright © 2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
8 #define DEBUG 1
9 #include <aros/debug.h>
11 #include <proto/intuition.h>
12 #include <proto/exec.h>
13 #include <proto/muimaster.h>
14 #include <proto/workbench.h>
15 #include <proto/dos.h>
17 #include <dos/dos.h>
18 #include <libraries/asl.h>
19 #include <libraries/mui.h>
20 #include <workbench/workbench.h>
21 #include <workbench/startup.h>
23 #include <string.h>
25 #include "locale.h"
27 STRPTR AllocateNameFromLock(BPTR lock);
29 int main(int argc, char **argv)
31 int result = RETURN_OK;
33 if (argc == 0)
35 struct WBStartup *startup = (struct WBStartup *) argv;
37 if (startup->sm_NumArgs == 2)
39 BPTR parent = startup->sm_ArgList[1].wa_Lock;
40 STRPTR name = startup->sm_ArgList[1].wa_Name;
44 MUI_Request
46 NULL, NULL, 0,
47 _(MSG_DELETE_REQUEST), _(MSG_DELETE_CHOICE),
48 _(MSG_REQUEST), (IPTR) name
49 ) == 1
52 BPTR cd = CurrentDir(parent);
53 BPTR lock = Lock(name, ACCESS_WRITE);
55 if (lock != NULL)
57 STRPTR buffer = AllocateNameFromLock(lock);
59 UnLock(lock);
61 if (buffer != NULL)
63 if (DeleteFile(name))
65 UpdateWorkbenchObject(buffer, WBPROJECT, TAG_DONE);
67 else
69 MUI_Request
71 NULL, NULL, 0,
72 _(MSG_ERROR), _(MSG_OK),
73 _(MSG_COULDNT_DELETE)
77 FreeVec(buffer);
79 else
81 MUI_Request
83 NULL, NULL, 0,
84 _(MSG_ERROR), _(MSG_OK),
85 _(MSG_COULDNT_ALLOCATE)
89 else
91 MUI_Request
93 NULL, NULL, 0,
94 _(MSG_ERROR), _(MSG_OK),
95 _(MSG_COULDNT_LOCK)
99 CurrentDir(cd);
102 else if (startup->sm_NumArgs > 2)
104 ULONG i;
106 for (i = 1; i < startup->sm_NumArgs; i++)
108 OpenWorkbenchObject
110 "WANDERER:Tools/Delete",
111 WBOPENA_ArgLock, (IPTR) startup->sm_ArgList[i].wa_Lock,
112 WBOPENA_ArgName, (IPTR) startup->sm_ArgList[i].wa_Name,
113 TAG_DONE
117 else
119 MUI_RequestA
121 NULL, NULL, 0,
122 _(MSG_INFO), _(MSG_OK), _(MSG_WRONG_ARGS), NULL
124 result = RETURN_ERROR;
127 else
129 PutStr(_(MSG_WB_ONLY));
130 result = RETURN_FAIL;
132 return result;
135 STRPTR AllocateNameFromLock(BPTR lock)
137 ULONG length = 512;
138 STRPTR buffer = NULL;
139 BOOL done = FALSE;
141 while (!done)
143 if (buffer != NULL) FreeVec(buffer);
145 buffer = AllocVec(length, MEMF_ANY);
146 if (buffer != NULL)
148 if (NameFromLock(lock, buffer, length))
150 done = TRUE;
151 break;
153 else
155 if (IoErr() == ERROR_LINE_TOO_LONG)
157 length += 512;
158 continue;
160 else
162 break;
166 else
168 SetIoErr(ERROR_NO_FREE_STORE);
169 break;
173 if (done)
175 return buffer;
177 else
179 if (buffer != NULL) FreeVec(buffer);
180 return NULL;