PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Simple Libraries
TextDevices
libsimpletext
dosprint.c
1
/*
2
* very simple printf, adapted from one written by me
3
* for the MiNT OS long ago
4
* placed in the public domain
5
* - Eric Smith
6
* 32 bit mode only. %b, %e, %f, %g added by Steve Denson
7
*/
8
#include <ctype.h>
9
#include <stdarg.h>
10
#include "
simpletext.h
"
11
12
/*
13
* very simple printf -- just understands a few format features
14
*/
15
16
int
_dosprnt(
const
char
*fmt, va_list args,
char
*obuf)
17
{
18
char
c, fill_char;
19
char
*s_arg;
20
int
i_arg;
21
long
l_arg;
22
int
width;
23
int
precision;
24
char
fstr[20];
25
26
char
*buf = obuf;
27
while
( (c = *fmt++) != 0 ) {
28
29
if
(c !=
'%'
) {
30
buf += SPUTC(c, buf);
31
continue
;
32
}
33
c = *fmt++;
34
width = 0;
35
precision = 6;
36
fill_char =
' '
;
37
if
(c ==
'0'
) fill_char =
'0'
;
38
while
(c &&
isdigit
(c)) {
39
width = 10*width + (c-
'0'
);
40
c = *fmt++;
41
}
42
if
(c ==
'.'
) {
43
precision = 0;
44
c = *fmt++;
45
while
(c &&
isdigit
(c)) {
46
precision = 10*precision + (c-
'0'
);
47
c = *fmt++;
48
}
49
}
50
if
(!c)
51
break
;
52
53
switch
(c) {
54
55
case
'%'
:
56
buf += SPUTC(c, buf);
57
break
;
58
59
case
'b'
:
60
l_arg = va_arg(args,
int
);
61
buf += SPUTL(l_arg, 2, width, fill_char, buf);
62
break
;
63
64
case
'c'
:
65
i_arg = va_arg(args,
int
);
66
buf += SPUTC(i_arg, buf);
67
break
;
68
69
case
's'
:
70
s_arg = va_arg(args,
char
*);
71
buf += SPUTS(s_arg, buf);
72
break
;
73
74
case
'd'
:
75
case
'u'
:
76
l_arg = va_arg(args,
int
);
77
if
(l_arg < 0 && c ==
'd'
) {
78
buf += SPUTC(
'-'
, buf);
79
width--;
80
l_arg = -l_arg;
81
}
82
buf += SPUTL(l_arg, 10, width, fill_char, buf);
83
break
;
84
#if 0
85
case
'e'
:
86
case
'g'
:
87
{
88
union
{
float
f;
int
i; } a;
89
a.i = va_arg(args,
int
);
90
buf += SPUTS(floatToScientific(a.f), buf);
91
break
;
92
}
93
#endif
94
case
'f'
: {
95
double
d = va_arg(args,
double
);
96
buf += SPUTS(float2string((
float
) d, fstr, width, precision), buf);
97
break
;
98
}
99
100
case
'x'
: {
101
l_arg = va_arg(args,
unsigned
int
);
102
buf += SPUTL(l_arg, 16, width, fill_char, buf);
103
break
;
104
}
105
}
106
}
107
*buf =
'\0'
;
108
return
buf-obuf;
109
}
110
111
/* +--------------------------------------------------------------------
112
* | TERMS OF USE: MIT License
113
* +--------------------------------------------------------------------
114
* Permission is hereby granted, free of charge, to any person obtaining
115
* a copy of this software and associated documentation files
116
* (the "Software"), to deal in the Software without restriction,
117
* including without limitation the rights to use, copy, modify, merge,
118
* publish, distribute, sublicense, and/or sell copies of the Software,
119
* and to permit persons to whom the Software is furnished to do so,
120
* subject to the following conditions:
121
*
122
* The above copyright notice and this permission notice shall be
123
* included in all copies or substantial portions of the Software.
124
*
125
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
126
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
127
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
128
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
129
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
130
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
131
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
132
* +--------------------------------------------------------------------
133
*/
isdigit
#define isdigit(c)
Definition:
ctype.h:83
simpletext.h
This library provides a collection of functions for communicating with text devices such as SimpleIDE...
Generated on Fri May 20 2022 16:48:05 for PropWare by
1.8.17