1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/genUsageTableEnum.pl Fri Dec 19 18:05:53 2014 +0100
1.3 @@ -0,0 +1,106 @@
1.4 +#!/usr/local/bin/perl
1.5 +#Developed by Stéphane Lenclud
1.6 +#Generate C# enumeration from parsing Hid Usage Table
1.7 +#See ../data/gl.h
1.8 +#Usage example
1.9 +#perl -S genUsageTableEnum.pl ../data/gl.h
1.10 +
1.11 +use strict;
1.12 +use warnings;
1.13 +
1.14 +
1.15 +my $inputFile = $ARGV[0];
1.16 +
1.17 +#my $dummy="lala";
1.18 +#$dummy=~s/(^\w)/uc($1)/e;
1.19 +#print "$dummy";
1.20 +#exit(0);
1.21 +
1.22 +#Open input file
1.23 +open INPUT, "< $inputFile" or die "Can't read $inputFile\n";
1.24 +my @lines = <INPUT>;
1.25 +close INPUT;
1.26 +
1.27 +
1.28 +my %hash = ();
1.29 +
1.30 +my $count=0;
1.31 +foreach my $line(@lines)
1.32 + {
1.33 + #if ($line=~ /^\#\s*define\s+(.+?)\s+([a-fA-FxX\d]+?)\s*$/)
1.34 + if ($line=~ /^([a-fA-FxX\d]+)(.+)\s+\w+\s+15\..*$/)
1.35 + {
1.36 + my $string=$2;
1.37 + my $value=$1;
1.38 +
1.39 + my $varName=FormatVarName($string);
1.40 +
1.41 +
1.42 + $hash{$string}=$value;
1.43 +
1.44 + print "$varName = 0x$value,\n";
1.45 + }
1.46 + else
1.47 + {
1.48 + #print "NO MATCH $line\n";
1.49 + }
1.50 + }
1.51 +
1.52 +exit(0);
1.53 +
1.54 +#Output in sorted order
1.55 +for my $string ( sort keys %hash )
1.56 + {
1.57 + #print "_S8(\"$string\"),$hash{$string}, //$count\n";
1.58 + print "_S8(\"$string\"),$string, //$count\n";
1.59 + $count++;
1.60 + }
1.61 +
1.62 +
1.63 +print "$count const found.\n";
1.64 +
1.65 +exit(0);
1.66 +
1.67 +#
1.68 +
1.69 +sub FormatVarName
1.70 + {
1.71 + my $text=$_[0];
1.72 + my $varName="";
1.73 + Trim($text);
1.74 + #Make sure AC ends up as AppCtrl
1.75 + $text=~s/(^AC)/App Ctrl/;
1.76 + #Make sure AL ends up as AppLaunch
1.77 + $text=~s/(^AL)/App Launch/;
1.78 + #Replace / by white-space
1.79 + $text=~s/\// /g;
1.80 + #Replace + with Plus
1.81 + $text=~s/\+/Plus/g;
1.82 + #Replace - with white-space
1.83 + $text=~s/-/ /g;
1.84 +
1.85 +
1.86 + $text=lc($text);
1.87 + while ($text=~/(\w+)\s+(.+)/)
1.88 + {
1.89 + my $word=$1;
1.90 + $text=$2;
1.91 + #upper case the first letter
1.92 + $word=~s/(^\w)/uc($1)/e;
1.93 + $varName.=$word;
1.94 + }
1.95 +
1.96 + $text=~s/(^\w)/uc($1)/e;
1.97 + $varName.=$text;
1.98 + #get ride of -
1.99 + $varName=~s/-(\w)/uc($1)/e;
1.100 +
1.101 + return $varName;
1.102 + }
1.103 +
1.104 +sub Trim
1.105 + {
1.106 + $_[0] =~ s/^\s+//; #Trim leading space and line return char
1.107 + $_[0] =~ s/\s+$//; #Trim trailling space and line return char
1.108 + }
1.109 +