kballard-osx-plist 1.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.txt +4 -4
  2. data/Rakefile +2 -2
  3. data/ext/plist/plist.c +30 -22
  4. metadata +5 -5
  5. data/plist.gemspec +0 -25
data/README.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  == osx/plist
2
2
  by Kevin Ballard
3
- http://github.com/kballard/plist
3
+ http://github.com/kballard/osx-plist
4
4
 
5
5
  == DESCRIPTION:
6
6
 
@@ -13,17 +13,17 @@ osx/plist is a Ruby library for manipulating Property Lists natively using the b
13
13
  == INSTALL:
14
14
 
15
15
  $ gem sources -a http://gems.github.com/ (you only need to do this once)
16
- $ gem install kballard-plist
16
+ $ gem install kballard-osx-plist
17
17
 
18
18
  == SOURCE:
19
19
 
20
20
  osx/plist's git repo is available on GitHub, which can be browsed at:
21
21
 
22
- http://github.com/kballard/plist
22
+ http://github.com/kballard/osx-plist
23
23
 
24
24
  and cloned from:
25
25
 
26
- git://github.com/kballard/plist.git
26
+ git://github.com/kballard/osx-plist.git
27
27
 
28
28
  == USAGE:
29
29
 
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
1
  require 'rubygems'
2
2
  require 'hoe'
3
3
 
4
- Hoe.new('osx-plist', "1.0") do |p|
4
+ Hoe.new('osx-plist', "1.0.1") do |p|
5
5
  p.author = "Kevin Ballard"
6
6
  p.email = "kevin@sb.org"
7
7
  p.summary = "Property List manipulation for OS X"
8
- p.url = "http://www.github.com/kballard/plist"
8
+ p.url = "http://www.github.com/kballard/osx-plist"
9
9
  p.spec_extras = {:extensions => "ext/plist/extconf.rb"}
10
10
  end
data/ext/plist/plist.c CHANGED
@@ -57,7 +57,11 @@
57
57
  */
58
58
 
59
59
  #include <ruby.h>
60
+ #if HAVE_RUBY_ST_H
61
+ #include <ruby/st.h>
62
+ #else
60
63
  #include <st.h>
64
+ #endif
61
65
  #include <CoreFoundation/CoreFoundation.h>
62
66
 
63
67
  // Here's some convenience macros
@@ -147,14 +151,14 @@ VALUE plist_load(int argc, VALUE *argv, VALUE self) {
147
151
  // even though binary shouldn't be < 6 characters
148
152
  UInt8 *bytes;
149
153
  int len;
150
- if (RSTRING(buffer)->len < 6) {
154
+ if (RSTRING_LEN(buffer) < 6) {
151
155
  bytes = ALLOC_N(UInt8, 6);
152
156
  memset(bytes, '\n', 6);
153
- MEMCPY(bytes, RSTRING(buffer)->ptr, UInt8, RSTRING(buffer)->len);
157
+ MEMCPY(bytes, RSTRING_PTR(buffer), UInt8, RSTRING_LEN(buffer));
154
158
  len = 6;
155
159
  } else {
156
- bytes = (UInt8 *)RSTRING(buffer)->ptr;
157
- len = RSTRING(buffer)->len;
160
+ bytes = (UInt8 *)RSTRING_PTR(buffer);
161
+ len = RSTRING_LEN(buffer);
158
162
  }
159
163
  CFReadStreamRef readStream = CFReadStreamCreateWithBytesNoCopy(kCFAllocatorDefault, bytes, len, kCFAllocatorNull);
160
164
  CFReadStreamOpen(readStream);
@@ -163,7 +167,7 @@ VALUE plist_load(int argc, VALUE *argv, VALUE self) {
163
167
  CFRelease(readStream);
164
168
  } else {
165
169
  // Format wasn't requested
166
- CFDataRef data = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, (const UInt8*)RSTRING(buffer)->ptr, RSTRING(buffer)->len, kCFAllocatorNull);
170
+ CFDataRef data = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, (const UInt8*)RSTRING_PTR(buffer), RSTRING_LEN(buffer), kCFAllocatorNull);
167
171
  plist = CFPropertyListCreateFromXMLData(kCFAllocatorDefault, data, kCFPropertyListImmutable, &error);
168
172
  CFRelease(data);
169
173
  }
