Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / muimaster / support_amigaos.c
blob76b2c380901391c061b0ffe7ad878200a951f673
1 #include <stdarg.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <stdarg.h>
6 #include <clib/alib_protos.h>
7 #include <proto/exec.h>
8 #include <proto/intuition.h>
9 #include <proto/utility.h>
11 #include "support_amigaos.h"
13 /***************************************************************************/
15 #ifndef __amigaos4__
17 /************************************************************
18 Like AllocVec() but for pools
19 *************************************************************/
20 APTR AllocVecPooled(APTR pool, ULONG size)
22 IPTR *memory;
24 if (pool == NULL) return NULL;
26 size += sizeof(IPTR);
27 memory = AllocPooled(pool, size);
29 if (memory != NULL)
31 *memory++ = size;
34 return memory;
37 /************************************************************
38 Like FreeVec() but for pools
39 *************************************************************/
40 VOID FreeVecPooled(APTR pool, APTR memory)
42 if (memory != NULL)
44 IPTR *real = (IPTR *) memory;
45 IPTR size = *--real;
47 FreePooled(pool, real, size);
51 struct snprintf_msg
53 int size;
54 char *buf;
57 /************************************************************
58 Snprintf function for RawDoFmt()
59 *************************************************************/
60 __asm void snprintf_func(register __d0 UBYTE chr, register __a3 struct snprintf_msg *msg)
62 if (msg->size)
64 *msg->buf++ = chr;
65 msg->size--;
69 /************************************************************
70 Snprintf via RawDoFmt()
71 *************************************************************/
72 int snprintf(char *buf, int size, const char *fmt, ...)
74 struct snprintf_msg msg;
75 if (!size) return 0;
77 msg.size = size;
78 msg.buf = buf;
80 RawDoFmt(fmt, (((ULONG *)&fmt)+1), snprintf_func, &msg);
82 buf[size-1] = 0;
84 return (int)strlen(buf);
87 /************************************************************
88 sprintf via RawDoFmt()
89 *************************************************************/
90 int sprintf(char *buf, const char *fmt, ...)
92 static const ULONG cpy_func = 0x16c04e75; /* move.b d0,(a3)+ ; rts */
93 RawDoFmt(fmt, (((ULONG *)&fmt)+1), (void(*)())&cpy_func, buf);
94 return (int)strlen(buf);
97 Object *VARARGS68K DoSuperNewTags(struct IClass *cl, Object *obj, void *dummy, ...)
99 va_list argptr;
100 va_start(argptr,dummy);
101 obj = DoSuperNewTagList(cl,obj,dummy,(struct TagItem*)argptr);
102 va_end(argptr);
103 return obj;
106 #else
109 ASM ULONG HookEntry(REG(a0, struct Hook *hook),REG(a2, APTR obj), REG(a1, APTR msg))
111 return hook->h_SubEntry(hook,obj,msg);
114 Object *VARARGS68K DoSuperNewTags(struct IClass *cl, Object *obj, void *dummy, ...)
116 va_list argptr;
117 struct TagItem *tagList;
119 va_startlinear(argptr, dummy);
120 tagList = va_getlinearva(argptr, struct TagItem *);
121 obj = DoSuperNewTagList(cl,obj,dummy,tagList);
122 va_end(argptr);
123 return obj;
126 int VARARGS68K SPrintf(char *buf, const char *fmt, ...)
128 va_list argptr;
129 APTR args;
131 va_startlinear(argptr, fmt);
132 args = va_getlinearva(argptr, APTR);
133 RawDoFmt((STRPTR)fmt, args, NULL, buf);
134 va_end(argptr);
136 return (int)strlen(buf);
140 #endif
142 /***************************************************************************/
144 char *StrDup(const char *x)
146 char *dup;
147 if (!x) return NULL;
148 dup = AllocVec(strlen(x) + 1, MEMF_PUBLIC);
149 if (dup) CopyMem((char*)x, dup, strlen(x) + 1);
150 return dup;
153 Object *DoSuperNewTagList(struct IClass *cl, Object *obj,void *dummy, struct TagItem *tags)
155 return (Object*)DoSuperMethod(cl,obj,OM_NEW,tags,NULL);
158 size_t strlcat(char *buf, const char *src, size_t len)
160 int l = strlen(buf);
161 buf += l;
162 len -= l;
164 if (len>0)
166 int i;
167 for (i=0; i < len - 1 && *src; i++)
168 *buf++ = *src++;
169 *buf = 0;
171 return 0; /* Actually don't know right rt here */