Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / libs / locale / locrawdofmt.c
blobfa363d90aabfa2a16f16e708d2f3e8754080bee5
1 /*
2 Copyright © 1995-2008, 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>
20 #ifdef __MORPHOS__
22 /* move.b d0,(a3)+
23 rts
25 #define ARRAY_FUNC 0x16c04e75
27 /* KPutChar
28 MOVE.L A6,-(SP) ;2F0E
29 MOVEA.L (4).L,A6 ;2C7900000004
30 JSR (-$0204,A6) ;4EAEFDFC
31 MOVEA.L (SP)+,A6 ;2C5F
32 RTS ;4E75
35 #define SERIAL_FUNC0 0x2f0e2c79
36 #define SERIAL_FUNC1 0x00000004
37 #define SERIAL_FUNC2 0x4eaefdfc
38 #define SERIAL_FUNC3 0x2c5f4e75
40 struct HookData
42 char *PutChData;
43 ULONG OldA4;
46 /* Quick reg layout function
48 #if 0
49 char *_PPCCallM68k_RawDoFmt(char MyChar,
50 char *(*PutChProc)(char*,char),
51 char *PutChData,
52 ULONG OldA4,
53 struct ExecBase *sysBase);
55 char *PPCCallM68k_RawDoFmt(char MyChar,
56 char *(*PutChProc)(char*,char),
57 char *PutChData,
58 ULONG OldA4,
59 struct ExecBase *sysBase)
61 /* As we call a *QUICK REG LAYOUT* function
62 * below we must make sure that this function backups/restores
63 * all registers
65 asm volatile (""
68 : "r13");
70 return _PPCCallM68k_RawDoFmt(MyChar,
71 PutChProc,
72 PutChData,
73 OldA4,
74 sysBase);
76 #else
77 char *PPCCallM68k_RawDoFmt(char MyChar,
78 char *(*PutChProc)(char*,char),
79 char *PutChData,
80 ULONG OldA4,
81 struct ExecBase *sysBase);
83 /* Shitty workaround for release/cisc - ignores r13 clobber */
85 __asm(".section \".text\"\n\t"
86 ".align 2\n\t"
87 ".globl PPCCallM68k_RawDoFmt\n\t"
88 ".type PPCCallM68k_RawDoFmt, @function\n"
89 "PPCCallM68k_RawDoFmt:\n\t"
90 "stwu 1, -96(1)\n\t"
91 "mflr 0\n\t"
92 "stmw 13, 20(1)\n\t"
93 "stw 0, 100(1)\n\t"
94 "bl _PPCCallM68k_RawDoFmt\n\t"
95 "lwz 0, 100(1)\n\t"
96 "mtlr 0\n\t"
97 "lmw 13, 20(1)\n\t"
98 "la 1, 96(1)\n\t"
99 "blr\n"
100 ".LfeN:\n\t"
101 ".size PPCCallM68k_RawDoFmt, .LfeN - PPCCallM68k_RawDoFmt"
103 #endif
105 #endif
108 AROS_UFH3(VOID, LocRawDoFmtFormatStringFunc,
109 AROS_UFHA(struct Hook *, hook, A0),
110 AROS_UFHA(struct Locale *, locale, A2),
111 AROS_UFHA(char, fill, A1))
113 AROS_USERFUNC_INIT
115 #ifdef __mc68000__
116 register char *pdata asm("a3") = hook->h_Data;
117 #else
118 char *pdata = hook->h_Data;
119 #endif
121 switch ((IPTR)hook->h_SubEntry)
123 case (IPTR)RAWFMTFUNC_STRING:
124 /* Standard Array Function */
125 *pdata++ = fill;
126 break;
127 case (IPTR)RAWFMTFUNC_SERIAL:
128 /* Standard Serial Function */
129 RawPutChar(fill);
130 break;
131 case (IPTR)RAWFMTFUNC_COUNT:
132 /* Standard Count Function */
133 (*((ULONG *)pdata))++;
134 break;
135 default:
136 AROS_UFC3(void, hook->h_SubEntry,
137 AROS_UFCA(char, fill, D0),
138 AROS_UFCA(APTR, pdata, A3),
139 AROS_UFCA(struct ExecBase *, SysBase, A6));
141 hook->h_Data = pdata;
143 AROS_USERFUNC_EXIT
146 #undef LocaleBase
148 /*****************************************************************************
150 NAME */
151 #include <proto/locale.h>
153 AROS_PLH4(APTR, LocRawDoFmt,
155 /* SYNOPSIS */
156 AROS_LHA(CONST_STRPTR, FormatString, A0),
157 AROS_LHA(APTR , DataStream, A1),
158 AROS_LHA(VOID_FUNC , PutChProc, A2),
159 AROS_LHA(APTR , PutChData, A3),
161 /* LOCATION */
162 struct ExecBase *, SysBase, 31, Locale)
164 /* FUNCTION
165 See exec.library/RawDoFmt
167 INPUTS
168 See exec.library/RawDoFmt
170 RESULT
172 NOTES
173 This function is not called by apps directly. Instead dos.library/DosGet-
174 LocalizedString is patched to use this function. This means, that the
175 LocaleBase parameter above actually points to SysBase, so we make use of
176 the global LocaleBase variable. This function is marked as private,
177 thus the headers generator won't mind the different basename in the header.
179 EXAMPLE
181 BUGS
183 SEE ALSO
184 RawDoFmt(), FormatString().
186 INTERNALS
188 HISTORY
189 27-11-96 digulla automatically created from
190 locale_lib.fd and clib/locale_protos.h
192 *****************************************************************************/
194 AROS_LIBFUNC_INIT
196 struct Hook hook;
197 APTR retval;
199 #ifdef __MORPHOS__
200 struct HookData data;
202 if ((ULONG) PutChProc > 1)
204 if (*((ULONG*) PutChProc) == ARRAY_FUNC)
206 PutChProc = 0;
208 #if 0
210 * This is the job of exec
212 else if ((((ULONG*) PutChProc)[0] == SERIAL_FUNC0) &&
213 (((ULONG*) PutChProc)[1] == SERIAL_FUNC1) &&
214 (((ULONG*) PutChProc)[2] == SERIAL_FUNC2) &&
215 (((ULONG*) PutChProc)[3] == SERIAL_FUNC3))
217 PutChProc = (APTR) 1;
219 #endif
222 hook.h_Entry = (HOOKFUNC)AROS_ASMSYMNAME(LocRawDoFmtFormatStringFunc);
223 hook.h_SubEntry = (HOOKFUNC)PutChProc;
224 hook.h_Data = &data;
225 data.PutChData = PutChData;
226 data.OldA4 = REG_A4;
228 #else
230 hook.h_Entry = (HOOKFUNC)AROS_ASMSYMNAME(LocRawDoFmtFormatStringFunc);
231 hook.h_SubEntry = (HOOKFUNC)PutChProc;
232 hook.h_Data = PutChData;
234 #endif
236 //kprintf("LocRawDoFmt: FormatString = \"%s\"\n", FormatString);
238 REPLACEMENT_LOCK;
240 retval = FormatString(&(IntLB(LocaleBase)->lb_CurrentLocale->il_Locale),
241 (STRPTR)FormatString,
242 DataStream,
243 &hook);
245 REPLACEMENT_UNLOCK;
247 //kprintf("LocRawDoFmt: FormatString: returning %x\n", retval);
249 return retval;
251 AROS_LIBFUNC_EXIT
253 } /* LocRawDoFmt */