PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Simple Libraries
TextDevices
libsimpletext
intprint.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
*
7
* 32 bit integer mode only. %b, added by Steve Denson
8
*/
9
#include <ctype.h>
10
#include <stdarg.h>
11
#include "
simpletext.h
"
12
13
/*
14
* very simple printf -- just understands a few format features
15
*/
16
17
int
_intsprnt(
const
char
*fmt, va_list args,
char
*obuf)
18
{
19
char
c, fill_char;
20
char
*s_arg;
21
int
i_arg;
22
long
l_arg;
23
int
width;
24
int
precision;
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
85
case
'x'
: {
86
l_arg = va_arg(args,
unsigned
int
);
87
buf += SPUTL(l_arg, 16, width, fill_char, buf);
88
break
;
89
}
90
}
91
}
92
*buf =
'\0'
;
93
return
buf-obuf;
94
}
95
96
/* +--------------------------------------------------------------------
97
* | TERMS OF USE: MIT License
98
* +--------------------------------------------------------------------
99
* Permission is hereby granted, free of charge, to any person obtaining
100
* a copy of this software and associated documentation files
101
* (the "Software"), to deal in the Software without restriction,
102
* including without limitation the rights to use, copy, modify, merge,
103
* publish, distribute, sublicense, and/or sell copies of the Software,
104
* and to permit persons to whom the Software is furnished to do so,
105
* subject to the following conditions:
106
*
107
* The above copyright notice and this permission notice shall be
108
* included in all copies or substantial portions of the Software.
109
*
110
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
111
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
112
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
113
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
114
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
115
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
116
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
117
* +--------------------------------------------------------------------
118
*/
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