@@ -346,15 +350,10 @@ VALUE plist_dump(int argc, VALUE *argv, VALUE self) {
346
350
  } else {
347
351
  type = rb_to_id(type);
348
352
  }
349
- if (type != id_xml && type != id_binary && type != id_openstep) {
350
- rb_raise(rb_eArgError, "Argument 3 must be one of :xml1, :binary1, or :openstep");
351
- return Qnil;
352
- }
353
353
  if (!RTEST(rb_respond_to(io, id_write))) {
354
354
  rb_raise(rb_eArgError, "Argument 1 must be an IO object");
355
355
  return Qnil;
356
356
  }
357
- CFPropertyListRef plist = convertObject(obj);
358
357
  CFPropertyListFormat format;
359
358
  if (type == id_xml) {
360
359
  format = kCFPropertyListXMLFormat_v1_0;
@@ -362,7 +361,11 @@ VALUE plist_dump(int argc, VALUE *argv, VALUE self) {
362
361
  format = kCFPropertyListBinaryFormat_v1_0;
363
362
  } else if (type == id_openstep) {
364
363
  format = kCFPropertyListOpenStepFormat;
364
+ } else {
365
+ rb_raise(rb_eArgError, "Argument 3 must be one of :xml1, :binary1, or :openstep");
366
+ return Qnil;
365
367
  }
368
+ CFPropertyListRef plist = convertObject(obj);
366
369
  VALUE data = convertPlistToString(plist, format);
367
370
  if (NIL_P(data)) {
368
371
  return Qnil;
@@ -388,11 +391,6 @@ VALUE obj_to_plist(int argc, VALUE *argv, VALUE self) {
388
391
  } else {
389
392
  type = rb_to_id(type);
390
393
  }
391
- if (type != id_xml && type != id_binary && type != id_openstep) {
392
- rb_raise(rb_eArgError, "Argument 2 must be one of :xml1, :binary1, or :openstep");
393
- return Qnil;
394
- }
395
- CFPropertyListRef plist = convertObject(self);
396
394
  CFPropertyListFormat format;
397
395
  if (type == id_xml) {
398
396
  format = kCFPropertyListXMLFormat_v1_0;
@@ -400,7 +398,11 @@ VALUE obj_to_plist(int argc, VALUE *argv, VALUE self) {
400
398
  format = kCFPropertyListBinaryFormat_v1_0;
401
399
  } else if (type == id_openstep) {
402
400
  format = kCFPropertyListOpenStepFormat;
401
+ } else {
402
+ rb_raise(rb_eArgError, "Argument 2 must be one of :xml1, :binary1, or :openstep");
403
+ return Qnil;
403
404
  }
405
+ CFPropertyListRef plist = convertObject(self);
404
406
  VALUE data = convertPlistToString(plist, format);
405
407
  CFRelease(plist);
406
408
  if (type == id_xml || type == id_binary) {
@@ -437,15 +439,15 @@ CFPropertyListRef convertString(VALUE obj) {
437
439
  if (RTEST(str_blob(obj))) {
438
440
  // convert to CFDataRef
439
441
  StringValue(obj);
440
- CFDataRef data = CFDataCreate(kCFAllocatorDefault, (const UInt8*)RSTRING(obj)->ptr, (CFIndex)RSTRING(obj)->len);
442
+ CFDataRef data = CFDataCreate(kCFAllocatorDefault, (const UInt8*)RSTRING_PTR(obj), (CFIndex)RSTRING_LEN(obj));
441
443
  return data;
442
444
  } else {
443
445
  // convert to CFStringRef
444
446
  StringValue(obj);
445
- CFStringRef string = CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8*)RSTRING(obj)->ptr, (CFIndex)RSTRING(obj)->len, kCFStringEncodingUTF8, false);
447
+ CFStringRef string = CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8*)RSTRING_PTR(obj), (CFIndex)RSTRING_LEN(obj), kCFStringEncodingUTF8, false);
446
448
  if (!string) {
447
449
  // try MacRoman
448
- string = CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8*)RSTRING(obj)->ptr, (CFIndex)RSTRING(obj)->len, kCFStringEncodingMacRoman, false);
450
+ string = CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8*)RSTRING_PTR(obj), (CFIndex)RSTRING_LEN(obj), kCFStringEncodingMacRoman, false);
449
451
  }
