Ignore:
Timestamp:
May 2, 2016, 3:28:16 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
1b7ea43
Parents:
1f6e009 (diff), e945826 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into global-init

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/iostream.c

    r1f6e009 r1048b31  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Mar  7 13:51:23 2016
    13 // Update Count     : 227
     12// Last Modified On : Sat Apr 30 14:00:53 2016
     13// Update Count     : 302
    1414//
    1515
     
    2727ostype * ?|?( ostype *os, char c ) {
    2828        prtfmt( os, "%c", c );
     29        sepOff( os );
    2930        return os;
    3031} // ?|?
     
    3233forall( dtype ostype | ostream( ostype ) )
    3334ostype * ?|?( ostype *os, short int si ) {
    34         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     35        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    3536        prtfmt( os, "%hd", si );
    3637        return os;
     
    3940forall( dtype ostype | ostream( ostype ) )
    4041ostype * ?|?( ostype *os, unsigned short int usi ) {
    41         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     42        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    4243        prtfmt( os, "%hu", usi );
    4344        return os;
     
    4647forall( dtype ostype | ostream( ostype ) )
    4748ostype * ?|?( ostype *os, int i ) {
    48         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     49        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    4950        prtfmt( os, "%d", i );
    5051        return os;
     
    5354forall( dtype ostype | ostream( ostype ) )
    5455ostype * ?|?( ostype *os, unsigned int ui ) {
    55         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     56        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    5657        prtfmt( os, "%u", ui );
    5758        return os;
     
    6061forall( dtype ostype | ostream( ostype ) )
    6162ostype * ?|?( ostype *os, long int li ) {
    62         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     63        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    6364        prtfmt( os, "%ld", li );
    6465        return os;
     
    6768forall( dtype ostype | ostream( ostype ) )
    6869ostype * ?|?( ostype *os, unsigned long int uli ) {
    69         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     70        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    7071        prtfmt( os, "%lu", uli );
    7172        return os;
     
    7475forall( dtype ostype | ostream( ostype ) )
    7576ostype * ?|?( ostype *os, long long int lli ) {
    76         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     77        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    7778        prtfmt( os, "%lld", lli );
    7879        return os;
     
    8182forall( dtype ostype | ostream( ostype ) )
    8283ostype * ?|?( ostype *os, unsigned long long int ulli ) {
    83         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     84        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    8485        prtfmt( os, "%llu", ulli );
    8586        return os;
     
    8889forall( dtype ostype | ostream( ostype ) )
    8990ostype * ?|?( ostype *os, float f ) {
    90         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     91        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    9192        prtfmt( os, "%g", f );
    9293        return os;
     
    9596forall( dtype ostype | ostream( ostype ) )
    9697ostype * ?|?( ostype *os, double d ) {
    97         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     98        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    9899        prtfmt( os, "%.*lg", DBL_DIG, d );
    99100        return os;
     
    102103forall( dtype ostype | ostream( ostype ) )
    103104ostype * ?|?( ostype *os, long double ld ) {
    104         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     105        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    105106        prtfmt( os, "%.*Lg", LDBL_DIG, ld );
    106107        return os;
     
    110111ostype * ?|?( ostype *os, float _Complex fc ) {
    111112        os | crealf( fc );
    112         if ( cimagf( fc ) >= 0 ) os | '+';
    113         os | "" | cimagf( fc ) | 'i';
     113        _Bool temp = sepDisable( os );                                          // disable separators within complex value
     114        if ( cimagf( fc ) >= 0 ) os | '+';                                      // negative value prints '-'
     115        os | cimagf( fc ) | 'i';
     116        sepReset( os, temp );                                                           // reset separator
    114117        return os;
    115118} // ?|?
     
    118121ostype * ?|?( ostype *os, double _Complex dc ) {
    119122        os | creal( dc );
    120         if ( cimag( dc ) >= 0 ) os | '+';
    121         os | "" | cimag( dc ) | 'i';
     123        _Bool temp = sepDisable( os );                                          // disable separators within complex value
     124        if ( cimag( dc ) >= 0 ) os | '+';                                       // negative value prints '-'
     125        os | cimag( dc ) | 'i';
     126        sepReset( os, temp );                                                           // reset separator
    122127        return os;
    123128} // ?|?
     
    126131ostype * ?|?( ostype *os, long double _Complex ldc ) {
    127132        os | creall( ldc );
    128         if ( cimagl( ldc ) >= 0 ) os | '+';
    129         os | "" | cimagl( ldc ) | 'i';
     133        _Bool temp = sepDisable( os );                                          // disable separators within complex value
     134        if ( cimagl( ldc ) >= 0 ) os | '+';                                     // negative value prints '-'
     135        os | cimagl( ldc ) | 'i';
     136        sepReset( os, temp );                                                           // reset separator
    130137        return os;
    131138} // ?|?
     
    134141ostype * ?|?( ostype *os, const char *cp ) {
    135142        enum { Open = 1, Close, OpenClose };
    136         static const char mask[256] = {
     143        static const unsigned char mask[256] = {
    137144                // opening delimiters
    138145                ['('] : Open, ['['] : Open, ['{'] : Open,
    139                 ['$'] : Open, [L'£'] : Open, [L'¥'] : Open, [L'¢'] : Open, [L'¿'] : Open, [L'«'] : Open,
     146                ['$'] : Open, [(unsigned char)'£'] : Open, [(unsigned char)'¥'] : Open,
     147                [(unsigned char)'¡'] : Open, [(unsigned char)'¿'] : Open, [(unsigned char)'«'] : Open,
    140148                // closing delimiters
    141149                [','] : Close, ['.'] : Close, [':'] : Close, [';'] : Close, ['!'] : Close, ['?'] : Close,
    142150                [')'] : Close, [']'] : Close, ['}'] : Close,
    143                 ['%'] : Close, [L'»'] : Close,
     151                ['%'] : Close, [(unsigned char)'¢'] : Close, [(unsigned char)'»'] : Close,
    144152                // opening-closing delimiters
    145153                ['\''] : OpenClose, ['`'] : OpenClose, ['"'] : OpenClose,
     154                [' '] : OpenClose, ['\f'] : OpenClose, ['\n'] : OpenClose, ['\r'] : OpenClose, ['\t'] : OpenClose, ['\v'] : OpenClose, // isspace
    146155        }; // mask
    147156
    148         int len = strlen( cp );
    149         // null string => no separator
    150   if ( len == 0 ) { sepOff( os ); return os; }
    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 ) {
     157  if ( cp[0] == '\0' ) { sepOff( os ); return os; }             // null string => no separator
     158
     159        // first character IS NOT spacing or closing punctuation => add left separator
     160        unsigned char ch = cp[0];                                                       // must make unsigned
     161        if ( sepPrt( os ) && mask[ ch ] != Close && mask[ ch ] != OpenClose ) {
    153162                prtfmt( os, "%s", sepGet( os ) );
    154163        } // if
     164
     165        // if string starts line, must reset to determine open state because separator is off
     166        sepReset( os );                                                                         // reset separator
     167
    155168        // last character IS spacing or opening punctuation => turn off separator for next item
    156         unsigned int posn = len - 1;
    157         if ( isspace( cp[posn] ) || mask[ cp[posn] ] == Open || mask[ cp[posn] ] == OpenClose ) {
     169        unsigned int len = strlen( cp ), posn = len - 1;
     170        ch = cp[posn];                                                                          // must make unsigned
     171        if ( sepPrt( os ) && mask[ ch ] != Open && mask[ ch ] != OpenClose ) {
     172                sepOn( os );
     173        } else {
    158174                sepOff( os );
    159         } else {
    160                 sepOn( os );
    161175        } // if
    162176        return write( os, cp, len );
     
    165179forall( dtype ostype | ostream( ostype ) )
    166180ostype * ?|?( ostype *os, const void *p ) {
    167         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     181        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    168182        prtfmt( os, "%p", p );
    169183        return os;
    170184} // ?|?
    171 
    172185
    173186forall( dtype ostype | ostream( ostype ) )
     
    196209} // sepOff
    197210
     211forall( dtype ostype | ostream( ostype ) )
     212ostype * sepEnable( ostype * os ) {
     213        sepEnable( os );
     214        return os;
     215} // sepEnable
     216
     217forall( dtype ostype | ostream( ostype ) )
     218ostype * sepDisable( ostype * os ) {
     219        sepDisable( os );
     220        return os;
     221} // sepDisable
     222
    198223//---------------------------------------
    199224
     
    310335} // ?|?
    311336
    312 _Istream_str1 str( char * s ) { _Istream_str1 s = { s }; return s; }
    313 forall( dtype istype | istream( istype ) )
    314 istype * ?|?( 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; }
    320 forall( dtype istype | istream( istype ) )
    321 istype * ?|?( istype * is, _Istream_str2 str ) {
     337_Istream_cstrUC cstr( char * s ) { _Istream_cstrUC s = { s }; return s; }
     338forall( dtype istype | istream( istype ) )
     339istype * ?|?( istype * is, _Istream_cstrUC cstr ) {
     340        scanfmt( is, "%s", cstr.s );
     341        return is;
     342} // cstr
     343
     344_Istream_cstrC cstr( char * s, int size ) { _Istream_cstrC s = { s, size }; return s; }
     345forall( dtype istype | istream( istype ) )
     346istype * ?|?( istype * is, _Istream_cstrC cstr ) {
    322347        char buf[16];
    323         sprintf( buf, "%%%ds", str.size );
    324         scanfmt( is, buf, str.s );
    325         return is;
    326 } // str
     348        sprintf( buf, "%%%ds", cstr.size );
     349        scanfmt( is, buf, cstr.s );
     350        return is;
     351} // cstr
    327352
    328353// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.