Permalink
Browse files

Updated to work under Ruby 1.9.2

  • Loading branch information...
1 parent 7b11184 commit b53dba299f53b094e1cbf0c4b3d2b4cb8719f6d4 @pbosetti committed Mar 4, 2011
Showing with 68 additions and 7 deletions.
  1. +4 −0 .gitignore
  2. +6 −2 extconf.rb
  3. +2 −2 rubyosa.gemspec
  4. +3 −1 src/lib/rbosa.rb
  5. +25 −1 src/rbosa.c
  6. +20 −1 src/rbosa_conv.c
  7. +8 −0 src/rbosa_sdef.c
View
@@ -0,0 +1,4 @@
+*.gem
+*.log
+Makefile
+src/osx_*.h
View
@@ -29,13 +29,17 @@
$CFLAGS << ' -Wall '
$LDFLAGS = '-framework Carbon -framework ApplicationServices'
+if RUBY_VERSION =~ /^1.9/ then
+ $CPPFLAGS += " -DRUBY_19"
+end
+
exit 1 unless have_func('OSACopyScriptingDefinition')
exit 1 unless have_func('LSFindApplicationForInfo')
# Avoid `ID' and `T_DATA' symbol collisions between Ruby and Carbon.
# (adapted code from RubyAEOSA - FUJIMOTO Hisakuni <hisa@fobj.com>)
-ruby_h = "#{Config::CONFIG['archdir']}/ruby.h"
-intern_h = "#{Config::CONFIG['archdir']}/intern.h"
+ruby_h = "#{Config::CONFIG['rubyhdrdir']}/ruby.h"
+intern_h = "#{Config::CONFIG['rubyhdrdir']}/ruby/intern.h"
new_filename_prefix = 'osx_'
[ ruby_h, intern_h ].each do |src_path|
dst_fname = File.join('./src', new_filename_prefix + File.basename(src_path))
View
@@ -1,12 +1,12 @@
Gem::Specification.new do |s|
s.name = 'pbosetti-rubyosa'
- s.version = '0.5.3'
+ s.version = '0.5.4'
s.date = '2009-11-09'
s.summary = 'A Ruby/AppleEvent bridge.'
s.email = 'lsansonetti@apple.com'
s.homepage = 'http://rubyosa.rubyforge.org'
s.rubyforge_project = 'rubyosa'
- s.description = "RubyOSA is a bridge that connects Ruby to the Apple Event Manager, automatically populating the API according to the target application's scriptable definition."
+ s.description = "RubyOSA is a bridge that connects Ruby to the Apple Event Manager, automatically populating the API according to the target application's scriptable definition. This version is 1.9.2 compatible!"
s.has_rdoc = false
s.authors = ['Laurent Sansonetti']
s.files = ['README.markdown', 'COPYRIGHT', 'AUTHORS', 'extconf.rb', 'src/rbosa.c', 'src/rbosa.h', 'src/rbosa_conv.c', 'src/rbosa_sdef.c', 'src/rbosa_err.c', 'src/lib/rbosa.rb', 'src/lib/rbosa_properties.rb', 'sample/Finder/show_desktop.rb', 'sample/iChat/uptime.rb', 'sample/iTunes/control.rb', 'sample/iTunes/fade_volume.rb', 'sample/iTunes/inspect.rb', 'sample/QuickTime/play_all.rb', 'sample/misc/sdef.rb', 'sample/BBEdit/unix_script.rb', 'sample/TextEdit/hello_world.rb', 'sample/iChat/image.rb', 'sample/iTunes/artwork.rb', 'sample/Mail/get_selected_mail.rb', 'sample/AddressBook/inspect.rb', 'sample/iTunes/tag_genre_lastfm.rb', 'data/rubyosa/rdoc_html.rb', 'sample/Photoshop/new_doc.rb', 'sample/Photoshop/new_doc_with_text.rb', 'sample/iTunes/name_that_tune.rb']
View
@@ -24,7 +24,9 @@
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
-$KCODE = 'u' # we will use UTF-8 strings
+unless RUBY_VERSION =~ /^1.9/ then
+ $KCODE = 'u' # we will use UTF-8 strings
+end
require 'osa'
require 'date'
View
@@ -161,8 +161,13 @@ rbosa_element_new (VALUE self, VALUE type, VALUE value)
}
else {
Check_Type (value, T_STRING);
+#ifdef RUBY_19
+ c_value = RSTRING_PTR(value);
+ c_value_size = RSTRING_LEN(value);
+#else
c_value = RSTRING (value)->ptr;
c_value_size = RSTRING (value)->len;
+#endif
}
error = AECreateDesc (ffc_type, c_value, c_value_size, &desc);
@@ -290,18 +295,32 @@ rbosa_app_send_event (VALUE self, VALUE event_class, VALUE event_id, VALUE param
if (!NIL_P (params)) {
unsigned i;
+#ifdef RUBY_19
+ for (i = 0; i < RARRAY_LEN(params); i++) {
+#else
for (i = 0; i < RARRAY (params)->len; i++) {
+#endif
VALUE ary;
VALUE type;
VALUE element;
FourCharCode code;
+#ifdef RUBY_19
+ ary = RARRAY_PTR(params)[i];
+ if (NIL_P (ary) || RARRAY_LEN(ary) != 2)
+#else
ary = RARRAY (params)->ptr[i];
- if (NIL_P (ary) || RARRAY (ary)->len != 2)
+ if (NIL_P (ary) || RARRAY (ary)->len != 2)
+#endif
continue;
+#ifdef RUBY_19
+ type = RARRAY_PTR(ary)[0];
+ element = RARRAY_PTR(ary)[1];
+#else
type = RARRAY (ary)->ptr[0];
element = RARRAY (ary)->ptr[1];
+#endif
code = RVAL2FOURCHAR (type);
if (code == '----')
@@ -560,8 +579,13 @@ rbosa_elementlist_new (int argc, VALUE *argv, VALUE self)
error_code_to_string (error), error);
if (!NIL_P (ary)) {
+#ifdef RUBY_19
+ for (i = 0; i < RARRAY_LEN(ary); i++)
+ __rbosa_elementlist_add (&list, RARRAY_PTR(ary)[i], i + 1);
+#else
for (i = 0; i < RARRAY (ary)->len; i++)
__rbosa_elementlist_add (&list, RARRAY (ary)->ptr[i], i + 1);
+#endif
}
return rbosa_element_make (self, &list, Qnil);
View
@@ -43,9 +43,15 @@ rbobj_to_fourchar (VALUE obj)
obj = rb_obj_as_string (obj);
if (rb_obj_is_kind_of (obj, rb_cString)) {
+#ifdef RUBY_19
+ if (RSTRING_LEN(obj) != 4)
+ rb_raise (rb_eArgError, USAGE_MSG);
+ result = *(FourCharCode*)(RSTRING_PTR(obj));
+#else
if (RSTRING (obj)->len != 4)
rb_raise (rb_eArgError, USAGE_MSG);
result = *(FourCharCode*)(RSTRING (obj)->ptr);
+#endif
result = CFSwapInt32HostToBig (result);
}
else {
@@ -75,9 +81,14 @@ rbobj_to_alias_handle (VALUE obj, AliasHandle *alias)
Check_Type (obj, T_STRING);
*alias = NULL;
- URL = CFURLCreateFromFileSystemRepresentation (kCFAllocatorDefault,
+ URL = CFURLCreateFromFileSystemRepresentation (kCFAllocatorDefault,
+#ifdef RUBY_19
+ (const UInt8 *)RSTRING_PTR(obj),
+ RSTRING_LEN(obj),
+#else
(const UInt8 *)RSTRING (obj)->ptr,
RSTRING (obj)->len,
+#endif
0 /* XXX: normally passing 0 even if it's a directory should
not hurt, as we are just getting the FSRef. */);
if (URL == NULL)
@@ -88,10 +99,18 @@ rbobj_to_alias_handle (VALUE obj, AliasHandle *alias)
error = FSNewAlias (NULL, &ref, alias);
if (error != noErr)
rb_raise (rb_eArgError, "Cannot create alias handle for given filename '%s' : %s (%d)",
+#ifdef RUBY_19
+ RSTRING_PTR(obj), GetMacOSStatusErrorString (error), error);
+#else
RSTRING (obj)->ptr, GetMacOSStatusErrorString (error), error);
+#endif
}
else {
rb_raise (rb_eArgError, "Cannot obtain the filesystem reference for given filename '%s'",
+#ifdef RUBY_19
+ RSTRING_PTR(obj));
+#else
RSTRING (obj)->ptr);
+#endif
}
}
View
@@ -331,12 +331,20 @@ rbosa_scripting_info (VALUE self, VALUE hash)
remote = CSTR2RVAL (c_remote);
}
+#ifdef RUBY_19
+ if (RHASH_TBL(hash)->num_entries > 0) {
+#else
if (RHASH (hash)->tbl->num_entries > 0) {
+#endif
VALUE keys;
keys = rb_funcall (hash, rb_intern ("keys"), 0);
rb_raise (rb_eArgError, "inappropriate argument(s): %s",
+#ifdef RUBY_19
+ RSTRING_PTR(rb_inspect (keys)));
+#else
RSTRING (rb_inspect (keys))->ptr);
+#endif
}
if (NIL_P (remote)) {

0 comments on commit b53dba2

Please sign in to comment.