Changeset 1048b31 for src/libcfa/iostream.c
- Timestamp:
- May 2, 2016, 3:28:16 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 1b7ea43
- Parents:
- 1f6e009 (diff), e945826 (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
r1f6e009 r1048b31 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Mar 7 13:51:23 201613 // Update Count : 22712 // Last Modified On : Sat Apr 30 14:00:53 2016 13 // Update Count : 302 14 14 // 15 15 … … 27 27 ostype * ?|?( ostype *os, char c ) { 28 28 prtfmt( os, "%c", c ); 29 sepOff( os ); 29 30 return os; 30 31 } // ?|? … … 32 33 forall( dtype ostype | ostream( ostype ) ) 33 34 ostype * ?|?( ostype *os, short int si ) { 34 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );35 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 35 36 prtfmt( os, "%hd", si ); 36 37 return os; … … 39 40 forall( dtype ostype | ostream( ostype ) ) 40 41 ostype * ?|?( ostype *os, unsigned short int usi ) { 41 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );42 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 42 43 prtfmt( os, "%hu", usi ); 43 44 return os; … … 46 47 forall( dtype ostype | ostream( ostype ) ) 47 48 ostype * ?|?( ostype *os, int i ) { 48 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );49 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 49 50 prtfmt( os, "%d", i ); 50 51 return os; … … 53 54 forall( dtype ostype | ostream( ostype ) ) 54 55 ostype * ?|?( ostype *os, unsigned int ui ) { 55 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );56 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 56 57 prtfmt( os, "%u", ui ); 57 58 return os; … … 60 61 forall( dtype ostype | ostream( ostype ) ) 61 62 ostype * ?|?( ostype *os, long int li ) { 62 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );63 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 63 64 prtfmt( os, "%ld", li ); 64 65 return os; … … 67 68 forall( dtype ostype | ostream( ostype ) ) 68 69 ostype * ?|?( ostype *os, unsigned long int uli ) { 69 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );70 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 70 71 prtfmt( os, "%lu", uli ); 71 72 return os; … … 74 75 forall( dtype ostype | ostream( ostype ) ) 75 76 ostype * ?|?( ostype *os, long long int lli ) { 76 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );77 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 77 78 prtfmt( os, "%lld", lli ); 78 79 return os; … … 81 82 forall( dtype ostype | ostream( ostype ) ) 82 83 ostype * ?|?( ostype *os, unsigned long long int ulli ) { 83 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );84 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 84 85 prtfmt( os, "%llu", ulli ); 85 86 return os; … … 88 89 forall( dtype ostype | ostream( ostype ) ) 89 90 ostype * ?|?( ostype *os, float f ) { 90 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );91 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 91 92 prtfmt( os, "%g", f ); 92 93 return os; … … 95 96 forall( dtype ostype | ostream( ostype ) ) 96 97 ostype * ?|?( ostype *os, double d ) { 97 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );98 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 98 99 prtfmt( os, "%.*lg", DBL_DIG, d ); 99 100 return os; … … 102 103 forall( dtype ostype | ostream( ostype ) ) 103 104 ostype * ?|?( ostype *os, long double ld ) { 104 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );105 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 105 106 prtfmt( os, "%.*Lg", LDBL_DIG, ld ); 106 107 return os; … … 110 111 ostype * ?|?( ostype *os, float _Complex fc ) { 111 112 os | crealf( fc ); 112 if ( cimagf( fc ) >= 0 ) os | '+'; 113 os | "" | cimagf( fc ) | 'i'; 113 _Bool temp = sepDisable( os ); // disable separators within complex value 114 if ( cimagf( fc ) >= 0 ) os | '+'; // negative value prints '-' 115 os | cimagf( fc ) | 'i'; 116 sepReset( os, temp ); // reset separator 114 117 return os; 115 118 } // ?|? … … 118 121 ostype * ?|?( ostype *os, double _Complex dc ) { 119 122 os | creal( dc ); 120 if ( cimag( dc ) >= 0 ) os | '+'; 121 os | "" | cimag( dc ) | 'i'; 123 _Bool temp = sepDisable( os ); // disable separators within complex value 124 if ( cimag( dc ) >= 0 ) os | '+'; // negative value prints '-' 125 os | cimag( dc ) | 'i'; 126 sepReset( os, temp ); // reset separator 122 127 return os; 123 128 } // ?|? … … 126 131 ostype * ?|?( ostype *os, long double _Complex ldc ) { 127 132 os | creall( ldc ); 128 if ( cimagl( ldc ) >= 0 ) os | '+'; 129 os | "" | cimagl( ldc ) | 'i'; 133 _Bool temp = sepDisable( os ); // disable separators within complex value 134 if ( cimagl( ldc ) >= 0 ) os | '+'; // negative value prints '-' 135 os | cimagl( ldc ) | 'i'; 136 sepReset( os, temp ); // reset separator 130 137 return os; 131 138 } // ?|? … … 134 141 ostype * ?|?( ostype *os, const char *cp ) { 135 142 enum { Open = 1, Close, OpenClose }; 136 static const char mask[256] = {143 static const unsigned char mask[256] = { 137 144 // opening delimiters 138 145 ['('] : Open, ['['] : Open, ['{'] : Open, 139 ['$'] : Open, [L'£'] : Open, [L'¥'] : Open, [L'¢'] : Open, [L'¿'] : Open, [L'«'] : Open, 146 ['$'] : Open, [(unsigned char)'£'] : Open, [(unsigned char)'¥'] : Open, 147 [(unsigned char)'¡'] : Open, [(unsigned char)'¿'] : Open, [(unsigned char)'«'] : Open, 140 148 // closing delimiters 141 149 [','] : Close, ['.'] : Close, [':'] : Close, [';'] : Close, ['!'] : Close, ['?'] : Close, 142 150 [')'] : Close, [']'] : Close, ['}'] : Close, 143 ['%'] : Close, [ L'»'] : Close,151 ['%'] : Close, [(unsigned char)'¢'] : Close, [(unsigned char)'»'] : Close, 144 152 // opening-closing delimiters 145 153 ['\''] : OpenClose, ['`'] : OpenClose, ['"'] : OpenClose, 154 [' '] : OpenClose, ['\f'] : OpenClose, ['\n'] : OpenClose, ['\r'] : OpenClose, ['\t'] : OpenClose, ['\v'] : OpenClose, // isspace 146 155 }; // mask 147 156 148 int len = strlen( cp ); 149 // null string => no separator 150 if ( len == 0 ) { sepOff( os ); return os; } 151 // first character NOT spacing or closing punctuation => add left separator152 if ( sepPrt( os ) && isspace( cp[0] ) == 0 && mask[ cp[0] ] != Close && mask[ cp[0]] != OpenClose ) {157 if ( cp[0] == '\0' ) { sepOff( os ); return os; } // null string => no separator 158 159 // first character IS NOT spacing or closing punctuation => add left separator 160 unsigned char ch = cp[0]; // must make unsigned 161 if ( sepPrt( os ) && mask[ ch ] != Close && mask[ ch ] != OpenClose ) { 153 162 prtfmt( os, "%s", sepGet( os ) ); 154 163 } // if 164 165 // if string starts line, must reset to determine open state because separator is off 166 sepReset( os ); // reset separator 167 155 168 // last character IS spacing or opening punctuation => turn off separator for next item 156 unsigned int posn = len - 1; 157 if ( isspace( cp[posn] ) || mask[ cp[posn] ] == Open || mask[ cp[posn] ] == OpenClose ) { 169 unsigned int len = strlen( cp ), posn = len - 1; 170 ch = cp[posn]; // must make unsigned 171 if ( sepPrt( os ) && mask[ ch ] != Open && mask[ ch ] != OpenClose ) { 172 sepOn( os ); 173 } else { 158 174 sepOff( os ); 159 } else {160 sepOn( os );161 175 } // if 162 176 return write( os, cp, len ); … … 165 179 forall( dtype ostype | ostream( ostype ) ) 166 180 ostype * ?|?( ostype *os, const void *p ) { 167 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );181 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 168 182 prtfmt( os, "%p", p ); 169 183 return os; 170 184 } // ?|? 171 172 185 173 186 forall( dtype ostype | ostream( ostype ) ) … … 196 209 } // sepOff 197 210 211 forall( dtype ostype | ostream( ostype ) ) 212 ostype * sepEnable( ostype * os ) { 213 sepEnable( os ); 214 return os; 215 } // sepEnable 216 217 forall( dtype ostype | ostream( ostype ) ) 218 ostype * sepDisable( ostype * os ) { 219 sepDisable( os ); 220 return os; 221 } // sepDisable 222 198 223 //--------------------------------------- 199 224 … … 310 335 } // ?|? 311 336 312 _Istream_ str1 str( char * s ) { _Istream_str1s = { s }; return s; }313 forall( dtype istype | istream( istype ) ) 314 istype * ?|?( istype * is, _Istream_ str1str ) {315 scanfmt( is, "%s", str.s );316 return is; 317 } // str318 319 _Istream_ str2 str( char * s, int size ) { _Istream_str2s = { s, size }; return s; }320 forall( dtype istype | istream( istype ) ) 321 istype * ?|?( istype * is, _Istream_ str2str ) {337 _Istream_cstrUC cstr( char * s ) { _Istream_cstrUC s = { s }; return s; } 338 forall( dtype istype | istream( istype ) ) 339 istype * ?|?( istype * is, _Istream_cstrUC cstr ) { 340 scanfmt( is, "%s", cstr.s ); 341 return is; 342 } // cstr 343 344 _Istream_cstrC cstr( char * s, int size ) { _Istream_cstrC s = { s, size }; return s; } 345 forall( dtype istype | istream( istype ) ) 346 istype * ?|?( istype * is, _Istream_cstrC cstr ) { 322 347 char buf[16]; 323 sprintf( buf, "%%%ds", str.size );324 scanfmt( is, buf, str.s );325 return is; 326 } // str348 sprintf( buf, "%%%ds", cstr.size ); 349 scanfmt( is, buf, cstr.s ); 350 return is; 351 } // cstr 327 352 328 353 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.