use new platform macros to access scheduling/per-cpu flags. fix execsmp wait()
[AROS.git] / workbench / tools / HDToolBox / hdtoolbox_support.c
blob4c06d85f9c17d301f0bd26b45bd3e91d1f19ca31
1 /*
2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/alib.h>
7 #include <proto/exec.h>
8 #include <proto/gadtools.h>
9 #include <proto/intuition.h>
11 #include <intuition/intuition.h>
12 #include <libraries/gadtools.h>
14 #include <ctype.h>
15 #include <stdio.h>
16 #include <stdlib.h>
18 #include "debug.h"
20 #define HDTB_HAVE_VARARGPROTOS
21 #include "hdtoolbox_support.h"
22 #include "platform.h"
24 struct Node *getNumNode(struct List *list, int num)
26 struct Node *node;
28 D(bug("[HDToolBox] getNumNode()\n"));
30 node = list->lh_Head;
31 while ((num) && (node->ln_Succ))
33 node = node->ln_Succ;
34 num--;
36 return node->ln_Succ ? node : 0;
39 ULONG getNodeNum(struct Node *node)
41 ULONG num = 0;
43 D(bug("[HDToolBox] getNodeNum()\n"));
45 for (;;)
47 node = node->ln_Pred;
48 if (node->ln_Pred == 0)
49 return num;
50 num++;
54 ULONG countNodes(struct List *list, UBYTE type)
56 ULONG count = 0;
57 struct Node *node;
59 D(bug("[HDToolBox] countNodes()\n"));
61 node = list->lh_Head;
62 while (node->ln_Succ)
64 if ((type == (UBYTE)-1) || (node->ln_Type == type))
65 count++;
66 node = node->ln_Succ;
68 return count;
71 void typestrncpy(STRPTR dst, STRPTR src, ULONG len)
73 while (len)
75 if (isprint(*src))
76 *dst++ = *src++;
77 else
79 *dst++ = '\\';
80 sprintf(dst,"%o", *src++);
81 while (*dst)
82 dst++;
84 len--;
88 UWORD strcpyESC(STRPTR dst, STRPTR fmt)
90 UWORD count = 0;
92 while (*fmt)
94 if (*fmt == '\\')
96 fmt++;
97 if (isdigit(*fmt))
99 ULONG val=0;
101 for(;;)
103 val += (*fmt-'0');
104 fmt++;
105 if (!isdigit(*fmt))
106 break;
107 val *= 8;
109 *dst++ = (UBYTE)val;
110 count++;
112 else
114 D(bug("[HDToolBox] strcpyESC:%s-%ld: unknown escape sequence\n", __FILE__, __LINE__));
117 else
119 *dst++ = *fmt++;
120 count++;
123 return count;
126 /* size in kB */
127 void getSizeStr(STRPTR str, ULONG size)
129 UBYTE c = 'M';
130 ULONG r;
132 r = size % 1024;
133 size = size / 1024;
134 if (size > 512)
136 c='G';
137 r = size % 1024;
138 size = size / 1024;
140 r = r*10/1024;
141 sprintf(str, "%d.%d%c",(int)size,(int)r,c);
144 /* size in kB */
145 ULONG sizeStrToUL(STRPTR str)
147 char *end;
148 ULONG size;
149 ULONG value = 0;
150 ULONG div;
152 size = strtoul(str, &end, 0);
153 if (*end == '.')
155 value = strtoul(end+1, &end, 0);
157 if (*end == 'M')
159 size *= 1024;
160 div = 1024;
162 else if (*end == 'G')
164 size *= 1024*1024;
165 div = 1024*1024;
167 else
169 /* assume bytes */
170 value = 0;
171 div = 0;
172 size /= 1024; /* we want it in kB */
174 if (div)
176 ULONG d=1;
179 d *= 10;
180 } while ((value/d)>=1);
181 value *= div;
182 value /= d;
184 size += value;
185 return size;
188 LONG GetPartitionAttrsA(struct PartitionHandle *ph, IPTR tag, ... )
190 #ifdef __AROS__
191 AROS_SLOWSTACKTAGS_PRE(tag)
192 retval = GetPartitionAttrs(ph, AROS_SLOWSTACKTAGS_ARG(tag));
193 AROS_SLOWSTACKTAGS_POST
194 #else
195 return GetPartitionAttrs(ph, (struct TagItem *)&tag);
196 #endif
199 LONG SetPartitionAttrsA(struct PartitionHandle *ph, IPTR tag, ... )
201 #ifdef __AROS__
202 AROS_SLOWSTACKTAGS_PRE(tag)
203 retval = SetPartitionAttrs(ph, AROS_SLOWSTACKTAGS_ARG(tag));
204 AROS_SLOWSTACKTAGS_POST
205 #else
206 return SetPartitionAttrs(ph, (struct TagItem *)&tag);
207 #endif
210 LONG GetPartitionTableAttrsA(struct PartitionHandle *ph, IPTR tag, ... )
212 #ifdef __AROS__
213 AROS_SLOWSTACKTAGS_PRE(tag)
214 retval = GetPartitionTableAttrs(ph, AROS_SLOWSTACKTAGS_ARG(tag));
215 AROS_SLOWSTACKTAGS_POST
216 #else
217 return GetPartitionTableAttrs(ph, (struct TagItem *)&tag);
218 #endif
221 ULONG getAttrInfo(const struct PartitionAttribute *attrlist, ULONG attr)
223 D(bug("[HDToolBox] getAttrInfo()\n"));
225 while (attrlist[0].attribute != PTA_DONE)
227 if (attrlist[0].attribute == attr)
228 return attrlist[0].mode;
229 attrlist++;
231 return 0;
234 UBYTE getBitNum(ULONG val)
236 UBYTE count = 0;
238 if (val==0)
239 return 0xFF;
241 for (;;)
243 val >>= 1;
244 if (val==0)
245 break;
246 count++;
248 return count;