#! /usr/bin/env perl # Used to be a one-liner: # # perl -0777pe ... # open (INPUT, "<$ARGV[0]") or die; @input = ; close (INPUT); $text = join ("", @input); # Kill uninteresting code sections. $text =~ s/#define.*//g; $text =~ s/#include.*//g; $text =~ s/#ifndef.*((.|[\r\n])*)#endif/\1/g; $text =~ s/#if DEBUG(.|[\r\n])*?#endif//g; $text =~ s/#ifdef __cplusplus(.|[\r\n])*?#endif//g; # Kill comments. $text =~ s{/\*(.|[\r\n])*?\*/}{}g; # Convert type specifiers. $text =~ s/(LLVM[^(\n\r]+?Ref)(?=[^(])/:pointer/g; $text =~ s/(const )?char \*/:string /g; $text =~ s/(\w|-|:)+ \*/:pointer /g; $text =~ s/unsigned long long/:unsigned-long-long/g; $text =~ s/($ARGV[1]") or die "Couldn't open file for writing: $ARGV[1]"; print (OUTPUT "$text\n"); close (OUTPUT); }