Import c99types.h and related probes from cdecl99.
[dxcommon.git] / t / flex.sh
blobf5fd6495014e9f3481777de4b1f9479f9d29f9d6
1 #!/bin/sh
3 # Copyright © 2020 Nick Bowler
5 # Fake flex program for testing the flex 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_FLEX_VERSION=2.0.0}"
13 argv0=$0
15 infile=
16 outfile=lex.yy.c
17 for arg
19 shift
21 case $arg in
22 -o) outfile=$1; shift ;;
23 *) set x "$@" "$arg"; shift ;;
24 esac
25 done
27 for arg
29 case $arg in
30 *.l) infile=$arg ;;
31 esac
32 done
34 if test x"$infile" = x""; then
35 printf '%s: error: no input file\n' "$argv0" 1>&2
36 exit 1
39 copyout=false
40 exec 3<"$infile" 4>"$outfile"
42 save_IFS=$IFS IFS=.
43 set x $FAKE_FLEX_VERSION 0 0 0; shift
44 IFS=$save_IFS
46 cat >&4 <<EOF
47 #define FLEX_SCANNER
48 #define YY_FLEX_MAJOR_VERSION $1
49 #define YY_FLEX_MINOR_VERSION $2
50 #define YY_FLEX_SUBMINOR_VERSION $3
51 EOF
53 while read line <&3; do
54 case $line in
55 %{) copyout=true ;;
56 %}) copyout=false ;;
57 %%) break ;;
58 *) $copyout && printf '%s\n' "$line" >&4 ;;
59 esac
60 done
62 cat >&4 <<EOF
63 int yylex(void)
65 return 0;
67 EOF
69 while read line <&3; do
70 case $line in
71 %%) break ;;
72 esac
73 done
75 cat <&3 >&4