update(add) packaging directory and spec file from OBSTF:Private, OBS
[external/ragel.git] / test / high3.rl
1 /*
2  * @LANG: obj-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 <objc/Object.h>
12
13 @interface Fsm : Object
14 {
15 @public
16         int cs;
17 };
18
19 // Initialize the machine. Invokes any init statement blocks. Returns 0
20 // if the machine begins in a non-accepting state and 1 if the machine
21 // begins in an accepting state.
22 - (int) initFsm;
23
24 // Execute the machine on a block of data. Returns -1 if after processing
25 // the data, the machine is in the error state and can never accept, 0 if
26 // the machine is in a non-accepting state and 1 if the machine is in an
27 // accepting state.
28 - (void) executeWithData:(const unsigned char *)data len:(int)len;
29
30 // Indicate that there is no more data. Returns -1 if the machine finishes
31 // in the error state and does not accept, 0 if the machine finishes
32 // in any other non-accepting state and 1 if the machine finishes in an
33 // accepting state.
34 - (int) finish;
35
36 @end
37
38 @implementation Fsm
39
40 %%{
41         machine Fsm;
42
43         alphtype unsigned char;
44
45         # Indicate we got the high character.
46         action gothigh {
47                 printf("yes\n");
48         }
49
50         main := 0xe8 @gothigh '\n';
51 }%%
52
53 %% write data;
54
55 - (int) initFsm;
56 {
57         %% write init;
58         return 1;
59 }
60
61 - (void) executeWithData:(const unsigned char *)_data len:(int)_len;
62 {
63         const unsigned char *p = _data;
64         const unsigned char *pe = _data + _len;
65         %% write exec;
66 }
67
68 - (int) finish;
69 {
70         if ( cs == Fsm_error )
71                 return -1;
72         else if ( cs >= Fsm_first_final )
73                 return 1;
74         return 0;
75 }
76
77
78 @end
79
80
81 #define BUFSIZE 2048
82
83 Fsm *fsm;
84 unsigned char buf[BUFSIZE];
85
86 void test( unsigned char *buf, int len )
87 {
88         fsm = [[Fsm alloc] init];
89         [fsm initFsm];
90         [fsm executeWithData:buf len:len];
91         if ( [fsm finish] > 0 )
92                 printf("ACCEPT\n");
93         else
94                 printf("FAIL\n");
95 }
96
97 unsigned char data1[] = { 0xe8, 10 };
98 unsigned char data2[] = { 0xf8, 10 };
99
100 int main()
101 {
102         test( data1, 2 );
103         test( data2, 2 );
104         return 0;
105 }
106
107 #ifdef _____OUTPUT_____
108 yes
109 ACCEPT
110 FAIL
111 #endif