Ignore:
Timestamp:
Mar 21, 2017, 10:04:47 PM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
87d13cd
Parents:
89d129c
Message:

add tuple separator to sout

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/iostream.c

    r89d129c r829c907  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Mar  6 20:52:02 2017
    13 // Update Count     : 313
     12// Last Modified On : Tue Mar 21 20:58:48 2017
     13// Update Count     : 347
    1414//
    1515
     
    2424
    2525forall( dtype ostype | ostream( ostype ) )
    26 ostype * ?|?( ostype *os, char c ) {
    27         prtfmt( os, "%c", c );
    28         sepOff( os );
    29         return os;
    30 } // ?|?
    31 
    32 forall( dtype ostype | ostream( ostype ) )
    33 ostype * ?|?( ostype *os, signed char c ) {
    34         prtfmt( os, "%hhd", c );
    35         sepOff( os );
    36         return os;
    37 } // ?|?
    38 
    39 forall( dtype ostype | ostream( ostype ) )
    40 ostype * ?|?( ostype *os, unsigned char c ) {
    41         prtfmt( os, "%hhu", c );
    42         sepOff( os );
    43         return os;
    44 } // ?|?
    45 
    46 forall( dtype ostype | ostream( ostype ) )
    47 ostype * ?|?( ostype *os, short int si ) {
    48         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    49         prtfmt( os, "%hd", si );
    50         return os;
    51 } // ?|?
    52 
    53 forall( dtype ostype | ostream( ostype ) )
    54 ostype * ?|?( ostype *os, unsigned short int usi ) {
    55         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    56         prtfmt( os, "%hu", usi );
    57         return os;
    58 } // ?|?
    59 
    60 forall( dtype ostype | ostream( ostype ) )
    61 ostype * ?|?( ostype *os, int i ) {
    62         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    63         prtfmt( os, "%d", i );
    64         return os;
    65 } // ?|?
    66 
    67 forall( dtype ostype | ostream( ostype ) )
    68 ostype * ?|?( ostype *os, unsigned int ui ) {
    69         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    70         prtfmt( os, "%u", ui );
    71         return os;
    72 } // ?|?
    73 
    74 forall( dtype ostype | ostream( ostype ) )
    75 ostype * ?|?( ostype *os, long int li ) {
    76         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    77         prtfmt( os, "%ld", li );
    78         return os;
    79 } // ?|?
    80 
    81 forall( dtype ostype | ostream( ostype ) )
    82 ostype * ?|?( ostype *os, unsigned long int uli ) {
    83         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    84         prtfmt( os, "%lu", uli );
    85         return os;
    86 } // ?|?
    87 
    88 forall( dtype ostype | ostream( ostype ) )
    89 ostype * ?|?( ostype *os, long long int lli ) {
    90         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    91         prtfmt( os, "%lld", lli );
    92         return os;
    93 } // ?|?
    94 
    95 forall( dtype ostype | ostream( ostype ) )
    96 ostype * ?|?( ostype *os, unsigned long long int ulli ) {
    97         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    98         prtfmt( os, "%llu", ulli );
    99         return os;
    100 } // ?|?
    101 
    102 forall( dtype ostype | ostream( ostype ) )
    103 ostype * ?|?( ostype *os, float f ) {
    104         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    105         prtfmt( os, "%g", f );
    106         return os;
    107 } // ?|?
    108 
    109 forall( dtype ostype | ostream( ostype ) )
    110 ostype * ?|?( ostype *os, double d ) {
    111         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    112         prtfmt( os, "%.*lg", DBL_DIG, d );
    113         return os;
    114 } // ?|?
    115 
    116 forall( dtype ostype | ostream( ostype ) )
    117 ostype * ?|?( ostype *os, long double ld ) {
    118         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    119         prtfmt( os, "%.*Lg", LDBL_DIG, ld );
    120         return os;
    121 } // ?|?
    122 
    123 forall( dtype ostype | ostream( ostype ) )
    124 ostype * ?|?( ostype *os, float _Complex fc ) {
     26ostype * ?|?( ostype * os, char c ) {
     27        fmt( os, "%c", c );
     28        sepOff( os );
     29        return os;
     30} // ?|?
     31
     32forall( dtype ostype | ostream( ostype ) )
     33ostype * ?|?( ostype * os, signed char c ) {
     34        fmt( os, "%hhd", c );
     35        sepOff( os );
     36        return os;
     37} // ?|?
     38
     39forall( dtype ostype | ostream( ostype ) )
     40ostype * ?|?( ostype * os, unsigned char c ) {
     41        fmt( os, "%hhu", c );
     42        sepOff( os );
     43        return os;
     44} // ?|?
     45
     46forall( dtype ostype | ostream( ostype ) )
     47ostype * ?|?( ostype * os, short int si ) {
     48        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     49        fmt( os, "%hd", si );
     50        return os;
     51} // ?|?
     52
     53forall( dtype ostype | ostream( ostype ) )
     54ostype * ?|?( ostype * os, unsigned short int usi ) {
     55        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     56        fmt( os, "%hu", usi );
     57        return os;
     58} // ?|?
     59
     60forall( dtype ostype | ostream( ostype ) )
     61ostype * ?|?( ostype * os, int i ) {
     62        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     63        fmt( os, "%d", i );
     64        return os;
     65} // ?|?
     66
     67forall( dtype ostype | ostream( ostype ) )
     68ostype * ?|?( ostype * os, unsigned int ui ) {
     69        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     70        fmt( os, "%u", ui );
     71        return os;
     72} // ?|?
     73
     74forall( dtype ostype | ostream( ostype ) )
     75ostype * ?|?( ostype * os, long int li ) {
     76        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     77        fmt( os, "%ld", li );
     78        return os;
     79} // ?|?
     80
     81forall( dtype ostype | ostream( ostype ) )
     82ostype * ?|?( ostype * os, unsigned long int uli ) {
     83        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     84        fmt( os, "%lu", uli );
     85        return os;
     86} // ?|?
     87
     88forall( dtype ostype | ostream( ostype ) )
     89ostype * ?|?( ostype * os, long long int lli ) {
     90        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     91        fmt( os, "%lld", lli );
     92        return os;
     93} // ?|?
     94
     95forall( dtype ostype | ostream( ostype ) )
     96ostype * ?|?( ostype * os, unsigned long long int ulli ) {
     97        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     98        fmt( os, "%llu", ulli );
     99        return os;
     100} // ?|?
     101
     102forall( dtype ostype | ostream( ostype ) )
     103ostype * ?|?( ostype * os, float f ) {
     104        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     105        fmt( os, "%g", f );
     106        return os;
     107} // ?|?
     108
     109forall( dtype ostype | ostream( ostype ) )
     110ostype * ?|?( ostype * os, double d ) {
     111        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     112        fmt( os, "%.*lg", DBL_DIG, d );
     113        return os;
     114} // ?|?
     115
     116forall( dtype ostype | ostream( ostype ) )
     117ostype * ?|?( ostype * os, long double ld ) {
     118        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     119        fmt( os, "%.*Lg", LDBL_DIG, ld );
     120        return os;
     121} // ?|?
     122
     123forall( dtype ostype | ostream( ostype ) )
     124ostype * ?|?( ostype * os, float _Complex fc ) {
    125125        os | crealf( fc );
    126126        _Bool temp = sepDisable( os );                                          // disable separators within complex value
     
    132132
    133133forall( dtype ostype | ostream( ostype ) )
    134 ostype * ?|?( ostype *os, double _Complex dc ) {
     134ostype * ?|?( ostype * os, double _Complex dc ) {
    135135        os | creal( dc );
    136136        _Bool temp = sepDisable( os );                                          // disable separators within complex value
     
    142142
    143143forall( dtype ostype | ostream( ostype ) )
    144 ostype * ?|?( ostype *os, long double _Complex ldc ) {
     144ostype * ?|?( ostype * os, long double _Complex ldc ) {
    145145        os | creall( ldc );
    146146        _Bool temp = sepDisable( os );                                          // disable separators within complex value
     
    152152
    153153forall( dtype ostype | ostream( ostype ) )
    154 ostype * ?|?( ostype *os, const char *cp ) {
     154ostype * ?|?( ostype * os, const char * cp ) {
    155155        enum { Open = 1, Close, OpenClose };
    156156        static const unsigned char mask[256] = {
     
    161161                // closing delimiters, no space before
    162162                [','] : Close, ['.'] : Close, [':'] : Close, [';'] : Close, ['!'] : Close, ['?'] : Close,
     163                ['%'] : Close, [(unsigned char)'¢'] : Close, [(unsigned char)'»'] : Close,
    163164                [')'] : Close, [']'] : Close, ['}'] : Close,
    164                 ['%'] : Close, [(unsigned char)'¢'] : Close, [(unsigned char)'»'] : Close,
    165165                // opening-closing delimiters, no space before or after
    166166                ['\''] : OpenClose, ['`'] : OpenClose, ['"'] : OpenClose,
     
    173173        unsigned char ch = cp[0];                                                       // must make unsigned
    174174        if ( sepPrt( os ) && mask[ ch ] != Close && mask[ ch ] != OpenClose ) {
    175                 prtfmt( os, "%s", sepGet( os ) );
     175                fmt( os, "%s", sepGetCur( os ) );
    176176        } // if
    177177
     
    191191
    192192forall( dtype ostype | ostream( ostype ) )
    193 ostype * ?|?( ostype *os, const void *p ) {
    194         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
    195         prtfmt( os, "%p", p );
     193ostype * ?|?( ostype * os, const void * p ) {
     194        if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     195        fmt( os, "%p", p );
    196196        return os;
    197197} // ?|?
     
    201201forall( dtype ostype, otype T, ttype Params | ostream( ostype ) | writeable( T ) | { ostype * ?|?( ostype *, Params ); } )
    202202ostype * ?|?( ostype * os, T arg, Params rest ) {
    203         os | arg | ", ";
    204         os | rest;
     203        sepSetCur( os, sepGetTuple( os ) );                                     // switch to tuple separator
     204        os | arg;                                                                                       // print first argument
     205        os | rest;                                                                                      // print remaining arguments
     206        sepSetCur( os, sepGet( os ) );                                          // switch to regular separator
    205207} // ?|?
    206208
     
    247249
    248250forall( otype elttype | writeable( elttype ), otype iteratortype | iterator( iteratortype, elttype ), dtype ostype | ostream( ostype ) )
    249 void write( iteratortype begin, iteratortype end, ostype *os ) {
     251void write( iteratortype begin, iteratortype end, ostype * os ) {
    250252        void print( elttype i ) { os | i; }
    251253        for_each( begin, end, print );
     
    253255
    254256forall( otype elttype | writeable( elttype ), otype iteratortype | iterator( iteratortype, elttype ), dtype ostype | ostream( ostype ) )
    255 void write_reverse( iteratortype begin, iteratortype end, ostype *os ) {
     257void write_reverse( iteratortype begin, iteratortype end, ostype * os ) {
    256258        void print( elttype i ) { os | i; }
    257259        for_each_reverse( begin, end, print );
     
    262264forall( dtype istype | istream( istype ) )
    263265istype * ?|?( istype * is, char * c ) {
    264         scanfmt( is, "%c", c );
     266        fmt( is, "%c", c );
    265267        return is;
    266268} // ?|?
     
    268270forall( dtype istype | istream( istype ) )
    269271istype * ?|?( istype * is, short int * si ) {
    270         scanfmt( is, "%hd", si );
     272        fmt( is, "%hd", si );
    271273        return is;
    272274} // ?|?
     
    274276forall( dtype istype | istream( istype ) )
    275277istype * ?|?( istype * is, unsigned short int * usi ) {
    276         scanfmt( is, "%hu", usi );
     278        fmt( is, "%hu", usi );
    277279        return is;
    278280} // ?|?
     
    280282forall( dtype istype | istream( istype ) )
    281283istype * ?|?( istype * is, int * i ) {
    282         scanfmt( is, "%d", i );
     284        fmt( is, "%d", i );
    283285        return is;
    284286} // ?|?
     
    286288forall( dtype istype | istream( istype ) )
    287289istype * ?|?( istype * is, unsigned int * ui ) {
    288         scanfmt( is, "%u", ui );
     290        fmt( is, "%u", ui );
    289291        return is;
    290292} // ?|?
     
    292294forall( dtype istype | istream( istype ) )
    293295istype * ?|?( istype * is, long int * li ) {
    294         scanfmt( is, "%ld", li );
     296        fmt( is, "%ld", li );
    295297        return is;
    296298} // ?|?
     
    298300forall( dtype istype | istream( istype ) )
    299301istype * ?|?( istype * is, unsigned long int * ulli ) {
    300         scanfmt( is, "%lu", ulli );
     302        fmt( is, "%lu", ulli );
    301303        return is;
    302304} // ?|?
     
    304306forall( dtype istype | istream( istype ) )
    305307istype * ?|?( istype * is, long long int * lli ) {
    306         scanfmt( is, "%lld", lli );
     308        fmt( is, "%lld", lli );
    307309        return is;
    308310} // ?|?
     
    310312forall( dtype istype | istream( istype ) )
    311313istype * ?|?( istype * is, unsigned long long int * ulli ) {
    312         scanfmt( is, "%llu", ulli );
     314        fmt( is, "%llu", ulli );
    313315        return is;
    314316} // ?|?
     
    317319forall( dtype istype | istream( istype ) )
    318320istype * ?|?( istype * is, float * f ) {
    319         scanfmt( is, "%f", f );
     321        fmt( is, "%f", f );
    320322        return is;
    321323} // ?|?
     
    323325forall( dtype istype | istream( istype ) )
    324326istype * ?|?( istype * is, double * d ) {
    325         scanfmt( is, "%lf", d );
     327        fmt( is, "%lf", d );
    326328        return is;
    327329} // ?|?
     
    329331forall( dtype istype | istream( istype ) )
    330332istype * ?|?( istype * is, long double * ld ) {
    331         scanfmt( is, "%Lf", ld );
     333        fmt( is, "%Lf", ld );
    332334        return is;
    333335} // ?|?
     
    337339istype * ?|?( istype * is, float _Complex * fc ) {
    338340        float re, im;
    339         scanfmt( is, "%g%gi", &re, &im );
     341        fmt( is, "%g%gi", &re, &im );
    340342        *fc = re + im * _Complex_I;
    341343        return is;
     
    345347istype * ?|?( istype * is, double _Complex * dc ) {
    346348        double re, im;
    347         scanfmt( is, "%lf%lfi", &re, &im );
     349        fmt( is, "%lf%lfi", &re, &im );
    348350        *dc = re + im * _Complex_I;
    349351        return is;
     
    353355istype * ?|?( istype * is, long double _Complex * ldc ) {
    354356        long double re, im;
    355         scanfmt( is, "%Lf%Lfi", &re, &im );
     357        fmt( is, "%Lf%Lfi", &re, &im );
    356358        *ldc = re + im * _Complex_I;
    357359        return is;
     
    361363forall( dtype istype | istream( istype ) )
    362364istype * ?|?( istype * is, _Istream_cstrUC cstr ) {
    363         scanfmt( is, "%s", cstr.s );
     365        fmt( is, "%s", cstr.s );
    364366        return is;
    365367} // cstr
     
    370372        char buf[16];
    371373        sprintf( buf, "%%%ds", cstr.size );
    372         scanfmt( is, buf, cstr.s );
     374        fmt( is, buf, cstr.s );
    373375        return is;
    374376} // cstr
Note: See TracChangeset for help on using the changeset viewer.