450
452
  return string;
451
453
  }
@@ -463,19 +465,25 @@ int iterateHash(VALUE key, VALUE val, VALUE dict) {
463
465
 
464
466
  // Converts a Hash to a CFDictionaryREf
465
467
  CFDictionaryRef convertHash(VALUE obj) {
466
- CFIndex count = (CFIndex)RHASH(obj)->tbl->num_entries;
468
+ // RHASH_TBL exists in ruby 1.8.7 but not ruby 1.8.6
469
+ #ifdef RHASH_TBL
470
+ st_table *tbl = RHASH_TBL(obj);
471
+ #else
472
+ st_table *tbl = RHASH(obj)->tbl;
473
+ #endif
474
+ CFIndex count = (CFIndex)tbl->num_entries;
467
475
  CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault, count, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
468
- st_foreach(RHASH(obj)->tbl, iterateHash, (VALUE)dict);
476
+ st_foreach(tbl, iterateHash, (VALUE)dict);
469
477
  return dict;
470
478
  }
471
479
 
472
480
  // Converts an Array to a CFArrayRef
473
481
  CFArrayRef convertArray(VALUE obj) {
474
- CFIndex count = (CFIndex)RARRAY(obj)->len;
482
+ CFIndex count = (CFIndex)RARRAY_LEN(obj);
475
483
  CFMutableArrayRef array = CFArrayCreateMutable(kCFAllocatorDefault, count, &kCFTypeArrayCallBacks);
476
484
  int i;
477
485
  for (i = 0; i < count; i++) {
478
- CFPropertyListRef aVal = convertObject(RARRAY(obj)->ptr[i]);
486
+ CFPropertyListRef aVal = convertObject(RARRAY_PTR(obj)[i]);
479
487
  CFArrayAppendValue(array, aVal);
480
488
  CFRelease(aVal);
481
489
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kballard-osx-plist
3
3
  version: !ruby/object:Gem::Version
4
- version: "1.0"
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Ballard
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-04-25 00:00:00 -07:00
12
+ date: 2009-02-05 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -19,7 +19,7 @@ dependencies:
19
19
  requirements:
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 1.5.1
22
+ version: 1.7.0
23
23
  version:
24
24
  description: osx/plist is a Ruby library for manipulating Property Lists natively using the built-in support in OS X.
25
25
  email: kevin@sb.org
@@ -43,7 +43,7 @@ files:
43
43
  - test/suite.rb
44
44
  - test/test_plist.rb
45
45
  has_rdoc: true
46
- homepage: http://www.github.com/kballard/plist
46
+ homepage: http://www.github.com/kballard/osx-plist
47
47
  post_install_message:
48
48
  rdoc_options:
49
49
  - --main
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  requirements: []
66
66
 
67
67
  rubyforge_project: osx-plist
68
- rubygems_version: 1.0.1
68
+ rubygems_version: 1.2.0
69
69
  signing_key:
70
70
  specification_version: 2
71
71
  summary: Property List manipulation for OS X
data/plist.gemspec DELETED
@@ -1,25 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = %q{osx-plist}
3
- s.version = "1.0"
4
-
5
- s.specification_version = 2 if s.respond_to? :specification_version=
6
-
7
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Kevin Ballard"]
9
- s.date = %q{2008-04-25}
10
- s.description = %q{osx/plist is a Ruby library for manipulating Property Lists natively using the built-in support in OS X.}
11
- s.email = %q{kevin@sb.org}
12
- s.extensions = ["ext/plist/extconf.rb"]
13
- s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
14
- s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "ext/plist/extconf.rb", "ext/plist/plist.c", "plist.gemspec", "test/fixtures/xml_plist", "test/suite.rb", "test/test_plist.rb"]
15
- s.has_rdoc = true
16
- s.homepage = %q{http://www.github.com/kballard/plist}
17
- s.rdoc_options = ["--main", "README.txt"]
18
- s.require_paths = ["ext"]
19
- s.rubyforge_project = %q{osx-plist}
20
- s.rubygems_version = %q{1.0.1}
21
- s.summary = %q{Property List manipulation for OS X}
22
- s.test_files = ["test/test_plist.rb"]
23
-
24
- s.add_dependency(%q<hoe>, [">= 1.5.1"])
25
- end