www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - scanf implementation

reply Sean Kelly <sean f4.ca> writes:
I went on vacation before I had time to finish my stream updates, but I thought
it might be useful to split out the scanf implementation and post it separately.
Don't expect much of a response from me for another week or so as I'm busy
overeating and swimming in the ocean, but here are a few details...  This is a
(mostly tested) C99 compliant scanf implementation.  It adds %C and %S for D
strings, as (AFAIK) the typeinfo currently isn't good enough to distinguish
between C pointers and D arrays.  The only feature that is not implemented is %p
because I wanted to see what Walter came up with for the printf side.  The
declaration for wscanf is commented out because there was some issue finding the
wide version of a function it uses.  I would also like to add complex number
support, but again some coordination should be done with printf.

Functionally, the implementation is a good demonstration of things that aren't
possible in C++.  Alias template parameters and inner functions made things
pretty clean and efficient--C++ would have required function pointers or wrapper
classes to do the same thing--and it was a neat discovery that D functions can
require interfaces of their own.  I did use goto a bit for clarity (yes clarity)
and exceptions for flow control.  And this same implementation can be used as a
mixin in the stream classes so there's no unnecessary code duplication or odd

The unit tests are basically nonexistent at the moment and will be expanded.  I
had some problems with .94 so I've commented out the %s test (it was giving an
access violation) for now--it worked in .93 so I'm going to assume it still

The link is here:


Jul 11 2004
parent reply Sean Kelly <sean f4.ca> writes:
Just a quick update.  I added support for %p and fixed an issue with C pointers.
The implementation is now complete unless there are any other bugs lurking.  The
file contains fscanf, sscanf, scanf, and the wchar versions of each.  The unit
tests have examples of string use but nothing else yet.  I'll improve that
within the next week.

Jul 13 2004
parent Sean Kelly <sean f4.ca> writes:
Looks like the implementation still has problems with typeid.  I'm posting a
small update that includes some modified unit tests, but the updates will
continue for the next week or two as I get the problems worked out.  Right now
I'm defaulting to C strings for the scanset type and D strings don't work for
that parameter type.  This version also includes a fix for the suppress flag.

Jul 16 2004