gphoto4ruby 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/ext/extconf.rb CHANGED
@@ -2,6 +2,9 @@ require "mkmf"
2
2
 
3
3
  dir_config("gphoto4ruby", "/usr/local")
4
4
  if have_library("gphoto2")
5
+ if RUBY_VERSION =~ /1\.9/
6
+ $CPPFLAGS += " -DRUBY_19"
7
+ end
5
8
  $CFLAGS = '-Wall ' + $CFLAGS
6
9
  create_makefile("gphoto4ruby")
7
10
  else
data/ext/gphoto2camera.c CHANGED
@@ -104,7 +104,7 @@ VALUE camera_initialize(int argc, VALUE *argv, VALUE self) {
104
104
 
105
105
  gp_result_check(gp_port_info_list_new(&portInfoList));
106
106
  gp_result_check(gp_port_info_list_load(portInfoList));
107
- portIndex = gp_result_check(gp_port_info_list_lookup_path(portInfoList, RSTRING(argv[0])->ptr));
107
+ portIndex = gp_result_check(gp_port_info_list_lookup_path(portInfoList, RSTRING_PTR(argv[0])));
108
108
  gp_result_check(gp_port_info_list_get_info(portInfoList, portIndex, &p));
109
109
  gp_result_check(gp_camera_set_port_info(c->camera, p));
110
110
  break;
@@ -248,7 +248,7 @@ VALUE camera_capture(int argc, VALUE *argv, VALUE self) {
248
248
  *
249
249
  */
250
250
  VALUE camera_save(int argc, VALUE *argv, VALUE self) {
251
- int i, count;
251
+ int i, count, retVal;
252
252
  int newName = 0;
253
253
  const char *fData, *key, *val, *name;
254
254
  char *fPath, *newNameStr, *pchNew, *pchSrc;
@@ -295,13 +295,13 @@ VALUE camera_save(int argc, VALUE *argv, VALUE self) {
295
295
  return Qnil;
296
296
  }
297
297
  arr = rb_funcall(argv[0], rb_intern("keys"), 0);
298
- for (i = 0; i < RARRAY(arr)->len; i++) {
299
- switch(TYPE(RARRAY(arr)->ptr[i])) {
298
+ for (i = 0; i < RARRAY_LEN(arr); i++) {
299
+ switch(TYPE(RARRAY_PTR(arr)[i])) {
300
300
  case T_STRING:
301
- key = RSTRING(RARRAY(arr)->ptr[i])->ptr;
301
+ key = RSTRING_PTR(RARRAY_PTR(arr)[i]);
302
302
  break;
303
303
  case T_SYMBOL:
304
- key = rb_id2name(rb_to_id(RARRAY(arr)->ptr[i]));
304
+ key = rb_id2name(rb_to_id(RARRAY_PTR(arr)[i]));
305
305
  break;
306
306
  default:
307
307
  gp_list_free(list);
@@ -309,7 +309,7 @@ VALUE camera_save(int argc, VALUE *argv, VALUE self) {
309
309
  return Qnil;
310
310
  }
311
311
  if (strcmp(key, "to_folder") == 0) {
312
- fPath = RSTRING(rb_hash_aref(argv[0], RARRAY(arr)->ptr[i]))->ptr;
312
+ fPath = RSTRING_PTR(rb_hash_aref(argv[0], RARRAY_PTR(arr)[i]));
313
313
  if (strlen(fPath) > 0) {
314
314
  if (fPath[strlen(fPath)] == '/') {
315
315
  strcpy(fName, fPath);
@@ -319,22 +319,22 @@ VALUE camera_save(int argc, VALUE *argv, VALUE self) {
319
319
  }
320
320
  }
321
321
  } else if (strcmp(key, "new_name") == 0) {
322
- newNameStr = RSTRING(rb_hash_aref(argv[0], RARRAY(arr)->ptr[i]))->ptr;
322
+ newNameStr = RSTRING_PTR(rb_hash_aref(argv[0], RARRAY_PTR(arr)[i]));
323
323
  if (strlen(newNameStr) > 0) {
324
324
  newName = 1;
325
325
  }
326
326
  } else if (strcmp(key, "type") == 0) {
327
- hVal = rb_hash_aref(argv[0], RARRAY(arr)->ptr[i]);
327
+ hVal = rb_hash_aref(argv[0], RARRAY_PTR(arr)[i]);
328
328
  Check_Type(hVal, T_SYMBOL);
329
329
  val = rb_id2name(rb_to_id(hVal));
330
330
  if (strcmp(val, "preview") == 0) {
331
331
  fileType = GP_FILE_TYPE_PREVIEW;
332
332
  }
333
333
  } else if (strcmp(key, "file") == 0) {
334
- hVal = rb_hash_aref(argv[0], RARRAY(arr)->ptr[i]);
334
+ hVal = rb_hash_aref(argv[0], RARRAY_PTR(arr)[i]);
335
335
  switch(TYPE(hVal)) {
336
336
  case T_STRING:
337
- strcpy(cFileName, RSTRING(hVal)->ptr);
337
+ strcpy(cFileName, RSTRING_PTR(hVal));
338
338
  break;
339
339
  case T_SYMBOL:
340
340
  val = rb_id2name(rb_to_id(hVal));
@@ -374,10 +374,13 @@ VALUE camera_save(int argc, VALUE *argv, VALUE self) {
374
374
  strcat(fName, cFileName);
375
375
  }
376
376
  fd = open(fName, O_CREAT | O_WRONLY, 0644);
377
- write(fd, fData, fSize);
377
+ retVal = write(fd, fData, fSize);
378
378
  close(fd);
379
379
  gp_file_free(file);
380
380
  gp_list_free(list);
381
+ if (retVal < 0) {
382
+ rb_raise(rb_eIOError, "Can't save into file");
383
+ }
381
384
  return self;
382
385
  }
383
386
 
@@ -437,13 +440,13 @@ VALUE camera_delete(int argc, VALUE *argv, VALUE self) {
437
440
  switch(TYPE(argv[0])) {
438
441
  case T_HASH:
439
442
  arr = rb_funcall(argv[0], rb_intern("keys"), 0);
440
- for (i = 0; i < RARRAY(arr)->len; i++) {
441
- switch(TYPE(RARRAY(arr)->ptr[i])) {
443
+ for (i = 0; i < RARRAY_LEN(arr); i++) {
444
+ switch(TYPE(RARRAY_PTR(arr)[i])) {
442
445
  case T_STRING:
443
- key = RSTRING(RARRAY(arr)->ptr[i])->ptr;
446
+ key = RSTRING_PTR(RARRAY_PTR(arr)[i]);
444
447
  break;
445
448
  case T_SYMBOL:
446
- key = rb_id2name(rb_to_id(RARRAY(arr)->ptr[i]));
449
+ key = rb_id2name(rb_to_id(RARRAY_PTR(arr)[i]));
447
450
  break;
448
451
  default:
449
452
  gp_list_free(list);
@@ -451,7 +454,7 @@ VALUE camera_delete(int argc, VALUE *argv, VALUE self) {
451
454
  return Qnil;
452
455
  }
453
456
  if (strcmp(key, "file") == 0) {
454
- strcpy(cFileName, RSTRING(rb_hash_aref(argv[0], RARRAY(arr)->ptr[i]))->ptr);
457
+ strcpy(cFileName, RSTRING_PTR(rb_hash_aref(argv[0], RARRAY_PTR(arr)[i])));
455
458
  }
456
459
  }
457
460
  break;
@@ -521,25 +524,25 @@ VALUE camera_get_config(int argc, VALUE *argv, VALUE self) {
521
524
  gp_widget_free(c->config);
522
525
  gp_result_check(gp_camera_get_config(c->camera, &(c->config), c->context));
523
526
  arr = rb_funcall(cfg, rb_intern("keys"), 0);
524
- for (i = 0; i < RARRAY(arr)->len; i++) {
525
- key = RSTRING(RARRAY(arr)->ptr[i])->ptr;
527
+ for (i = 0; i < RARRAY_LEN(arr); i++) {
528
+ key = RSTRING_PTR(RARRAY_PTR(arr)[i]);
526
529
  gp_result_check(gp_widget_get_child_by_name(c->config, key, &(c->childConfig)));
527
530
  gp_result_check(gp_widget_get_type(c->childConfig, &widgettype));
528
531
  switch (widgettype) {
529
532
  case GP_WIDGET_RADIO:
530
- rb_hash_aset(cfg, RARRAY(arr)->ptr[i], getRadio(c->childConfig));
533
+ rb_hash_aset(cfg, RARRAY_PTR(arr)[i], getRadio(c->childConfig));
531
534
  break;
532
535
  case GP_WIDGET_TEXT:
533
- rb_hash_aset(cfg, RARRAY(arr)->ptr[i], getText(c->childConfig));
536
+ rb_hash_aset(cfg, RARRAY_PTR(arr)[i], getText(c->childConfig));
534
537
  break;
535
538
  case GP_WIDGET_RANGE:
536
- rb_hash_aset(cfg, RARRAY(arr)->ptr[i], getRange(c->childConfig));
539
+ rb_hash_aset(cfg, RARRAY_PTR(arr)[i], getRange(c->childConfig));
537
540
  break;
538
541
  case GP_WIDGET_TOGGLE:
539
- rb_hash_aset(cfg, RARRAY(arr)->ptr[i], getToggle(c->childConfig));
542
+ rb_hash_aset(cfg, RARRAY_PTR(arr)[i], getToggle(c->childConfig));
540
543
  break;
541
544
  case GP_WIDGET_DATE:
542
- rb_hash_aset(cfg, RARRAY(arr)->ptr[i], getDate(c->childConfig));
545
+ rb_hash_aset(cfg, RARRAY_PTR(arr)[i], getDate(c->childConfig));
543
546
  break;
544
547
  default:
545
548
  break;
@@ -584,13 +587,13 @@ VALUE camera_config_merge(VALUE self, VALUE hash) {
584
587
  arr = rb_funcall(hash, rb_intern("keys"), 0);
585
588
  cfgs = rb_iv_get(self, "@configuration");
586
589
  cfg_changed = rb_iv_get(self, "@configs_changed");
587
- for (i = 0; i < RARRAY(arr)->len; i++) {
588
- switch(TYPE(RARRAY(arr)->ptr[i])) {
590
+ for (i = 0; i < RARRAY_LEN(arr); i++) {
591
+ switch(TYPE(RARRAY_PTR(arr)[i])) {
589
592
  case T_STRING:
590
- key = RSTRING(RARRAY(arr)->ptr[i])->ptr;
593
+ key = RSTRING_PTR(RARRAY_PTR(arr)[i]);
591
594
  break;
592
595
  case T_SYMBOL:
593
- key = rb_id2name(rb_to_id(RARRAY(arr)->ptr[i]));
596
+ key = rb_id2name(rb_to_id(RARRAY_PTR(arr)[i]));
594
597
  break;
595
598
  default:
596
599
  rb_raise(rb_eTypeError, "Not valid key type");
@@ -602,23 +605,23 @@ VALUE camera_config_merge(VALUE self, VALUE hash) {
602
605
  switch (widgettype) {
603
606
  case GP_WIDGET_RADIO:
604
607
  rb_ary_push(cfg_changed, rb_str_new2(key));
605
- setRadio(self, c, rb_hash_aref(hash, RARRAY(arr)->ptr[i]), 0);
608
+ setRadio(self, c, rb_hash_aref(hash, RARRAY_PTR(arr)[i]), 0);
606
609
  break;
607
610
  case GP_WIDGET_TEXT:
608
611
  rb_ary_push(cfg_changed, rb_str_new2(key));
609
- setText(self, c, rb_hash_aref(hash, RARRAY(arr)->ptr[i]), 0);
612
+ setText(self, c, rb_hash_aref(hash, RARRAY_PTR(arr)[i]), 0);
610
613
  break;
611
614
  case GP_WIDGET_RANGE:
612
615
  rb_ary_push(cfg_changed, rb_str_new2(key));
613
- setRange(self, c, rb_hash_aref(hash, RARRAY(arr)->ptr[i]), 0);
616
+ setRange(self, c, rb_hash_aref(hash, RARRAY_PTR(arr)[i]), 0);
614
617
  break;
615
618
  case GP_WIDGET_TOGGLE:
616
619
  rb_ary_push(cfg_changed, rb_str_new2(key));
617
- setToggle(self, c, rb_hash_aref(hash, RARRAY(arr)->ptr[i]), 0);
620
+ setToggle(self, c, rb_hash_aref(hash, RARRAY_PTR(arr)[i]), 0);
618
621
  break;
619
622
  case GP_WIDGET_DATE:
620
623
  rb_ary_push(cfg_changed, rb_str_new2(key));
621
- setDate(self, c, rb_hash_aref(hash, RARRAY(arr)->ptr[i]), 0);
624
+ setDate(self, c, rb_hash_aref(hash, RARRAY_PTR(arr)[i]), 0);
622
625
  break;
623
626
  default:
624
627
  break;
@@ -666,7 +669,7 @@ VALUE camera_get_value(int argc, VALUE *argv, VALUE self) {
666
669
 
667
670
  switch (TYPE(str)) {
668
671
  case T_STRING:
669
- name = RSTRING(str)->ptr;
672
+ name = RSTRING_PTR(str);
670
673
  break;
671
674
  case T_SYMBOL:
672
675
  name = rb_id2name(rb_to_id(str));
@@ -799,7 +802,7 @@ VALUE camera_set_value(VALUE self, VALUE str, VALUE newVal) {
799
802
 
800
803
  switch (TYPE(str)) {
801
804
  case T_STRING:
802
- name = RSTRING(str)->ptr;
805
+ name = RSTRING_PTR(str);
803
806
  break;
804
807
  case T_SYMBOL:
805
808
  name = rb_id2name(rb_to_id(str));
@@ -1070,7 +1073,7 @@ VALUE camera_folder_down(VALUE self, VALUE folder) {
1070
1073
 
1071
1074
  gp_list_new(&list);
1072
1075
 
1073
- name = RSTRING(folder)->ptr;
1076
+ name = RSTRING_PTR(folder);
1074
1077
  RESULT_CHECK_LIST(gp_camera_folder_list_folders(c->camera, c->virtFolder, list, c->context), list);
1075
1078
  RESULT_CHECK_LIST(gp_list_find_by_name(list, &index, name), list);
1076
1079
  if (strlen(c->virtFolder) > 1) {
@@ -1102,7 +1105,7 @@ VALUE camera_create_folder(VALUE self, VALUE folder) {
1102
1105
 
1103
1106
  Data_Get_Struct(self, GPhoto2Camera, c);
1104
1107
 
1105
- name = RSTRING(folder)->ptr;
1108
+ name = RSTRING_PTR(folder);
1106
1109
  gp_result_check(gp_camera_folder_make_dir(c->camera, c->virtFolder, name, c->context));
1107
1110
  return self;
1108
1111
  }
data/ext/gphoto2camera.h CHANGED
@@ -23,6 +23,7 @@
23
23
  #include <stdlib.h>
24
24
  #include <stdio.h>
25
25
  #include <fcntl.h>
26
+ #include <unistd.h>
26
27
  #include <string.h>
27
28
  #include <gphoto2/gphoto2.h>
28
29
  #include <ruby.h>
@@ -62,7 +62,7 @@ VALUE listRadio(CameraWidget *cc) {
62
62
  VALUE setRadio(VALUE self, GPhoto2Camera *c, VALUE newVal, int save) {
63
63
  const char *val;
64
64
 
65
- val = RSTRING(rb_funcall(newVal, rb_intern("to_s"), 0))->ptr;
65
+ val = RSTRING_PTR(rb_funcall(newVal, rb_intern("to_s"), 0));
66
66
 
67
67
  gp_result_check(gp_widget_set_value(c->childConfig, val));
68
68
  if (save == 1) {
@@ -85,7 +85,7 @@ VALUE getText(CameraWidget *cc) {
85
85
  VALUE setText(VALUE self, GPhoto2Camera *c, VALUE newVal, int save) {
86
86
  const char *val;
87
87
 
88
- val = RSTRING(rb_funcall(newVal, rb_intern("to_s"), 0))->ptr;
88
+ val = RSTRING_PTR(rb_funcall(newVal, rb_intern("to_s"), 0));
89
89
 
90
90
  gp_result_check(gp_widget_set_value(c->childConfig, val));
91
91
  if (save == 1) {
@@ -140,7 +140,7 @@ VALUE getToggle(CameraWidget *cc) {
140
140
 
141
141
  VALUE setToggle(VALUE self, GPhoto2Camera *c, VALUE newVal, int save) {
142
142
  int val = -1;
143
- char *nV;
143
+ const char *nV;
144
144
 
145
145
  switch(TYPE(newVal)) {
146
146
  case T_TRUE:
@@ -150,7 +150,7 @@ VALUE setToggle(VALUE self, GPhoto2Camera *c, VALUE newVal, int save) {
150
150
  val = 0;
151
151
  break;
152
152
  case T_SYMBOL:
153
- nV = rb_id2name(rb_to_id(newVal));
153
+ nV = rb_id2name(SYM2ID(newVal));
154
154
  if (strcmp(nV, "true") == 0) {
155
155
  val = 1;
156
156
  } else if(strcmp(nV, "false") == 0) {
@@ -206,7 +206,7 @@ void saveConfigs(VALUE self, GPhoto2Camera *c) {
206
206
  cfgs = rb_iv_get(self, "@configuration");
207
207
  name = rb_ary_shift(cfg_changed);
208
208
  while (TYPE(name) != T_NIL) {
209
- gp_result_check(gp_widget_get_child_by_name(c->config, RSTRING(name)->ptr, &(c->childConfig)));
209
+ gp_result_check(gp_widget_get_child_by_name(c->config, RSTRING_PTR(name), &(c->childConfig)));
210
210
  gp_result_check(gp_widget_get_type(c->childConfig, &widgettype));
211
211
  switch (widgettype) {
212
212
  case GP_WIDGET_RADIO:
data/ext/gphoto4ruby.c CHANGED
@@ -19,12 +19,14 @@
19
19
  * along with GPhoto4Ruby. If not, see <http://www.gnu.org/licenses/>.
20
20
  *
21
21
  */
22
+ /*
23
+ #ifndef RUBY_19
24
+ #define RSTRING_PTR(c) (RSTRING(c)->ptr)
25
+ #define RARRAY_PTR(c) (RARRAY(c)->ptr)
26
+ #define RARRAY_LEN(c) (RARRAY(c)->len)
27
+ #endif
28
+ */
22
29
 
23
- #include <stdlib.h>
24
- #include <stdio.h>
25
- #include <fcntl.h>
26
- #include <string.h>
27
- #include <gphoto2/gphoto2.h>
28
30
  #include <ruby.h>
29
31
  #include "gphoto2camera_event.h"
30
32
  #include "gphoto2camera_utilities.h"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gphoto4ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - neq4 company
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-06-15 00:00:00 +04:00
13
+ date: 2009-10-14 00:00:00 +04:00
14
14
  default_executable:
15
15
  dependencies: []
16
16