locale.library: adjust types in code to RAWARG changes
[AROS.git] / workbench / libs / locale / locrawdofmt.c
blobefab63d2eeea937935485c2171ce3f0db05a3ba8
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Locale_RawDoFmt - locale.library's private replacement
6 of exec.library/RawDoFmt function. IPrefs will install
7 the patch.
9 Lang: english
12 #include <exec/rawfmt.h>
13 #include <exec/types.h>
14 #include <proto/exec.h>
15 #include <proto/locale.h>
16 #include "locale_intern.h"
17 #include <aros/asmcall.h>
18 #include <stdarg.h>
19 #include <alloca.h>
21 #include <clib/alib_protos.h>
23 AROS_UFH3(VOID, LocRawDoFmtFormatStringFunc,
24 AROS_UFHA(struct Hook *, hook, A0),
25 AROS_UFHA(struct Locale *, locale, A2),
26 AROS_UFHA(char, fill, A1))
28 AROS_USERFUNC_INIT
30 #ifdef __mc68000__
31 register char *pdata asm("a3") = hook->h_Data;
32 #else
33 char *pdata = hook->h_Data;
34 #endif
36 switch ((IPTR) hook->h_SubEntry)
38 case (IPTR) RAWFMTFUNC_STRING:
39 /* Standard Array Function */
40 *pdata++ = fill;
41 break;
42 case (IPTR) RAWFMTFUNC_SERIAL:
43 /* Standard Serial Function */
44 RawPutChar(fill);
45 break;
46 case (IPTR) RAWFMTFUNC_COUNT:
47 /* Standard Count Function */
48 (*((ULONG *) pdata))++;
49 break;
50 default:
51 AROS_UFC3NR(void, hook->h_SubEntry,
52 AROS_UFCA(char, fill, D0),
53 AROS_UFCA(APTR, pdata, A3),
54 AROS_UFCA(struct ExecBase *, SysBase, A6));
56 hook->h_Data = pdata;
58 AROS_USERFUNC_EXIT
61 AROS_UFH3(VOID, LocRawDoFmtFormatStringFunc_SysV,
62 AROS_UFHA(struct Hook *, hook, A0),
63 AROS_UFHA(struct Locale *, locale, A2), AROS_UFHA(char, fill, A1))
65 AROS_USERFUNC_INIT
67 APTR(*proc) (APTR, UBYTE) = (APTR) hook->h_SubEntry;
68 char *pdata = hook->h_Data;
70 switch ((IPTR) hook->h_SubEntry)
72 case (IPTR) RAWFMTFUNC_STRING:
73 /* Standard Array Function */
74 *pdata++ = fill;
75 break;
77 case (IPTR) RAWFMTFUNC_SERIAL:
78 /* Standard Serial Function */
79 RawPutChar(fill);
80 break;
82 case (IPTR) RAWFMTFUNC_COUNT:
83 /* Standard Count Function */
84 (*((ULONG *) pdata))++;
85 break;
87 default:
88 pdata = proc(pdata, fill);
90 hook->h_Data = pdata;
92 AROS_USERFUNC_EXIT
95 #undef LocaleBase
97 /*****************************************************************************
99 NAME */
100 #include <proto/locale.h>
102 AROS_PLH4(APTR, LocRawDoFmt,
104 /* SYNOPSIS */
105 AROS_LHA(CONST_STRPTR, FormatString, A0),
106 AROS_LHA(RAWARG , DataStream, A1),
107 AROS_LHA(VOID_FUNC , PutChProc, A2),
108 AROS_LHA(APTR , PutChData, A3),
110 /* LOCATION */
111 struct ExecBase *, SysBase, 31, Locale)
113 /* FUNCTION
114 See exec.library/RawDoFmt
116 INPUTS
117 See exec.library/RawDoFmt
119 RESULT
121 NOTES
122 This function is not called by apps directly. Instead dos.library/DosGet-
123 LocalizedString is patched to use this function. This means, that the
124 LocaleBase parameter above actually points to SysBase, so we make use of
125 the global LocaleBase variable. This function is marked as private,
126 thus the headers generator won't mind the different basename in the header.
128 EXAMPLE
130 BUGS
132 SEE ALSO
133 RawDoFmt(), FormatString().
135 INTERNALS
137 *****************************************************************************/
139 AROS_LIBFUNC_INIT
141 struct Hook hook;
142 APTR retval;
144 hook.h_Entry = (HOOKFUNC) AROS_ASMSYMNAME(LocRawDoFmtFormatStringFunc);
145 hook.h_SubEntry = (HOOKFUNC) PutChProc;
146 hook.h_Data = PutChData;
148 //kprintf("LocRawDoFmt: FormatString = \"%s\"\n", FormatString);
150 REPLACEMENT_LOCK;
152 retval = FormatString(&(IntLB(LocaleBase)->lb_CurrentLocale->il_Locale),
153 (STRPTR) FormatString, DataStream, &hook);
155 REPLACEMENT_UNLOCK;
157 //kprintf("LocRawDoFmt: FormatString: returning %x\n", retval);
159 return retval;
161 AROS_LIBFUNC_EXIT
165 /*****************************************************************************
167 NAME */
168 #include <proto/locale.h>
170 AROS_PLH4(APTR, LocVNewRawDoFmt,
172 /* SYNOPSIS */
173 AROS_LHA(CONST_STRPTR, FormatString, A0),
174 AROS_LHA(VOID_FUNC , PutChProc, A2),
175 AROS_LHA(APTR , PutChData, A3),
176 AROS_LHA(va_list , DataStream, A1),
178 /* LOCATION */
179 struct ExecBase *, SysBase, 39, Locale)
181 /* FUNCTION
182 See exec.library/VNewRawDoFmt
184 INPUTS
185 See exec.library/VNewRawDoFmt
187 RESULT
189 NOTES
190 This function is not called by apps directly. Instead exec.library/VNewRawDoFmt
191 is patched to use this function. This means, that the library base parameter above
192 actually points to SysBase, so we make use of the global LocaleBase variable.
193 This function is marked as private, thus the headers generator won't mind the
194 different basename in the header.
196 EXAMPLE
198 BUGS
200 SEE ALSO
201 RawDoFmt(), FormatString().
203 INTERNALS
205 *****************************************************************************/
208 AROS_LIBFUNC_INIT
210 struct Hook hook;
211 ULONG *iStream;
212 APTR dStream;
213 ULONG iSize = 0, dSize = 0;
214 #if defined(__arm__) || defined(__x86_64__)
215 va_list nullarg = {};
216 #else
217 va_list nullarg = 0;
218 #endif
220 /* Scan to determine the location of the positional arguments */
221 GetDataStreamFromFormat(FormatString, nullarg, NULL, NULL,
222 NULL, &iSize);
223 iStream = alloca(iSize);
225 /* Scan to determine the size of the repacked datastream */
226 GetDataStreamFromFormat(FormatString, nullarg, NULL, &dSize,
227 iStream, &iSize);
228 dStream = alloca(dSize);
230 /* Repack the va_list into the datastream */
231 GetDataStreamFromFormat(FormatString, DataStream, dStream, &dSize,
232 iStream, &iSize);
234 hook.h_Entry =
235 (HOOKFUNC) AROS_ASMSYMNAME(LocRawDoFmtFormatStringFunc_SysV);
236 hook.h_SubEntry = (HOOKFUNC) PutChProc;
237 hook.h_Data = PutChData;
239 REPLACEMENT_LOCK;
241 InternalFormatString(&(IntLB(LocaleBase)->lb_CurrentLocale->il_Locale),
242 (STRPTR) FormatString, dStream, iStream, &hook);
244 REPLACEMENT_UNLOCK;
246 return hook.h_Data;
248 AROS_LIBFUNC_EXIT