Changes in src/libcfa/iostream.c [53ba273:b63e376]
- File:
-
- 1 edited
-
src/libcfa/iostream.c (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/iostream.c
r53ba273 rb63e376 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Apr 6 16:13:29201613 // Update Count : 2 7812 // Last Modified On : Mon Mar 7 13:51:23 2016 13 // Update Count : 227 14 14 // 15 15 … … 27 27 ostype * ?|?( ostype *os, char c ) { 28 28 prtfmt( os, "%c", c ); 29 sepOff( os );30 29 return os; 31 30 } // ?|? … … 33 32 forall( dtype ostype | ostream( ostype ) ) 34 33 ostype * ?|?( ostype *os, short int si ) { 35 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 36 sepReset( os ); 34 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 37 35 prtfmt( os, "%hd", si ); 38 36 return os; … … 41 39 forall( dtype ostype | ostream( ostype ) ) 42 40 ostype * ?|?( ostype *os, unsigned short int usi ) { 43 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 44 sepReset( os ); 41 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 45 42 prtfmt( os, "%hu", usi ); 46 43 return os; … … 49 46 forall( dtype ostype | ostream( ostype ) ) 50 47 ostype * ?|?( ostype *os, int i ) { 51 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 52 sepReset( os ); 48 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 53 49 prtfmt( os, "%d", i ); 54 50 return os; … … 57 53 forall( dtype ostype | ostream( ostype ) ) 58 54 ostype * ?|?( ostype *os, unsigned int ui ) { 59 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 60 sepReset( os ); 55 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 61 56 prtfmt( os, "%u", ui ); 62 57 return os; … … 65 60 forall( dtype ostype | ostream( ostype ) ) 66 61 ostype * ?|?( ostype *os, long int li ) { 67 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 68 sepReset( os ); 62 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 69 63 prtfmt( os, "%ld", li ); 70 64 return os; … … 73 67 forall( dtype ostype | ostream( ostype ) ) 74 68 ostype * ?|?( ostype *os, unsigned long int uli ) { 75 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 76 sepReset( os ); 69 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 77 70 prtfmt( os, "%lu", uli ); 78 71 return os; … … 81 74 forall( dtype ostype | ostream( ostype ) ) 82 75 ostype * ?|?( ostype *os, long long int lli ) { 83 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 84 sepReset( os ); 76 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 85 77 prtfmt( os, "%lld", lli ); 86 78 return os; … … 89 81 forall( dtype ostype | ostream( ostype ) ) 90 82 ostype * ?|?( ostype *os, unsigned long long int ulli ) { 91 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 92 sepReset( os ); 83 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 93 84 prtfmt( os, "%llu", ulli ); 94 85 return os; … … 97 88 forall( dtype ostype | ostream( ostype ) ) 98 89 ostype * ?|?( ostype *os, float f ) { 99 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 100 sepReset( os ); 90 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 101 91 prtfmt( os, "%g", f ); 102 92 return os; … … 105 95 forall( dtype ostype | ostream( ostype ) ) 106 96 ostype * ?|?( ostype *os, double d ) { 107 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 108 sepReset( os ); 97 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 109 98 prtfmt( os, "%.*lg", DBL_DIG, d ); 110 99 return os; … … 113 102 forall( dtype ostype | ostream( ostype ) ) 114 103 ostype * ?|?( ostype *os, long double ld ) { 115 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 116 sepReset( os ); 104 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 117 105 prtfmt( os, "%.*Lg", LDBL_DIG, ld ); 118 106 return os; … … 122 110 ostype * ?|?( ostype *os, float _Complex fc ) { 123 111 os | crealf( fc ); 124 _Bool temp = sepDisable( os ); // disable separators within complex value 125 if ( cimagf( fc ) >= 0 ) os | '+'; // negative value prints '-' 126 os | cimagf( fc ) | 'i'; 127 sepReset( os, temp ); // reset separator 112 if ( cimagf( fc ) >= 0 ) os | '+'; 113 os | "" | cimagf( fc ) | 'i'; 128 114 return os; 129 115 } // ?|? … … 132 118 ostype * ?|?( ostype *os, double _Complex dc ) { 133 119 os | creal( dc ); 134 _Bool temp = sepDisable( os ); // disable separators within complex value 135 if ( cimag( dc ) >= 0 ) os | '+'; // negative value prints '-' 136 os | cimag( dc ) | 'i'; 137 sepReset( os, temp ); // reset separator 120 if ( cimag( dc ) >= 0 ) os | '+'; 121 os | "" | cimag( dc ) | 'i'; 138 122 return os; 139 123 } // ?|? … … 142 126 ostype * ?|?( ostype *os, long double _Complex ldc ) { 143 127 os | creall( ldc ); 144 _Bool temp = sepDisable( os ); // disable separators within complex value 145 if ( cimagl( ldc ) >= 0 ) os | '+'; // negative value prints '-' 146 os | cimagl( ldc ) | 'i'; 147 sepReset( os, temp ); // reset separator 128 if ( cimagl( ldc ) >= 0 ) os | '+'; 129 os | "" | cimagl( ldc ) | 'i'; 148 130 return os; 149 131 } // ?|? … … 152 134 ostype * ?|?( ostype *os, const char *cp ) { 153 135 enum { Open = 1, Close, OpenClose }; 154 static const unsignedchar mask[256] = {136 static const char mask[256] = { 155 137 // opening delimiters 156 138 ['('] : Open, ['['] : Open, ['{'] : Open, 157 ['$'] : Open, [ (unsigned char)'£'] : Open, [(unsigned char)'¥'] : Open, [(unsigned char)'¿'] : Open, [(unsigned char)'«'] : Open,139 ['$'] : Open, [L'£'] : Open, [L'¥'] : Open, [L'¢'] : Open, [L'¿'] : Open, [L'«'] : Open, 158 140 // closing delimiters 159 141 [','] : Close, ['.'] : Close, [':'] : Close, [';'] : Close, ['!'] : Close, ['?'] : Close, 160 142 [')'] : Close, [']'] : Close, ['}'] : Close, 161 ['%'] : Close, [ (unsigned char)'¢'] : Close, [(unsigned char)'»'] : Close,143 ['%'] : Close, [L'»'] : Close, 162 144 // opening-closing delimiters 163 145 ['\''] : OpenClose, ['`'] : OpenClose, ['"'] : OpenClose, 164 ['\f'] : OpenClose, ['\n'] : OpenClose, ['\r'] : OpenClose, ['\t'] : OpenClose, ['\v'] : OpenClose, // isspace165 146 }; // mask 166 147 … … 168 149 // null string => no separator 169 150 if ( len == 0 ) { sepOff( os ); return os; } 170 // first character IS NOT spacing or closing punctuation => add left separator 171 unsigned char ch = cp[0]; // must make unsigned 172 if ( sepPrt( os ) && mask[ ch ] != Close && mask[ ch ] != OpenClose ) { 151 // first character NOT spacing or closing punctuation => add left separator 152 if ( sepPrt( os ) && isspace( cp[0] ) == 0 && mask[ cp[0] ] != Close && mask[ cp[0] ] != OpenClose ) { 173 153 prtfmt( os, "%s", sepGet( os ) ); 174 154 } // if 175 155 // last character IS spacing or opening punctuation => turn off separator for next item 176 156 unsigned int posn = len - 1; 177 ch = cp[posn]; // must make unsigned 178 if ( mask[ ch ] == Open || mask[ ch ] == OpenClose ) { 157 if ( isspace( cp[posn] ) || mask[ cp[posn] ] == Open || mask[ cp[posn] ] == OpenClose ) { 179 158 sepOff( os ); 180 159 } else { … … 186 165 forall( dtype ostype | ostream( ostype ) ) 187 166 ostype * ?|?( ostype *os, const void *p ) { 188 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 189 sepReset( os ); 167 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 190 168 prtfmt( os, "%p", p ); 191 169 return os; … … 218 196 } // sepOff 219 197 220 forall( dtype ostype | ostream( ostype ) )221 ostype * sepEnable( ostype * os ) {222 sepEnable( os );223 return os;224 } // sepEnable225 226 forall( dtype ostype | ostream( ostype ) )227 ostype * sepDisable( ostype * os ) {228 sepDisable( os );229 return os;230 } // sepDisable231 232 198 //--------------------------------------- 233 199 … … 344 310 } // ?|? 345 311 346 _Istream_ cstrUC cstr( char * s ) { _Istream_cstrUCs = { s }; return s; }347 forall( dtype istype | istream( istype ) ) 348 istype * ?|?( istype * is, _Istream_ cstrUC cstr ) {349 scanfmt( is, "%s", cstr.s );350 return is; 351 } // cstr352 353 _Istream_ cstrC cstr( char * s, int size ) { _Istream_cstrCs = { s, size }; return s; }354 forall( dtype istype | istream( istype ) ) 355 istype * ?|?( istype * is, _Istream_ cstrC cstr ) {312 _Istream_str1 str( char * s ) { _Istream_str1 s = { s }; return s; } 313 forall( dtype istype | istream( istype ) ) 314 istype * ?|?( istype * is, _Istream_str1 str ) { 315 scanfmt( is, "%s", str.s ); 316 return is; 317 } // str 318 319 _Istream_str2 str( char * s, int size ) { _Istream_str2 s = { s, size }; return s; } 320 forall( dtype istype | istream( istype ) ) 321 istype * ?|?( istype * is, _Istream_str2 str ) { 356 322 char buf[16]; 357 sprintf( buf, "%%%ds", cstr.size );358 scanfmt( is, buf, cstr.s );359 return is; 360 } // cstr323 sprintf( buf, "%%%ds", str.size ); 324 scanfmt( is, buf, str.s ); 325 return is; 326 } // str 361 327 362 328 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.