ADT
        aaron-thesis
        arm-eh
        ast-experimental
        cleanup-dtors
        deferred_resn
        demangler
        enum
        forall-pointer-decay
        jacob/cs343-translation
        jenkins-sandbox
        new-ast
        new-ast-unique-expr
        new-env
        no_list
        persistent-indexer
        pthread-emulation
        qualifiedEnum
        resolv-new
        with_gc
      
      
        
          | 
            Last change
 on this file since 4b6ef70 was             e06be49, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago           | 
        
        
          | 
             
add output coroutine test 
 
           | 
        
        
          
            
              - 
Property                 mode
 set to                 
100644
               
             
           | 
        
        
          | 
            File size:
            1.6 KB
           | 
        
      
      
| Line |   | 
|---|
| 1 | // 
 | 
|---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo
 | 
|---|
| 3 | //
 | 
|---|
| 4 | // The contents of this file are covered under the licence agreement in the
 | 
|---|
| 5 | // file "LICENCE" distributed with Cforall.
 | 
|---|
| 6 | // 
 | 
|---|
| 7 | // fmtLines.cc -- 
 | 
|---|
| 8 | // 
 | 
|---|
| 9 | // Author           : Peter A. Buhr
 | 
|---|
| 10 | // Created On       : Sun Sep 17 21:56:15 2017
 | 
|---|
| 11 | // Last Modified By : Peter A. Buhr
 | 
|---|
| 12 | // Last Modified On : Mon Sep 18 11:35:57 2017
 | 
|---|
| 13 | // Update Count     : 31
 | 
|---|
| 14 | // 
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #include <fstream>
 | 
|---|
| 17 | #include <coroutine>
 | 
|---|
| 18 | 
 | 
|---|
| 19 | coroutine Format {
 | 
|---|
| 20 |         char ch;                                                                                        // used for communication
 | 
|---|
| 21 |         int g, b;                                                                                       // global because used in destructor
 | 
|---|
| 22 | };
 | 
|---|
| 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 | endl;
 | 
|---|
| 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
 | 
|---|
| 37 |                                         suspend();
 | 
|---|
| 38 |                                         if ( fmt.ch != '\n' ) break;            // ignore newline
 | 
|---|
| 39 |                                 } // for
 | 
|---|
| 40 |                                 sout | fmt.ch;                                                  // print character
 | 
|---|
| 41 |                         } // for
 | 
|---|
| 42 |                         sout | "  ";                                                            // print block separator
 | 
|---|
| 43 |                 } // for
 | 
|---|
| 44 |                 sout | endl;                                                                    // print group separator
 | 
|---|
| 45 |         } // for
 | 
|---|
| 46 | } // main
 | 
|---|
| 47 | 
 | 
|---|
| 48 | void prt( Format & fmt, char ch ) {
 | 
|---|
| 49 |     fmt.ch = ch;
 | 
|---|
| 50 |     resume( fmt );
 | 
|---|
| 51 | } // prt
 | 
|---|
| 52 | 
 | 
|---|
| 53 | int main() {
 | 
|---|
| 54 |         Format fmt;
 | 
|---|
| 55 |         char ch;
 | 
|---|
| 56 | 
 | 
|---|
| 57 |         for ( ;; ) {
 | 
|---|
| 58 |                 sin | ch;                                                                               // read one character
 | 
|---|
| 59 |           if ( eof( sin ) ) break;                                                      // eof ?
 | 
|---|
| 60 |                 prt( fmt, ch );
 | 
|---|
| 61 |         } // for
 | 
|---|
| 62 | } // main
 | 
|---|
| 63 | 
 | 
|---|
| 64 | // Local Variables: //
 | 
|---|
| 65 | // tab-width: 4 //
 | 
|---|
| 66 | // compile-command: "cfa fmtLines.c" //
 | 
|---|
| 67 | // End: //
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.