Changeset 3ac5fd8 for tests/generator
- Timestamp:
- Aug 17, 2024, 3:15:21 PM (4 months ago)
- Branches:
- master
- Children:
- df2e00f
- Parents:
- afb15cf
- Location:
- tests/generator
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/generator/.expect/fmtLines.txt
rafb15cf r3ac5fd8 9 9 E" d istr ibut ed w ith 10 10 Cfor all. //// fmt Line 11 s.cc --/ /// Auth or 12 : P eter A. 13 Buhr // C reat ed O n 14 : Su n Se p 17 21: 15 56:1 5 20 17// Las t Mo 16 difi ed B y : Pete r A. 17 Buh r// Last Mod ifie 18 d On : F ri M ar 2 2 13 19 :41: 03 2 019/ / Up date 20 Cou nt : 33/ /#in 21 clud e <f stre am.h fa># 22 incl ude <cor outi ne.h 23 fa>c orou tine For mat 24 { ch ar c h; 25 // used for com muni 26 cati on i nt g , b; 27 / / gl obal bec 28 ause use d in des truc 29 tor} ;voi d ?{ }( F orma 30 t & fmt ) { r esum 31 e( f mt ) ; / 32 / st art coro utin e}vo 33 id ^ ?{}( For mat & fm 34 t ) { if ( fm t.g 35 != 0 || fmt. b != 0 ) 36 sou t | nl;} void mai 37 n( F orma t & fmt ) { 38 for ( ;; ) { 39 // for as many cha 40 ract ers for ( f mt.g 41 = 0 ; fm t.g < 5; fmt 42 .g + = 1 ) { // grou 43 ps o f 5 bloc ks for 44 ( f mt.b = 0 ; fm t.b 45 < 4; fmt .b + = 1 ) { 46 // b lock s of 4 c hara 47 cter s for ( ; ; ) 48 { // f or n ewli 49 ne c hara cter s su 50 spen d; i f ( fmt. 51 ch ! = '\ n' ) bre ak; 52 // igno re n ewli ne 53 } // f or so ut | 54 fmt .ch; / / pr 55 int char acte r } // 56 for s out | " "; 57 / / pr int bloc 58 k se para tor } / / fo 59 r s out | nl ; 60 // pri nt g roup sep 61 arat or } // for} // 62 main void prt ( Fo rmat 63 & f mt, char ch ) { 64 f mt.c h = ch; r 65 esum e( f mt ) ;} / / pr 66 tint mai n() { Fo rmat 67 fmt ; ch ar c h; f or ( 68 ;; ) { sin | c h; 69 // r ead one 70 char acte r if ( eof 71 ( si n ) ) br eak; 72 / / eo f ? prt ( fm 73 t, c h ); } / / fo r} / 74 / ma in// Loc al V aria 75 bles : // // t ab-w idth 76 : 4 //// com pile -com 77 mand : "c fa f mtLi nes. 78 cfa" /// / En d: / / 11 s.cf a -- for mat char 12 acte rs i nto bloc ks o 13 f 4 and grou ps o f 5 14 bloc ks p er l ine/ /// 15 Auth or : T 16 hier ry D elis le// Cre 17 ated On : Thu 18 Mar 5 1 6:09 :08 2020 19 // L ast Modi fied By 20 : Pe ter A. B uhr/ / La 21 st M odif ied On : Sat 22 Aug 17 14:2 1:28 202 23 4// Upda te C ount 24 : 5 //#i nclu de < fstr 25 eam. hfa> gene rato r Fo 26 rmat { c har ch; 27 // use d fo r co 28 mmun icat ion int g, b 29 ; // g loba 30 l be caus e us ed i n de 31 stru ctor };vo id m ain( 32 For mat & fm t ) with 33 ( fm t ) { fo r () { 34 // for as m 35 any char acte rs for 36 ( g = 0; g < 5; g += 37 1 ) { / / gr oups 38 of 5 bl ocks f or ( 39 b = 0; b < 4; b += 40 1 ) { // bloc ks o 41 f 4 char acte rs fo 42 r () { // for 43 new line cha ract ers 44 susp end; if 45 ( c h != '\n ' ) brea 46 k; // ign ore newl 47 ine } // for s 48 out | ch ; // 49 prin t ch arac ter } 50 // f or sou t | " " 51 ; // prin t bl 52 ock sepa rato r } // 53 for sou t | nl; 54 // prin t gr oup 55 sepa rato r } // f or} 56 // m ainv oid ?{}( For 57 mat & fm t ) { re sume 58 ( fm t ); // 59 pri me ( star t) c orou 60 tine }voi d ^? {}( Form 61 at & fmt ) w ith( fmt 62 ) { if ( g != 0 || 63 b != 0 ) sou t | nl;} 64 void for mat( For mat 65 & fm t ) { re sume ( fm 66 t ); } // for mati nt m 67 ain( ) { Form at f mt; 68 sout | n lOff ; 69 / / tu rn o ff a uto 70 newl ine try { f or ( 71 ) { // read 72 unt il e nd o f fi le 73 sin | f mt.c h; 74 // rea d on e ch arac 75 ter fo rmat ( fm t ); 76 // p ush char 77 acte r fo r fo rmat ting 78 } // f or } cat ch( 79 end_ of_f ile * ) { } 80 // t ry} // m ain -
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: // -
tests/generator/fmtLines.cfa
rafb15cf r3ac5fd8 10 10 // Created On : Thu Mar 5 16:09:08 2020 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jun 10 21:56:22 202113 // Update Count : 212 // Last Modified On : Sat Aug 17 14:21:28 2024 13 // Update Count : 5 14 14 // 15 15 … … 53 53 sout | nlOff; // turn off auto newline 54 54 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 59 } // 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 60 62 } // main 61 62 // Local Variables: //63 // tab-width: 4 //64 // compile-command: "cfa fmtLines.cfa" //65 // End: //
Note: See TracChangeset
for help on using the changeset viewer.