1 |
48 |
alirezamon |
/*
|
2 |
|
|
* Copyright (c) 2016, Matt Redfearn
|
3 |
|
|
* All rights reserved.
|
4 |
|
|
*
|
5 |
|
|
* Redistribution and use in source and binary forms, with or without
|
6 |
|
|
* modification, are permitted provided that the following conditions are met:
|
7 |
|
|
*
|
8 |
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
9 |
|
|
* this list of conditions and the following disclaimer.
|
10 |
|
|
*
|
11 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
12 |
|
|
* this list of conditions and the following disclaimer in the documentation
|
13 |
|
|
* and/or other materials provided with the distribution.
|
14 |
|
|
*
|
15 |
|
|
* 3. Neither the name of the copyright holder nor the names of its
|
16 |
|
|
* contributors may be used to endorse or promote products derived from this
|
17 |
|
|
* software without specific prior written permission.
|
18 |
|
|
*
|
19 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
20 |
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
22 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
23 |
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
24 |
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25 |
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26 |
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27 |
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28 |
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29 |
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
30 |
|
|
*
|
31 |
|
|
*
|
32 |
|
|
* This library provides a simple implementation of printf and sprintf. I wrote
|
33 |
|
|
* it because I could not find a good BSD licensed printf that may be built in
|
34 |
|
|
* to proprietary software.
|
35 |
|
|
*
|
36 |
|
|
* The formats specifiers supported by this implementation are:
|
37 |
|
|
* 'd' 'u' 'x' 'X' 'c' 's'.
|
38 |
|
|
*
|
39 |
|
|
* Zero padding and field width are also supported, as well as pad right and
|
40 |
|
|
* variable pad width.
|
41 |
|
|
*
|
42 |
|
|
* To use printf() your program should provide an implementation of putchar()
|
43 |
|
|
* to output a character, for example:
|
44 |
|
|
*
|
45 |
|
|
* void putchar(char c)
|
46 |
|
|
* {
|
47 |
|
|
* while(!SERIAL_PORT_EMPTY);
|
48 |
|
|
* SERIAL_PORT_TX_REGISTER = c;
|
49 |
|
|
* }
|
50 |
|
|
*
|
51 |
|
|
* The code is re-entrant, so it is safe to call from any context, though you
|
52 |
|
|
* will probably get interleaved output. This means that your putchar()
|
53 |
|
|
* function should also be reentrant.
|
54 |
|
|
*/
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
#ifndef __SIMPLE_FPRINTF__
|
58 |
|
|
#define __SIMPLE_FPRINTF__
|
59 |
|
|
|
60 |
|
|
/* Platform must supply this function to output a character */
|
61 |
|
|
void foutbyte(char c);
|
62 |
|
|
void fout_select(char * f);
|
63 |
|
|
|
64 |
|
|
//#include "printf.c"
|
65 |
|
|
|
66 |
|
|
//int simple_printf (__const char *__restrict __format, ...);
|
67 |
|
|
int simple_fprintf(char *str,char *fmt, ...);
|
68 |
|
|
|
69 |
|
|
//int fsprintf (char *str, __const char *__restrict __format, ...);
|
70 |
|
|
|
71 |
|
|
#define fprintf simple_fprintf
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
#endif /* __SIMPLE_FPRINTF__ */
|