// // 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. // // io2.cfa -- // // Author : Peter A. Buhr // Created On : Wed Mar 2 16:56:02 2016 // Last Modified By : Peter A. Buhr // Last Modified On : Thu Jun 13 16:43:14 2019 // Update Count : 120 // #include #define xstr(s) str(s) #define str(s) #s int main() { _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, "a", 7.2 ]; 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/\" io2.cfa" // // End: //