source: src/tests/io.c@ 8aa474a

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 8aa474a was 09687aa, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

complete conversion of iostream/fstream to use references

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