[darwin] changed, replace wrapping with wrapper.rb with linker alias_list
authorS. Davilla <davilla@4pi.com>
Wed, 9 Mar 2011 05:04:18 +0000 (00:04 -0500)
committerS. Davilla <davilla@4pi.com>
Wed, 9 Mar 2011 05:23:03 +0000 (00:23 -0500)
41 files changed:
lib/Makefile.in
lib/cximage-6.0/Makefile.in
lib/libass/xbmc/Makefile.in
lib/libdvd/Makefile.in
lib/libexif/Makefile.in
lib/libflac/Makefile.in
lib/libhdhomerun/Makefile.in
lib/libid3tag/Makefile.in
lib/libsidplay2/Makefile.in
lib/libsquish/Makefile.in
lib/nosefart/Makefile.in
lib/snesapu/SNES/SNESAPU/Makefile.in
lib/stsound/StSoundLibrary/Makefile.in
lib/timidity/Makefile.in
lib/vgmstream/Makefile.in
lib/win32/libwavpack/Makefile.in
lib/xbadpcm/Makefile.in
tools/Mach5/Makefile [deleted file]
tools/Mach5/bit-struct.rb [deleted file]
tools/Mach5/bit-struct/bit-struct.rb [deleted file]
tools/Mach5/bit-struct/char-field.rb [deleted file]
tools/Mach5/bit-struct/float-field.rb [deleted file]
tools/Mach5/bit-struct/hex-octet-field.rb [deleted file]
tools/Mach5/bit-struct/nested-field.rb [deleted file]
tools/Mach5/bit-struct/octet-field.rb [deleted file]
tools/Mach5/bit-struct/pad-field.rb [deleted file]
tools/Mach5/bit-struct/signed-field.rb [deleted file]
tools/Mach5/bit-struct/text-field.rb [deleted file]
tools/Mach5/bit-struct/unsigned-field.rb [deleted file]
tools/Mach5/bit-struct/yaml.rb [deleted file]
tools/Mach5/mach5.rb [deleted file]
tools/Mach5/wrapper.rb [deleted file]
xbmc/cores/DllLoader/exports/Makefile
xbmc/cores/DllLoader/exports/wrapper.c
xbmc/cores/DllLoader/exports/wrapper_mach_alias [new file with mode: 0644]
xbmc/interfaces/python/linux/Makefile.in
xbmc/visualizations/Goom/Makefile.in
xbmc/visualizations/OpenGLSpectrum/Makefile.in
xbmc/visualizations/WaveForm/Makefile.in
xbmc/visualizations/XBMCProjectM/Makefile.in
xbmc/visualizations/iTunes/Makefile.in

index 2e5bc6d..038895b 100644 (file)
@@ -1,11 +1,23 @@
+ARCH=@ARCH@
+SYSROOT=@SYSROOT@
+
+LD=@LD@
 CC=@CC@
 CXX=@CXX@
 SHELL=@SHELL@
+ifeq ($(findstring osx,$(ARCH)),osx)
+ifeq ($(findstring arm,$(ARCH)),arm)
+LDFLAGS=-arch armv7 -iphoneos_version_min 4.1 -bundle -undefined dynamic_lookup -read_only_relocs suppress
+else
+LDFLAGS=-bundle -undefined dynamic_lookup -read_only_relocs suppress
+endif
+else
 LDFLAGS=-shared -fPIC -rdynamic
-ARCH=@ARCH@
+endif
 SYSDIR=@abs_top_srcdir@/system/players/dvdplayer
 WRAPPER=@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o
-WRAPPER_OSX=@abs_top_srcdir@/tools/Mach5/wrapper.rb
+WRAPPER_MACH_ALIAS=@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper_mach_alias
+
 DIRS=
 ifneq (@USE_EXTERNAL_FFMPEG@,1)
   DIRS+=ffmpeg
@@ -24,7 +36,7 @@ endif
 ifneq (,$(findstring powerpc,$(ARCH)))
   ARCH_DIR=ppc
 else
-ifeq ($(ARCH), arm)
+ifeq ($(findstring arm,$(ARCH)),arm)
   ARCH_DIR=arm
 else
   ARCH_DIR=x86
@@ -42,43 +54,37 @@ ifeq ($(ARCH), powerpc-osx)
 BUNDLE1_O = -lbundle1.o
 endif
 
