Make sure Locale dirs exsit before copying icons to them.
[cake.git] / rom / workbench / support.c
blob1e2d80b0e410d398dd082604cb6adf6944a23bdc
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
5 Miscellanous support functions.
6 */
8 #define DEBUG 1
9 #include <aros/debug.h>
11 #include <aros/atomic.h>
12 #include <dos/dostags.h>
13 #include <string.h>
15 #include "workbench_intern.h"
16 #include "support.h"
18 void __AddHiddenDevice(STRPTR name, struct WorkbenchBase *WorkbenchBase)
20 /* Make sure we got valid pointers... */
21 if ((name == NULL) || (WorkbenchBase == NULL))
23 D(bug("Workbench/AddHiddenDevice: Got NULL pointers!\n"));
24 return;
27 /* Only add the device name if it isn't already the list. */
28 if (FindName(&(WorkbenchBase->wb_HiddenDevices), name ) == NULL)
30 struct Node *deviceName;
32 if ((deviceName = AllocMem(sizeof(struct Node), MEMF_ANY | MEMF_CLEAR )))
34 deviceName->ln_Name = name;
35 AddTail(&(WorkbenchBase->wb_HiddenDevices), deviceName);
37 /* FIXME: Notify WB App. Not here though. (We might want to use this
38 * onn startup for adding all hidden devices that was set in prefs,
39 * then unneccesery to notify app at each addition... */
44 void __RemoveHiddenDevice(STRPTR name, struct WorkbenchBase *WorkbenchBase)
46 struct Node *deviceName;
48 /* Make sure we got valid pointers... */
49 if ((name == NULL) || (WorkbenchBase == NULL))
51 D(bug("Workbench/RemoveHiddenDevice: Got NULL pointers!\n"));
52 return;
55 if ((deviceName = FindName(&(WorkbenchBase->wb_HiddenDevices), name)))
57 Remove(deviceName);
58 FreeVec(deviceName);
60 /* TODO: Notify WB App. Maybe not here...*/
64 STRPTR __AllocateNameFromLock(BPTR lock, struct WorkbenchBase *WorkbenchBase)
66 ULONG length = 512;
67 STRPTR buffer = NULL;
68 BOOL done = FALSE;
70 while (!done)
72 if (buffer != NULL) FreeVec(buffer);
74 buffer = AllocVec(length, MEMF_ANY);
75 if (buffer != NULL)
77 if (NameFromLock(lock, buffer, length))
79 done = TRUE;
80 break;
82 else
84 if (IoErr() == ERROR_LINE_TOO_LONG)
86 length += 512;
87 continue;
89 else
91 break;
95 else
97 SetIoErr(ERROR_NO_FREE_STORE);
98 break;
102 if (done)
104 return buffer;
106 else
108 if (buffer != NULL) FreeVec(buffer);
109 return NULL;
113 STRPTR __StrDup(CONST_STRPTR str, struct WorkbenchBase *WorkbenchBase)
115 STRPTR dup;
116 ULONG len;
118 if (str == NULL) return NULL;
120 len = strlen(str);
121 dup = AllocVec(len + 1, MEMF_PUBLIC);
122 if (dup != NULL) CopyMem(str, dup, len + 1);
124 return dup;
127 BPTR __DuplicateSearchPath(BPTR list, struct WorkbenchBase *WorkbenchBase)
129 BPTR *paths, *current = NULL, *previous = NULL, first = NULL;
133 paths = (BPTR *) BADDR(list);
134 paths != NULL;
135 paths = (BPTR *) BADDR(paths[0]) /* next path */
138 if ((current = (BPTR *) AllocVec(2 * sizeof(BPTR), MEMF_ANY)) != NULL)
140 current[0] = NULL;
141 current[1] = DupLock(paths[1]);
143 if (previous != NULL) previous[0] = (BPTR) MKBADDR(current);
144 else first = (BPTR) MKBADDR(current);
146 previous = current;
148 else
150 break;
154 return first;
157 VOID __FreeSearchPath(BPTR list, struct WorkbenchBase *WorkbenchBase)
159 BPTR *current = BADDR(list);
161 while (current != NULL)
163 BPTR *next = (BPTR *) BADDR(current[0]);
165 UnLock(current[1]);
166 FreeVec(current);
168 current = next;