Changeset 3ac5fd8 for tests/generator/.in/fmtLines.txt
- Timestamp:
- Aug 17, 2024, 3:15:21 PM (3 months ago)
- Branches:
- master
- Children:
- df2e00f
- Parents:
- afb15cf
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/generator/.in/fmtLines.txt
rafb15cf r3ac5fd8 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // fmtLines.c c --7 // fmtLines.cfa -- format characters into blocks of 4 and groups of 5 blocks per line 8 8 // 9 // Author : Peter A. Buhr10 // Created On : Sun Sep 17 21:56:15 20179 // Author : Thierry Delisle 10 // Created On : Thu Mar 5 16:09:08 2020 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:21:28 2024 13 // Update Count : 5 14 14 // 15 15 16 16 #include <fstream.hfa> 17 #include <coroutine.hfa>18 17 19 coroutineFormat {18 generator Format { 20 19 char ch; // used for communication 21 20 int g, b; // global because used in destructor 22 21 }; 23 22 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 23 void main( Format & fmt ) with( fmt ) { 24 for () { // for as many characters 25 for ( g = 0; g < 5; g += 1 ) { // groups of 5 blocks 26 for ( b = 0; b < 4; b += 1 ) { // blocks of 4 characters 27 for () { // for newline characters 37 28 suspend; 38 if ( fmt.ch != '\n' ) break;// ignore newline29 if ( ch != '\n' ) break; // ignore newline 39 30 } // for 40 sout | fmt.ch;// print character31 sout | ch; // print character 41 32 } // for 42 33 sout | " "; // print block separator 43 34 } // for 44 sout | nl; // print group separator35 sout | nl; // print group separator 45 36 } // for 46 37 } // main 47 38 48 void prt( Format & fmt, char ch ) { 49 fmt.ch = ch; 50 resume( fmt ); 51 } // prt 39 void ?{}( Format & fmt ) { 40 resume( fmt ); // prime (start) coroutine 41 } 42 43 void ^?{}( Format & fmt ) with( fmt ) { 44 if ( g != 0 || b != 0 ) sout | nl; 45 } 46 47 void format( Format & fmt ) { 48 resume( fmt ); 49 } // format 52 50 53 51 int main() { 54 52 Format fmt; 55 char ch;53 sout | nlOff; // turn off auto newline 56 54 57 for ( ;; ) { 58 sin | ch; // read one character 59 if ( eof( sin ) ) break; // eof ? 60 prt( fmt, ch ); 61 } // for 55 try { 56 for () { // read until end of file 57 sin | fmt.ch; // read one character 58 format( fmt ); // push character for formatting 59 } // for 60 } catch( end_of_file * ) { 61 } // try 62 62 } // 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.