[cbdf565] | 1 | //
|
---|
[53ba273] | 2 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
|
---|
| 3 | //
|
---|
| 4 | // The contents of this file are covered under the licence agreement in the
|
---|
| 5 | // file "LICENCE" distributed with Cforall.
|
---|
[cbdf565] | 6 | //
|
---|
[dc8511c] | 7 | // io2.cfa --
|
---|
[cbdf565] | 8 | //
|
---|
[53ba273] | 9 | // Author : Peter A. Buhr
|
---|
| 10 | // Created On : Wed Mar 2 16:56:02 2016
|
---|
| 11 | // Last Modified By : Peter A. Buhr
|
---|
[dc5072f] | 12 | // Last Modified On : Thu Jun 13 16:43:14 2019
|
---|
| 13 | // Update Count : 120
|
---|
[cbdf565] | 14 | //
|
---|
[53ba273] | 15 |
|
---|
[73abe95] | 16 | #include <fstream.hfa>
|
---|
[53ba273] | 17 |
|
---|
[200fcb3] | 18 | #define xstr(s) str(s)
|
---|
[cbdf565] | 19 | #define str(s) #s
|
---|
| 20 |
|
---|
[53ba273] | 21 | int main() {
|
---|
[5f20b30] | 22 | _Bool b; // basic types
|
---|
| 23 | char c;
|
---|
[cd218e8] | 24 | signed char sc;
|
---|
| 25 | unsigned char usc;
|
---|
[53ba273] | 26 | short int si;
|
---|
| 27 | unsigned short int usi;
|
---|
| 28 | int i;
|
---|
| 29 | unsigned int ui;
|
---|
| 30 | long int li;
|
---|
| 31 | unsigned long int uli;
|
---|
| 32 | long long int lli;
|
---|
| 33 | unsigned long long int ulli;
|
---|
| 34 | float f;
|
---|
| 35 | double d;
|
---|
| 36 | long double ld;
|
---|
| 37 | float _Complex fc;
|
---|
| 38 | double _Complex dc;
|
---|
| 39 | long double _Complex ldc;
|
---|
[5a7966bb] | 40 | enum { size = 10 };
|
---|
| 41 | char s1[size], s2[size];
|
---|
[53ba273] | 42 |
|
---|
[200fcb3] | 43 | ifstream in = { xstr(IN_DIR) "io.data" }; // create / open file
|
---|
[53ba273] | 44 |
|
---|
[200fcb3] | 45 | sout | "input bacis types";
|
---|
[ac1ae2c6] | 46 | in | b; // boolean
|
---|
| 47 | in | c | sc | usc; // character
|
---|
| 48 | in | si | usi | i | ui | li | uli | lli | ulli; // integral
|
---|
| 49 | in | f | d | ld; // floating point
|
---|
| 50 | in | fc | dc | ldc; // floating-point complex
|
---|
[dc5072f] | 51 | in | s1 | wdi( size, s2 ); // C string, length unchecked and checked
|
---|
[200fcb3] | 52 | sout | nl;
|
---|
[53ba273] | 53 |
|
---|
[200fcb3] | 54 | sout | "output basic types";
|
---|
[ac1ae2c6] | 55 | sout | b; // boolean
|
---|
| 56 | sout | c | ' ' | sc | ' ' | usc; // character
|
---|
| 57 | sout | si | usi | i | ui | li | uli | lli | ulli; // integral
|
---|
| 58 | sout | f | d | ld; // floating point
|
---|
| 59 | sout | fc | dc | ldc; // complex
|
---|
[200fcb3] | 60 | sout | nl;
|
---|
[86f384b] | 61 |
|
---|
[200fcb3] | 62 | sout | "tuples";
|
---|
[53a6c2a] | 63 | [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
|
---|
[200fcb3] | 64 | sout | t1 | t2; // print tuple
|
---|
| 65 | sout | nl;
|
---|
[86f384b] | 66 |
|
---|
[200fcb3] | 67 | sout | "toggle separator";
|
---|
[ac1ae2c6] | 68 | sout | f | "" | d | "" | ld; // floating point without separator
|
---|
| 69 | sout | sepDisable | fc | dc | ldc; // complex without separator
|
---|
| 70 | sout | fc | sepOn | dc | ldc; // local separator add
|
---|
| 71 | sout | sepEnable | fc | dc | ldc; // complex with separator
|
---|
| 72 | sout | fc | sepOff | dc | ldc; // local separator removal
|
---|
| 73 | sout | s1 | sepOff | s2; // local separator removal
|
---|
| 74 | sout | s1 | "" | s2; // local separator removal
|
---|
[200fcb3] | 75 | sout | nl;
|
---|
[53ba273] | 76 |
|
---|
[200fcb3] | 77 | sout | "change separator";
|
---|
| 78 | sout | "from \"" | sep | "\"" | nonl;
|
---|
[5a7966bb] | 79 | sepSet( sout, ", $" ); // change separator, maximum of 15 characters
|
---|
[200fcb3] | 80 | sout | " to \"" | sep | "\"";
|
---|
[ac1ae2c6] | 81 | sout | f | d | ld;
|
---|
| 82 | sout | fc | dc | ldc;
|
---|
| 83 | sout | s1 | s2;
|
---|
| 84 | sout | t1 | t2; // print tuple
|
---|
[200fcb3] | 85 | sout | nl;
|
---|
| 86 | sout | "from \"" | sep | "\" " | nonl;
|
---|
[86f384b] | 87 | sepSet( sout, " " ); // restore separator
|
---|
[200fcb3] | 88 | sout | "to \"" | sep | "\"";
|
---|
[ac1ae2c6] | 89 | sout | f | d | ld;
|
---|
| 90 | sout | fc | dc | ldc;
|
---|
| 91 | sout | s1 | s2;
|
---|
| 92 | sout | t1 | t2; // print tuple
|
---|
[200fcb3] | 93 | sout | nl;
|
---|
[6b6597c] | 94 |
|
---|
[200fcb3] | 95 | sout | "check sepOn/sepOff";
|
---|
| 96 | sout | sepOn | 1 | 2 | 3 | sepOn; // no separator at start/end of line
|
---|
| 97 | sout | 1 | sepOff | 2 | 3; // locally turn off implicit separator
|
---|
[5ea5b28] | 98 | sout | sepOn | sepOn | 1 | 2 | 3 | sepOn | sepOff | sepOn | '\n' | nonl; // no separator at start/end of line
|
---|
[342136ab] | 99 | sout | 1 | 2 | 3 | "\n\n" | sepOn | nonl; // no separator at start of next line
|
---|
[200fcb3] | 100 | sout | 1 | 2 | 3;
|
---|
| 101 | sout | nl;
|
---|
[5a7966bb] | 102 |
|
---|
[200fcb3] | 103 | sout | "check enable/disable";
|
---|
| 104 | sout | sepDisable | 1 | 2 | 3; // globally turn off implicit separation
|
---|
| 105 | sout | 1 | sepOn | 2 | 3; // locally turn on implicit separator
|
---|
| 106 | sout | sepEnable | 1 | 2 | 3 | sepDisable; // globally turn on/off implicit separation
|
---|
| 107 | sout | 1 | 2 | 3 | sepEnable; // globally turn on implicit separation
|
---|
| 108 | sout | 1 | 2 | 3 | sepOn | sepDisable; // ignore seperate at end of line
|
---|
| 109 | sout | 1 | 2 | 3 | sepOn | sepEnable; // separator at end of line
|
---|
| 110 | sout | 1 | 2 | 3;
|
---|
| 111 | sout | nl;
|
---|
[5a7966bb] | 112 |
|
---|
[200fcb3] | 113 | // sout | fmt( d, "%8.3f" );
|
---|
[53a6c2a] | 114 |
|
---|
[5a7966bb] | 115 | sepSetTuple( sout, " " ); // set tuple separator from ", " to " "
|
---|
[200fcb3] | 116 | sout | t1 | t2 | " \"" | sep | "\"";
|
---|
[5a7966bb] | 117 | sepSetTuple( sout, ", " ); // reset tuple separator to ", "
|
---|
[200fcb3] | 118 | sout | t1 | t2 | " \"" | sep | "\"";
|
---|
| 119 | sout | t1 | t2; // print tuple
|
---|
| 120 | sout | nl;
|
---|
[829c907] | 121 |
|
---|
[5a7966bb] | 122 | [int, int, const char *, double] t3 = { 3, 4, "a", 7.2 };
|
---|
[200fcb3] | 123 | sout | [ 3, 4, "a", 7.2 ];
|
---|
| 124 | sout | t3;
|
---|
[829c907] | 125 | sepSetTuple( sout, " " );
|
---|
[200fcb3] | 126 | sout | t3;
|
---|
| 127 | sout | sepOn | t3 | sepDisable | t3 | sepEnable | t3;
|
---|
[829c907] | 128 | sepSet( sout, "^" );
|
---|
| 129 | sepSetTuple( sout, "-" );
|
---|
[200fcb3] | 130 | sout | t3 | 3 | 4 | t3;
|
---|
[53ba273] | 131 | }
|
---|
| 132 |
|
---|
| 133 | // Local Variables: //
|
---|
| 134 | // tab-width: 4 //
|
---|
[61c7239] | 135 | // compile-command: "cfa -DIN_DIR=\".in/\" io2.cfa" //
|
---|
[53ba273] | 136 | // End: //
|
---|