Fixes for gcc 4.3.
[external/ragel.git] / test / langtrans_c.sh
1 #!/bin/bash
2 #
3
4 file=$1
5
6 [ -f $file ] || exit 1
7
8 # Get the machine name.
9 machine=`sed -n 's/^[\t ]*machine[\t ]*\([a-zA-Z_0-9]*\)[\t ]*;[\t ]*$/\1/p' $file`
10
11 # Make a temporary version of the test case using the C language translations.
12 sed -n '/\/\*/,/\*\//d;p' $file | txl -q stdin langtrans_c.txl > $file.pr
13
14 needs_eof=`sed '/@NEEDS_EOF/s/^.*$/yes/p;d' $file`
15 if [ "$needs_eof" != 'yes' ]; then
16         needs_eof=`sed -n '/\/\*/,/\*\//d;p' $file | txl -q stdin checkeofact.txl`
17 fi
18
19 # Begin writing out the test case.
20 cat << EOF
21 /*
22  * @LANG: c
23  * @GENERATED: yes
24  */
25 #include <string.h>
26 #include <stdio.h>
27 EOF
28
29 # Write the data declarations
30 sed -n '/^%%$/q;p' $file.pr
31
32 # Write out the machine specification.
33 sed -n '/^%%{$/,/^}%%/p' $file.pr
34
35 # Write out the init and execute routines.
36 cat << EOF
37 int cs;
38 %% write data;
39 void init()
40 {
41 EOF
42
43 sed -n '0,/^%%$/d; /^%%{$/q; {s/^/\t/;p}' $file.pr
44
45 cat << EOF
46         %% write init;
47 }
48
49 void exec( char *data, int len )
50 {
51         char *p = data;
52         char *pe = data + len;
53 EOF
54
55 [ "$needs_eof" = "yes" ] && echo "char *eof = pe;"
56
57 cat << EOF
58         %% write exec;
59 }
60
61 void finish( )
62 {
63         if ( cs >= ${machine}_first_final )
64                 printf( "ACCEPT\\n" );
65         else
66                 printf( "FAIL\\n" );
67 }
68 EOF
69
70 # Write out the test data.
71 sed -n '0,/\/\* _____INPUT_____/d; /_____INPUT_____ \*\//q; p;' $file | awk '
72 BEGIN {
73         print "char *inp[] = {"
74 }
75 {
76         print " " $0 ","
77 }
78 END {
79         print "};"
80         print ""
81         print "int inplen = " NR ";"
82 }'
83
84 # Write out the main routine.
85 cat << EOF
86
87 int main( )
88 {
89         int i;
90         for ( i = 0; i < inplen; i++ ) {
91                 init();
92                 exec( inp[i], strlen(inp[i]) );
93                 finish();
94         }
95         return 0;
96 }
97 #ifdef _____OUTPUT_____
98 EOF
99
100 # Write out the expected output.
101 sed -n '0,/\/\* _____OUTPUT_____/d; /_____OUTPUT_____ \*\//q; p;' $file
102 echo "#endif"
103
104 # Don't need this language-specific file anymore.
105 rm $file.pr