Changeset 3ac5fd8 for tests/coroutine/.in
- Timestamp:
- Aug 17, 2024, 3:15:21 PM (16 months ago)
- Branches:
- master
- Children:
- df2e00f
- Parents:
- afb15cf
- File:
-
- 1 edited
-
tests/coroutine/.in/fmtLines.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/coroutine/.in/fmtLines.txt
rafb15cf r3ac5fd8 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // fmtLines.cc -- 7 // fmtLines.cc -- format characters into blocks of 4 and groups of 5 blocks per line 8 8 // 9 9 // Author : Peter A. Buhr 10 10 // Created On : Sun Sep 17 21:56:15 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 22 13:41:03 201913 // Update Count : 3312 // Last Modified On : Sat Aug 17 14:26:03 2024 13 // Update Count : 60 14 14 // 15 15 … … 22 22 }; 23 23 24 void ?{}( Format & fmt ) { 25 resume( fmt ); // start coroutine 26 } 27 28 void ^?{}( Format & fmt ) { 29 if ( fmt.g != 0 || fmt.b != 0 ) sout | nl; 30 } 31 32 void main( Format & fmt ) { 33 for ( ;; ) { // for as many characters 34 for ( fmt.g = 0; fmt.g < 5; fmt.g += 1 ) { // groups of 5 blocks 35 for ( fmt.b = 0; fmt.b < 4; fmt.b += 1 ) { // blocks of 4 characters 36 for ( ;; ) { // for newline characters 24 void main( Format & fmt ) with( fmt ) { 25 for () { // for as many characters 26 for ( g = 0; g < 5; g += 1 ) { // groups of 5 blocks 27 for ( b = 0; b < 4; b += 1 ) { // blocks of 4 characters 28 for () { // for newline characters 37 29 suspend; 38 if ( fmt.ch != '\n' ) break;// ignore newline30 if ( ch != '\n' ) break; // ignore newline 39 31 } // for 40 sout | fmt.ch;// print character32 sout | ch; // print character 41 33 } // for 42 34 sout | " "; // print block separator 43 35 } // for 44 sout | nl; // print group separator36 sout | nl; // print group separator 45 37 } // for 46 38 } // main 47 39 48 void prt( Format & fmt, char ch ) { 49 fmt.ch = ch; 50 resume( fmt ); 51 } // prt 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 | nl; 46 } 47 48 void format( Format & fmt ) { 49 resume( fmt ); 50 } // format 52 51 53 52 int main() { 54 53 Format fmt; 55 char ch;54 sout | nlOff; // turn off auto newline 56 55 57 for ( ;; ) { 58 sin | ch; // read one character 59 if ( eof( sin ) ) break; // eof ? 60 prt( fmt, ch ); 61 } // for 56 try { 57 for () { // read until end of file 58 sin | fmt.ch; // read one character 59 format( fmt ); // push character for formatting 60 } // for 61 } catch( end_of_file * ) { 62 } // try 62 63 } // main 63 64 // Local Variables: //65 // tab-width: 4 //66 // compile-command: "cfa fmtLines.cfa" //67 // End: //
Note:
See TracChangeset
for help on using the changeset viewer.