-$(SYSDIR)/avutil-50-$(ARCH).so: ffmpeg/libavutil/libavutil.dylib
-       $(CC) -bundle -flat_namespace -undefined suppress -read_only_relocs suppress -o $@ \
-               ffmpeg/libavutil/*.o \
+$(SYSDIR)/avutil-50-$(ARCH).so: $(WRAPPER) ffmpeg/libavutil/libavutil.dylib
+       $(LD) $(LDFLAGS) -alias_list $(WRAPPER_MACH_ALIAS) -o $@ \
+               $(WRAPPER) ffmpeg/libavutil/*.o \
                ffmpeg/libavutil/$(ARCH_DIR)/*.o
-       $(WRAPPER_OSX) $@;mv output.so $@
-       chmod +x $@
 
-$(SYSDIR)/avcodec-52-$(ARCH).so: ffmpeg/libavcodec/libavcodec.dylib
-       $(CC) -bundle -flat_namespace -undefined suppress -read_only_relocs suppress -o $@ \
-               ffmpeg/libavcodec/*.o \
+$(SYSDIR)/avcodec-52-$(ARCH).so: $(WRAPPER) ffmpeg/libavcodec/libavcodec.dylib
+       $(LD) $(LDFLAGS) -alias_list $(WRAPPER_MACH_ALIAS) -o $@ \
+               $(WRAPPER) ffmpeg/libavcodec/*.o \
                ffmpeg/libavcodec/$(ARCH_DIR)/*.o
-       $(WRAPPER_OSX) $@;mv output.so $@
-       chmod +x $@
-
-$(SYSDIR)/avcore-0-$(ARCH).so: ffmpeg/libavcore/libavcore.dylib
-       $(CC) -bundle -flat_namespace -undefined suppress -read_only_relocs suppress -o $@ \
-               ffmpeg/libavcore/*.o
-       $(WRAPPER_OSX) $@;mv output.so $@
-       chmod +x $@
-
-$(SYSDIR)/avformat-52-$(ARCH).so: ffmpeg/libavformat/libavformat.dylib
-       $(CC) -bundle -flat_namespace -undefined suppress -read_only_relocs suppress -o $@ \
-               ffmpeg/libavformat/*.o
-       $(WRAPPER_OSX) $@;mv output.so $@
-       chmod +x $@
-
-$(SYSDIR)/swscale-0-$(ARCH).so: ffmpeg/libswscale/libswscale.dylib
-       $(CC) -bundle -flat_namespace -undefined suppress -read_only_relocs suppress -o $@ \
-               ffmpeg/libswscale/*.o ffmpeg/libswscale/$(ARCH_DIR)/*.o
-       $(WRAPPER_OSX) $@;mv output.so $@
-       chmod +x $@
-
-$(SYSDIR)/postproc-51-$(ARCH).so: ffmpeg/libpostproc/libpostproc.dylib
-       $(CC) -bundle -flat_namespace -undefined suppress -read_only_relocs suppress -o $@ \
-               ffmpeg/libpostproc/*.o
-       $(WRAPPER_OSX) $@;mv output.so $@
-       chmod +x $@
+
+$(SYSDIR)/avcore-0-$(ARCH).so: $(WRAPPER) ffmpeg/libavcore/libavcore.dylib
+       $(LD) $(LDFLAGS) -alias_list $(WRAPPER_MACH_ALIAS)  -o $@ \
+               $(WRAPPER) ffmpeg/libavcore/*.o
+
+$(SYSDIR)/avformat-52-$(ARCH).so: $(WRAPPER) ffmpeg/libavformat/libavformat.dylib
+       $(LD) $(LDFLAGS) -alias_list $(WRAPPER_MACH_ALIAS)  -o $@ \
+               $(WRAPPER) ffmpeg/libavformat/*.o
+
+ifneq ($(findstring arm,$(ARCH)), arm)
+$(SYSDIR)/swscale-0-$(ARCH).so: $(WRAPPER) ffmpeg/libswscale/libswscale.dylib
+       $(LD) $(LDFLAGS) -alias_list $(WRAPPER_MACH_ALIAS)  -o $@ \
+               $(WRAPPER) ffmpeg/libswscale/*.o ffmpeg/libswscale/$(ARCH_DIR)/*.o
+else # No ARM version of swscale available yet.
+$(SYSDIR)/swscale-0-$(ARCH).so: $(WRAPPER) ffmpeg/libswscale/libswscale.dylib
+       $(LD) $(LDFLAGS) -alias_list $(WRAPPER_MACH_ALIAS)  -o $@ \
+               $(WRAPPER) ffmpeg/libswscale/*.o
+endif
+
+$(SYSDIR)/postproc-51-$(ARCH).so: $(WRAPPER) ffmpeg/libpostproc/libpostproc.dylib
+       $(LD) $(LDFLAGS) -alias_list $(WRAPPER_MACH_ALIAS)  -o $@ \
+               $(WRAPPER) ffmpeg/libpostproc/*.o
 
 ffmpeg/libavutil/libavutil.dylib     : ffmpeg;
 ffmpeg/libavcodec/libavcodec.dylib   : ffmpeg;
index 0267df0..9ad358a 100644 (file)
@@ -9,6 +9,7 @@ SLIBS=CxImage/cximage.a raw/raw.a jbig/jbig.a
 
 ifeq ($(findstring osx,$(ARCH)), osx)
        export ARCH
+       export SYSROOT
        DIRS+=jasper
        SLIBS+=jasper/jasper.a
 endif
@@ -17,10 +18,9 @@ endif
 
 $(SLIB): $(SLIBS)
 ifeq ($(findstring osx,$(ARCH)), osx)
-       $(CXX) $(LDFLAGS) -bundle -flat_namespace -undefined suppress -shared -lpng -ljpeg -ltiff -lz -o $@ \
-               CxImage/*.o jasper/*/*.o jbig/*.o raw/*.o
-       ../../tools/Mach5/wrapper.rb $@;mv output.so $@
-       chmod +x $@
+       $(CXX) $(LDFLAGS) -Wl,-alias_list,@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper_mach_alias \
+       -bundle -undefined dynamic_lookup -read_only_relocs suppress -lpng -ljpeg -ltiff -lz -o $@ \
+       @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o CxImage/*.o jasper/*/*.o jbig/*.o raw/*.o
 else
        $(CXX) $(CFLAGS) $(LDFLAGS) -shared -o $(SLIB) -Wl,--whole-archive $(SLIBS) \
                -Wl,--no-whole-archive -lpng -ljasper -ljpeg -ltiff -lz \
index c6acb05..13726e7 100644 (file)
@@ -1,6 +1,8 @@
 abs_top_srcdir=@abs_top_srcdir@
 
 ARCH=@ARCH@
+SYSROOT=@SYSROOT@
+
 SYSDIR=$(abs_top_srcdir)/system/players/dvdplayer
 SO=libass-$(ARCH).so
 SLIB=$(SYSDIR)/$(SO)
@@ -10,13 +12,11 @@ DIRS=..
 
 ifeq ($(findstring osx,$(ARCH)), osx)
 $(SLIB): ../libass/.libs/libass.dylib
-       $(CXX) $(LDFLAGS) -bundle -flat_namespace -undefined suppress -shared -fPIC \
-       -lfontconfig -o $@ ../libass/.libs/*.o
-       $(abs_top_srcdir)/tools/Mach5/wrapper.rb $@;mv output.so $@
-       chmod +x $@
+       $(CC) $(SYSROOT) $(LDFLAGS) -Wl,-alias_list,@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper_mach_alias \
+               -bundle -undefined dynamic_lookup -read_only_relocs suppress -lfontconfig -o $@ \
+               @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o ../libass/.libs/*.o
 
 ../libass/.libs/libass.dylib: compile
-       export MACOSX_DEPLOYMENT_TARGET=10.4
        $(MAKE) -C ..
 else
 $(SLIB): ../libass/.libs/libass.so
index e7910da..91df03e 100644 (file)
@@ -1,14 +1,23 @@
 
 ARCH=@ARCH@
+SYSROOT=@SYSROOT@
+CC=@CC@
+CXX=@CXX@
+
 SYSDIR=@abs_top_srcdir@/system/players/dvdplayer
 SOS= libdvdnav-$(ARCH).so
 DIRS=  libdvdread \
        libdvdnav
 
 WRAPPER=@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o
-WRAPPER_OSX=@abs_top_srcdir@/tools/Mach5/wrapper.rb
+WRAPPER_MACH_ALIAS=@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper_mach_alias
 
+ifeq ($(findstring osx,$(ARCH)),osx)
+LDFLAGS +=-bundle -undefined dynamic_lookup -read_only_relocs suppress
+else
 LDFLAGS += -shared -fPIC -rdynamic
+endif
+
 ifeq ($(ARCH), powerpc-osx)
        # Add -lbundle1.o for powerpc-osx
        BUNDLE1_O = -lbundle1.o
@@ -36,15 +45,13 @@ all: $(SLIB)
 
 ifeq ($(findstring osx,$(ARCH)), osx)
 
-$(SYSDIR)/libdvdcss-$(ARCH).so:  $(WRAPPER_OSX) libdvdcss/src/.libs/libdvdcss.a
-       ld -bundle -flat_namespace -undefined suppress -o $@ \
-               libdvdcss/src/*.o $(BUNDLE1_O)
-       $(WRAPPER_OSX) $@;mv output.so $@
+$(SYSDIR)/libdvdcss-$(ARCH).so:  $($(WRAPPER)) libdvdcss/src/.libs/libdvdcss.a
+       $(CC) $(SYSROOT) $(LDFLAGS) -Wl,-alias_list,$(WRAPPER_MACH_ALIAS) -o $@ \
+               $(WRAPPER) libdvdcss/src/*.o $(BUNDLE1_O)
 
-$(SYSDIR)/libdvdnav-$(ARCH).so: $(WRAPPER_OSX) $(DVDCSS_A) libdvdread/obj/libdvdread.a libdvdnav/obj/libdvdnav.a
-       ld -bundle -flat_namespace -undefined suppress -o $@ \
-               $(DVDCSS_O) libdvdread/obj/*.o libdvdnav/obj/*.o $(BUNDLE1_O)
-       $(WRAPPER_OSX) $@;mv output.so $@
+$(SYSDIR)/libdvdnav-$(ARCH).so: $($(WRAPPER)) $(DVDCSS_A) libdvdread/obj/libdvdread.a libdvdnav/obj/libdvdnav.a
+       $(CC) $(SYSROOT) $(LDFLAGS) -Wl,-alias_list,$(WRAPPER_MACH_ALIAS) -o $@ \
+               $(WRAPPER) $(DVDCSS_O) libdvdread/obj/*.o libdvdnav/obj/*.o $(BUNDLE1_O)
 
 else
 
index 7e3d3e9..292bc4b 100644 (file)
@@ -10,8 +10,9 @@ SLIB=@abs_top_srcdir@/system/$(SO)
 
 $(SLIB): $(OBJS)
 ifeq ($(findstring osx,$(ARCH)), osx)
-       $(CXX) $(CFLAGS) -bundle -flat_namespace -undefined suppress -shared -fPIC -o $@ $(OBJS)
-       @abs_top_srcdir@/tools/Mach5/wrapper.rb $@;mv output.so $@
+       $(CXX) $(LDFLAGS) -Wl,-alias_list,@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper_mach_alias \
+               -bundle -undefined dynamic_lookup -read_only_relocs suppress -o $@ \
+               @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o $(OBJS)
 else
        $(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $@ $(OBJS) \
                `cat @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.def` @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o
index 5ee0dbd..613c796 100644 (file)
@@ -12,10 +12,9 @@ all: $(FLAC_LIB)
 
 ifeq ($(findstring osx,$(ARCH)), osx)
 $(FLAC_LIB): flac-1.2.1/src/libFLAC/.libs/libFLAC.a
-       $(CC) -bundle -flat_namespace -undefined suppress -shared -fPIC \
-       -mmacosx-version-min=10.4 -o $@ flac-1.2.1/src/libFLAC/.libs/*.o
-       @abs_top_srcdir@/tools/Mach5/wrapper.rb $@;mv output.so $@
-       chmod +x $@
+       $(CC) $(SYSROOT) $(LDFLAGS) -bundle -undefined dynamic_lookup -read_only_relocs suppress -fPIC \
+       -Wl,-alias_list,@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper_mach_alias -o $@ \
+       @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o flac-1.2.1/src/libFLAC/.libs/*.o
 else
 ifneq (@USE_EXTERNAL_LIBFLAC@,1)
 $(FLAC_LIB): flac-1.2.1/src/libFLAC/.libs/libFLAC.a
index 513ece1..e447aca 100644 (file)
@@ -10,10 +10,6 @@ OBJS += hdhomerun_video.o
 OBJS += hdhomerun_device.o
 
 CFLAGS += -Wall -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wpointer-arith -fPIC
-ifeq ($(findstring osx,$(ARCH)), osx)
-       CFLAGS +=-isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4
-       LDFLAGS +=-isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4
-endif
 
 SLIBS += -lws2_32
 DEFINES += -D__MINGW__
@@ -24,9 +20,9 @@ SLIB=$(SYSDIR)/$(SO)
 
 $(SLIB): $(OBJS)
 ifeq ($(findstring osx,$(ARCH)), osx)
-       $(CC) $(OBJS) -bundle -flat_namespace -undefined suppress -shared -o $@
-       @abs_top_srcdir@/tools/Mach5/wrapper.rb $@;mv output.so $@
-       chmod +x $@
+       $(CC) $(LDFLAGS) -Wl,-alias_list,@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper_mach_alias \
+               -bundle -undefined dynamic_lookup -read_only_relocs suppress -o $@ \
+               @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o $(OBJS)
 else
        $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -shared -o $@ `cat @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.def` \
                @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o
index a334833..dba5b87 100644 (file)
@@ -10,9 +10,9 @@ CLEAN_FILES=libid3tag/compat.c libid3tag/frametype.c
 
 ifeq ($(findstring osx,$(ARCH)), osx)
 $(SLIB): libid3tag/.libs/libid3tag.dylib
-       $(CXX) $(CFLAGS) -bundle -flat_namespace -undefined suppress -shared -fPIC \
-               -o $@ libid3tag/.libs/*.o
-       ../../tools/Mach5/wrapper.rb $@;mv output.so $@
+       $(CXX) $(LDFLAGS) -Wl,-alias_list,@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper_mach_alias \
+               -bundle -undefined dynamic_lookup -read_only_relocs suppress -fPIC -o $@ \
+               @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o libid3tag/.libs/*.o
        chmod +x $@
 else
 $(SLIB): libid3tag/.libs/libid3tag.so
index dddbf22..eddf8cb 100644 (file)
@@ -1,4 +1,5 @@
 ARCH=@ARCH@
+SYSROOT=@SYSROOT@
 
 CFLAGS +=-D_LINUX -DHAVE_UNIX -DHAVE_STRCASECMP -DHAVE_STRNCASECMP \
          -DHAVE_IOS_OPENMODE -fPIC -Ilibsidplay/win/VC \
@@ -53,10 +54,9 @@ SLIB=@abs_top_srcdir@/system/players/paplayer/libsidplay2-@ARCH@.so
 
 $(SLIB): $(OBJS) @abs_top_srcdir@/xbmc/linux/XHandle.o
 ifeq ($(findstring osx,$(ARCH)), osx)
-       ld -bundle -flat_namespace -undefined suppress -o $@ \
-               $(OBJS) @abs_top_srcdir@/xbmc/linux/XHandle.o $(BUNDLE1_O)
-       @abs_top_srcdir@/tools/Mach5/wrapper.rb $@;mv output.so $@
-       chmod +x $@
+       $(CXX) $(SYSROOT) -Wl,-alias_list,@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper_mach_alias \
+               -bundle -undefined dynamic_lookup -read_only_relocs suppress -o $@ \
+               @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o $(OBJS) @abs_top_srcdir@/xbmc/linux/XHandle.o $(BUNDLE1_O)
 else
        $(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $@ $(OBJS) @abs_top_srcdir@/xbmc/linux/XHandle.o `cat @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.def` @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o
 endif
index e7d20da..c562c83 100644 (file)
@@ -5,7 +5,7 @@ SRCS=alpha.cpp clusterfit.cpp colourblock.cpp colourfit.cpp colourset.cpp maths.
 ifeq ($(findstring powerpc,$(ARCH)),powerpc)
 CXXFLAGS+=-I. -DSQUISH_USE_ALTIVEC=1 -maltivec
 else
-ifeq ($(ARCH),arm)
+ifeq ($(findstring arm,$(ARCH)), arm)
 CXXFLAGS+=-I.
 else
 CXXFLAGS+=-I. -DSQUISH_USE_SSE=2 -msse2
index ed17cb5..2d0fe71 100644 (file)
@@ -1,4 +1,5 @@
 ARCH=@ARCH@
+SYSROOT=@SYSROOT@
 
 CFLAGS +=-D_LINUX -fPIC -DNSF_PLAYER
 CXXFLAGS +=-D_LINUX -fPIC -DNSF_PLAYER
@@ -27,9 +28,9 @@ SLIB=@abs_top_srcdir@/system/players/paplayer/nosefart-@ARCH@.so
 
 $(SLIB): $(OBJS)
 ifeq ($(findstring osx,$(ARCH)), osx)
-       ld -bundle -flat_namespace -undefined suppress -o $@ $(OBJS) $(BUNDLE1_O)
-       @abs_top_srcdir@/tools/Mach5/wrapper.rb $@;mv output.so $@
-       chmod +x $@
+       $(CC) $(SYSROOT) -Wl,-alias_list,@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper_mach_alias \
+       -bundle -undefined dynamic_lookup -read_only_relocs suppress -o $@ \
+       @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o $(OBJS) $(BUNDLE1_O)
 else
        $(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $(OBJS) `cat @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.def` @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o
 endif
index 40494dc..e7ade0b 100644 (file)
@@ -17,13 +17,9 @@ SLIB=$(SYSDIR)/$(SO)
 
 $(SLIB): $(OBJS)
 ifeq ($(findstring osx,$(ARCH)), osx)
-       $(CC) -bundle -undefined dynamic_lookup  \
-               -isysroot /Developer/SDKs/MacOSX10.4u.sdk \
-               -mmacosx-version-min=10.4 \
-               -read_only_relocs suppress \
-               -o $@ $(OBJS)
-       @abs_top_srcdir@/tools/Mach5/wrapper.rb $@;mv output.so $@
-       chmod +x $@
+       $(CC) $(LDFLAGS) -Wl,-alias_list,@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper_mach_alias \
+               -bundle -undefined dynamic_lookup -read_only_relocs suppress -o $@ \
+               @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o $(OBJS)
 else
        $(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $@ $(OBJS) \
                `cat @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.def` @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o
index 6f0b5ed..b75fda3 100644 (file)
@@ -1,4 +1,5 @@
 ARCH=@ARCH@
+SYSROOT=@SYSROOT@
 
 CFLAGS +=-D_LINUX -fPIC
 CXXFLAGS +=-D_LINUX -fPIC
@@ -20,9 +21,9 @@ SLIB=@abs_top_srcdir@/system/players/paplayer/stsoundlibrary-@ARCH@.so
 
 $(SLIB): $(OBJS)
 ifeq ($(findstring osx,$(ARCH)), osx)
-       ld -bundle -flat_namespace -undefined suppress -o $@ $(OBJS) $(BUNDLE1_O)
-       @abs_top_srcdir@/tools/Mach5/wrapper.rb $@;mv output.so $@
-       chmod +x $@
+       $(CXX) $(SYSROOT) -Wl,-alias_list,@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper_mach_alias \
+       -bundle -undefined dynamic_lookup -read_only_relocs suppress -o $@ \
+       @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o $(OBJS) $(BUNDLE1_O)
 else
        $(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $@ $(OBJS) `cat @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.def` @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o
 endif
index d60e543..fa9f208 100644 (file)
@@ -1,4 +1,5 @@
 ARCH=@ARCH@
+SYSROOT=@SYSROOT@
 
 CFLAGS+=-D_LINUX -fPIC -DHAVE_GETTIMEOFDAY -I. -Itimidity -Ilibarc -Iutils
 ifeq ($(ARCH), powerpc-osx)
@@ -53,9 +54,8 @@ SLIB=@abs_top_srcdir@/system/players/paplayer/timidity-@ARCH@.so
 
 $(SLIB): $(OBJS) exports.def
 ifeq ($(findstring osx,$(ARCH)), osx)
-       ld -bundle -undefined dynamic_lookup -o $@ $(OBJS) $(BUNDLE1_O)
-       @abs_top_srcdir@/tools/Mach5/wrapper.rb $@;mv output.so $@
-       chmod +x $@
+       $(CXX) $(SYSROOT) -Wl,-alias_list,@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper_mach_alias -bundle \
+       -undefined dynamic_lookup -read_only_relocs suppress -o $@ @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o $(OBJS) $(BUNDLE1_O)
 else
        $(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $@ $(OBJS) `cat @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.def` @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o -Wl,--version-script=exports.def
 endif
index 9db00ba..0d5cfad 100644 (file)
@@ -1,8 +1,9 @@
 ARCH=@ARCH@
+SYSROOT=@SYSROOT@
 
 ifeq ($(findstring osx,$(ARCH)), osx)
-       CFLAGS +=-D_LINUX -fPIC -DPIC -O3 -DXBMC
-       CXXFLAGS +=-D_LINUX -fPIC -DPIC -O3 -DXBMC
+       CFLAGS +=-fms-extensions -D_LINUX -O3 -DXBMC
+       CXXFLAGS +=-fms-extensions -D_LINUX -O3 -DXBMC
 else
        CFLAGS +=-D_LINUX -fPIC -DXBMC
        CXXFLAGS +=-D_LINUX -fPIC -DXBMC
@@ -195,9 +196,9 @@ SLIB=@abs_top_srcdir@/system/players/paplayer/vgmstream-@ARCH@.so
 
 $(SLIB): $(OBJS)
 ifeq ($(findstring osx,$(ARCH)), osx)
-       ld -bundle -flat_namespace -undefined suppress -o $@ $(OBJS) $(BUNDLE1_O)
-       @abs_top_srcdir@/tools/Mach5/wrapper.rb $@;mv output.so $@
-       chmod +x $@
+       $(CXX) $(SYSROOT) -Wl,-alias_list,@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper_mach_alias \
+       -bundle -undefined dynamic_lookup -read_only_relocs suppress  -o $@ \
+       @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o $(OBJS) $(BUNDLE1_O)
 else
        $(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $@ $(OBJS) `cat @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.def` @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o
 
index fc48807..2ff7356 100644 (file)
@@ -10,9 +10,9 @@ SLIB=../../../../system/players/paplayer/wavpack-@ARCH@.so
 
 $(SLIB): $(OBJS)
 ifeq ($(findstring osx,$(ARCH)), osx)
-       ld -bundle -flat_namespace -undefined suppress -o $@ $(OBJS) $(BUNDLE1_O)
-       ../../../../tools/Mach5/wrapper.rb $@;mv output.so $@
-       chmod +x $@
+       $(CC) $(LDFLAGS) -Wl,-alias_list,@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper_mach_alias \
+               -bundle -undefined dynamic_lookup -read_only_relocs suppress -o $@
+               @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o  $(OBJS) $(BUNDLE1_O)
 else
        $(CC) $(CFLAGS) -shared -o $@ $(OBJS) `cat ../../DllLoader/exports/wrapper.def` ../../DllLoader/exports/wrapper.o
 endif
index 0cda9eb..20807fd 100644 (file)
@@ -1,4 +1,5 @@
 ARCH=@ARCH@
+SYSROOT=@SYSROOT@
 OBJS=uXboxAdpcmDecoder.o ADPCMDll.o
 CFLAGS +=-D_LINUX -fPIC
 CXXFLAGS += -D_LINUX -fPIC
@@ -7,8 +8,9 @@ SLIB=@abs_top_srcdir@/system/players/paplayer/adpcm-@ARCH@.so
 
 $(SLIB): $(OBJS)
 ifeq ($(findstring osx,$(ARCH)), osx)
-       ld -bundle -flat_namespace -undefined suppress -o $@ *.o $(BUNDLE1_O)
-       @abs_top_srcdir@/tools/Mach5/wrapper.rb $@;mv output.so $@
+       $(CC) $(SYSROOT) -Wl,-alias_list,@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper_mach_alias \
+       -bundle -undefined dynamic_lookup -read_only_relocs suppress -o $@ \
+       @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o *.o $(BUNDLE1_O)
        chmod +x $@
 else
        $(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ *.o `cat @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.def` @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o
diff --git a/tools/Mach5/Makefile b/tools/Mach5/Makefile
deleted file mode 100644 (file)
index c134f13..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-default:
-
-python: ../../xbmc/lib/libPython/Python/python24-osx.so
-       ./mach5.rb $<
-       ./mach5.rb output.so libpython
diff --git a/tools/Mach5/bit-struct.rb b/tools/Mach5/bit-struct.rb
deleted file mode 100644 (file)
index ea2e17d..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-# A Convenience to load all field classes and yaml handling.
-
-require 'bit-struct/unsigned-field'
-require 'bit-struct/signed-field'
-require 'bit-struct/octet-field'
-require 'bit-struct/hex-octet-field'
-require 'bit-struct/char-field'
-require 'bit-struct/text-field'
-require 'bit-struct/nested-field'
-require 'bit-struct/float-field'
-require 'bit-struct/pad-field'
-require 'bit-struct/yaml'
diff --git a/tools/Mach5/bit-struct/bit-struct.rb b/tools/Mach5/bit-struct/bit-struct.rb
deleted file mode 100644 (file)
index 27af66b..0000000
+++ /dev/null
@@ -1,515 +0,0 @@
-# Class for packed binary data, with defined bitfields and accessors for them.
-# See {intro.txt}[link:../doc/files/intro_txt.html] for an overview.
-#
-# Data after the end of the defined fields is accessible using the +rest+
-# declaration. See examples/ip.rb. Nested fields can be declared using +nest+.
-# See examples/nest.rb.
-#
-# Note that all string methods are still available: length, grep, etc.
-# The String#replace method is useful.
-#
-class BitStruct < String
-
-  class Field
-    # Offset of field in bits.
-    attr_reader :offset
-    
-    # Length of field in bits.
-    attr_reader :length
-    alias size length
-    
-    # Name of field (used for its accessors).
-    attr_reader :name
-    
-    # Options, such as :default (varies for each field subclass).
-    # In general, options can be provided as strings or as symbols.
-    attr_reader :options
-    
-    # Display name of field (used for printing).
-    attr_reader :display_name
-    
-    # Default value.
-    attr_reader :default
-    
-    # Format for printed value of field.
-    attr_reader :format
-    
-    # Subclasses can override this to define a default for all fields of this
-    # class, not just the one currently being added to a BitStruct class, a
-    # "default default" if you will. The global default, if #default returns
-    # nil, is to fill the field with zero. Most field classes just let this
-    # default stand. The default can be overridden per-field when a BitStruct
-    # class is defined.
-    def self.default; nil; end
-
-    # Used in describe.
-    def self.class_name
-      @class_name ||= name[/\w+$/]
-    end
-    
-    # Used in describe. Can be overridden per-subclass, as in NestedField.
-    def class_name
-      self.class.class_name
-    end
-
-    # Yield the description of this field, as an array of 5 strings: byte
-    # offset, type, name, size, and description. The opts hash may have:
-    #
-    # :expand ::  if the value is true, expand complex fields
-    #
-    # (Subclass implementations may yield more than once for complex fields.)
-    #
-    def describe opts
-      bits = size
-      if bits > 32 and bits % 8 == 0
-        len_str = "%dB" % (bits/8)
-      else
-        len_str = "%db" % bits
-      end
-      
-      byte_offset = offset / 8 + (opts[:byte_offset] || 0)
-
-      yield ["@%d" % byte_offset, class_name, name, len_str, display_name]
-    end
-
-    # Options are _display_name_, _default_, and _format_ (subclasses of Field
-    # may add other options).
-    def initialize(offset, length, name, opts = {})
-      @offset, @length, @name, @options =
-        offset, length, name, opts
-      
-      @display_name = opts[:display_name] || opts["display_name"]
-      @default      = opts[:default] || opts["default"] || self.class.default
-      @format       = opts[:format] || opts["format"]
-    end
-    
-    # Inspect the value of this field in the specified _obj_.
-    def inspect_in_object(obj, opts)
-      val = obj.send(name)
-      str =
-        begin
-          val.inspect(opts)
-        rescue ArgumentError # assume: "wrong number of arguments (1 for 0)"
-          val.inspect
-        end
-      (f=@format) ? (f % str) : str
-    end
-    
-    # Normally, all fields show up in inspect, but some, such as padding,
-    # should not.
-    def inspectable?; true; end
-  end
-  
-  NULL_FIELD = Field.new(0, 0, :null, :display_name => "null field")
-  
-  # Raised when a field is added after an instance has been created. Fields
-  # cannot be added after this point.
-  class ClosedClassError < StandardError; end
-
-  # Raised if the chosen field name is not allowed, either because another
-  # field by that name exists, or because a method by that name exists.
-  class FieldNameError < StandardError; end
-  
-  @default_options = {}
-    
-  class << self
-    # ------------------------
-    # :section: field access methods
-    #
-    # For introspection and metaprogramming.
-    #
-    # ------------------------
-
-    # Return the list of fields for this class.
-    def fields
-      @fields ||= self == BitStruct ? [] : superclass.fields.dup
-    end
-    
-    # Return the list of fields defined by this class, not inherited
-    # from the superclass.
-    def own_fields
-      @own_fields ||= []
-    end
-
-    # Add a field to the BitStruct (usually, this is only used internally).
-    def add_field(name, length, opts = {})
-      round_byte_length ## just to make sure this has been calculated
-      ## before adding anything
-      
-      name = name.to_sym
-      
-      if @closed
-        raise ClosedClassError, "Cannot add field #{name}: " +
-          "The definition of the #{self.inspect} BitStruct class is closed."
-      end
-
-      if fields.find {|f|f.name == name}
-        raise FieldNameError, "Field #{name} is already defined as a field."
-      end
-
-      if instance_methods(true).find {|m| m == name}
-        if opts[:allow_method_conflict] || opts["allow_method_conflict"]
-          warn "Field #{name} is already defined as a method."
-        else
-          raise FieldNameError,"Field #{name} is already defined as a method."
-        end
-      end
-      
-      field_class = opts[:field_class]
-      
-      prev = fields[-1] || NULL_FIELD
-      offset = prev.offset + prev.length
-      field = field_class.new(offset, length, name, opts)
-      field.add_accessors_to(self)
-      fields << field
-      own_fields << field
-      @bit_length += field.length
-      @round_byte_length = (bit_length/8.0).ceil
-
-      if @initial_value
-        diff = @round_byte_length - @initial_value.length
-        if diff > 0
-          @initial_value << "\0" * diff
-        end
-      end
-
-      field
-    end
-
-    def parse_options(ary, default_name, default_field_class) # :nodoc:
-      opts = ary.grep(Hash).first || {}
-      opts = default_options.merge(opts)
-      
-      opts[:display_name]  = ary.grep(String).first || default_name
-      opts[:field_class]   = ary.grep(Class).first || default_field_class
-      
-      opts
-    end
-    
-    # Get or set the hash of default options for the class, which apply to all
-    # fields. Changes take effect immediately, so can be used alternatingly with
-    # blocks of field declarations. If +h+ is provided, update the default
-    # options with that hash. Default options are inherited.
-    #
-    # This is especially useful with the <tt>:endian => val</tt> option.
-    def default_options h = nil
-      @default_options ||= superclass.default_options.dup
-      if h
-        @default_options.merge! h
-      end
-      @default_options
-    end
-    
-    # Length, in bits, of this object.
-    def bit_length
-      @bit_length ||= fields.inject(0) {|a, f| a + f.length}
-    end
-    
-    # Length, in bytes (rounded up), of this object.
-    def round_byte_length
-      @round_byte_length ||= (bit_length/8.0).ceil
-    end
-    
-    def closed! # :nodoc:
-      @closed = true
-    end
-
-    def field_by_name name
-      @field_by_name ||= {}
-      field = @field_by_name[name]
-      unless field
-        field = fields.find {|f| f.name == name}
-        @field_by_name[name] = field if field
-      end
-      field
-    end
-  end
-  
-  # Return the list of fields for this class.
-  def fields
-    self.class.fields
-  end
-  
-  # Return the field with the given name.
-  def field_by_name name
-    self.class.field_by_name name
-  end
-
-  # ------------------------
-  # :section: metadata inspection methods
-  #
-  # Methods to textually describe the format of a BitStruct subclass.
-  #
-  # ------------------------
-
-  class << self
-    # Default format for describe. Fields are byte, type, name, size,
-    # and description.
-    DESCRIBE_FORMAT = "%8s: %-12s %-14s[%4s] %s"
-    
-    # Can be overridden to use a different format.
-    def describe_format
-      DESCRIBE_FORMAT
-    end
-
-    # Textually describe the fields of this class of BitStructs.
-    # Returns a printable table (array of line strings), based on +fmt+,
-    # which defaults to #describe_format, which defaults to +DESCRIBE_FORMAT+.
-    def describe(fmt = nil, opts = {})
-      if block_given?
-        fields.each do |field|
-          field.describe(opts) do |desc|
-            yield desc
-          end
-        end
-        nil
-        
-      else
-        fmt ||= describe_format
-
-        result = []
-
-        unless opts[:omit_header]
-          result << fmt % ["byte", "type", "name", "size", "description"]
-          result << "-"*70
-        end
-
-        fields.each do |field|
-          field.describe(opts) do |desc|
-            result << fmt % desc
-          end
-        end
-
-        unless opts[:omit_footer]
-          result << @note if @note
-        end
-
-        result
-      end
-    end
-    
-    # Subclasses can use this to append a string (or several) to the #describe
-    # output. Notes are not cumulative with inheritance. When used with no
-    # arguments simply returns the note string
-    def note(*str)
-      @note = str unless str.empty?
-      @note
-    end
-  end
-  
-  # ------------------------
-  # :section: initialization and conversion methods
-  #
-  # ------------------------
-
-  # Initialize the string with the given string or bitstruct, or with a hash of
-  # field=>value pairs, or with the defaults for the BitStruct subclass. Fields
-  # can be strings or symbols. Finally, if a block is given, yield the instance
-  # for modification using accessors.
-  def initialize(value = nil)   # :yields: instance
-    self << self.class.initial_value
-
-    case value
-    when Hash
-      value.each do |k, v|
-        send "#{k}=", v
-      end
-    
-    when nil
-      
-    else
-      self[0, value.length] = value
-    end
-    
-    self.class.closed!
-    yield self if block_given?
-  end
-  
-  DEFAULT_TO_H_OPTS = {
-    :convert_keys   => :to_sym,
-    :include_rest   => true
-  }
-  
-  # Returns a hash of {name=>value,...} for each field. By default, include
-  # the rest field.
-  # Keys are symbols derived from field names using +to_sym+, unless
-  # <tt>opts[:convert_keys]<\tt> is set to some other method name.
-  def to_h(opts = DEFAULT_TO_H_OPTS)
-    converter = opts[:convert_keys] || :to_sym
-
-    fields_for_to_h = fields
-    if opts[:include_rest] and (rest_field = self.class.rest_field)
-      fields_for_to_h += [rest_field]
-    end
-    
-    fields_for_to_h.inject({}) do |h,f|
-      h[f.name.send(converter)] = send(f.name)
-      h
-    end
-  end
-  
-  # Returns an array of values of the fields of the BitStruct. By default,
-  # include the rest field.
-  def to_a(include_rest = true)
-    ary =
-      fields.map do |f|
-        send(f.name)
-      end
-    
-    if include_rest and (rest_field = self.class.rest_field)
-      ary << send(rest_field.name)
-    end
-  end
-  
-  class << self
-    # The unique "prototype" object from which new instances are copied.
-    # The fields of this instance can be modified in the class definition
-    # to set default values for the fields in that class. (Otherwise, defaults
-    # defined by the fields themselves are used.) A copy of this object is
-    # inherited in subclasses, which they may override using defaults and
-    # by writing to the initial_value object itself.
-    #
-    # If called with a block, yield the initial value object before returning
-    # it. Useful for customization within a class definition.
-    #
-    def initial_value   # :yields: the initial value
-      unless @initial_value
-        iv = defined?(superclass.initial_value) ? 
-          superclass.initial_value.dup : ""
-        if iv.length < round_byte_length
-          iv << "\0" * (round_byte_length - iv.length)
-        end
-
-        @initial_value = "" # Serves as initval while the real initval is inited
-        @initial_value = new(iv)
-        @closed = false # only creating the first _real_ instance closes.
-        
-        fields.each do |field|
-          @initial_value.send("#{field.name}=", field.default) if field.default
-        end
-      end
-      yield @initial_value if block_given?
-      @initial_value
-    end
-    
-    # Take +data+ (a string or BitStruct) and parse it into instances of
-    # the +classes+, returning them in an array. The classes can be given
-    # as an array or a separate arguments. (For parsing a string into a _single_
-    # BitStruct instance, just use the #new method with the string as an arg.)
-    def parse(data, *classes)
-      classes.flatten.map do |c|
-        c.new(data.slice!(0...c.round_byte_length))
-      end
-    end
-    
-    # Join the given structs (array or multiple args) as a string.
-    # Actually, the inherited String#+ instance method is the same, as is using
-    # Array#join.
-    def join(*structs)
-      structs.flatten.map {|struct| struct.to_s}.join("")
-    end
-  end
-
-  # ------------------------
-  # :section: inspection methods
-  #
-  # ------------------------
-
-  DEFAULT_INSPECT_OPTS = {
-    :format           => "#<%s %s>",
-    :field_format     => "%s=%s",
-    :separator        => ", ",
-    :field_name_meth  => :name,
-    :include_rest     => true
-  }
-  
-  DETAILED_INSPECT_OPTS = {
-    :format           => "%s:\n%s",
-    :field_format     => "%30s = %s",
-    :separator        => "\n",
-    :field_name_meth  => :display_name,
-    :include_rest     => true
-  }
-  
-  # A standard inspect method which does not add newlines.
-  def inspect(opts = DEFAULT_INSPECT_OPTS)
-    field_format = opts[:field_format]
-    field_name_meth = opts[:field_name_meth]
-    
-    fields_for_inspect = fields.select {|field| field.inspectable?}
-    if opts[:include_rest] and (rest_field = self.class.rest_field)
-      fields_for_inspect << rest_field
-    end
-    
-    ary = fields_for_inspect.map do |field|
-      field_format %
-       [field.send(field_name_meth),
-        field.inspect_in_object(self, opts)]
-    end
-        
-    body = ary.join(opts[:separator])
-    
-    opts[:format] % [self.class, body]
-  end
-  
-  # A more visually appealing inspect method that puts each field/value on
-  # a separate line. Very useful when output is scrolling by on a screen.
-  #
-  # (This is actually a convenience method to call #inspect with the
-  # DETAILED_INSPECT_OPTS opts.)
-  def inspect_detailed
-    inspect(DETAILED_INSPECT_OPTS)
-  end
-
-  # ------------------------
-  # :section: field declaration methods
-  #
-  # ------------------------
-  
-  # Define accessors for a variable length substring from the end of
-  # the defined fields to the end of the BitStruct. The _rest_ may behave as
-  # a String or as some other String or BitStruct subclass.
-  #
-  # This does not add a field, which is useful because a superclass can have
-  # a rest method which accesses subclass data. In particular, #rest does
-  # not affect the #round_byte_length class method. Of course, any data
-  # in rest does add to the #length of the BitStruct, calculated as a string.
-  # Also, _rest_ is not inherited.
-  #
-  # The +ary+ argument(s) work as follows:
-  #
-  # If a class is provided, use it for the Field class (String by default).
-  # If a string is provided, use it for the display_name (+name+ by default).
-  # If a hash is provided, use it for options.
-  #
-  # *Warning*: the rest reader method returns a copy of the field, so
-  # accessors on that returned value do not affect the original rest field. 
-  #
-  def self.rest(name, *ary)
-    if @rest_field
-      raise ArgumentError, "Duplicate rest field: #{name.inspect}."
-    end
-    
-    opts = parse_options(ary, name, String)
-    offset = round_byte_length
-    byte_range = offset..-1
-    class_eval do
-      field_class = opts[:field_class]
-      define_method name do ||
-        field_class.new(self[byte_range])
-      end
-
-      define_method "#{name}=" do |val|
-        self[byte_range] = val
-      end
-      
-      @rest_field = Field.new(offset, -1, name, {
-        :display_name => opts[:display_name],
-        :rest_class => field_class
-      })
-    end
-  end
-  
-  # Not included with the other fields, but accessible separately.
-  def self.rest_field; @rest_field; end
-end
diff --git a/tools/Mach5/bit-struct/char-field.rb b/tools/Mach5/bit-struct/char-field.rb
deleted file mode 100644 (file)
index 21a835f..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-require 'bit-struct/bit-struct'
-
-class BitStruct
-  # Class for fixed length binary strings of characters.
-  # Declared with BitStruct.char.
-  class CharField < Field
-    #def self.default
-    #  don't define this, since it must specify N nulls and we don't know N
-    #end
-    
-    # Used in describe.
-    def self.class_name
-      @class_name ||= "char"
-    end
-
-    def add_accessors_to(cl, attr = name) # :nodoc:
-      unless offset % 8 == 0
-        raise ArgumentError,
-          "Bad offset, #{offset}, for #{self.class} #{name}." +
-          " Must be multiple of 8."
-      end
-      
-      unless length % 8 == 0
-        raise ArgumentError,
-          "Bad length, #{length}, for #{self.class} #{name}." +
-          " Must be multiple of 8."
-      end
-      
-      offset_byte = offset / 8
-      length_byte = length / 8
-      last_byte = offset_byte + length_byte - 1
-      byte_range = offset_byte..last_byte
-      val_byte_range = 0..length_byte-1
-
-      cl.class_eval do
-        define_method attr do ||
-          self[byte_range].to_s
-        end
-
-        define_method "#{attr}=" do |val|
-          val = val.to_s
-          if val.length < length_byte
-            val += "\0" * (length_byte - val.length)
-          end
-          self[byte_range] = val[val_byte_range]
-        end
-      end
-    end
-  end
-  
-  class << self
-    # Define a char string field in the current subclass of BitStruct,
-    # with the given _name_ and _length_ (in bits). Trailing nulls _are_
-    # considered part of the string.
-    #
-    # If a class is provided, use it for the Field class.
-    # If a string is provided, use it for the display_name.
-    # If a hash is provided, use it for options.
-    #
-    # Note that the accessors have COPY semantics, not reference.
-    #
-    def char(name, length, *rest)
-      opts = parse_options(rest, name, CharField)
-      add_field(name, length, opts)
-    end
-    alias string char
-  end
-end
diff --git a/tools/Mach5/bit-struct/float-field.rb b/tools/Mach5/bit-struct/float-field.rb
deleted file mode 100644 (file)
index c651d51..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-require 'bit-struct/bit-struct'
-
-class BitStruct
-  # Class for floats (single and double precision) in network order.
-  # Declared with BitStruct.float.
-  class FloatField < Field
-    # Used in describe.
-    def self.class_name
-      @class_name ||= "float"
-    end
-    
-    def add_accessors_to(cl, attr = name) # :nodoc:
-      unless offset % 8 == 0
-        raise ArgumentError,
-          "Bad offset, #{offset}, for #{self.class} #{name}." +
-          " Must be multiple of 8."
-      end
-      
-      unless length == 32 or length == 64
-        raise ArgumentError,
-          "Bad length, #{length}, for #{self.class} #{name}." +
-          " Must be 32 or 64."
-      end
-      
-      offset_byte = offset / 8
-      length_byte = length / 8
-      last_byte = offset_byte + length_byte - 1
-      byte_range = offset_byte..last_byte
-
-      endian = (options[:endian] || options["endian"]).to_s
-      case endian
-      when "native"
-        ctl = case length
-          when 32; "f"
-          when 64; "d"
-        end
-      when "little"
-        ctl = case length
-          when 32; "e"
-          when 64; "E"
-        end
-      when "network", "big", ""
-        ctl = case length
-          when 32; "g"
-          when 64; "G"
-        end
-      else
-        raise ArgumentError,
-          "Unrecognized endian option: #{endian.inspect}"
-      end
-      
-      cl.class_eval do
-        define_method attr do ||
-          self[byte_range].unpack(ctl).first
-        end
-
-        define_method "#{attr}=" do |val|
-          self[byte_range] = [val].pack(ctl)
-        end
-      end
-    end
-  end
-
-  class << self
-    # Define a floating point field in the current subclass of BitStruct,
-    # with the given _name_ and _length_ (in bits).
-    #
-    # If a class is provided, use it for the Field class.
-    # If a string is provided, use it for the display_name.
-    # If a hash is provided, use it for options.
-    #
-    # The <tt>:endian => :native</tt> option overrides the default of
-    # <tt>:network</tt> byte ordering, in favor of native byte ordering. Also
-    # permitted are <tt>:big</tt> (same as <tt>:network</tt>) and
-    # <tt>:little</tt>.
-    #
-    def float name, length, *rest
-      opts = parse_options(rest, name, FloatField)
-      add_field(name, length, opts)
-    end
-  end
-end
diff --git a/tools/Mach5/bit-struct/hex-octet-field.rb b/tools/Mach5/bit-struct/hex-octet-field.rb
deleted file mode 100644 (file)
index 475a572..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-require 'bit-struct/char-field'
-
-class BitStruct
-  # Class for char fields that can be accessed with values like
-  # "xx:xx:xx:xx", where each xx is up to 2 hex digits representing a
-  # single octet. The original string-based accessors are still available with
-  # the <tt>_chars</tt> suffix.
-  # 
-  # Declared with BitStruct.hex_octets.
-  class HexOctetField < BitStruct::OctetField
-    # Used in describe.
-    def self.class_name
-      @class_name ||= "hex_octets"
-    end
-    
-    SEPARATOR = ":"
-    FORMAT    = "%02x"
-    BASE      = 16
-  end
-  
-  class << self
-    # Define an octet string field in the current subclass of BitStruct,
-    # with the given _name_ and _length_ (in bits). Trailing nulls are
-    # not considered part of the string. The field is accessed using
-    # period-separated hex digits.
-    #
-    # If a class is provided, use it for the Field class.
-    # If a string is provided, use it for the display_name.
-    # If a hash is provided, use it for options.
-    #
-    def hex_octets(name, length, *rest)
-      opts = parse_options(rest, name, HexOctetField)
-      add_field(name, length, opts)
-    end
-  end
-end
diff --git a/tools/Mach5/bit-struct/nested-field.rb b/tools/Mach5/bit-struct/nested-field.rb
deleted file mode 100644 (file)
index 19b333e..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-require 'bit-struct/bit-struct'
-
-class BitStruct
-  # Class for nesting a BitStruct as a field within another BitStruct.
-  # Declared with BitStruct.nest.
-  class NestedField < Field
-    def initialize(*args)
-      super
-    end
-    
-    # Used in describe.
-    def self.class_name
-      @class_name ||= "nest"
-    end
-    
-    def class_name
-      @class_name ||= nested_class.name[/\w+$/]
-    end
-    
-    def nested_class
-      @nested_class ||= options[:nested_class] || options["nested_class"]
-    end
-
-    def describe opts
-      if opts[:expand]
-        opts = opts.dup
-        opts[:byte_offset] = offset / 8
-        opts[:omit_header] = opts[:omit_footer] = true
-        nested_class.describe(nil, opts) {|desc| yield desc}
-      else
-        super
-      end
-    end
-
-    def add_accessors_to(cl, attr = name) # :nodoc:
-      unless offset % 8 == 0
-        raise ArgumentError,
-          "Bad offset, #{offset}, for nested field #{name}." +
-          " Must be multiple of 8."
-      end
-      
-      unless length % 8 == 0
-        raise ArgumentError,
-          "Bad length, #{length}, for nested field #{name}." +
-          " Must be multiple of 8."
-      end
-      
-      offset_byte = offset / 8
-      length_byte = length / 8
-      last_byte = offset_byte + length_byte - 1
-      byte_range = offset_byte..last_byte
-      val_byte_range = 0..length_byte-1
-
-      nc = nested_class
-      
-      cl.class_eval do
-        define_method attr do ||
-          nc.new(self[byte_range])
-        end
-
-        define_method "#{attr}=" do |val|
-          if val.length != length_byte
-            raise ArgumentError, "Size mismatch in nested struct assignment " +
-              "to #{attr} with value #{val.inspect}"
-          end
-          
-          if val.class != nc
-            warn "Type mismatch in nested struct assignment " +
-              "to #{attr} with value #{val.inspect}"
-          end
-          
-          self[byte_range] = val[val_byte_range]
-        end
-      end
-    end
-  end
-  
-  class << self
-    # Define a nested field in the current subclass of BitStruct,
-    # with the given _name_ and _nested_class_. Length is determined from
-    # _nested_class_.
-    #
-    # In _rest_:
-    #
-    # If a class is provided, use it for the Field class (i.e. <=NestedField).
-    # If a string is provided, use it for the display_name.
-    # If a hash is provided, use it for options.
-    #
-    # WARNING: the accessors have COPY semantics, not reference. When you call a
-    # reader method to get the nested structure, you get a *copy* of that data.
-    #
-    # For example:
-    #
-    #   class Sub < BitStruct
-    #     unsigned :x,    8
-    #   end
-    #
-    #   class A < BitStruct
-    #     nest    :n,  Sub
-    #   end
-    #
-    #   a = A.new
-    #
-    #   p a  # ==> #<A n=#<Sub x=0>>
-    #
-    #   # This fails to set x in a.
-    #   a.n.x = 3
-    #   p a  # ==> #<A n=#<Sub x=0>>
-    #
-    #   # This works
-    #   n = a.n
-    #   n.x = 3
-    #   a.n = n
-    #   p a  # ==> #<A n=#<Sub x=3>>
-    # 
-    def nest(name, nested_class, *rest)
-      opts = parse_options(rest, name, NestedField)
-      opts[:default] ||= nested_class.initial_value.dup
-      opts[:nested_class] = nested_class
-      field = add_field(name, nested_class.bit_length, opts)
-      field
-    end
-    alias struct nest
-  end
-end
diff --git a/tools/Mach5/bit-struct/octet-field.rb b/tools/Mach5/bit-struct/octet-field.rb
deleted file mode 100644 (file)
index d05e868..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-require 'bit-struct/char-field'
-
-class BitStruct
-  # Class for char fields that can be accessed with values like
-  # "xxx.xxx.xxx.xxx", where each xxx is up to 3 decimal digits representing a
-  # single octet. The original string-based accessors are still available with
-  # the <tt>_chars</tt> suffix.
-  # 
-  # Declared with BitStruct.octets.
-  class OctetField < BitStruct::CharField
-    # Used in describe.
-    def self.class_name
-      @class_name ||= "octets"
-    end
-    
-    SEPARATOR = "."
-    FORMAT    = "%d"
-    BASE      = 10
-
-    def add_accessors_to(cl, attr = name) # :nodoc:
-      attr_chars = "#{attr}_chars"
-      super(cl, attr_chars)
-      sep   = self.class::SEPARATOR
-      base  = self.class::BASE
-      fmt   = self.class::FORMAT
-      
-      cl.class_eval do
-        define_method attr do ||
-          ary = []
-          send(attr_chars).each_byte do  |c|
-            ary << fmt % c
-          end
-          ary.join(sep)
-        end
-        
-        old_writer = "#{attr_chars}="
-
-        define_method "#{attr}=" do |val|
-          data = val.split(sep).map{|s|s.to_i(base)}.pack("c*")
-          send(old_writer, data)
-        end
-      end
-    end
-  end
-  
-  class << self
-    # Define an octet string field in the current subclass of BitStruct,
-    # with the given _name_ and _length_ (in bits). Trailing nulls are
-    # not considered part of the string. The field is accessed using
-    # period-separated decimal digits.
-    #
-    # If a class is provided, use it for the Field class.
-    # If a string is provided, use it for the display_name.
-    # If a hash is provided, use it for options.
-    #
-    def octets(name, length, *rest)
-      opts = parse_options(rest, name, OctetField)
-      add_field(name, length, opts)
-    end
-  end
-end
diff --git a/tools/Mach5/bit-struct/pad-field.rb b/tools/Mach5/bit-struct/pad-field.rb
deleted file mode 100644 (file)
index d626510..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-require 'bit-struct/bit-struct'
-
-class BitStruct
-  # Class for fixed length padding.
-  class PadField < Field
-    # Used in describe.
-    def self.class_name
-      @class_name ||= "padding"
-    end
-
-    def add_accessors_to(cl, attr = name) # :nodoc:
-      # No accessors for padding.
-    end
-
-    def inspectable?; false; end
-  end
-  
-  class << self
-    # Define a padding field in the current subclass of BitStruct,
-    # with the given _name_ and _length_ (in bits).
-    #
-    # If a class is provided, use it for the Field class.
-    # If a string is provided, use it for the display_name.
-    # If a hash is provided, use it for options.
-    #
-    def pad(name, length, *rest)
-      opts = parse_options(rest, name, PadField)
-      add_field(name, length, opts)
-    end
-    alias padding pad
-  end
-end
diff --git a/tools/Mach5/bit-struct/signed-field.rb b/tools/Mach5/bit-struct/signed-field.rb
deleted file mode 100644 (file)
index bc17f5e..0000000
+++ /dev/null
@@ -1,283 +0,0 @@
-require 'bit-struct/bit-struct'
-
-class BitStruct
-  # Class for signed integers in network order, 1-16 bits, or 8n bits.
-  # Declared with BitStruct.signed.
-  class SignedField < Field
-    # Used in describe.
-    def self.class_name
-      @class_name ||= "signed"
-    end
-    
-    def add_accessors_to(cl, attr = name) # :nodoc:
-      offset_byte = offset / 8
-      offset_bit = offset % 8
-      
-      length_bit = offset_bit + length
-      length_byte = (length_bit/8.0).ceil
-      last_byte = offset_byte + length_byte - 1
-      max = 2**length-1
-      mid = 2**(length-1)
-      max_unsigned = 2**length
-      to_signed = proc {|n| (n>=mid) ? n - max_unsigned : n}
-#      to_signed = proc {|n| (n>=mid) ? -((n ^ max) + 1) : n}
-      
-      divisor = options[:fixed] || options["fixed"]
-      divisor_f = divisor && divisor.to_f
-#      if divisor and not divisor.is_a? Fixnum
-#        raise ArgumentError, "fixed-point divisor must be a fixnum"
-#      end
-
-      endian = (options[:endian] || options["endian"]).to_s
-      case endian
-      when "native"
-        ctl = length_byte <= 2 ? "s" : "l"
-        if length == 16 or length == 32
-          to_signed = proc {|n| n}
-          # with pack support, to_signed can be replaced with no-op
-        end
-      when "little"
-        ctl = length_byte <= 2 ? "v" : "V"
-      when "network", "big", ""
-        ctl = length_byte <= 2 ? "n" : "N"
-      else
-        raise ArgumentError,
-          "Unrecognized endian option: #{endian.inspect}"
-      end
-      
-      data_is_big_endian =
-        ([1234].pack(ctl) == [1234].pack(length_byte <= 2 ? "n" : "N"))
-      
-      if length_byte == 1
-        rest = 8 - length_bit
-        mask  = ["0"*offset_bit + "1"*length + "0"*rest].pack("B8")[0]
-        mask2 = ["1"*offset_bit + "0"*length + "1"*rest].pack("B8")[0]
-        
-        cl.class_eval do
-          if divisor
-            define_method attr do ||
-              to_signed[(self[offset_byte] & mask) >> rest] / divisor_f
-            end
-
-            define_method "#{attr}=" do |val|
-              val = (val * divisor).round
-              self[offset_byte] =
-                (self[offset_byte] & mask2) | ((val<<rest) & mask)
-            end
-
-          else
-            define_method attr do ||
-              to_signed[(self[offset_byte] & mask) >> rest]
-            end
-
-            define_method "#{attr}=" do |val|
-              self[offset_byte] =
-                (self[offset_byte] & mask2) | ((val<<rest) & mask)
-            end
-          end
-        end
-      
-      elsif offset_bit == 0 and length % 8 == 0
-        field_length = length
-        byte_range = offset_byte..last_byte
-        
-        cl.class_eval do
-          case field_length
-          when 8
-            if divisor
-              define_method attr do ||
-                to_signed[self[offset_byte]] / divisor_f
-              end
-
-              define_method "#{attr}=" do |val|
-                val = (val * divisor).round
-                self[offset_byte] = val
-              end
-          
-            else
-              define_method attr do ||
-                to_signed[self[offset_byte]]
-              end
-
-              define_method "#{attr}=" do |val|
-                self[offset_byte] = val
-              end
-            end
-        
-          when 16, 32
-            if divisor
-              define_method attr do ||
-                to_signed[self[byte_range].unpack(ctl).first] / divisor_f
-              end
-
-              define_method "#{attr}=" do |val|
-                val = (val * divisor).round
-                self[byte_range] = [val].pack(ctl)
-              end
-            
-            else
-              define_method attr do ||
-                to_signed[self[byte_range].unpack(ctl).first]
-              end
-
-              define_method "#{attr}=" do |val|
-                self[byte_range] = [val].pack(ctl)
-              end
-            end
-          
-          else
-            reader_helper = proc do |substr|
-              bytes = substr.unpack("C*")
-              bytes.reverse! unless data_is_big_endian
-              bytes.inject do |sum, byte|
-                (sum << 8) + byte
-              end
-            end
-            
-            writer_helper = proc do |val|
-              bytes = []
-              val += max_unsigned if val < 0
-              while val > 0
-                bytes.push val % 256
-                val = val >> 8
-              end
-              if bytes.length < length_byte
-                bytes.concat [0] * (length_byte - bytes.length)
-              end
-
-              bytes.reverse! if data_is_big_endian
-              bytes.pack("C*")
-            end
-            
-            if divisor
-              define_method attr do ||
-                to_signed[reader_helper[self[byte_range]] / divisor_f]
-              end
-              
-              define_method "#{attr}=" do |val|
-                self[byte_range] = writer_helper[(val * divisor).round]
-              end
-            
-            else
-              define_method attr do ||
-                to_signed[reader_helper[self[byte_range]]]
-              end
-              
-              define_method "#{attr}=" do |val|
-                self[byte_range] = writer_helper[val]
-              end
-            end
-          end
-        end
-
-      elsif length_byte == 2 # unaligned field that fits within two whole bytes
-        byte_range = offset_byte..last_byte
-        rest = 16 - length_bit
-        
-        mask  = ["0"*offset_bit + "1"*length + "0"*rest]
-        mask = mask.pack("B16").unpack(ctl).first
-        
-        mask2 = ["1"*offset_bit + "0"*length + "1"*rest]
-        mask2 = mask2.pack("B16").unpack(ctl).first
-
-        cl.class_eval do
-          if divisor
-            define_method attr do ||
-              to_signed[(self[byte_range].unpack(ctl).first & mask) >> rest] /
-                 divisor_f
-            end
-
-            define_method "#{attr}=" do |val|
-              val = (val * divisor).round
-              x = (self[byte_range].unpack(ctl).first & mask2) |
-                ((val<<rest) & mask)
-              self[byte_range] = [x].pack(ctl)
-            end
-
-          else
-            define_method attr do ||
-              to_signed[(self[byte_range].unpack(ctl).first & mask) >> rest]
-            end
-
-            define_method "#{attr}=" do |val|
-              x = (self[byte_range].unpack(ctl).first & mask2) |
-                ((val<<rest) & mask)
-              self[byte_range] = [x].pack(ctl)
-            end
-          end
-        end
-      
-      elsif length_byte == 3 # unaligned field that fits within 3 whole bytes
-        byte_range = offset_byte..last_byte
-        rest = 32 - length_bit
-        
-        mask  = ["0"*offset_bit + "1"*length + "0"*rest]
-        mask = mask.pack("B32").unpack(ctl).first
-        
-        mask2 = ["1"*offset_bit + "0"*length + "1"*rest]
-        mask2 = mask2.pack("B32").unpack(ctl).first
-
-        cl.class_eval do
-          if divisor
-            define_method attr do ||
-              bytes = self[byte_range]
-              bytes << 0
-              to_signed[((bytes.unpack(ctl).first & mask) >> rest)] /
-                 divisor_f
-            end
-
-            define_method "#{attr}=" do |val|
-              val = (val * divisor).round
-              bytes = self[byte_range]
-              bytes << 0
-              x = (bytes.unpack(ctl).first & mask2) |
-                ((val<<rest) & mask)
-              self[byte_range] = [x].pack(ctl)[0..2]
-            end
-
-          else
-            define_method attr do ||
-              bytes = self[byte_range]
-              bytes << 0
-              to_signed[(bytes.unpack(ctl).first & mask) >> rest]
-            end
-
-            define_method "#{attr}=" do |val|
-              bytes = self[byte_range]
-              bytes << 0
-              x = (bytes.unpack(ctl).first & mask2) |
-                ((val<<rest) & mask)
-              self[byte_range] = [x].pack(ctl)[0..2]
-            end
-          end
-        end
-      
-      else
-        raise "unsupported: #{inspect}"
-      end
-    end
-  end
-
-  class << self
-    # Define a signed integer field in the current subclass of BitStruct,
-    # with the given _name_ and _length_ (in bits).
-    #
-    # If a class is provided, use it for the Field class.
-    # If a string is provided, use it for the display_name.
-    # If a hash is provided, use it for options.
-    #
-    # SignedField adds the <tt>:fixed => divisor</tt> option, which specifies
-    # that the internally stored value is interpreted as a fixed point real
-    # number with the specified +divisor+.
-    #
-    # The <tt>:endian => :native</tt> option overrides the default of
-    # <tt>:network</tt> byte ordering, in favor of native byte ordering. Also
-    # permitted are <tt>:big</tt> (same as <tt>:network</tt>) and
-    # <tt>:little</tt>.
-    #
-    def signed name, length, *rest
-      opts = parse_options(rest, name, SignedField)
-      add_field(name, length, opts)
-    end
-  end
-end
diff --git a/tools/Mach5/bit-struct/text-field.rb b/tools/Mach5/bit-struct/text-field.rb
deleted file mode 100644 (file)
index 369981f..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-require 'bit-struct/bit-struct'
-
-class BitStruct
-  # Class for null-terminated printable text strings.
-  # Declared with BitStruct.text.
-  class TextField < Field
-    # Used in describe.
-    def self.class_name
-      @class_name ||= "text"
-    end
-
-    def add_accessors_to(cl, attr = name) # :nodoc:
-      unless offset % 8 == 0
-        raise ArgumentError,
-          "Bad offset, #{offset}, for #{self.class} #{name}." +
-          " Must be multiple of 8."
-      end
-      
-      unless length % 8 == 0
-        raise ArgumentError,
-          "Bad length, #{length}, for #{self.class} #{name}." +
-          " Must be multiple of 8."
-      end
-      
-      offset_byte = offset / 8
-      length_byte = length / 8
-      last_byte = offset_byte + length_byte - 1
-      byte_range = offset_byte..last_byte
-      val_byte_range = 0..length_byte-1
-
-      cl.class_eval do
-        define_method attr do ||
-          self[byte_range].sub(/\0*$/, "").to_s
-        end
-
-        define_method "#{attr}=" do |val|
-          val = val.to_s
-          if val.length < length_byte
-            val += "\0" * (length_byte - val.length)
-          end
-          self[byte_range] = val[val_byte_range]
-        end
-      end
-    end
-  end
-  
-  class << self
-    # Define a printable text string field in the current subclass of BitStruct,
-    # with the given _name_ and _length_ (in bits). Trailing nulls are
-    # _not_ considered part of the string.
-    #
-    # If a class is provided, use it for the Field class.
-    # If a string is provided, use it for the display_name.
-    # If a hash is provided, use it for options.
-    #
-    # Note that the accessors have COPY semantics, not reference.
-    #
-    def text(name, length, *rest)
-      opts = parse_options(rest, name, TextField)
-      add_field(name, length, opts)
-    end
-  end
-end
diff --git a/tools/Mach5/bit-struct/unsigned-field.rb b/tools/Mach5/bit-struct/unsigned-field.rb
deleted file mode 100644 (file)
index 41571b1..0000000
+++ /dev/null
@@ -1,273 +0,0 @@
-require 'bit-struct/bit-struct'
-
-class BitStruct
-  # Class for unsigned integers in network order, 1-16 bits, or 8n bits.
-  # Declared with BitStruct.unsigned.
-  class UnsignedField < Field
-    # Used in describe.
-    def self.class_name
-      @class_name ||= "unsigned"
-    end
-    
-    def add_accessors_to(cl, attr = name) # :nodoc:
-      offset_byte = offset / 8
-      offset_bit = offset % 8
-      
-      length_bit = offset_bit + length
-      length_byte = (length_bit/8.0).ceil
-      last_byte = offset_byte + length_byte - 1
-      
-      divisor = options[:fixed] || options["fixed"]
-      divisor_f = divisor && divisor.to_f
-#      if divisor and not divisor.is_a? Fixnum
-#        raise ArgumentError, "fixed-point divisor must be a fixnum"
-#      end
-      
-      endian = (options[:endian] || options["endian"]).to_s
-      case endian
-      when "native"
-        ctl = length_byte <= 2 ? "S" : "L"
-      when "little"
-        ctl = length_byte <= 2 ? "v" : "V"
-      when "network", "big", ""
-        ctl = length_byte <= 2 ? "n" : "N"
-      else
-        raise ArgumentError,
-          "Unrecognized endian option: #{endian.inspect}"
-      end
-      
-      data_is_big_endian =
-        ([1234].pack(ctl) == [1234].pack(length_byte <= 2 ? "n" : "N"))
-      
-      if length_byte == 1
-        rest = 8 - length_bit
-        mask  = ["0"*offset_bit + "1"*length + "0"*rest].pack("B8")[0]
-        mask2 = ["1"*offset_bit + "0"*length + "1"*rest].pack("B8")[0]
-        
-        cl.class_eval do
-          if divisor
-            define_method attr do ||
-              ((self[offset_byte] & mask) >> rest) / divisor_f
-            end
-
-            define_method "#{attr}=" do |val|
-              val = (val * divisor).round
-              self[offset_byte] =
-                (self[offset_byte] & mask2) | ((val<<rest) & mask)
-            end
-
-          else
-            define_method attr do ||
-              (self[offset_byte] & mask) >> rest
-            end
-
-            define_method "#{attr}=" do |val|
-              self[offset_byte] =
-                (self[offset_byte] & mask2) | ((val<<rest) & mask)
-            end
-          end
-        end
-      
-      elsif offset_bit == 0 and length % 8 == 0
-        field_length = length
-        byte_range = offset_byte..last_byte
-        
-        cl.class_eval do
-          case field_length
-          when 8
-            if divisor
-              define_method attr do ||
-                self[offset_byte] / divisor_f
-              end
-
-              define_method "#{attr}=" do |val|
-                val = (val * divisor).round
-                self[offset_byte] = val
-              end
-          
-            else
-              define_method attr do ||
-                self[offset_byte]
-              end
-
-              define_method "#{attr}=" do |val|
-                self[offset_byte] = val
-              end
-            end
-        
-          when 16, 32
-            if divisor
-              define_method attr do ||
-                self[byte_range].unpack(ctl).first / divisor_f
-              end
-
-              define_method "#{attr}=" do |val|
-                val = (val * divisor).round
-                self[byte_range] = [val].pack(ctl)
-              end
-            
-            else
-              define_method attr do ||
-                self[byte_range].unpack(ctl).first
-              end
-
-              define_method "#{attr}=" do |val|
-                self[byte_range] = [val].pack(ctl)
-              end
-            end
-          
-          else
-            reader_helper = proc do |substr|
-              bytes = substr.unpack("C*")
-              bytes.reverse! unless data_is_big_endian
-              bytes.inject do |sum, byte|
-                (sum << 8) + byte
-              end
-            end
-            
-            writer_helper = proc do |val|
-              bytes = []
-              while val > 0
-                bytes.push val % 256
-                val = val >> 8
-              end
-              if bytes.length < length_byte
-                bytes.concat [0] * (length_byte - bytes.length)
-              end
-
-              bytes.reverse! if data_is_big_endian
-              bytes.pack("C*")
-            end
-            
-            if divisor
-              define_method attr do ||
-                reader_helper[self[byte_range]] / divisor_f
-              end
-              
-              define_method "#{attr}=" do |val|
-                self[byte_range] = writer_helper[(val * divisor).round]
-              end
-            
-            else
-              define_method attr do ||
-                reader_helper[self[byte_range]]
-              end
-              
-              define_method "#{attr}=" do |val|
-                self[byte_range] = writer_helper[val]
-              end
-            end
-          end
-        end
-
-      elsif length_byte == 2 # unaligned field that fits within two whole bytes
-        byte_range = offset_byte..last_byte
-        rest = 16 - length_bit
-        
-        mask  = ["0"*offset_bit + "1"*length + "0"*rest]
-        mask = mask.pack("B16").unpack(ctl).first
-        
-        mask2 = ["1"*offset_bit + "0"*length + "1"*rest]
-        mask2 = mask2.pack("B16").unpack(ctl).first
-
-        cl.class_eval do
-          if divisor
-            define_method attr do ||
-              ((self[byte_range].unpack(ctl).first & mask) >> rest) /
-                 divisor_f
-            end
-
-            define_method "#{attr}=" do |val|
-              val = (val * divisor).round
-              x = (self[byte_range].unpack(ctl).first & mask2) |
-                ((val<<rest) & mask)
-              self[byte_range] = [x].pack(ctl)
-            end
-
-          else
-            define_method attr do ||
-              (self[byte_range].unpack(ctl).first & mask) >> rest
-            end
-
-            define_method "#{attr}=" do |val|
-              x = (self[byte_range].unpack(ctl).first & mask2) |
-                ((val<<rest) & mask)
-              self[byte_range] = [x].pack(ctl)
-            end
-          end
-        end
-      
-      elsif length_byte == 3 # unaligned field that fits within 3 whole bytes
-        byte_range = offset_byte..last_byte
-        rest = 32 - length_bit
-        
-        mask  = ["0"*offset_bit + "1"*length + "0"*rest]
-        mask = mask.pack("B32").unpack(ctl).first
-        
-        mask2 = ["1"*offset_bit + "0"*length + "1"*rest]
-        mask2 = mask2.pack("B32").unpack(ctl).first
-
-        cl.class_eval do
-          if divisor
-            define_method attr do ||
-              bytes = self[byte_range]
-              bytes << 0
-              ((bytes.unpack(ctl).first & mask) >> rest) /
-                 divisor_f
-            end
-
-            define_method "#{attr}=" do |val|
-              val = (val * divisor).round
-              bytes = self[byte_range]
-              bytes << 0
-              x = (bytes.unpack(ctl).first & mask2) |
-                ((val<<rest) & mask)
-              self[byte_range] = [x].pack(ctl)[0..2]
-            end
-
-          else
-            define_method attr do ||
-              bytes = self[byte_range]
-              bytes << 0
-              (bytes.unpack(ctl).first & mask) >> rest
-            end
-
-            define_method "#{attr}=" do |val|
-              bytes = self[byte_range]
-              bytes << 0
-              x = (bytes.unpack(ctl).first & mask2) |
-                ((val<<rest) & mask)
-              self[byte_range] = [x].pack(ctl)[0..2]
-            end
-          end
-        end
-      
-      else
-        raise "unsupported: #{inspect}"
-      end
-    end
-  end
-
-  class << self
-    # Define a unsigned integer field in the current subclass of BitStruct,
-    # with the given _name_ and _length_ (in bits).
-    #
-    # If a class is provided, use it for the Field class.
-    # If a string is provided, use it for the display_name.
-    # If a hash is provided, use it for options.
-    #
-    # UnsignedField adds the <tt>:fixed => divisor</tt> option, which specifies
-    # that the internally stored value is interpreted as a fixed point real
-    # number with the specified +divisor+.
-    #
-    # The <tt>:endian => :native</tt> option overrides the default of
-    # <tt>:network</tt> byte ordering, in favor of native byte ordering. Also
-    # permitted are <tt>:big</tt> (same as <tt>:network</tt>) and
-    # <tt>:little</tt>.
-    #
-    def unsigned name, length, *rest
-      opts = parse_options(rest, name, UnsignedField)
-      add_field(name, length, opts)
-    end
-  end
-end
diff --git a/tools/Mach5/bit-struct/yaml.rb b/tools/Mach5/bit-struct/yaml.rb
deleted file mode 100644 (file)
index f298ab2..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-require 'bit-struct/bit-struct'
-require 'yaml'
-
-class BitStruct
-  if RUBY_VERSION == "1.8.2"
-    def is_complex_yaml? # :nodoc:
-      true
-    end
-
-    YAML.add_ruby_type(/^bitstruct/) do |type, val|
-      subtype, subclass = YAML.read_type_class(type, Object)
-      subclass.new(val)
-    end
-
-    def to_yaml_type # :nodoc:
-      "!ruby/bitstruct:#{self.class}"
-    end
-
-    def to_yaml( opts = {} ) # :nodoc:
-      opts[:DocType] = self.class if Hash === opts
-      YAML.quick_emit(self.object_id, opts) do |out|
-        out.map(to_yaml_type) do |map|
-          fields.each do |field|
-            fn = field.name
-            map.add(fn, send(fn))
-          end
-        end
-      end
-    end
-
-  else
-    yaml_as "tag:path.berkeley.edu,2006:bitstruct"
-
-    def to_yaml_properties # :nodoc:
-      yaml_fields = fields.select {|field| field.inspectable?}
-      props = yaml_fields.map {|f| f.name.to_s}
-      if (rest_field = self.class.rest_field)
-        props << rest_field.name.to_s
-      end
-      props
-    end
-
-    # Return YAML representation of the BitStruct.
-    def to_yaml( opts = {} )
-      YAML::quick_emit( object_id, opts ) do |out|
-        out.map( taguri, to_yaml_style ) do |map|
-          to_yaml_properties.each do |m|
-            map.add( m, send( m ) )
-          end
-        end
-      end
-    end
-
-    def self.yaml_new( klass, tag, val ) # :nodoc:
-      unless Hash === val
-        raise YAML::TypeError, "Invalid BitStruct: " + val.inspect
-      end
-
-      bitstruct_name, bitstruct_type = YAML.read_type_class( tag, BitStruct )
-
-      st = bitstruct_type.new
-
-      val.each do |k,v|
-        st.send( "#{k}=", v )
-      end
-
-      st
-    end
-  end
-end
diff --git a/tools/Mach5/mach5.rb b/tools/Mach5/mach5.rb
deleted file mode 100755 (executable)
index b7d9cc4..0000000
+++ /dev/null
@@ -1,263 +0,0 @@
-#!/usr/bin/env ruby
-#
-#  Copyright (C) 2008 Elan Feingold (elan at bluemandrill dot com)
-#
-#  This Program is free software; you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2, or (at your option)
-#  any later version.
-#
-#  This Program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-#  GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with GNU Make; see the file COPYING.  If not, write to
-#  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-#  http://www.gnu.org/copyleft/gpl.html
-#
-#
-
-require 'bit-struct'
-
-# For example, "_calloc" => "_wrap_calloc"
-prefix = '___wrap_'
-mappings = {
-#'calloc' => true,
-'clearerr' => true,
-'close' => true,
-'fclose' => true,
-'fdopen' => true,
-'feof' => true,
-'ferror' => true,
-'fflush' => true,
-'fgetc' => true,
-'fgetpos' => true,
-'fgets' => true,
-'fileno' => true,
-'flockfile' => true,
-'fopen' => true,
-'fopen64' => true,
-'fprintf' => true,
-'fputc' => true,
-'fputs' => true,
-'fread' => true,
-#'free' => true,
-'freopen' => true,
-'fseek' => true,
-'fsetpos' => true,
-'fstatvfs64' => true,
-'ftell' => true,
-'ftrylockfile' => true,
-'funlockfile' => true,
-'fwrite' => true,
-'getc_unlocked' => true,
-'ioctl' => true,
-'lseek' => true,
-'lseek64' => true,
-#'malloc' => true,
-'open' => true,
-'open64' => true,
-'popen' => true,
-'printf' => true,
-'read' => true,
-#'realloc' => true,
-'rewind' => true,
-'stat' => true,
-'fstat' => true,
-'ungetc' => true,
-'vfprintf' => true,
-'write' => true,
-'putc' => '___wrap__IO_putc',
-'getc' => '___wrap__IO_getc',
-'getc_unlocked' => '___wrap__IO_getc_unlocked'
-}
-
-prefix_python = '___py_wrap_'
-mappings_python = {
-  'getcwd' => true, 'chdir' => true, 'access' => true, 'unlink' => true, 'chmod' => true, 
-  'rmdir' => true, 'utime' => true, 'rename' => true, 'mkdir' => true,  
-  'opendir' => true, 'dlopen' => true, 'dlclose' => true, 'dlsym' => true,
-  'lstat' => true
-}
-
-LC_SYMTAB = 0x02
-LC_SEGMENT = 0x01
-
-class MachHeader < BitStruct
-  hex_octets  :magic,       32, "Magic Number"
-  unsigned    :cputype,     32, "CPU Type", :endian => :native
-  unsigned    :cpusubtype,  32, "CPU Subtype", :endian => :native
-  unsigned    :filetype,    32, "File Type", :endian => :native
-  unsigned    :ncmds,       32, "Number of commands", :endian => :native
-  unsigned    :sizeofcmds,  32, "Size of commands", :endian => :native
-  unsigned    :flags,       32, "Flags", :endian => :native
-  rest        :data,            "Data"
-end
-
-class LoadCommand < BitStruct
-  unsigned    :cmd,         32, "Command", :endian => :native
-  unsigned    :cmdsize,     32, "Command Size", :endian => :native
-end
-
-class SymtabCommand < BitStruct
-  unsigned    :cmd,         32, "Command", :endian => :native
-  unsigned    :cmdsize,     32, "Command Size", :endian => :native
-  unsigned    :symoff,      32, "Symbol Offset", :endian => :native
-  unsigned    :nsyms,       32, "Number of Symbols", :endian => :native
-  unsigned    :stroff,      32, "String table offset", :endian => :native
-  unsigned    :strsize,     32, "Size of string table", :endian => :native
-end
-
-class SegmentCommand < BitStruct
-  unsigned    :cmd,         32, "Command", :endian => :native
-  unsigned    :cmdsize,     32, "Command Size", :endian => :native
-  char        :segname,    16*8, "Segment name", :endian => :native
-  unsigned    :vmaddr,      32, "VM Adddress", :endian => :native
-  unsigned    :vmsize,      32, "VM Size", :endian => :native
-  unsigned    :fileoff,     32, "File Offset", :endian => :native
-  unsigned    :filesize,    32, "File Size", :endian => :native
-end
-
-class SymtabEntry < BitStruct
-  unsigned  :strtableoffset, 32, "String table offset", :endian => :native
-  unsigned  :debuggingEntry,  3, "Debugging entry", :endian => :native
-  unsigned  :privateExternal, 1, "Is Private Enternal", :endian => :native
-  unsigned  :type,            3, "Type bits", :endian => :native
-  unsigned  :external,        1, "External symbol", :endian => :native
-  unsigned  :sectionNumber,   8, "Section number", :endian => :native
-  unsigned  :description,    16, "Description", :endian => :native
-  unsigned  :value,          32, "Value", :endian => :native
-end
-
-# Select which mapping to use.
-if ARGV.size() > 1 and ARGV[1].index('libpython') == 0
-  puts "Using Python mappings."
-  mappings = mappings_python
-  #prefix = prefix_python
-end
-
-data = open(ARGV[0]).read
-puts "Input file was #{data.length} bytes long."
-
-# Parse the header.
-header = MachHeader.new(data)
-sym_cmd = nil
-
-# String table.
-string_table = nil
-string_table_offset = nil
-string_table_map = {}
-offset_map = {}
-
-# Symbol table.
-symbol_table = nil
-symbol_table_offset = nil
-symbols = []
-
-# Link segment.
-link_cmd = nil
-link_cmd_offset = nil
-
-# Walk through all the commands.
-offset = data.size - header.data.size
-header.ncmds.times do |i|
-  load_cmd = LoadCommand.new(data[offset..-1])
-  
-  if load_cmd.cmd == LC_SEGMENT
-    seg_cmd = SegmentCommand.new(data[offset..-1])
-    if seg_cmd.segname.index('__LINKEDIT') == 0
-      puts "Found LINKEDIT segment at offset #{offset}"
-      link_cmd = seg_cmd
-      link_cmd_offset = offset
-    end
-  end
-  
-  if load_cmd.cmd == LC_SYMTAB
-    # Parse the symbol table command.
-    sym_cmd = SymtabCommand.new(data[offset..-1])
-    symbol_table_offset = offset
-    
-    # Parse the string table, store with offsets.
-    string_table_offset = sym_cmd.stroff
-    string_table = data[sym_cmd.stroff..sym_cmd.stroff+sym_cmd.strsize-1]
-    i = 0
-    string_table.split("\x00", -1).each do |s|
-      string_table_map[i] = s
-      i += s.length + 1
-    end
-    
-    # Parse the symbol table.
-    symbol_table = data[sym_cmd.symoff..-1]
-    i = 0
-    puts "Symbol table has #{sym_cmd.nsyms} symbols."
-    sym_cmd.nsyms.times do |n|
-      symbols << SymtabEntry.new(symbol_table[i..i+11])
-      i += 12
-    end
-    
-    # Now go through and make renames to the symbols.
-    size_diff = 0
-    
-    string_table_map.keys.sort.each do |i|
-      orig_sym = string_table_map[i]
-      
-      # Store the offset mapping.
-      offset_map[i] = (i + size_diff)
-      
-      if orig_sym.length > 1
-        sym = orig_sym[1..-1].gsub('$UNIX2003','')
-        if mappings.has_key?(sym)
-          if mappings[sym] != true
-            string_table_map[i] = mappings[sym]
-          else
-            string_table_map[i] = "#{prefix}#{sym}"
-          end
-          puts "   - Mapping: #{orig_sym} to #{string_table_map[i]} (offset #{i} -> #{i + size_diff})"
-                          
-          # Accumulate the offset difference.
-          size_diff += string_table_map[i].length - orig_sym.length
-        end
-      end
-    end
-  end
-  
-  offset += load_cmd.cmdsize
-end
-
-# OK, now lets rewrite the symbol table. Offsets may have changed, but the size doesn't.
-new_symbol_table = ''
-i = 0
-symbols.each do |symbol|
-  puts "  - Mapped #{i} symbols..." if i % 10000 == 0 and i > 0
-  symbol.strtableoffset = offset_map[symbol.strtableoffset] if symbol.strtableoffset > 1
-  new_symbol_table << symbol
-  i += 1
-end
-
-# OK, now lets rewrite the string table. The size will be different if mappings have occurred.
-new_string_table = string_table_map.keys.sort.collect { |i| string_table_map[i] }.join("\x00")
-
-# Next, modify the LC_SYMTAB header.
-size_diff = new_string_table.length - sym_cmd.strsize
-sym_cmd.strsize = new_string_table.length
-
-# Lastly, modify the LINKEDIT segment if it exists.
-if link_cmd
-  puts "Size changed by #{size_diff} bytes, rewriting LINKEDIT segment."
-  link_cmd.filesize += size_diff
-  SegmentCommand.round_byte_length.times { |i| data[link_cmd_offset + i] = link_cmd[i] }
-end
-
-# Create the new file in memory. First, copy the new symbol table header into place.
-24.times { |i| data[symbol_table_offset + i] = sym_cmd[i] }
-
-# Now copy the new symbol table.
-new_symbol_table.length.times { |i| data[sym_cmd.symoff + i] = new_symbol_table[i] }
-
-# Finally, add the new string table.
-data = data[0..string_table_offset-1] + new_string_table
-
-puts "Output file is #{data.length} bytes long."
-open("output.so", "wb").write(data)
diff --git a/tools/Mach5/wrapper.rb b/tools/Mach5/wrapper.rb
deleted file mode 100755 (executable)
index 30b25c4..0000000
+++ /dev/null
@@ -1,1877 +0,0 @@
-#!/usr/bin/env ruby
-# Class for packed binary data, with defined bitfields and accessors for them.
-# See {intro.txt}[link:../doc/files/intro_txt.html] for an overview.
-#
-# Data after the end of the defined fields is accessible using the +rest+
-# declaration. See examples/ip.rb. Nested fields can be declared using +nest+.
-# See examples/nest.rb.
-#
-# Note that all string methods are still available: length, grep, etc.
-# The String#replace method is useful.
-#
-class BitStruct < String
-
-  class Field
-    # Offset of field in bits.
-    attr_reader :offset
-    
-    # Length of field in bits.
-    attr_reader :length
-    alias size length
-    
-    # Name of field (used for its accessors).
-    attr_reader :name
-    
-    # Options, such as :default (varies for each field subclass).
-    # In general, options can be provided as strings or as symbols.
-    attr_reader :options
-    
-    # Display name of field (used for printing).
-    attr_reader :display_name
-    
-    # Default value.
-    attr_reader :default
-    
-    # Format for printed value of field.
-    attr_reader :format
-    
-    # Subclasses can override this to define a default for all fields of this
-    # class, not just the one currently being added to a BitStruct class, a
-    # "default default" if you will. The global default, if #default returns
-    # nil, is to fill the field with zero. Most field classes just let this
-    # default stand. The default can be overridden per-field when a BitStruct
-    # class is defined.
-    def self.default; nil; end
-
-    # Used in describe.
-    def self.class_name
-      @class_name ||= name[/\w+$/]
-    end
-    
-    # Used in describe. Can be overridden per-subclass, as in NestedField.
-    def class_name
-      self.class.class_name
-    end
-
-    # Yield the description of this field, as an array of 5 strings: byte
-    # offset, type, name, size, and description. The opts hash may have:
-    #
-    # :expand ::  if the value is true, expand complex fields
-    #
-    # (Subclass implementations may yield more than once for complex fields.)
-    #
-    def describe opts
-      bits = size
-      if bits > 32 and bits % 8 == 0
-        len_str = "%dB" % (bits/8)
-      else
-        len_str = "%db" % bits
-      end
-      
-      byte_offset = offset / 8 + (opts[:byte_offset] || 0)
-
-      yield ["@%d" % byte_offset, class_name, name, len_str, display_name]
-    end
-
-    # Options are _display_name_, _default_, and _format_ (subclasses of Field
-    # may add other options).
-    def initialize(offset, length, name, opts = {})
-      @offset, @length, @name, @options =
-        offset, length, name, opts
-      
-      @display_name = opts[:display_name] || opts["display_name"]
-      @default      = opts[:default] || opts["default"] || self.class.default
-      @format       = opts[:format] || opts["format"]
-    end
-    
-    # Inspect the value of this field in the specified _obj_.
-    def inspect_in_object(obj, opts)
-      val = obj.send(name)
-      str =
-        begin
-          val.inspect(opts)
-        rescue ArgumentError # assume: "wrong number of arguments (1 for 0)"
-          val.inspect
-        end
-      (f=@format) ? (f % str) : str
-    end
-    
-    # Normally, all fields show up in inspect, but some, such as padding,
-    # should not.
-    def inspectable?; true; end
-  end
-  
-  NULL_FIELD = Field.new(0, 0, :null, :display_name => "null field")
-  
-  # Raised when a field is added after an instance has been created. Fields
-  # cannot be added after this point.
-  class ClosedClassError < StandardError; end
-
-  # Raised if the chosen field name is not allowed, either because another
-  # field by that name exists, or because a method by that name exists.
-  class FieldNameError < StandardError; end
-  
-  @default_options = {}
-    
-  class << self
-    # ------------------------
-    # :section: field access methods
-    #
-    # For introspection and metaprogramming.
-    #
-    # ------------------------
-
-    # Return the list of fields for this class.
-    def fields
-      @fields ||= self == BitStruct ? [] : superclass.fields.dup
-    end
-    
-    # Return the list of fields defined by this class, not inherited
-    # from the superclass.
-    def own_fields
-      @own_fields ||= []
-    end
-
-    # Add a field to the BitStruct (usually, this is only used internally).
-    def add_field(name, length, opts = {})
-      round_byte_length ## just to make sure this has been calculated
-      ## before adding anything
-      
-      name = name.to_sym
-      
-      if @closed
-        raise ClosedClassError, "Cannot add field #{name}: " +
-          "The definition of the #{self.inspect} BitStruct class is closed."
-      end
-
-      if fields.find {|f|f.name == name}
-        raise FieldNameError, "Field #{name} is already defined as a field."
-      end
-
-      if instance_methods(true).find {|m| m == name}
-        if opts[:allow_method_conflict] || opts["allow_method_conflict"]
-          warn "Field #{name} is already defined as a method."
-        else
-          raise FieldNameError,"Field #{name} is already defined as a method."
-        end
-      end
-      
-      field_class = opts[:field_class]
-      
-      prev = fields[-1] || NULL_FIELD
-      offset = prev.offset + prev.length
-      field = field_class.new(offset, length, name, opts)
-      field.add_accessors_to(self)
-      fields << field
-      own_fields << field
-      @bit_length += field.length
-      @round_byte_length = (bit_length/8.0).ceil
-
-      if @initial_value
-        diff = @round_byte_length - @initial_value.length
-        if diff > 0
-          @initial_value << "\0" * diff
-        end
-      end
-
-      field
-    end
-
-    def parse_options(ary, default_name, default_field_class) # :nodoc:
-      opts = ary.grep(Hash).first || {}
-      opts = default_options.merge(opts)
-      
-      opts[:display_name]  = ary.grep(String).first || default_name
-      opts[:field_class]   = ary.grep(Class).first || default_field_class
-      
-      opts
-    end
-    
-    # Get or set the hash of default options for the class, which apply to all
-    # fields. Changes take effect immediately, so can be used alternatingly with
-    # blocks of field declarations. If +h+ is provided, update the default
-    # options with that hash. Default options are inherited.
-    #
-    # This is especially useful with the <tt>:endian => val</tt> option.
-    def default_options h = nil
-      @default_options ||= superclass.default_options.dup
-      if h
-        @default_options.merge! h
-      end
-      @default_options
-    end
-    
-    # Length, in bits, of this object.
-    def bit_length
-      @bit_length ||= fields.inject(0) {|a, f| a + f.length}
-    end
-    
-    # Length, in bytes (rounded up), of this object.
-    def round_byte_length
-      @round_byte_length ||= (bit_length/8.0).ceil
-    end
-    
-    def closed! # :nodoc:
-      @closed = true
-    end
-
-    def field_by_name name
-      @field_by_name ||= {}
-      field = @field_by_name[name]
-      unless field
-        field = fields.find {|f| f.name == name}
-        @field_by_name[name] = field if field
-      end
-      field
-    end
-  end
-  
-  # Return the list of fields for this class.
-  def fields
-    self.class.fields
-  end
-  
-  # Return the field with the given name.
-  def field_by_name name
-    self.class.field_by_name name
-  end
-
-  # ------------------------
-  # :section: metadata inspection methods
-  #
-  # Methods to textually describe the format of a BitStruct subclass.
-  #
-  # ------------------------
-
-  class << self
-    # Default format for describe. Fields are byte, type, name, size,
-    # and description.
-    DESCRIBE_FORMAT = "%8s: %-12s %-14s[%4s] %s"
-    
-    # Can be overridden to use a different format.
-    def describe_format
-      DESCRIBE_FORMAT
-    end
-
-    # Textually describe the fields of this class of BitStructs.
-    # Returns a printable table (array of line strings), based on +fmt+,
-    # which defaults to #describe_format, which defaults to +DESCRIBE_FORMAT+.
-    def describe(fmt = nil, opts = {})
-      if block_given?
-        fields.each do |field|
-          field.describe(opts) do |desc|
-            yield desc
-          end
-        end
-        nil
-        
-      else
-        fmt ||= describe_format
-
-        result = []
-
-        unless opts[:omit_header]
-          result << fmt % ["byte", "type", "name", "size", "description"]
-          result << "-"*70
-        end
-
-        fields.each do |field|
-          field.describe(opts) do |desc|
-            result << fmt % desc
-          end
-        end
-
-        unless opts[:omit_footer]
-          result << @note if @note
-        end
-
-        result
-      end
-    end
-    
-    # Subclasses can use this to append a string (or several) to the #describe
-    # output. Notes are not cumulative with inheritance. When used with no
-    # arguments simply returns the note string
-    def note(*str)
-      @note = str unless str.empty?
-      @note
-    end
-  end
-  
-  # ------------------------
-  # :section: initialization and conversion methods
-  #
-  # ------------------------
-
-  # Initialize the string with the given string or bitstruct, or with a hash of
-  # field=>value pairs, or with the defaults for the BitStruct subclass. Fields
-  # can be strings or symbols. Finally, if a block is given, yield the instance
-  # for modification using accessors.
-  def initialize(value = nil)   # :yields: instance
-    self << self.class.initial_value
-
-    case value
-    when Hash
-      value.each do |k, v|
-        send "#{k}=", v
-      end
-    
-    when nil
-      
-    else
-      self[0, value.length] = value
-    end
-    
-    self.class.closed!
-    yield self if block_given?
-  end
-  
-  DEFAULT_TO_H_OPTS = {
-    :convert_keys   => :to_sym,
-    :include_rest   => true
-  }
-  
-  # Returns a hash of {name=>value,...} for each field. By default, include
-  # the rest field.
-  # Keys are symbols derived from field names using +to_sym+, unless
-  # <tt>opts[:convert_keys]<\tt> is set to some other method name.
-  def to_h(opts = DEFAULT_TO_H_OPTS)
-    converter = opts[:convert_keys] || :to_sym
-
-    fields_for_to_h = fields
-    if opts[:include_rest] and (rest_field = self.class.rest_field)
-      fields_for_to_h += [rest_field]
-    end
-    
-    fields_for_to_h.inject({}) do |h,f|
-      h[f.name.send(converter)] = send(f.name)
-      h
-    end
-  end
-  
-  # Returns an array of values of the fields of the BitStruct. By default,
-  # include the rest field.
-  def to_a(include_rest = true)
-    ary =
-      fields.map do |f|
-        send(f.name)
-      end
-    
-    if include_rest and (rest_field = self.class.rest_field)
-      ary << send(rest_field.name)
-    end
-  end
-  
-  class << self
-    # The unique "prototype" object from which new instances are copied.
-    # The fields of this instance can be modified in the class definition
-    # to set default values for the fields in that class. (Otherwise, defaults
-    # defined by the fields themselves are used.) A copy of this object is
-    # inherited in subclasses, which they may override using defaults and
-    # by writing to the initial_value object itself.
-    #
-    # If called with a block, yield the initial value object before returning
-    # it. Useful for customization within a class definition.
-    #
-    def initial_value   # :yields: the initial value
-      unless @initial_value
-        iv = defined?(superclass.initial_value) ? 
-          superclass.initial_value.dup : ""
-        if iv.length < round_byte_length
-          iv << "\0" * (round_byte_length - iv.length)
-        end
-
-        @initial_value = "" # Serves as initval while the real initval is inited
-        @initial_value = new(iv)
-        @closed = false # only creating the first _real_ instance closes.
-        
-        fields.each do |field|
-          @initial_value.send("#{field.name}=", field.default) if field.default
-        end
-      end
-      yield @initial_value if block_given?
-      @initial_value
-    end
-    
-    # Take +data+ (a string or BitStruct) and parse it into instances of
-    # the +classes+, returning them in an array. The classes can be given
-    # as an array or a separate arguments. (For parsing a string into a _single_
-    # BitStruct instance, just use the #new method with the string as an arg.)
-    def parse(data, *classes)
-      classes.flatten.map do |c|
-        c.new(data.slice!(0...c.round_byte_length))
-      end
-    end
-    
-    # Join the given structs (array or multiple args) as a string.
-    # Actually, the inherited String#+ instance method is the same, as is using
-    # Array#join.
-    def join(*structs)
-      structs.flatten.map {|struct| struct.to_s}.join("")
-    end
-  end
-
-  # ------------------------
-  # :section: inspection methods
-  #
-  # ------------------------
-
-  DEFAULT_INSPECT_OPTS = {
-    :format           => "#<%s %s>",
-    :field_format     => "%s=%s",
-    :separator        => ", ",
-    :field_name_meth  => :name,
-    :include_rest     => true
-  }
-  
-  DETAILED_INSPECT_OPTS = {
-    :format           => "%s:\n%s",
-    :field_format     => "%30s = %s",
-    :separator        => "\n",
-    :field_name_meth  => :display_name,
-    :include_rest     => true
-  }
-  
-  # A standard inspect method which does not add newlines.
-  def inspect(opts = DEFAULT_INSPECT_OPTS)
-    field_format = opts[:field_format]
-    field_name_meth = opts[:field_name_meth]
-    
-    fields_for_inspect = fields.select {|field| field.inspectable?}
-    if opts[:include_rest] and (rest_field = self.class.rest_field)
-      fields_for_inspect << rest_field
-    end
-    
-    ary = fields_for_inspect.map do |field|
-      field_format %
-       [field.send(field_name_meth),
-        field.inspect_in_object(self, opts)]
-    end
-        
-    body = ary.join(opts[:separator])
-    
-    opts[:format] % [self.class, body]
-  end
-  
-  # A more visually appealing inspect method that puts each field/value on
-  # a separate line. Very useful when output is scrolling by on a screen.
-  #
-  # (This is actually a convenience method to call #inspect with the
-  # DETAILED_INSPECT_OPTS opts.)
-  def inspect_detailed
-    inspect(DETAILED_INSPECT_OPTS)
-  end
-
-  # ------------------------
-  # :section: field declaration methods
-  #
-  # ------------------------
-  
-  # Define accessors for a variable length substring from the end of
-  # the defined fields to the end of the BitStruct. The _rest_ may behave as
-  # a String or as some other String or BitStruct subclass.
-  #
-  # This does not add a field, which is useful because a superclass can have
-  # a rest method which accesses subclass data. In particular, #rest does
-  # not affect the #round_byte_length class method. Of course, any data
-  # in rest does add to the #length of the BitStruct, calculated as a string.
-  # Also, _rest_ is not inherited.
-  #
-  # The +ary+ argument(s) work as follows:
-  #
-  # If a class is provided, use it for the Field class (String by default).
-  # If a string is provided, use it for the display_name (+name+ by default).
-  # If a hash is provided, use it for options.
-  #
-  # *Warning*: the rest reader method returns a copy of the field, so
-  # accessors on that returned value do not affect the original rest field. 
-  #
-  def self.rest(name, *ary)
-    if @rest_field
-      raise ArgumentError, "Duplicate rest field: #{name.inspect}."
-    end
-    
-    opts = parse_options(ary, name, String)
-    offset = round_byte_length
-    byte_range = offset..-1
-    class_eval do
-      field_class = opts[:field_class]
-      define_method name do ||
-        field_class.new(self[byte_range])
-      end
-
-      define_method "#{name}=" do |val|
-        self[byte_range] = val
-      end
-      
-      @rest_field = Field.new(offset, -1, name, {
-        :display_name => opts[:display_name],
-        :rest_class => field_class
-      })
-    end
-  end
-  
-  # Not included with the other fields, but accessible separately.
-  def self.rest_field; @rest_field; end
-end
-#require 'bit-struct/bit-struct'
-
-class BitStruct
-  # Class for fixed length binary strings of characters.
-  # Declared with BitStruct.char.
-  class CharField < Field
-    #def self.default
-    #  don't define this, since it must specify N nulls and we don't know N
-    #end
-    
-    # Used in describe.
-    def self.class_name
-      @class_name ||= "char"
-    end
-
-    def add_accessors_to(cl, attr = name) # :nodoc:
-      unless offset % 8 == 0
-        raise ArgumentError,
-          "Bad offset, #{offset}, for #{self.class} #{name}." +
-          " Must be multiple of 8."
-      end
-      
-      unless length % 8 == 0
-        raise ArgumentError,
-          "Bad length, #{length}, for #{self.class} #{name}." +
-          " Must be multiple of 8."
-      end
-      
-      offset_byte = offset / 8
-      length_byte = length / 8
-      last_byte = offset_byte + length_byte - 1
-      byte_range = offset_byte..last_byte
-      val_byte_range = 0..length_byte-1
-
-      cl.class_eval do
-        define_method attr do ||
-          self[byte_range].to_s
-        end
-
-        define_method "#{attr}=" do |val|
-          val = val.to_s
-          if val.length < length_byte
-            val += "\0" * (length_byte - val.length)
-          end
-          self[byte_range] = val[val_byte_range]
-        end
-      end
-    end
-  end
-  
-  class << self
-    # Define a char string field in the current subclass of BitStruct,
-    # with the given _name_ and _length_ (in bits). Trailing nulls _are_
-    # considered part of the string.
-    #
-    # If a class is provided, use it for the Field class.
-    # If a string is provided, use it for the display_name.
-    # If a hash is provided, use it for options.
-    #
-    # Note that the accessors have COPY semantics, not reference.
-    #
-    def char(name, length, *rest)
-      opts = parse_options(rest, name, CharField)
-      add_field(name, length, opts)
-    end
-    alias string char
-  end
-end
-#require 'bit-struct/bit-struct'
-
-class BitStruct
-  # Class for floats (single and double precision) in network order.
-  # Declared with BitStruct.float.
-  class FloatField < Field
-    # Used in describe.
-    def self.class_name
-      @class_name ||= "float"
-    end
-    
-    def add_accessors_to(cl, attr = name) # :nodoc:
-      unless offset % 8 == 0
-        raise ArgumentError,
-          "Bad offset, #{offset}, for #{self.class} #{name}." +
-          " Must be multiple of 8."
-      end
-      
-      unless length == 32 or length == 64
-        raise ArgumentError,
-          "Bad length, #{length}, for #{self.class} #{name}." +
-          " Must be 32 or 64."
-      end
-      
-      offset_byte = offset / 8
-      length_byte = length / 8
-      last_byte = offset_byte + length_byte - 1
-      byte_range = offset_byte..last_byte
-
-      endian = (options[:endian] || options["endian"]).to_s
-      case endian
-      when "native"
-        ctl = case length
-          when 32; "f"
-          when 64; "d"
-        end
-      when "little"
-        ctl = case length
-          when 32; "e"
-          when 64; "E"
-        end
-      when "network", "big", ""
-        ctl = case length
-          when 32; "g"
-          when 64; "G"
-        end
-      else
-        raise ArgumentError,
-          "Unrecognized endian option: #{endian.inspect}"
-      end
-      
-      cl.class_eval do
-        define_method attr do ||
-          self[byte_range].unpack(ctl).first
-        end
-
-        define_method "#{attr}=" do |val|
-          self[byte_range] = [val].pack(ctl)
-        end
-      end
-    end
-  end
-
-  class << self
-    # Define a floating point field in the current subclass of BitStruct,
-    # with the given _name_ and _length_ (in bits).
-    #
-    # If a class is provided, use it for the Field class.
-    # If a string is provided, use it for the display_name.
-    # If a hash is provided, use it for options.
-    #
-    # The <tt>:endian => :native</tt> option overrides the default of
-    # <tt>:network</tt> byte ordering, in favor of native byte ordering. Also
-    # permitted are <tt>:big</tt> (same as <tt>:network</tt>) and
-    # <tt>:little</tt>.
-    #
-    def float name, length, *rest
-      opts = parse_options(rest, name, FloatField)
-      add_field(name, length, opts)
-    end
-  end
-end
-#require 'bit-struct/char-field'
-
-class BitStruct
-  # Class for char fields that can be accessed with values like
-  # "xxx.xxx.xxx.xxx", where each xxx is up to 3 decimal digits representing a
-  # single octet. The original string-based accessors are still available with
-  # the <tt>_chars</tt> suffix.
-  # 
-  # Declared with BitStruct.octets.
-  class OctetField < BitStruct::CharField
-    # Used in describe.
-    def self.class_name
-      @class_name ||= "octets"
-    end
-    
-    SEPARATOR = "."
-    FORMAT    = "%d"
-    BASE      = 10
-
-    def add_accessors_to(cl, attr = name) # :nodoc:
-      attr_chars = "#{attr}_chars"
-      super(cl, attr_chars)
-      sep   = self.class::SEPARATOR
-      base  = self.class::BASE
-      fmt   = self.class::FORMAT
-      
-      cl.class_eval do
-        define_method attr do ||
-          ary = []
-          send(attr_chars).each_byte do  |c|
-            ary << fmt % c
-          end
-          ary.join(sep)
-        end
-        
-        old_writer = "#{attr_chars}="
-
-        define_method "#{attr}=" do |val|
-          data = val.split(sep).map{|s|s.to_i(base)}.pack("c*")
-          send(old_writer, data)
-        end
-      end
-    end
-  end
-  
-  class << self
-    # Define an octet string field in the current subclass of BitStruct,
-    # with the given _name_ and _length_ (in bits). Trailing nulls are
-    # not considered part of the string. The field is accessed using
-    # period-separated decimal digits.
-    #
-    # If a class is provided, use it for the Field class.
-    # If a string is provided, use it for the display_name.
-    # If a hash is provided, use it for options.
-    #
-    def octets(name, length, *rest)
-      opts = parse_options(rest, name, OctetField)
-      add_field(name, length, opts)
-    end
-  end
-end
-#require 'bit-struct/char-field'
-
-class BitStruct
-  # Class for char fields that can be accessed with values like
-  # "xx:xx:xx:xx", where each xx is up to 2 hex digits representing a
-  # single octet. The original string-based accessors are still available with
-  # the <tt>_chars</tt> suffix.
-  # 
-  # Declared with BitStruct.hex_octets.
-  class HexOctetField < BitStruct::OctetField
-    # Used in describe.
-    def self.class_name
-      @class_name ||= "hex_octets"
-    end
-    
-    SEPARATOR = ":"
-    FORMAT    = "%02x"
-    BASE      = 16
-  end
-  
-  class << self
-    # Define an octet string field in the current subclass of BitStruct,
-    # with the given _name_ and _length_ (in bits). Trailing nulls are
-    # not considered part of the string. The field is accessed using
-    # period-separated hex digits.
-    #
-    # If a class is provided, use it for the Field class.
-    # If a string is provided, use it for the display_name.
-    # If a hash is provided, use it for options.
-    #
-    def hex_octets(name, length, *rest)
-      opts = parse_options(rest, name, HexOctetField)
-      add_field(name, length, opts)
-    end
-  end
-end
-#require 'bit-struct/bit-struct'
-
-class BitStruct
-  # Class for nesting a BitStruct as a field within another BitStruct.
-  # Declared with BitStruct.nest.
-  class NestedField < Field
-    def initialize(*args)
-      super
-    end
-    
-    # Used in describe.
-    def self.class_name
-      @class_name ||= "nest"
-    end
-    
-    def class_name
-      @class_name ||= nested_class.name[/\w+$/]
-    end
-    
-    def nested_class
-      @nested_class ||= options[:nested_class] || options["nested_class"]
-    end
-
-    def describe opts
-      if opts[:expand]
-        opts = opts.dup
-        opts[:byte_offset] = offset / 8
-        opts[:omit_header] = opts[:omit_footer] = true
-        nested_class.describe(nil, opts) {|desc| yield desc}
-      else
-        super
-      end
-    end
-
-    def add_accessors_to(cl, attr = name) # :nodoc:
-      unless offset % 8 == 0
-        raise ArgumentError,
-          "Bad offset, #{offset}, for nested field #{name}." +
-          " Must be multiple of 8."
-      end
-      
-      unless length % 8 == 0
-        raise ArgumentError,
-          "Bad length, #{length}, for nested field #{name}." +
-          " Must be multiple of 8."
-      end
-      
-      offset_byte = offset / 8
-      length_byte = length / 8
-      last_byte = offset_byte + length_byte - 1
-      byte_range = offset_byte..last_byte
-      val_byte_range = 0..length_byte-1
-
-      nc = nested_class
-      
-      cl.class_eval do
-        define_method attr do ||
-          nc.new(self[byte_range])
-        end
-
-        define_method "#{attr}=" do |val|
-          if val.length != length_byte
-            raise ArgumentError, "Size mismatch in nested struct assignment " +
-              "to #{attr} with value #{val.inspect}"
-          end
-          
-          if val.class != nc
-            warn "Type mismatch in nested struct assignment " +
-              "to #{attr} with value #{val.inspect}"
-          end
-          
-          self[byte_range] = val[val_byte_range]
-        end
-      end
-    end
-  end
-  
-  class << self
-    # Define a nested field in the current subclass of BitStruct,
-    # with the given _name_ and _nested_class_. Length is determined from
-    # _nested_class_.
-    #
-    # In _rest_:
-    #
-    # If a class is provided, use it for the Field class (i.e. <=NestedField).
-    # If a string is provided, use it for the display_name.
-    # If a hash is provided, use it for options.
-    #
-    # WARNING: the accessors have COPY semantics, not reference. When you call a
-    # reader method to get the nested structure, you get a *copy* of that data.
-    #
-    # For example:
-    #
-    #   class Sub < BitStruct
-    #     unsigned :x,    8
-    #   end
-    #
-    #   class A < BitStruct
-    #     nest    :n,  Sub
-    #   end
-    #
-    #   a = A.new
-    #
-    #   p a  # ==> #<A n=#<Sub x=0>>
-    #
-    #   # This fails to set x in a.
-    #   a.n.x = 3
-    #   p a  # ==> #<A n=#<Sub x=0>>
-    #
-    #   # This works
-    #   n = a.n
-    #   n.x = 3
-    #   a.n = n
-    #   p a  # ==> #<A n=#<Sub x=3>>
-    # 
-    def nest(name, nested_class, *rest)
-      opts = parse_options(rest, name, NestedField)
-      opts[:default] ||= nested_class.initial_value.dup
-      opts[:nested_class] = nested_class
-      field = add_field(name, nested_class.bit_length, opts)
-      field
-    end
-    alias struct nest
-  end
-end
-#require 'bit-struct/bit-struct'
-
-class BitStruct
-  # Class for fixed length padding.
-  class PadField < Field
-    # Used in describe.
-    def self.class_name
-      @class_name ||= "padding"
-    end
-
-    def add_accessors_to(cl, attr = name) # :nodoc:
-      # No accessors for padding.
-    end
-
-    def inspectable?; false; end
-  end
-  
-  class << self
-    # Define a padding field in the current subclass of BitStruct,
-    # with the given _name_ and _length_ (in bits).
-    #
-    # If a class is provided, use it for the Field class.
-    # If a string is provided, use it for the display_name.
-    # If a hash is provided, use it for options.
-    #
-    def pad(name, length, *rest)
-      opts = parse_options(rest, name, PadField)
-      add_field(name, length, opts)
-    end
-    alias padding pad
-  end
-end
-#require 'bit-struct/bit-struct'
-
-class BitStruct
-  # Class for signed integers in network order, 1-16 bits, or 8n bits.
-  # Declared with BitStruct.signed.
-  class SignedField < Field
-    # Used in describe.
-    def self.class_name
-      @class_name ||= "signed"
-    end
-    
-    def add_accessors_to(cl, attr = name) # :nodoc:
-      offset_byte = offset / 8
-      offset_bit = offset % 8
-      
-      length_bit = offset_bit + length
-      length_byte = (length_bit/8.0).ceil
-      last_byte = offset_byte + length_byte - 1
-      max = 2**length-1
-      mid = 2**(length-1)
-      max_unsigned = 2**length
-      to_signed = proc {|n| (n>=mid) ? n - max_unsigned : n}
-#      to_signed = proc {|n| (n>=mid) ? -((n ^ max) + 1) : n}
-      
-      divisor = options[:fixed] || options["fixed"]
-      divisor_f = divisor && divisor.to_f
-#      if divisor and not divisor.is_a? Fixnum
-#        raise ArgumentError, "fixed-point divisor must be a fixnum"
-#      end
-
-      endian = (options[:endian] || options["endian"]).to_s
-      case endian
-      when "native"
-        ctl = length_byte <= 2 ? "s" : "l"
-        if length == 16 or length == 32
-          to_signed = proc {|n| n}
-          # with pack support, to_signed can be replaced with no-op
-        end
-      when "little"
-        ctl = length_byte <= 2 ? "v" : "V"
-      when "network", "big", ""
-        ctl = length_byte <= 2 ? "n" : "N"
-      else
-        raise ArgumentError,
-          "Unrecognized endian option: #{endian.inspect}"
-      end
-      
-      data_is_big_endian =
-        ([1234].pack(ctl) == [1234].pack(length_byte <= 2 ? "n" : "N"))
-      
-      if length_byte == 1
-        rest = 8 - length_bit
-        mask  = ["0"*offset_bit + "1"*length + "0"*rest].pack("B8")[0]
-        mask2 = ["1"*offset_bit + "0"*length + "1"*rest].pack("B8")[0]
-        
-        cl.class_eval do
-          if divisor
-            define_method attr do ||
-              to_signed[(self[offset_byte] & mask) >> rest] / divisor_f
-            end
-
-            define_method "#{attr}=" do |val|
-              val = (val * divisor).round
-              self[offset_byte] =
-                (self[offset_byte] & mask2) | ((val<<rest) & mask)
-            end
-
-          else
-            define_method attr do ||
-              to_signed[(self[offset_byte] & mask) >> rest]
-            end
-
-            define_method "#{attr}=" do |val|
-              self[offset_byte] =
-                (self[offset_byte] & mask2) | ((val<<rest) & mask)
-            end
-          end
-        end
-      
-      elsif offset_bit == 0 and length % 8 == 0
-        field_length = length
-        byte_range = offset_byte..last_byte
-        
-        cl.class_eval do
-          case field_length
-          when 8
-            if divisor
-              define_method attr do ||
-                to_signed[self[offset_byte]] / divisor_f
-              end
-
-              define_method "#{attr}=" do |val|
-                val = (val * divisor).round
-                self[offset_byte] = val
-              end
-          
-            else
-              define_method attr do ||
-                to_signed[self[offset_byte]]
-              end
-
-              define_method "#{attr}=" do |val|
-                self[offset_byte] = val
-              end
-            end
-        
-          when 16, 32
-            if divisor
-              define_method attr do ||
-                to_signed[self[byte_range].unpack(ctl).first] / divisor_f
-              end
-
-              define_method "#{attr}=" do |val|
-                val = (val * divisor).round
-                self[byte_range] = [val].pack(ctl)
-              end
-            
-            else
-              define_method attr do ||
-                to_signed[self[byte_range].unpack(ctl).first]
-              end
-
-              define_method "#{attr}=" do |val|
-                self[byte_range] = [val].pack(ctl)
-              end
-            end
-          
-          else
-            reader_helper = proc do |substr|
-              bytes = substr.unpack("C*")
-              bytes.reverse! unless data_is_big_endian
-              bytes.inject do |sum, byte|
-                (sum << 8) + byte
-              end
-            end
-            
-            writer_helper = proc do |val|
-              bytes = []
-              val += max_unsigned if val < 0
-              while val > 0
-                bytes.push val % 256
-                val = val >> 8
-              end
-              if bytes.length < length_byte
-                bytes.concat [0] * (length_byte - bytes.length)
-              end
-
-              bytes.reverse! if data_is_big_endian
-              bytes.pack("C*")
-            end
-            
-            if divisor
-              define_method attr do ||
-                to_signed[reader_helper[self[byte_range]] / divisor_f]
-              end
-              
-              define_method "#{attr}=" do |val|
-                self[byte_range] = writer_helper[(val * divisor).round]
-              end
-            
-            else
-              define_method attr do ||
-                to_signed[reader_helper[self[byte_range]]]
-              end
-              
-              define_method "#{attr}=" do |val|
-                self[byte_range] = writer_helper[val]
-              end
-            end
-          end
-        end
-
-      elsif length_byte == 2 # unaligned field that fits within two whole bytes
-        byte_range = offset_byte..last_byte
-        rest = 16 - length_bit
-        
-        mask  = ["0"*offset_bit + "1"*length + "0"*rest]
-        mask = mask.pack("B16").unpack(ctl).first
-        
-        mask2 = ["1"*offset_bit + "0"*length + "1"*rest]
-        mask2 = mask2.pack("B16").unpack(ctl).first
-
-        cl.class_eval do
-          if divisor
-            define_method attr do ||
-              to_signed[(self[byte_range].unpack(ctl).first & mask) >> rest] /
-                 divisor_f
-            end
-
-            define_method "#{attr}=" do |val|
-              val = (val * divisor).round
-              x = (self[byte_range].unpack(ctl).first & mask2) |
-                ((val<<rest) & mask)
-              self[byte_range] = [x].pack(ctl)
-            end
-
-          else
-            define_method attr do ||
-              to_signed[(self[byte_range].unpack(ctl).first & mask) >> rest]
-            end
-
-            define_method "#{attr}=" do |val|
-              x = (self[byte_range].unpack(ctl).first & mask2) |
-                ((val<<rest) & mask)
-              self[byte_range] = [x].pack(ctl)
-            end
-          end
-        end
-      
-      elsif length_byte == 3 # unaligned field that fits within 3 whole bytes
-        byte_range = offset_byte..last_byte
-        rest = 32 - length_bit
-        
-        mask  = ["0"*offset_bit + "1"*length + "0"*rest]
-        mask = mask.pack("B32").unpack(ctl).first
-        
-        mask2 = ["1"*offset_bit + "0"*length + "1"*rest]
-        mask2 = mask2.pack("B32").unpack(ctl).first
-
-        cl.class_eval do
-          if divisor
-            define_method attr do ||
-              bytes = self[byte_range]
-              bytes << 0
-              to_signed[((bytes.unpack(ctl).first & mask) >> rest)] /
-                 divisor_f
-            end
-
-            define_method "#{attr}=" do |val|
-              val = (val * divisor).round
-              bytes = self[byte_range]
-              bytes << 0
-              x = (bytes.unpack(ctl).first & mask2) |
-                ((val<<rest) & mask)
-              self[byte_range] = [x].pack(ctl)[0..2]
-            end
-
-          else
-            define_method attr do ||
-              bytes = self[byte_range]
-              bytes << 0
-              to_signed[(bytes.unpack(ctl).first & mask) >> rest]
-            end
-
-            define_method "#{attr}=" do |val|
-              bytes = self[byte_range]
-              bytes << 0
-              x = (bytes.unpack(ctl).first & mask2) |
-                ((val<<rest) & mask)
-              self[byte_range] = [x].pack(ctl)[0..2]
-            end
-          end
-        end
-      
-      else
-        raise "unsupported: #{inspect}"
-      end
-    end
-  end
-
-  class << self
-    # Define a signed integer field in the current subclass of BitStruct,
-    # with the given _name_ and _length_ (in bits).
-    #
-    # If a class is provided, use it for the Field class.
-    # If a string is provided, use it for the display_name.
-    # If a hash is provided, use it for options.
-    #
-    # SignedField adds the <tt>:fixed => divisor</tt> option, which specifies
-    # that the internally stored value is interpreted as a fixed point real
-    # number with the specified +divisor+.
-    #
-    # The <tt>:endian => :native</tt> option overrides the default of
-    # <tt>:network</tt> byte ordering, in favor of native byte ordering. Also
-    # permitted are <tt>:big</tt> (same as <tt>:network</tt>) and
-    # <tt>:little</tt>.
-    #
-    def signed name, length, *rest
-      opts = parse_options(rest, name, SignedField)
-      add_field(name, length, opts)
-    end
-  end
-end
-#require 'bit-struct/bit-struct'
-
-class BitStruct
-  # Class for null-terminated printable text strings.
-  # Declared with BitStruct.text.
-  class TextField < Field
-    # Used in describe.
-    def self.class_name
-      @class_name ||= "text"
-    end
-
-    def add_accessors_to(cl, attr = name) # :nodoc:
-      unless offset % 8 == 0
-        raise ArgumentError,
-          "Bad offset, #{offset}, for #{self.class} #{name}." +
-          " Must be multiple of 8."
-      end
-      
-      unless length % 8 == 0
-        raise ArgumentError,
-          "Bad length, #{length}, for #{self.class} #{name}." +
-          " Must be multiple of 8."
-      end
-      
-      offset_byte = offset / 8
-      length_byte = length / 8
-      last_byte = offset_byte + length_byte - 1
-      byte_range = offset_byte..last_byte
-      val_byte_range = 0..length_byte-1
-
-      cl.class_eval do
-        define_method attr do ||
-          self[byte_range].sub(/\0*$/, "").to_s
-        end
-
-        define_method "#{attr}=" do |val|
-          val = val.to_s
-          if val.length < length_byte
-            val += "\0" * (length_byte - val.length)
-          end
-          self[byte_range] = val[val_byte_range]
-        end
-      end
-    end
-  end
-  
-  class << self
-    # Define a printable text string field in the current subclass of BitStruct,
-    # with the given _name_ and _length_ (in bits). Trailing nulls are
-    # _not_ considered part of the string.
-    #
-    # If a class is provided, use it for the Field class.
-    # If a string is provided, use it for the display_name.
-    # If a hash is provided, use it for options.
-    #
-    # Note that the accessors have COPY semantics, not reference.
-    #
-    def text(name, length, *rest)
-      opts = parse_options(rest, name, TextField)
-      add_field(name, length, opts)
-    end
-  end
-end
-#require 'bit-struct/bit-struct'
-
-class BitStruct
-  # Class for unsigned integers in network order, 1-16 bits, or 8n bits.
-  # Declared with BitStruct.unsigned.
-  class UnsignedField < Field
-    # Used in describe.
-    def self.class_name
-      @class_name ||= "unsigned"
-    end
-    
-    def add_accessors_to(cl, attr = name) # :nodoc:
-      offset_byte = offset / 8
-      offset_bit = offset % 8
-      
-      length_bit = offset_bit + length
-      length_byte = (length_bit/8.0).ceil
-      last_byte = offset_byte + length_byte - 1
-      
-      divisor = options[:fixed] || options["fixed"]
-      divisor_f = divisor && divisor.to_f
-#      if divisor and not divisor.is_a? Fixnum
-#        raise ArgumentError, "fixed-point divisor must be a fixnum"
-#      end
-      
-      endian = (options[:endian] || options["endian"]).to_s
-      case endian
-      when "native"
-        ctl = length_byte <= 2 ? "S" : "L"
-      when "little"
-        ctl = length_byte <= 2 ? "v" : "V"
-      when "network", "big", ""
-        ctl = length_byte <= 2 ? "n" : "N"
-      else
-        raise ArgumentError,
-          "Unrecognized endian option: #{endian.inspect}"
-      end
-      
-      data_is_big_endian =
-        ([1234].pack(ctl) == [1234].pack(length_byte <= 2 ? "n" : "N"))
-      
-      if length_byte == 1
-        rest = 8 - length_bit
-        mask  = ["0"*offset_bit + "1"*length + "0"*rest].pack("B8")[0]
-        mask2 = ["1"*offset_bit + "0"*length + "1"*rest].pack("B8")[0]
-        
-        cl.class_eval do
-          if divisor
-            define_method attr do ||
-              ((self[offset_byte] & mask) >> rest) / divisor_f
-            end
-
-            define_method "#{attr}=" do |val|
-              val = (val * divisor).round
-              self[offset_byte] =
-                (self[offset_byte] & mask2) | ((val<<rest) & mask)
-            end
-
-          else
-            define_method attr do ||
-              (self[offset_byte] & mask) >> rest
-            end
-
-            define_method "#{attr}=" do |val|
-              self[offset_byte] =
-                (self[offset_byte] & mask2) | ((val<<rest) & mask)
-            end
-          end
-        end
-      
-      elsif offset_bit == 0 and length % 8 == 0
-        field_length = length
-        byte_range = offset_byte..last_byte
-        
-        cl.class_eval do
-          case field_length
-          when 8
-            if divisor
-              define_method attr do ||
-                self[offset_byte] / divisor_f
-              end
-
-              define_method "#{attr}=" do |val|
-                val = (val * divisor).round
-                self[offset_byte] = val
-              end
-          
-            else
-              define_method attr do ||
-                self[offset_byte]
-              end
-
-              define_method "#{attr}=" do |val|
-                self[offset_byte] = val
-              end
-            end
-        
-          when 16, 32
-            if divisor
-              define_method attr do ||
-                self[byte_range].unpack(ctl).first / divisor_f
-              end
-
-              define_method "#{attr}=" do |val|
-                val = (val * divisor).round
-                self[byte_range] = [val].pack(ctl)
-              end
-            
-            else
-              define_method attr do ||
-                self[byte_range].unpack(ctl).first
-              end
-
-              define_method "#{attr}=" do |val|
-                self[byte_range] = [val].pack(ctl)
-              end
-            end
-          
-          else
-            reader_helper = proc do |substr|
-              bytes = substr.unpack("C*")
-              bytes.reverse! unless data_is_big_endian
-              bytes.inject do |sum, byte|
-                (sum << 8) + byte
-              end
-            end
-            
-            writer_helper = proc do |val|
-              bytes = []
-              while val > 0
-                bytes.push val % 256
-                val = val >> 8
-              end
-              if bytes.length < length_byte
-                bytes.concat [0] * (length_byte - bytes.length)
-              end
-
-              bytes.reverse! if data_is_big_endian
-              bytes.pack("C*")
-            end
-            
-            if divisor
-              define_method attr do ||
-                reader_helper[self[byte_range]] / divisor_f
-              end
-              
-              define_method "#{attr}=" do |val|
-                self[byte_range] = writer_helper[(val * divisor).round]
-              end
-            
-            else
-              define_method attr do ||
-                reader_helper[self[byte_range]]
-              end
-              
-              define_method "#{attr}=" do |val|
-                self[byte_range] = writer_helper[val]
-              end
-            end
-          end
-        end
-
-      elsif length_byte == 2 # unaligned field that fits within two whole bytes
-        byte_range = offset_byte..last_byte
-        rest = 16 - length_bit
-        
-        mask  = ["0"*offset_bit + "1"*length + "0"*rest]
-        mask = mask.pack("B16").unpack(ctl).first
-        
-        mask2 = ["1"*offset_bit + "0"*length + "1"*rest]
-        mask2 = mask2.pack("B16").unpack(ctl).first
-
-        cl.class_eval do
-          if divisor
-            define_method attr do ||
-              ((self[byte_range].unpack(ctl).first & mask) >> rest) /
-                 divisor_f
-            end
-
-            define_method "#{attr}=" do |val|
-              val = (val * divisor).round
-              x = (self[byte_range].unpack(ctl).first & mask2) |
-                ((val<<rest) & mask)
-              self[byte_range] = [x].pack(ctl)
-            end
-
-          else
-            define_method attr do ||
-              (self[byte_range].unpack(ctl).first & mask) >> rest
-            end
-
-            define_method "#{attr}=" do |val|
-              x = (self[byte_range].unpack(ctl).first & mask2) |
-                ((val<<rest) & mask)
-              self[byte_range] = [x].pack(ctl)
-            end
-          end
-        end
-      
-      elsif length_byte == 3 # unaligned field that fits within 3 whole bytes
-        byte_range = offset_byte..last_byte
-        rest = 32 - length_bit
-        
-        mask  = ["0"*offset_bit + "1"*length + "0"*rest]
-        mask = mask.pack("B32").unpack(ctl).first
-        
-        mask2 = ["1"*offset_bit + "0"*length + "1"*rest]
-        mask2 = mask2.pack("B32").unpack(ctl).first
-
-        cl.class_eval do
-          if divisor
-            define_method attr do ||
-              bytes = self[byte_range]
-              bytes << 0
-              ((bytes.unpack(ctl).first & mask) >> rest) /
-                 divisor_f
-            end
-
-            define_method "#{attr}=" do |val|
-              val = (val * divisor).round
-              bytes = self[byte_range]
-              bytes << 0
-              x = (bytes.unpack(ctl).first & mask2) |
-                ((val<<rest) & mask)
-              self[byte_range] = [x].pack(ctl)[0..2]
-            end
-
-          else
-            define_method attr do ||
-              bytes = self[byte_range]
-              bytes << 0
-              (bytes.unpack(ctl).first & mask) >> rest
-            end
-
-            define_method "#{attr}=" do |val|
-              bytes = self[byte_range]
-              bytes << 0
-              x = (bytes.unpack(ctl).first & mask2) |
-                ((val<<rest) & mask)
-              self[byte_range] = [x].pack(ctl)[0..2]
-            end
-          end
-        end
-      
-      else
-        raise "unsupported: #{inspect}"
-      end
-    end
-  end
-
-  class << self
-    # Define a unsigned integer field in the current subclass of BitStruct,
-    # with the given _name_ and _length_ (in bits).
-    #
-    # If a class is provided, use it for the Field class.
-    # If a string is provided, use it for the display_name.
-    # If a hash is provided, use it for options.
-    #
-    # UnsignedField adds the <tt>:fixed => divisor</tt> option, which specifies
-    # that the internally stored value is interpreted as a fixed point real
-    # number with the specified +divisor+.
-    #
-    # The <tt>:endian => :native</tt> option overrides the default of
-    # <tt>:network</tt> byte ordering, in favor of native byte ordering. Also
-    # permitted are <tt>:big</tt> (same as <tt>:network</tt>) and
-    # <tt>:little</tt>.
-    #
-    def unsigned name, length, *rest
-      opts = parse_options(rest, name, UnsignedField)
-      add_field(name, length, opts)
-    end
-  end
-end
-#require 'bit-struct/bit-struct'
-require 'yaml'
-
-class BitStruct
-  if RUBY_VERSION == "1.8.2"
-    def is_complex_yaml? # :nodoc:
-      true
-    end
-
-    YAML.add_ruby_type(/^bitstruct/) do |type, val|
-      subtype, subclass = YAML.read_type_class(type, Object)
-      subclass.new(val)
-    end
-
-    def to_yaml_type # :nodoc:
-      "!ruby/bitstruct:#{self.class}"
-    end
-
-    def to_yaml( opts = {} ) # :nodoc:
-      opts[:DocType] = self.class if Hash === opts
-      YAML.quick_emit(self.object_id, opts) do |out|
-        out.map(to_yaml_type) do |map|
-          fields.each do |field|
-            fn = field.name
-            map.add(fn, send(fn))
-          end
-        end
-      end
-    end
-
-  else
-    yaml_as "tag:path.berkeley.edu,2006:bitstruct"
-
-    def to_yaml_properties # :nodoc:
-      yaml_fields = fields.select {|field| field.inspectable?}
-      props = yaml_fields.map {|f| f.name.to_s}
-      if (rest_field = self.class.rest_field)
-        props << rest_field.name.to_s
-      end
-      props
-    end
-
-    # Return YAML representation of the BitStruct.
-    def to_yaml( opts = {} )
-      YAML::quick_emit( object_id, opts ) do |out|
-        out.map( taguri, to_yaml_style ) do |map|
-          to_yaml_properties.each do |m|
-            map.add( m, send( m ) )
-          end
-        end
-      end
-    end
-
-    def self.yaml_new( klass, tag, val ) # :nodoc:
-      unless Hash === val
-        raise YAML::TypeError, "Invalid BitStruct: " + val.inspect
-      end
-
-      bitstruct_name, bitstruct_type = YAML.read_type_class( tag, BitStruct )
-
-      st = bitstruct_type.new
-
-      val.each do |k,v|
-        st.send( "#{k}=", v )
-      end
-
-      st
-    end
-  end
-end
-
-#!/usr/bin/env ruby
-#
-#  Copyright (C) 2008 Elan Feingold (elan at bluemandrill dot com)
-#
-#  This Program is free software; you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2, or (at your option)
-#  any later version.
-#
-#  This Program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-#  GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with GNU Make; see the file COPYING.  If not, write to
-#  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-#  http://www.gnu.org/copyleft/gpl.html
-#
-#
-
-#require 'bit-struct'
-
-# For example, "_calloc" => "_wrap_calloc"
-prefix = '___wrap_'
-mappings = {
-#'calloc' => true,
-'clearerr' => true,
-'close' => true,
-'fclose' => true,
-'fdopen' => true,
-'feof' => true,
-'ferror' => true,
-'fflush' => true,
-'fgetc' => true,
-'fgetpos' => true,
-'fgets' => true,
-'fileno' => true,
-'flockfile' => true,
-'fopen' => true,
-'fopen64' => true,
-'fprintf' => true,
-'fputc' => true,
-'fputs' => true,
-'fread' => true,
-#'free' => true,
-'freopen' => true,
-'fseek' => true,
-'fsetpos' => true,
-'fstatvfs64' => true,
-'ftell' => true,
-'ftrylockfile' => true,
-'funlockfile' => true,
-'fwrite' => true,
-'getc_unlocked' => true,
-'ioctl' => true,
-'lseek' => true,
-'lseek64' => true,
-#'malloc' => true,
-'open' => true,
-'open64' => true,
-'popen' => true,
-'printf' => true,
-'read' => true,
-'opendir' => true,
-'readdir' => true,
-'closedir' => true,
-'rewinddir' => true,
-#'realloc' => true,
-'rewind' => true,
-'stat' => true,
-'fstat' => true,
-'ungetc' => true,
-'vfprintf' => true,
-'write' => true,
-'putc' => '___wrap__IO_putc',
-'getc' => '___wrap__IO_getc',
-'getc_unlocked' => '___wrap__IO_getc_unlocked'
-}
-
-prefix_python = '___py_wrap_'
-mappings_python = {
-  'getcwd' => true, 'chdir' => true, 'access' => true, 'unlink' => true, 'chmod' => true, 
-  'rmdir' => true, 'utime' => true, 'rename' => true, 'mkdir' => true,  
-  'dlopen' => true, 'dlclose' => true, 'dlsym' => true,
-  'lstat' => true
-}
-
-LC_SYMTAB = 0x02
-LC_SEGMENT = 0x01
-
-class MachHeader < BitStruct
-  hex_octets  :magic,       32, "Magic Number"
-  unsigned    :cputype,     32, "CPU Type", :endian => :native
-  unsigned    :cpusubtype,  32, "CPU Subtype", :endian => :native
-  unsigned    :filetype,    32, "File Type", :endian => :native
-  unsigned    :ncmds,       32, "Number of commands", :endian => :native
-  unsigned    :sizeofcmds,  32, "Size of commands", :endian => :native
-  unsigned    :flags,       32, "Flags", :endian => :native
-  rest        :data,            "Data"
-end
-
-class LoadCommand < BitStruct
-  unsigned    :cmd,         32, "Command", :endian => :native
-  unsigned    :cmdsize,     32, "Command Size", :endian => :native
-end
-
-class SymtabCommand < BitStruct
-  unsigned    :cmd,         32, "Command", :endian => :native
-  unsigned    :cmdsize,     32, "Command Size", :endian => :native
-  unsigned    :symoff,      32, "Symbol Offset", :endian => :native
-  unsigned    :nsyms,       32, "Number of Symbols", :endian => :native
-  unsigned    :stroff,      32, "String table offset", :endian => :native
-  unsigned    :strsize,     32, "Size of string table", :endian => :native
-end
-
-class SegmentCommand < BitStruct
-  unsigned    :cmd,         32, "Command", :endian => :native
-  unsigned    :cmdsize,     32, "Command Size", :endian => :native
-  char        :segname,    16*8, "Segment name", :endian => :native
-  unsigned    :vmaddr,      32, "VM Adddress", :endian => :native
-  unsigned    :vmsize,      32, "VM Size", :endian => :native
-  unsigned    :fileoff,     32, "File Offset", :endian => :native
-  unsigned    :filesize,    32, "File Size", :endian => :native
-end
-
-class SymtabEntry < BitStruct
-  unsigned  :strtableoffset, 32, "String table offset", :endian => :native
-  unsigned  :debuggingEntry,  3, "Debugging entry", :endian => :native
-  unsigned  :privateExternal, 1, "Is Private Enternal", :endian => :native
-  unsigned  :type,            3, "Type bits", :endian => :native
-  unsigned  :external,        1, "External symbol", :endian => :native
-  unsigned  :sectionNumber,   8, "Section number", :endian => :native
-  unsigned  :description,    16, "Description", :endian => :native
-  unsigned  :value,          32, "Value", :endian => :native
-end
-
-# Select which mapping to use.
-if ARGV.size() > 1 and ARGV[1].index('libpython') == 0
-  puts "Using Python mappings."
-  mappings = mappings_python
-  #prefix = prefix_python
-end
-
-data = open(ARGV[0]).read
-puts "Input file was #{data.length} bytes long."
-
-# Parse the header.
-header = MachHeader.new(data)
-sym_cmd = nil
-
-# String table.
-string_table = nil
-string_table_offset = nil
-string_table_map = {}
-offset_map = {}
-
-# Symbol table.
-symbol_table = nil
-symbol_table_offset = nil
-symbols = []
-
-# Link segment.
-link_cmd = nil
-link_cmd_offset = nil
-
-# Walk through all the commands.
-offset = data.size - header.data.size
-header.ncmds.times do |i|
-  load_cmd = LoadCommand.new(data[offset..-1])
-  
-  if load_cmd.cmd == LC_SEGMENT
-    seg_cmd = SegmentCommand.new(data[offset..-1])
-    if seg_cmd.segname.index('__LINKEDIT') == 0
-      puts "Found LINKEDIT segment at offset #{offset}"
-      link_cmd = seg_cmd
-      link_cmd_offset = offset
-    end
-  end
-  
-  if load_cmd.cmd == LC_SYMTAB
-    # Parse the symbol table command.
-    sym_cmd = SymtabCommand.new(data[offset..-1])
-    symbol_table_offset = offset
-    
-    # Parse the string table, store with offsets.
-    string_table_offset = sym_cmd.stroff
-    string_table = data[sym_cmd.stroff..sym_cmd.stroff+sym_cmd.strsize-1]
-    i = 0
-    string_table.split("\x00", -1).each do |s|
-      string_table_map[i] = s
-      i += s.length + 1
-    end
-    
-    # Parse the symbol table.
-    symbol_table = data[sym_cmd.symoff..-1]
-    i = 0
-    puts "Symbol table has #{sym_cmd.nsyms} symbols."
-    sym_cmd.nsyms.times do |n|
-      symbols << SymtabEntry.new(symbol_table[i..i+11])
-      i += 12
-    end
-    
-    # Now go through and make renames to the symbols.
-    size_diff = 0
-    
-    string_table_map.keys.sort.each do |i|
-      orig_sym = string_table_map[i]
-      
-      # Store the offset mapping.
-      offset_map[i] = (i + size_diff)
-      
-      if orig_sym.length > 1
-        sym = orig_sym[1..-1].gsub('$UNIX2003','')
-        if mappings.has_key?(sym)
-          if mappings[sym] != true
-            string_table_map[i] = mappings[sym]
-          else
-            string_table_map[i] = "#{prefix}#{sym}"
-          end
-          puts "   - Mapping: #{orig_sym} to #{string_table_map[i]} (offset #{i} -> #{i + size_diff})"
-                          
-          # Accumulate the offset difference.
-          size_diff += string_table_map[i].length - orig_sym.length
-        end
-      end
-    end
-  end
-  
-  offset += load_cmd.cmdsize
-end
-
-# OK, now lets rewrite the symbol table. Offsets may have changed, but the size doesn't.
-new_symbol_table = ''
-i = 0
-symbols.each do |symbol|
-  puts "  - Mapped #{i} symbols..." if i % 10000 == 0 and i > 0
-  symbol.strtableoffset = offset_map[symbol.strtableoffset] if symbol.strtableoffset > 1
-  new_symbol_table << symbol
-  i += 1
-end
-
-# OK, now lets rewrite the string table. The size will be different if mappings have occurred.
-new_string_table = string_table_map.keys.sort.collect { |i| string_table_map[i] }.join("\x00")
-
-# Next, modify the LC_SYMTAB header.
-size_diff = new_string_table.length - sym_cmd.strsize
-sym_cmd.strsize = new_string_table.length
-
-# Lastly, modify the LINKEDIT segment if it exists.
-if link_cmd
-  puts "Size changed by #{size_diff} bytes, rewriting LINKEDIT segment."
-  link_cmd.filesize += size_diff
-  SegmentCommand.round_byte_length.times { |i| data[link_cmd_offset + i] = link_cmd[i] }
-end
-
-# Create the new file in memory. First, copy the new symbol table header into place.
-24.times { |i| data[symbol_table_offset + i] = sym_cmd[i] }
-
-# Now copy the new symbol table.
-new_symbol_table.length.times { |i| data[sym_cmd.symoff + i] = new_symbol_table[i] }
-
-# Finally, add the new string table.
-data = data[0..string_table_offset-1] + new_string_table
-
-puts "Output file is #{data.length} bytes long."
-open("output.so", "wb").write(data)
index eaa281d..d287e89 100644 (file)
@@ -12,14 +12,10 @@ include ../../../../Makefile.include
 -include $(patsubst %.cpp,%.P,$(patsubst %.c,%.P,$(SRCS)))
 
 wrapper.o : wrapper.c
-       $(CC) $(CFLAGS) $(DEFINES) -fPIC -c -g -D_LINUX -D_REENTRANT -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 $(INCLUDES) $< -o $@
+       $(CC) $(CFLAGS) $(DEFINES) -c $(INCLUDES) $< -o $@
 
 exports_python_linux.o : exports_python_linux.cpp
-       $(CXX) $(CXXFLAGS) $(DEFINES) -c -g -D_LINUX -D_REENTRANT -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 $(INCLUDES) $< -o $@
+       $(CXX) $(CXXFLAGS) $(DEFINES) -c $(INCLUDES) $< -o $@
 
-wrapper.def : wrapper.c
-       LD_OPTS=$$(for func in $$(grep __wrap wrapper.c | grep -v bash | \
-           sed "s/.*__wrap_//g" | sed "s/(.*//g" | \
-           awk '{printf("%s ",$$0);}'); \
-           do echo -n "-Wl,-wrap,$$func "; done); \
-           echo -n $$LD_OPTS > $@
+wrapper.def : wrapper.o
+       nm wrapper.o | grep __wrap | awk '{printf("%s ", $$3);}' | sed "s/___wrap_/__wrap_/g" | sed "s/__wrap_/-Wl,-wrap,/g" > $@
index fc3a509..54abc33 100644 (file)
 typedef int64_t   off64_t;
 typedef off_t     __off_t;
 typedef off64_t   __off64_t;
