sl@33: #!/usr/local/bin/perl sl@33: #Developed by Stéphane Lenclud sl@33: #Generate C# enumeration from parsing Hid Usage Table sl@33: #See ../data/gl.h sl@33: #Usage example sl@33: #perl -S genUsageTableEnum.pl ../data/gl.h sl@33: sl@33: use strict; sl@33: use warnings; sl@33: sl@33: sl@33: my $inputFile = $ARGV[0]; sl@33: sl@33: #my $dummy="lala"; sl@33: #$dummy=~s/(^\w)/uc($1)/e; sl@33: #print "$dummy"; sl@33: #exit(0); sl@33: sl@33: #Open input file sl@33: open INPUT, "< $inputFile" or die "Can't read $inputFile\n"; sl@33: my @lines = ; sl@33: close INPUT; sl@33: sl@33: sl@33: my %hash = (); sl@33: sl@33: my $count=0; sl@33: foreach my $line(@lines) sl@33: { sl@34: #if ($line=~ /^([a-fA-FxX\d]+)(.+)\s+\w+\s+15\..*$/) sl@34: if ($line=~ /^([a-fA-FxX\d]+)(.+)\s+\w+\s+\d+\..*$/) sl@33: { sl@33: my $string=$2; sl@33: my $value=$1; sl@33: sl@33: my $varName=FormatVarName($string); sl@33: sl@33: sl@33: $hash{$string}=$value; sl@33: sl@33: print "$varName = 0x$value,\n"; sl@33: } sl@33: else sl@33: { sl@33: #print "NO MATCH $line\n"; sl@33: } sl@33: } sl@33: sl@33: exit(0); sl@33: sl@33: #Output in sorted order sl@33: for my $string ( sort keys %hash ) sl@33: { sl@33: #print "_S8(\"$string\"),$hash{$string}, //$count\n"; sl@33: print "_S8(\"$string\"),$string, //$count\n"; sl@33: $count++; sl@33: } sl@33: sl@33: sl@33: print "$count const found.\n"; sl@33: sl@33: exit(0); sl@33: sl@33: # sl@33: sl@33: sub FormatVarName sl@33: { sl@33: my $text=$_[0]; sl@33: my $varName=""; sl@33: Trim($text); sl@33: #Make sure AC ends up as AppCtrl sl@33: $text=~s/(^AC)/App Ctrl/; sl@33: #Make sure AL ends up as AppLaunch sl@33: $text=~s/(^AL)/App Launch/; sl@33: #Replace / by white-space sl@33: $text=~s/\// /g; sl@33: #Replace + with Plus sl@33: $text=~s/\+/Plus/g; sl@33: #Replace - with white-space sl@33: $text=~s/-/ /g; sl@33: sl@33: sl@33: $text=lc($text); sl@33: while ($text=~/(\w+)\s+(.+)/) sl@33: { sl@33: my $word=$1; sl@33: $text=$2; sl@33: #upper case the first letter sl@33: $word=~s/(^\w)/uc($1)/e; sl@33: $varName.=$word; sl@33: } sl@33: sl@33: $text=~s/(^\w)/uc($1)/e; sl@33: $varName.=$text; sl@33: #get ride of - sl@33: $varName=~s/-(\w)/uc($1)/e; sl@33: sl@33: return $varName; sl@33: } sl@33: sl@33: sub Trim sl@33: { sl@33: $_[0] =~ s/^\s+//; #Trim leading space and line return char sl@33: $_[0] =~ s/\s+$//; #Trim trailling space and line return char sl@33: } sl@33: