Spelling fix.
[bertos.git] / mware / sprintf.c
1 /*!
2  * \file
3  * <!--
4  * Copyright (C) 2002,2004 Develer S.r.l. (http://www.develer.com/)
5  * This file is part of DevLib - See devlib/README for information.
6  * -->
7  *
8  * \version $Id$
9  *
10  * \author Bernardo Innocenti <bernie@develer.com>
11  *
12  * \brief Simple sprintf() implementation based on _formatted_write()
13  */
14
15 /*#*
16  *#* $Log$
17  *#* Revision 1.4  2004/08/25 14:12:09  rasky
18  *#* Aggiornato il comment block dei log RCS
19  *#*
20  *#* Revision 1.3  2004/06/27 15:20:26  aleph
21  *#* Change UNUSED() macro to accept two arguments: type and name;
22  *#* Add macro GNUC_PREREQ to detect GCC version during build;
23  *#* Some spacing cleanups and typo fix
24  *#*
25  *#* Revision 1.2  2004/06/03 11:27:09  bernie
26  *#* Add dual-license information.
27  *#*
28  *#* Revision 1.1  2004/05/23 15:43:16  bernie
29  *#* Import mware modules.
30  *#*
31  *#* Revision 1.4  2004/04/03 20:42:27  aleph
32  *#* Remove duplicated defines
33  *#*
34  *#* Revision 1.3  2004/03/24 15:48:53  bernie
35  *#* Remove Copyright messages from Doxygen output
36  *#*
37  *#* Revision 1.2  2004/03/19 16:51:30  bernie
38  *#* Add PROGMEM kludge.
39  *#*
40  *#* Revision 1.1  2004/02/23 09:45:09  aleph
41  *#* Add missing library functions.
42  *#*
43  *#* Revision 1.1  2003/11/13 16:56:37  aleph
44  *#* Add first implementation of dsp firmware
45  *#*
46  *#*/
47
48 #include "compiler.h"
49 #include "formatwr.h"
50 #include <stdio.h>
51
52
53 static void __str_put_char(char c, void *ptr)
54 {
55         /*
56          * This Does not work on Code Warrior. Hmm...
57          *      *(*((char **)ptr))++ = c;
58          */
59
60         **((char **)ptr) = c;
61         (*((char **)ptr))++;
62 }
63
64 static void __null_put_char(UNUSED(char, c), UNUSED(void *, ptr))
65 {
66         /* nop */
67 }
68
69
70 int PGM_FUNC(vsprintf)(char * str, const char * PGM_ATTR fmt, va_list ap)
71 {
72         int result;
73
74         result = PGM_FUNC(_formatted_write)(
75                         fmt, (str ? __str_put_char : __null_put_char), &str, ap);
76
77         /* terminate string */
78         *str = '\0';
79
80         return result;
81 }
82
83 /* FIXME: sprintf_P is incorrectly declared in <stdio.h> */
84 int PGM_FUNC(sprintf)(char *str, const char * fmt, ...)
85 {
86         int result;
87         va_list ap;
88
89         va_start(ap, fmt);
90         result = PGM_FUNC(vsprintf)(str, fmt, ap);
91         va_end(ap);
92
93         /* terminate string */
94         *str = '\0';
95
96         return result;
97 }