-typedef fpos_t fpos64_t;
-#define stat64 stat
+typedef fpos_t    fpos64_t;
+#define stat64    stat
 #define statvfs64 statvfs
+// this is not right, fix later
+//#define _G_va_list va_list
 #endif
 
 #ifdef _LINUX
@@ -372,6 +374,11 @@ int __wrap_ungetc(int c, FILE *stream)
   return dll_ungetc(c, stream);
 }
 
+int __wrap_getc(FILE *stream)
+{
+  return dll_getc(stream);
+}
+
 int __wrap_ioctl(int d, unsigned long int request, ...)
 {
     int res;
@@ -382,7 +389,7 @@ int __wrap_ioctl(int d, unsigned long int request, ...)
     return res;
 } 
 
-int __wrap_stat(const char *path, struct _stat *buffer)
+int __wrap__stat(const char *path, struct _stat *buffer)
 {
   return dll_stat(path, buffer);
 }
diff --git a/xbmc/cores/DllLoader/exports/wrapper_mach_alias b/xbmc/cores/DllLoader/exports/wrapper_mach_alias
new file mode 100644 (file)
index 0000000..4558481
--- /dev/null
@@ -0,0 +1,53 @@
+# List of wrapper aliases for Mach-O
+___wrap_clearerr _clearerr
+___wrap_close _close
+___wrap_fclose _fclose
+___wrap_fdopen _fdopen
+___wrap_feof _feof
+___wrap_ferror _ferror
+___wrap_fflush _fflush
+___wrap_fgetc _fgetc
+___wrap_fgetpos _fgetpos
+___wrap_fgets _fgets
+___wrap_fileno _fileno
+___wrap_flockfile _flockfile
+___wrap_fopen _fopen
+___wrap_fopen64 _fopen64
+___wrap_fprintf _fprintf
+___wrap_fputc _fputc
+___wrap_fputs _fputs
+___wrap_fread _fread
+___wrap_freopen _freopen
+___wrap_fseek _fseek
+___wrap_fsetpos _fsetpos
+___wrap_fstatvfs64 _fstatvfs64
+___wrap_ftell _ftell
+___wrap_ftrylockfile _ftrylockfile
+___wrap_funlockfile _funlockfile
+___wrap_fwrite _fwrite
+___wrap_ioctl _ioctl
+___wrap_lseek _lseek
+___wrap_lseek64 _lseek64
+___wrap_open _open
+___wrap_open64 _open64
+___wrap_popen _popen
+___wrap_printf _printf
+___wrap_read _read
+___wrap_opendir _opendir
+___wrap_readdir _readdir
+___wrap_closedir _closedir
+___wrap_rewinddir _rewinddir
+___wrap_rewind _rewind
+___wrap_stat _stat
+___wrap_fstat _fstat
+___wrap_ungetc _ungetc
+___wrap_vfprintf _vfprintf
+___wrap_write _write
+___wrap__IO_putc _putc
+___wrap__IO_getc _getc
+___wrap__IO_getc_unlocked _getc_unlocked
+___wrap_fwrite _fwrite$UNIX2003
+___wrap_close _close$UNIX2003
+___wrap_fcntl _fcntl$UNIX2003
+___wrap_open _open$UNIX2003
+
index d486993..7b5648b 100644 (file)
@@ -44,14 +44,7 @@ endif
 endif
 
 PYDIRS=bsddb compiler curses distutils email encodings hotshot idlelib \
