| [53ba273] | 1 | // 
 | 
|---|
 | 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.
 | 
|---|
 | 6 | // 
 | 
|---|
 | 7 | // io.c -- 
 | 
|---|
 | 8 | // 
 | 
|---|
 | 9 | // Author           : Peter A. Buhr
 | 
|---|
 | 10 | // Created On       : Wed Mar  2 16:56:02 2016
 | 
|---|
 | 11 | // Last Modified By : Peter A. Buhr
 | 
|---|
| [5f20b30] | 12 | // Last Modified On : Fri Jan 26 15:19:34 2018
 | 
|---|
 | 13 | // Update Count     : 100
 | 
|---|
| [53ba273] | 14 | // 
 | 
|---|
 | 15 | 
 | 
|---|
 | 16 | #include <fstream>
 | 
|---|
 | 17 | 
 | 
|---|
 | 18 | int main() {
 | 
|---|
| [5f20b30] | 19 |         _Bool b;                                                                                        // basic types
 | 
|---|
 | 20 |         char c;
 | 
|---|
| [cd218e8] | 21 |         signed char sc;
 | 
|---|
 | 22 |         unsigned char usc;
 | 
|---|
| [53ba273] | 23 |         short int si;
 | 
|---|
 | 24 |         unsigned short int usi;
 | 
|---|
 | 25 |         int i;
 | 
|---|
 | 26 |         unsigned int ui;
 | 
|---|
 | 27 |         long int li;
 | 
|---|
 | 28 |         unsigned long int uli;
 | 
|---|
 | 29 |         long long int lli;
 | 
|---|
 | 30 |         unsigned long long int ulli;
 | 
|---|
 | 31 |         float f;
 | 
|---|
 | 32 |         double d;
 | 
|---|
 | 33 |         long double ld;
 | 
|---|
 | 34 |         float _Complex fc;
 | 
|---|
 | 35 |         double _Complex dc;
 | 
|---|
 | 36 |         long double _Complex ldc;
 | 
|---|
| [5a7966bb] | 37 |         enum { size = 10 };
 | 
|---|
 | 38 |         char s1[size], s2[size];
 | 
|---|
| [53ba273] | 39 | 
 | 
|---|
| [58b5d03] | 40 |         int x = 3, y = 5, z = 7;
 | 
|---|
 | 41 |         sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;
 | 
|---|
 | 42 |         sout | 1 | 2 | 3 | endl;
 | 
|---|
 | 43 |         sout | '1' | '2' | '3' | endl;
 | 
|---|
 | 44 |         sout | 1 | "" | 2 | "" | 3 | endl;
 | 
|---|
 | 45 |         sout | endl;
 | 
|---|
 | 46 | 
 | 
|---|
| [86f384b] | 47 |         sout | "opening delimiters" | endl;
 | 
|---|
| [5a7966bb] | 48 |         sout
 | 
|---|
| [09687aa] | 49 |                  | "x (" | 1
 | 
|---|
 | 50 |                  | "x [" | 2
 | 
|---|
 | 51 |                  | "x {" | 3
 | 
|---|
 | 52 |                  | "x =" | 4
 | 
|---|
 | 53 |                  | "x $" | 5
 | 
|---|
 | 54 |                  | "x £" | 6
 | 
|---|
 | 55 |                  | "x ¥" | 7
 | 
|---|
 | 56 |                  | "x ¡" | 8
 | 
|---|
 | 57 |                  | "x ¿" | 9
 | 
|---|
 | 58 |                  | "x «" | 10
 | 
|---|
 | 59 |                  | endl | endl;
 | 
|---|
| [86f384b] | 60 | 
 | 
|---|
 | 61 |         sout | "closing delimiters" | endl;
 | 
|---|
| [5a7966bb] | 62 |         sout
 | 
|---|
| [09687aa] | 63 |                  | 1 | ", x"
 | 
|---|
 | 64 |                  | 2 | ". x"
 | 
|---|
 | 65 |                  | 3 | "; x"
 | 
|---|
 | 66 |                  | 4 | "! x"
 | 
|---|
 | 67 |                  | 5 | "? x"
 | 
|---|
 | 68 |                  | 6 | "% x"
 | 
|---|
 | 69 |                  | 7 | "¢ x"
 | 
|---|
 | 70 |                  | 8 | "» x"
 | 
|---|
 | 71 |                  | 9 | ") x"
 | 
|---|
 | 72 |                  | 10 | "] x"
 | 
|---|
 | 73 |                  | 11 | "} x"
 | 
|---|
 | 74 |                  | endl | endl;
 | 
|---|
| [86f384b] | 75 | 
 | 
|---|
 | 76 |         sout | "opening/closing delimiters" | endl;
 | 
|---|
| [5a7966bb] | 77 |         sout
 | 
|---|
| [09687aa] | 78 |                  | "x`" | 1 | "`x'" | 2
 | 
|---|
 | 79 |                  | "'x\"" | 3 | "\"x:" | 4
 | 
|---|
 | 80 |                  | ":x " | 5 | " x\t" | 6
 | 
|---|
 | 81 |                  | "\tx\f" | 7 | "\fx\v" | 8
 | 
|---|
 | 82 |                  | "\vx\n" | 9 | "\nx\r" | 10
 | 
|---|
 | 83 |                  | "\rx"
 | 
|---|
 | 84 |                  | endl | endl;
 | 
|---|
| [86f384b] | 85 | 
 | 
|---|
 | 86 |         sout | "override opening/closing delimiters" | endl;
 | 
|---|
| [5a7966bb] | 87 |         sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4 | endl;
 | 
|---|
| [86f384b] | 88 |         sout | endl;
 | 
|---|
| [5a7966bb] | 89 | 
 | 
|---|
| [09687aa] | 90 |         ifstream in = { "io.data" };                                            // create / open file
 | 
|---|
| [53ba273] | 91 | 
 | 
|---|
| [86f384b] | 92 |         sout | "input bacis types" | endl;
 | 
|---|
| [5f20b30] | 93 |         in       | b                                                                                    // boolean
 | 
|---|
 | 94 |                  | c | sc | usc                                                                 // character
 | 
|---|
| [09687aa] | 95 |                  | si | usi | i | ui | li | uli | lli | ulli    // integral
 | 
|---|
 | 96 |                  | f | d | ld                                                                   // floating point
 | 
|---|
 | 97 |                  | fc | dc | ldc                                                                // floating-point complex
 | 
|---|
 | 98 |                  | cstr( s1 ) | cstr( s2, size );                               // C string, length unchecked and checked
 | 
|---|
| [86f384b] | 99 |         sout | endl;
 | 
|---|
| [53ba273] | 100 | 
 | 
|---|
| [86f384b] | 101 |         sout | "output basic types" | endl;
 | 
|---|
| [5f20b30] | 102 |         sout | b | endl                                                                         // boolean
 | 
|---|
 | 103 |                  | c | ' ' | sc | ' ' | usc | endl                              // character
 | 
|---|
| [09687aa] | 104 |                  | si | usi | i | ui | li | uli | lli | ulli | endl // integral
 | 
|---|
 | 105 |                  | f | d | ld | endl                                                    // floating point
 | 
|---|
 | 106 |                  | fc | dc | ldc | endl;                                                // complex
 | 
|---|
| [53ba273] | 107 |         sout | endl;
 | 
|---|
| [86f384b] | 108 | 
 | 
|---|
 | 109 |         sout | "tuples" | endl;
 | 
|---|
| [53a6c2a] | 110 |         [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
 | 
|---|
| [86f384b] | 111 |         sout | t1 | t2 | endl;                                                          // print tuple
 | 
|---|
 | 112 |         sout | endl;
 | 
|---|
 | 113 | 
 | 
|---|
 | 114 |         sout | "toggle separator" | endl;
 | 
|---|
| [5a7966bb] | 115 |         sout | f | "" | d | "" | ld | endl                                      // floating point without separator
 | 
|---|
| [09687aa] | 116 |                  | sepDisable | fc | dc | ldc | endl                    // complex without separator
 | 
|---|
 | 117 |                  | fc | sepOn | dc | ldc | endl                                 // local separator add
 | 
|---|
 | 118 |                  | sepEnable | fc | dc | ldc | endl                             // complex with separator
 | 
|---|
 | 119 |                  | fc | sepOff | dc | ldc | endl                                // local separator removal
 | 
|---|
 | 120 |                  | s1 | sepOff | s2 | endl                                              // local separator removal
 | 
|---|
 | 121 |                  | s1 | "" | s2 | endl;                                                 // local separator removal
 | 
|---|
| [53ba273] | 122 |         sout | endl;
 | 
|---|
 | 123 | 
 | 
|---|
| [86f384b] | 124 |         sout | "change separator" | endl;
 | 
|---|
| [53a6c2a] | 125 |         sout | "from \"" | sep | "\"";
 | 
|---|
| [5a7966bb] | 126 |         sepSet( sout, ", $" );                                                          // change separator, maximum of 15 characters
 | 
|---|
| [53a6c2a] | 127 |         sout | " to \"" | sep | "\"" | endl;
 | 
|---|
| [829c907] | 128 |         sout | f | d | ld | endl
 | 
|---|
| [09687aa] | 129 |                  | fc | dc | ldc | endl
 | 
|---|
 | 130 |                  | s1 | s2 | endl
 | 
|---|
 | 131 |                  | t1 | t2 | endl;                                                              // print tuple
 | 
|---|
| [d395012] | 132 |         sout | endl;
 | 
|---|
| [53a6c2a] | 133 |         sout | "from \"" | sep | "\" ";
 | 
|---|
| [86f384b] | 134 |         sepSet( sout, " " );                                                            // restore separator
 | 
|---|
| [53a6c2a] | 135 |         sout | "to \"" | sep | "\"" | endl;
 | 
|---|
| [86f384b] | 136 |         sout | f | d | ld | endl
 | 
|---|
| [09687aa] | 137 |                  | fc | dc | ldc | endl
 | 
|---|
 | 138 |                  | s1 | s2 | endl
 | 
|---|
 | 139 |                  | t1 | t2 | endl;                                                              // print tuple
 | 
|---|
| [d395012] | 140 |         sout | endl;
 | 
|---|
| [6b6597c] | 141 | 
 | 
|---|
| [53a6c2a] | 142 |         sout | "check sepOn/sepOff" | endl;
 | 
|---|
 | 143 |         sout | sepOn | 1 | 2 | 3 | sepOn | endl;                        // no separator at start/end of line
 | 
|---|
| [5a7966bb] | 144 |         sout | 1 | sepOff | 2 | 3 | endl;                                       // locally turn off implicit separator
 | 
|---|
| [53a6c2a] | 145 |         sout | sepOn | sepOn | 1 | 2 | 3 | sepOn | sepOff | sepOn | '\n'; // no separator at start/end of line
 | 
|---|
 | 146 |         sout | 1 | 2 | 3 | "\n\n" | sepOn;                                      // no separator at start of next line
 | 
|---|
| [d395012] | 147 |         sout | 1 | 2 | 3 | endl;
 | 
|---|
 | 148 |         sout | endl;
 | 
|---|
| [5a7966bb] | 149 | 
 | 
|---|
| [53a6c2a] | 150 |         sout | "check enable/disable" | endl;
 | 
|---|
| [5a7966bb] | 151 |         sout | sepDisable | 1 | 2 | 3 | endl;                           // globally turn off implicit separation
 | 
|---|
 | 152 |         sout | 1 | sepOn | 2 | 3 | endl;                                        // locally turn on implicit separator
 | 
|---|
| [d395012] | 153 |         sout | sepEnable | 1 | 2 | 3 | endl | sepDisable;       // globally turn on/off implicit separation
 | 
|---|
 | 154 |         sout | 1 | 2 | 3 | endl | sepEnable;                            // globally turn on implicit separation
 | 
|---|
 | 155 |         sout | 1 | 2 | 3 | sepOn | sepDisable | endl;           // ignore seperate at end of line
 | 
|---|
 | 156 |         sout | 1 | 2 | 3 | sepOn | sepEnable | endl;            // separator at end of line
 | 
|---|
 | 157 |         sout | 1 | 2 | 3 | endl;
 | 
|---|
 | 158 |         sout | endl;
 | 
|---|
| [5a7966bb] | 159 | 
 | 
|---|
| [53a6c2a] | 160 | //      sout | fmt( d, "%8.3f" ) || endl;
 | 
|---|
 | 161 | //      sout | endl;
 | 
|---|
 | 162 | 
 | 
|---|
| [5a7966bb] | 163 |         sepSetTuple( sout, " " );                                                       // set tuple separator from ", " to " "
 | 
|---|
| [53a6c2a] | 164 |         sout | t1 | t2 | " \"" | sep | "\"" | endl;
 | 
|---|
| [5a7966bb] | 165 |         sepSetTuple( sout, ", " );                                                      // reset tuple separator to ", "
 | 
|---|
| [53a6c2a] | 166 |         sout | t1 | t2 | " \"" | sep | "\"" | endl;
 | 
|---|
| [5a7966bb] | 167 |         sout | t1 | t2 | endl;                                                          // print tuple
 | 
|---|
| [d395012] | 168 |         sout | endl;
 | 
|---|
| [829c907] | 169 | 
 | 
|---|
| [5a7966bb] | 170 |         [int, int, const char *, double] t3 = { 3, 4, "a", 7.2 };
 | 
|---|
| [cb91437] | 171 |         sout | [ 3, 4, "a", 7.2 ] | endl;
 | 
|---|
| [5a7966bb] | 172 |         sout | t3 | endl;
 | 
|---|
| [829c907] | 173 |         sepSetTuple( sout, " " );
 | 
|---|
| [5a7966bb] | 174 |         sout | t3 | endl;
 | 
|---|
 | 175 |         sout | sepOn | t3 | sepDisable | t3 | sepEnable | t3 | endl;
 | 
|---|
| [829c907] | 176 |         sepSet( sout, "^" );
 | 
|---|
 | 177 |         sepSetTuple( sout, "-" );
 | 
|---|
| [5a7966bb] | 178 |         sout | t3 | 3 | 4 | t3 | endl;
 | 
|---|
| [53ba273] | 179 | }
 | 
|---|
 | 180 | 
 | 
|---|
 | 181 | // Local Variables: //
 | 
|---|
 | 182 | // tab-width: 4 //
 | 
|---|
 | 183 | // compile-command: "cfa io.c" //
 | 
|---|
 | 184 | // End: //
 | 
|---|