[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-libc-dev] scanf() is there!

From: Joerg Wunsch
Subject: [avr-libc-dev] scanf() is there!
Date: Wed, 8 Jan 2003 00:02:25 +0100
User-agent: Mutt/1.2.5i

OK, i finally got it into some shape where i think it's worth
committing.  I wrote a complete scanf() family of functions.  The
heart of it is (again) vfscanf(), anything else wraps around that
function, setting various flags in struct __file, etc.

The basic skeleton is somewhat inspired by Alexander Popov's printf(),
so at a first glance, both files might look somewhat similar in
structure.  Also as with vfprintf(), there are again three different
implementation options around.  The default version is currently 1320
bytes long (on the avr5 target) and has everything minus floating
point minus the %[ format (which is costs several hundred bytes of
code by itself, and like the floating point conversions, requires the
use of a temporary malloc()ed buffer).

The vfscanf_flt version has all of it, basically any of the
conversions that are documented in the (now obsolete) 1990 C standard
are implemented.  The 1999 standard adds a number of things that
mostly don't make sense on the AVR like wide character support, except
perhaps the hh modifier to indicate an integer-style conversion, but a
"char *" as the target.  Also, none of our printf()/scanf() so far
supports long long variables, i wonder whether there would be any
interest in this?  Right now, the full version is 2068 bytes of code
plus 14 bytes of initialized data on avr5.  This is still less than
the printf() counterpart which is ~ 3 KB in size, but unlike printf(),
scanf() resorts to use strtod() on a temporary buffer since this
seemed to be more convenient, so add another 422 bytes for this.

The vfscanf_min version further removes anything except basic
conversions: the `*' (suppress assignment) and field width modifiers
are not supported, the `n' non-conversion is omitted (tell how many
bytes have been consumed so far), and plain text matching
non-conversions are not there, this also includes the white space
consumption that would happen by providing a single space in the
format string.  (Implicit white-space consumption by those formats
that support it is implemented though.)  All this together,
vfscanf_min.o is again less than 1 KB.

There might be some potential for further optimizations which needs to
be investigated still.  However, doing this in CVS is more convenient
to me, now that the basic functionality is there and seems to work OK.
Also, the matter is quite complex, so i have of course not been able
to test /every/ aspect of it.  Please give it a try, and report any
bugs found to me.

I'll also prepare a demo project that explains all this within a
practical example, and that will also contain examples for a simple
UART-based input support function that includes a simple line
editor (i. e. something where you could at least delete the last
characters you've entered before it's going to be passed to stdio).
J"org Wunsch                                           Unix support engineer
address@hidden        http://www.interface-systems.de/~j/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]