Changeset b826e6b for src/libcfa/iostream.c
- Timestamp:
- Jul 19, 2017, 11:49:33 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 9cc0472
- Parents:
- fea3faa (diff), a57cb58 (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
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/iostream.c
rfea3faa rb826e6b 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 8 18:24:23 201713 // Update Count : 3 6912 // Last Modified On : Sun Jul 16 21:12:03 2017 13 // Update Count : 398 14 14 // 15 15 … … 18 18 extern "C" { 19 19 #include <stdio.h> 20 #include <stdbool.h> // true/false 20 21 #include <string.h> // strlen 21 22 #include <float.h> // DBL_DIG, LDBL_DIG … … 24 25 25 26 forall( dtype ostype | ostream( ostype ) ) 26 ostype * ?|?( ostype * os, char c ) { 27 fmt( os, "%c", c ); 27 ostype * ?|?( ostype * os, char ch ) { 28 fmt( os, "%c", ch ); 29 if ( ch == '\n' ) setNL( os, true ); 28 30 sepOff( os ); 29 31 return os; … … 123 125 forall( dtype ostype | ostream( ostype ) ) 124 126 ostype * ?|?( ostype * os, float _Complex fc ) { 125 os | crealf( fc ); 126 _Bool temp = sepDisable( os ); // disable separators within complex value 127 if ( cimagf( fc ) >= 0 ) os | '+'; // negative value prints '-' 128 os | cimagf( fc ) | 'i'; 129 sepReset( os, temp ); // reset separator 127 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 128 fmt( os, "%g%+gi", crealf( fc ), cimagf( fc ) ); 130 129 return os; 131 130 } // ?|? … … 133 132 forall( dtype ostype | ostream( ostype ) ) 134 133 ostype * ?|?( ostype * os, double _Complex dc ) { 135 os | creal( dc ); 136 _Bool temp = sepDisable( os ); // disable separators within complex value 137 if ( cimag( dc ) >= 0 ) os | '+'; // negative value prints '-' 138 os | cimag( dc ) | 'i'; 139 sepReset( os, temp ); // reset separator 134 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 135 fmt( os, "%.*lg%+.*lgi", DBL_DIG, creal( dc ), DBL_DIG, cimag( dc ) ); 140 136 return os; 141 137 } // ?|? … … 143 139 forall( dtype ostype | ostream( ostype ) ) 144 140 ostype * ?|?( ostype * os, long double _Complex ldc ) { 145 os | creall( ldc ); 146 _Bool temp = sepDisable( os ); // disable separators within complex value 147 if ( cimagl( ldc ) >= 0 ) os | '+'; // negative value prints '-' 148 os | cimagl( ldc ) | 'i'; 149 sepReset( os, temp ); // reset separator 141 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); 142 fmt( os, "%.*Lg%+.*Lgi", LDBL_DIG, creall( ldc ), LDBL_DIG, cimagl( ldc ) ); 150 143 return os; 151 144 } // ?|? … … 180 173 181 174 // last character IS spacing or opening punctuation => turn off separator for next item 182 unsigned int len = strlen( cp ), posn = len - 1;183 ch = cp[ posn];// must make unsigned175 size_t len = strlen( cp ); 176 ch = cp[len - 1]; // must make unsigned 184 177 if ( sepPrt( os ) && mask[ ch ] != Open && mask[ ch ] != OpenClose ) { 185 178 sepOn( os ); … … 187 180 sepOff( os ); 188 181 } // if 182 if ( ch == '\n' ) setNL( os, true ); // check *AFTER* sepPrt call above as it resets NL flag 189 183 return write( os, cp, len ); 190 184 } // ?|? … … 201 195 forall( dtype ostype, otype T, ttype Params | ostream( ostype ) | writeable( T ) | { ostype * ?|?( ostype *, Params ); } ) 202 196 ostype * ?|?( ostype * os, T arg, Params rest ) { 197 os | arg; // print first argument 203 198 sepSetCur( os, sepGetTuple( os ) ); // switch to tuple separator 204 os | arg; // print first argument205 199 os | rest; // print remaining arguments 206 200 sepSetCur( os, sepGet( os ) ); // switch to regular separator … … 216 210 217 211 forall( dtype ostype | ostream( ostype ) ) 212 ostype * sep( ostype * os ) { 213 os | sepGet( os ); 214 return os; 215 } // sep 216 217 forall( dtype ostype | ostream( ostype ) ) 218 ostype * sepTuple( ostype * os ) { 219 os | sepGetTuple( os ); 220 return os; 221 } // sepTuple 222 223 forall( dtype ostype | ostream( ostype ) ) 218 224 ostype * endl( ostype * os ) { 219 225 os | '\n'; 226 setNL( os, true ); 220 227 flush( os ); 221 228 sepOff( os ); // prepare for next line
Note:
See TracChangeset
for help on using the changeset viewer.