]> git.draconx.ca Git - cdecl99.git/blob - test/typegen.sh
1658d5db81c30d24e590270c5a17ea7bb551c02c
[cdecl99.git] / test / typegen.sh
1 #!/bin/sh
2 #
3 # Copyright © 2011 Nick Bowler
4 #
5 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
6 # This is free software: you are free to do what the fuck you want to.
7 # There is NO WARRANTY, to the extent permitted by law.
8
9 cat <<EOF
10 /* This file was automatically generated by $0 $*. */
11 struct cdecl_declspec *s, *p;
12 EOF
13
14 i=0
15 while read line
16 do
17         case "$line" in
18         [[:alpha:]_]*)
19                 :
20                 ;;
21         *)
22                 printf '%s\n' "$line";
23                 continue
24                 ;;
25         esac
26
27         cat <<EOF
28 case $i:
29         s = NULL;
30 EOF
31
32         set $line
33         while test $# -gt 0
34         do
35                 token=`printf '%s' "$1" | tr [:lower:] [:upper:] | tr -d _`
36                 cat <<EOF
37         p = s;
38         s = malloc_nofail(sizeof *s);
39         *s = (struct cdecl_declspec) {
40                 .type = CDECL_TYPE_$token,
41                 .next = p,
42         };
43 EOF
44                 shift
45         done
46
47         i=`expr $i + 1`
48         cat <<EOF
49         return s;
50 EOF
51 done
52
53 cat <<EOF
54 default:
55         assert(0);
56 #define TOTAL_TYPES $i
57 EOF