// // 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 : Tue Dec 11 21:51:52 2018 // Update Count : 109 // #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 | c | sc | usc // character | si | usi | i | ui | li | uli | lli | ulli // integral | f | d | ld // floating point | fc | dc | ldc // floating-point complex | cstr( s1 ) | cstr( s2, size ); // C string, length unchecked and checked sout | nl; sout | "output basic types"; sout | b | nl // boolean | c | ' ' | sc | ' ' | usc | nl // character | si | usi | i | ui | li | uli | lli | ulli | nl // integral | f | d | ld | nl // floating point | 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 | nl // floating point without separator | sepDisable | fc | dc | ldc | nl // complex without separator | fc | sepOn | dc | ldc | nl // local separator add | sepEnable | fc | dc | ldc | nl // complex with separator | fc | sepOff | dc | ldc | nl // local separator removal | s1 | sepOff | s2 | nl // local separator removal | 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 | nl | fc | dc | ldc | nl | s1 | s2 | nl | t1 | t2; // print tuple sout | nl; sout | "from \"" | sep | "\" " | nonl; sepSet( sout, " " ); // restore separator sout | "to \"" | sep | "\""; sout | f | d | ld | nl | fc | dc | ldc | nl | s1 | s2 | nl | 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'; // no separator at start/end of line sout | 1 | 2 | 3 | "\n\n" | sepOn; // 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 io2.cfa" // // End: //