grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / system / Wanderer / portable_utils.c
blobc9155bcc1b04643dad95fa611da5fb330a5609ce
1 #include "portable_macros.h"
3 #include <stdio.h>
4 #include <string.h>
5 #include <time.h>
7 #include <proto/exec.h>
8 #include <proto/utility.h>
10 #include <proto/graphics.h>
11 #include <proto/datatypes.h>
12 #include <proto/dos.h>
13 #include <proto/icon.h>
14 #include <proto/locale.h>
15 #include <proto/layers.h>
16 #include <proto/diskfont.h>
17 #include <proto/asl.h>
18 #include <proto/keymap.h>
19 #include <proto/iffparse.h>
20 #include <exec/memory.h>
21 #include <graphics/rastport.h>
22 #include <intuition/pointerclass.h>
24 #if defined(__AMIGA__) && !defined(__PPC__)
25 #define NO_INLINE_STDARG
26 #endif
27 #include <proto/intuition.h>
28 #include <proto/muimaster.h>
30 #ifndef __AROS__
31 #define DEBUG 1
33 #ifdef DEBUG
34 #define D(x) if (DEBUG) x
35 #ifdef __amigaos4__
36 #define bug DebugPrintF
37 #else
38 #define bug kprintf
39 #endif
40 #else
41 #define D(...)
42 #endif
43 #endif
46 #ifndef __MORPHOS__
47 Object * VARARGS68K DoSuperNew(struct IClass *cl, Object *obj, ...)
49 Object *rc;
50 VA_LIST args;
52 VA_START(args, obj);
54 rc = (Object *)DoSuperMethod(cl, obj, OM_NEW, VA_ARG(args, IPTR), NULL);
56 VA_END(args);
58 return rc;
60 #endif
62 Object *VARARGS68K DoSuperNewTags(struct IClass *cl, Object *obj, void *dummy, ...)
64 Object *rc;
65 VA_LIST argptr;
67 VA_START(argptr, dummy);
69 rc = (Object*)DoSuperMethod(cl,obj,OM_NEW,VA_ARG(argptr, IPTR),dummy);
71 VA_END(argptr);
73 return rc;
76 STRPTR StrDup (CONST_STRPTR str)
78 STRPTR dup;
79 ULONG len;
81 if (str == NULL) return NULL;
83 len = strlen(str);
84 dup = AllocVec(len + 1, MEMF_PUBLIC);
85 if (dup != NULL) CopyMem(str, dup, len + 1);
87 return dup;
89 } /* StrDup */
92 struct RastPort *CreateRastPort(void)
94 struct RastPort *newrp = AllocMem(sizeof(*newrp), MEMF_PUBLIC);
96 if (newrp)
98 InitRastPort(newrp);
101 return newrp;
104 struct RastPort *CloneRastPort(struct RastPort *rp)
106 struct RastPort *newrp = NULL;
108 if (rp)
110 newrp = AllocMem(sizeof(*newrp), MEMF_PUBLIC);
111 if (newrp)
113 // *newrp = *rp;
115 memcpy(newrp,rp,sizeof(struct RastPort));
119 return newrp;
122 void FreeRastPort(struct RastPort *rp)
124 FreeMem(rp, sizeof(*rp));
128 BOOL AndRectRect(struct Rectangle *rect1, struct Rectangle *rect2, struct Rectangle *intersect)
130 if (!(((LONG)rect1 > 1024) && TypeOfMem((APTR)rect1)))
131 D(bug("\x07, %ld: bad pointer: %s = $%lx\n", __LINE__, rect1, (APTR)(rect1)) );
133 if (!(((LONG)(rect2) > 1024) && TypeOfMem((APTR)(rect2))))
134 D(bug("\x07, %ld: bad pointer: %s = $%lx\n", __LINE__, rect2, (APTR)(rect2)) );
136 if (!((((APTR)(intersect)) == NULL) || (((LONG)(intersect) > 1024) && TypeOfMem((APTR)(intersect)))))
137 D(bug("\x07:%ld: bad pointer: %s = $%lx\n", __LINE__, intersect, (APTR)(intersect)));
139 if (intersect)
140 return _AndRectRect(rect1, rect2, intersect);
141 else
142 return overlap(*rect1, *rect2);
144 } /* AndRectRect */
146 #if defined(__AMIGA__) && !defined(__PPC__)
147 APTR AllocVecPooled(APTR pool, ULONG size)
150 IPTR *memory;
152 if (pool == NULL) return NULL;
154 size += sizeof(IPTR);
155 memory = AllocPooled(pool, size);
157 if (memory != NULL)
159 *memory++ = size;
162 return memory;
163 } /* AllocVecPooled() */
166 void FreeVecPooled(APTR pool, APTR memory)
168 if (memory != NULL)
170 IPTR *real = (IPTR *) memory;
171 IPTR size = *--real;
173 FreePooled(pool, real, size);
175 } /* FreeVecPooled() */
176 #endif