source: src/tests/io.c@ f240484

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 f240484 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
RevLine 
[53ba273]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
[09687aa]12// Last Modified On : Wed Dec 6 23:15:42 2017
13// Update Count : 88
[53ba273]14//
15
16#include <fstream>
17
18int main() {
[5a7966bb]19 char c; // basic types
[cd218e8]20 signed char sc;
21 unsigned char usc;
[53ba273]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;
[5a7966bb]36 enum { size = 10 };
37 char s1[size], s2[size];
[53ba273]38
[58b5d03]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
[86f384b]46 sout | "opening delimiters" | endl;
[5a7966bb]47 sout
[09687aa]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;
[86f384b]59
60 sout | "closing delimiters" | endl;
[5a7966bb]61 sout
[09687aa]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;
[86f384b]74
75 sout | "opening/closing delimiters" | endl;
[5a7966bb]76 sout
[09687aa]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;
[86f384b]84
85 sout | "override opening/closing delimiters" | endl;
[5a7966bb]86 sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4 | endl;
[86f384b]87 sout | endl;
[5a7966bb]88
[09687aa]89 ifstream in = { "io.data" }; // create / open file
[53ba273]90
[86f384b]91 sout | "input bacis types" | endl;
[09687aa]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
[86f384b]97 sout | endl;
[53ba273]98
[86f384b]99 sout | "output basic types" | endl;
[cd218e8]100 sout | c | ' ' | sc | ' ' | usc | endl // character
[09687aa]101 | si | usi | i | ui | li | uli | lli | ulli | endl // integral
102 | f | d | ld | endl // floating point
103 | fc | dc | ldc | endl; // complex
[53ba273]104 sout | endl;
[86f384b]105
106 sout | "tuples" | endl;
[53a6c2a]107 [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
[86f384b]108 sout | t1 | t2 | endl; // print tuple
109 sout | endl;
110
111 sout | "toggle separator" | endl;
[5a7966bb]112 sout | f | "" | d | "" | ld | endl // floating point without separator
[09687aa]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
[53ba273]119 sout | endl;
120
[86f384b]121 sout | "change separator" | endl;
[53a6c2a]122 sout | "from \"" | sep | "\"";
[5a7966bb]123 sepSet( sout, ", $" ); // change separator, maximum of 15 characters
[53a6c2a]124 sout | " to \"" | sep | "\"" | endl;
[829c907]125 sout | f | d | ld | endl
[09687aa]126 | fc | dc | ldc | endl
127 | s1 | s2 | endl
128 | t1 | t2 | endl; // print tuple
[d395012]129 sout | endl;
[53a6c2a]130 sout | "from \"" | sep | "\" ";
[86f384b]131 sepSet( sout, " " ); // restore separator
[53a6c2a]132 sout | "to \"" | sep | "\"" | endl;
[86f384b]133 sout | f | d | ld | endl
[09687aa]134 | fc | dc | ldc | endl
135 | s1 | s2 | endl
136 | t1 | t2 | endl; // print tuple
[d395012]137 sout | endl;
[6b6597c]138
[53a6c2a]139 sout | "check sepOn/sepOff" | endl;
140 sout | sepOn | 1 | 2 | 3 | sepOn | endl; // no separator at start/end of line
[5a7966bb]141 sout | 1 | sepOff | 2 | 3 | endl; // locally turn off implicit separator
[53a6c2a]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
[d395012]144 sout | 1 | 2 | 3 | endl;
145 sout | endl;
[5a7966bb]146
[53a6c2a]147 sout | "check enable/disable" | endl;
[5a7966bb]148 sout | sepDisable | 1 | 2 | 3 | endl; // globally turn off implicit separation
149 sout | 1 | sepOn | 2 | 3 | endl; // locally turn on implicit separator
[d395012]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;
[5a7966bb]156
[53a6c2a]157// sout | fmt( d, "%8.3f" ) || endl;
158// sout | endl;
159
[5a7966bb]160 sepSetTuple( sout, " " ); // set tuple separator from ", " to " "
[53a6c2a]161 sout | t1 | t2 | " \"" | sep | "\"" | endl;
[5a7966bb]162 sepSetTuple( sout, ", " ); // reset tuple separator to ", "
[53a6c2a]163 sout | t1 | t2 | " \"" | sep | "\"" | endl;
[5a7966bb]164 sout | t1 | t2 | endl; // print tuple
[d395012]165 sout | endl;
[829c907]166
[5a7966bb]167 [int, int, const char *, double] t3 = { 3, 4, "a", 7.2 };
[cb91437]168 sout | [ 3, 4, "a", 7.2 ] | endl;
[5a7966bb]169 sout | t3 | endl;
[829c907]170 sepSetTuple( sout, " " );
[5a7966bb]171 sout | t3 | endl;
172 sout | sepOn | t3 | sepDisable | t3 | sepEnable | t3 | endl;
[829c907]173 sepSet( sout, "^" );
174 sepSetTuple( sout, "-" );
[5a7966bb]175 sout | t3 | 3 | 4 | t3 | endl;
[53ba273]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.