Initialize Tizen 2.3
[external/ragel.git] / test / high1.rl
1 /*
2  * @LANG: c
3  * @ALLOW_GENFLAGS: -T0 -T1 -G0 -G1 -G2
4  */
5
6 /**
7  * Test a high character to make sure signedness 
8  * isn't messing us up.
9  */
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14
15 struct high
16 {
17         int cs;
18 };
19
20 %%{
21         machine high;
22         variable cs fsm->cs;
23
24         # We Want the header portion.
25         alphtype unsigned int;
26
27         main := ( 
28                         0x20 .. 0xefffffff   @1 @{printf("gothigh1\n");} | 
29                         0xf0000000           @1 @{printf("gothigh1\n");} | 
30                         0x200 .. 0xfe000000  @1 @{printf("gothigh2\n");} |
31                         any                  @0 @{printf("else\n");}
32                 )*;
33 }%%
34
35 %% write data;
36
37 void high_init( struct high *fsm )
38 {
39         %% write init;
40 }
41
42 void high_execute( struct high *fsm, const unsigned int *_data, int _len )
43 {
44         const unsigned int *p = _data;
45         const unsigned int *pe = _data+_len;
46
47         %% write exec;
48 }
49
50 int high_finish( struct high *fsm )
51 {
52         if ( fsm->cs == high_error )
53                 return -1;
54         if ( fsm->cs >= high_first_final )
55                 return 1;
56         return 0;
57 }
58
59 struct high high;
60
61 #define BUFSIZE 1024
62 char cbuf[BUFSIZE];
63 unsigned int buf[BUFSIZE];
64 int buflen = 0;
65 char numbuf[9];
66 int numlen = 0;
67
68 struct tokenizer
69 {
70         int cs;
71 };
72
73 %%{
74         machine tokenizer;
75         variable cs fsm->cs;
76
77         action bufdigit {
78                 if ( numlen < 8 )
79                         numbuf[numlen++] = fc;
80         }
81
82         action writeDigit {
83                 /* Null terminate the buffer storing the number and reset. */
84                 numbuf[numlen] = 0;
85                 numlen = 0;
86
87                 /* Store the number in the buf. If the buf is full then 
88                  * flush and reset the buffer. */
89                 buf[buflen++] = strtoul( numbuf, 0, 16 );
90                 if ( buflen == BUFSIZE ) {
91                         high_execute( &high, buf, BUFSIZE );
92                         buflen = 0;
93                 }
94         }
95
96         action finish {
97                 if ( buflen > 0 )
98                         high_execute( &high, buf, buflen );
99                 if ( high_finish( &high ) > 0 )
100                         printf("ACCEPT\n");
101                 else
102                         printf("FAIL\n");
103         }
104
105         num = ( digit | 'a'..'f' )+ $bufdigit %writeDigit;
106         main := ( num $1 %0 | space )* %/finish;
107 }%%
108
109 %% write data;
110
111 void tokenizer_init( struct tokenizer *fsm )
112 {
113         %% write init;
114 }
115
116 void tokenizer_execute( struct tokenizer *fsm, const char *_data, int _len )
117 {
118         const char *p = _data;
119         const char *pe = _data+_len;
120         const char *eof = pe;
121
122         %% write exec;
123 }
124
125 int tokenizer_finish( struct tokenizer *fsm )
126 {
127         if ( fsm->cs == tokenizer_error )
128                 return -1;
129         if ( fsm->cs >= tokenizer_first_final )
130                 return 1;
131         return 0;
132 }
133
134 struct tokenizer tok;
135
136 void test( char *cbuf )
137 {
138         int len = strlen( cbuf );
139         high_init( &high );
140         tokenizer_init( &tok );
141         tokenizer_execute( &tok, cbuf, len );
142         if ( tokenizer_finish( &tok ) <= 0 )
143                 printf("Tokenizer FAIL\n");
144 }
145
146 char data[] =
147         "10 20 30 40 50 200 300 400 \n"
148         "d0000000 f0000000 fd000000 fe000000\n"
149         "ff000000 ffffffffffffffffffffffffff\n"
150         "ff\n";
151
152 int main()
153 {
154         test( data );
155         return 0;
156 }
157
158 #ifdef _____OUTPUT_____
159 else
160 gothigh1
161 gothigh1
162 gothigh1
163 gothigh1
164 gothigh1
165 gothigh2
166 gothigh1
167 gothigh2
168 gothigh1
169 gothigh2
170 gothigh1
171 gothigh2
172 gothigh1
173 gothigh2
174 gothigh2
175 gothigh2
176 else
177 else
178 gothigh1
179 ACCEPT
180 #endif