Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/iostream.c

    r53ba273 rb63e376  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr  6 16:13:29 2016
    13 // Update Count     : 278
     12// Last Modified On : Mon Mar  7 13:51:23 2016
     13// Update Count     : 227
    1414//
    1515
     
    2727ostype * ?|?( ostype *os, char c ) {
    2828        prtfmt( os, "%c", c );
    29         sepOff( os );
    3029        return os;
    3130} // ?|?
     
    3332forall( dtype ostype | ostream( ostype ) )
    3433ostype * ?|?( ostype *os, short int si ) {
    35         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    36         sepReset( os );
     34        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
    3735        prtfmt( os, "%hd", si );
    3836        return os;
     
    4139forall( dtype ostype | ostream( ostype ) )
    4240ostype * ?|?( ostype *os, unsigned short int usi ) {
    43         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    44         sepReset( os );
     41        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
    4542        prtfmt( os, "%hu", usi );
    4643        return os;
     
    4946forall( dtype ostype | ostream( ostype ) )
    5047ostype * ?|?( ostype *os, int i ) {
    51         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    52         sepReset( os );
     48        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
    5349        prtfmt( os, "%d", i );
    5450        return os;
     
    5753forall( dtype ostype | ostream( ostype ) )
    5854ostype * ?|?( ostype *os, unsigned int ui ) {
    59         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    60         sepReset( os );
     55        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
    6156        prtfmt( os, "%u", ui );
    6257        return os;
     
    6560forall( dtype ostype | ostream( ostype ) )
    6661ostype * ?|?( ostype *os, long int li ) {
    67         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    68         sepReset( os );
     62        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
    6963        prtfmt( os, "%ld", li );
    7064        return os;
     
    7367forall( dtype ostype | ostream( ostype ) )
    7468ostype * ?|?( ostype *os, unsigned long int uli ) {
    75         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    76         sepReset( os );
     69        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
    7770        prtfmt( os, "%lu", uli );
    7871        return os;
     
    8174forall( dtype ostype | ostream( ostype ) )
    8275ostype * ?|?( ostype *os, long long int lli ) {
    83         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    84         sepReset( os );
     76        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
    8577        prtfmt( os, "%lld", lli );
    8678        return os;
     
    8981forall( dtype ostype | ostream( ostype ) )
    9082ostype * ?|?( ostype *os, unsigned long long int ulli ) {
    91         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    92         sepReset( os );
     83        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
    9384        prtfmt( os, "%llu", ulli );
    9485        return os;
     
    9788forall( dtype ostype | ostream( ostype ) )
    9889ostype * ?|?( ostype *os, float f ) {
    99         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    100         sepReset( os );
     90        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
    10191        prtfmt( os, "%g", f );
    10292        return os;
     
    10595forall( dtype ostype | ostream( ostype ) )
    10696ostype * ?|?( ostype *os, double d ) {
    107         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    108         sepReset( os );
     97        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
    10998        prtfmt( os, "%.*lg", DBL_DIG, d );
    11099        return os;
     
    113102forall( dtype ostype | ostream( ostype ) )
    114103ostype * ?|?( ostype *os, long double ld ) {
    115         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    116         sepReset( os );
     104        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
    117105        prtfmt( os, "%.*Lg", LDBL_DIG, ld );
    118106        return os;
     
    122110ostype * ?|?( ostype *os, float _Complex fc ) {
    123111        os | crealf( fc );
    124         _Bool temp = sepDisable( os );                                          // disable separators within complex value
    125         if ( cimagf( fc ) >= 0 ) os | '+';                                      // negative value prints '-'
    126         os | cimagf( fc ) | 'i';
    127         sepReset( os, temp );                                                           // reset separator
     112        if ( cimagf( fc ) >= 0 ) os | '+';
     113        os | "" | cimagf( fc ) | 'i';
    128114        return os;
    129115} // ?|?
     
    132118ostype * ?|?( ostype *os, double _Complex dc ) {
    133119        os | creal( dc );
    134         _Bool temp = sepDisable( os );                                          // disable separators within complex value
    135         if ( cimag( dc ) >= 0 ) os | '+';                                       // negative value prints '-'
    136         os | cimag( dc ) | 'i';
    137         sepReset( os, temp );                                                           // reset separator
     120        if ( cimag( dc ) >= 0 ) os | '+';
     121        os | "" | cimag( dc ) | 'i';
    138122        return os;
    139123} // ?|?
     
    142126ostype * ?|?( ostype *os, long double _Complex ldc ) {
    143127        os | creall( ldc );
    144         _Bool temp = sepDisable( os );                                          // disable separators within complex value
    145         if ( cimagl( ldc ) >= 0 ) os | '+';                                     // negative value prints '-'
    146         os | cimagl( ldc ) | 'i';
    147         sepReset( os, temp );                                                           // reset separator
     128        if ( cimagl( ldc ) >= 0 ) os | '+';
     129        os | "" | cimagl( ldc ) | 'i';
    148130        return os;
    149131} // ?|?
     
    152134ostype * ?|?( ostype *os, const char *cp ) {
    153135        enum { Open = 1, Close, OpenClose };
    154         static const unsigned char mask[256] = {
     136        static const char mask[256] = {
    155137                // opening delimiters
    156138                ['('] : Open, ['['] : Open, ['{'] : Open,
    157                 ['$'] : Open, [(unsigned char)'£'] : Open, [(unsigned char)'¥'] : Open, [(unsigned char)'¿'] : Open, [(unsigned char)'«'] : Open,
     139                ['$'] : Open, [L'£'] : Open, [L'¥'] : Open, [L'¢'] : Open, [L'¿'] : Open, [L'«'] : Open,
    158140                // closing delimiters
    159141                [','] : Close, ['.'] : Close, [':'] : Close, [';'] : Close, ['!'] : Close, ['?'] : Close,
    160142                [')'] : Close, [']'] : Close, ['}'] : Close,
    161                 ['%'] : Close, [(unsigned char)'¢'] : Close, [(unsigned char)'»'] : Close,
     143                ['%'] : Close, [L'»'] : Close,
    162144                // opening-closing delimiters
    163145                ['\''] : OpenClose, ['`'] : OpenClose, ['"'] : OpenClose,
    164                 ['\f'] : OpenClose, ['\n'] : OpenClose, ['\r'] : OpenClose, ['\t'] : OpenClose, ['\v'] : OpenClose, // isspace
    165146        }; // mask
    166147
     
    168149        // null string => no separator
    169150  if ( len == 0 ) { sepOff( os ); return os; }
    170         // first character IS NOT spacing or closing punctuation => add left separator
    171         unsigned char ch = cp[0];                                                       // must make unsigned
    172         if ( sepPrt( os ) && mask[ ch ] != Close && mask[ ch ] != OpenClose ) {
     151        // first character NOT spacing or closing punctuation => add left separator
     152        if ( sepPrt( os ) && isspace( cp[0] ) == 0 && mask[ cp[0] ] != Close && mask[ cp[0] ] != OpenClose ) {
    173153                prtfmt( os, "%s", sepGet( os ) );
    174154        } // if
    175155        // last character IS spacing or opening punctuation => turn off separator for next item
    176156        unsigned int posn = len - 1;
    177         ch = cp[posn];                                                                          // must make unsigned
    178         if ( mask[ ch ] == Open || mask[ ch ] == OpenClose ) {
     157        if ( isspace( cp[posn] ) || mask[ cp[posn] ] == Open || mask[ cp[posn] ] == OpenClose ) {
    179158                sepOff( os );
    180159        } else {
     
    186165forall( dtype ostype | ostream( ostype ) )
    187166ostype * ?|?( ostype *os, const void *p ) {
    188         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    189         sepReset( os );
     167        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
    190168        prtfmt( os, "%p", p );
    191169        return os;
     
    218196} // sepOff
    219197
    220 forall( dtype ostype | ostream( ostype ) )
    221 ostype * sepEnable( ostype * os ) {
    222         sepEnable( os );
    223         return os;
    224 } // sepEnable
    225 
    226 forall( dtype ostype | ostream( ostype ) )
    227 ostype * sepDisable( ostype * os ) {
    228         sepDisable( os );
    229         return os;
    230 } // sepDisable
    231 
    232198//---------------------------------------
    233199
     
    344310} // ?|?
    345311
    346 _Istream_cstrUC cstr( char * s ) { _Istream_cstrUC s = { s }; return s; }
    347 forall( dtype istype | istream( istype ) )
    348 istype * ?|?( istype * is, _Istream_cstrUC cstr ) {
    349         scanfmt( is, "%s", cstr.s );
    350         return is;
    351 } // cstr
    352 
    353 _Istream_cstrC cstr( char * s, int size ) { _Istream_cstrC s = { s, size }; return s; }
    354 forall( dtype istype | istream( istype ) )
    355 istype * ?|?( istype * is, _Istream_cstrC cstr ) {
     312_Istream_str1 str( char * s ) { _Istream_str1 s = { s }; return s; }
     313forall( dtype istype | istream( istype ) )
     314istype * ?|?( istype * is, _Istream_str1 str ) {
     315        scanfmt( is, "%s", str.s );
     316        return is;
     317} // str
     318
     319_Istream_str2 str( char * s, int size ) { _Istream_str2 s = { s, size }; return s; }
     320forall( dtype istype | istream( istype ) )
     321istype * ?|?( istype * is, _Istream_str2 str ) {
    356322        char buf[16];
    357         sprintf( buf, "%%%ds", cstr.size );
    358         scanfmt( is, buf, cstr.s );
    359         return is;
    360 } // cstr
     323        sprintf( buf, "%%%ds", str.size );
     324        scanfmt( is, buf, str.s );
     325        return is;
     326} // str
    361327
    362328// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.