Last change
on this file since 8315947 was
a573c22,
checked in by Peter A. Buhr <pabuhr@…>, 5 years ago
|
example programs updated for concurrency paper
|
-
Property mode set to
100644
|
File size:
890 bytes
|
Line | |
---|
1 | #include <stdio.h> |
---|
2 | |
---|
3 | typedef struct { |
---|
4 | int restart, g, b; |
---|
5 | char ch; |
---|
6 | } Fmt; |
---|
7 | |
---|
8 | void comain( Fmt * f ) { |
---|
9 | static void * states[] = {&&s0, &&s1}; |
---|
10 | goto *states[f->restart]; |
---|
11 | s0: f->restart = 1; |
---|
12 | for ( ;; ) { |
---|
13 | for ( f->g = 0; f->g < 5; f->g += 1 ) { // groups |
---|
14 | for ( f->b = 0; f->b < 4; f->b += 1 ) { // blocks |
---|
15 | do { |
---|
16 | return; s1: ; |
---|
17 | } while ( f->ch == '\n' ); // ignore |
---|
18 | printf( "%c", f->ch ); // print character |
---|
19 | } |
---|
20 | printf( " " ); // block separator |
---|
21 | } |
---|
22 | printf( "\n" ); // group separator |
---|
23 | } |
---|
24 | } |
---|
25 | |
---|
26 | int main() { |
---|
27 | Fmt fmt = { 0 }; |
---|
28 | comain( &fmt ); // prime |
---|
29 | for ( ;; ) { |
---|
30 | scanf( "%c", &fmt.ch ); // direct read into communication variable |
---|
31 | if ( feof( stdin ) ) break; |
---|
32 | comain( &fmt ); |
---|
33 | } |
---|
34 | if ( fmt.g != 0 || fmt.b != 0 ) printf( "\n" ); |
---|
35 | } |
---|
36 | |
---|
37 | // Local Variables: // |
---|
38 | // tab-width: 4 // |
---|
39 | // compile-command: "gcc-8 Format.c" // |
---|
40 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.