// // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // io.cfa -- // // Author : Peter A. Buhr // Created On : Wed Mar 2 16:56:02 2016 // Last Modified By : Peter A. Buhr // Last Modified On : Sun Feb 21 10:56:33 2021 // Update Count : 121 // #include #define xstr(s) str(s) #define str(s) #s int main() { sout | nlOff; // auto nl off sout | "opening delimiters" | nl; sout | "x (" | 1; sout | "x [" | 2; sout | "x {" | 3; sout | "x =" | 4; sout | "x $" | 5; sout | "x £" | 6; sout | "x ¥" | 7; sout | "x ¡" | 8; sout | "x ¿" | 9; sout | "x «" | 10; sout | nl | nl; sout | "closing delimiters" | nl; sout | 1 | ", x"; sout | 2 | ". x"; sout | 3 | "; x"; sout | 4 | "! x"; sout | 5 | "? x"; sout | 6 | "% x"; sout | 7 | "¢ x"; sout | 8 | "» x"; sout | 9 | ") x"; sout | 10 | "] x"; sout | 11 | "} x"; sout | nl | nl; sout | "opening/closing delimiters" | nl; sout | "x`" | 1 | "`x'" | 2; sout | "'x\"" | 3 | "\"x:" | 4; sout | ":x " | 5 | " x\t" | 6; sout | "\tx\f" | 7 | "\fx\v" | 8; sout | "\vx\n" | 9 | "\nx\r" | 10; sout | "\rx"; sout | nl | nl; sout | nlOn; // auto nl on sout | "override opening/closing delimiters"; sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4; sout | nl; sout | "spacing"; sout | 0 | 1 | 2 | 3; sout | '0' | '1' | '2' | '3'; sout | 0 | "" | 1 | "" | 2 | "" | 3; sout | nl; sout | "expressions"; int x = 3, y = 5, z = 7; sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2); sout | nl; _Bool b; // basic types char c; signed char sc; unsigned char usc; short int si; unsigned short int usi; int i; unsigned int ui; long int li; unsigned long int uli; long long int lli; unsigned long long int ulli; float f; double d; long double ld; float _Complex fc; double _Complex dc; long double _Complex ldc; enum { size = 10 }; char s1[size], s2[size]; ifstream in = { xstr(IN_DIR) "io.data" }; // create / open file sout | "input bacis types"; in | b; // boolean in | c | sc | usc; // character in | si | usi | i | ui | li | uli | lli | ulli; // integral in | f | d | ld; // floating point in | fc | dc | ldc; // floating-point complex in | s1 | wdi( size, s2 ); // C string, length unchecked and checked sout | nl; sout | "output basic types"; sout | b; // boolean sout | c | ' ' | sc | ' ' | usc; // character sout | si | usi | i | ui | li | uli | lli | ulli; // integral sout | f | d | ld; // floating point sout | fc | dc | ldc; // complex sout | nl; sout | "tuples"; [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ]; sout | t1 | t2; // print tuple sout | nl; sout | "toggle separator"; sout | f | "" | d | "" | ld; // floating point without separator sout | sepDisable | fc | dc | ldc; // complex without separator sout | fc | sepOn | dc | ldc; // local separator add sout | sepEnable | fc | dc | ldc; // complex with separator sout | fc | sepOff | dc | ldc; // local separator removal sout | s1 | sepOff | s2; // local separator removal sout | s1 | "" | s2; // local separator removal sout | nl; sout | "change separator"; sout | "from \"" | sep | "\"" | nonl; sepSet( sout, ", $" ); // change separator, maximum of 15 characters sout | " to \"" | sep | "\""; sout | f | d | ld; sout | fc | dc | ldc; sout | s1 | s2; sout | t1 | t2; // print tuple sout | nl; sout | "from \"" | sep | "\" " | nonl; sepSet( sout, " " ); // restore separator sout | "to \"" | sep | "\""; sout | f | d | ld; sout | fc | dc | ldc; sout | s1 | s2; sout | t1 | t2; // print tuple sout | nl; sout | "check sepOn/sepOff"; sout | sepOn | 1 | 2 | 3 | sepOn; // no separator at start/end of line sout | 1 | sepOff | 2 | 3; // locally turn off implicit separator sout | sepOn | sepOn | 1 | 2 | 3 | sepOn | sepOff | sepOn | '\n' | nonl; // no separator at start/end of line sout | 1 | 2 | 3 | "\n\n" | sepOn | nonl; // no separator at start of next line sout | 1 | 2 | 3; sout | nl; sout | "check enable/disable"; sout | sepDisable | 1 | 2 | 3; // globally turn off implicit separation sout | 1 | sepOn | 2 | 3; // locally turn on implicit separator sout | sepEnable | 1 | 2 | 3 | sepDisable; // globally turn on/off implicit separation sout | 1 | 2 | 3 | sepEnable; // globally turn on implicit separation sout | 1 | 2 | 3 | sepOn | sepDisable; // ignore seperate at end of line sout | 1 | 2 | 3 | sepOn | sepEnable; // separator at end of line sout | 1 | 2 | 3; sout | nl; // sout | fmt( d, "%8.3f" ); sepSetTuple( sout, " " ); // set tuple separator from ", " to " " sout | t1 | t2 | " \"" | sep | "\""; sepSetTuple( sout, ", " ); // reset tuple separator to ", " sout | t1 | t2 | " \"" | sep | "\""; sout | t1 | t2; // print tuple sout | nl; [int, int, const char *, double] t3 = { 3, 4, "a", 7.2 }; sout | [ 3, 4, (const char*)"a", 7.2 ]; // workaround trac#207: the const cast should not be needed sout | t3; sepSetTuple( sout, " " ); sout | t3; sout | sepOn | t3 | sepDisable | t3 | sepEnable | t3; sepSet( sout, "^" ); sepSetTuple( sout, "-" ); sout | t3 | 3 | 4 | t3; } // Local Variables: // // tab-width: 4 // // compile-command: "cfa -DIN_DIR=\".in/\" io.cfa" // // End: //