2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 Desc: Format a string and emit it.
9 #include <aros/libcall.h>
10 #include <aros/asmcall.h>
11 #include <proto/exec.h>
16 #include "exec_intern.h"
17 #include "exec_util.h"
19 /*****************************************************************************
23 AROS_LH4I(STRPTR
,VNewRawDoFmt
,
26 AROS_LHA(CONST_STRPTR
, FormatString
, A0
),
27 AROS_LHA(VOID_FUNC
, PutChProc
, A2
),
28 AROS_LHA(APTR
, PutChData
, A3
),
29 AROS_LHA(va_list, DataStream
, A1
),
32 struct ExecBase
*, SysBase
, 137, Exec
)
35 printf-style formatting function with callback hook and C-style
39 FormatString - Pointer to the format string with any of the following
40 DataStream formatting options allowed:
42 %[leftalign][minwidth.][maxwidth][size][type]
44 leftalign - '-' means align left. Default: align right.
45 minwidth - minimum width of field. Defaults to 0.
46 maxwidth - maximum width of field (for strings only).
49 size - 'l' can be used, but effectively ignored for
50 backwards compatibility with original RawDoFmt().
51 In C arguments are always at least int-sized.
53 type - 'b' BSTR. It will use the internal representation
54 of the BSTR defined by the ABI.
56 'd' signed decimal number.
57 's' C string. NULL terminated.
58 'u' unsigned decimal number.
59 'x' unsigned hexdecimal number.
60 'P' pointer. Size depends on the architecture.
61 'p' The same as 'P', for AmigaOS v4 compatibility.
63 PutChProc - Callback function. Called for each character, including
64 the NULL terminator. The function should be declared as
67 APTR PutChProc(APTR PutChData, UBYTE char);
69 The function should return new value for PutChData variable.
71 Additionally, PutChProc can be set to one of the following
74 RAWFMTFUNC_STRING - Write output to string buffer pointed
75 to by PutChData which is incremented
77 RAWFMTFUNC_SERIAL - Write output to debug output. PutChData
78 is ignored and not touched.
79 RAWFMTFUNC_COUNT - Count number of characters in the result.
80 PutChData is a pointer to ULONG which
81 is incremented every character. Initial
82 value of the counter is kept as it is.
84 PutChData - Data propagated to each call of the callback hook.
86 DataStream - C-style data stream (va_list variable)
89 Final PutChData value.
94 Build a sprintf style function:
96 void my_sprintf(UBYTE *buffer, UBYTE *format, ...)
100 va_start(args, format);
101 VNewRawDoFmt(format, RAWFMTFUNC_STRING, buffer, args);
110 In AROS this function supports also 'i' type specifier
111 standing for full IPTR argument. This makes difference on
112 64-bit machines. At the moment this addition is not stable
113 and subject to change. Consider using %P or %p to output
114 full 64-bit pointers.
116 When locale.library starts up this function is replaced
117 with advanced version, supporting extensions supported
118 by FormatString() function.
120 ******************************************************************************/
124 return InternalRawDoFmt(FormatString
, NULL
, PutChProc
, PutChData
, DataStream
);