Ignore:
Timestamp:
Aug 31, 2023, 11:31:15 PM (2 years ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
950c58e
Parents:
92355883 (diff), 686912c (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:

Resolve conflict

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/iostream.cfa

    r92355883 r2a301ff  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan  9 09:27:58 2023
    13 // Update Count     : 1361
     12// Last Modified On : Thu Aug 31 11:27:56 2023
     13// Update Count     : 1545
    1414//
    1515
     
    2121#include <float.h>                                                                              // DBL_DIG, LDBL_DIG
    2222#include <complex.h>                                                                    // creal, cimag
    23 //#include <string.h>                                                                   // strlen, strcmp, memcpy
     23//#include <stdio.h>
     24
    2425extern "C" {
    2526extern size_t strlen (const char *__s) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
     
    3435#pragma GCC visibility push(default)
    3536
     37
    3638// *********************************** ostream ***********************************
    3739
     
    4345                return os;
    4446        } // ?|?
    45         void ?|?( ostype & os, bool b ) {
    46                 (ostype &)(os | b); ends( os );
    47         } // ?|?
     47        OSTYPE_VOID_IMPL( bool )
    4848
    4949        ostype & ?|?( ostype & os, char c ) {
    5050                fmt( os, "%c", c );
    5151                if ( c == '\n' ) setNL$( os, true );
    52                 return sepOff( os );
    53         } // ?|?
    54         void ?|?( ostype & os, char c ) {
    55                 (ostype &)(os | c); ends( os );
    56         } // ?|?
     52                return nosep( os );
     53        } // ?|?
     54        OSTYPE_VOID_IMPL( char )
    5755
    5856        ostype & ?|?( ostype & os, signed char sc ) {
     
    6159                return os;
    6260        } // ?|?
    63         void ?|?( ostype & os, signed char sc ) {
    64                 (ostype &)(os | sc); ends( os );
    65         } // ?|?
     61        OSTYPE_VOID_IMPL( signed char )
    6662
    6763        ostype & ?|?( ostype & os, unsigned char usc ) {
     
    7066                return os;
    7167        } // ?|?
    72         void ?|?( ostype & os, unsigned char usc ) {
    73                 (ostype &)(os | usc); ends( os );
    74         } // ?|?
     68        OSTYPE_VOID_IMPL( unsigned char )
    7569
    7670        ostype & ?|?( ostype & os, short int si ) {
     
    7973                return os;
    8074        } // ?|?
    81         void & ?|?( ostype & os, short int si ) {
    82                 (ostype &)(os | si); ends( os );
    83         } // ?|?
     75        OSTYPE_VOID_IMPL( short int )
    8476
    8577        ostype & ?|?( ostype & os, unsigned short int usi ) {
     
    8880                return os;
    8981        } // ?|?
    90         void & ?|?( ostype & os, unsigned short int usi ) {
    91                 (ostype &)(os | usi); ends( os );
    92         } // ?|?
     82        OSTYPE_VOID_IMPL( unsigned short int )
    9383
    9484        ostype & ?|?( ostype & os, int i ) {
     
    9787                return os;
    9888        } // ?|?
    99         void & ?|?( ostype & os, int i ) {
    100                 (ostype &)(os | i); ends( os );
    101         } // ?|?
     89        OSTYPE_VOID_IMPL( int )
    10290
    10391        ostype & ?|?( ostype & os, unsigned int ui ) {
     
    10694                return os;
    10795        } // ?|?
    108         void & ?|?( ostype & os, unsigned int ui ) {
    109                 (ostype &)(os | ui); ends( os );
    110         } // ?|?
     96        OSTYPE_VOID_IMPL( unsigned int )
    11197
    11298        ostype & ?|?( ostype & os, long int li ) {
     
    115101                return os;
    116102        } // ?|?
    117         void & ?|?( ostype & os, long int li ) {
    118                 (ostype &)(os | li); ends( os );
    119         } // ?|?
     103        OSTYPE_VOID_IMPL( long int )
    120104
    121105        ostype & ?|?( ostype & os, unsigned long int uli ) {
     
    124108                return os;
    125109        } // ?|?
    126         void & ?|?( ostype & os, unsigned long int uli ) {
    127                 (ostype &)(os | uli); ends( os );
    128         } // ?|?
     110        OSTYPE_VOID_IMPL( unsigned long int )
    129111
    130112        ostype & ?|?( ostype & os, long long int lli ) {
     
    133115                return os;
    134116        } // ?|?
    135         void & ?|?( ostype & os, long long int lli ) {
    136                 (ostype &)(os | lli); ends( os );
    137         } // ?|?
     117        OSTYPE_VOID_IMPL( long long int )
    138118
    139119        ostype & ?|?( ostype & os, unsigned long long int ulli ) {
     
    142122                return os;
    143123        } // ?|?
    144         void & ?|?( ostype & os, unsigned long long int ulli ) {
    145                 (ostype &)(os | ulli); ends( os );
    146         } // ?|?
     124        OSTYPE_VOID_IMPL( unsigned long long int )
    147125
    148126        #if defined( __SIZEOF_INT128__ )
     
    176154                return os;
    177155        } // ?|?
    178         void & ?|?( ostype & os, int128 llli ) {
    179                 (ostype &)(os | llli); ends( os );
    180         } // ?|?
     156        OSTYPE_VOID_IMPL( int128 )
    181157
    182158        ostype & ?|?( ostype & os, unsigned int128 ullli ) {
     
    185161                return os;
    186162        } // ?|?
    187         void & ?|?( ostype & os, unsigned int128 ullli ) {
    188                 (ostype &)(os | ullli); ends( os );
    189         } // ?|?
     163        OSTYPE_VOID_IMPL( unsigned int128 )
    190164        #endif // __SIZEOF_INT128__
    191165
    192         #define PrintWithDP( os, format, val, ... ) \
     166        #define PRINT_WITH_DP( os, format, val, ... ) \
    193167                { \
    194168                        enum { size = 48 }; \
     
    199173                                for ( i; 0 ~ @ ) { \
    200174                                        if ( i == len ) { fmt( os, "." ); break; } \
    201                                         if ( buf[i] == '.' || buf[i] == 'e' || buf[i] == 'E' ) break; /* decimal point or scientific ? */ \
     175                                        if ( buf[i] == '.' || buf[i] == 'e' || buf[i] == 'E' || \
     176                                                 buf[i] == 'p' || buf[i] == 'P' ) break; /* decimal point or scientific ? */ \
    202177                                } /* for */ \
    203178                        } /* if */ \
     
    206181        ostype & ?|?( ostype & os, float f ) {
    207182                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    208                 PrintWithDP( os, "%'g", f );
    209                 return os;
    210         } // ?|?
    211         void & ?|?( ostype & os, float f ) {
    212                 (ostype &)(os | f); ends( os );
    213         } // ?|?
     183                PRINT_WITH_DP( os, "%'g", f );
     184                return os;
     185        } // ?|?
     186        OSTYPE_VOID_IMPL( float )
    214187
    215188        ostype & ?|?( ostype & os, double d ) {
    216189                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    217                 PrintWithDP( os, "%'.*lg", d, DBL_DIG );
    218                 return os;
    219         } // ?|?
    220         void & ?|?( ostype & os, double d ) {
    221                 (ostype &)(os | d); ends( os );
    222         } // ?|?
     190                PRINT_WITH_DP( os, "%'.*lg", d, DBL_DIG );
     191                return os;
     192        } // ?|?
     193        OSTYPE_VOID_IMPL( double )
    223194
    224195        ostype & ?|?( ostype & os, long double ld ) {
    225196                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    226                 PrintWithDP( os, "%'.*Lg", ld, LDBL_DIG );
    227                 return os;
    228         } // ?|?
    229         void & ?|?( ostype & os, long double ld ) {
    230                 (ostype &)(os | ld); ends( os );
    231         } // ?|?
     197                PRINT_WITH_DP( os, "%'.*Lg", ld, LDBL_DIG );
     198                return os;
     199        } // ?|?
     200        OSTYPE_VOID_IMPL( long double )
    232201
    233202        ostype & ?|?( ostype & os, float _Complex fc ) {
    234203                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    235204//              os | crealf( fc ) | nonl;
    236                 PrintWithDP( os, "%'g", crealf( fc ) );
    237                 PrintWithDP( os, "%'+g", cimagf( fc ) );
     205                PRINT_WITH_DP( os, "%'g", crealf( fc ) );
     206                PRINT_WITH_DP( os, "%'+g", cimagf( fc ) );
    238207                fmt( os, "i" );
    239208                return os;
    240209        } // ?|?
    241         void & ?|?( ostype & os, float _Complex fc ) {
    242                 (ostype &)(os | fc); ends( os );
    243         } // ?|?
     210        OSTYPE_VOID_IMPL( float _Complex )
    244211
    245212        ostype & ?|?( ostype & os, double _Complex dc ) {
    246213                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    247214//              os | creal( dc ) | nonl;
    248                 PrintWithDP( os, "%'.*lg", creal( dc ), DBL_DIG );
    249                 PrintWithDP( os, "%'+.*lg", cimag( dc ), DBL_DIG );
     215                PRINT_WITH_DP( os, "%'.*lg", creal( dc ), DBL_DIG );
     216                PRINT_WITH_DP( os, "%'+.*lg", cimag( dc ), DBL_DIG );
    250217                fmt( os, "i" );
    251218                return os;
    252219        } // ?|?
    253         void & ?|?( ostype & os, double _Complex dc ) {
    254                 (ostype &)(os | dc); ends( os );
    255         } // ?|?
     220        OSTYPE_VOID_IMPL( double _Complex )
    256221
    257222        ostype & ?|?( ostype & os, long double _Complex ldc ) {
    258223                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    259224//              os | creall( ldc ) || nonl;
    260                 PrintWithDP( os, "%'.*Lg", creall( ldc ), LDBL_DIG );
    261                 PrintWithDP( os, "%'+.*Lg", cimagl( ldc ), LDBL_DIG );
     225                PRINT_WITH_DP( os, "%'.*Lg", creall( ldc ), LDBL_DIG );
     226                PRINT_WITH_DP( os, "%'+.*Lg", cimagl( ldc ), LDBL_DIG );
    262227                fmt( os, "i" );
    263228                return os;
    264229        } // ?|?
    265         void & ?|?( ostype & os, long double _Complex ldc ) {
    266                 (ostype &)(os | ldc); ends( os );
    267         } // ?|?
     230        OSTYPE_VOID_IMPL( long double _Complex )
    268231
    269232        ostype & ?|?( ostype & os, const char s[] ) {
    270233                enum { Open = 1, Close, OpenClose };
    271                 static const unsigned char mask[256] @= {
     234                static const unsigned char mask[256] @= {               // 256 covers all Latin-1 characters
    272235                        // opening delimiters, no space after
    273236                        ['('] : Open, ['['] : Open, ['{'] : Open,
     
    284247
    285248          if ( s == 0p ) { fmt( os, "%s", "0p" ); return os; } // null pointer
    286           if ( s[0] == '\0' ) { sepOff( os ); return os; } // null string => no separator
     249          if ( s[0] == '\0' ) { nosep( os ); return os; }       // null string => no leading/trailing separator
    287250
    288251                // first character IS NOT spacing or closing punctuation => add left separator
     
    300263                fmt( os, "%s", s );                                                             // fmt resets seperator, but reset it again
    301264                if ( sepPrt$( os ) && mask[ ch ] != Open && mask[ ch ] != OpenClose ) {
    302                         sepOn( os );
     265                        sep( os );
    303266                } else {
    304                         sepOff( os );
     267                        nosep( os );
    305268                } // if
    306269                if ( ch == '\n' ) setNL$( os, true );                   // check *AFTER* sepPrt$ call above as it resets NL flag
     
    308271//              return write( os, s, len );
    309272        } // ?|?
    310         void ?|?( ostype & os, const char s[] ) {
    311                 (ostype &)(os | s); ends( os );
    312         } // ?|?
    313 
    314 //      ostype & ?|?( ostype & os, const char16_t * s ) {
     273        OSTYPE_VOID_IMPL( const char * )
     274
     275//      ostype & ?|?( ostype & os, const char16_t s[] ) {
    315276//              if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    316277//              fmt( os, "%ls", s );
     
    319280
    320281// #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous
    321 //      ostype & ?|?( ostype & os, const char32_t * s ) {
     282//      ostype & ?|?( ostype & os, const char32_t s[] ) {
    322283//              if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    323284//              fmt( os, "%ls", s );
     
    326287// #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 )
    327288
    328 //      ostype & ?|?( ostype & os, const wchar_t * s ) {
     289//      ostype & ?|?( ostype & os, const wchar_t s[] ) {
    329290//              if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    330291//              fmt( os, "%ls", s );
     
    337298                return os;
    338299        } // ?|?
    339         void ?|?( ostype & os, const void * p ) {
    340                 (ostype &)(os | p); ends( os );
    341         } // ?|?
     300        OSTYPE_VOID_IMPL( const void * )
    342301
    343302        // manipulators
     
    351310        } // ?|?
    352311
    353         ostype & sep( ostype & os ) {
    354                 return (ostype &)(os | sepGet( os ));
    355         } // sep
    356 
    357         ostype & sepTuple( ostype & os ) {
    358                 return os | sepGetTuple( os );
    359         } // sepTuple
    360 
    361312        ostype & nl( ostype & os ) {
    362313                (ostype &)(os | '\n');
    363314                setPrt$( os, false );                                                   // turn off
    364315                setNL$( os, true );
    365                 return sepOff( os );                                                    // prepare for next line
     316                return nosep( os );                                                             // prepare for next line
    366317        } // nl
    367318
     
    371322        } // nonl
    372323
     324        ostype & nlOn( ostype & os ) {
     325                nlOn( os );                                                                             // call void returning
     326                return os;
     327        } // nlOn
     328
     329        ostype & nlOff( ostype & os ) {
     330                nlOff( os );                                                                    // call void returning
     331                return os;
     332        } // nlOff
     333
     334        ostype & sepVal( ostype & os ) {
     335                return (ostype &)(os | sepGet( os ));
     336        } // sepVal
     337
     338        ostype & sepTupleVal( ostype & os ) {
     339                return os | sepGetTuple( os );
     340        } // sepTupleVal
     341
     342        ostype & sep( ostype & os ) {
     343                sep( os );                                                                              // call void returning
     344                return os;
     345        } // sep
     346
     347        ostype & nosep( ostype & os ) {
     348                nosep( os );                                                                    // call void returning
     349                return os;
     350        } // nosep
     351
    373352        ostype & sepOn( ostype & os ) {
    374353                sepOn( os );                                                                    // call void returning
     
    380359                return os;
    381360        } // sepOff
    382 
    383         ostype & sepEnable( ostype & os ) {
    384                 sepEnable( os );                                                                // call void returning
    385                 return os;
    386         } // sepEnable
    387 
    388         ostype & sepDisable( ostype & os ) {
    389                 sepDisable( os );                                                               // call void returning
    390                 return os;
    391         } // sepDisable
    392 
    393         ostype & nlOn( ostype & os ) {
    394                 nlOn( os );                                                                             // call void returning
    395                 return os;
    396         } // nlOn
    397 
    398         ostype & nlOff( ostype & os ) {
    399                 nlOff( os );                                                                    // call void returning
    400                 return os;
    401         } // nlOff
    402361} // distribution
    403362
     
    442401
    443402// Default prefix for non-decimal prints is 0b, 0, 0x.
    444 #define IntegralFMTImpl( T, IFMTNP, IFMTP ) \
     403#define INTEGRAL_FMT_IMPL( T, IFMTNP, IFMTP ) \
    445404forall( ostype & | basic_ostream( ostype ) ) { \
    446405        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \
     
    508467                fmtstr[star] = '%'; \
    509468\
     469                /* Special case printing 0 in hexadecimal as printf does not put the base. */ \
     470                if ( (f.base == 'x' | f.base == 'X') && ! f.flags.nobsdp && f.val == 0 ) { \
     471                        fmt( os, f.base == 'x' ? "0x" : "0X" ); \
     472                        f.wd -= 2; \
     473                        if ( f.wd < 0 ) f.wd = 1; \
     474                } /* if */ \
     475\
    510476                if ( ! f.flags.pc ) {                                                   /* no precision */ \
    511477                        fmtstr[sizeof(IFMTNP)-2] = f.base;                      /* sizeof includes '\0' */ \
     
    519485                return os; \
    520486        } /* ?|? */ \
    521         void ?|?( ostype & os, _Ostream_Manip(T) f ) { \
    522                 (ostype &)(os | f); ends( os ); \
    523         } /* ?|? */ \
    524 } // distribution
    525 
    526 IntegralFMTImpl( signed char,            "      *hh ", "      *.*hh " )
    527 IntegralFMTImpl( unsigned char,          "      *hh ", "      *.*hh " )
    528 IntegralFMTImpl( signed short int,       "      *h ",  "      *.*h " )
    529 IntegralFMTImpl( unsigned short int,     "      *h ",  "      *.*h " )
    530 IntegralFMTImpl( signed int,             "      * ",   "      *.* " )
    531 IntegralFMTImpl( unsigned int,           "      * ",   "      *.* " )
    532 IntegralFMTImpl( signed long int,        "      *l ",  "      *.*l " )
    533 IntegralFMTImpl( unsigned long int,      "      *l ",  "      *.*l " )
    534 IntegralFMTImpl( signed long long int,   "      *ll ", "      *.*ll " )
    535 IntegralFMTImpl( unsigned long long int, "      *ll ", "      *.*ll " )
     487        OSTYPE_VOID_IMPL( _Ostream_Manip(T) ) \
     488} // distribution
     489
     490INTEGRAL_FMT_IMPL( signed char,            "      *hh ", "      *.*hh " )
     491INTEGRAL_FMT_IMPL( unsigned char,          "      *hh ", "      *.*hh " )
     492INTEGRAL_FMT_IMPL( signed short int,       "      *h ",  "      *.*h " )
     493INTEGRAL_FMT_IMPL( unsigned short int,     "      *h ",  "      *.*h " )
     494INTEGRAL_FMT_IMPL( signed int,             "      * ",   "      *.* " )
     495INTEGRAL_FMT_IMPL( unsigned int,           "      * ",   "      *.* " )
     496INTEGRAL_FMT_IMPL( signed long int,        "      *l ",  "      *.*l " )
     497INTEGRAL_FMT_IMPL( unsigned long int,      "      *l ",  "      *.*l " )
     498INTEGRAL_FMT_IMPL( signed long long int,   "      *ll ", "      *.*ll " )
     499INTEGRAL_FMT_IMPL( unsigned long long int, "      *ll ", "      *.*ll " )
    536500
    537501
     
    550514                if ( cnt == 1 ) {
    551515                        if ( f.flags.left ) { wd -= maxdig; f.wd = wd < 0 ? 1 : wd; } // update and restore f.wd for printing end chunk
    552                         sepOff( os );                                                           // no seperator between chunks
     516                        nosep( os );                                                            // no seperator between chunks
    553517                } // if
    554518        } else {                                                                                        // print start chunk
     
    595559                else { f.pc = maxdig; f.flags.pc = true; }              // left pad with precision
    596560
    597                 if ( cnt != 0 ) sepOff( os );                                   // no seperator between chunks
     561                if ( cnt != 0 ) nosep( os );                                    // no seperator between chunks
    598562                f.wd = wd;                                                                              // reset f.wd for next chunk
    599563                f.flags.sign = false;                                                   // no leading +/- sign
     
    602566} // base_128
    603567
    604 #define IntegralFMTImpl128( T ) \
     568#define INTEGRAL_FMT_IMPL128( T ) \
    605569forall( ostype & | basic_ostream( ostype ) ) { \
    606570        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \
     
    619583                return os; \
    620584        } /* ?|? */ \
    621         void ?|?( ostype & os, _Ostream_Manip(T) f ) { (ostype &)(os | f); ends( os ); } \
    622 } // distribution
    623 
    624 IntegralFMTImpl128( int128 )
    625 IntegralFMTImpl128( unsigned int128 )
     585        OSTYPE_VOID_IMPL( _Ostream_Manip(T) ) \
     586} // distribution
     587
     588INTEGRAL_FMT_IMPL128( int128 )
     589INTEGRAL_FMT_IMPL128( unsigned int128 )
    626590#endif // __SIZEOF_INT128__
    627591
     
    635599#define SUFFIXES_END (SUFFIXES_START + (int)((sizeof(suffixes) / sizeof(char *) - 1) * 3))
    636600
    637 #define PrintWithDP2( os, format, ... ) \
     601#define PRINT_WITH_DP2( os, format, ... ) \
    638602        { \
    639603                if ( ! f.flags.eng ) { \
    640604                        len = snprintf( buf, size, format, ##__VA_ARGS__ ); \
    641                         if ( isfinite( f.val ) && ( f.pc != 0 || ! f.flags.nobsdp ) ) { /* if number, print decimal point when no fraction or exponent */ \
    642                                 for ( i = 0; i < len && buf[i] != '.' && buf[i] != 'e' && buf[i] != 'E'; i += 1 ); /* decimal point or scientific ? */ \
     605                        if ( isfinite( f.val ) && ! f.flags.nobsdp ) { /* if number, print decimal point when no fraction or exponent */ \
     606                                for ( i = 0; i < len && buf[i] != '.' && buf[i] != 'e' && buf[i] != 'E' && \
     607                                                         buf[i] != 'p' && buf[i] != 'P'; i += 1 ); /* decimal point or scientific ? */ \
    643608                                if ( i == len ) { \
    644609                                        if ( ! f.flags.left ) { \
     
    676641        }
    677642
    678 #define FloatingPointFMTImpl( T, DFMTNP, DFMTP ) \
     643#define FLOATING_POINT_FMT_IMPL( T, DFMTNP, DFMTP ) \
    679644forall( ostype & | basic_ostream( ostype ) ) { \
    680645        static void eng( T &value, int & pc, int & exp10 ) { \
     
    707672                        fmtstr[sizeof(DFMTNP)-2] = f.base;                      /* sizeof includes '\0' */ \
    708673                        /* printf( "%g %d %s\n", f.val, f.wd, &fmtstr[star] ); */ \
    709                         PrintWithDP2( os, &fmtstr[star], f.wd, f.val ) \
     674                        PRINT_WITH_DP2( os, &fmtstr[star], f.wd, f.val ) \
    710675                } else {                                                                                /* precision */ \
    711676                        fmtstr[sizeof(DFMTP)-2] = f.base;                       /* sizeof includes '\0' */ \
    712677                        /* printf( "%g %d %d %s\n", f.val, f.wd, f.pc, &fmtstr[star] ); */ \
    713                         PrintWithDP2( os, &fmtstr[star], f.wd, f.pc, f.val ) \
     678                        PRINT_WITH_DP2( os, &fmtstr[star], f.wd, f.pc, f.val ) \
    714679                } /* if */ \
    715680                return os; \
    716681        } /* ?|? */ \
    717682\
    718         void ?|?( ostype & os, _Ostream_Manip(T) f ) { (ostype &)(os | f); ends( os ); } \
    719 } // distribution
    720 
    721 FloatingPointFMTImpl( double,      "      * ",  "      *.* " )
    722 FloatingPointFMTImpl( long double, "      *L ", "      *.*L " )
     683        OSTYPE_VOID_IMPL( _Ostream_Manip(T) ) \
     684} // distribution
     685
     686FLOATING_POINT_FMT_IMPL( double,      "      * ",  "      *.* " )
     687FLOATING_POINT_FMT_IMPL( long double, "      *L ", "      *.*L " )
    723688
    724689// *********************************** character ***********************************
     
    751716                return os;
    752717        } // ?|?
    753 
    754         void ?|?( ostype & os, _Ostream_Manip(char) f ) { (ostype &)(os | f); ends( os ); }
     718        OSTYPE_VOID_IMPL( _Ostream_Manip(char) )
    755719} // distribution
    756720
     
    773737                } // if
    774738
    775                 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     739                if ( f.val[0] != '\0' &&                                                // null string => no leading separator
     740                         sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    776741
    777742                #define SFMTNP "% * "
     
    795760                        fmt( os, &fmtstr[star], f.wd, f.pc, f.val );
    796761                } // if
    797                 return os;
    798         } // ?|?
    799 
    800         void ?|?( ostype & os, _Ostream_Manip(const char *) f ) { (ostype &)(os | f); ends( os ); }
     762                if ( f.val[0] == '\0' ) { nosep( os ); }                // null string => no trailing separator
     763                return os;
     764        } // ?|?
     765        OSTYPE_VOID_IMPL( _Ostream_Manip(const char *) )
    801766} // distribution
    802767
     
    817782                return is;
    818783        } // ?|?
    819         void ?|?( istype & is, bool & b ) {
    820                 (istype &)(is | b); ends( is );
    821         } // ?|?
     784        ISTYPE_VOID_IMPL( bool & )
    822785
    823786        istype & ?|?( istype & is, char & c ) {
     
    831794                return is;
    832795        } // ?|?
    833         void ?|?( istype & is, char & c ) {
    834                 (istype &)(is | c); ends( is );
    835         } // ?|?
     796        ISTYPE_VOID_IMPL( char & )
    836797
    837798        istype & ?|?( istype & is, signed char & sc ) {
     
    839800                return is;
    840801        } // ?|?
    841         void ?|?( istype & is, signed char & sc ) {
    842                 (istype &)(is | sc); ends( is );
    843         } // ?|?
     802        ISTYPE_VOID_IMPL( signed char & )
    844803
    845804        istype & ?|?( istype & is, unsigned char & usc ) {
     
    847806                return is;
    848807        } // ?|?
    849         void ?|?( istype & is, unsigned char & usc ) {
    850                 (istype &)(is | usc); ends( is );
    851         } // ?|?
     808        ISTYPE_VOID_IMPL( unsigned char & )
    852809
    853810        istype & ?|?( istype & is, short int & si ) {
     
    855812                return is;
    856813        } // ?|?
    857         void ?|?( istype & is, short int & si ) {
    858                 (istype &)(is | si); ends( is );
    859         } // ?|?
     814        ISTYPE_VOID_IMPL( short int & )
    860815
    861816        istype & ?|?( istype & is, unsigned short int & usi ) {
     
    863818                return is;
    864819        } // ?|?
    865         void ?|?( istype & is, unsigned short int & usi ) {
    866                 (istype &)(is | usi); ends( is );
    867         } // ?|?
     820        ISTYPE_VOID_IMPL( unsigned short int & )
    868821
    869822        istype & ?|?( istype & is, int & i ) {
     
    871824                return is;
    872825        } // ?|?
    873         void ?|?( istype & is, int & i ) {
    874                 (istype &)(is | i); ends( is );
    875         } // ?|?
     826        ISTYPE_VOID_IMPL( int & )
    876827
    877828        istype & ?|?( istype & is, unsigned int & ui ) {
     
    879830                return is;
    880831        } // ?|?
    881         void ?|?( istype & is, unsigned int & ui ) {
    882                 (istype &)(is | ui); ends( is );
    883         } // ?|?
     832        ISTYPE_VOID_IMPL( unsigned int & )
    884833
    885834        istype & ?|?( istype & is, long int & li ) {
     
    887836                return is;
    888837        } // ?|?
    889         void ?|?( istype & is, long int & li ) {
    890                 (istype &)(is | li); ends( is );
    891         } // ?|?
     838        ISTYPE_VOID_IMPL( long int & )
    892839
    893840        istype & ?|?( istype & is, unsigned long int & ulli ) {
     
    895842                return is;
    896843        } // ?|?
    897         void ?|?( istype & is, unsigned long int & ulli ) {
    898                 (istype &)(is | ulli); ends( is );
    899         } // ?|?
     844        ISTYPE_VOID_IMPL( unsigned long int & )
    900845
    901846        istype & ?|?( istype & is, long long int & lli ) {
     
    903848                return is;
    904849        } // ?|?
    905         void ?|?( istype & is, long long int & lli ) {
    906                 (istype &)(is | lli); ends( is );
    907         } // ?|?
     850        ISTYPE_VOID_IMPL( long long int & )
    908851
    909852        istype & ?|?( istype & is, unsigned long long int & ulli ) {
     
    911854                return is;
    912855        } // ?|?
    913         void & ?|?( istype & is, unsigned long long int & ulli ) {
    914                 (istype &)(is | ulli); ends( is );
    915         } // ?|?
     856        ISTYPE_VOID_IMPL( unsigned long long int & )
    916857
    917858        #if defined( __SIZEOF_INT128__ )
     
    919860                return (istype &)(is | (unsigned int128 &)llli);
    920861        } // ?|?
    921         void ?|?( istype & is, int128 & llli ) {
    922                 (istype &)(is | llli); ends( is );
    923         } // ?|?
     862        ISTYPE_VOID_IMPL( int128 & )
    924863
    925864        istype & ?|?( istype & is, unsigned int128 & ullli ) {
     
    938877                return is;
    939878        } // ?|?
    940         void ?|?( istype & is, unsigned int128 & ullli ) {
    941                 (istype &)(is | ullli); ends( is );
    942         } // ?|?
     879        ISTYPE_VOID_IMPL( unsigned int128 & )
    943880        #endif // __SIZEOF_INT128__
    944881
     
    947884                return is;
    948885        } // ?|?
    949         void ?|?( istype & is, float & f ) {
    950                 (istype &)(is | f); ends( is );
    951         } // ?|?
     886        ISTYPE_VOID_IMPL( float & )
    952887
    953888        istype & ?|?( istype & is, double & d ) {
     
    955890                return is;
    956891        } // ?|?
    957         void ?|?( istype & is, double & d ) {
    958                 (istype &)(is | d); ends( is );
    959         } // ?|?
     892        ISTYPE_VOID_IMPL( double & )
    960893
    961894        istype & ?|?( istype & is, long double & ld ) {
     
    963896                return is;
    964897        } // ?|?
    965         void ?|?( istype & is, long double & ld ) {
    966                 (istype &)(is | ld); ends( is );
    967         } // ?|?
     898        ISTYPE_VOID_IMPL( long double & )
    968899
    969900        istype & ?|?( istype & is, float _Complex & fc ) {
     
    973904                return is;
    974905        } // ?|?
    975         void ?|?( istype & is, float _Complex & fc ) {
    976                 (istype &)(is | fc); ends( is );
    977         } // ?|?
     906        ISTYPE_VOID_IMPL( float _Complex & )
    978907
    979908        istype & ?|?( istype & is, double _Complex & dc ) {
     
    983912                return is;
    984913        } // ?|?
    985         void ?|?( istype & is, double _Complex & dc ) {
    986                 (istype &)(is | dc); ends( is );
    987         } // ?|?
     914        ISTYPE_VOID_IMPL( double _Complex & )
    988915
    989916        istype & ?|?( istype & is, long double _Complex & ldc ) {
     
    993920                return is;
    994921        } // ?|?
    995         void ?|?( istype & is, long double _Complex & ldc ) {
    996                 (istype &)(is | ldc); ends( is );
    997         } // ?|?
     922        ISTYPE_VOID_IMPL( long double _Complex & )
    998923
    999924        // istype & ?|?( istype & is, const char fmt[] ) {
     
    1002927        // } // ?|?
    1003928
    1004         istype & ?|?( istype & is, char s[] ) {
    1005                 fmt( is, "%s", s );
    1006                 return is;
    1007         } // ?|?
    1008         void ?|?( istype & is, char s[] ) {
    1009                 (istype &)(is | s); ends( is );
    1010         } // ?|?
     929        // istype & ?|?( istype & is, char s[] ) {
     930        //      fmt( is, "%s", s );
     931        //      return is;
     932        // } // ?|?
     933        // ISTYPE_VOID_IMPL( char * )
    1011934
    1012935        // manipulators
     
    1014937                return manip( is );
    1015938        } // ?|?
     939
    1016940        void ?|?( istype & is, istype & (* manip)( istype & ) ) {
    1017941                manip( is ); ends( is );
     
    1020944        istype & nl( istype & is ) {
    1021945                fmt( is, "%*[^\n]" );                                                   // ignore characters to newline
     946                if ( ! eof( is ) && getANL$( is ) ) fmt( is, "%*c" ); // read newline
    1022947                return is;
    1023948        } // nl
     
    1038963forall( istype & | basic_istream( istype ) ) {
    1039964        istype & ?|?( istype & is, _Istream_Cstr f ) {
    1040                 // skip xxx
     965                // skip
    1041966                if ( ! f.s ) {
    1042967                        // printf( "skip %s %d\n", f.scanset, f.wd );
    1043                         if ( f.wd == -1 ) fmt( is, f.scanset, "" );             // no input arguments
     968                        if ( f.wd == -1 ) fmt( is, f.scanset, "" );     // no input arguments
    1044969                        else for ( f.wd ) fmt( is, "%*c" );
    1045970                        return is;
    1046971                } // if
     972
     973                const char * scanset = f.scanset;
     974                if ( f.flags.delimit ) scanset = f.delimit;             // getline ?
     975
    1047976                size_t len = 0;
    1048                 if ( f.scanset ) len = strlen( f.scanset );
     977                if ( scanset ) len = strlen( scanset );
    1049978                char fmtstr[len + 16];
    1050979                int start = 1;
     
    1052981                if ( f.flags.ignore ) { fmtstr[1] = '*'; start += 1; }
    1053982                if ( f.wd != -1 ) { start += sprintf( &fmtstr[start], "%d", f.wd ); }
    1054                 // cstr %s, %*s, %ws, %*ws
    1055                 if ( ! f.scanset ) {
     983
     984                if ( ! scanset ) {
     985                        // %s, %*s, %ws, %*ws
    1056986                        fmtstr[start] = 's'; fmtstr[start + 1] = '\0';
    1057987                        // printf( "cstr %s\n", fmtstr );
    1058                         fmt( is, fmtstr, f.s );
    1059                         return is;
    1060                 } // if
    1061                 // incl %[xxx],  %*[xxx],  %w[xxx],  %*w[xxx]
    1062                 // excl %[^xxx], %*[^xxx], %w[^xxx], %*w[^xxx]
    1063                 fmtstr[start] = '['; start += 1;
    1064                 if ( f.flags.inex ) { fmtstr[start] = '^'; start += 1; }
    1065                 strcpy( &fmtstr[start], f.scanset );                            // copy includes '\0'
    1066                 len += start;
    1067                 fmtstr[len] = ']'; fmtstr[len + 1] = '\0';
    1068                 // printf( "incl/excl %s\n", fmtstr );
    1069                 fmt( is, fmtstr, f.s );
    1070                 return is;
    1071         } // ?|?
    1072         void ?|?( istype & is, _Istream_Cstr f ) {
    1073                 (istype &)(is | f); ends( is );
    1074         } // ?|?
     988                } else {
     989                        // incl %[xxx],  %*[xxx],  %w[xxx],  %*w[xxx]
     990                        // excl %[^xxx], %*[^xxx], %w[^xxx], %*w[^xxx]
     991                        fmtstr[start] = '['; start += 1;
     992                        if ( f.flags.inex ) { fmtstr[start] = '^'; start += 1; }
     993                        strcpy( &fmtstr[start], scanset );                      // copy includes '\0'
     994                        len += start;
     995                        fmtstr[len] = ']'; fmtstr[len + 1] = '\0';
     996                        // printf( "incl/excl %s\n", fmtstr );
     997                } // if
     998
     999                int check = f.wd - 1;
     1000                if ( ! f.flags.rwd ) f.s[check] = '\0';                 // insert sentinel
     1001                len = fmt( is, fmtstr, f.s );
     1002                //fprintf( stderr, "KK %s %zd %d %c %s\n", fmtstr, len, check, f.s[check], f.s );
     1003
     1004                if ( ! f.flags.rwd && f.s[check] != '\0' )              // sentinel overwritten ?
     1005                        throw (cstring_length){ &cstring_length_vt };
     1006
     1007                if ( f.flags.delimit ) {                                                // getline ?
     1008                        if ( len == 0 ) f.s[0] = '\0';                          // empty read => argument unchanged => set empty
     1009                        if ( ! eof( is ) ) fmt( is, "%*c" );            // ignore delimiter
     1010                } //if
     1011                return is;
     1012        } // ?|?
     1013        ISTYPE_VOID_IMPL( _Istream_Cstr )
    10751014
    10761015        istype & ?|?( istype & is, _Istream_Char f ) {
    1077                 fmt( is, "%*c" );                                                                       // argument variable unused
    1078                 return is;
    1079         } // ?|?
    1080         void ?|?( istype & is, _Istream_Char f ) {
    1081                 (istype &)(is | f); ends( is );
    1082         } // ?|?
    1083 } // distribution
    1084 
    1085 #define InputFMTImpl( T, CODE ) \
     1016                fmt( is, "%*c" );                                                               // argument variable unused
     1017                return is;
     1018        } // ?|?
     1019        ISTYPE_VOID_IMPL( _Istream_Char )
     1020} // distribution
     1021
     1022#define INPUT_FMT_IMPL( T, CODE ) \
    10861023forall( istype & | basic_istream( istype ) ) { \
    10871024        istype & ?|?( istype & is, _Istream_Manip(T) f ) { \
     
    10971034                return is; \
    10981035        } /* ?|? */ \
    1099         void ?|?( istype & is, _Istream_Manip(T) f ) { \
    1100                 (istype &)(is | f); ends( is ); \
    1101         } /* ?|? */ \
    1102 } // distribution
    1103 
    1104 InputFMTImpl( signed char, "hhi" )
    1105 InputFMTImpl( unsigned char, "hhi" )
    1106 InputFMTImpl( signed short int, "hi" )
    1107 InputFMTImpl( unsigned short int, "hi" )
    1108 InputFMTImpl( signed int, "i" )
    1109 InputFMTImpl( unsigned int, "i" )
    1110 InputFMTImpl( signed long int, "li" )
    1111 InputFMTImpl( unsigned long int, "li" )
    1112 InputFMTImpl( signed long long int, "lli" )
    1113 InputFMTImpl( unsigned long long int, "lli" )
    1114 
    1115 InputFMTImpl( float, "f" )
    1116 InputFMTImpl( double, "lf" )
    1117 InputFMTImpl( long double, "Lf" )
     1036        ISTYPE_VOID_IMPL( _Istream_Manip(T) ) \
     1037} // distribution
     1038
     1039INPUT_FMT_IMPL( signed char, "hhi" )
     1040INPUT_FMT_IMPL( unsigned char, "hhi" )
     1041INPUT_FMT_IMPL( signed short int, "hi" )
     1042INPUT_FMT_IMPL( unsigned short int, "hi" )
     1043INPUT_FMT_IMPL( signed int, "i" )
     1044INPUT_FMT_IMPL( unsigned int, "i" )
     1045INPUT_FMT_IMPL( signed long int, "li" )
     1046INPUT_FMT_IMPL( unsigned long int, "li" )
     1047INPUT_FMT_IMPL( signed long long int, "lli" )
     1048INPUT_FMT_IMPL( unsigned long long int, "lli" )
     1049
     1050INPUT_FMT_IMPL( float, "f" )
     1051INPUT_FMT_IMPL( double, "lf" )
     1052INPUT_FMT_IMPL( long double, "Lf" )
    11181053
    11191054forall( istype & | basic_istream( istype ) ) {
     
    11271062                return is;
    11281063        } // ?|?
    1129         void ?|?( istype & is, _Istream_Manip(float _Complex) fc ) {
    1130                 (istype &)(is | fc); ends( is );
    1131         } // ?|?
     1064        ISTYPE_VOID_IMPL( _Istream_Manip(float _Complex) )
    11321065
    11331066        istype & ?|?( istype & is, _Istream_Manip(double _Complex) dc ) {
     
    11401073                return is;
    11411074        } // ?|?
    1142         void ?|?( istype & is, _Istream_Manip(double _Complex) dc ) {
    1143                 (istype &)(is | dc); ends( is );
    1144         } // ?|?
     1075        ISTYPE_VOID_IMPL( _Istream_Manip(double _Complex) )
    11451076
    11461077        istype & ?|?( istype & is, _Istream_Manip(long double _Complex) ldc ) {
     
    11531084                return is;
    11541085        } // ?|?
    1155         void ?|?( istype & is, _Istream_Manip(long double _Complex) ldc ) {
    1156                 (istype &)(is | ldc); ends( is );
    1157         } // ?|?
    1158 } // distribution
     1086        ISTYPE_VOID_IMPL( _Istream_Manip(long double _Complex) )
     1087} // distribution
     1088
    11591089
    11601090// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.