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