From 75a80ae3780483139549dbde692145d7f460b68b Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 18 Oct 2009 21:46:53 +0000 Subject: [PATCH] added gen-sdl-keymap.pl to generate sdl_keymap.h and sdl_keymap.cc git-svn-id: svn://anubis/anaglym/trunk@96 99a6e188-d820-4881-8870-2d33a10e2619 --- Makefile | 7 +++++- gen-sdl-keymap.pl | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100755 gen-sdl-keymap.pl diff --git a/Makefile b/Makefile index 3842e1c..2914afe 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ endif TARGET := anaglym COBJS := $(patsubst %.c,%.o,$(wildcard *.c)) -CXXOBJS := $(patsubst %.cc,%.o,$(wildcard *.cc)) +CXXOBJS := $(subst sdl_keymap.o,,$(patsubst %.cc,%.o,$(wildcard *.cc))) sdl_keymap.o OBJS := $(COBJS) $(CXXOBJS) CDEPS := $(COBJS:.o=.dep) CXXDEPS := $(CXXOBJS:.o=.dep) @@ -72,6 +72,11 @@ TextureCache/TextureCache.o: %.o: %.cc $(CXX) -c -o $@ $(CPPFLAGS) $(CXXFLAGS) $< +sdl_keymap.o: sdl_keymap.cc + +sdl_keymap.cc: gen-sdl-keymap.pl + perl $< + # Make dependency files %.dep: %.c @set -e; rm -f $@; \ diff --git a/gen-sdl-keymap.pl b/gen-sdl-keymap.pl new file mode 100755 index 0000000..4592802 --- /dev/null +++ b/gen-sdl-keymap.pl @@ -0,0 +1,58 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +my $sdl_config_out = `sdl-config --cflags`; +if ($sdl_config_out =~ /-I(\S+)\s/) +{ + my $sdl_path = $1; + open(my $fh, '<', "$sdl_path/SDL_keysym.h"); + + my %keys; + while (my $line = <$fh>) + { + if ($line =~ /SDLK_(\S+)\s*=\s*(\d+)/) + { + my $keyname = lc($1); + my $keynum = $2; + $keys{$keynum} = $keyname; + } + } + close($fh); + + open(my $output, '>', 'sdl_keymap.cc'); + print $output < + +const char * sdl_keymap[SDLK_LAST+1] = { +EOP + + my $current_id = 0; + for my $id (sort { $a <=> $b } keys(%keys)) + { + while ($current_id < $id) + { + printf $output " %-20s, /* %d */\n", '""', $current_id++; + } + printf $output " %-20s, /* %d */\n", '"' . $keys{$id} . '"', $id; + $current_id++; + } + print $output " \"last\"\n};\n"; + close($output); + + open(my $output_h, '>', 'sdl_keymap.h'); + print $output_h <