Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/iostream.c

    r6ba0659 r5721a6d  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 17 14:19:56 2016
    13 // Update Count     : 76
     12// Last Modified On : Mon Feb  1 14:20:30 2016
     13// Update Count     : 60
    1414//
    1515
     
    1919#include <stdio.h>
    2020#include <string.h>                                                                             // strlen
    21 #include <float.h>                                                                              // DBL_DIG, LDBL_DIG
    2221#include <complex.h>                                                                    // creal, cimag
    2322}
     
    7372ostype * ?|?( ostype *os, double d ) {
    7473        char buffer[32];
    75         return write( os, buffer, sprintf( buffer, "%.*lg", DBL_DIG, d ) );
     74        return write( os, buffer, sprintf( buffer, "%g", d ) );
    7675} // ?|?
    7776
     
    7978ostype * ?|?( ostype *os, long double d ) {
    8079        char buffer[32];
    81         return write( os, buffer, sprintf( buffer, "%.*Lg", LDBL_DIG, d ) );
     80        return write( os, buffer, sprintf( buffer, "%Lg", d ) );
    8281} // ?|?
    8382
     
    111110forall( dtype ostype, dtype retostype | ostream( ostype ) | ostream( retostype ) )
    112111retostype * ?|?( ostype *os, retostype * (*manip)(ostype*) ) {
    113   return manip( os );
     112  return manip(os);
    114113}
    115114
    116115forall( dtype ostype | ostream( ostype ) )
    117116ostype * endl( ostype * os ) {
    118         os | "\n";
    119         flush( os );
    120         return os;
     117  os | "\n";
     118  // flush
     119  return os;
    121120} // endl
    122121
    123 //---------------------------------------
    124 
    125 forall( type elt_type | writeable( elt_type ), type iterator_type | iterator( iterator_type, elt_type ),
     122forall( type elt_type | writeable( elt_type ),
     123                type iterator_type | iterator( iterator_type, elt_type ),
    126124                dtype os_type | ostream( os_type ) )
    127125void write( iterator_type begin, iterator_type end, os_type *os ) {
    128         void print( elt_type i ) { os | i | ' '; }
     126        void print( elt_type i ) {
     127                os | i | ' ';
     128        }
    129129        for_each( begin, end, print );
    130130} // ?|?
    131131
    132 forall( type elt_type | writeable( elt_type ), type iterator_type | iterator( iterator_type, elt_type ),
     132forall( type elt_type | writeable( elt_type ),
     133                type iterator_type | iterator( iterator_type, elt_type ),
    133134                dtype os_type | ostream( os_type ) )
    134135void write_reverse( iterator_type begin, iterator_type end, os_type *os ) {
     
    137138} // ?|?
    138139
    139 //---------------------------------------
    140140
    141141forall( dtype istype | istream( istype ) )
     
    146146forall( dtype istype | istream( istype ) )
    147147istype * ?|?( istype *is, int *ip ) {
    148         return get( is, ip );
     148        char cur;
     149 
     150        // skip some whitespace
     151        do {
     152                is | &cur;
     153                if ( fail( is ) || eof( is ) ) return is;
     154        } while ( !( cur >= '0' && cur <= '9' ) );
     155 
     156        // accumulate digits
     157        *ip = 0;
     158        while ( cur >= '0' && cur <= '9' ) {
     159                *ip = *ip * 10 + ( cur - '0' );
     160                is | &cur;
     161                if ( fail( is ) || eof( is ) ) return is;
     162        }
     163 
     164        unread( is, cur );
     165        return is;
    149166} // ?|?
    150167
Note: See TracChangeset for help on using the changeset viewer.