Changeset 61c7239
- Timestamp:
- Jun 9, 2019, 6:23:47 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- a62749f, ca8824d, e7f8119
- Parents:
- 1e6ea4e1
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/iostream.cfa
r1e6ea4e1 r61c7239 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jun 4 17:32:34201913 // Update Count : 76112 // Last Modified On : Sun Jun 9 16:27:17 2019 13 // Update Count : 803 14 14 // 15 15 … … 28 28 #include <complex.h> // creal, cimag 29 29 } // extern "C" 30 31 32 //*********************************** Ostream *********************************** 33 30 34 31 35 forall( dtype ostype | ostream( ostype ) ) { … … 391 395 } // distribution 392 396 397 // writes the range [begin, end) to the given stream 398 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) { 399 void write( iterator_type begin, iterator_type end, ostype & os ) { 400 void print( elt_type i ) { os | i; } 401 for_each( begin, end, print ); 402 } // ?|? 403 404 void write_reverse( iterator_type begin, iterator_type end, ostype & os ) { 405 void print( elt_type i ) { os | i; } 406 for_each_reverse( begin, end, print ); 407 } // ?|? 408 } // distribution 409 410 //*********************************** Manipulators *********************************** 393 411 394 412 //*********************************** Integral *********************************** … … 606 624 } // distribution 607 625 608 //---------------------------------------609 610 // writes the range [begin, end) to the given stream611 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) {612 void write( iterator_type begin, iterator_type end, ostype & os ) {613 void print( elt_type i ) { os | i; }614 for_each( begin, end, print );615 } // ?|?616 617 void write_reverse( iterator_type begin, iterator_type end, ostype & os ) {618 void print( elt_type i ) { os | i; }619 for_each_reverse( begin, end, print );620 } // ?|?621 } // distribution622 623 626 624 627 //*********************************** Istream *********************************** … … 758 761 } // distribution 759 762 760 _Istream_cstrUC cstr( char * str ) { return (_Istream_cstrUC){ str }; } 763 //*********************************** Manipulators *********************************** 764 761 765 forall( dtype istype | istream( istype ) ) 762 istype & ?|?( istype & is, _Istream_cstrUC cstr ) { 763 fmt( is, "%s", cstr.s ); 766 istype & ?|?( istype & is, _Istream_Cstr f ) { 767 // skip xxx 768 if ( ! f.s ) { 769 // printf( "skip %s\n", f.scanset ); 770 fmt( is, f.scanset, "" ); // no input arguments 771 return is; 772 } // if 773 size_t len = 0; 774 if ( f.scanset ) len = strlen( f.scanset ); 775 char fmtstr[len + 16]; 776 int start = 1; 777 fmtstr[0] = '%'; 778 if ( f.flags.ignore ) { fmtstr[1] = '*'; start += 1; } 779 if ( f.wd != -1 ) { start += sprintf( &fmtstr[start], "%d", f.wd ); } 780 // cstr %s, %*s, %ws, %*ws 781 if ( ! f.scanset ) { 782 fmtstr[start] = 's'; fmtstr[start + 1] = '\0'; 783 // printf( "cstr %s\n", fmtstr ); 784 fmt( is, fmtstr, f.s ); 785 return is; 786 } // if 787 // incl %[xxx], %*[xxx], %w[xxx], %*w[xxx] 788 // excl %[^xxx], %*[^xxx], %w[^xxx], %*w[^xxx] 789 fmtstr[start] = '['; start += 1; 790 if ( f.flags.inex ) { fmtstr[start] = '^'; start += 1; } 791 strcpy( &fmtstr[start], f.scanset ); // copy includes '\0' 792 len += start; 793 fmtstr[len] = ']'; fmtstr[len + 1] = '\0'; 794 // printf( "incl/excl %s\n", fmtstr ); 795 fmt( is, fmtstr, f.s ); 764 796 return is; 765 } // cstr 766 767 _Istream_cstrC cstr( char * str, int size ) { return (_Istream_cstrC){ str, size }; } 768 forall( dtype istype | istream( istype ) ) 769 istype & ?|?( istype & is, _Istream_cstrC cstr ) { 770 char buf[16]; 771 sprintf( buf, "%%%ds", cstr.size ); 772 fmt( is, buf, cstr.s ); 773 return is; 774 } // cstr 775 776 #if 0 777 forall( dtype istype | istream( istype ) ) 778 istype & ?|?( istype & is, _Istream_skip skip ) { 779 fmt( is, skip.s, "" ); // no input arguments 780 return is; 781 } // skip 782 783 forall( dtype istype | istream( istype ) ) 784 istype & ?|?( istype & is, _Istream_incl incl ) { 785 size_t len = strlen( incl.scanset ) + 4; // extras: "%[]\0" 786 char fmtstr[len]; 787 fmtstr[0] = '%'; fmtstr[1] = '['; 788 strcpy( &fmtstr[2], incl.scanset ); // after '[', copy includes '\0' 789 fmtstr[len - 2] = ']'; fmtstr[len - 1] = '\0'; 790 fmt( is, fmtstr, incl.s ); 791 return is; 792 } // incl 793 794 forall( dtype istype | istream( istype ) ) 795 istype & ?|?( istype & is, _Istream_excl excl ) { 796 size_t len = strlen( excl.scanset ); 797 char fmtstr[len+5]; 798 fmtstr[0] = '%'; fmtstr[1] = '['; fmtstr[2] = '^'; 799 strcpy( &fmtstr[3], excl.scanset ); // after '^', copy includes '\0' 800 fmtstr[len - 2] = ']'; fmtstr[len - 1] = '\0'; 801 fmt( is, fmtstr, excl.s ); 802 return is; 803 } // excl 804 805 forall( dtype istype | istream( istype ) ) 806 istype & ?|?( istype & is, _Istream_cstr cstr ) { 807 fmt( is, "%s", cstr.s ); 808 return is; 809 } // cstr 810 811 _Istream_cstrW cstr( char * s, int size ) { return (_Istream_cstrW){ s, size }; } 812 forall( dtype istype | istream( istype ) ) 813 istype & ?|?( istype & is, _Istream_cstrW cstr ) { 814 enum { size = 16 }; 815 char fmtstr[size]; 816 sprintf( fmtstr, "%%%ds", cstr.size ); 817 fmt( is, fmtstr, cstr.s ); 818 return is; 819 } // cstr 820 821 forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, _Istream_Cstr ) { 822 823 } 824 825 //*********************************** Manipulators *********************************** 797 } // ?|? 826 798 827 799 #define InputFMTImpl( T, CODE ) \ … … 830 802 enum { size = 16 }; \ 831 803 char fmtstr[size]; \ 832 if ( f.wd == -1 ) {\804 if ( f.wd == -1 || strcmp( CODE, "c" ) == 0 ) { /* ignore width with "c" */ \ 833 805 snprintf( fmtstr, size, "%%%s%s", f.ignore ? "*" : "", CODE ); \ 834 806 } else { \ … … 838 810 fmt( is, fmtstr, &f.val ); \ 839 811 return is; \ 840 } / * ?|? */812 } // ?|? 841 813 842 814 InputFMTImpl( char, "c" ) … … 856 828 InputFMTImpl( long double, "Lf" ) 857 829 858 InputFMTImpl( float _Complex, "ff" ) 859 InputFMTImpl( double _Complex, "lf" ) 860 InputFMTImpl( long double _Complex, "Lf" ) 861 #endif // 0 830 forall( dtype istype | istream( istype ) ) 831 istype & ?|?( istype & is, _Istream_Manip(float _Complex) fc ) { 832 float re, im; 833 _Istream_Manip(float) fmtuc @= { re, fc.wd, fc.ignore }; 834 is | fmtuc; 835 &fmtuc.val = &im; 836 is | fmtuc; 837 if ( ! fc.ignore ) fc.val = re + im * _Complex_I; // re/im are uninitialized for ignore 838 return is; 839 } // ?|? 840 841 forall( dtype istype | istream( istype ) ) 842 istype & ?|?( istype & is, _Istream_Manip(double _Complex) dc ) { 843 double re, im; 844 _Istream_Manip(double) fmtuc @= { re, dc.wd, dc.ignore }; 845 is | fmtuc; 846 &fmtuc.val = &im; 847 is | fmtuc; 848 if ( ! dc.ignore ) dc.val = re + im * _Complex_I; // re/im are uninitialized for ignore 849 return is; 850 } // ?|? 851 852 forall( dtype istype | istream( istype ) ) 853 istype & ?|?( istype & is, _Istream_Manip(long double _Complex) ldc ) { 854 long double re, im; 855 _Istream_Manip(long double) fmtuc @= { re, ldc.wd, ldc.ignore }; 856 is | fmtuc; 857 &fmtuc.val = &im; 858 is | fmtuc; 859 if ( ! ldc.ignore ) ldc.val = re + im * _Complex_I; // re/im are uninitialized for ignore 860 return is; 861 } // ?|? 862 862 863 863 // Local Variables: // -
libcfa/src/iostream.hfa
r1e6ea4e1 r61c7239 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jun 4 17:33:43201913 // Update Count : 28612 // Last Modified On : Sat Jun 8 17:28:44 2019 13 // Update Count : 312 14 14 // 15 15 … … 171 171 //*********************************** Integral *********************************** 172 172 173 // See 6.7.9. 19) The initialization shall occur in initializer list order, each initializer provided for a particular 174 // subobject overriding any previously listed initializer for the same subobject; ***all subobjects that are not 175 // initialized explicitly shall be initialized implicitly the same as objects that have static storage duration.*** 176 173 177 #define IntegralFMTDecl( T, CODE ) \ 174 178 static inline { \ 175 _Ostream_Manip(T) bin( T v ) { return (_Ostream_Manip(T))@{ v, 1, 0, 'b', { .all : 0 } }; } \176 _Ostream_Manip(T) oct( T v ) { return (_Ostream_Manip(T))@{ v, 1, 0, 'o', { .all : 0 } }; } \177 _Ostream_Manip(T) hex( T v ) { return (_Ostream_Manip(T))@{ v, 1, 0, 'x', { .all : 0 } }; } \178 _Ostream_Manip(T) wd( unsigned char w, T v ) { return (_Ostream_Manip(T))@{ v, w, 0, CODE, { .all : 0 } }; } \179 _Ostream_Manip(T) wd( unsigned char w, unsigned char p , T v ) { return (_Ostream_Manip(T))@{ v, w, p, CODE, { .flags.pc : true } }; } \180 _Ostream_Manip(T) & wd( unsigned char w, _Ostream_Manip(T) & fmt ) with(fmt) {wd = w; return fmt; } \181 _Ostream_Manip(T) & wd( unsigned char w, unsigned char p , _Ostream_Manip(T) & fmt ) with(fmt) { wd = w; pc = p;flags.pc = true; return fmt; } \179 _Ostream_Manip(T) bin( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'b', { .all : 0 } }; } \ 180 _Ostream_Manip(T) oct( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'o', { .all : 0 } }; } \ 181 _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'x', { .all : 0 } }; } \ 182 _Ostream_Manip(T) wd( unsigned char w, T val ) { return (_Ostream_Manip(T))@{ val, w, 0, CODE, { .all : 0 } }; } \ 183 _Ostream_Manip(T) wd( unsigned char w, unsigned char pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, CODE, { .flags.pc : true } }; } \ 184 _Ostream_Manip(T) & wd( unsigned char w, _Ostream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \ 185 _Ostream_Manip(T) & wd( unsigned char w, unsigned char pc, _Ostream_Manip(T) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \ 182 186 _Ostream_Manip(T) & left( _Ostream_Manip(T) & fmt ) { fmt.flags.left = true; return fmt; } \ 183 187 _Ostream_Manip(T) & upcase( _Ostream_Manip(T) & fmt ) { if ( fmt.base == 'x' || fmt.base == 'b' ) fmt.base -= 32; /* upper case */ return fmt; } \ 184 188 _Ostream_Manip(T) & nobase( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \ 185 189 _Ostream_Manip(T) & pad0( _Ostream_Manip(T) & fmt ) { fmt.flags.pad0 = true; return fmt; } \ 186 _Ostream_Manip(T) sign( T v ) { return (_Ostream_Manip(T))@{ v, 1, 0, CODE, { .flags.sign : true } }; } \190 _Ostream_Manip(T) sign( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, CODE, { .flags.sign : true } }; } \ 187 191 _Ostream_Manip(T) & sign( _Ostream_Manip(T) & fmt ) { fmt.flags.sign = true; return fmt; } \ 188 192 } \ … … 190 194 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \ 191 195 void ?|?( ostype & os, _Ostream_Manip(T) f ); \ 192 } 196 } // ?|? 193 197 194 198 IntegralFMTDecl( signed char, 'd' ) … … 208 212 #define FloatingPointFMTDecl( T ) \ 209 213 static inline { \ 210 _Ostream_Manip(T) sci( T v ) { return (_Ostream_Manip(T))@{ v, 1, 0, 'e', { .all : 0 } }; } \211 _Ostream_Manip(T) hex( T v ) { return (_Ostream_Manip(T))@{ v, 1, 0, 'a', { .all : 0 } }; } \212 _Ostream_Manip(T) wd( unsigned char w, T v ) { return (_Ostream_Manip(T))@{ v, w, 0, 'f', { .all : 0 } }; } \213 _Ostream_Manip(T) wd( unsigned char w, unsigned char p , T v ) { return (_Ostream_Manip(T))@{ v, w, p, 'f', { .flags.pc : true } }; } \214 _Ostream_Manip(T) ws( unsigned char w, unsigned char p , T v ) { return (_Ostream_Manip(T))@{ v, w, p, 'g', { .flags.pc : true } }; } \215 _Ostream_Manip(T) & wd( unsigned char w, _Ostream_Manip(T) & fmt ) with(fmt) {wd = w; return fmt; } \216 _Ostream_Manip(T) & wd( unsigned char w, unsigned char p , _Ostream_Manip(T) & fmt ) with(fmt) { wd = w; pc = p;flags.pc = true; return fmt; } \214 _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'a', { .all : 0 } }; } \ 215 _Ostream_Manip(T) sci( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'e', { .all : 0 } }; } \ 216 _Ostream_Manip(T) wd( unsigned char w, T val ) { return (_Ostream_Manip(T))@{ val, w, 0, 'f', { .all : 0 } }; } \ 217 _Ostream_Manip(T) wd( unsigned char w, unsigned char pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'f', { .flags.pc : true } }; } \ 218 _Ostream_Manip(T) ws( unsigned char w, unsigned char pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'g', { .flags.pc : true } }; } \ 219 _Ostream_Manip(T) & wd( unsigned char w, _Ostream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \ 220 _Ostream_Manip(T) & wd( unsigned char w, unsigned char pc, _Ostream_Manip(T) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \ 217 221 _Ostream_Manip(T) & left( _Ostream_Manip(T) & fmt ) { fmt.flags.left = true; return fmt; } \ 218 _Ostream_Manip(T) upcase( T v ) { return (_Ostream_Manip(T))@{ v, 1, 0, 'G', { .all : 0 } }; } \222 _Ostream_Manip(T) upcase( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'G', { .all : 0 } }; } \ 219 223 _Ostream_Manip(T) & upcase( _Ostream_Manip(T) & fmt ) { fmt.base -= 32; /* upper case */ return fmt; } \ 220 224 _Ostream_Manip(T) & pad0( _Ostream_Manip(T) & fmt ) { fmt.flags.pad0 = true; return fmt; } \ 221 _Ostream_Manip(T) sign( T v ) { return (_Ostream_Manip(T))@{ v, 1, 0, 'g', { .flags.sign : true } }; } \225 _Ostream_Manip(T) sign( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.sign : true } }; } \ 222 226 _Ostream_Manip(T) & sign( _Ostream_Manip(T) & fmt ) { fmt.flags.sign = true; return fmt; } \ 223 _Ostream_Manip(T) nodp( T v ) { return (_Ostream_Manip(T))@{ v, 1, 0, 'g', { .flags.nobsdp : true } }; } \227 _Ostream_Manip(T) nodp( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.nobsdp : true } }; } \ 224 228 _Ostream_Manip(T) & nodp( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \ 225 229 } \ … … 227 231 ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \ 228 232 void ?|?( ostype & os, _Ostream_Manip(T) f ); \ 229 } 233 } // ?|? 230 234 231 235 FloatingPointFMTDecl( double ) … … 235 239 236 240 static inline { 237 _Ostream_Manip(char) bin( char v ) { return (_Ostream_Manip(char))@{ v, 1, 0, 'b', { .all : 0 } }; }238 _Ostream_Manip(char) oct( char v ) { return (_Ostream_Manip(char))@{ v, 1, 0, 'o', { .all : 0 } }; }239 _Ostream_Manip(char) hex( char v ) { return (_Ostream_Manip(char))@{ v, 1, 0, 'x', { .all : 0 } }; }240 _Ostream_Manip(char) wd( unsigned char w, char v ) { return (_Ostream_Manip(char))@{ v, w, 0, 'c', { .all : 0 } }; }241 _Ostream_Manip(char) & wd( unsigned char w, _Ostream_Manip(char) & fmt ) with(fmt) {wd = w; return fmt; }241 _Ostream_Manip(char) bin( char val ) { return (_Ostream_Manip(char))@{ val, 1, 0, 'b', { .all : 0 } }; } 242 _Ostream_Manip(char) oct( char val ) { return (_Ostream_Manip(char))@{ val, 1, 0, 'o', { .all : 0 } }; } 243 _Ostream_Manip(char) hex( char val ) { return (_Ostream_Manip(char))@{ val, 1, 0, 'x', { .all : 0 } }; } 244 _Ostream_Manip(char) wd( unsigned char w, char val ) { return (_Ostream_Manip(char))@{ val, w, 0, 'c', { .all : 0 } }; } 245 _Ostream_Manip(char) & wd( unsigned char w, _Ostream_Manip(char) & fmt ) { fmt.wd = w; return fmt; } 242 246 _Ostream_Manip(char) & left( _Ostream_Manip(char) & fmt ) { fmt.flags.left = true; return fmt; } 243 247 _Ostream_Manip(char) & upcase( _Ostream_Manip(char) & fmt ) { if ( fmt.base == 'x' || fmt.base == 'b' ) fmt.base -= 32; /* upper case */ return fmt; } … … 247 251 ostype & ?|?( ostype & os, _Ostream_Manip(char) f ); 248 252 void ?|?( ostype & os, _Ostream_Manip(char) f ); 249 } 253 } // ?|? 250 254 251 255 //*********************************** C String *********************************** 252 256 253 257 static inline { 254 _Ostream_Manip(const char *) bin( const char * v ) { return (_Ostream_Manip(const char *))@{ v, 1, 0, 'b', { .all : 0 } }; }255 _Ostream_Manip(const char *) oct( const char * v ) { return (_Ostream_Manip(const char *))@{ v, 1, 0, 'o', { .all : 0 } }; }256 _Ostream_Manip(const char *) hex( const char * v ) { return (_Ostream_Manip(const char *))@{ v, 1, 0, 'x', { .all : 0 } }; }257 _Ostream_Manip(const char *) wd( unsigned char w, const char * v ) { return (_Ostream_Manip(const char *))@{ v, w, 0, 's', { .all : 0 } }; }258 _Ostream_Manip(const char *) wd( unsigned char w, unsigned char p , const char * v ) { return (_Ostream_Manip(const char *))@{ v, w, p, 's', { .flags.pc : true } }; }259 _Ostream_Manip(const char *) & wd( unsigned char w, _Ostream_Manip(const char *) & fmt ) with(fmt) {wd = w; return fmt; }260 _Ostream_Manip(const char *) & wd( unsigned char w, unsigned char p , _Ostream_Manip(const char *) & fmt ) with(fmt) { wd = w; pc = p;flags.pc = true; return fmt; }258 _Ostream_Manip(const char *) bin( const char * val ) { return (_Ostream_Manip(const char *))@{ val, 1, 0, 'b', { .all : 0 } }; } 259 _Ostream_Manip(const char *) oct( const char * val ) { return (_Ostream_Manip(const char *))@{ val, 1, 0, 'o', { .all : 0 } }; } 260 _Ostream_Manip(const char *) hex( const char * val ) { return (_Ostream_Manip(const char *))@{ val, 1, 0, 'x', { .all : 0 } }; } 261 _Ostream_Manip(const char *) wd( unsigned char w, const char * val ) { return (_Ostream_Manip(const char *))@{ val, w, 0, 's', { .all : 0 } }; } 262 _Ostream_Manip(const char *) wd( unsigned char w, unsigned char pc, const char * val ) { return (_Ostream_Manip(const char *))@{ val, w, pc, 's', { .flags.pc : true } }; } 263 _Ostream_Manip(const char *) & wd( unsigned char w, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; return fmt; } 264 _Ostream_Manip(const char *) & wd( unsigned char w, unsigned char pc, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } 261 265 _Ostream_Manip(const char *) & left( _Ostream_Manip(const char *) & fmt ) { fmt.flags.left = true; return fmt; } 262 266 _Ostream_Manip(const char *) & nobase( _Ostream_Manip(const char *) & fmt ) { fmt.flags.nobsdp = true; return fmt; } … … 265 269 ostype & ?|?( ostype & os, _Ostream_Manip(const char *) f ); 266 270 void ?|?( ostype & os, _Ostream_Manip(const char *) f ); 267 } 271 } // ?|? 268 272 269 273 … … 312 316 istype & ?|?( istype &, long double _Complex & ); 313 317 318 // Cannot have char & and char * => cstr manipulator 319 // istype & ?|?( istype &, char * ); 320 314 321 // manipulators 315 322 istype & ?|?( istype &, istype & (*)( istype & ) ); … … 319 326 } // distribution 320 327 321 struct _Istream_cstrUC { char * s; }; 322 _Istream_cstrUC cstr( char * ); 323 forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, _Istream_cstrUC ); 324 325 struct _Istream_cstrC { char * s; int size; }; 326 _Istream_cstrC cstr( char *, int size ); 327 forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, _Istream_cstrC ); 328 329 #if 0 328 //*********************************** Manipulators *********************************** 329 330 330 struct _Istream_Cstr { 331 char * s, * scanset; 331 char * s; 332 const char * scanset; 332 333 int wd; // width 333 bool ignore; // no input argument 334 }; 335 static inline _Istream_Cstr skip( char * s ) { return (_Istream_Cstr){ 0p, s, -1, false }; } 336 static inline _Istream_Cstr incl( const char * scanset, char * s ) { return (_Istream_Cstr){ s, scanset, -1, false }; } 337 static inline _Istream_Cstr excl( const char * scanset, char * s ) { return (_Istream_Cstr){ s, scanset, -1, false }; } 338 static inline _Istream_Cstr cstr( char * s ) { return (_Istream_Cstr){ s, 0p, -1, false }; } 339 static inline _Istream_Cstr ignore( char * s ) { return (_Istream_Cstr)@{ s, 0p, -1, true }; } 340 static inline _Istream_Cstr ignore( _Istream_Cstr & fmt ) { fmt.ignore = true; return fmt; } 341 static inline _Istream_Cstr wd( unsigned int w, char * s ) { return (_Istream_Cstr)@{ s, 0p, w, false }; } 334 union { 335 unsigned char all; 336 struct { 337 unsigned char ignore:1; // do not change input argument 338 unsigned char inex:1; // include/exclude characters in scanset 339 } flags; 340 }; 341 }; // _Istream_Cstr 342 343 static inline _Istream_Cstr skip( const char * scanset ) { return (_Istream_Cstr){ 0p, scanset, -1, { .all : 0 } }; } 344 static inline _Istream_Cstr incl( const char * scanset, char * s ) { return (_Istream_Cstr){ s, scanset, -1, { .flags.inex : false } }; } 345 static inline _Istream_Cstr incl( const char * scanset, _Istream_Cstr & fmt ) { fmt.flags.inex = false; return fmt; } 346 static inline _Istream_Cstr excl( const char * scanset, char * s ) { return (_Istream_Cstr){ s, scanset, -1, { .flags.inex : true } }; } 347 static inline _Istream_Cstr excl( const char * scanset, _Istream_Cstr & fmt ) { fmt.flags.inex = true; return fmt; } 348 static inline _Istream_Cstr cstr( char * s ) { return (_Istream_Cstr){ s, 0p, -1, { .all : 0 } }; } 349 static inline _Istream_Cstr ignore( const char * s ) { return (_Istream_Cstr)@{ s, 0p, -1, { .flags.ignore : true } }; } 350 static inline _Istream_Cstr ignore( _Istream_Cstr & fmt ) { fmt.flags.ignore = true; return fmt; } 351 static inline _Istream_Cstr wd( unsigned int w, char * s ) { return (_Istream_Cstr)@{ s, 0p, w, { .all : 0 } }; } 352 static inline _Istream_Cstr wd( unsigned int w, _Istream_Cstr & fmt ) { fmt.wd = w; return fmt; } 342 353 forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, _Istream_Cstr ); 343 344 //*********************************** Manipulators ***********************************345 354 346 355 forall( otype T ) … … 348 357 T & val; // polymorphic base-type 349 358 int wd; // width 350 bool ignore; // noinput argument359 bool ignore; // do not change input argument 351 360 }; // _Istream_Manip 352 361 353 362 #define InputFMTDecl( T ) \ 354 static inline _Istream_Manip(T) ignore( T & v ) { return (_Istream_Manip(T))@{ v, -1, true }; } \363 static inline _Istream_Manip(T) ignore( const T & val ) { return (_Istream_Manip(T))@{ (T &)val, -1, true }; } \ 355 364 static inline _Istream_Manip(T) ignore( _Istream_Manip(T) & fmt ) { fmt.ignore = true; return fmt; } \ 356 static inline _Istream_Manip(T) wd( unsigned int w, T & v ) { return (_Istream_Manip(T))@{ v, w, false }; } \365 static inline _Istream_Manip(T) wd( unsigned int w, T & val ) { return (_Istream_Manip(T))@{ val, w, false }; } \ 357 366 forall( dtype istype | istream( istype ) ) { \ 358 367 istype & ?|?( istype & is, _Istream_Manip(T) f ); \ 359 } 368 } // ?|? 360 369 361 370 InputFMTDecl( char ) … … 378 387 InputFMTDecl( double _Complex ) 379 388 InputFMTDecl( long double _Complex ) 380 #endif // 0381 389 382 390 -
tests/io2.cfa
r1e6ea4e1 r61c7239 10 10 // Created On : Wed Mar 2 16:56:02 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Apr 18 08:03:30201913 // Update Count : 11 312 // Last Modified On : Sun Jun 9 08:07:42 2019 13 // Update Count : 117 14 14 // 15 15 … … 49 49 in | f | d | ld; // floating point 50 50 in | fc | dc | ldc; // floating-point complex 51 in | cstr( s1 ) | cstr( s2, size );// C string, length unchecked and checked51 in | cstr( s1 ) | wd( size, cstr( s2 ) ); // C string, length unchecked and checked 52 52 sout | nl; 53 53 … … 133 133 // Local Variables: // 134 134 // tab-width: 4 // 135 // compile-command: "cfa -DIN_DIR= ".in/" io2.cfa" //135 // compile-command: "cfa -DIN_DIR=\".in/\" io2.cfa" // 136 136 // End: //
Note: See TracChangeset
for help on using the changeset viewer.