Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
fwatch
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
8
Issues
8
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
fwatch
Commits
93ba0e61
Commit
93ba0e61
authored
Aug 04, 2014
by
Grzegorz Daniluk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lightweight printf implementation taken from wrpc-sw
parent
ab4df796
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
131 additions
and
0 deletions
+131
-0
pp-printf.h
sw/common/pp_printf/pp-printf.h
+8
-0
vsprintf-xint.c
sw/common/pp_printf/vsprintf-xint.c
+121
-0
Makefile
sw/freewatch/Makefile
+2
-0
No files found.
sw/common/pp_printf/pp-printf.h
0 → 100644
View file @
93ba0e61
#include <stdarg.h>
extern
int
pp_sprintf
(
char
*
s
,
const
char
*
fmt
,
...)
__attribute__
((
format
(
printf
,
2
,
3
)));
extern
int
pp_vsprintf
(
char
*
buf
,
const
char
*
,
va_list
)
__attribute__
((
format
(
printf
,
2
,
0
)));
sw/common/pp_printf/vsprintf-xint.c
0 → 100644
View file @
93ba0e61
/*
* vsprintf-xint: a possible free-software replacement for mprintf
*
* public domain
*/
#include <stdarg.h>
#include <stdint.h>
static
const
char
hex
[]
=
"0123456789abcdef"
;
static
int
number
(
char
*
out
,
unsigned
value
,
int
base
,
int
lead
,
int
wid
)
{
char
tmp
[
16
];
int
i
=
16
,
ret
,
negative
=
0
;
/* No error checking at all: it is as ugly as possible */
if
((
signed
)
value
<
0
&&
base
==
10
)
{
negative
=
1
;
value
=
-
value
;
}
while
(
value
&&
i
)
{
tmp
[
--
i
]
=
hex
[
value
%
base
];
value
/=
base
;
}
if
(
i
==
16
)
tmp
[
--
i
]
=
'0'
;
if
(
negative
&&
lead
==
' '
)
{
tmp
[
--
i
]
=
'-'
;
negative
=
0
;
}
while
(
i
>
16
-
wid
+
negative
)
tmp
[
--
i
]
=
lead
;
if
(
negative
)
tmp
[
--
i
]
=
'-'
;
ret
=
16
-
i
;
while
(
i
<
16
)
*
(
out
++
)
=
tmp
[
i
++
];
return
ret
;
}
int
pp_vsprintf
(
char
*
buf
,
const
char
*
fmt
,
va_list
args
)
{
char
*
s
,
*
str
=
buf
;
int
base
,
lead
,
wid
;
for
(;
*
fmt
;
++
fmt
)
{
if
(
*
fmt
!=
'%'
)
{
*
str
++
=
*
fmt
;
continue
;
}
base
=
10
;
lead
=
' '
;
wid
=
1
;
repeat:
fmt
++
;
/* Skip '%' initially, other stuff later */
switch
(
*
fmt
)
{
case
'\0'
:
goto
ret
;
case
'0'
:
lead
=
'0'
;
goto
repeat
;
case
'*'
:
/* should be precision, just eat it */
base
=
va_arg
(
args
,
int
);
/* fall through: discard unknown stuff */
default:
if
(
*
fmt
>=
'1'
&&
*
fmt
<=
'9'
)
wid
=
*
fmt
-
'0'
;
goto
repeat
;
/* Special cases for conversions */
case
'c'
:
/* char: supported */
*
str
++
=
(
unsigned
char
)
va_arg
(
args
,
int
);
break
;
case
's'
:
/* string: supported */
s
=
va_arg
(
args
,
char
*
);
while
(
*
s
)
*
str
++
=
*
s
++
;
break
;
case
'n'
:
/* number-thus-far: not supported */
break
;
case
'%'
:
/* supported */
*
str
++
=
'%'
;
break
;
/* integers are more or less printed */
case
'p'
:
case
'x'
:
case
'X'
:
base
=
16
;
case
'o'
:
if
(
base
==
10
)
/* yet unchaged */
base
=
8
;
case
'd'
:
case
'i'
:
case
'u'
:
str
+=
number
(
str
,
va_arg
(
args
,
int
),
base
,
lead
,
wid
);
break
;
}
}
ret:
*
str
=
'\0'
;
return
str
-
buf
;
}
int
pp_sprintf
(
char
*
s
,
const
char
*
fmt
,
...)
{
va_list
args
;
int
ret
;
va_start
(
args
,
fmt
);
ret
=
pp_vsprintf
(
s
,
fmt
,
args
);
va_end
(
args
);
return
ret
;
}
sw/freewatch/Makefile
View file @
93ba0e61
...
...
@@ -134,6 +134,7 @@ INCLUDEPATHS += \
-I../common/emlib/inc
\
-I../common/drivers
\
-I../common/glib
\
-I../common/pp_printf
\
-I../common
####################################################################
...
...
@@ -167,6 +168,7 @@ C_SRC += \
../common/gfx/font_helv17b.c
\
../common/gfx/font_xm4x5.c
\
../common/gfx/font_xm4x6.c
\
../common/pp_printf/vsprintf-xint.c
\
../common/udelay.c
\
main.c
#../common/drivers/display.c \
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment