| [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 | // | 
|---|
|  | 7 | // iostream.c -- | 
|---|
|  | 8 | // | 
|---|
|  | 9 | // Author           : Richard C. Bilson | 
|---|
|  | 10 | // Created On       : Wed May 27 17:56:53 2015 | 
|---|
|  | 11 | // Last Modified By : Peter A. Buhr | 
|---|
|  | 12 | // Last Modified On : Wed May 27 18:18:13 2015 | 
|---|
|  | 13 | // Update Count     : 2 | 
|---|
|  | 14 | // | 
|---|
| [51b73452] | 15 |  | 
|---|
|  | 16 | #include "iostream.h" | 
|---|
|  | 17 | extern "C" { | 
|---|
|  | 18 | #include <stdio.h> | 
|---|
| [134b86a] | 19 | //#include <string.h> | 
|---|
|  | 20 | //#include <ctype.h> | 
|---|
| [86bd7c1f] | 21 | typedef long unsigned int size_t; | 
|---|
|  | 22 | size_t strlen(const char *s); | 
|---|
| [51b73452] | 23 | } | 
|---|
|  | 24 |  | 
|---|
|  | 25 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [134b86a] | 26 | ostype * ?<<?( ostype *os, char c ) { | 
|---|
| [86bd7c1f] | 27 | return write( os, &c, 1 ); | 
|---|
| [51b73452] | 28 | } | 
|---|
|  | 29 |  | 
|---|
|  | 30 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [134b86a] | 31 | ostype * ?<<?( ostype *os, int i ) { | 
|---|
| [86bd7c1f] | 32 | char buffer[20];      // larger than the largest integer | 
|---|
|  | 33 | sprintf( buffer, "%d", i ); | 
|---|
|  | 34 | return write( os, buffer, strlen( buffer ) ); | 
|---|
| [51b73452] | 35 | } | 
|---|
|  | 36 |  | 
|---|
|  | 37 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
| [134b86a] | 38 | ostype * ?<<?( ostype *os, double d ) { | 
|---|
| [86bd7c1f] | 39 | char buffer[32];      // larger than the largest double | 
|---|
|  | 40 | sprintf( buffer, "%g", d ); | 
|---|
|  | 41 | return write( os, buffer, strlen( buffer ) ); | 
|---|
| [134b86a] | 42 | } | 
|---|
|  | 43 |  | 
|---|
|  | 44 | forall( dtype ostype | ostream( ostype ) ) | 
|---|
|  | 45 | ostype * ?<<?( ostype *os, const char *cp ) { | 
|---|
| [86bd7c1f] | 46 | return write( os, cp, strlen( cp ) ); | 
|---|
| [51b73452] | 47 | } | 
|---|
|  | 48 |  | 
|---|
|  | 49 | forall( dtype istype | istream( istype ) ) | 
|---|
| [134b86a] | 50 | istype * ?>>?( istype *is, char *cp ) { | 
|---|
| [86bd7c1f] | 51 | return read( is, cp, 1 ); | 
|---|
| [51b73452] | 52 | } | 
|---|
|  | 53 |  | 
|---|
|  | 54 | forall( dtype istype | istream( istype ) ) | 
|---|
| [134b86a] | 55 | istype * ?>>?( istype *is, int *ip ) { | 
|---|
| [86bd7c1f] | 56 | char cur; | 
|---|
| [51b73452] | 57 |  | 
|---|
| [86bd7c1f] | 58 | // skip some whitespace | 
|---|
|  | 59 | do { | 
|---|
|  | 60 | is >> &cur; | 
|---|
|  | 61 | if ( fail( is ) || eof( is ) ) return is; | 
|---|
|  | 62 | } while ( !( cur >= '0' && cur <= '9' ) ); | 
|---|
| [51b73452] | 63 |  | 
|---|
| [86bd7c1f] | 64 | // accumulate digits | 
|---|
|  | 65 | *ip = 0; | 
|---|
|  | 66 | while ( cur >= '0' && cur <= '9' ) { | 
|---|
|  | 67 | *ip = *ip * 10 + ( cur - '0' ); | 
|---|
|  | 68 | is >> &cur; | 
|---|
|  | 69 | if ( fail( is ) || eof( is ) ) return is; | 
|---|
|  | 70 | } | 
|---|
| [51b73452] | 71 |  | 
|---|
| [86bd7c1f] | 72 | unread( is, cur ); | 
|---|
|  | 73 | return is; | 
|---|
| [51b73452] | 74 | } | 
|---|
| [86bd7c1f] | 75 |  | 
|---|
|  | 76 | // Local Variables: // | 
|---|
|  | 77 | // tab-width: 4 // | 
|---|
|  | 78 | // compile-command: "cfa iostream.c" // | 
|---|
|  | 79 | // End: // | 
|---|