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
This commit is contained in:
parent
79b11ba619
commit
75a80ae378
7
Makefile
7
Makefile
@ -8,7 +8,7 @@ endif
|
|||||||
|
|
||||||
TARGET := anaglym
|
TARGET := anaglym
|
||||||
COBJS := $(patsubst %.c,%.o,$(wildcard *.c))
|
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)
|
OBJS := $(COBJS) $(CXXOBJS)
|
||||||
CDEPS := $(COBJS:.o=.dep)
|
CDEPS := $(COBJS:.o=.dep)
|
||||||
CXXDEPS := $(CXXOBJS:.o=.dep)
|
CXXDEPS := $(CXXOBJS:.o=.dep)
|
||||||
@ -72,6 +72,11 @@ TextureCache/TextureCache.o:
|
|||||||
%.o: %.cc
|
%.o: %.cc
|
||||||
$(CXX) -c -o $@ $(CPPFLAGS) $(CXXFLAGS) $<
|
$(CXX) -c -o $@ $(CPPFLAGS) $(CXXFLAGS) $<
|
||||||
|
|
||||||
|
sdl_keymap.o: sdl_keymap.cc
|
||||||
|
|
||||||
|
sdl_keymap.cc: gen-sdl-keymap.pl
|
||||||
|
perl $<
|
||||||
|
|
||||||
# Make dependency files
|
# Make dependency files
|
||||||
%.dep: %.c
|
%.dep: %.c
|
||||||
@set -e; rm -f $@; \
|
@set -e; rm -f $@; \
|
||||||
|
58
gen-sdl-keymap.pl
Executable file
58
gen-sdl-keymap.pl
Executable file
@ -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 <<EOP;
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
|
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 <<EOP;
|
||||||
|
|
||||||
|
#ifndef SDL_KEYMAP_H
|
||||||
|
#define SDL_KEYMAP_H
|
||||||
|
|
||||||
|
extern char * sdl_keymap[SDLK_LAST+1];
|
||||||
|
|
||||||
|
#endif
|
||||||
|
EOP
|
||||||
|
close($output_h);
|
||||||
|
}
|
||||||
|
|
||||||
|
exit(0);
|
Loading…
x
Reference in New Issue
Block a user