shader audit script improved (parses shaders now)
[xonotic/xonotic-maps.pk3dir.git] / scripts / shader-audit.sh
1 #!/bin/sh
2
3 use_texture()
4 {
5         echo "$1 uses texture $2"
6 }
7
8 parsing_shader=
9
10 parse_shaderstage()
11 {
12         while read L A1 A2 Aother; do
13                 case "$L" in
14                         map)
15                                 case "$A1" in
16                                         '$lightmap')
17                                                 ;;
18                                         *)
19                                                 use_texture "$parsing_shader" "$A1"
20                                                 ;;
21                                 esac
22                                 ;;
23                         animmap)
24                                 for X in $A2 $Aother; do
25                                         use_texture "$parsing_shader" "$X"
26                                 done
27                                 ;;
28                         '}')
29                                 break
30                                 ;;
31                         *)
32                                 ;;
33                 esac
34         done
35 }
36
37 parse_shader()
38 {
39         while read L A1; do
40                 case "$L" in
41                         qer_editorimage\ *)
42                                 use_texture "$parsing_shader" "$A1"
43                                 ;;
44                         '{')
45                                 parse_shaderstage
46                                 ;;
47                         '}')
48                                 break
49                                 ;;
50                         *)
51                                 ;;
52                 esac
53         done
54 }
55
56 parse_shaderfile()
57 {
58         while read L; do
59                 case "$L" in
60                         textures/*)
61                                 parsing_shader="$L"
62                                 ;;
63                         '{')
64                                 parse_shader
65                                 ;;
66                         *)
67                                 ;;
68                 esac
69         done
70 }
71
72 strip_comments()
73 {
74         sed 's,//.*,,g; s,\r, ,g; s,\t, ,g; s,  *, ,g; s, $,,; s,^ ,,; /^$/ d'
75 }
76
77 t=`mktemp`
78 for X in *.shader; do
79         strip_comments < "$X" > "$t"
80         parse_shaderfile < "$t"
81 done
82 rm -f "$t"
83
84 ( cd ../textures; find */ -type f -not -name '*_norm.*' -not -name '*_glow.*' -not -name '*_gloss.*' -print ) | while IFS= read -r TEX; do
85         TEX=${TEX%.*}
86         # does it have a shader?
87         if ! grep -Ei '^[[:space:]]*((animmap|map|qer_editorimage)[[:space:]]+)?"?textures/'"$TEX"'(\.tga)?"?[[:space:]]*(//.*)?$' *.shader >/dev/null; then
88                 echo "No shader defined using $TEX, please add one"
89         fi
90 done