Initialize Tizen 2.3
[external/ragel.git] / test / high2.rl
1 /*
2  * @LANG: c++
3  */
4
5 /**
6  * Test a high character to make sure signedness 
7  * isn't messing us up.
8  */
9
10 #include <stdio.h>
11 #include <string.h>
12
13 struct Fsm
14 {
15         int cs;
16
17         // Initialize the machine. Invokes any init statement blocks. Returns 0
18         // if the machine begins in a non-accepting state and 1 if the machine
19         // begins in an accepting state.
20         int init( );
21
22         // Execute the machine on a block of data. Returns -1 if after processing
23         // the data, the machine is in the error state and can never accept, 0 if
24         // the machine is in a non-accepting state and 1 if the machine is in an
25         // accepting state.
26         int execute( const unsigned char *data, int len );
27
28         // Indicate that there is no more data. Returns -1 if the machine finishes
29         // in the error state and does not accept, 0 if the machine finishes
30         // in any other non-accepting state and 1 if the machine finishes in an
31         // accepting state.
32         int finish( );
33 };
34
35 %%{
36         machine Fsm;
37
38         alphtype unsigned char;
39
40         # Indicate we got the high character.
41         action gothigh {
42                 printf("yes\n");
43         }
44
45         main := 0xe8 @gothigh '\n';
46 }%%
47
48 %% write data;
49
50 int Fsm::init( )
51 {
52         %% write init;
53         return 0;
54 }
55
56 int Fsm::execute( const unsigned char *_data, int _len )
57 {
58         const unsigned char *p = _data;
59         const unsigned char *pe = _data+_len;
60         %% write exec;
61         if ( cs == Fsm_error )
62                 return -1;
63         if ( cs >= Fsm_first_final )
64                 return 1;
65         return 0;
66 }
67
68 int Fsm::finish()
69 {
70         if ( cs == Fsm_error )
71                 return -1;
72         if ( cs >= Fsm_first_final )
73                 return 1;
74         return 0;
75 }
76
77 Fsm fsm;
78
79 void test( unsigned char *buf, int len )
80 {
81         fsm.init();
82         fsm.execute( buf, len );
83         if ( fsm.finish() > 0 )
84                 printf("ACCEPT\n");
85         else
86                 printf("FAIL\n");
87 }
88
89 unsigned char data1[] = { 0xe8, 10 };
90 unsigned char data2[] = { 0xf8, 10 };
91
92 int main()
93 {
94         test( data1, 2 );
95         test( data2, 2 );
96         return 0;
97 }
98
99 #ifdef _____OUTPUT_____
100 yes
101 ACCEPT
102 FAIL
103 #endif