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