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 7bdcac1 was
a0cfa44,
checked in by Peter A. Buhr <pabuhr@…>, 6 years ago
|
simplify
|
-
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 | // |
---|
[a0cfa44] | 7 | // fmtLines.cc -- format characters into blocks of 4 and groups of 5 blocks per line |
---|
[e06be49] | 8 | // |
---|
| 9 | // Author : Peter A. Buhr |
---|
| 10 | // Created On : Sun Sep 17 21:56:15 2017 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[a0cfa44] | 12 | // Last Modified On : Tue May 15 12:25:33 2018 |
---|
| 13 | // Update Count : 42 |
---|
[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 | |
---|
[971d9f2] | 24 | void main( Format & fmt ) with( fmt ) { |
---|
[e06be49] | 25 | for ( ;; ) { // for as many characters |
---|
[971d9f2] | 26 | for ( g = 0; g < 5; g += 1 ) { // groups of 5 blocks |
---|
| 27 | for ( b = 0; b < 4; b += 1 ) { // blocks of 4 characters |
---|
[e06be49] | 28 | for ( ;; ) { // for newline characters |
---|
| 29 | suspend(); |
---|
[971d9f2] | 30 | if ( ch != '\n' ) break; // ignore newline |
---|
[e06be49] | 31 | } // for |
---|
[971d9f2] | 32 | sout | ch; // print character |
---|
[e06be49] | 33 | } // for |
---|
| 34 | sout | " "; // print block separator |
---|
| 35 | } // for |
---|
| 36 | sout | endl; // print group separator |
---|
| 37 | } // for |
---|
| 38 | } // main |
---|
| 39 | |
---|
[a0cfa44] | 40 | void ?{}( Format & fmt ) { |
---|
| 41 | resume( fmt ); // prime (start) coroutine |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | void ^?{}( Format & fmt ) with( fmt ) { |
---|
| 45 | if ( g != 0 || b != 0 ) sout | endl; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | void format( Format & fmt ) { |
---|
[6545adff] | 49 | resume( fmt ); |
---|
[e06be49] | 50 | } // prt |
---|
| 51 | |
---|
| 52 | int main() { |
---|
[a0cfa44] | 53 | Format fmt; |
---|
[e06be49] | 54 | |
---|
[a0cfa44] | 55 | eof: for ( ;; ) { // read until end of file |
---|
| 56 | sin | fmt.ch; // read one character |
---|
| 57 | if ( eof( sin ) ) break eof; // eof ? |
---|
| 58 | format( fmt ); // push character for formatting |
---|
[e06be49] | 59 | } // for |
---|
| 60 | } // main |
---|
| 61 | |
---|
| 62 | // Local Variables: // |
---|
| 63 | // tab-width: 4 // |
---|
| 64 | // compile-command: "cfa fmtLines.c" // |
---|
| 65 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.