From ed2dd0afe1541439fe3c1aed5a5866642e96b5ab Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 20 Aug 2009 02:52:19 +0000 Subject: add fmt-bindings from 3.0 git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@5551 d708f5d6-7413-0410-9779-e7cbd77b26cf --- tools/fmt-bindings | 414 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 414 insertions(+) create mode 100755 tools/fmt-bindings (limited to 'tools') diff --git a/tools/fmt-bindings b/tools/fmt-bindings new file mode 100755 index 0000000000..148ca20955 --- /dev/null +++ b/tools/fmt-bindings @@ -0,0 +1,414 @@ +#!/usr/bin/perl + +# import module +use Getopt::Long; + +$semicolon = ";"; # help out stupid emacs +$title = "Ardour Shortcuts"; +$in_group_def = 0; +$group_name; +$group_text; +$group_key; +$group_number = 0; +%group_names; +%group_text; +%group_bindings; +%modifier_map; +%group_numbering; +%merge_bindings; + +$platform = linux; +$winkey = 'Mod4> \$platform, + "winkey=s" => \$winkey, + "cheatsheet" => \$make_cheatsheet, + "accelmap" => \$make_accelmap, + "merge=s" => \$merge_from); + +if ($platform eq "osx") { + + $gtk_modifier_map{'PRIMARY'} = 'meta'; + $gtk_modifier_map{'SECONDARY'} = 'Mod1'; + $gtk_modifier_map{'TERTIARY'} = 'Shift'; + $gtk_modifier_map{'LEVEL4'} = 'Control'; + $gtk_modifier_map{'WINDOW'} = 'Mod1'; + + $cs_modifier_map{'PRIMARY'} = 'Command'; + $cs_modifier_map{'SECONDARY'} = 'Opt'; + $cs_modifier_map{'TERTIARY'} = 'Shift'; + $cs_modifier_map{'LEVEL4'} = 'Control'; + $cs_modifier_map{'WINDOW'} = 'Opt'; + + $mouse_modifier_map{'PRIMARY'} = 'Cmd'; + $mouse_modifier_map{'SECONDARY'} = 'Opt'; + $mouse_modifier_map{'TERTIARY'} = 'Shift'; + $mouse_modifier_map{'LEVEL4'} = 'Control'; + $mouse_modifier_map{'WINDOW'} = 'Opt'; + +} else { + + $gtk_modifier_map{'PRIMARY'} = 'Control'; + $gtk_modifier_map{'SECONDARY'} = 'Alt'; + $gtk_modifier_map{'TERTIARY'} = 'Shift'; + $gtk_modifier_map{'LEVEL4'} = $winkey; + $gtk_modifier_map{'WINDOW'} = 'Alt'; + $gtk_modifier_map{$winkey} => 'Win'; + + $cs_modifier_map{'PRIMARY'} = 'Control'; + $cs_modifier_map{'SECONDARY'} = 'Alt'; + $cs_modifier_map{'TERTIARY'} = 'Shift'; + $cs_modifier_map{'LEVEL4'} = 'Win'; + $cs_modifier_map{'WINDOW'} = 'Alt'; + $cs_modifier_map{$winkey} => 'Win'; + + $mouse_modifier_map{'PRIMARY'} = 'Ctl'; + $mouse_modifier_map{'SECONDARY'} = 'Alt'; + $mouse_modifier_map{'TERTIARY'} = 'Shift'; + $mouse_modifier_map{'LEVEL4'} = 'Win'; + $mouse_modifier_map{'WINDOW'} = 'Alt'; + $mouse_modifier_map{$winkey} => 'Win'; +} + +%keycodes = ( + 'asciicircum' => '\\verb=^=', + 'apostrophe' => '\'', + 'bracketleft' => '[', + 'bracketright' => ']', + 'braceleft' => '\\{', + 'braceright' => '\\}', + 'backslash' => '$\\backslash$', + 'slash' => '/', + 'rightanglebracket' => '>', + 'leftanglebracket' => '<', + 'ampersand' => '\\&', + 'comma' => ',', + 'period' => '.', + 'semicolon' => ';', + 'colon' => ':', + 'equal' => '=', + 'minus' => '-', + 'plus' => '+', + 'grave' => '`', + 'rightarrow' => '$\rightarrow$', + 'leftarrow' => '$\\leftarrow$', + 'uparrow' => '$\\uparrow$', + 'downarrow' => '$\\downarrow$', + 'Page_Down' => 'Page Down', + 'Page_Up' => 'Page Up', + 'space' => 'space', + 'KP_' => 'KP$\_$', + ); + +if ($merge_from) { + open (BINDINGS, $merge_from) || die ("merge from bindings: file not readable"); + while () { + next if (/^$semicolon/); + if (/^\(gtk_accel/) { + chop; # newline + chop; # closing parenthesis + s/"//g; + ($junk, $action, $binding) = split; + $merge_bindings{$action} = $binding; + } + } + close (BINDINGS); +} + +if ($make_accelmap && !$merge_from) { + print ";; this accelmap was produced by tools/fmt-bindings\n"; +} + +while (<>) { + next if /^$semicolon/; + + if (/^\$/) { + s/^\$//; + $title = $_; + next; + } + + if (/^%/) { + + if ($in_group_def) { + chop $group_text; + $group_names{$group_key} = $group_name; + $group_text{$group_key} = $group_text; + $group_numbering{$group_key} = $group_number; + # each binding entry is 2 element array. bindings + # are all collected into a container array. create + # the first dummy entry so that perl knows what we + # are doing. + $group_bindings{$group_key} = [ [] ]; + } + + s/^%//; + chop; + ($group_key,$group_name) = split (/\s+/, $_, 2); + $group_number++; + $group_text = ""; + $in_group_def = 1; + next; + } + + if ($in_group_def) { + if (/^@/) { + chop $group_text; + $group_names{$group_key} = $group_name; + $group_text{$group_key} = $group_text; + $in_group_def = 0; + } else { + next if (/^[ \t]+$/); + $group_text .= $_; + $group_text; + next; + } + } + + if (/^@/) { + s/^@//; + chop; + ($key,$action,$binding,$text) = split (/\|/, $_, 4); + + # substitute bindings + + $gtk_binding = $binding; + + if ($merge_from) { + $lookup = "/" . $action; + if ($merge_bindings{$lookup}) { + $binding = $merge_bindings{$lookup}; + } else { + if ($key =~ /^\+/) { + # forced inclusion of bindings from template + } else { + # this action is not defined in the merge from set, so forget it + next; + } + } + } + + # print the accelmap output + + if ($key =~ /^\+/) { + # remove + and don't print it in the accelmap + $key =~ s/^\+//; + } else { + # include this in the accelmap + if (!$merge_from && $make_accelmap) { + foreach $k (keys %gtk_modifier_map) { + $gtk_binding =~ s/\@$k\@/$gtk_modifier_map{$k}/; + } + print "(gtk_accel_map \"/$action\" \"$gtk_binding\")\n"; + } + } + + if ($key =~ /^-/) { + # do not include this binding in the cheat sheet + next; + } + + $bref = $group_bindings{$key}; + push (@$bref, [$binding, $text]); + + next; + } + + next; +} + +if ($make_accelmap || !$make_cheatsheet) { + exit 0; +} + +# Now print the cheatsheet + +$boilerplate_header = < $group_numbering{$b} } keys %group_numbering; + +foreach $gk (@groups_sorted_by_number) { + # $bref is a reference to the array of arrays for this group + $bref = $group_bindings{$gk}; + + if (scalar @$bref > 1) { + print "\\section{$group_names{$gk}}\n"; + + if (!($group_text{$gk} eq "")) { + print "$group_text{$gk}\n\\par\n"; + } + + # ignore the first entry, which was empty + + shift (@$bref); + + # find the longest descriptive text (this is not 100% accuracy due to typography) + + $maxtextlen = 0; + $maxtext = ""; + + for $bbref (@$bref) { + # $bbref is a reference to an array + $text = @$bbref[1]; + + # + # if there is a linebreak, just use everything up the linebreak + # to determine the width + # + + if ($text =~ /\\linebreak/) { + $matchtext = s/\\linebreak.*//; + } else { + $matchtext = $text; + } + if (length ($matchtext) > $maxtextlen) { + $maxtextlen = length ($matchtext); + $maxtext = $matchtext; + } + } + + if ($gk =~ /^m/) { + # mouse mode: don't extend max text at all - space it tight + $maxtext .= "."; + } else { + $maxtext .= "...."; + } + + # set up the table + + print "\\settowidth{\\MyLen}{\\texttt{$maxtext}}\n"; + print "\\begin{tabular}{\@{}p{\\the\\MyLen}% + \@{}p{\\linewidth-\\the\\MyLen}% + \@{}}\n"; + + # sort the array of arrays by the descriptive text for nicer appearance, + # and print them + + for $bbref (sort { @$a[1] cmp @$b[1] } @$bref) { + # $bbref is a reference to an array + + $binding = @$bbref[0]; + $text = @$bbref[1]; + + if ($binding =~ /:/) { # mouse binding with "where" clause + ($binding,$where) = split (/:/, $binding, 2); + } + + if ($gk =~ /^m/) { + # mouse mode - use shorter abbrevs + foreach $k (keys %mouse_modifier_map) { + $binding =~ s/\@$k\@/$mouse_modifier_map{$k}/; + } + } else { + foreach $k (keys %cs_modifier_map) { + $binding =~ s/\@$k\@/$cs_modifier_map{$k}/; + } + } + + $binding =~ s/>/\+/; + + # substitute keycode names for something printable + + $re = qr/${ \(join'|', map quotemeta, keys %keycodes)}/; + $binding =~ s/($re)/$keycodes{$1}/g; + + # split up mouse bindings to "click" and "where" parts + + if ($gk eq "mobject") { + print "{\\tt @$bbref[1] } & {\\tt $binding} {\\it $where}\\\\\n"; + } else { + print "{\\tt @$bbref[1] } & {\\tt $binding} \\\\\n"; + } + } + + print "\\end{tabular}\n"; + + } +} + +print $boilerplate_footer; + +exit 0; -- cgit v1.2.3