Bringing ChocolateCaste-0.7 into the main branch.
[AROS-Contrib.git] / bgui / strformat.c
blob1a4111179e450f0d9d61c9b9c32ea257d399a8b6
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) IPTR *args)
77 struct Hook hook = { { NULL, NULL}, (HOOKFUNC)LHook_Count, NULL, (APTR)0 };
78 struct Locale *loc;
81 * Locale available?
83 if (LocaleBase && (loc = OpenLocale(NULL)))
86 * Count the formatted length.
88 FormatString(loc, fstring, (APTR)args, &hook);
91 * Kill locale.
93 CloseLocale(loc);
95 return (ULONG)(hook.h_Data - NULL);
97 return StrLenfA(fstring, args);
100 makeproto ASM VOID DoSPrintF(REG(a0) UBYTE *buffer, REG(a1) UBYTE *fstring, REG(a2) IPTR *args)
102 struct Hook hook = { {NULL, NULL}, (HOOKFUNC)LHook_Format, NULL, NULL };
103 struct Locale *loc;
106 * Locale available?
108 if (LocaleBase && (loc = OpenLocale(NULL)))
111 * Init hook structure.
113 hook.h_Data = (APTR)buffer;
116 * Format...
118 FormatString(loc, fstring, (APTR)args, &hook);
121 * Kill locale.
123 CloseLocale(loc);
125 else
126 SPrintfA(buffer, fstring, args);
129 #ifdef __AROS__
130 #else
131 //makeproto void sprintf(char *buffer, const char *format, ...)
133 // SPrintfA(buffer, format, (ULONG *)&format + 1);
135 #endif
137 extern __stdargs VOID KPutFmt( STRPTR format, ULONG *values);
139 makeproto void tprintf(char *format, ...)
141 #ifdef DEBUG_BGUI
142 char *buffer;
143 struct Message *msg;
144 struct MsgPort *tap;
145 int len;
147 Forbid();
148 if ((tap = FindPort("Tap")))
150 if (buffer = AllocVec(4096, 0))
152 SPrintfA(buffer, format, (ULONG *)&format + 1);
154 len = strlen(buffer) + sizeof(struct Message) + 1;
155 if (msg = AllocVec(len, MEMF_CLEAR))
157 msg->mn_Length = len;
158 strcpy((char *)msg + sizeof(struct Message), buffer);
159 PutMsg(tap, msg);
161 FreeVec(buffer);
164 else
165 KPutFmt(format,(ULONG *)&format + 1);
166 Permit();
167 #endif