| [86bd7c1f] | 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 | // | 
|---|
| [a5a71d0] | 7 | // iostream.c -- | 
|---|
| [86bd7c1f] | 8 | // | 
|---|
| [90c3b1c] | 9 | // Author           : Peter A. Buhr | 
|---|
| [86bd7c1f] | 10 | // Created On       : Wed May 27 17:56:53 2015 | 
|---|
| [e24f13a] | 11 | // Last Modified By : Peter A. Buhr | 
|---|
| [87d13cd] | 12 | // Last Modified On : Tue Mar 21 22:05:57 2017 | 
|---|
|  | 13 | // Update Count     : 348 | 
|---|
| [86bd7c1f] | 14 | // | 
|---|
| [51b73452] | 15 |  | 
|---|
| [d3b7937] | 16 | #include "iostream" | 
|---|
|  | 17 |  | 
|---|
| [51b73452] | 18 | extern "C" { | 
|---|
|  | 19 | #include <stdio.h> | 
|---|
| [839ccbb] | 20 | #include <string.h>                                                                             // strlen | 
|---|
| [52f85e0] | 21 | #include <float.h>                                                                              // DBL_DIG, LDBL_DIG | 
|---|
| [d3b7937] | 22 | #include <complex.h>                                                                    // creal, cimag | 
|---|
| [51b73452] | 23 | } | 
|---|
|  | 24 |  | 
|---|
|  | 25 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 26 | ostype * ?|?( ostype * os, char c ) { | 
|---|
|  | 27 | fmt( os, "%c", c ); | 
|---|
| [53ba273] | 28 | sepOff( os ); | 
|---|
| [90c3b1c] | 29 | return os; | 
|---|
|  | 30 | } // ?|? | 
|---|
|  | 31 |  | 
|---|
| [1630f18] | 32 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 33 | ostype * ?|?( ostype * os, signed char c ) { | 
|---|
|  | 34 | fmt( os, "%hhd", c ); | 
|---|
| [1630f18] | 35 | sepOff( os ); | 
|---|
|  | 36 | return os; | 
|---|
|  | 37 | } // ?|? | 
|---|
|  | 38 |  | 
|---|
|  | 39 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 40 | ostype * ?|?( ostype * os, unsigned char c ) { | 
|---|
|  | 41 | fmt( os, "%hhu", c ); | 
|---|
| [1630f18] | 42 | sepOff( os ); | 
|---|
|  | 43 | return os; | 
|---|
|  | 44 | } // ?|? | 
|---|
|  | 45 |  | 
|---|
| [90c3b1c] | 46 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 47 | ostype * ?|?( ostype * os, short int si ) { | 
|---|
|  | 48 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 49 | fmt( os, "%hd", si ); | 
|---|
| [90c3b1c] | 50 | return os; | 
|---|
|  | 51 | } // ?|? | 
|---|
|  | 52 |  | 
|---|
|  | 53 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 54 | ostype * ?|?( ostype * os, unsigned short int usi ) { | 
|---|
|  | 55 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 56 | fmt( os, "%hu", usi ); | 
|---|
| [90c3b1c] | 57 | return os; | 
|---|
| [cf16f94] | 58 | } // ?|? | 
|---|
| [51b73452] | 59 |  | 
|---|
|  | 60 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 61 | ostype * ?|?( ostype * os, int i ) { | 
|---|
|  | 62 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 63 | fmt( os, "%d", i ); | 
|---|
| [90c3b1c] | 64 | return os; | 
|---|
| [784deab] | 65 | } // ?|? | 
|---|
|  | 66 |  | 
|---|
|  | 67 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 68 | ostype * ?|?( ostype * os, unsigned int ui ) { | 
|---|
|  | 69 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 70 | fmt( os, "%u", ui ); | 
|---|
| [90c3b1c] | 71 | return os; | 
|---|
| [784deab] | 72 | } // ?|? | 
|---|
|  | 73 |  | 
|---|
|  | 74 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 75 | ostype * ?|?( ostype * os, long int li ) { | 
|---|
|  | 76 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 77 | fmt( os, "%ld", li ); | 
|---|
| [90c3b1c] | 78 | return os; | 
|---|
| [784deab] | 79 | } // ?|? | 
|---|
|  | 80 |  | 
|---|
|  | 81 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 82 | ostype * ?|?( ostype * os, unsigned long int uli ) { | 
|---|
|  | 83 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 84 | fmt( os, "%lu", uli ); | 
|---|
| [90c3b1c] | 85 | return os; | 
|---|
| [784deab] | 86 | } // ?|? | 
|---|
|  | 87 |  | 
|---|
|  | 88 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 89 | ostype * ?|?( ostype * os, long long int lli ) { | 
|---|
|  | 90 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 91 | fmt( os, "%lld", lli ); | 
|---|
| [90c3b1c] | 92 | return os; | 
|---|
| [784deab] | 93 | } // ?|? | 
|---|
|  | 94 |  | 
|---|
|  | 95 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 96 | ostype * ?|?( ostype * os, unsigned long long int ulli ) { | 
|---|
|  | 97 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 98 | fmt( os, "%llu", ulli ); | 
|---|
| [90c3b1c] | 99 | return os; | 
|---|
| [cf16f94] | 100 | } // ?|? | 
|---|
| [51b73452] | 101 |  | 
|---|
| [d3b7937] | 102 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 103 | ostype * ?|?( ostype * os, float f ) { | 
|---|
|  | 104 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 105 | fmt( os, "%g", f ); | 
|---|
| [90c3b1c] | 106 | return os; | 
|---|
| [d3b7937] | 107 | } // ?|? | 
|---|
|  | 108 |  | 
|---|
| [51b73452] | 109 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 110 | ostype * ?|?( ostype * os, double d ) { | 
|---|
|  | 111 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 112 | fmt( os, "%.*lg", DBL_DIG, d ); | 
|---|
| [90c3b1c] | 113 | return os; | 
|---|
| [cf16f94] | 114 | } // ?|? | 
|---|
| [134b86a] | 115 |  | 
|---|
|  | 116 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 117 | ostype * ?|?( ostype * os, long double ld ) { | 
|---|
|  | 118 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 119 | fmt( os, "%.*Lg", LDBL_DIG, ld ); | 
|---|
| [90c3b1c] | 120 | return os; | 
|---|
| [cf16f94] | 121 | } // ?|? | 
|---|
| [51b73452] | 122 |  | 
|---|
| [d3b7937] | 123 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 124 | ostype * ?|?( ostype * os, float _Complex fc ) { | 
|---|
| [90c3b1c] | 125 | os | crealf( fc ); | 
|---|
| [53ba273] | 126 | _Bool temp = sepDisable( os );                                          // disable separators within complex value | 
|---|
|  | 127 | if ( cimagf( fc ) >= 0 ) os | '+';                                      // negative value prints '-' | 
|---|
|  | 128 | os | cimagf( fc ) | 'i'; | 
|---|
|  | 129 | sepReset( os, temp );                                                           // reset separator | 
|---|
| [90c3b1c] | 130 | return os; | 
|---|
| [d3b7937] | 131 | } // ?|? | 
|---|
|  | 132 |  | 
|---|
|  | 133 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 134 | ostype * ?|?( ostype * os, double _Complex dc ) { | 
|---|
| [90c3b1c] | 135 | os | creal( dc ); | 
|---|
| [53ba273] | 136 | _Bool temp = sepDisable( os );                                          // disable separators within complex value | 
|---|
|  | 137 | if ( cimag( dc ) >= 0 ) os | '+';                                       // negative value prints '-' | 
|---|
|  | 138 | os | cimag( dc ) | 'i'; | 
|---|
|  | 139 | sepReset( os, temp );                                                           // reset separator | 
|---|
| [90c3b1c] | 140 | return os; | 
|---|
| [d3b7937] | 141 | } // ?|? | 
|---|
|  | 142 |  | 
|---|
|  | 143 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 144 | ostype * ?|?( ostype * os, long double _Complex ldc ) { | 
|---|
| [90c3b1c] | 145 | os | creall( ldc ); | 
|---|
| [53ba273] | 146 | _Bool temp = sepDisable( os );                                          // disable separators within complex value | 
|---|
|  | 147 | if ( cimagl( ldc ) >= 0 ) os | '+';                                     // negative value prints '-' | 
|---|
|  | 148 | os | cimagl( ldc ) | 'i'; | 
|---|
|  | 149 | sepReset( os, temp );                                                           // reset separator | 
|---|
| [90c3b1c] | 150 | return os; | 
|---|
| [d3b7937] | 151 | } // ?|? | 
|---|
|  | 152 |  | 
|---|
| [e56cfdb0] | 153 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 154 | ostype * ?|?( ostype * os, const char * cp ) { | 
|---|
| [b63e376] | 155 | enum { Open = 1, Close, OpenClose }; | 
|---|
| [53ba273] | 156 | static const unsigned char mask[256] = { | 
|---|
| [c443d1d] | 157 | // opening delimiters, no space after | 
|---|
| [b63e376] | 158 | ['('] : Open, ['['] : Open, ['{'] : Open, | 
|---|
| [c443d1d] | 159 | ['$'] : Open, ['='] : Open, [(unsigned char)'£'] : Open, [(unsigned char)'¥'] : Open, | 
|---|
| [e945826] | 160 | [(unsigned char)'¡'] : Open, [(unsigned char)'¿'] : Open, [(unsigned char)'«'] : Open, | 
|---|
| [c443d1d] | 161 | // closing delimiters, no space before | 
|---|
| [b63e376] | 162 | [','] : Close, ['.'] : Close, [':'] : Close, [';'] : Close, ['!'] : Close, ['?'] : Close, | 
|---|
| [53ba273] | 163 | ['%'] : Close, [(unsigned char)'¢'] : Close, [(unsigned char)'»'] : Close, | 
|---|
| [829c907] | 164 | [')'] : Close, [']'] : Close, ['}'] : Close, | 
|---|
| [c443d1d] | 165 | // opening-closing delimiters, no space before or after | 
|---|
| [b63e376] | 166 | ['\''] : OpenClose, ['`'] : OpenClose, ['"'] : OpenClose, | 
|---|
| [e945826] | 167 | [' '] : OpenClose, ['\f'] : OpenClose, ['\n'] : OpenClose, ['\r'] : OpenClose, ['\t'] : OpenClose, ['\v'] : OpenClose, // isspace | 
|---|
| [b63e376] | 168 | }; // mask | 
|---|
|  | 169 |  | 
|---|
| [b72bad4f] | 170 | if ( cp[0] == '\0' ) { sepOff( os ); return os; }             // null string => no separator | 
|---|
|  | 171 |  | 
|---|
| [53ba273] | 172 | // first character IS NOT spacing or closing punctuation => add left separator | 
|---|
|  | 173 | unsigned char ch = cp[0];                                                       // must make unsigned | 
|---|
|  | 174 | if ( sepPrt( os ) && mask[ ch ] != Close && mask[ ch ] != OpenClose ) { | 
|---|
| [829c907] | 175 | fmt( os, "%s", sepGetCur( os ) ); | 
|---|
| [90c3b1c] | 176 | } // if | 
|---|
| [b72bad4f] | 177 |  | 
|---|
|  | 178 | // if string starts line, must reset to determine open state because separator is off | 
|---|
|  | 179 | sepReset( os );                                                                         // reset separator | 
|---|
|  | 180 |  | 
|---|
| [b63e376] | 181 | // last character IS spacing or opening punctuation => turn off separator for next item | 
|---|
| [b72bad4f] | 182 | unsigned int len = strlen( cp ), posn = len - 1; | 
|---|
| [53ba273] | 183 | ch = cp[posn];                                                                          // must make unsigned | 
|---|
| [b72bad4f] | 184 | if ( sepPrt( os ) && mask[ ch ] != Open && mask[ ch ] != OpenClose ) { | 
|---|
| [90c3b1c] | 185 | sepOn( os ); | 
|---|
| [b72bad4f] | 186 | } else { | 
|---|
|  | 187 | sepOff( os ); | 
|---|
| [90c3b1c] | 188 | } // if | 
|---|
|  | 189 | return write( os, cp, len ); | 
|---|
| [784deab] | 190 | } // ?|? | 
|---|
|  | 191 |  | 
|---|
|  | 192 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 193 | ostype * ?|?( ostype * os, const void * p ) { | 
|---|
|  | 194 | if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); | 
|---|
|  | 195 | fmt( os, "%p", p ); | 
|---|
| [90c3b1c] | 196 | return os; | 
|---|
| [cf16f94] | 197 | } // ?|? | 
|---|
|  | 198 |  | 
|---|
|  | 199 |  | 
|---|
| [c443d1d] | 200 | // tuples | 
|---|
|  | 201 | forall( dtype ostype, otype T, ttype Params | ostream( ostype ) | writeable( T ) | { ostype * ?|?( ostype *, Params ); } ) | 
|---|
|  | 202 | ostype * ?|?( ostype * os, T arg, Params rest ) { | 
|---|
| [829c907] | 203 | sepSetCur( os, sepGetTuple( os ) );                                     // switch to tuple separator | 
|---|
|  | 204 | os | arg;                                                                                       // print first argument | 
|---|
|  | 205 | os | rest;                                                                                      // print remaining arguments | 
|---|
|  | 206 | sepSetCur( os, sepGet( os ) );                                          // switch to regular separator | 
|---|
| [c443d1d] | 207 | } // ?|? | 
|---|
|  | 208 |  | 
|---|
|  | 209 |  | 
|---|
|  | 210 | // manipulators | 
|---|
| [a5a71d0] | 211 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [4e06c1e] | 212 | ostype * ?|?( ostype * os, ostype * (* manip)( ostype * ) ) { | 
|---|
| [90c3b1c] | 213 | return manip( os ); | 
|---|
|  | 214 | } // ?|? | 
|---|
| [cf16f94] | 215 |  | 
|---|
| [a5a71d0] | 216 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [cf16f94] | 217 | ostype * endl( ostype * os ) { | 
|---|
| [90c3b1c] | 218 | os | '\n'; | 
|---|
| [6ba0659] | 219 | flush( os ); | 
|---|
| [90c3b1c] | 220 | sepOff( os ); | 
|---|
| [6ba0659] | 221 | return os; | 
|---|
| [cf16f94] | 222 | } // endl | 
|---|
| [e56cfdb0] | 223 |  | 
|---|
| [a5a71d0] | 224 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [90c3b1c] | 225 | ostype * sepOn( ostype * os ) { | 
|---|
|  | 226 | sepOn( os ); | 
|---|
|  | 227 | return os; | 
|---|
|  | 228 | } // sepOn | 
|---|
|  | 229 |  | 
|---|
| [a5a71d0] | 230 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [90c3b1c] | 231 | ostype * sepOff( ostype * os ) { | 
|---|
|  | 232 | sepOff( os ); | 
|---|
|  | 233 | return os; | 
|---|
|  | 234 | } // sepOff | 
|---|
|  | 235 |  | 
|---|
| [70a06f6] | 236 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [53ba273] | 237 | ostype * sepEnable( ostype * os ) { | 
|---|
|  | 238 | sepEnable( os ); | 
|---|
|  | 239 | return os; | 
|---|
|  | 240 | } // sepEnable | 
|---|
|  | 241 |  | 
|---|
| [70a06f6] | 242 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [53ba273] | 243 | ostype * sepDisable( ostype * os ) { | 
|---|
|  | 244 | sepDisable( os ); | 
|---|
|  | 245 | return os; | 
|---|
|  | 246 | } // sepDisable | 
|---|
|  | 247 |  | 
|---|
| [6ba0659] | 248 | //--------------------------------------- | 
|---|
|  | 249 |  | 
|---|
| [4040425] | 250 | forall( otype elttype | writeable( elttype ), otype iteratortype | iterator( iteratortype, elttype ), dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 251 | void write( iteratortype begin, iteratortype end, ostype * os ) { | 
|---|
| [90c3b1c] | 252 | void print( elttype i ) { os | i; } | 
|---|
| [e56cfdb0] | 253 | for_each( begin, end, print ); | 
|---|
| [cf16f94] | 254 | } // ?|? | 
|---|
| [e56cfdb0] | 255 |  | 
|---|
| [4040425] | 256 | forall( otype elttype | writeable( elttype ), otype iteratortype | iterator( iteratortype, elttype ), dtype ostype | ostream( ostype ) ) | 
|---|
| [829c907] | 257 | void write_reverse( iteratortype begin, iteratortype end, ostype * os ) { | 
|---|
| [90c3b1c] | 258 | void print( elttype i ) { os | i; } | 
|---|
| [e56cfdb0] | 259 | for_each_reverse( begin, end, print ); | 
|---|
| [cf16f94] | 260 | } // ?|? | 
|---|
| [e56cfdb0] | 261 |  | 
|---|
| [6ba0659] | 262 | //--------------------------------------- | 
|---|
| [e56cfdb0] | 263 |  | 
|---|
| [51b73452] | 264 | forall( dtype istype | istream( istype ) ) | 
|---|
| [90c3b1c] | 265 | istype * ?|?( istype * is, char * c ) { | 
|---|
| [829c907] | 266 | fmt( is, "%c", c ); | 
|---|
| [90c3b1c] | 267 | return is; | 
|---|
|  | 268 | } // ?|? | 
|---|
|  | 269 |  | 
|---|
|  | 270 | forall( dtype istype | istream( istype ) ) | 
|---|
|  | 271 | istype * ?|?( istype * is, short int * si ) { | 
|---|
| [829c907] | 272 | fmt( is, "%hd", si ); | 
|---|
| [90c3b1c] | 273 | return is; | 
|---|
|  | 274 | } // ?|? | 
|---|
|  | 275 |  | 
|---|
|  | 276 | forall( dtype istype | istream( istype ) ) | 
|---|
|  | 277 | istype * ?|?( istype * is, unsigned short int * usi ) { | 
|---|
| [829c907] | 278 | fmt( is, "%hu", usi ); | 
|---|
| [90c3b1c] | 279 | return is; | 
|---|
|  | 280 | } // ?|? | 
|---|
|  | 281 |  | 
|---|
|  | 282 | forall( dtype istype | istream( istype ) ) | 
|---|
|  | 283 | istype * ?|?( istype * is, int * i ) { | 
|---|
| [829c907] | 284 | fmt( is, "%d", i ); | 
|---|
| [90c3b1c] | 285 | return is; | 
|---|
|  | 286 | } // ?|? | 
|---|
|  | 287 |  | 
|---|
|  | 288 | forall( dtype istype | istream( istype ) ) | 
|---|
|  | 289 | istype * ?|?( istype * is, unsigned int * ui ) { | 
|---|
| [829c907] | 290 | fmt( is, "%u", ui ); | 
|---|
| [90c3b1c] | 291 | return is; | 
|---|
|  | 292 | } // ?|? | 
|---|
|  | 293 |  | 
|---|
|  | 294 | forall( dtype istype | istream( istype ) ) | 
|---|
|  | 295 | istype * ?|?( istype * is, long int * li ) { | 
|---|
| [829c907] | 296 | fmt( is, "%ld", li ); | 
|---|
| [90c3b1c] | 297 | return is; | 
|---|
| [cf16f94] | 298 | } // ?|? | 
|---|
| [51b73452] | 299 |  | 
|---|
|  | 300 | forall( dtype istype | istream( istype ) ) | 
|---|
| [90c3b1c] | 301 | istype * ?|?( istype * is, unsigned long int * ulli ) { | 
|---|
| [829c907] | 302 | fmt( is, "%lu", ulli ); | 
|---|
| [90c3b1c] | 303 | return is; | 
|---|
|  | 304 | } // ?|? | 
|---|
|  | 305 |  | 
|---|
|  | 306 | forall( dtype istype | istream( istype ) ) | 
|---|
|  | 307 | istype * ?|?( istype * is, long long int * lli ) { | 
|---|
| [829c907] | 308 | fmt( is, "%lld", lli ); | 
|---|
| [90c3b1c] | 309 | return is; | 
|---|
|  | 310 | } // ?|? | 
|---|
|  | 311 |  | 
|---|
|  | 312 | forall( dtype istype | istream( istype ) ) | 
|---|
|  | 313 | istype * ?|?( istype * is, unsigned long long int * ulli ) { | 
|---|
| [829c907] | 314 | fmt( is, "%llu", ulli ); | 
|---|
| [90c3b1c] | 315 | return is; | 
|---|
|  | 316 | } // ?|? | 
|---|
|  | 317 |  | 
|---|
|  | 318 |  | 
|---|
|  | 319 | forall( dtype istype | istream( istype ) ) | 
|---|
|  | 320 | istype * ?|?( istype * is, float * f ) { | 
|---|
| [829c907] | 321 | fmt( is, "%f", f ); | 
|---|
| [90c3b1c] | 322 | return is; | 
|---|
| [cf16f94] | 323 | } // ?|? | 
|---|
| [86bd7c1f] | 324 |  | 
|---|
| [90c3b1c] | 325 | forall( dtype istype | istream( istype ) ) | 
|---|
|  | 326 | istype * ?|?( istype * is, double * d ) { | 
|---|
| [829c907] | 327 | fmt( is, "%lf", d ); | 
|---|
| [90c3b1c] | 328 | return is; | 
|---|
|  | 329 | } // ?|? | 
|---|
|  | 330 |  | 
|---|
|  | 331 | forall( dtype istype | istream( istype ) ) | 
|---|
|  | 332 | istype * ?|?( istype * is, long double * ld ) { | 
|---|
| [829c907] | 333 | fmt( is, "%Lf", ld ); | 
|---|
| [90c3b1c] | 334 | return is; | 
|---|
|  | 335 | } // ?|? | 
|---|
|  | 336 |  | 
|---|
|  | 337 |  | 
|---|
|  | 338 | forall( dtype istype | istream( istype ) ) | 
|---|
|  | 339 | istype * ?|?( istype * is, float _Complex * fc ) { | 
|---|
|  | 340 | float re, im; | 
|---|
| [829c907] | 341 | fmt( is, "%g%gi", &re, &im ); | 
|---|
| [90c3b1c] | 342 | *fc = re + im * _Complex_I; | 
|---|
|  | 343 | return is; | 
|---|
|  | 344 | } // ?|? | 
|---|
|  | 345 |  | 
|---|
|  | 346 | forall( dtype istype | istream( istype ) ) | 
|---|
|  | 347 | istype * ?|?( istype * is, double _Complex * dc ) { | 
|---|
|  | 348 | double re, im; | 
|---|
| [829c907] | 349 | fmt( is, "%lf%lfi", &re, &im ); | 
|---|
| [90c3b1c] | 350 | *dc = re + im * _Complex_I; | 
|---|
|  | 351 | return is; | 
|---|
| [cf16f94] | 352 | } // ?|? | 
|---|
| [51b73452] | 353 |  | 
|---|
|  | 354 | forall( dtype istype | istream( istype ) ) | 
|---|
| [90c3b1c] | 355 | istype * ?|?( istype * is, long double _Complex * ldc ) { | 
|---|
|  | 356 | long double re, im; | 
|---|
| [829c907] | 357 | fmt( is, "%Lf%Lfi", &re, &im ); | 
|---|
| [90c3b1c] | 358 | *ldc = re + im * _Complex_I; | 
|---|
|  | 359 | return is; | 
|---|
| [cf16f94] | 360 | } // ?|? | 
|---|
| [86bd7c1f] | 361 |  | 
|---|
| [e24f13a] | 362 | _Istream_cstrUC cstr( char * str ) { return (_Istream_cstrUC){ str }; } | 
|---|
| [90c3b1c] | 363 | forall( dtype istype | istream( istype ) ) | 
|---|
| [53ba273] | 364 | istype * ?|?( istype * is, _Istream_cstrUC cstr ) { | 
|---|
| [829c907] | 365 | fmt( is, "%s", cstr.s ); | 
|---|
| [90c3b1c] | 366 | return is; | 
|---|
| [53ba273] | 367 | } // cstr | 
|---|
| [90c3b1c] | 368 |  | 
|---|
| [e24f13a] | 369 | _Istream_cstrC cstr( char * str, int size ) { return (_Istream_cstrC){ str, size }; } | 
|---|
| [90c3b1c] | 370 | forall( dtype istype | istream( istype ) ) | 
|---|
| [53ba273] | 371 | istype * ?|?( istype * is, _Istream_cstrC cstr ) { | 
|---|
| [90c3b1c] | 372 | char buf[16]; | 
|---|
| [53ba273] | 373 | sprintf( buf, "%%%ds", cstr.size ); | 
|---|
| [829c907] | 374 | fmt( is, buf, cstr.s ); | 
|---|
| [90c3b1c] | 375 | return is; | 
|---|
| [53ba273] | 376 | } // cstr | 
|---|
| [90c3b1c] | 377 |  | 
|---|
| [86bd7c1f] | 378 | // Local Variables: // | 
|---|
|  | 379 | // tab-width: 4 // | 
|---|
|  | 380 | // compile-command: "cfa iostream.c" // | 
|---|
|  | 381 | // End: // | 
|---|