Initialize Tizen 2.3
[external/ragel.git] / test / erract3.rl
1 /*
2  * @LANG: c
3  */
4
5 #include <stdio.h>
6 #define IDENT_BUFLEN 256
7
8 struct erract
9 {
10         int cs;
11 };
12
13 %%{
14         machine erract;
15         variable cs fsm->cs;
16
17         # The data that is to go into the fsm structure.
18         action hello_fails { printf("hello fails\n");}
19
20         newline = ( any | '\n' @{printf("newline\n");} )*;
21         hello = 'hello\n'* $lerr hello_fails @eof hello_fails;
22         main := newline | hello;
23 }%%
24
25 %% write data;
26
27 void erract_init( struct erract *fsm )
28 {
29         %% write init;
30 }
31
32 void erract_execute( struct erract *fsm, const char *_data, int _len )
33 {
34         const char *p = _data;
35         const char *pe = _data+_len;
36         const char *eof = pe;
37         %% write exec;
38 }
39
40 int erract_finish( struct erract *fsm )
41 {
42         if ( fsm->cs == erract_error )
43                 return -1;
44         else if ( fsm->cs >= erract_first_final )
45                 return 1;
46         return 0;
47 }
48
49 #include <stdio.h>
50 #include <string.h>
51
52 struct erract fsm;
53
54 void test( char *buf )
55 {
56         int len = strlen(buf);
57         erract_init( &fsm );
58         erract_execute( &fsm, buf, len );
59         if ( erract_finish( &fsm ) > 0 )
60                 printf("ACCEPT\n");
61         else
62                 printf("FAIL\n");
63 }
64
65 int main()
66 {
67         test(
68                 "hello\n"
69                 "hello\n"
70                 "hello\n"
71         );
72
73         test(
74                 "hello\n"
75                 "hello\n"
76                 "hello there\n"
77         );
78
79         test(
80                 "hello\n"
81                 "hello\n"
82                 "he"    );
83
84         test( "" );
85
86         return 0;
87 }
88
89 #ifdef _____OUTPUT_____
90 newline
91 newline
92 newline
93 ACCEPT
94 newline
95 newline
96 hello fails
97 newline
98 ACCEPT
99 newline
100 newline
101 hello fails
102 ACCEPT
103 ACCEPT
104 #endif