Experiment:
[AROS-Contrib.git] / bgui / strformat.c
blob2e024b4fb5a918db8a6d04f1e8effdcc06a6ea9f
1 /*
2 * @(#) $Header$
4 * BGUI library
5 * strformat.c -- Locale/exec style formatting.
7 * (C) Copyright 1998 Manuel Lemos.
8 * (C) Copyright 1996-1997 Ian J. Einman.
9 * (C) Copyright 1993-1996 Jaba Development.
10 * (C) Copyright 1993-1996 Jan van den Baard.
11 * All Rights Reserved.
13 * $Log$
14 * Revision 42.7 2004/06/16 20:16:48 verhaegs
15 * Use METHODPROTO, METHOD_END and REGFUNCPROTOn where needed.
17 * Revision 42.6 2003/01/18 19:10:01 chodorowski
18 * Instead of using the _AROS or __AROS preprocessor symbols, use __AROS__.
20 * Revision 42.5 2000/08/08 20:57:26 chodorowski
21 * Minor fixes to build on Amiga.
23 * Revision 42.4 2000/08/08 14:11:55 chodorowski
24 * Fixes to make BGUI compile on Amiga. Most notably this file defined
25 * it's own sprintf() which clashed quite severely with the one in clib.
26 * Does anyone know why this was done this way? The one in clib uses
27 * (I think) it's own routines, while the one in this file uses SprintfA()
28 * which in it's turn uses RawDoFmt() from exec.library. Are there any
29 * big differences how they handle formatting of strings?
30 * Anyway, it's disabled now, and everything seems to work...
32 * Revision 42.3 2000/07/03 21:21:00 bergers
33 * Replaced stch_l & stcu_d and had to make a few changes in other places because of that.
35 * Revision 42.2 2000/05/29 00:40:24 bergers
36 * Update to compile with AROS now. Should also still compile with SASC etc since I only made changes that test the define __AROS__. The compilation is still very noisy but it does the trick for the main directory. Maybe members of the BGUI team should also have a look at the compiler warnings because some could also cause problems on other systems... (Comparison always TRUE due to datatype (or something like that)). And please compile it on an Amiga to see whether it still works... Thanks.
38 * Revision 42.1 2000/05/14 23:32:48 stegerg
39 * changed over 200 function headers which all use register
40 * parameters (oh boy ...), because the simple REG() macro
41 * doesn't work with AROS. And there are still hundreds
42 * of headers left to be fixed :(
44 * Many of these functions would also work with stack
45 * params, but since i have fixed every single one
46 * I encountered up to now, I guess will have to do
47 * the same for the rest.
49 * Revision 42.0 2000/05/09 22:10:21 mlemos
50 * Bumped to revision 42.0 before handing BGUI to AROS team
52 * Revision 41.11 2000/05/09 19:55:13 mlemos
53 * Merged with the branch Manuel_Lemos_fixes.
55 * Revision 41.10.2.1 1998/10/12 01:29:58 mlemos
56 * Made the tprintf function divert the debug output to the serial port via
57 * kprintf whenever the Tap program port is not available.
58 * Made the tprintf code only compile when bgui.library is compiled for
59 * debugging.
61 * Revision 41.10 1998/02/25 21:13:13 mlemos
62 * Bumping to 41.10
64 * Revision 1.1 1998/02/25 17:09:51 mlemos
65 * Ian sources
70 #include "include/classdefs.h"
72 extern struct LocaleBase *LocaleBase;
75 //makeproto ASM ULONG CompStrlenF(REG(a0) UBYTE *fstring, REG(a1) ULONG *args)
76 makeproto ASM REGFUNC2(ULONG, CompStrlenF,
77 REGPARAM(A0, UBYTE *, fstring),
78 REGPARAM(A1, ULONG *, args))
80 struct Hook hook = { NULL, NULL, (HOOKFUNC)LHook_Count, NULL, (APTR)0 };
81 struct Locale *loc;
84 * Locale available?
86 if (LocaleBase && (loc = OpenLocale(NULL)))
89 * Count the formatted length.
91 FormatString(loc, fstring, (APTR)args, &hook);
94 * Kill locale.
96 CloseLocale(loc);
98 return (ULONG)hook.h_Data;
100 return StrLenfA(fstring, args);
102 REGFUNC_END
104 //makeproto ASM VOID DoSPrintF(REG(a0) UBYTE *buffer, REG(a1) UBYTE *fstring, REG(a2) ULONG *args)
105 makeproto ASM REGFUNC3(VOID, DoSPrintF,
106 REGPARAM(A0, UBYTE *, buffer),
107 REGPARAM(A1, UBYTE *, fstring),
108 REGPARAM(A2, ULONG *, args))
110 struct Hook hook = { NULL, NULL, (HOOKFUNC)LHook_Format, NULL, NULL };
111 struct Locale *loc;
114 * Locale available?
116 if (LocaleBase && (loc = OpenLocale(NULL)))
119 * Init hook structure.
121 hook.h_Data = (APTR)buffer;
124 * Format...
126 FormatString(loc, fstring, (APTR)args, &hook);
129 * Kill locale.
131 CloseLocale(loc);
133 else
134 SPrintfA(buffer, fstring, args);
136 REGFUNC_END
138 #ifdef __AROS__
139 #else
140 //makeproto void sprintf(char *buffer, const char *format, ...)
142 // SPrintfA(buffer, format, (ULONG *)&format + 1);
144 #endif
146 extern __stdargs VOID KPutFmt( STRPTR format, ULONG *values);
148 makeproto void tprintf(char *format, ...)
150 #ifdef DEBUG_BGUI
151 char *buffer;
152 struct Message *msg;
153 struct MsgPort *tap;
154 int len;
156 Forbid();
157 if ((tap = FindPort("Tap")))
159 if (buffer = AllocVec(4096, 0))
161 SPrintfA(buffer, format, (ULONG *)&format + 1);
163 len = strlen(buffer) + sizeof(struct Message) + 1;
164 if (msg = AllocVec(len, MEMF_CLEAR))
166 msg->mn_Length = len;
167 strcpy((char *)msg + sizeof(struct Message), buffer);
168 PutMsg(tap, msg);
170 FreeVec(buffer);
173 else
174 KPutFmt(format,(ULONG *)&format + 1);
175 Permit();
176 #endif