use File::Glob; my $output = < "'0"'0 { } + - * / = ! % & ( ) , . : ; ? @ [ ] ^ | ~ + < = > 1/* 2*/ 0// for if else do while switch case default return break continue new decl public stock const enum forward static funcenum functag native sizeof true false # Action bool Float Plugin String any __tags__ MaxClients __defines__ EOF my @incs = glob("sourcepawn_include/*.inc"); my %generated_stuff = {}; my @tags = (); my @defines = (); foreach (@incs) { undef $/; open FILE, $_ or die "Couldn't open file: $!"; binmode FILE; my $contents = ; close FILE; push(@tags, $contents =~ m/enum\s+([a-zA-Z][a-zA-Z0-9_-]*)\s*\{/g); push(@defines, $contents =~ m/\#define\s+([^_\s][^\s]*)/g); while ($contents =~ m/[^c]enum\s+(?:\w+\s+)?{(.+?)}/sg) { my $enumcontents = $1; $enumcontents =~ s/=\s*[a-zA-Z0-9\+\-\*\/_\|&><\(\)~\^!=]+\s*//g; $enumcontents =~ s/\/\/.*//g; $enumcontents =~ s/\/\*.*?\*\///sg; $enumcontents =~ s/\s//g; $enumcontents =~ s/,$//; push(@defines, split(/,/, $enumcontents)); } } foreach (@tags) { $generated_stuff{tags} .= "$_ "; } foreach (@defines) { $generated_stuff{defines} .= "$_ "; } $output =~ s/__tags__/$generated_stuff{tags}/; $output =~ s/__defines__/$generated_stuff{defines}/; open OUTPUTTEXT, ">userDefineLang.xml"; print OUTPUTTEXT $output; close OUTPUTTEXT;