revert between 56095 -> 55830 in arch
[AROS.git] / compiler / include / SDI / doc / examples / misc / example_miscuse.c
blobda34ebf87ab15ab1481826bad6d267cc7f7a1556
1 /* Example source
3 Name: example_miscuse.c
4 Versionstring: $VER: example_miscuse.c 1.0 (17.05.2005)
5 Author: Guido Mersmann
6 Distribution: PD
7 Description: shows how the SDI_misc.h header includes are used
9 1.0 17.05.04 : initial version showing how the SDI_misc.h header have to be
10 used if one wants to keep the sources platform independent
11 throughout all common AmigaOS compatible platforms like OS3,
12 OS4 and MorphOS.
15 Please note that this example is just for educational purposes and wasn't
16 checked for complete correctness. However, it should compile and probably also
17 work as expected. But please note that its purpose is to show how the misc
18 macros make it very easy to deal with those functions and also keep the
19 sources simple and platform independent through OS3, OS4 and MorphOS.
21 Feel free to comment and submit any suggestions directly to
22 Guido Mersmann <geit@gmx.de>
26 #include <proto/exec.h>
27 #include <proto/utility.h>
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <ctype.h>
33 #include "SDI_misc.h"
38 **This structure keeps our internal sprintf vars during RawDoFmt()
42 struct SPrintfStream
44 char *Target;
45 ULONG TargetSize; /* Obsolete in this example, but useful when
46 dealing with size limited streams */
50 ** SPrintf_DoChar
52 ** The following function is just an example where we use the object
53 ** for composing some minor text. Do you see how easy it is to use and
54 ** how great it is to use SDI_misc.h to automatically keep your sources
55 ** compatible to all common AmigaOS platforms?
59 PUTCHARPROTO( SPrintf_DoChar, char c, struct SPrintfStream *s )
61 *(s->Target++) = c;
66 ** SPrintf
68 ** Here you can see how the function is used by the ENTRY() function.
72 ULONG SPrintf( char *format, char *target, ULONG *args );
73 ULONG SPrintf( char *format, char *target, ULONG *args )
75 struct SPrintfStream s;
77 s.Target = target;
79 RawDoFmt( format, args, ENTRY( SPrintf_DoChar ), &s);
81 return( s.Target - target );
86 ** The main entry point
90 int main(void)
92 char buf[0x80]; /* storage for keeping the SPrintf result string */
93 ULONG args[2]; /* storage for keeping the SPrintf arguments */
95 args[0] = (ULONG) "result";
96 args[1] = (ULONG) "PUTCHARPROTO macro";
98 SPrintf("I am the %s of using SPrintf() with the new %s!", buf, args);
100 printf("%s\n", buf); /* just a simple printf to output and add the \n */
102 return( 0);