Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tests/coroutine/fmtLines.c

    ra0cfa44 r971d9f2  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // fmtLines.cc -- format characters into blocks of 4 and groups of 5 blocks per line
     7// fmtLines.cc --
    88//
    99// Author           : Peter A. Buhr
    1010// Created On       : Sun Sep 17 21:56:15 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 15 12:25:33 2018
    13 // Update Count     : 42
     12// Last Modified On : Tue Dec  5 21:56:35 2017
     13// Update Count     : 38
    1414//
    1515
     
    2121        int g, b;                                                                                       // global because used in destructor
    2222};
     23
     24void ?{}( Format & fmt ) {
     25        resume( fmt );                                                                          // prime (start) coroutine
     26}
     27
     28void ^?{}( Format & fmt ) with( fmt ) {
     29        if ( g != 0 || b != 0 ) sout | endl;
     30}
    2331
    2432void main( Format & fmt ) with( fmt ) {
     
    3846} // main
    3947
    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 ) {
     48void prt( Format & fmt, char ch ) {
     49        fmt.ch = ch;
    4950        resume( fmt );
    5051} // prt
    5152
    5253int main() {
    53         Format fmt;
     54        Format fmt;                                                                                     // format characters into blocks of 4 and groups of 5 blocks per line
     55        char ch;
    5456
    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
     57        Eof: for ( ;; ) {                                                                       // read until end of file
     58                sin | ch;                                                                               // read one character
     59          if ( eof( sin ) ) break Eof;                                          // eof ?
     60                prt( fmt, ch );                                                                 // push character for formatting
    5961        } // for
    6062} // main
Note: See TracChangeset for help on using the changeset viewer.