| 1 | // | 
|---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo | 
|---|
| 3 | // | 
|---|
| 4 | // The contents of this file are covered under the licence agreement in the | 
|---|
| 5 | // file "LICENCE" distributed with Cforall. | 
|---|
| 6 | // | 
|---|
| 7 | // iostream.cfa -- | 
|---|
| 8 | // | 
|---|
| 9 | // Author           : Peter A. Buhr | 
|---|
| 10 | // Created On       : Wed May 27 17:56:53 2015 | 
|---|
| 11 | // Last Modified By : Peter A. Buhr | 
|---|
| 12 | // Last Modified On : Fri Apr 24 11:48:53 2020 | 
|---|
| 13 | // Update Count     : 954 | 
|---|
| 14 | // | 
|---|
| 15 |  | 
|---|
| 16 | #include "iostream.hfa" | 
|---|
| 17 |  | 
|---|
| 18 | extern "C" { | 
|---|
| 19 | #include <stdio.h> | 
|---|
| 20 | #include <stdbool.h>                                                                    // true/false | 
|---|
| 21 | #include <stdint.h>                                                                             // UINT64_MAX | 
|---|
| 22 | //#include <string.h>                                                                   // strlen, strcmp | 
|---|
| 23 | extern size_t strlen (const char *__s) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); | 
|---|
| 24 | extern int strcmp (const char *__s1, const char *__s2) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); | 
|---|
| 25 | extern char *strcpy (char *__restrict __dest, const char *__restrict __src) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); | 
|---|
| 26 | extern void *memcpy (void *__restrict __dest, const void *__restrict __src, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); | 
|---|
| 27 | #include <float.h>                                                                              // DBL_DIG, LDBL_DIG | 
|---|
| 28 | #include <math.h>                                                                               // isfinite | 
|---|
| 29 | #include <complex.h>                                                                    // creal, cimag | 
|---|
| 30 | } // extern "C" | 
|---|
| 31 |  | 
|---|
| 32 | #include <bitmanip.hfa>                                                                 // fms | 
|---|
| 33 |  | 
|---|
| 34 |  | 
|---|
| 35 | //*********************************** ostream *********************************** | 
|---|
| 36 |  | 
|---|
| 37 |  | 
|---|
| 38 | forall( dtype ostype | ostream( ostype ) ) { | 
|---|
| 39 | ostype & ?|?( ostype & os, zero_t ) { | 
|---|
| 40 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 41 | fmt( os, "%d", 0n ); | 
|---|
| 42 | return os; | 
|---|
| 43 | } // ?|? | 
|---|
| 44 | void ?|?( ostype & os, zero_t z ) { | 
|---|
| 45 | (ostype &)(os | z); ends( os ); | 
|---|
| 46 | } // ?|? | 
|---|
| 47 |  | 
|---|
| 48 | ostype & ?|?( ostype & os, one_t ) { | 
|---|
| 49 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 50 | fmt( os, "%d", 1n ); | 
|---|
| 51 | return os; | 
|---|
| 52 | } // ?|? | 
|---|
| 53 | void ?|?( ostype & os, one_t o ) { | 
|---|
| 54 | (ostype &)(os | o); ends( os ); | 
|---|
| 55 | } // ?|? | 
|---|
| 56 |  | 
|---|
| 57 | ostype & ?|?( ostype & os, bool b ) { | 
|---|
| 58 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 59 | fmt( os, "%s", b ? "true" : "false" ); | 
|---|
| 60 | return os; | 
|---|
| 61 | } // ?|? | 
|---|
| 62 | void ?|?( ostype & os, bool b ) { | 
|---|
| 63 | (ostype &)(os | b); ends( os ); | 
|---|
| 64 | } // ?|? | 
|---|
| 65 |  | 
|---|
| 66 | ostype & ?|?( ostype & os, char c ) { | 
|---|
| 67 | fmt( os, "%c", c ); | 
|---|
| 68 | if ( c == '\n' ) $setNL( os, true ); | 
|---|
| 69 | return sepOff( os ); | 
|---|
| 70 | } // ?|? | 
|---|
| 71 | void ?|?( ostype & os, char c ) { | 
|---|
| 72 | (ostype &)(os | c); ends( os ); | 
|---|
| 73 | } // ?|? | 
|---|
| 74 |  | 
|---|
| 75 | ostype & ?|?( ostype & os, signed char sc ) { | 
|---|
| 76 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 77 | fmt( os, "%hhd", sc ); | 
|---|
| 78 | return os; | 
|---|
| 79 | } // ?|? | 
|---|
| 80 | void ?|?( ostype & os, signed char sc ) { | 
|---|
| 81 | (ostype &)(os | sc); ends( os ); | 
|---|
| 82 | } // ?|? | 
|---|
| 83 |  | 
|---|
| 84 | ostype & ?|?( ostype & os, unsigned char usc ) { | 
|---|
| 85 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 86 | fmt( os, "%hhu", usc ); | 
|---|
| 87 | return os; | 
|---|
| 88 | } // ?|? | 
|---|
| 89 | void ?|?( ostype & os, unsigned char usc ) { | 
|---|
| 90 | (ostype &)(os | usc); ends( os ); | 
|---|
| 91 | } // ?|? | 
|---|
| 92 |  | 
|---|
| 93 | ostype & ?|?( ostype & os, short int si ) { | 
|---|
| 94 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 95 | fmt( os, "%hd", si ); | 
|---|
| 96 | return os; | 
|---|
| 97 | } // ?|? | 
|---|
| 98 | void & ?|?( ostype & os, short int si ) { | 
|---|
| 99 | (ostype &)(os | si); ends( os ); | 
|---|
| 100 | } // ?|? | 
|---|
| 101 |  | 
|---|
| 102 | ostype & ?|?( ostype & os, unsigned short int usi ) { | 
|---|
| 103 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 104 | fmt( os, "%hu", usi ); | 
|---|
| 105 | return os; | 
|---|
| 106 | } // ?|? | 
|---|
| 107 | void & ?|?( ostype & os, unsigned short int usi ) { | 
|---|
| 108 | (ostype &)(os | usi); ends( os ); | 
|---|
| 109 | } // ?|? | 
|---|
| 110 |  | 
|---|
| 111 | ostype & ?|?( ostype & os, int i ) { | 
|---|
| 112 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 113 | fmt( os, "%d", i ); | 
|---|
| 114 | return os; | 
|---|
| 115 | } // ?|? | 
|---|
| 116 | void & ?|?( ostype & os, int i ) { | 
|---|
| 117 | (ostype &)(os | i); ends( os ); | 
|---|
| 118 | } // ?|? | 
|---|
| 119 |  | 
|---|
| 120 | ostype & ?|?( ostype & os, unsigned int ui ) { | 
|---|
| 121 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 122 | fmt( os, "%u", ui ); | 
|---|
| 123 | return os; | 
|---|
| 124 | } // ?|? | 
|---|
| 125 | void & ?|?( ostype & os, unsigned int ui ) { | 
|---|
| 126 | (ostype &)(os | ui); ends( os ); | 
|---|
| 127 | } // ?|? | 
|---|
| 128 |  | 
|---|
| 129 | ostype & ?|?( ostype & os, long int li ) { | 
|---|
| 130 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 131 | fmt( os, "%ld", li ); | 
|---|
| 132 | return os; | 
|---|
| 133 | } // ?|? | 
|---|
| 134 | void & ?|?( ostype & os, long int li ) { | 
|---|
| 135 | (ostype &)(os | li); ends( os ); | 
|---|
| 136 | } // ?|? | 
|---|
| 137 |  | 
|---|
| 138 | ostype & ?|?( ostype & os, unsigned long int uli ) { | 
|---|
| 139 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 140 | fmt( os, "%lu", uli ); | 
|---|
| 141 | return os; | 
|---|
| 142 | } // ?|? | 
|---|
| 143 | void & ?|?( ostype & os, unsigned long int uli ) { | 
|---|
| 144 | (ostype &)(os | uli); ends( os ); | 
|---|
| 145 | } // ?|? | 
|---|
| 146 |  | 
|---|
| 147 | ostype & ?|?( ostype & os, long long int lli ) { | 
|---|
| 148 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 149 | fmt( os, "%lld", lli ); | 
|---|
| 150 | return os; | 
|---|
| 151 | } // ?|? | 
|---|
| 152 | void & ?|?( ostype & os, long long int lli ) { | 
|---|
| 153 | (ostype &)(os | lli); ends( os ); | 
|---|
| 154 | } // ?|? | 
|---|
| 155 |  | 
|---|
| 156 | ostype & ?|?( ostype & os, unsigned long long int ulli ) { | 
|---|
| 157 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 158 | fmt( os, "%llu", ulli ); | 
|---|
| 159 | return os; | 
|---|
| 160 | } // ?|? | 
|---|
| 161 | void & ?|?( ostype & os, unsigned long long int ulli ) { | 
|---|
| 162 | (ostype &)(os | ulli); ends( os ); | 
|---|
| 163 | } // ?|? | 
|---|
| 164 |  | 
|---|
| 165 | #if defined( __SIZEOF_INT128__ ) | 
|---|
| 166 | //      UINT64_MAX 18_446_744_073_709_551_615_ULL | 
|---|
| 167 | #define P10_UINT64 10_000_000_000_000_000_000_ULL       // 19 zeroes | 
|---|
| 168 |  | 
|---|
| 169 | static void base10_128( ostype & os, unsigned int128 val ) { | 
|---|
| 170 | if ( val > UINT64_MAX ) { | 
|---|
| 171 | base10_128( os, val / P10_UINT64 );                     // recursive | 
|---|
| 172 | fmt( os, "%.19lu", (uint64_t)(val % P10_UINT64) ); | 
|---|
| 173 | } else { | 
|---|
| 174 | fmt( os, "%lu", (uint64_t)val ); | 
|---|
| 175 | } // if | 
|---|
| 176 | } // base10_128 | 
|---|
| 177 |  | 
|---|
| 178 | static void base10_128( ostype & os, int128 val ) { | 
|---|
| 179 | if ( val < 0 ) { | 
|---|
| 180 | fmt( os, "-" );                                                         // leading negative sign | 
|---|
| 181 | val = -val; | 
|---|
| 182 | } // if | 
|---|
| 183 | base10_128( os, (unsigned int128)val );                 // print zero/positive value | 
|---|
| 184 | } // base10_128 | 
|---|
| 185 |  | 
|---|
| 186 | ostype & ?|?( ostype & os, int128 llli ) { | 
|---|
| 187 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 188 | base10_128( os, llli ); | 
|---|
| 189 | return os; | 
|---|
| 190 | } // ?|? | 
|---|
| 191 | void & ?|?( ostype & os, int128 llli ) { | 
|---|
| 192 | (ostype &)(os | llli); ends( os ); | 
|---|
| 193 | } // ?|? | 
|---|
| 194 |  | 
|---|
| 195 | ostype & ?|?( ostype & os, unsigned int128 ullli ) { | 
|---|
| 196 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 197 | base10_128( os, ullli ); | 
|---|
| 198 | return os; | 
|---|
| 199 | } // ?|? | 
|---|
| 200 | void & ?|?( ostype & os, unsigned int128 ullli ) { | 
|---|
| 201 | (ostype &)(os | ullli); ends( os ); | 
|---|
| 202 | } // ?|? | 
|---|
| 203 | #endif // __SIZEOF_INT128__ | 
|---|
| 204 |  | 
|---|
| 205 | #define PrintWithDP( os, format, val, ... ) \ | 
|---|
| 206 | { \ | 
|---|
| 207 | enum { size = 48 }; \ | 
|---|
| 208 | char buf[size]; \ | 
|---|
| 209 | int len = snprintf( buf, size, format, ##__VA_ARGS__, val ); \ | 
|---|
| 210 | fmt( os, "%s", buf ); \ | 
|---|
| 211 | if ( isfinite( val ) ) {                                        /* if number, always print decimal point */ \ | 
|---|
| 212 | for ( int i = 0;; i += 1 ) { \ | 
|---|
| 213 | if ( i == len ) { fmt( os, "." ); break; } \ | 
|---|
| 214 | if ( buf[i] == '.' ) break; \ | 
|---|
| 215 | } /* for */ \ | 
|---|
| 216 | } /* if */ \ | 
|---|
| 217 | } | 
|---|
| 218 |  | 
|---|
| 219 | ostype & ?|?( ostype & os, float f ) { | 
|---|
| 220 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 221 | PrintWithDP( os, "%g", f ); | 
|---|
| 222 | return os; | 
|---|
| 223 | } // ?|? | 
|---|
| 224 | void & ?|?( ostype & os, float f ) { | 
|---|
| 225 | (ostype &)(os | f); ends( os ); | 
|---|
| 226 | } // ?|? | 
|---|
| 227 |  | 
|---|
| 228 | ostype & ?|?( ostype & os, double d ) { | 
|---|
| 229 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 230 | PrintWithDP( os, "%.*lg", d, DBL_DIG ); | 
|---|
| 231 | return os; | 
|---|
| 232 | } // ?|? | 
|---|
| 233 | void & ?|?( ostype & os, double d ) { | 
|---|
| 234 | (ostype &)(os | d); ends( os ); | 
|---|
| 235 | } // ?|? | 
|---|
| 236 |  | 
|---|
| 237 | ostype & ?|?( ostype & os, long double ld ) { | 
|---|
| 238 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 239 | PrintWithDP( os, "%.*Lg", ld, LDBL_DIG ); | 
|---|
| 240 | return os; | 
|---|
| 241 | } // ?|? | 
|---|
| 242 | void & ?|?( ostype & os, long double ld ) { | 
|---|
| 243 | (ostype &)(os | ld); ends( os ); | 
|---|
| 244 | } // ?|? | 
|---|
| 245 |  | 
|---|
| 246 | ostype & ?|?( ostype & os, float _Complex fc ) { | 
|---|
| 247 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 248 | //              os | crealf( fc ) | nonl; | 
|---|
| 249 | PrintWithDP( os, "%g", crealf( fc ) ); | 
|---|
| 250 | PrintWithDP( os, "%+g", cimagf( fc ) ); | 
|---|
| 251 | fmt( os, "i" ); | 
|---|
| 252 | return os; | 
|---|
| 253 | } // ?|? | 
|---|
| 254 | void & ?|?( ostype & os, float _Complex fc ) { | 
|---|
| 255 | (ostype &)(os | fc); ends( os ); | 
|---|
| 256 | } // ?|? | 
|---|
| 257 |  | 
|---|
| 258 | ostype & ?|?( ostype & os, double _Complex dc ) { | 
|---|
| 259 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 260 | //              os | creal( dc ) | nonl; | 
|---|
| 261 | PrintWithDP( os, "%.*lg", creal( dc ), DBL_DIG ); | 
|---|
| 262 | PrintWithDP( os, "%+.*lg", cimag( dc ), DBL_DIG ); | 
|---|
| 263 | fmt( os, "i" ); | 
|---|
| 264 | return os; | 
|---|
| 265 | } // ?|? | 
|---|
| 266 | void & ?|?( ostype & os, double _Complex dc ) { | 
|---|
| 267 | (ostype &)(os | dc); ends( os ); | 
|---|
| 268 | } // ?|? | 
|---|
| 269 |  | 
|---|
| 270 | ostype & ?|?( ostype & os, long double _Complex ldc ) { | 
|---|
| 271 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 272 | //              os | creall( ldc ) || nonl; | 
|---|
| 273 | PrintWithDP( os, "%.*Lg", creall( ldc ), LDBL_DIG ); | 
|---|
| 274 | PrintWithDP( os, "%+.*Lg", cimagl( ldc ), LDBL_DIG ); | 
|---|
| 275 | fmt( os, "i" ); | 
|---|
| 276 | return os; | 
|---|
| 277 | } // ?|? | 
|---|
| 278 | void & ?|?( ostype & os, long double _Complex ldc ) { | 
|---|
| 279 | (ostype &)(os | ldc); ends( os ); | 
|---|
| 280 | } // ?|? | 
|---|
| 281 |  | 
|---|
| 282 | ostype & ?|?( ostype & os, const char str[] ) { | 
|---|
| 283 | enum { Open = 1, Close, OpenClose }; | 
|---|
| 284 | static const unsigned char mask[256] @= { | 
|---|
| 285 | // opening delimiters, no space after | 
|---|
| 286 | ['('] : Open, ['['] : Open, ['{'] : Open, | 
|---|
| 287 | ['='] : Open, ['$'] : Open, [(unsigned char)'£'] : Open, [(unsigned char)'¥'] : Open, | 
|---|
| 288 | [(unsigned char)'¡'] : Open, [(unsigned char)'¿'] : Open, [(unsigned char)'«'] : Open, | 
|---|
| 289 | // closing delimiters, no space before | 
|---|
| 290 | [','] : Close, ['.'] : Close, [';'] : Close, ['!'] : Close, ['?'] : Close, | 
|---|
| 291 | ['%'] : Close, [(unsigned char)'¢'] : Close, [(unsigned char)'»'] : Close, | 
|---|
| 292 | [')'] : Close, [']'] : Close, ['}'] : Close, | 
|---|
| 293 | // opening-closing delimiters, no space before or after | 
|---|
| 294 | ['\''] : OpenClose, ['`'] : OpenClose, ['"'] : OpenClose, [':'] : OpenClose, | 
|---|
| 295 | [' '] : OpenClose, ['\f'] : OpenClose, ['\n'] : OpenClose, ['\r'] : OpenClose, ['\t'] : OpenClose, ['\v'] : OpenClose, // isspace | 
|---|
| 296 | }; // mask | 
|---|
| 297 |  | 
|---|
| 298 | if ( str[0] == '\0' ) { sepOff( os ); return os; } // null string => no separator | 
|---|
| 299 |  | 
|---|
| 300 | // first character IS NOT spacing or closing punctuation => add left separator | 
|---|
| 301 | unsigned char ch = str[0];                                              // must make unsigned | 
|---|
| 302 | if ( $sepPrt( os ) && mask[ ch ] != Close && mask[ ch ] != OpenClose ) { | 
|---|
| 303 | fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 304 | } // if | 
|---|
| 305 |  | 
|---|
| 306 | // if string starts line, must reset to determine open state because separator is off | 
|---|
| 307 | $sepReset( os );                                                                // reset separator | 
|---|
| 308 |  | 
|---|
| 309 | // last character IS spacing or opening punctuation => turn off separator for next item | 
|---|
| 310 | size_t len = strlen( str ); | 
|---|
| 311 | ch = str[len - 1];                                                              // must make unsigned | 
|---|
| 312 | if ( $sepPrt( os ) && mask[ ch ] != Open && mask[ ch ] != OpenClose ) { | 
|---|
| 313 | sepOn( os ); | 
|---|
| 314 | } else { | 
|---|
| 315 | sepOff( os ); | 
|---|
| 316 | } // if | 
|---|
| 317 | if ( ch == '\n' ) $setNL( os, true );                   // check *AFTER* $sepPrt call above as it resets NL flag | 
|---|
| 318 | return write( os, str, len ); | 
|---|
| 319 | } // ?|? | 
|---|
| 320 |  | 
|---|
| 321 | void ?|?( ostype & os, const char str[] ) { | 
|---|
| 322 | (ostype &)(os | str); ends( os ); | 
|---|
| 323 | } // ?|? | 
|---|
| 324 |  | 
|---|
| 325 | //      ostype & ?|?( ostype & os, const char16_t * str ) { | 
|---|
| 326 | //              if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 327 | //              fmt( os, "%ls", str ); | 
|---|
| 328 | //              return os; | 
|---|
| 329 | //      } // ?|? | 
|---|
| 330 |  | 
|---|
| 331 | // #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous | 
|---|
| 332 | //      ostype & ?|?( ostype & os, const char32_t * str ) { | 
|---|
| 333 | //              if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 334 | //              fmt( os, "%ls", str ); | 
|---|
| 335 | //              return os; | 
|---|
| 336 | //      } // ?|? | 
|---|
| 337 | // #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) | 
|---|
| 338 |  | 
|---|
| 339 | //      ostype & ?|?( ostype & os, const wchar_t * str ) { | 
|---|
| 340 | //              if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 341 | //              fmt( os, "%ls", str ); | 
|---|
| 342 | //              return os; | 
|---|
| 343 | //      } // ?|? | 
|---|
| 344 |  | 
|---|
| 345 | ostype & ?|?( ostype & os, const void * p ) { | 
|---|
| 346 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 347 | fmt( os, "%p", p ); | 
|---|
| 348 | return os; | 
|---|
| 349 | } // ?|? | 
|---|
| 350 | void ?|?( ostype & os, const void * p ) { | 
|---|
| 351 | (ostype &)(os | p); ends( os ); | 
|---|
| 352 | } // ?|? | 
|---|
| 353 |  | 
|---|
| 354 | // manipulators | 
|---|
| 355 | ostype & ?|?( ostype & os, ostype & (* manip)( ostype & ) ) { | 
|---|
| 356 | (ostype &)(manip( os )); | 
|---|
| 357 | return os; | 
|---|
| 358 | } // ?|? | 
|---|
| 359 | void ?|?( ostype & os, ostype & (* manip)( ostype & ) ) { | 
|---|
| 360 | (ostype &)(manip( os )); | 
|---|
| 361 | if ( $getPrt( os ) ) ends( os );                                // something printed ? | 
|---|
| 362 | $setPrt( os, false );                                                   // turn off | 
|---|
| 363 | } // ?|? | 
|---|
| 364 |  | 
|---|
| 365 | ostype & sep( ostype & os ) { | 
|---|
| 366 | return (ostype &)(os | sepGet( os )); | 
|---|
| 367 | } // sep | 
|---|
| 368 |  | 
|---|
| 369 | ostype & sepTuple( ostype & os ) { | 
|---|
| 370 | return os | sepGetTuple( os ); | 
|---|
| 371 | } // sepTuple | 
|---|
| 372 |  | 
|---|
| 373 | ostype & nl( ostype & os ) { | 
|---|
| 374 | (ostype &)(os | '\n'); | 
|---|
| 375 | $setPrt( os, false );                                                   // turn off | 
|---|
| 376 | $setNL( os, true ); | 
|---|
| 377 | flush( os ); | 
|---|
| 378 | return sepOff( os );                                                    // prepare for next line | 
|---|
| 379 | } // nl | 
|---|
| 380 |  | 
|---|
| 381 | ostype & nonl( ostype & os ) { | 
|---|
| 382 | $setPrt( os, false );                                                   // turn off | 
|---|
| 383 | return os; | 
|---|
| 384 | } // nonl | 
|---|
| 385 |  | 
|---|
| 386 | ostype & sepOn( ostype & os ) { | 
|---|
| 387 | sepOn( os );                                                                    // call void returning | 
|---|
| 388 | return os; | 
|---|
| 389 | } // sepOn | 
|---|
| 390 |  | 
|---|
| 391 | ostype & sepOff( ostype & os ) { | 
|---|
| 392 | sepOff( os );                                                                   // call void returning | 
|---|
| 393 | return os; | 
|---|
| 394 | } // sepOff | 
|---|
| 395 |  | 
|---|
| 396 | ostype & sepEnable( ostype & os ) { | 
|---|
| 397 | sepEnable( os );                                                                // call void returning | 
|---|
| 398 | return os; | 
|---|
| 399 | } // sepEnable | 
|---|
| 400 |  | 
|---|
| 401 | ostype & sepDisable( ostype & os ) { | 
|---|
| 402 | sepDisable( os );                                                               // call void returning | 
|---|
| 403 | return os; | 
|---|
| 404 | } // sepDisable | 
|---|
| 405 |  | 
|---|
| 406 | ostype & nlOn( ostype & os ) { | 
|---|
| 407 | nlOn( os );                                                                             // call void returning | 
|---|
| 408 | return os; | 
|---|
| 409 | } // nlOn | 
|---|
| 410 |  | 
|---|
| 411 | ostype & nlOff( ostype & os ) { | 
|---|
| 412 | nlOff( os );                                                                    // call void returning | 
|---|
| 413 | return os; | 
|---|
| 414 | } // nlOff | 
|---|
| 415 | } // distribution | 
|---|
| 416 |  | 
|---|
| 417 | // tuples | 
|---|
| 418 | forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) { | 
|---|
| 419 | ostype & ?|?( ostype & os, T arg, Params rest ) { | 
|---|
| 420 | (ostype &)(os | arg);                                                   // print first argument | 
|---|
| 421 | $sepSetCur( os, sepGetTuple( os ) );                    // switch to tuple separator | 
|---|
| 422 | (ostype &)(os | rest);                                                  // print remaining arguments | 
|---|
| 423 | $sepSetCur( os, sepGet( os ) );                                 // switch to regular separator | 
|---|
| 424 | return os; | 
|---|
| 425 | } // ?|? | 
|---|
| 426 | void ?|?( ostype & os, T arg, Params rest ) { | 
|---|
| 427 | // (ostype &)(?|?( os, arg, rest )); ends( os ); | 
|---|
| 428 | (ostype &)(os | arg);                                                   // print first argument | 
|---|
| 429 | $sepSetCur( os, sepGetTuple( os ) );                    // switch to tuple separator | 
|---|
| 430 | (ostype &)(os | rest);                                                  // print remaining arguments | 
|---|
| 431 | $sepSetCur( os, sepGet( os ) );                                 // switch to regular separator | 
|---|
| 432 | ends( os ); | 
|---|
| 433 | } // ?|? | 
|---|
| 434 | } // distribution | 
|---|
| 435 |  | 
|---|
| 436 | // writes the range [begin, end) to the given stream | 
|---|
| 437 | forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) { | 
|---|
| 438 | void write( iterator_type begin, iterator_type end, ostype & os ) { | 
|---|
| 439 | void print( elt_type i ) { os | i; } | 
|---|
| 440 | for_each( begin, end, print ); | 
|---|
| 441 | } // ?|? | 
|---|
| 442 |  | 
|---|
| 443 | void write_reverse( iterator_type begin, iterator_type end, ostype & os ) { | 
|---|
| 444 | void print( elt_type i ) { os | i; } | 
|---|
| 445 | for_each_reverse( begin, end, print ); | 
|---|
| 446 | } // ?|? | 
|---|
| 447 | } // distribution | 
|---|
| 448 |  | 
|---|
| 449 | //*********************************** manipulators *********************************** | 
|---|
| 450 |  | 
|---|
| 451 | //*********************************** integral *********************************** | 
|---|
| 452 |  | 
|---|
| 453 | static const char * shortbin[] = { "0", "1", "10", "11", "100", "101", "110", "111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111" }; | 
|---|
| 454 | static const char * longbin[]  = { "0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111" }; | 
|---|
| 455 |  | 
|---|
| 456 | // Default prefix for non-decimal prints is 0b, 0, 0x. | 
|---|
| 457 | #define IntegralFMTImpl( T, CODE, IFMTNP, IFMTP ) \ | 
|---|
| 458 | forall( dtype ostype | ostream( ostype ) ) { \ | 
|---|
| 459 | ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \ | 
|---|
| 460 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); \ | 
|---|
| 461 | \ | 
|---|
| 462 | if ( f.base == 'b' || f.base == 'B' ) {                 /* bespoke binary format */ \ | 
|---|
| 463 | int bits = high1( f.val );                                      /* position of most significant bit */ \ | 
|---|
| 464 | if ( bits == 0 ) bits = 1;                                      /* 0 value => force one bit to print */ \ | 
|---|
| 465 | int spaces = f.wd - bits;                                       /* can be negative */ \ | 
|---|
| 466 | if ( ! f.flags.nobsdp ) { spaces -= 2; }        /* base prefix takes space */ \ | 
|---|
| 467 | /* printf( "%d %d\n", bits, spaces ); */ \ | 
|---|
| 468 | if ( ! f.flags.left ) {                                         /* right justified ? */ \ | 
|---|
| 469 | /* Note, base prefix then zero padding or spacing then prefix. */ \ | 
|---|
| 470 | if ( f.flags.pad0 || f.flags.pc ) { \ | 
|---|
| 471 | if ( ! f.flags.nobsdp ) { fmt( os, "0%c", f.base ); } \ | 
|---|
| 472 | if ( f.flags.pc ) spaces = f.pc - bits; \ | 
|---|
| 473 | if ( spaces > 0 ) fmt( os, "%0*d", spaces, 0 ); /* zero pad */ \ | 
|---|
| 474 | } else { \ | 
|---|
| 475 | if ( spaces > 0 ) fmt( os, "%*s", spaces, " " ); /* space pad */ \ | 
|---|
| 476 | if ( ! f.flags.nobsdp ) { fmt( os, "0%c", f.base ); } \ | 
|---|
| 477 | } /* if */ \ | 
|---|
| 478 | } else if ( ! f.flags.nobsdp ) { \ | 
|---|
| 479 | fmt( os, "0%c", f.base ); \ | 
|---|
| 480 | } /* if */ \ | 
|---|
| 481 | int shift = (bits - 1) / 4 * 4; /* floor( bits - 1, 4 ) */ \ | 
|---|
| 482 | typeof( f.val ) temp = f.val; \ | 
|---|
| 483 | fmt( os, "%s", shortbin[(temp >> shift) & 0xf] ); \ | 
|---|
| 484 | for () { \ | 
|---|
| 485 | shift -= 4; \ | 
|---|
| 486 | if ( shift < 0 ) break; \ | 
|---|
| 487 | temp = f.val; \ | 
|---|
| 488 | fmt( os, "%s", longbin[(temp >> shift) & 0xf] ); \ | 
|---|
| 489 | } /* for */ \ | 
|---|
| 490 | if ( f.flags.left && spaces > 0 ) fmt( os, "%*s", spaces, " " ); \ | 
|---|
| 491 | return os; \ | 
|---|
| 492 | } /* if  */ \ | 
|---|
| 493 | \ | 
|---|
| 494 | char fmtstr[sizeof(IFMTP)];                                             /* sizeof includes '\0' */ \ | 
|---|
| 495 | if ( ! f.flags.pc ) memcpy( &fmtstr, IFMTNP, sizeof(IFMTNP) ); \ | 
|---|
| 496 | else memcpy( &fmtstr, IFMTP, sizeof(IFMTP) ); \ | 
|---|
| 497 | int star = 4;                                                                   /* position before first '*' */ \ | 
|---|
| 498 | \ | 
|---|
| 499 | /* Insert flags into spaces before '*', from right to left. */ \ | 
|---|
| 500 | if ( ! f.flags.nobsdp ) { fmtstr[star] = '#'; star -= 1; } \ | 
|---|
| 501 | if ( f.flags.left ) { fmtstr[star] = '-'; star -= 1; } \ | 
|---|
| 502 | if ( f.flags.sign && f.base == CODE ) { fmtstr[star] = '+'; star -= 1; } \ | 
|---|
| 503 | if ( f.flags.pad0 && ! f.flags.pc ) { fmtstr[star] = '0'; star -= 1; } \ | 
|---|
| 504 | fmtstr[star] = '%'; \ | 
|---|
| 505 | \ | 
|---|
| 506 | if ( ! f.flags.pc ) {                                                   /* no precision */ \ | 
|---|
| 507 | fmtstr[sizeof(IFMTNP)-2] = f.base;                      /* sizeof includes '\0' */ \ | 
|---|
| 508 | /* printf( "%s %c %c\n", &fmtstr[star], f.base, CODE ); */ \ | 
|---|
| 509 | fmt( os, &fmtstr[star], f.wd, f.val ); \ | 
|---|
| 510 | } else {                                                                                /* precision */ \ | 
|---|
| 511 | fmtstr[sizeof(IFMTP)-2] = f.base;                       /* sizeof includes '\0' */ \ | 
|---|
| 512 | /* printf( "%s %c %c\n", &fmtstr[star], f.base, CODE ); */ \ | 
|---|
| 513 | fmt( os, &fmtstr[star], f.wd, f.pc, f.val ); \ | 
|---|
| 514 | } /* if */ \ | 
|---|
| 515 | return os; \ | 
|---|
| 516 | } /* ?|? */ \ | 
|---|
| 517 | void ?|?( ostype & os, _Ostream_Manip(T) f ) { (ostype &)(os | f); ends( os ); } \ | 
|---|
| 518 | } // distribution | 
|---|
| 519 |  | 
|---|
| 520 | IntegralFMTImpl( signed char, 'd', "%    *hh ", "%    *.*hh " ) | 
|---|
| 521 | IntegralFMTImpl( unsigned char, 'u', "%    *hh ", "%    *.*hh " ) | 
|---|
| 522 | IntegralFMTImpl( signed short int, 'd', "%    *h ", "%    *.*h " ) | 
|---|
| 523 | IntegralFMTImpl( unsigned short int, 'u', "%    *h ", "%    *.*h " ) | 
|---|
| 524 | IntegralFMTImpl( signed int, 'd', "%    * ", "%    *.* " ) | 
|---|
| 525 | IntegralFMTImpl( unsigned int, 'u', "%    * ", "%    *.* " ) | 
|---|
| 526 | IntegralFMTImpl( signed long int, 'd', "%    *l ", "%    *.*l " ) | 
|---|
| 527 | IntegralFMTImpl( unsigned long int, 'u', "%    *l ", "%    *.*l " ) | 
|---|
| 528 | IntegralFMTImpl( signed long long int, 'd', "%    *ll ", "%    *.*ll " ) | 
|---|
| 529 | IntegralFMTImpl( unsigned long long int, 'u', "%    *ll ", "%    *.*ll " ) | 
|---|
| 530 |  | 
|---|
| 531 |  | 
|---|
| 532 | #if defined( __SIZEOF_INT128__ ) | 
|---|
| 533 | // Default prefix for non-decimal prints is 0b, 0, 0x. | 
|---|
| 534 | #define IntegralFMTImpl128( T, SIGNED, CODE, IFMTNP, IFMTP ) \ | 
|---|
| 535 | forall( dtype ostype | ostream( ostype ) ) \ | 
|---|
| 536 | static void base10_128( ostype & os, _Ostream_Manip(T) f ) { \ | 
|---|
| 537 | if ( f.val > UINT64_MAX ) { \ | 
|---|
| 538 | unsigned long long int lsig = f.val % P10_UINT64; \ | 
|---|
| 539 | f.val /= P10_UINT64; /* msig */ \ | 
|---|
| 540 | base10_128( os, f ); /* recursion */ \ | 
|---|
| 541 | _Ostream_Manip(unsigned long long int) fmt @= { lsig, 0, 19, 'u', { .all : 0 } }; \ | 
|---|
| 542 | fmt.flags.nobsdp = true; \ | 
|---|
| 543 | /* printf( "fmt1 %c %lld %d\n", fmt.base, fmt.val, fmt.all ); */ \ | 
|---|
| 544 | sepOff( os ); \ | 
|---|
| 545 | (ostype &)(os | fmt); \ | 
|---|
| 546 | } else { \ | 
|---|
| 547 | /* printf( "fmt2 %c %lld %d\n", f.base, (unsigned long long int)f.val, f.all ); */ \ | 
|---|
| 548 | _Ostream_Manip(SIGNED long long int) fmt @= { (SIGNED long long int)f.val, f.wd, f.pc, f.base, { .all : f.all } }; \ | 
|---|
| 549 | (ostype &)(os | fmt); \ | 
|---|
| 550 | } /* if */ \ | 
|---|
| 551 | } /* base10_128 */ \ | 
|---|
| 552 | forall( dtype ostype | ostream( ostype ) ) { \ | 
|---|
| 553 | ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \ | 
|---|
| 554 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); \ | 
|---|
| 555 | \ | 
|---|
| 556 | if ( f.base == 'b' | f.base == 'B' | f.base == 'o' | f.base == 'x' | f.base == 'X' ) { \ | 
|---|
| 557 | unsigned long long int msig = (unsigned long long int)(f.val >> 64); \ | 
|---|
| 558 | unsigned long long int lsig = (unsigned long long int)(f.val); \ | 
|---|
| 559 | _Ostream_Manip(SIGNED long long int) fmt @= { msig, f.wd, f.pc, f.base, { .all : f.all } }; \ | 
|---|
| 560 | _Ostream_Manip(unsigned long long int) fmt2 @= { lsig, 0, 0, f.base, { .all : 0 } }; \ | 
|---|
| 561 | if ( msig == 0 ) { \ | 
|---|
| 562 | fmt.val = lsig; \ | 
|---|
| 563 | (ostype &)(os | fmt); \ | 
|---|
| 564 | } else { \ | 
|---|
| 565 | fmt2.flags.pad0 = fmt2.flags.nobsdp = true;     \ | 
|---|
| 566 | if ( f.base == 'b' | f.base == 'B' ) { \ | 
|---|
| 567 | if ( fmt.flags.pc && fmt.pc > 64 ) fmt.pc -= 64; \ | 
|---|
| 568 | if ( fmt.flags.left ) { \ | 
|---|
| 569 | fmt2.wd = fmt.wd; \ | 
|---|
| 570 | if ( fmt2.wd <= 64 ) { \ | 
|---|
| 571 | fmt2.wd = 64; \ | 
|---|
| 572 | } else { \ | 
|---|
| 573 | if ( fmt.pc > 0 ) { \ | 
|---|
| 574 | fmt2.wd -= fmt.pc; \ | 
|---|
| 575 | } else { \ | 
|---|
| 576 | fmt2.wd = fmt.wd - high1( msig ); \ | 
|---|
| 577 | } /* if */ \ | 
|---|
| 578 | if ( ! fmt.flags.nobsdp ) fmt2.wd -= 2; \ | 
|---|
| 579 | if ( fmt2.wd < 0 ) fmt2.wd = 0; \ | 
|---|
| 580 | fmt2.flags.left = true; \ | 
|---|
| 581 | fmt.wd = 0; \ | 
|---|
| 582 | } /* if */ \ | 
|---|
| 583 | printf( "left %d %d %x\n", f.wd, f.pc, f.all ); \ | 
|---|
| 584 | printf( "left %d %d %x\n", fmt.wd, fmt.pc, fmt.all ); \ | 
|---|
| 585 | } else { \ | 
|---|
| 586 | fmt2.wd = 64; \ | 
|---|
| 587 | if ( fmt.wd > 64 ) fmt.wd -= 64; \ | 
|---|
| 588 | printf( "left %d %d %x\n", f.wd, f.pc, f.all ); \ | 
|---|
| 589 | printf( "left %d %d %x\n", fmt.wd, fmt.pc, fmt.all ); \ | 
|---|
| 590 | } /* if */ \ | 
|---|
| 591 | fmt2.pc = 64; fmt2.flags.pc = true;     \ | 
|---|
| 592 | printf( "left %d %d %x\n", fmt2.wd, fmt2.pc, fmt2.all ); \ | 
|---|
| 593 | (ostype &)(os | fmt | "" | fmt2); \ | 
|---|
| 594 | } else if ( f.base == 'o' ) { \ | 
|---|
| 595 | if ( fmt.flags.pc && fmt.pc > 22 ) fmt.pc -= 22; \ | 
|---|
| 596 | if ( fmt.flags.left ) { \ | 
|---|
| 597 | fmt.flags.left = false; \ | 
|---|
| 598 | fmt.wd = 1; \ | 
|---|
| 599 | fmt.val = (unsigned long long int)fmt.val >> 2; \ | 
|---|
| 600 | fmt2.wd = 1; \ | 
|---|
| 601 | fmt2.val = ((msig & 0x3) << 1) + ((lsig & 0x8000000000000000U) != 0); \ | 
|---|
| 602 | if ( fmt2.val > 1 && fmt.flags.pc && fmt.pc > 0 ) fmt.pc -= 1; \ | 
|---|
| 603 | /* printf( "L %llo %llo %llo %llo %d %d '%c' %x\n", msig, lsig, fmt.val, fmt2.val, fmt.wd, fmt.pc, fmt.base, fmt.all ); */ \ | 
|---|
| 604 | (ostype &)(os | fmt | "" | fmt2); \ | 
|---|
| 605 | sepOff( os ); \ | 
|---|
| 606 | fmt2.flags.left = true; \ | 
|---|
| 607 | int msigd = ceiling( high1( fmt.val ), 3 ) + 1; \ | 
|---|
| 608 | fmt2.wd = f.wd - (fmt.pc > msigd ? fmt.pc : msigd); \ | 
|---|
| 609 | if ( fmt2.wd < 0 ) fmt2.wd = 21; \ | 
|---|
| 610 | fmt2.flags.pc = true; fmt2.pc = 21; \ | 
|---|
| 611 | if ( ! fmt.flags.nobsdp ) { if ( fmt.pc < fmt.wd ) fmt.wd -= 1; else fmt.pc -= 1; } \ | 
|---|
| 612 | fmt2.val = lsig & 0x7fffffffffffffffU; \ | 
|---|
| 613 | (ostype &)(os | fmt2); \ | 
|---|
| 614 | } else { \ | 
|---|
| 615 | fmt.val = (unsigned long long int)fmt.val >> 2; \ | 
|---|
| 616 | if ( fmt.wd > 21 ) fmt.wd -= 21; \ | 
|---|
| 617 | if ( ! fmt.flags.nobsdp ) { if ( fmt.pc < fmt.wd ) fmt.wd -= 1; else fmt.pc -= 1; } \ | 
|---|
| 618 | fmt2.wd = 1; \ | 
|---|
| 619 | fmt2.val = ((msig & 0x3) << 1) + (lsig & 0x8000000000000000U != 0); \ | 
|---|
| 620 | (ostype &)(os | fmt | "" | fmt2); \ | 
|---|
| 621 | sepOff( os ); \ | 
|---|
| 622 | fmt2.wd = 21; \ | 
|---|
| 623 | fmt2.val = lsig & 0x7fffffffffffffffU; \ | 
|---|
| 624 | (ostype &)(os | fmt2); \ | 
|---|
| 625 | } /* if */ \ | 
|---|
| 626 | } else { \ | 
|---|
| 627 | if ( fmt.flags.pc && fmt.pc > 16 ) fmt.pc -= 16; \ | 
|---|
| 628 | if ( fmt.flags.left ) { \ | 
|---|
| 629 | fmt2.wd = fmt.wd; \ | 
|---|
| 630 | if ( fmt2.wd <= 16 ) { \ | 
|---|
| 631 | fmt2.wd = 16; \ | 
|---|
| 632 | } else { \ | 
|---|
| 633 | if ( fmt.pc > 0 ) { \ | 
|---|
| 634 | fmt2.wd -= fmt.pc; \ | 
|---|
| 635 | } else { \ | 
|---|
| 636 | fmt2.wd = fmt.wd - ceiling2( high1( msig ), 4 ) / 4; \ | 
|---|
| 637 | } /* if */ \ | 
|---|
| 638 | if ( ! fmt.flags.nobsdp ) fmt2.wd -= 2; \ | 
|---|
| 639 | if ( fmt2.wd < 0 ) fmt2.wd = 0; \ | 
|---|
| 640 | fmt2.flags.left = true; \ | 
|---|
| 641 | fmt.wd = 0; \ | 
|---|
| 642 | } /* if */ \ | 
|---|
| 643 | } else { \ | 
|---|
| 644 | fmt2.wd = 16; \ | 
|---|
| 645 | if ( fmt.wd > 16 ) fmt.wd -= 16; \ | 
|---|
| 646 | } /* if */ \ | 
|---|
| 647 | fmt2.pc = 16; fmt2.flags.pc = true; \ | 
|---|
| 648 | (ostype &)(os | fmt | "" | fmt2); \ | 
|---|
| 649 | } /* if */ \ | 
|---|
| 650 | } /* if */ \ | 
|---|
| 651 | } else { \ | 
|---|
| 652 | if ( CODE == 'd' ) { \ | 
|---|
| 653 | if ( f.val < 0 )  { fmt( os, "-" ); sepOff( os ); f.val = -f.val; f.flags.sign = false; } \ | 
|---|
| 654 | } /* if */ \ | 
|---|
| 655 | base10_128( os, f ); \ | 
|---|
| 656 | } /* if */ \ | 
|---|
| 657 | return os; \ | 
|---|
| 658 | } /* ?|? */ \ | 
|---|
| 659 | void ?|?( ostype & os, _Ostream_Manip(T) f ) { (ostype &)(os | f); ends( os ); } \ | 
|---|
| 660 | } // distribution | 
|---|
| 661 |  | 
|---|
| 662 | IntegralFMTImpl128( int128, signed, 'd', "%    *ll ", "%    *.*ll " ) | 
|---|
| 663 | IntegralFMTImpl128( unsigned int128, unsigned, 'u', "%    *ll ", "%    *.*ll " ) | 
|---|
| 664 | #endif // __SIZEOF_INT128__ | 
|---|
| 665 |  | 
|---|
| 666 | //*********************************** floating point *********************************** | 
|---|
| 667 |  | 
|---|
| 668 | #define PrintWithDP2( os, format, val, ... ) \ | 
|---|
| 669 | { \ | 
|---|
| 670 | enum { size = 48 }; \ | 
|---|
| 671 | char buf[size]; \ | 
|---|
| 672 | int bufbeg = 0, i, len = snprintf( buf, size, format, ##__VA_ARGS__, val ); \ | 
|---|
| 673 | if ( isfinite( val ) && (f.base != 'g' || f.pc != 0) ) { /* if number, print decimal point */ \ | 
|---|
| 674 | for ( i = 0; i < len && buf[i] != '.' && buf[i] != 'e' && buf[i] != 'E'; i += 1 ); /* decimal point or scientific ? */ \ | 
|---|
| 675 | if ( i == len && ! f.flags.nobsdp ) { \ | 
|---|
| 676 | if ( ! f.flags.left ) { \ | 
|---|
| 677 | buf[i] = '.'; buf[i + 1] = '\0'; \ | 
|---|
| 678 | if ( buf[0] == ' ' ) bufbeg = 1;        /* decimal point within width */ \ | 
|---|
| 679 | } else { \ | 
|---|
| 680 | for ( i = 0; i < len && buf[i] != ' '; i += 1 ); /* trailing blank ? */ \ | 
|---|
| 681 | buf[i] = '.'; \ | 
|---|
| 682 | if ( i == len ) buf[i + 1] = '\0'; \ | 
|---|
| 683 | } /* if */ \ | 
|---|
| 684 | } /* if */ \ | 
|---|
| 685 | } /* if */ \ | 
|---|
| 686 | fmt( os, "%s", &buf[bufbeg] ); \ | 
|---|
| 687 | } | 
|---|
| 688 |  | 
|---|
| 689 | #define FloatingPointFMTImpl( T, DFMTNP, DFMTP ) \ | 
|---|
| 690 | forall( dtype ostype | ostream( ostype ) ) { \ | 
|---|
| 691 | ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \ | 
|---|
| 692 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); \ | 
|---|
| 693 | char fmtstr[sizeof(DFMTP)];                                             /* sizeof includes '\0' */ \ | 
|---|
| 694 | if ( ! f.flags.pc ) memcpy( &fmtstr, DFMTNP, sizeof(DFMTNP) ); \ | 
|---|
| 695 | else memcpy( &fmtstr, DFMTP, sizeof(DFMTP) ); \ | 
|---|
| 696 | int star = 4;                                                                   /* position before first '*' */ \ | 
|---|
| 697 | \ | 
|---|
| 698 | /* Insert flags into spaces before '*', from right to left. */ \ | 
|---|
| 699 | if ( f.flags.left ) { fmtstr[star] = '-'; star -= 1; } \ | 
|---|
| 700 | if ( f.flags.sign ) { fmtstr[star] = '+'; star -= 1; } \ | 
|---|
| 701 | if ( f.flags.pad0 ) { fmtstr[star] = '0'; star -= 1; } \ | 
|---|
| 702 | fmtstr[star] = '%'; \ | 
|---|
| 703 | \ | 
|---|
| 704 | if ( ! f.flags.pc ) {                                                   /* no precision */ \ | 
|---|
| 705 | fmtstr[sizeof(DFMTNP)-2] = f.base;                      /* sizeof includes '\0' */ \ | 
|---|
| 706 | /* printf( "%g %d %s\n", f.val, f.wd, &fmtstr[star]); */ \ | 
|---|
| 707 | PrintWithDP2( os, &fmtstr[star], f.val, f.wd ) \ | 
|---|
| 708 | } else {                                                                                /* precision */ \ | 
|---|
| 709 | fmtstr[sizeof(DFMTP)-2] = f.base;                       /* sizeof includes '\0' */ \ | 
|---|
| 710 | /* printf( "%g %d %d %s\n", f.val, f.wd, f.pc, &fmtstr[star] ); */ \ | 
|---|
| 711 | PrintWithDP2( os, &fmtstr[star], f.val, f.wd, f.pc ) \ | 
|---|
| 712 | } /* if */ \ | 
|---|
| 713 | return os; \ | 
|---|
| 714 | } /* ?|? */ \ | 
|---|
| 715 | \ | 
|---|
| 716 | void ?|?( ostype & os, _Ostream_Manip(T) f ) { (ostype &)(os | f); ends( os ); } \ | 
|---|
| 717 | } // distribution | 
|---|
| 718 |  | 
|---|
| 719 | FloatingPointFMTImpl( double, "%    * ", "%    *.* " ) | 
|---|
| 720 | FloatingPointFMTImpl( long double, "%    *L ", "%    *.*L " ) | 
|---|
| 721 |  | 
|---|
| 722 | //*********************************** character *********************************** | 
|---|
| 723 |  | 
|---|
| 724 | forall( dtype ostype | ostream( ostype ) ) { | 
|---|
| 725 | ostype & ?|?( ostype & os, _Ostream_Manip(char) f ) { | 
|---|
| 726 | if ( f.base != 'c' ) {                                                  // bespoke binary/octal/hex format | 
|---|
| 727 | _Ostream_Manip(unsigned char) fmtuc @= { f.val, f.wd, f.pc, f.base, {'\0'} }; | 
|---|
| 728 | fmtuc.flags.pc = f.flags.pc; | 
|---|
| 729 | fmtuc.flags.nobsdp = f.flags.nobsdp; | 
|---|
| 730 | //                      os | fmtuc | nonl; | 
|---|
| 731 | (ostype &)(os | fmtuc); | 
|---|
| 732 | return os; | 
|---|
| 733 | } // if | 
|---|
| 734 |  | 
|---|
| 735 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 736 |  | 
|---|
| 737 | #define CFMTNP "% * " | 
|---|
| 738 | char fmtstr[sizeof(CFMTNP)];                                    // sizeof includes '\0' | 
|---|
| 739 | memcpy( &fmtstr, CFMTNP, sizeof(CFMTNP) ); | 
|---|
| 740 | int star = 1;                                                                   // position before first '*' | 
|---|
| 741 |  | 
|---|
| 742 | // Insert flags into spaces before '*', from right to left. | 
|---|
| 743 | if ( f.flags.left ) { fmtstr[star] = '-'; star -= 1; } | 
|---|
| 744 | fmtstr[star] = '%'; | 
|---|
| 745 |  | 
|---|
| 746 | fmtstr[sizeof(CFMTNP)-2] = f.base;                              // sizeof includes '\0' | 
|---|
| 747 | // printf( "%d %s\n", f.wd, &fmtstr[star] ); | 
|---|
| 748 | fmt( os, &fmtstr[star], f.wd, f.val ); | 
|---|
| 749 | return os; | 
|---|
| 750 | } // ?|? | 
|---|
| 751 |  | 
|---|
| 752 | void ?|?( ostype & os, _Ostream_Manip(char) f ) { (ostype &)(os | f); ends( os ); } | 
|---|
| 753 | } // distribution | 
|---|
| 754 |  | 
|---|
| 755 | //*********************************** C string *********************************** | 
|---|
| 756 |  | 
|---|
| 757 | forall( dtype ostype | ostream( ostype ) ) { | 
|---|
| 758 | ostype & ?|?( ostype & os, _Ostream_Manip(const char *) f ) { | 
|---|
| 759 | if ( ! f.val ) return os;                                               // null pointer ? | 
|---|
| 760 |  | 
|---|
| 761 | if ( f.base != 's' ) {                                                  // bespoke binary/octal/hex format | 
|---|
| 762 | _Ostream_Manip(unsigned char) fmtuc @= { 0, f.wd, f.pc, f.base, {'\0'} }; | 
|---|
| 763 | fmtuc.flags.pc = f.flags.pc; | 
|---|
| 764 | fmtuc.flags.nobsdp = f.flags.nobsdp; | 
|---|
| 765 | for ( unsigned int i = 0; f.val[i] != '\0'; i += 1 ) { | 
|---|
| 766 | fmtuc.val = f.val[i]; | 
|---|
| 767 | //                              os | fmtuc | nonl; | 
|---|
| 768 | (ostype &)(os | fmtuc); | 
|---|
| 769 | } // for | 
|---|
| 770 | return os; | 
|---|
| 771 | } // if | 
|---|
| 772 |  | 
|---|
| 773 | if ( $sepPrt( os ) ) fmt( os, "%s", $sepGetCur( os ) ); | 
|---|
| 774 |  | 
|---|
| 775 | #define SFMTNP "% * " | 
|---|
| 776 | #define SFMTP "% *.* " | 
|---|
| 777 | char fmtstr[sizeof(SFMTP)];                                             // sizeof includes '\0' | 
|---|
| 778 | if ( ! f.flags.pc ) memcpy( &fmtstr, SFMTNP, sizeof(SFMTNP) ); | 
|---|
| 779 | else memcpy( &fmtstr, SFMTP, sizeof(SFMTP) ); | 
|---|
| 780 | int star = 1;                                                                   // position before first '*' | 
|---|
| 781 |  | 
|---|
| 782 | // Insert flags into spaces before '*', from right to left. | 
|---|
| 783 | if ( f.flags.left ) { fmtstr[star] = '-'; star -= 1; } | 
|---|
| 784 | fmtstr[star] = '%'; | 
|---|
| 785 |  | 
|---|
| 786 | if ( ! f.flags.pc ) {                                                   // no precision | 
|---|
| 787 | // printf( "%d %s\n", f.wd, &fmtstr[star] ); | 
|---|
| 788 | fmtstr[sizeof(SFMTNP)-2] = f.base;                      // sizeof includes '\0' | 
|---|
| 789 | fmt( os, &fmtstr[star], f.wd, f.val ); | 
|---|
| 790 | } else {                                                                                // precision | 
|---|
| 791 | fmtstr[sizeof(SFMTP)-2] = f.base;                       // sizeof includes '\0' | 
|---|
| 792 | // printf( "%d %d %s\n", f.wd, f.pc, &fmtstr[star] ); | 
|---|
| 793 | fmt( os, &fmtstr[star], f.wd, f.pc, f.val ); | 
|---|
| 794 | } // if | 
|---|
| 795 | return os; | 
|---|
| 796 | } // ?|? | 
|---|
| 797 |  | 
|---|
| 798 | void ?|?( ostype & os, _Ostream_Manip(const char *) f ) { (ostype &)(os | f); ends( os ); } | 
|---|
| 799 | } // distribution | 
|---|
| 800 |  | 
|---|
| 801 |  | 
|---|
| 802 | //*********************************** istream *********************************** | 
|---|
| 803 |  | 
|---|
| 804 |  | 
|---|
| 805 | forall( dtype istype | istream( istype ) ) { | 
|---|
| 806 | istype & ?|?( istype & is, bool & b ) { | 
|---|
| 807 | char val[6]; | 
|---|
| 808 | fmt( is, "%5s", val ); | 
|---|
| 809 | if ( strcmp( val, "true" ) == 0 ) b = true; | 
|---|
| 810 | else if ( strcmp( val, "false" ) == 0 ) b = false; | 
|---|
| 811 | else { | 
|---|
| 812 | fprintf( stderr, "invalid Boolean constant\n" ); | 
|---|
| 813 | abort();                                                                        // cannot use abort stream | 
|---|
| 814 | } // if | 
|---|
| 815 | return is; | 
|---|
| 816 | } // ?|? | 
|---|
| 817 |  | 
|---|
| 818 | istype & ?|?( istype & is, char & c ) { | 
|---|
| 819 | char temp; | 
|---|
| 820 | for () { | 
|---|
| 821 | fmt( is, "%c", &temp );                                         // must pass pointer through varg to fmt | 
|---|
| 822 | // do not overwrite parameter with newline unless appropriate | 
|---|
| 823 | if ( temp != '\n' || getANL( is ) ) { c = temp; break; } | 
|---|
| 824 | if ( eof( is ) ) break; | 
|---|
| 825 | } // for | 
|---|
| 826 | return is; | 
|---|
| 827 | } // ?|? | 
|---|
| 828 |  | 
|---|
| 829 | istype & ?|?( istype & is, signed char & sc ) { | 
|---|
| 830 | fmt( is, "%hhi", &sc ); | 
|---|
| 831 | return is; | 
|---|
| 832 | } // ?|? | 
|---|
| 833 |  | 
|---|
| 834 | istype & ?|?( istype & is, unsigned char & usc ) { | 
|---|
| 835 | fmt( is, "%hhi", &usc ); | 
|---|
| 836 | return is; | 
|---|
| 837 | } // ?|? | 
|---|
| 838 |  | 
|---|
| 839 | istype & ?|?( istype & is, short int & si ) { | 
|---|
| 840 | fmt( is, "%hi", &si ); | 
|---|
| 841 | return is; | 
|---|
| 842 | } // ?|? | 
|---|
| 843 |  | 
|---|
| 844 | istype & ?|?( istype & is, unsigned short int & usi ) { | 
|---|
| 845 | fmt( is, "%hi", &usi ); | 
|---|
| 846 | return is; | 
|---|
| 847 | } // ?|? | 
|---|
| 848 |  | 
|---|
| 849 | istype & ?|?( istype & is, int & i ) { | 
|---|
| 850 | fmt( is, "%i", &i ); | 
|---|
| 851 | return is; | 
|---|
| 852 | } // ?|? | 
|---|
| 853 |  | 
|---|
| 854 | istype & ?|?( istype & is, unsigned int & ui ) { | 
|---|
| 855 | fmt( is, "%i", &ui ); | 
|---|
| 856 | return is; | 
|---|
| 857 | } // ?|? | 
|---|
| 858 |  | 
|---|
| 859 | istype & ?|?( istype & is, long int & li ) { | 
|---|
| 860 | fmt( is, "%li", &li ); | 
|---|
| 861 | return is; | 
|---|
| 862 | } // ?|? | 
|---|
| 863 |  | 
|---|
| 864 | istype & ?|?( istype & is, unsigned long int & ulli ) { | 
|---|
| 865 | fmt( is, "%li", &ulli ); | 
|---|
| 866 | return is; | 
|---|
| 867 | } // ?|? | 
|---|
| 868 |  | 
|---|
| 869 | istype & ?|?( istype & is, long long int & lli ) { | 
|---|
| 870 | fmt( is, "%lli", &lli ); | 
|---|
| 871 | return is; | 
|---|
| 872 | } // ?|? | 
|---|
| 873 |  | 
|---|
| 874 | istype & ?|?( istype & is, unsigned long long int & ulli ) { | 
|---|
| 875 | fmt( is, "%lli", &ulli ); | 
|---|
| 876 | return is; | 
|---|
| 877 | } // ?|? | 
|---|
| 878 |  | 
|---|
| 879 |  | 
|---|
| 880 | istype & ?|?( istype & is, float & f ) { | 
|---|
| 881 | fmt( is, "%f", &f ); | 
|---|
| 882 | return is; | 
|---|
| 883 | } // ?|? | 
|---|
| 884 |  | 
|---|
| 885 | istype & ?|?( istype & is, double & d ) { | 
|---|
| 886 | fmt( is, "%lf", &d ); | 
|---|
| 887 | return is; | 
|---|
| 888 | } // ?|? | 
|---|
| 889 |  | 
|---|
| 890 | istype & ?|?( istype & is, long double & ld ) { | 
|---|
| 891 | fmt( is, "%Lf", &ld ); | 
|---|
| 892 | return is; | 
|---|
| 893 | } // ?|? | 
|---|
| 894 |  | 
|---|
| 895 |  | 
|---|
| 896 | istype & ?|?( istype & is, float _Complex & fc ) { | 
|---|
| 897 | float re, im; | 
|---|
| 898 | fmt( is, "%f%fi", &re, &im ); | 
|---|
| 899 | fc = re + im * _Complex_I; | 
|---|
| 900 | return is; | 
|---|
| 901 | } // ?|? | 
|---|
| 902 |  | 
|---|
| 903 | istype & ?|?( istype & is, double _Complex & dc ) { | 
|---|
| 904 | double re, im; | 
|---|
| 905 | fmt( is, "%lf%lfi", &re, &im ); | 
|---|
| 906 | dc = re + im * _Complex_I; | 
|---|
| 907 | return is; | 
|---|
| 908 | } // ?|? | 
|---|
| 909 |  | 
|---|
| 910 | istype & ?|?( istype & is, long double _Complex & ldc ) { | 
|---|
| 911 | long double re, im; | 
|---|
| 912 | fmt( is, "%Lf%Lfi", &re, &im ); | 
|---|
| 913 | ldc = re + im * _Complex_I; | 
|---|
| 914 | return is; | 
|---|
| 915 | } // ?|? | 
|---|
| 916 |  | 
|---|
| 917 | // istype & ?|?( istype & is, const char fmt[] ) { | 
|---|
| 918 | //      fmt( is, fmt, "" ); | 
|---|
| 919 | //      return is; | 
|---|
| 920 | // } // ?|? | 
|---|
| 921 |  | 
|---|
| 922 | istype & ?|?( istype & is, char * s ) { | 
|---|
| 923 | fmt( is, "%s", s ); | 
|---|
| 924 | return is; | 
|---|
| 925 | } // ?|? | 
|---|
| 926 |  | 
|---|
| 927 | // manipulators | 
|---|
| 928 | istype & ?|?( istype & is, istype & (* manip)( istype & ) ) { | 
|---|
| 929 | return manip( is ); | 
|---|
| 930 | } // ?|? | 
|---|
| 931 |  | 
|---|
| 932 | istype & nl( istype & is ) { | 
|---|
| 933 | fmt( is, "%*[^\n]" );                                                   // ignore characters to newline | 
|---|
| 934 | return is; | 
|---|
| 935 | } // nl | 
|---|
| 936 |  | 
|---|
| 937 | istype & nlOn( istype & is ) { | 
|---|
| 938 | nlOn( is );                                                                             // call void returning | 
|---|
| 939 | return is; | 
|---|
| 940 | } // nlOn | 
|---|
| 941 |  | 
|---|
| 942 | istype & nlOff( istype & is ) { | 
|---|
| 943 | nlOff( is );                                                                    // call void returning | 
|---|
| 944 | return is; | 
|---|
| 945 | } // nlOff | 
|---|
| 946 | } // distribution | 
|---|
| 947 |  | 
|---|
| 948 | //*********************************** manipulators *********************************** | 
|---|
| 949 |  | 
|---|
| 950 | forall( dtype istype | istream( istype ) ) | 
|---|
| 951 | istype & ?|?( istype & is, _Istream_Cstr f ) { | 
|---|
| 952 | // skip xxx | 
|---|
| 953 | if ( ! f.s ) { | 
|---|
| 954 | // printf( "skip %s %d\n", f.scanset, f.wd ); | 
|---|
| 955 | if ( f.wd == -1 ) fmt( is, f.scanset, "" );             // no input arguments | 
|---|
| 956 | else for ( f.wd ) fmt( is, "%*c" ); | 
|---|
| 957 | return is; | 
|---|
| 958 | } // if | 
|---|
| 959 | size_t len = 0; | 
|---|
| 960 | if ( f.scanset ) len = strlen( f.scanset ); | 
|---|
| 961 | char fmtstr[len + 16]; | 
|---|
| 962 | int start = 1; | 
|---|
| 963 | fmtstr[0] = '%'; | 
|---|
| 964 | if ( f.flags.ignore ) { fmtstr[1] = '*'; start += 1; } | 
|---|
| 965 | if ( f.wd != -1 ) { start += sprintf( &fmtstr[start], "%d", f.wd ); } | 
|---|
| 966 | // cstr %s, %*s, %ws, %*ws | 
|---|
| 967 | if ( ! f.scanset ) { | 
|---|
| 968 | fmtstr[start] = 's'; fmtstr[start + 1] = '\0'; | 
|---|
| 969 | // printf( "cstr %s\n", fmtstr ); | 
|---|
| 970 | fmt( is, fmtstr, f.s ); | 
|---|
| 971 | return is; | 
|---|
| 972 | } // if | 
|---|
| 973 | // incl %[xxx],  %*[xxx],  %w[xxx],  %*w[xxx] | 
|---|
| 974 | // excl %[^xxx], %*[^xxx], %w[^xxx], %*w[^xxx] | 
|---|
| 975 | fmtstr[start] = '['; start += 1; | 
|---|
| 976 | if ( f.flags.inex ) { fmtstr[start] = '^'; start += 1; } | 
|---|
| 977 | strcpy( &fmtstr[start], f.scanset );                            // copy includes '\0' | 
|---|
| 978 | len += start; | 
|---|
| 979 | fmtstr[len] = ']'; fmtstr[len + 1] = '\0'; | 
|---|
| 980 | // printf( "incl/excl %s\n", fmtstr ); | 
|---|
| 981 | fmt( is, fmtstr, f.s ); | 
|---|
| 982 | return is; | 
|---|
| 983 | } // ?|? | 
|---|
| 984 |  | 
|---|
| 985 | forall( dtype istype | istream( istype ) ) | 
|---|
| 986 | istype & ?|?( istype & is, _Istream_Char f ) { | 
|---|
| 987 | fmt( is, "%*c" );                                                                       // argument variable unused | 
|---|
| 988 | return is; | 
|---|
| 989 | } // ?|? | 
|---|
| 990 |  | 
|---|
| 991 | #define InputFMTImpl( T, CODE ) \ | 
|---|
| 992 | forall( dtype istype | istream( istype ) ) \ | 
|---|
| 993 | istype & ?|?( istype & is, _Istream_Manip(T) f ) { \ | 
|---|
| 994 | enum { size = 16 }; \ | 
|---|
| 995 | char fmtstr[size]; \ | 
|---|
| 996 | if ( f.wd == -1 ) { \ | 
|---|
| 997 | snprintf( fmtstr, size, "%%%s%s", f.ignore ? "*" : "", CODE ); \ | 
|---|
| 998 | } else { \ | 
|---|
| 999 | snprintf( fmtstr, size, "%%%s%d%s", f.ignore ? "*" : "", f.wd, CODE ); \ | 
|---|
| 1000 | } /* if */ \ | 
|---|
| 1001 | /* printf( "%d %s %p\n", f.wd, fmtstr, &f.val ); */ \ | 
|---|
| 1002 | fmt( is, fmtstr, &f.val ); \ | 
|---|
| 1003 | return is; \ | 
|---|
| 1004 | } // ?|? | 
|---|
| 1005 |  | 
|---|
| 1006 | InputFMTImpl( signed char, "hhi" ) | 
|---|
| 1007 | InputFMTImpl( unsigned char, "hhi" ) | 
|---|
| 1008 | InputFMTImpl( signed short int, "hi" ) | 
|---|
| 1009 | InputFMTImpl( unsigned short int, "hi" ) | 
|---|
| 1010 | InputFMTImpl( signed int, "i" ) | 
|---|
| 1011 | InputFMTImpl( unsigned int, "i" ) | 
|---|
| 1012 | InputFMTImpl( signed long int, "li" ) | 
|---|
| 1013 | InputFMTImpl( unsigned long int, "li" ) | 
|---|
| 1014 | InputFMTImpl( signed long long int, "lli" ) | 
|---|
| 1015 | InputFMTImpl( unsigned long long int, "lli" ) | 
|---|
| 1016 |  | 
|---|
| 1017 | InputFMTImpl( float, "f" ) | 
|---|
| 1018 | InputFMTImpl( double, "lf" ) | 
|---|
| 1019 | InputFMTImpl( long double, "Lf" ) | 
|---|
| 1020 |  | 
|---|
| 1021 | forall( dtype istype | istream( istype ) ) | 
|---|
| 1022 | istype & ?|?( istype & is, _Istream_Manip(float _Complex) fc ) { | 
|---|
| 1023 | float re, im; | 
|---|
| 1024 | _Istream_Manip(float) fmtuc @= { re, fc.wd, fc.ignore }; | 
|---|
| 1025 | is | fmtuc; | 
|---|
| 1026 | &fmtuc.val = &im; | 
|---|
| 1027 | is | fmtuc; | 
|---|
| 1028 | if ( ! fc.ignore ) fc.val = re + im * _Complex_I;       // re/im are uninitialized for ignore | 
|---|
| 1029 | return is; | 
|---|
| 1030 | } // ?|? | 
|---|
| 1031 |  | 
|---|
| 1032 | forall( dtype istype | istream( istype ) ) | 
|---|
| 1033 | istype & ?|?( istype & is, _Istream_Manip(double _Complex) dc ) { | 
|---|
| 1034 | double re, im; | 
|---|
| 1035 | _Istream_Manip(double) fmtuc @= { re, dc.wd, dc.ignore }; | 
|---|
| 1036 | is | fmtuc; | 
|---|
| 1037 | &fmtuc.val = &im; | 
|---|
| 1038 | is | fmtuc; | 
|---|
| 1039 | if ( ! dc.ignore ) dc.val = re + im * _Complex_I;       // re/im are uninitialized for ignore | 
|---|
| 1040 | return is; | 
|---|
| 1041 | } // ?|? | 
|---|
| 1042 |  | 
|---|
| 1043 | forall( dtype istype | istream( istype ) ) | 
|---|
| 1044 | istype & ?|?( istype & is, _Istream_Manip(long double _Complex) ldc ) { | 
|---|
| 1045 | long double re, im; | 
|---|
| 1046 | _Istream_Manip(long double) fmtuc @= { re, ldc.wd, ldc.ignore }; | 
|---|
| 1047 | is | fmtuc; | 
|---|
| 1048 | &fmtuc.val = &im; | 
|---|
| 1049 | is | fmtuc; | 
|---|
| 1050 | if ( ! ldc.ignore ) ldc.val = re + im * _Complex_I;     // re/im are uninitialized for ignore | 
|---|
| 1051 | return is; | 
|---|
| 1052 | } // ?|? | 
|---|
| 1053 |  | 
|---|
| 1054 | // Local Variables: // | 
|---|
| 1055 | // tab-width: 4 // | 
|---|
| 1056 | // compile-command: "cfa iostream.cfa" // | 
|---|
| 1057 | // End: // | 
|---|