- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/concurrency/examples/Format1.c
ra573c22 r466fa01 2 2 3 3 typedef struct { 4 int restart, g, b;4 void * next; 5 5 char ch; 6 int g, b; 6 7 } Fmt; 7 8 8 9 void format( Fmt * f ) { 9 static void * states[] = {&&s0, &&s1}; 10 goto *states[f->restart]; 11 s0: f->restart = 1; 10 if ( __builtin_expect(f->next != 0, 1) ) goto *f->next; 11 f->next = &&s1; 12 12 for ( ;; ) { 13 13 for ( f->g = 0; f->g < 5; f->g += 1 ) { // groups 14 14 for ( f->b = 0; f->b < 4; f->b += 1 ) { // blocks 15 15 return; 16 s1: if ( f->ch == '\0' ) goto fini; // EOF ? 16 s1: ; 17 if ( f->ch == '\0' ) goto fini; // EOF ? 17 18 while ( f->ch == '\n' ) return; // ignore 18 //printf( "%c", f->ch ); // print character19 printf( "%c", f->ch ); // print character 19 20 } 20 //printf( " " ); // block separator21 printf( " " ); // block separator 21 22 } 22 //printf( "\n" ); // group separator23 printf( "\n" ); // group separator 23 24 } 24 fini: ;25 //if ( f->g != 0 || f->b != 0 ) printf( "\n" );25 fini: 26 if ( f->g != 0 || f->b != 0 ) printf( "\n" ); 26 27 } 27 28 28 29 int main() { 29 Fmt fmt = { 0};30 Fmt fmt = { NULL }; 30 31 format( &fmt ); // prime 31 fmt.ch = 'a'; 32 for ( long int i = 0; i < 1000000000; i += 1 ) { 33 // scanf( "%c", &fmt.ch ); // direct read into communication variable 34 // if ( feof( stdin ) ) break; 32 for ( ;; ) { 33 scanf( "%c", &fmt.ch ); // direct read into communication variable 34 if ( feof( stdin ) ) break; 35 35 format( &fmt ); 36 36 } 37 fmt.ch = '\0'; // sentential (EOF)37 fmt.ch = '\0'; 38 38 format( &fmt ); 39 39 }
Note:
See TracChangeset
for help on using the changeset viewer.