-       lib-old lib-tk logging site-packages xml
-ifeq ($(findstring osx,$(ARCH)),osx)
-       PYLIBDIR=lib.macosx-10.4-@ARCHTYPE@-2.4
-       PYDIRS+=plat-darwin
-       PYDIRS+=plat-mac
-else
-       PYDIRS+=plat-linux2
-endif
+       lib-old lib-tk logging site-packages xml plat-linux2
 
 PY=$(wildcard $(abs_top_srcdir)/lib/python/Lib/*.py)
 PY+=$(foreach DIR, $(PYDIRS), $(wildcard $(abs_top_srcdir)/lib/python/Lib/$(DIR)/*.py))
@@ -65,35 +58,9 @@ PYO=$(addsuffix o, $(PY))
 ifeq ($(findstring osx,$(ARCH)), osx)
 all: $(SLIB)
 
-ifneq (@USE_EXTERNAL_PYTHON@,1)
-$(SLIB): $(PYWRAP) $(abs_top_srcdir)/lib/python/libpython2.4.a $(PYO) $(abs_top_srcdir)/tools/Mach5/wrapper.rb
-       rm -rf $(SYSDIR)/Lib
-       rsync -a --exclude '.svn' -t $(abs_top_srcdir)/lib/python/build/$(PYLIBDIR)/*.so $(SYSDIR)/Lib
-       rsync -a --exclude '.svn' -t $(abs_top_srcdir)/lib/python/Lib/*.{py,pyo} $(SYSDIR)/Lib
-       for dirs in $(PYDIRS); do rsync -a --exclude 'test*'  --exclude '.svn' $(abs_top_srcdir)/lib/python/Lib/$$dirs $(SYSDIR)/Lib; done
-       (mkdir -p tmp && rm -rf tmp/*)
-       (cd ./tmp && ar x $(abs_top_srcdir)/lib/python/libpython2.4.a)
-       $(CXX) -bundle -flat_namespace -undefined suppress -shared -o $@ \
-               tmp/*.o \
-               wrapper_python.o
-       $(abs_top_srcdir)/tools/Mach5/wrapper.rb $@ libpython;mv output.so $@
-       $(abs_top_srcdir)/tools/Mach5/wrapper.rb $@;mv output.so $@
-       @rm -rf tmp
-else
 $(SLIB): $(PYWRAP)
        $(CC) $(LDFLAGS) -bundle -undefined dynamic_lookup -o $@ \
                -l$(PYVERSION) wrapper_python.o
-endif
-
-$(abs_top_srcdir)/lib/python/libpython2.4.a: compile
-       $(MAKE) -C $(abs_top_srcdir)/lib/python
-
-%pyo: %py
-       @echo Compiling $@
-       @$(abs_top_srcdir)/lib/python/python.exe -O $(abs_top_srcdir)/lib/python/Lib/py_compile.py $<
-
-$(PYWRAP): $(PYWRAP:.o=.c)
-        $(CC) $(CFLAGS) -fPIC -o $@ -D_FILE_DEFINED -D_REENTRANT -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c $<
 
 else
 all: $(SLIB)
index 7b968d9..e307d71 100644 (file)
@@ -9,9 +9,9 @@ DISTCLEAN_FILES=../../../addons/visualization.goom
 
 $(SLIB): $(OBJS) goom2k4-0/src/.libs/libgoom2.a
 ifeq ($(findstring osx,$(ARCH)), osx)
-       $(CXX) -fPIC -bundle -shared -undefined suppress -flat_namespace \
-               goom2k4-0/src/.libs/libgoom2.a $(CXXFLAGS) -o $(SLIB) $(OBJS)
-       ../../../tools/Mach5/wrapper.rb $@;mv output.so $@
+       $(CXX) $(CXXFLAGS) $(LDFLAGS) -Wl,-alias_list,@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper_mach_alias \
+               -bundle -undefined suppress -read_only_relocs suppress -o $(SLIB) \
+               @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o goom2k4-0/src/.libs/libgoom2.a  $(OBJS)
 else
        $(CXX) $(LDFLAGS) -fPIC goom2k4-0/src/*.o -shared $(CXXFLAGS) -o $(SLIB) $(OBJS) \
                `cat ../../cores/DllLoader/exports/wrapper.def` \
index c4107d8..f96cb77 100644 (file)
@@ -7,9 +7,9 @@ SLIB=@abs_top_srcdir@/addons/visualization.glspectrum/opengl_spectrum.vis
 
 $(SLIB): $(OBJS)
 ifeq ($(findstring osx,$(ARCH)), osx)
-       @export MACOSX_DEPLOYMENT_TARGET=10.4
-       $(CXX) $(CXXFLAGS) -bundle -shared -flat_namespace -undefined suppress -o $@ $(OBJS)
-       @abs_top_srcdir@/tools/Mach5/wrapper.rb $@;mv output.so $@
+       $(CXX) $(CXXFLAGS) $(LDFLAGS) -Wl,-alias_list,@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper_mach_alias \
+       -bundle -undefined dynamic_lookup -read_only_relocs suppress -o $@ \
+       @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o $(OBJS)
 else
        $(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -g -o $(SLIB) $(OBJS)
 endif
index 61c0ee2..bf704bc 100644 (file)
@@ -7,9 +7,9 @@ SLIB=@abs_top_srcdir@/addons/visualization.waveform/Waveform.vis
 
 $(SLIB): $(OBJS)
 ifeq ($(findstring osx,$(ARCH)), osx)
-       @export MACOSX_DEPLOYMENT_TARGET=10.4
-       $(CXX) -bundle -shared -flat_namespace -undefined suppress -o $(SLIB) $(OBJS)
-       @abs_top_srcdir@/tools/Mach5/wrapper.rb $@;mv output.so $@
+       $(CXX) $(LDFLAGS) -Wl,-alias_list,@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper_mach_alias \
+               -bundle -undefined dynamic_lookup -read_only_relocs suppress -o $(SLIB) \
+               @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o $(OBJS)
 else
        $(CXX) $(CFLAGS) $(LDFLAGS) -shared -g -o $(SLIB) $(OBJS)
 endif
index 5b209b8..249338c 100644 (file)
@@ -10,10 +10,9 @@ ifeq ($(findstring osx,$(ARCH)), osx)
 CXXFLAGS+=-fno-common 
 
 $(SLIB): $(OBJS) libprojectM/libprojectM.dylib
-       $(CXX) -bundle -shared -undefined suppress -flat_namespace $(CFLAGS) -o $(SLIB) \
-               ./libprojectM/CMakeFiles/projectM.dir/*.o \
-               $(OBJS)
-       @abs_top_srcdir@/tools/Mach5/wrapper.rb $@;mv output.so $@
+       $(CXX)  $(CFLAGS) $(LDFLAGS) -Wl,-alias_list,@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper_mach_alias \
+               -bundle -undefined dynamic_lookup -read_only_relocs suppress -o $(SLIB) \
+                @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o ./libprojectM/CMakeFiles/projectM.dir/*.o $(OBJS)
        $(MAKE) $(PRESETS)
 
 libprojectM/libprojectM.dylib:
index 880c3f1..2f344a3 100644 (file)
@@ -1,15 +1,14 @@
 ARCH=@ARCH@
-INCLUDES=-I. -I../../addons/include -I/opt/local/include
+INCLUDES=-I. -I@abs_top_srcdir@/addons/include
 OBJS=Main.o itunes_vis.o qview.o common_osx.o
 CXXFLAGS=-Wall -g -fPIC
 SLIB=../../../addons/visualization.itunes/iTunes.mvis
 
 $(SLIB): $(OBJS)
 ifeq ($(findstring osx,$(ARCH)), osx)
-       @export MACOSX_DEPLOYMENT_TARGET=10.4
-       $(CXX) $(CXXFLAGS) -framework Carbon -bundle -shared -flat_namespace \
-               -undefined suppress -o $@ $(OBJS) 
-       ../../../tools/Mach5/wrapper.rb $@;mv output.so $@
+       $(CXX) $(CXXFLAGS) $(LDFLAGS) -Wl,-alias_list,@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper_mach_alias \
+               -framework Carbon -bundle -undefined dynamic_lookup -read_only_relocs suppress -o $@ \
+               @abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o $(OBJS) 
 endif
 
 include ../../../Makefile.include