Changeset 2a301ff for libcfa/src/iostream.cfa
- Timestamp:
- Aug 31, 2023, 11:31:15 PM (2 years ago)
- 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. - File:
-
- 1 edited
-
libcfa/src/iostream.cfa (modified) (69 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/iostream.cfa
r92355883 r2a301ff 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 9 09:27:58202313 // Update Count : 1 36112 // Last Modified On : Thu Aug 31 11:27:56 2023 13 // Update Count : 1545 14 14 // 15 15 … … 21 21 #include <float.h> // DBL_DIG, LDBL_DIG 22 22 #include <complex.h> // creal, cimag 23 //#include <string.h> // strlen, strcmp, memcpy 23 //#include <stdio.h> 24 24 25 extern "C" { 25 26 extern size_t strlen (const char *__s) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); … … 34 35 #pragma GCC visibility push(default) 35 36 37 36 38 // *********************************** ostream *********************************** 37 39 … … 43 45 return os; 44 46 } // ?|? 45 void ?|?( ostype & os, bool b ) { 46 (ostype &)(os | b); ends( os ); 47 } // ?|? 47 OSTYPE_VOID_IMPL( bool ) 48 48 49 49 ostype & ?|?( ostype & os, char c ) { 50 50 fmt( os, "%c", c ); 51 51 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 ) 57 55 58 56 ostype & ?|?( ostype & os, signed char sc ) { … … 61 59 return os; 62 60 } // ?|? 63 void ?|?( ostype & os, signed char sc ) { 64 (ostype &)(os | sc); ends( os ); 65 } // ?|? 61 OSTYPE_VOID_IMPL( signed char ) 66 62 67 63 ostype & ?|?( ostype & os, unsigned char usc ) { … … 70 66 return os; 71 67 } // ?|? 72 void ?|?( ostype & os, unsigned char usc ) { 73 (ostype &)(os | usc); ends( os ); 74 } // ?|? 68 OSTYPE_VOID_IMPL( unsigned char ) 75 69 76 70 ostype & ?|?( ostype & os, short int si ) { … … 79 73 return os; 80 74 } // ?|? 81 void & ?|?( ostype & os, short int si ) { 82 (ostype &)(os | si); ends( os ); 83 } // ?|? 75 OSTYPE_VOID_IMPL( short int ) 84 76 85 77 ostype & ?|?( ostype & os, unsigned short int usi ) { … … 88 80 return os; 89 81 } // ?|? 90 void & ?|?( ostype & os, unsigned short int usi ) { 91 (ostype &)(os | usi); ends( os ); 92 } // ?|? 82 OSTYPE_VOID_IMPL( unsigned short int ) 93 83 94 84 ostype & ?|?( ostype & os, int i ) { … … 97 87 return os; 98 88 } // ?|? 99 void & ?|?( ostype & os, int i ) { 100 (ostype &)(os | i); ends( os ); 101 } // ?|? 89 OSTYPE_VOID_IMPL( int ) 102 90 103 91 ostype & ?|?( ostype & os, unsigned int ui ) { … … 106 94 return os; 107 95 } // ?|? 108 void & ?|?( ostype & os, unsigned int ui ) { 109 (ostype &)(os | ui); ends( os ); 110 } // ?|? 96 OSTYPE_VOID_IMPL( unsigned int ) 111 97 112 98 ostype & ?|?( ostype & os, long int li ) { … … 115 101 return os; 116 102 } // ?|? 117 void & ?|?( ostype & os, long int li ) { 118 (ostype &)(os | li); ends( os ); 119 } // ?|? 103 OSTYPE_VOID_IMPL( long int ) 120 104 121 105 ostype & ?|?( ostype & os, unsigned long int uli ) { … … 124 108 return os; 125 109 } // ?|? 126 void & ?|?( ostype & os, unsigned long int uli ) { 127 (ostype &)(os | uli); ends( os ); 128 } // ?|? 110 OSTYPE_VOID_IMPL( unsigned long int ) 129 111 130 112 ostype & ?|?( ostype & os, long long int lli ) { … … 133 115 return os; 134 116 } // ?|? 135 void & ?|?( ostype & os, long long int lli ) { 136 (ostype &)(os | lli); ends( os ); 137 } // ?|? 117 OSTYPE_VOID_IMPL( long long int ) 138 118 139 119 ostype & ?|?( ostype & os, unsigned long long int ulli ) { … … 142 122 return os; 143 123 } // ?|? 144 void & ?|?( ostype & os, unsigned long long int ulli ) { 145 (ostype &)(os | ulli); ends( os ); 146 } // ?|? 124 OSTYPE_VOID_IMPL( unsigned long long int ) 147 125 148 126 #if defined( __SIZEOF_INT128__ ) … … 176 154 return os; 177 155 } // ?|? 178 void & ?|?( ostype & os, int128 llli ) { 179 (ostype &)(os | llli); ends( os ); 180 } // ?|? 156 OSTYPE_VOID_IMPL( int128 ) 181 157 182 158 ostype & ?|?( ostype & os, unsigned int128 ullli ) { … … 185 161 return os; 186 162 } // ?|? 187 void & ?|?( ostype & os, unsigned int128 ullli ) { 188 (ostype &)(os | ullli); ends( os ); 189 } // ?|? 163 OSTYPE_VOID_IMPL( unsigned int128 ) 190 164 #endif // __SIZEOF_INT128__ 191 165 192 #define P rintWithDP( os, format, val, ... ) \166 #define PRINT_WITH_DP( os, format, val, ... ) \ 193 167 { \ 194 168 enum { size = 48 }; \ … … 199 173 for ( i; 0 ~ @ ) { \ 200 174 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 ? */ \ 202 177 } /* for */ \ 203 178 } /* if */ \ … … 206 181 ostype & ?|?( ostype & os, float f ) { 207 182 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 ) 214 187 215 188 ostype & ?|?( ostype & os, double d ) { 216 189 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 ) 223 194 224 195 ostype & ?|?( ostype & os, long double ld ) { 225 196 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 ) 232 201 233 202 ostype & ?|?( ostype & os, float _Complex fc ) { 234 203 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 235 204 // os | crealf( fc ) | nonl; 236 P rintWithDP( os, "%'g", crealf( fc ) );237 P rintWithDP( os, "%'+g", cimagf( fc ) );205 PRINT_WITH_DP( os, "%'g", crealf( fc ) ); 206 PRINT_WITH_DP( os, "%'+g", cimagf( fc ) ); 238 207 fmt( os, "i" ); 239 208 return os; 240 209 } // ?|? 241 void & ?|?( ostype & os, float _Complex fc ) { 242 (ostype &)(os | fc); ends( os ); 243 } // ?|? 210 OSTYPE_VOID_IMPL( float _Complex ) 244 211 245 212 ostype & ?|?( ostype & os, double _Complex dc ) { 246 213 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 247 214 // os | creal( dc ) | nonl; 248 P rintWithDP( os, "%'.*lg", creal( dc ), DBL_DIG );249 P rintWithDP( 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 ); 250 217 fmt( os, "i" ); 251 218 return os; 252 219 } // ?|? 253 void & ?|?( ostype & os, double _Complex dc ) { 254 (ostype &)(os | dc); ends( os ); 255 } // ?|? 220 OSTYPE_VOID_IMPL( double _Complex ) 256 221 257 222 ostype & ?|?( ostype & os, long double _Complex ldc ) { 258 223 if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 259 224 // os | creall( ldc ) || nonl; 260 P rintWithDP( os, "%'.*Lg", creall( ldc ), LDBL_DIG );261 P rintWithDP( 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 ); 262 227 fmt( os, "i" ); 263 228 return os; 264 229 } // ?|? 265 void & ?|?( ostype & os, long double _Complex ldc ) { 266 (ostype &)(os | ldc); ends( os ); 267 } // ?|? 230 OSTYPE_VOID_IMPL( long double _Complex ) 268 231 269 232 ostype & ?|?( ostype & os, const char s[] ) { 270 233 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 272 235 // opening delimiters, no space after 273 236 ['('] : Open, ['['] : Open, ['{'] : Open, … … 284 247 285 248 if ( s == 0p ) { fmt( os, "%s", "0p" ); return os; } // null pointer 286 if ( s[0] == '\0' ) { sepOff( os ); return os; } // null string => noseparator249 if ( s[0] == '\0' ) { nosep( os ); return os; } // null string => no leading/trailing separator 287 250 288 251 // first character IS NOT spacing or closing punctuation => add left separator … … 300 263 fmt( os, "%s", s ); // fmt resets seperator, but reset it again 301 264 if ( sepPrt$( os ) && mask[ ch ] != Open && mask[ ch ] != OpenClose ) { 302 sep On( os );265 sep( os ); 303 266 } else { 304 sepOff( os );267 nosep( os ); 305 268 } // if 306 269 if ( ch == '\n' ) setNL$( os, true ); // check *AFTER* sepPrt$ call above as it resets NL flag … … 308 271 // return write( os, s, len ); 309 272 } // ?|? 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[] ) { 315 276 // if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 316 277 // fmt( os, "%ls", s ); … … 319 280 320 281 // #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[] ) { 322 283 // if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 323 284 // fmt( os, "%ls", s ); … … 326 287 // #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) 327 288 328 // ostype & ?|?( ostype & os, const wchar_t * s) {289 // ostype & ?|?( ostype & os, const wchar_t s[] ) { 329 290 // if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); 330 291 // fmt( os, "%ls", s ); … … 337 298 return os; 338 299 } // ?|? 339 void ?|?( ostype & os, const void * p ) { 340 (ostype &)(os | p); ends( os ); 341 } // ?|? 300 OSTYPE_VOID_IMPL( const void * ) 342 301 343 302 // manipulators … … 351 310 } // ?|? 352 311 353 ostype & sep( ostype & os ) {354 return (ostype &)(os | sepGet( os ));355 } // sep356 357 ostype & sepTuple( ostype & os ) {358 return os | sepGetTuple( os );359 } // sepTuple360 361 312 ostype & nl( ostype & os ) { 362 313 (ostype &)(os | '\n'); 363 314 setPrt$( os, false ); // turn off 364 315 setNL$( os, true ); 365 return sepOff( os );// prepare for next line316 return nosep( os ); // prepare for next line 366 317 } // nl 367 318 … … 371 322 } // nonl 372 323 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 373 352 ostype & sepOn( ostype & os ) { 374 353 sepOn( os ); // call void returning … … 380 359 return os; 381 360 } // sepOff 382 383 ostype & sepEnable( ostype & os ) {384 sepEnable( os ); // call void returning385 return os;386 } // sepEnable387 388 ostype & sepDisable( ostype & os ) {389 sepDisable( os ); // call void returning390 return os;391 } // sepDisable392 393 ostype & nlOn( ostype & os ) {394 nlOn( os ); // call void returning395 return os;396 } // nlOn397 398 ostype & nlOff( ostype & os ) {399 nlOff( os ); // call void returning400 return os;401 } // nlOff402 361 } // distribution 403 362 … … 442 401 443 402 // Default prefix for non-decimal prints is 0b, 0, 0x. 444 #define I ntegralFMTImpl( T, IFMTNP, IFMTP ) \403 #define INTEGRAL_FMT_IMPL( T, IFMTNP, IFMTP ) \ 445 404 forall( ostype & | basic_ostream( ostype ) ) { \ 446 405 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \ … … 508 467 fmtstr[star] = '%'; \ 509 468 \ 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 \ 510 476 if ( ! f.flags.pc ) { /* no precision */ \ 511 477 fmtstr[sizeof(IFMTNP)-2] = f.base; /* sizeof includes '\0' */ \ … … 519 485 return os; \ 520 486 } /* ?|? */ \ 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 490 INTEGRAL_FMT_IMPL( signed char, " *hh ", " *.*hh " ) 491 INTEGRAL_FMT_IMPL( unsigned char, " *hh ", " *.*hh " ) 492 INTEGRAL_FMT_IMPL( signed short int, " *h ", " *.*h " ) 493 INTEGRAL_FMT_IMPL( unsigned short int, " *h ", " *.*h " ) 494 INTEGRAL_FMT_IMPL( signed int, " * ", " *.* " ) 495 INTEGRAL_FMT_IMPL( unsigned int, " * ", " *.* " ) 496 INTEGRAL_FMT_IMPL( signed long int, " *l ", " *.*l " ) 497 INTEGRAL_FMT_IMPL( unsigned long int, " *l ", " *.*l " ) 498 INTEGRAL_FMT_IMPL( signed long long int, " *ll ", " *.*ll " ) 499 INTEGRAL_FMT_IMPL( unsigned long long int, " *ll ", " *.*ll " ) 536 500 537 501 … … 550 514 if ( cnt == 1 ) { 551 515 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 chunks516 nosep( os ); // no seperator between chunks 553 517 } // if 554 518 } else { // print start chunk … … 595 559 else { f.pc = maxdig; f.flags.pc = true; } // left pad with precision 596 560 597 if ( cnt != 0 ) sepOff( os ); // no seperator between chunks561 if ( cnt != 0 ) nosep( os ); // no seperator between chunks 598 562 f.wd = wd; // reset f.wd for next chunk 599 563 f.flags.sign = false; // no leading +/- sign … … 602 566 } // base_128 603 567 604 #define I ntegralFMTImpl128( T ) \568 #define INTEGRAL_FMT_IMPL128( T ) \ 605 569 forall( ostype & | basic_ostream( ostype ) ) { \ 606 570 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \ … … 619 583 return os; \ 620 584 } /* ?|? */ \ 621 void ?|?( ostype & os, _Ostream_Manip(T) f ) { (ostype &)(os | f); ends( os ); }\622 } // distribution 623 624 I ntegralFMTImpl128( int128 )625 I ntegralFMTImpl128( unsigned int128 )585 OSTYPE_VOID_IMPL( _Ostream_Manip(T) ) \ 586 } // distribution 587 588 INTEGRAL_FMT_IMPL128( int128 ) 589 INTEGRAL_FMT_IMPL128( unsigned int128 ) 626 590 #endif // __SIZEOF_INT128__ 627 591 … … 635 599 #define SUFFIXES_END (SUFFIXES_START + (int)((sizeof(suffixes) / sizeof(char *) - 1) * 3)) 636 600 637 #define P rintWithDP2( os, format, ... ) \601 #define PRINT_WITH_DP2( os, format, ... ) \ 638 602 { \ 639 603 if ( ! f.flags.eng ) { \ 640 604 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 ? */ \ 643 608 if ( i == len ) { \ 644 609 if ( ! f.flags.left ) { \ … … 676 641 } 677 642 678 #define F loatingPointFMTImpl( T, DFMTNP, DFMTP ) \643 #define FLOATING_POINT_FMT_IMPL( T, DFMTNP, DFMTP ) \ 679 644 forall( ostype & | basic_ostream( ostype ) ) { \ 680 645 static void eng( T &value, int & pc, int & exp10 ) { \ … … 707 672 fmtstr[sizeof(DFMTNP)-2] = f.base; /* sizeof includes '\0' */ \ 708 673 /* printf( "%g %d %s\n", f.val, f.wd, &fmtstr[star] ); */ \ 709 P rintWithDP2( os, &fmtstr[star], f.wd, f.val ) \674 PRINT_WITH_DP2( os, &fmtstr[star], f.wd, f.val ) \ 710 675 } else { /* precision */ \ 711 676 fmtstr[sizeof(DFMTP)-2] = f.base; /* sizeof includes '\0' */ \ 712 677 /* printf( "%g %d %d %s\n", f.val, f.wd, f.pc, &fmtstr[star] ); */ \ 713 P rintWithDP2( os, &fmtstr[star], f.wd, f.pc, f.val ) \678 PRINT_WITH_DP2( os, &fmtstr[star], f.wd, f.pc, f.val ) \ 714 679 } /* if */ \ 715 680 return os; \ 716 681 } /* ?|? */ \ 717 682 \ 718 void ?|?( ostype & os, _Ostream_Manip(T) f ) { (ostype &)(os | f); ends( os ); }\719 } // distribution 720 721 F loatingPointFMTImpl( double, " * ", " *.* " )722 F loatingPointFMTImpl( long double, " *L ", " *.*L " )683 OSTYPE_VOID_IMPL( _Ostream_Manip(T) ) \ 684 } // distribution 685 686 FLOATING_POINT_FMT_IMPL( double, " * ", " *.* " ) 687 FLOATING_POINT_FMT_IMPL( long double, " *L ", " *.*L " ) 723 688 724 689 // *********************************** character *********************************** … … 751 716 return os; 752 717 } // ?|? 753 754 void ?|?( ostype & os, _Ostream_Manip(char) f ) { (ostype &)(os | f); ends( os ); } 718 OSTYPE_VOID_IMPL( _Ostream_Manip(char) ) 755 719 } // distribution 756 720 … … 773 737 } // if 774 738 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 ) ); 776 741 777 742 #define SFMTNP "% * " … … 795 760 fmt( os, &fmtstr[star], f.wd, f.pc, f.val ); 796 761 } // 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 *) ) 801 766 } // distribution 802 767 … … 817 782 return is; 818 783 } // ?|? 819 void ?|?( istype & is, bool & b ) { 820 (istype &)(is | b); ends( is ); 821 } // ?|? 784 ISTYPE_VOID_IMPL( bool & ) 822 785 823 786 istype & ?|?( istype & is, char & c ) { … … 831 794 return is; 832 795 } // ?|? 833 void ?|?( istype & is, char & c ) { 834 (istype &)(is | c); ends( is ); 835 } // ?|? 796 ISTYPE_VOID_IMPL( char & ) 836 797 837 798 istype & ?|?( istype & is, signed char & sc ) { … … 839 800 return is; 840 801 } // ?|? 841 void ?|?( istype & is, signed char & sc ) { 842 (istype &)(is | sc); ends( is ); 843 } // ?|? 802 ISTYPE_VOID_IMPL( signed char & ) 844 803 845 804 istype & ?|?( istype & is, unsigned char & usc ) { … … 847 806 return is; 848 807 } // ?|? 849 void ?|?( istype & is, unsigned char & usc ) { 850 (istype &)(is | usc); ends( is ); 851 } // ?|? 808 ISTYPE_VOID_IMPL( unsigned char & ) 852 809 853 810 istype & ?|?( istype & is, short int & si ) { … … 855 812 return is; 856 813 } // ?|? 857 void ?|?( istype & is, short int & si ) { 858 (istype &)(is | si); ends( is ); 859 } // ?|? 814 ISTYPE_VOID_IMPL( short int & ) 860 815 861 816 istype & ?|?( istype & is, unsigned short int & usi ) { … … 863 818 return is; 864 819 } // ?|? 865 void ?|?( istype & is, unsigned short int & usi ) { 866 (istype &)(is | usi); ends( is ); 867 } // ?|? 820 ISTYPE_VOID_IMPL( unsigned short int & ) 868 821 869 822 istype & ?|?( istype & is, int & i ) { … … 871 824 return is; 872 825 } // ?|? 873 void ?|?( istype & is, int & i ) { 874 (istype &)(is | i); ends( is ); 875 } // ?|? 826 ISTYPE_VOID_IMPL( int & ) 876 827 877 828 istype & ?|?( istype & is, unsigned int & ui ) { … … 879 830 return is; 880 831 } // ?|? 881 void ?|?( istype & is, unsigned int & ui ) { 882 (istype &)(is | ui); ends( is ); 883 } // ?|? 832 ISTYPE_VOID_IMPL( unsigned int & ) 884 833 885 834 istype & ?|?( istype & is, long int & li ) { … … 887 836 return is; 888 837 } // ?|? 889 void ?|?( istype & is, long int & li ) { 890 (istype &)(is | li); ends( is ); 891 } // ?|? 838 ISTYPE_VOID_IMPL( long int & ) 892 839 893 840 istype & ?|?( istype & is, unsigned long int & ulli ) { … … 895 842 return is; 896 843 } // ?|? 897 void ?|?( istype & is, unsigned long int & ulli ) { 898 (istype &)(is | ulli); ends( is ); 899 } // ?|? 844 ISTYPE_VOID_IMPL( unsigned long int & ) 900 845 901 846 istype & ?|?( istype & is, long long int & lli ) { … … 903 848 return is; 904 849 } // ?|? 905 void ?|?( istype & is, long long int & lli ) { 906 (istype &)(is | lli); ends( is ); 907 } // ?|? 850 ISTYPE_VOID_IMPL( long long int & ) 908 851 909 852 istype & ?|?( istype & is, unsigned long long int & ulli ) { … … 911 854 return is; 912 855 } // ?|? 913 void & ?|?( istype & is, unsigned long long int & ulli ) { 914 (istype &)(is | ulli); ends( is ); 915 } // ?|? 856 ISTYPE_VOID_IMPL( unsigned long long int & ) 916 857 917 858 #if defined( __SIZEOF_INT128__ ) … … 919 860 return (istype &)(is | (unsigned int128 &)llli); 920 861 } // ?|? 921 void ?|?( istype & is, int128 & llli ) { 922 (istype &)(is | llli); ends( is ); 923 } // ?|? 862 ISTYPE_VOID_IMPL( int128 & ) 924 863 925 864 istype & ?|?( istype & is, unsigned int128 & ullli ) { … … 938 877 return is; 939 878 } // ?|? 940 void ?|?( istype & is, unsigned int128 & ullli ) { 941 (istype &)(is | ullli); ends( is ); 942 } // ?|? 879 ISTYPE_VOID_IMPL( unsigned int128 & ) 943 880 #endif // __SIZEOF_INT128__ 944 881 … … 947 884 return is; 948 885 } // ?|? 949 void ?|?( istype & is, float & f ) { 950 (istype &)(is | f); ends( is ); 951 } // ?|? 886 ISTYPE_VOID_IMPL( float & ) 952 887 953 888 istype & ?|?( istype & is, double & d ) { … … 955 890 return is; 956 891 } // ?|? 957 void ?|?( istype & is, double & d ) { 958 (istype &)(is | d); ends( is ); 959 } // ?|? 892 ISTYPE_VOID_IMPL( double & ) 960 893 961 894 istype & ?|?( istype & is, long double & ld ) { … … 963 896 return is; 964 897 } // ?|? 965 void ?|?( istype & is, long double & ld ) { 966 (istype &)(is | ld); ends( is ); 967 } // ?|? 898 ISTYPE_VOID_IMPL( long double & ) 968 899 969 900 istype & ?|?( istype & is, float _Complex & fc ) { … … 973 904 return is; 974 905 } // ?|? 975 void ?|?( istype & is, float _Complex & fc ) { 976 (istype &)(is | fc); ends( is ); 977 } // ?|? 906 ISTYPE_VOID_IMPL( float _Complex & ) 978 907 979 908 istype & ?|?( istype & is, double _Complex & dc ) { … … 983 912 return is; 984 913 } // ?|? 985 void ?|?( istype & is, double _Complex & dc ) { 986 (istype &)(is | dc); ends( is ); 987 } // ?|? 914 ISTYPE_VOID_IMPL( double _Complex & ) 988 915 989 916 istype & ?|?( istype & is, long double _Complex & ldc ) { … … 993 920 return is; 994 921 } // ?|? 995 void ?|?( istype & is, long double _Complex & ldc ) { 996 (istype &)(is | ldc); ends( is ); 997 } // ?|? 922 ISTYPE_VOID_IMPL( long double _Complex & ) 998 923 999 924 // istype & ?|?( istype & is, const char fmt[] ) { … … 1002 927 // } // ?|? 1003 928 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 * ) 1011 934 1012 935 // manipulators … … 1014 937 return manip( is ); 1015 938 } // ?|? 939 1016 940 void ?|?( istype & is, istype & (* manip)( istype & ) ) { 1017 941 manip( is ); ends( is ); … … 1020 944 istype & nl( istype & is ) { 1021 945 fmt( is, "%*[^\n]" ); // ignore characters to newline 946 if ( ! eof( is ) && getANL$( is ) ) fmt( is, "%*c" ); // read newline 1022 947 return is; 1023 948 } // nl … … 1038 963 forall( istype & | basic_istream( istype ) ) { 1039 964 istype & ?|?( istype & is, _Istream_Cstr f ) { 1040 // skip xxx965 // skip 1041 966 if ( ! f.s ) { 1042 967 // printf( "skip %s %d\n", f.scanset, f.wd ); 1043 if ( f.wd == -1 ) fmt( is, f.scanset, "" ); // no input arguments968 if ( f.wd == -1 ) fmt( is, f.scanset, "" ); // no input arguments 1044 969 else for ( f.wd ) fmt( is, "%*c" ); 1045 970 return is; 1046 971 } // if 972 973 const char * scanset = f.scanset; 974 if ( f.flags.delimit ) scanset = f.delimit; // getline ? 975 1047 976 size_t len = 0; 1048 if ( f.scanset ) len = strlen( f.scanset );977 if ( scanset ) len = strlen( scanset ); 1049 978 char fmtstr[len + 16]; 1050 979 int start = 1; … … 1052 981 if ( f.flags.ignore ) { fmtstr[1] = '*'; start += 1; } 1053 982 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 1056 986 fmtstr[start] = 's'; fmtstr[start + 1] = '\0'; 1057 987 // 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 ) 1075 1014 1076 1015 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 ) \ 1086 1023 forall( istype & | basic_istream( istype ) ) { \ 1087 1024 istype & ?|?( istype & is, _Istream_Manip(T) f ) { \ … … 1097 1034 return is; \ 1098 1035 } /* ?|? */ \ 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 1039 INPUT_FMT_IMPL( signed char, "hhi" ) 1040 INPUT_FMT_IMPL( unsigned char, "hhi" ) 1041 INPUT_FMT_IMPL( signed short int, "hi" ) 1042 INPUT_FMT_IMPL( unsigned short int, "hi" ) 1043 INPUT_FMT_IMPL( signed int, "i" ) 1044 INPUT_FMT_IMPL( unsigned int, "i" ) 1045 INPUT_FMT_IMPL( signed long int, "li" ) 1046 INPUT_FMT_IMPL( unsigned long int, "li" ) 1047 INPUT_FMT_IMPL( signed long long int, "lli" ) 1048 INPUT_FMT_IMPL( unsigned long long int, "lli" ) 1049 1050 INPUT_FMT_IMPL( float, "f" ) 1051 INPUT_FMT_IMPL( double, "lf" ) 1052 INPUT_FMT_IMPL( long double, "Lf" ) 1118 1053 1119 1054 forall( istype & | basic_istream( istype ) ) { … … 1127 1062 return is; 1128 1063 } // ?|? 1129 void ?|?( istype & is, _Istream_Manip(float _Complex) fc ) { 1130 (istype &)(is | fc); ends( is ); 1131 } // ?|? 1064 ISTYPE_VOID_IMPL( _Istream_Manip(float _Complex) ) 1132 1065 1133 1066 istype & ?|?( istype & is, _Istream_Manip(double _Complex) dc ) { … … 1140 1073 return is; 1141 1074 } // ?|? 1142 void ?|?( istype & is, _Istream_Manip(double _Complex) dc ) { 1143 (istype &)(is | dc); ends( is ); 1144 } // ?|? 1075 ISTYPE_VOID_IMPL( _Istream_Manip(double _Complex) ) 1145 1076 1146 1077 istype & ?|?( istype & is, _Istream_Manip(long double _Complex) ldc ) { … … 1153 1084 return is; 1154 1085 } // ?|? 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 1159 1089 1160 1090 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.