source: tests/io2.c@ dfb7c96

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr no_list persistent-indexer pthread-emulation qualifiedEnum
Last change on this file since dfb7c96 was 73abe95, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Replace extension-less headers with .hfa

  • Property mode set to 100644
File size: 4.4 KB
RevLine 
[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//
7// io2.c --
8//
[53ba273]9// Author : Peter A. Buhr
10// Created On : Wed Mar 2 16:56:02 2016
11// Last Modified By : Peter A. Buhr
[ef3403c6]12// Last Modified On : Thu May 24 21:17:41 2018
13// Update Count : 103
[cbdf565]14//
[53ba273]15
[73abe95]16#include <fstream.hfa>
[53ba273]17
[cbdf565]18 #define xstr(s) str(s)
19#define str(s) #s
20
[53ba273]21int 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
[cbdf565]43 ifstream in = { xstr(IN_DIR) "io.data" }; // create / open file
[53ba273]44
[86f384b]45 sout | "input bacis types" | endl;
[5f20b30]46 in | b // boolean
47 | c | sc | usc // character
[09687aa]48 | si | usi | i | ui | li | uli | lli | ulli // integral
49 | f | d | ld // floating point
50 | fc | dc | ldc // floating-point complex
51 | cstr( s1 ) | cstr( s2, size ); // C string, length unchecked and checked
[86f384b]52 sout | endl;
[53ba273]53
[86f384b]54 sout | "output basic types" | endl;
[5f20b30]55 sout | b | endl // boolean
56 | c | ' ' | sc | ' ' | usc | endl // character
[09687aa]57 | si | usi | i | ui | li | uli | lli | ulli | endl // integral
58 | f | d | ld | endl // floating point
59 | fc | dc | ldc | endl; // complex
[53ba273]60 sout | endl;
[86f384b]61
62 sout | "tuples" | endl;
[53a6c2a]63 [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
[86f384b]64 sout | t1 | t2 | endl; // print tuple
65 sout | endl;
66
67 sout | "toggle separator" | endl;
[5a7966bb]68 sout | f | "" | d | "" | ld | endl // floating point without separator
[09687aa]69 | sepDisable | fc | dc | ldc | endl // complex without separator
70 | fc | sepOn | dc | ldc | endl // local separator add
71 | sepEnable | fc | dc | ldc | endl // complex with separator
72 | fc | sepOff | dc | ldc | endl // local separator removal
73 | s1 | sepOff | s2 | endl // local separator removal
74 | s1 | "" | s2 | endl; // local separator removal
[53ba273]75 sout | endl;
76
[86f384b]77 sout | "change separator" | endl;
[53a6c2a]78 sout | "from \"" | sep | "\"";
[5a7966bb]79 sepSet( sout, ", $" ); // change separator, maximum of 15 characters
[53a6c2a]80 sout | " to \"" | sep | "\"" | endl;
[829c907]81 sout | f | d | ld | endl
[09687aa]82 | fc | dc | ldc | endl
83 | s1 | s2 | endl
84 | t1 | t2 | endl; // print tuple
[d395012]85 sout | endl;
[53a6c2a]86 sout | "from \"" | sep | "\" ";
[86f384b]87 sepSet( sout, " " ); // restore separator
[53a6c2a]88 sout | "to \"" | sep | "\"" | endl;
[86f384b]89 sout | f | d | ld | endl
[09687aa]90 | fc | dc | ldc | endl
91 | s1 | s2 | endl
92 | t1 | t2 | endl; // print tuple
[d395012]93 sout | endl;
[6b6597c]94
[53a6c2a]95 sout | "check sepOn/sepOff" | endl;
96 sout | sepOn | 1 | 2 | 3 | sepOn | endl; // no separator at start/end of line
[5a7966bb]97 sout | 1 | sepOff | 2 | 3 | endl; // locally turn off implicit separator
[53a6c2a]98 sout | sepOn | sepOn | 1 | 2 | 3 | sepOn | sepOff | sepOn | '\n'; // no separator at start/end of line
99 sout | 1 | 2 | 3 | "\n\n" | sepOn; // no separator at start of next line
[d395012]100 sout | 1 | 2 | 3 | endl;
101 sout | endl;
[5a7966bb]102
[53a6c2a]103 sout | "check enable/disable" | endl;
[5a7966bb]104 sout | sepDisable | 1 | 2 | 3 | endl; // globally turn off implicit separation
105 sout | 1 | sepOn | 2 | 3 | endl; // locally turn on implicit separator
[d395012]106 sout | sepEnable | 1 | 2 | 3 | endl | sepDisable; // globally turn on/off implicit separation
107 sout | 1 | 2 | 3 | endl | sepEnable; // globally turn on implicit separation
108 sout | 1 | 2 | 3 | sepOn | sepDisable | endl; // ignore seperate at end of line
109 sout | 1 | 2 | 3 | sepOn | sepEnable | endl; // separator at end of line
110 sout | 1 | 2 | 3 | endl;
111 sout | endl;
[5a7966bb]112
[53a6c2a]113// sout | fmt( d, "%8.3f" ) || endl;
114// sout | endl;
115
[5a7966bb]116 sepSetTuple( sout, " " ); // set tuple separator from ", " to " "
[53a6c2a]117 sout | t1 | t2 | " \"" | sep | "\"" | endl;
[5a7966bb]118 sepSetTuple( sout, ", " ); // reset tuple separator to ", "
[53a6c2a]119 sout | t1 | t2 | " \"" | sep | "\"" | endl;
[5a7966bb]120 sout | t1 | t2 | endl; // print tuple
[d395012]121 sout | endl;
[829c907]122
[5a7966bb]123 [int, int, const char *, double] t3 = { 3, 4, "a", 7.2 };
[cb91437]124 sout | [ 3, 4, "a", 7.2 ] | endl;
[5a7966bb]125 sout | t3 | endl;
[829c907]126 sepSetTuple( sout, " " );
[5a7966bb]127 sout | t3 | endl;
128 sout | sepOn | t3 | sepDisable | t3 | sepEnable | t3 | endl;
[829c907]129 sepSet( sout, "^" );
130 sepSetTuple( sout, "-" );
[5a7966bb]131 sout | t3 | 3 | 4 | t3 | endl;
[53ba273]132}
133
134// Local Variables: //
135// tab-width: 4 //
[ef3403c6]136// compile-command: "cfa io2.c" //
[53ba273]137// End: //
Note: See TracBrowser for help on using the repository browser.