Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Initial import of Ruby bindings for PhysicsFS.
  • Loading branch information
icculus committed Dec 11, 2002
1 parent f69a6c5 commit 0392bf8
Show file tree
Hide file tree
Showing 14 changed files with 1,789 additions and 0 deletions.
103 changes: 103 additions & 0 deletions extras/physfs_rb/installer.rb
@@ -0,0 +1,103 @@
# $Id: installer.rb,v 1.1 2002/12/11 15:37:23 icculus Exp $

require 'rbconfig'
require 'find'
require 'ftools'

include Config

module Slimb
class Installer
def initialize target_dir = "", &user_skip
@user_skip = user_skip or proc {|f| false}

@version = CONFIG["MAJOR"] + "." + CONFIG["MINOR"]
@libdir = File.join(CONFIG["libdir"], "ruby", @version)
@sitedir = CONFIG["sitedir"] || File.join(@libdir, "site_ruby")
@dest = File.join @sitedir, target_dir

File::makedirs @dest
File::chmod 0755, @dest, true
end

def skip? file
@user_skip[file] or
file[0] == ?. or file[-1] == ?~ or file[-1] == ?#
end

def install_dir dir
File::makedirs(File.join(@dest, dir))
File::chmod(0755, File.join(@dest, dir), true)
Dir.foreach(dir) {|file|
next if skip? file

if File.ftype(File.join(dir, file)) == "directory"
install_dir File.join(dir, file)
else
install_file File.join(dir, file)
end
}
end

def install_file file
if file =~ /\.so$/
install_so file
else
File::install file, File.join(@dest, file), 0644, true
end
end

def install_so file
File::install file, File.join(CONFIG["sitearchdir"], file), 0644, true
end

def uninstall_so file
file = File.join(CONFIG["sitearchdir"], file)
File::safe_unlink file
end

def install something
case something
when Array
something.each {|x|
install x if x.is_a? String
}
when String
if File.ftype(something) == "directory"
install_dir something
else
install_file something
end
end
end

def uninstall what = "*"
case what
when Array
files = what.map {|x| File.join(@dest, x)}
when String
files = Dir[File.join(@dest, what)]
end

files.each {|x|
# FIXME: recursive uninstall is a must
next if FileTest.directory? x
File::safe_unlink x
}
end

def run files, argv
if !argv.grep(/--uninstall/).empty?
uninstall files
else
install files
end
end
end
end

# self-installation
if $0 == __FILE__
$stderr.puts "Installing slimb installer..."
Slimb::Installer.new("slimb").install File.basename(__FILE__)
end
9 changes: 9 additions & 0 deletions extras/physfs_rb/physfs/extconf.rb
@@ -0,0 +1,9 @@
require 'mkmf'

$CFLAGS += `sdl-config --cflags`.chomp
$LDFLAGS += `sdl-config --libs`.chomp

have_library "physfs", "PHYSFS_init"
have_library "SDL", "SDL_AllocRW"

create_makefile "physfs_so"
7 changes: 7 additions & 0 deletions extras/physfs_rb/physfs/install.rb
@@ -0,0 +1,7 @@
#!/usr/local/bin/ruby

if __FILE__ == $0
require 'slimb/installer'
files = ["physfs.rb", "physfs_so.so"]
installer = Slimb::Installer.new.run files, ARGV
end
9 changes: 9 additions & 0 deletions extras/physfs_rb/physfs/make_install_test.sh
@@ -0,0 +1,9 @@
#!/bin/sh
ruby extconf.rb
make
cd ..
ruby installer.rb
cd physfs
ruby install.rb
cd test
ruby test_physfs.rb
121 changes: 121 additions & 0 deletions extras/physfs_rb/physfs/physfs.rb
@@ -0,0 +1,121 @@
#
# PhysicsFS - ruby interface
#
# Author: Ed Sinjiashvili (slimb@vlinkmail.com)
# License: LGPL
#

require 'physfs_so'

module PhysicsFS

class Version
def initialize major, minor, patch
@major = major
@minor = minor
@patch = patch
end

attr_reader :major, :minor, :patch

def to_s
"#@major.#@minor.#@patch"
end
end

class ArchiveInfo
def initialize ext, desc, author, url
@extension = ext
@description = desc
@author = author
@url = url
end

attr_reader :extension, :description
attr_reader :author, :url

def to_s
" * #@extension: #@description\n Written by #@author.\n #@url\n"
end
end

#
# convenience methods
#
class << self

def init argv0 = $0
init_internal argv0
end

def append_search_path str
add_to_search_path str, 1
self
end

def prepend_search_path str
add_to_search_path str, 0
self
end

alias_method :<<, :append_search_path
alias_method :push, :append_search_path
alias_method :unshift, :prepend_search_path

def ls path = ""
enumerate path
end
end

#
# File - PhysicsFS abstract file - can be drawn from various sources
#
class File
def write_str str
write str, 1, str.length
end

def cat
prev_pos = tell
seek 0
r = read length, 1
seek prev_pos
r
end

alias_method :size, :length
end

#
# RWops - general stdio like operations on file-like creatures
#
class RWops
SEEK_SET = 0
SEEK_CUR = 1
SEEK_END = 2

# tell current position of RWopted entity
def tell
seek 0, SEEK_CUR
end

# length of RWops abstracted entity
def length
cur = tell
r = seek 0, SEEK_END
seek cur, SEEK_SET
r
end

alias_method :size, :length

#
# create rwops from PhysicsFS file object
#
def self.from_physfs file
file.to_rwops
end
end
end

# physfs.rb ends here #

0 comments on commit 0392bf8

Please sign in to comment.