Changes in src/libcfa/iostream.c [e945826:b63e376]
- File:
-
- 1 edited
-
src/libcfa/iostream.c (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/iostream.c
re945826 rb63e376 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Apr 30 14:00:53 201613 // Update Count : 30212 // 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 ) ); 34 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 36 35 prtfmt( os, "%hd", si ); 37 36 return os; … … 40 39 forall( dtype ostype | ostream( ostype ) ) 41 40 ostype * ?|?( ostype *os, unsigned short int usi ) { 42 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 41 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 43 42 prtfmt( os, "%hu", usi ); 44 43 return os; … … 47 46 forall( dtype ostype | ostream( ostype ) ) 48 47 ostype * ?|?( ostype *os, int i ) { 49 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 48 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 50 49 prtfmt( os, "%d", i ); 51 50 return os; … … 54 53 forall( dtype ostype | ostream( ostype ) ) 55 54 ostype * ?|?( ostype *os, unsigned int ui ) { 56 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 55 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 57 56 prtfmt( os, "%u", ui ); 58 57 return os; … … 61 60 forall( dtype ostype | ostream( ostype ) ) 62 61 ostype * ?|?( ostype *os, long int li ) { 63 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 62 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 64 63 prtfmt( os, "%ld", li ); 65 64 return os; … … 68 67 forall( dtype ostype | ostream( ostype ) ) 69 68 ostype * ?|?( ostype *os, unsigned long int uli ) { 70 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 69 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 71 70 prtfmt( os, "%lu", uli ); 72 71 return os; … … 75 74 forall( dtype ostype | ostream( ostype ) ) 76 75 ostype * ?|?( ostype *os, long long int lli ) { 77 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 76 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 78 77 prtfmt( os, "%lld", lli ); 79 78 return os; … … 82 81 forall( dtype ostype | ostream( ostype ) ) 83 82 ostype * ?|?( ostype *os, unsigned long long int ulli ) { 84 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 83 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 85 84 prtfmt( os, "%llu", ulli ); 86 85 return os; … … 89 88 forall( dtype ostype | ostream( ostype ) ) 90 89 ostype * ?|?( ostype *os, float f ) { 91 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 90 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 92 91 prtfmt( os, "%g", f ); 93 92 return os; … … 96 95 forall( dtype ostype | ostream( ostype ) ) 97 96 ostype * ?|?( ostype *os, double d ) { 98 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 97 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 99 98 prtfmt( os, "%.*lg", DBL_DIG, d ); 100 99 return os; … … 103 102 forall( dtype ostype | ostream( ostype ) ) 104 103 ostype * ?|?( ostype *os, long double ld ) { 105 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 104 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 106 105 prtfmt( os, "%.*Lg", LDBL_DIG, ld ); 107 106 return os; … … 111 110 ostype * ?|?( ostype *os, float _Complex fc ) { 112 111 os | crealf( fc ); 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 112 if ( cimagf( fc ) >= 0 ) os | '+'; 113 os | "" | cimagf( fc ) | 'i'; 117 114 return os; 118 115 } // ?|? … … 121 118 ostype * ?|?( ostype *os, double _Complex dc ) { 122 119 os | creal( dc ); 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 120 if ( cimag( dc ) >= 0 ) os | '+'; 121 os | "" | cimag( dc ) | 'i'; 127 122 return os; 128 123 } // ?|? … … 131 126 ostype * ?|?( ostype *os, long double _Complex ldc ) { 132 127 os | creall( ldc ); 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 128 if ( cimagl( ldc ) >= 0 ) os | '+'; 129 os | "" | cimagl( ldc ) | 'i'; 137 130 return os; 138 131 } // ?|? … … 141 134 ostype * ?|?( ostype *os, const char *cp ) { 142 135 enum { Open = 1, Close, OpenClose }; 143 static const unsignedchar mask[256] = {136 static const char mask[256] = { 144 137 // opening delimiters 145 138 ['('] : Open, ['['] : Open, ['{'] : Open, 146 ['$'] : Open, [(unsigned char)'£'] : Open, [(unsigned char)'¥'] : Open, 147 [(unsigned char)'¡'] : Open, [(unsigned char)'¿'] : Open, [(unsigned char)'«'] : Open, 139 ['$'] : Open, [L'£'] : Open, [L'¥'] : Open, [L'¢'] : Open, [L'¿'] : Open, [L'«'] : Open, 148 140 // closing delimiters 149 141 [','] : Close, ['.'] : Close, [':'] : Close, [';'] : Close, ['!'] : Close, ['?'] : Close, 150 142 [')'] : Close, [']'] : Close, ['}'] : Close, 151 ['%'] : Close, [ (unsigned char)'¢'] : Close, [(unsigned char)'»'] : Close,143 ['%'] : Close, [L'»'] : Close, 152 144 // opening-closing delimiters 153 145 ['\''] : OpenClose, ['`'] : OpenClose, ['"'] : OpenClose, 154 [' '] : OpenClose, ['\f'] : OpenClose, ['\n'] : OpenClose, ['\r'] : OpenClose, ['\t'] : OpenClose, ['\v'] : OpenClose, // isspace155 146 }; // mask 156 147 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 unsigned161 if ( sepPrt( os ) && mask[ ch ] != Close && mask[ ch] != OpenClose ) {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 separator 152 if ( sepPrt( os ) && isspace( cp[0] ) == 0 && mask[ cp[0] ] != Close && mask[ cp[0] ] != OpenClose ) { 162 153 prtfmt( os, "%s", sepGet( os ) ); 163 154 } // if 164 165 // if string starts line, must reset to determine open state because separator is off166 sepReset( os ); // reset separator167 168 155 // last character IS spacing or opening punctuation => turn off separator for next item 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 ) { 156 unsigned int posn = len - 1; 157 if ( isspace( cp[posn] ) || mask[ cp[posn] ] == Open || mask[ cp[posn] ] == OpenClose ) { 158 sepOff( os ); 159 } else { 172 160 sepOn( os ); 173 } else {174 sepOff( os );175 161 } // if 176 162 return write( os, cp, len ); … … 179 165 forall( dtype ostype | ostream( ostype ) ) 180 166 ostype * ?|?( ostype *os, const void *p ) { 181 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); 167 if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os ); 182 168 prtfmt( os, "%p", p ); 183 169 return os; 184 170 } // ?|? 171 185 172 186 173 forall( dtype ostype | ostream( ostype ) ) … … 209 196 } // sepOff 210 197 211 forall( dtype ostype | ostream( ostype ) )212 ostype * sepEnable( ostype * os ) {213 sepEnable( os );214 return os;215 } // sepEnable216 217 forall( dtype ostype | ostream( ostype ) )218 ostype * sepDisable( ostype * os ) {219 sepDisable( os );220 return os;221 } // sepDisable222 223 198 //--------------------------------------- 224 199 … … 335 310 } // ?|? 336 311 337 _Istream_ cstrUC cstr( char * s ) { _Istream_cstrUCs = { 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 } // cstr343 344 _Istream_ cstrC cstr( char * s, int size ) { _Istream_cstrCs = { s, size }; return s; }345 forall( dtype istype | istream( istype ) ) 346 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 ) { 347 322 char buf[16]; 348 sprintf( buf, "%%%ds", cstr.size );349 scanfmt( is, buf, cstr.s );350 return is; 351 } // cstr323 sprintf( buf, "%%%ds", str.size ); 324 scanfmt( is, buf, str.s ); 325 return is; 326 } // str 352 327 353 328 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.