7 my $data = do { undef local $/; <STDIN>; };
11 my ($returnnewline) = @_;
21 $data =~ s/^[ \t\r\n]*//;
29 $data =~ s/^\/\/[^\r\n]*// and goto skipwhite;
31 $data =~ s/^\/\*.*?\*\/// and goto skipwhite;
33 if($data =~ s/^(["'])(.*?)\1//)
36 my %q = ( "\\" => "\\", "n" => "\n", "t" => "\t" );
37 $str =~ s/\\([\\nt])/$q{$1}/ge;
48 if($data =~ s/^([][\n{})(:,;])//)
54 if($data =~ s/^([^][ \t\r\n{})(:,;]*)//)
69 $p =~ s/(?:\.jpg|\.png|\.tga)$//gi;
74 my $find_texture_names = grep { /^-t$/ } @ARGV;
75 my $dump_shaders = grep { /^-d$/ } @ARGV;
76 my @match = grep { !/^-/ } @ARGV;
83 $curshader = normalize_path $com_token;
86 if(!gettoken(0) || $com_token ne "{")
88 die "parsing error - expected \"{\", found \"$com_token\"";
95 last if $com_token eq "}";
100 # we're not actually parsing this
102 $shadertext .= " {\n";
106 last if $com_token eq "}";
107 next if $com_token eq "\n";
111 while($com_token ne "\n" && $com_token ne "}")
113 push @parameter, $com_token;
114 last unless gettoken 1;
117 $shadertext .= " @parameter\n";
119 last if $com_token eq "}";
122 $shadertext .= " }\n";
127 while($com_token ne "\n" && $com_token ne "}")
129 push @parameter, $com_token;
130 last unless gettoken 1;
133 next if @parameter < 1;
135 $shadertext .= " @parameter\n";
138 $shadertext .= "}\n";
140 if(!@match || grep { $_ eq $curshader } @match)
142 printf "%s %s\n", Digest::MD5::md5_hex($shadertext), $curshader;
144 if($find_texture_names)
146 # find out possibly loaded textures
147 my @maps = ($shadertext =~ /^(?:clampmap|map|q3r_lightimage|q3r_editorimage) ([^\$].*)$/gim);
148 for($shadertext =~ /^animmap \S+ (.*)$/gim)
150 push @maps, split / /, $_;
152 for($shadertext =~ /^skyparms (.*)$/gim)
157 push @maps, "$_"."_lf";
158 push @maps, "$_"."_ft";
159 push @maps, "$_"."_rt";
160 push @maps, "$_"."_bk";
161 push @maps, "$_"."_up";
162 push @maps, "$_"."_dn";
167 printf "* %s %s\n", $_, $curshader
168 for map { normalize_path $_ } @maps;
173 print "| $_\n" for split /\n/, $shadertext;