ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumwith_gc
Last change
on this file since 17417cf was
971d9f2,
checked in by Peter A. Buhr <pabuhr@…>, 7 years ago
|
add "with" clause to test programs
|
-
Property mode set to
100644
|
File size:
1.7 KB
|
Rev | Line | |
---|
[e06be49] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2017 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 | // fmtLines.cc -- |
---|
| 8 | // |
---|
| 9 | // Author : Peter A. Buhr |
---|
| 10 | // Created On : Sun Sep 17 21:56:15 2017 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[971d9f2] | 12 | // Last Modified On : Tue Dec 5 21:56:35 2017 |
---|
| 13 | // Update Count : 38 |
---|
[e06be49] | 14 | // |
---|
| 15 | |
---|
| 16 | #include <fstream> |
---|
| 17 | #include <coroutine> |
---|
| 18 | |
---|
| 19 | coroutine Format { |
---|
| 20 | char ch; // used for communication |
---|
| 21 | int g, b; // global because used in destructor |
---|
| 22 | }; |
---|
| 23 | |
---|
| 24 | void ?{}( Format & fmt ) { |
---|
[6545adff] | 25 | resume( fmt ); // prime (start) coroutine |
---|
[e06be49] | 26 | } |
---|
| 27 | |
---|
[971d9f2] | 28 | void ^?{}( Format & fmt ) with( fmt ) { |
---|
| 29 | if ( g != 0 || b != 0 ) sout | endl; |
---|
[e06be49] | 30 | } |
---|
| 31 | |
---|
[971d9f2] | 32 | void main( Format & fmt ) with( fmt ) { |
---|
[e06be49] | 33 | for ( ;; ) { // for as many characters |
---|
[971d9f2] | 34 | for ( g = 0; g < 5; g += 1 ) { // groups of 5 blocks |
---|
| 35 | for ( b = 0; b < 4; b += 1 ) { // blocks of 4 characters |
---|
[e06be49] | 36 | for ( ;; ) { // for newline characters |
---|
| 37 | suspend(); |
---|
[971d9f2] | 38 | if ( ch != '\n' ) break; // ignore newline |
---|
[e06be49] | 39 | } // for |
---|
[971d9f2] | 40 | sout | ch; // print character |
---|
[e06be49] | 41 | } // for |
---|
| 42 | sout | " "; // print block separator |
---|
| 43 | } // for |
---|
| 44 | sout | endl; // print group separator |
---|
| 45 | } // for |
---|
| 46 | } // main |
---|
| 47 | |
---|
| 48 | void prt( Format & fmt, char ch ) { |
---|
[6545adff] | 49 | fmt.ch = ch; |
---|
| 50 | resume( fmt ); |
---|
[e06be49] | 51 | } // prt |
---|
| 52 | |
---|
| 53 | int main() { |
---|
[6545adff] | 54 | Format fmt; // format characters into blocks of 4 and groups of 5 blocks per line |
---|
[e06be49] | 55 | char ch; |
---|
| 56 | |
---|
[6545adff] | 57 | Eof: for ( ;; ) { // read until end of file |
---|
[e06be49] | 58 | sin | ch; // read one character |
---|
[6545adff] | 59 | if ( eof( sin ) ) break Eof; // eof ? |
---|
| 60 | prt( fmt, ch ); // push character for formatting |
---|
[e06be49] | 61 | } // for |
---|
| 62 | } // main |
---|
| 63 | |
---|
| 64 | // Local Variables: // |
---|
| 65 | // tab-width: 4 // |
---|
| 66 | // compile-command: "cfa fmtLines.c" // |
---|
| 67 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.