]> git.rm.cloudns.org Git - xonotic/xonotic-maps.pk3dir.git/commitdiff
shader audit script improved (parses shaders now)
authorRudolf Polzer <divverent@alientrap.org>
Thu, 15 Jul 2010 15:45:00 +0000 (17:45 +0200)
committerRudolf Polzer <divverent@alientrap.org>
Thu, 15 Jul 2010 15:45:00 +0000 (17:45 +0200)
scripts/shader-audit.sh

index d5710c7083d2612981857737944089da3325f3ee..388f3944d97c2a5f267ccc8f1192f259b92f4c75 100644 (file)
@@ -1,5 +1,86 @@
 #!/bin/sh
 
+use_texture()
+{
+       echo "$1 uses texture $2"
+}
+
+parsing_shader=
+
+parse_shaderstage()
+{
+       while read L A1 A2 Aother; do
+               case "$L" in
+                       map)
+                               case "$A1" in
+                                       '$lightmap')
+                                               ;;
+                                       *)
+                                               use_texture "$parsing_shader" "$A1"
+                                               ;;
+                               esac
+                               ;;
+                       animmap)
+                               for X in $A2 $Aother; do
+                                       use_texture "$parsing_shader" "$X"
+                               done
+                               ;;
+                       '}')
+                               break
+                               ;;
+                       *)
+                               ;;
+               esac
+       done
+}
+
+parse_shader()
+{
+       while read L A1; do
+               case "$L" in
+                       qer_editorimage\ *)
+                               use_texture "$parsing_shader" "$A1"
+                               ;;
+                       '{')
+                               parse_shaderstage
+                               ;;
+                       '}')
+                               break
+                               ;;
+                       *)
+                               ;;
+               esac
+       done
+}
+
+parse_shaderfile()
+{
+       while read L; do
+               case "$L" in
+                       textures/*)
+                               parsing_shader="$L"
+                               ;;
+                       '{')
+                               parse_shader
+                               ;;
+                       *)
+                               ;;
+               esac
+       done
+}
+
+strip_comments()
+{
+       sed 's,//.*,,g; s,\r, ,g; s,\t, ,g; s,  *, ,g; s, $,,; s,^ ,,; /^$/ d'
+}
+
+t=`mktemp`
+for X in *.shader; do
+       strip_comments < "$X" > "$t"
+       parse_shaderfile < "$t"
+done
+rm -f "$t"
+
 ( cd ../textures; find */ -type f -not -name '*_norm.*' -not -name '*_glow.*' -not -name '*_gloss.*' -print ) | while IFS= read -r TEX; do
        TEX=${TEX%.*}
        # does it have a shader?