Ignore:
Timestamp:
Aug 17, 2024, 3:15:21 PM (16 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
df2e00f
Parents:
afb15cf
Message:

first attempt changing end-of-file to an exception

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/coroutine/.in/fmtLines.txt

    rafb15cf r3ac5fd8  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // fmtLines.cc --
     7// fmtLines.cc -- format characters into blocks of 4 and groups of 5 blocks per line
    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 : Fri Mar 22 13:41:03 2019
    13 // Update Count     : 33
     12// Last Modified On : Sat Aug 17 14:26:03 2024
     13// Update Count     : 60
    1414//
    1515
     
    2222};
    2323
    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
     24void 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
    3729                                        suspend;
    38                                         if ( fmt.ch != '\n' ) break;            // ignore newline
     30                                  if ( ch != '\n' ) break;                              // ignore newline
    3931                                } // for
    40                                 sout | fmt.ch;                                                  // print character
     32                                sout | ch;                                                              // print character
    4133                        } // for
    4234                        sout | "  ";                                                            // print block separator
    4335                } // for
    44                 sout | nl;                                                                      // print group separator
     36                sout | nl;                                                                              // print group separator
    4537        } // for
    4638} // main
    4739
    48 void prt( Format & fmt, char ch ) {
    49     fmt.ch = ch;
    50     resume( fmt );
    51 } // prt
     40void ?{}( Format & fmt ) {
     41        resume( fmt );                                                                          // prime (start) coroutine
     42}
     43
     44void ^?{}( Format & fmt ) with( fmt ) {
     45        if ( g != 0 || b != 0 ) sout | nl;
     46}
     47
     48void format( Format & fmt ) {
     49        resume( fmt );
     50} // format
    5251
    5352int main() {
    5453        Format fmt;
    55         char ch;
     54        sout | nlOff;                                                                           // turn off auto newline
    5655
    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
    6263} // 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.