gen-strtab.awk: Work around IRIX 6.2 nawk bug.
[dxcommon.git] / t / bison.sh
blobc21d1bf6dd87220ffb5f60085ca18d224e318e90
1 #!/bin/sh
3 # Copyright © 2021 Nick Bowler
5 # Fake bison program for testing the bison detection macro.
7 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
8 # This is free software: you are free to do what the fuck you want to.
9 # There is NO WARRANTY, to the extent permitted by law.
11 : "${FAKE_BISON_VERSION=2.4.0}"
13 argv0=$0
15 infile=
16 outheader=
17 use_header=false
19 for arg
21 case $arg in
22 --defines) use_header=true ;;
23 --defines=*) use_header=true outheader=${arg%*=} ;;
24 *.y) infile=$arg ;;
25 esac
26 done
28 if test x"$infile" = x""; then
29 printf '%s: error: no input file\n' "$argv0" 1>&2
30 exit 1
33 outfile=${infile%.y}.tab.c
34 if $use_header; then
35 test ${outheader:+y} || outheader=${outfile%.c}.h
36 exec 5>"$outheader"
38 exec 3<"$infile" 4>"$outfile"
40 copy_header=false copy_impl=false
41 while read line <&3; do
42 case $line in
43 %require*)
44 save_IFS=$IFS IFS=$IFS\".
45 set x $FAKE_BISON_VERSION 0 0 0; shift
46 fake_major=$1 fake_minor=$2 fake_revision=$3
47 set x ${line#*\"} 0 0 0; shift
48 req_major=$1 req_minor=$2 req_revision=$3
49 IFS=$save_IFS
50 set -x
51 test $fake_major -ge $req_major || exit 1
52 if test $fake_major -eq $req_major; then
53 test $fake_minor -ge $req_minor || exit 1
54 if test $fake_minor -eq $req_minor; then
55 test $fake_revision -ge $req_revision || exit 1
58 set +x
60 %code*)
61 set x $line; shift
62 case $2 in
63 requires|provides) copy_header=true copy_impl=true ;;
64 top) copy_impl=true ;;
65 esac
67 [}])
68 copy_header=false copy_impl=false
70 %%)
71 break
74 $copy_header && printf '%s\n' "$line" >&5
75 $copy_impl && printf '%s\n' "$line" >&4
77 esac
78 done
80 cat >&4 <<EOF
81 int yyparse(void)
83 return 0;
85 EOF
87 while read line <&3; do
88 case $line in
89 %%) break;
90 esac
91 done
93 cat <&3 >&4