Changes in libcfa/src/iostream.cfa [4f37255:dc5072f]
- File:
-
- 1 edited
-
libcfa/src/iostream.cfa (modified) (40 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/iostream.cfa
r4f37255 rdc5072f 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 13 08:07:59201913 // Update Count : 8 2112 // Last Modified On : Thu Jun 13 17:21:10 2019 13 // Update Count : 812 14 14 // 15 15 … … 30 30 31 31 32 //*********************************** ostream ***********************************32 //*********************************** Ostream *********************************** 33 33 34 34 … … 40 40 } // ?|? 41 41 void ?|?( ostype & os, zero_t z ) { 42 (ostype &)(os | z); ends( os );42 (ostype &)(os | z); nl( os ); 43 43 } // ?|? 44 44 … … 49 49 } // ?|? 50 50 void ?|?( ostype & os, one_t o ) { 51 (ostype &)(os | o); ends( os );51 (ostype &)(os | o); nl( os ); 52 52 } // ?|? 53 53 … … 58 58 } // ?|? 59 59 void ?|?( ostype & os, bool b ) { 60 (ostype &)(os | b); ends( os );60 (ostype &)(os | b); nl( os ); 61 61 } // ?|? 62 62 … … 67 67 } // ?|? 68 68 void ?|?( ostype & os, char c ) { 69 (ostype &)(os | c); ends( os );69 (ostype &)(os | c); nl( os ); 70 70 } // ?|? 71 71 … … 76 76 } // ?|? 77 77 void ?|?( ostype & os, signed char sc ) { 78 (ostype &)(os | sc); ends( os );78 (ostype &)(os | sc); nl( os ); 79 79 } // ?|? 80 80 … … 85 85 } // ?|? 86 86 void ?|?( ostype & os, unsigned char usc ) { 87 (ostype &)(os | usc); ends( os );87 (ostype &)(os | usc); nl( os ); 88 88 } // ?|? 89 89 … … 94 94 } // ?|? 95 95 void & ?|?( ostype & os, short int si ) { 96 (ostype &)(os | si); ends( os );96 (ostype &)(os | si); nl( os ); 97 97 } // ?|? 98 98 … … 103 103 } // ?|? 104 104 void & ?|?( ostype & os, unsigned short int usi ) { 105 (ostype &)(os | usi); ends( os );105 (ostype &)(os | usi); nl( os ); 106 106 } // ?|? 107 107 … … 112 112 } // ?|? 113 113 void & ?|?( ostype & os, int i ) { 114 (ostype &)(os | i); ends( os );114 (ostype &)(os | i); nl( os ); 115 115 } // ?|? 116 116 … … 121 121 } // ?|? 122 122 void & ?|?( ostype & os, unsigned int ui ) { 123 (ostype &)(os | ui); ends( os );123 (ostype &)(os | ui); nl( os ); 124 124 } // ?|? 125 125 … … 130 130 } // ?|? 131 131 void & ?|?( ostype & os, long int li ) { 132 (ostype &)(os | li); ends( os );132 (ostype &)(os | li); nl( os ); 133 133 } // ?|? 134 134 … … 139 139 } // ?|? 140 140 void & ?|?( ostype & os, unsigned long int uli ) { 141 (ostype &)(os | uli); ends( os );141 (ostype &)(os | uli); nl( os ); 142 142 } // ?|? 143 143 … … 148 148 } // ?|? 149 149 void & ?|?( ostype & os, long long int lli ) { 150 (ostype &)(os | lli); ends( os );150 (ostype &)(os | lli); nl( os ); 151 151 } // ?|? 152 152 … … 157 157 } // ?|? 158 158 void & ?|?( ostype & os, unsigned long long int ulli ) { 159 (ostype &)(os | ulli); ends( os );159 (ostype &)(os | ulli); nl( os ); 160 160 } // ?|? 161 161 … … 180 180 } // ?|? 181 181 void & ?|?( ostype & os, float f ) { 182 (ostype &)(os | f); ends( os );182 (ostype &)(os | f); nl( os ); 183 183 } // ?|? 184 184 … … 189 189 } // ?|? 190 190 void & ?|?( ostype & os, double d ) { 191 (ostype &)(os | d); ends( os );191 (ostype &)(os | d); nl( os ); 192 192 } // ?|? 193 193 … … 198 198 } // ?|? 199 199 void & ?|?( ostype & os, long double ld ) { 200 (ostype &)(os | ld); ends( os );200 (ostype &)(os | ld); nl( os ); 201 201 } // ?|? 202 202 … … 210 210 } // ?|? 211 211 void & ?|?( ostype & os, float _Complex fc ) { 212 (ostype &)(os | fc); ends( os );212 (ostype &)(os | fc); nl( os ); 213 213 } // ?|? 214 214 … … 222 222 } // ?|? 223 223 void & ?|?( ostype & os, double _Complex dc ) { 224 (ostype &)(os | dc); ends( os );224 (ostype &)(os | dc); nl( os ); 225 225 } // ?|? 226 226 … … 234 234 } // ?|? 235 235 void & ?|?( ostype & os, long double _Complex ldc ) { 236 (ostype &)(os | ldc); ends( os );236 (ostype &)(os | ldc); nl( os ); 237 237 } // ?|? 238 238 … … 276 276 } // ?|? 277 277 void ?|?( ostype & os, const char * str ) { 278 (ostype &)(os | str); ends( os );278 (ostype &)(os | str); nl( os ); 279 279 } // ?|? 280 280 … … 305 305 } // ?|? 306 306 void ?|?( ostype & os, const void * p ) { 307 (ostype &)(os | p); ends( os );307 (ostype &)(os | p); nl( os ); 308 308 } // ?|? 309 309 … … 315 315 void ?|?( ostype & os, ostype & (* manip)( ostype & ) ) { 316 316 (ostype &)(manip( os )); 317 if ( getPrt( os ) ) ends( os ); // something printed ?317 if ( getPrt( os ) ) nl( os ); // something printed ? 318 318 setPrt( os, false ); // turn off 319 319 } // ?|? … … 335 335 } // nl 336 336 337 void nl( ostype & os ) { 338 if ( getANL( os ) ) (ostype &)(nl( os )); // implementation only 339 else setPrt( os, false ); // turn off 340 } // nl 341 337 342 ostype & nonl( ostype & os ) { 338 343 setPrt( os, false ); // turn off … … 381 386 } // ?|? 382 387 void ?|?( ostype & os, T arg, Params rest ) { 383 // (ostype &)(?|?( os, arg, rest )); ends( os );388 // (ostype &)(?|?( os, arg, rest )); nl( os ); 384 389 (ostype &)(os | arg); // print first argument 385 390 sepSetCur( os, sepGetTuple( os ) ); // switch to tuple separator 386 391 (ostype &)(os | rest); // print remaining arguments 387 392 sepSetCur( os, sepGet( os ) ); // switch to regular separator 388 ends( os );393 nl( os ); 389 394 } // ?|? 390 395 } // distribution … … 403 408 } // distribution 404 409 405 //*********************************** manipulators ***********************************406 407 //*********************************** integral ***********************************410 //*********************************** Manipulators *********************************** 411 412 //*********************************** Integral *********************************** 408 413 409 414 static const char * shortbin[] = { "0", "1", "10", "11", "100", "101", "110", "111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111" }; … … 473 478 return os; \ 474 479 } /* ?|? */ \ 475 void ?|?( ostype & os, _Ostream_Manip(T) f ) { (ostype &)(os | f); ends( os ); } \480 void ?|?( ostype & os, _Ostream_Manip(T) f ) { (ostype &)(os | f); nl( os ); } \ 476 481 } // distribution 477 482 … … 487 492 IntegralFMTImpl( unsigned long long int, 'u', "% *ll ", "% *.*ll " ) 488 493 489 //*********************************** floating point ***********************************494 //*********************************** Floating Point *********************************** 490 495 491 496 #define PrintWithDP2( os, format, val, ... ) \ … … 499 504 if ( ! f.flags.left ) { \ 500 505 buf[i] = '.'; buf[i + 1] = '\0'; \ 501 if ( buf[0] == ' ' ) bufbeg = 1; /* decimal point within width */ \506 if ( buf[0] == ' ' ) bufbeg = 1; /* decimal point within width */ \ 502 507 } else { \ 503 508 for ( i = 0; i < len && buf[i] != ' '; i += 1 ); /* trailing blank ? */ \ … … 536 541 return os; \ 537 542 } /* ?|? */ \ 538 void ?|?( ostype & os, _Ostream_Manip(T) f ) { (ostype &)(os | f); ends( os ); } \543 void ?|?( ostype & os, _Ostream_Manip(T) f ) { (ostype &)(os | f); nl( os ); } \ 539 544 } // distribution 540 545 … … 542 547 FloatingPointFMTImpl( long double, "% *L ", "% *.*L " ) 543 548 544 //*********************************** character ***********************************549 //*********************************** Character *********************************** 545 550 546 551 forall( dtype ostype | ostream( ostype ) ) { 547 552 ostype & ?|?( ostype & os, _Ostream_Manip(char) f ) { 548 if ( f.base != 'c' ) { // bespoke binary/octal/hex format553 if ( f.base != 'c' ) { // bespoke binary/octal/hex format 549 554 _Ostream_Manip(unsigned char) fmtuc @= { f.val, f.wd, f.pc, f.base, {'\0'} }; 550 555 fmtuc.flags.pc = f.flags.pc; … … 558 563 559 564 #define CFMTNP "% * " 560 char fmtstr[sizeof(CFMTNP)]; // sizeof includes '\0'565 char fmtstr[sizeof(CFMTNP)]; // sizeof includes '\0' 561 566 memcpy( &fmtstr, CFMTNP, sizeof(CFMTNP) ); 562 int star = 1; // position before first '*'567 int star = 1; // position before first '*' 563 568 564 569 // Insert flags into spaces before '*', from right to left. … … 566 571 fmtstr[star] = '%'; 567 572 568 fmtstr[sizeof(CFMTNP)-2] = f.base; // sizeof includes '\0'573 fmtstr[sizeof(CFMTNP)-2] = f.base; // sizeof includes '\0' 569 574 // printf( "%d %s\n", f.wd, &fmtstr[star] ); 570 575 fmt( os, &fmtstr[star], f.wd, f.val ); 571 576 return os; 572 577 } // ?|? 573 void ?|?( ostype & os, _Ostream_Manip(char) f ) { (ostype &)(os | f); ends( os ); }578 void ?|?( ostype & os, _Ostream_Manip(char) f ) { (ostype &)(os | f); nl( os ); } 574 579 } // distribution 575 580 576 //*********************************** C string ***********************************581 //*********************************** C String *********************************** 577 582 578 583 forall( dtype ostype | ostream( ostype ) ) { … … 616 621 return os; 617 622 } // ?|? 618 void ?|?( ostype & os, _Ostream_Manip(const char *) f ) { (ostype &)(os | f); ends( os ); }623 void ?|?( ostype & os, _Ostream_Manip(const char *) f ) { (ostype &)(os | f); nl( os ); } 619 624 } // distribution 620 625 621 626 622 //*********************************** istream ***********************************627 //*********************************** Istream *********************************** 623 628 624 629 … … 631 636 else { 632 637 fprintf( stderr, "invalid Boolean constant\n" ); 633 abort(); // cannot use abort stream638 abort(); 634 639 } // if 635 640 return is; … … 639 644 char temp; 640 645 for () { 641 fmt( is, "%c", &temp ); // must pass pointer through varg to fmt646 fmt( is, "%c", &temp ); // must pass pointer through varg to fmt 642 647 // do not overwrite parameter with newline unless appropriate 643 648 if ( temp != '\n' || getANL( is ) ) { c = temp; break; } … … 766 771 } // distribution 767 772 768 //*********************************** manipulators ***********************************773 //*********************************** Manipulators *********************************** 769 774 770 775 forall( dtype istype | istream( istype ) ) … … 773 778 if ( ! f.s ) { 774 779 // printf( "skip %s %d\n", f.scanset, f.wd ); 775 if ( f.wd == -1 ) fmt( is, f.scanset, "" ); // no input arguments780 if ( f.wd == -1 ) fmt( is, f.scanset, "" ); // no input arguments 776 781 else for ( f.wd ) fmt( is, "%*c" ); 777 782 return is;
Note:
See TracChangeset
for help on using the changeset viewer.