Introcuded the "eof" variable for indicating the end of file. The p variable is
[ragel.git] / test / langtrans_c.sh
blob431ec2649624efb07b77d99797fbfdf15bf97df5
1 #!/bin/bash
4 file=$1
6 [ -f $file ] || exit 1
8 # Get the machine name.
9 machine=`sed -n 's/^[\t ]*machine[\t ]*\([a-zA-Z_0-9]*\)[\t ]*;[\t ]*$/\1/p' $file`
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
14 has_eof_act=`sed -n '/\/\*/,/\*\//d;p' $file | txl -q stdin checkeofact.txl`
16 # Begin writing out the test case.
17 cat << EOF
19 * @LANG: c
20 * @GENERATED: yes
22 #include <string.h>
23 #include <stdio.h>
24 EOF
26 # Write the data declarations
27 sed -n '/^%%$/q;p' $file.pr
29 # Write out the machine specification.
30 sed -n '/^%%{$/,/^}%%/p' $file.pr
32 # Write out the init and execute routines.
33 cat << EOF
34 int cs;
35 %% write data;
36 void init()
38 EOF
40 sed -n '0,/^%%$/d; /^%%{$/q; {s/^/\t/;p}' $file.pr
42 cat << EOF
43 %% write init;
46 void exec( char *data, int len )
48 char *p = data;
49 char *pe = data + len;
50 EOF
52 [ "$has_eof_act" = "yes" ] && echo "char *eof = pe;"
54 cat << EOF
55 %% write exec;
58 void finish( )
60 if ( cs >= ${machine}_first_final )
61 printf( "ACCEPT\\n" );
62 else
63 printf( "FAIL\\n" );
65 EOF
67 # Write out the test data.
68 sed -n '0,/\/\* _____INPUT_____/d; /_____INPUT_____ \*\//q; p;' $file | awk '
69 BEGIN {
70 print "char *inp[] = {"
73 print " " $0 ","
75 END {
76 print "};"
77 print ""
78 print "int inplen = " NR ";"
81 # Write out the main routine.
82 cat << EOF
84 int main( )
86 int i;
87 for ( i = 0; i < inplen; i++ ) {
88 init();
89 exec( inp[i], strlen(inp[i]) );
90 finish();
92 return 0;
94 #ifdef _____OUTPUT_____
95 EOF
97 # Write out the expected output.
98 sed -n '0,/\/\* _____OUTPUT_____/d; /_____OUTPUT_____ \*\//q; p;' $file
99 echo "#endif"
101 # Don't need this language-specific file anymore.
102 rm $file.pr