gmt 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 95a8003af67677af616118eca5328e10c509cb84
4
- data.tar.gz: 58224d0ff46be31e78016d23a4173afd334b996e
3
+ metadata.gz: 7fa6455137a875453333acb344af988d06610a9c
4
+ data.tar.gz: b06416fe648fda0fa83d1d8d8a2b38c2fb3e41a9
5
5
  SHA512:
6
- metadata.gz: 47e480dfdfe0c27b70e727d39e5e362a004fc760d0b80018390baee247b7ecc08ed3683d4da48cc467d556a742f537537330e82436f7d7612780487e40c201da
7
- data.tar.gz: 82e1c0d38739842d0d7ba33dd5239c7eece6b13532f55d830ef338f6b5e43d82a87dd7750eb2817ffce819f8f10fe61012083e93af397d874be9e726ff1fd877
6
+ metadata.gz: 95eba465b3606499f9200fbcd41e5d5426282a5a9436eea512e5b71a4f7abdc23806fc9c12e647283aad032394d27379bbbee01ddfc672212af57c7ce7fa73a2
7
+ data.tar.gz: 4f4149ed3eb0b7e80c149d140cbdbb568e8edebde42e837a85512e178bae1858a205d7c7f72b423c0030711bab0dca650a50f28d29ab8fe5262df4be8abe2ad6
data/ext/gmt/gmt.c CHANGED
@@ -81,8 +81,7 @@ static VALUE gmt_release(VALUE self)
81
81
  static VALUE gmt_simple(const char *name, int argc, VALUE *argv, VALUE self)
82
82
  {
83
83
  VALUE files, opts;
84
- rb_scan_args(argc, argv, "*:", &files, &opts);
85
- if (TYPE(opts) == T_NIL) opts = rb_hash_new();
84
+ rb_scan_args(argc, argv, "*1", &files, &opts);
86
85
 
87
86
  gmt_t *gmt;
88
87
  Data_Get_Struct(self, gmt_t, gmt);
@@ -91,7 +90,7 @@ static VALUE gmt_simple(const char *name, int argc, VALUE *argv, VALUE self)
91
90
  void *session = gmt->session;
92
91
 
93
92
  gmt_option_t *gmt_opts;
94
- gmt_opts = ruby_hash_to_gmt_options(opts, session);
93
+ gmt_opts = ruby_array_to_gmt_options(opts, session);
95
94
  gmt_opts = append_inputs_to_gmt_options(files, gmt_opts, session);
96
95
 
97
96
  int err = GMT_Call_Module(session, name, -1, gmt_opts);
data/ext/gmt/option.c CHANGED
@@ -8,35 +8,13 @@
8
8
 
9
9
  #include "option.h"
10
10
 
11
- typedef struct {
12
- void *session;
13
- gmt_option_t *gmt_opts;
14
- } rhtgo_cb_arg_t;
15
-
16
- static void rhtgo_cb_arg_free(void *arg){ };
17
-
18
- static VALUE rhtgo_cb_arg_class;
19
-
20
- static ID append_id(void)
21
- {
22
- static ID cached = 0;
23
-
24
- if (! cached)
25
- cached = rb_intern(">>");
26
-
27
- return cached;
28
- }
29
-
30
- static ID id_of_key(VALUE key)
11
+ static char char_of_key(VALUE key)
31
12
  {
32
13
  if (TYPE(key) != T_SYMBOL)
33
14
  rb_raise(rb_eArgError, "option keys should be symbols");
34
15
 
35
- return SYM2ID(key);
36
- }
16
+ ID key_id = SYM2ID(key);
37
17
 
38
- static char char_of_key_id(ID key_id)
39
- {
40
18
  const char *key_s = rb_id2name(key_id);
41
19
 
42
20
  if (key_s == NULL || *key_s == '\0')
@@ -54,91 +32,41 @@ static gmt_option_t* append_option(void *session,
54
32
  return GMT_Append_Option(session, gmt_opt, gmt_opts);
55
33
  }
56
34
 
57
- static int rhtgo_cb(VALUE key, VALUE value, VALUE arg)
35
+ extern gmt_option_t* ruby_array_to_gmt_options(VALUE opts, void *session)
58
36
  {
59
- rhtgo_cb_arg_t *rhtgo_cb_arg;
60
-
61
- Data_Get_Struct(arg, rhtgo_cb_arg_t, rhtgo_cb_arg);
62
-
63
- void *session = rhtgo_cb_arg->session;
64
- gmt_option_t *gmt_opt, *gmt_opts = rhtgo_cb_arg->gmt_opts;
37
+ if (TYPE(opts) != T_ARRAY)
38
+ rb_raise(rb_eArgError, "options should be an array");
65
39
 
66
- ID key_id = id_of_key(key);
40
+ gmt_option_t *gmt_opts = NULL;
67
41
 
68
- if (key_id == append_id())
42
+ for (size_t i = 0 ; i < RARRAY_LEN(opts) ; i++)
69
43
  {
70
- /*
71
- the append key (>>) is a special case, since this needs to be converted
72
- to the (option, argument) pair ('>', '>filename'), see the discussion at
73
- http://gmt.soest.hawaii.edu/boards/1/topics/3665?r=3677
74
- */
75
-
76
- if (TYPE(value) != T_STRING)
77
- rb_raise(rb_eArgError, "argument for >> option must be a string");
78
-
79
- const char *filename = StringValueCStr(value);
80
- size_t len = strlen(filename);
81
- char option_arg[len+2];
82
- snprintf(option_arg, len+2, ">%s", filename);
83
-
84
- gmt_opts = append_option(session, '>', option_arg, gmt_opts);
85
- }
86
- else
87
- {
88
- char option_name = char_of_key_id(key_id);
89
-
90
- switch (TYPE(value))
44
+ VALUE opt = RARRAY_PTR(opts)[i];
45
+ if (TYPE(opt) != T_ARRAY)
46
+ rb_raise(rb_eArgError, "each option should be a array");
47
+ if (RARRAY_LEN(opt) != 2)
48
+ rb_raise(rb_eArgError, "each option should be a pair");
49
+ VALUE key = RARRAY_PTR(opt)[0];
50
+ char option_name = char_of_key(key);
51
+ VALUE arg = RARRAY_PTR(opt)[1];
52
+ const char *option_arg;
53
+ switch (TYPE(arg))
91
54
  {
92
- const char *option_arg;
93
-
94
55
  case T_STRING:
95
- option_arg = StringValueCStr(value);
96
- gmt_opts = append_option(session, option_name, option_arg, gmt_opts);
56
+ option_arg = StringValueCStr(arg);
97
57
  break;
98
58
 
99
59
  case T_NIL:
100
- gmt_opts = append_option(session, option_name, NULL, gmt_opts);
101
- break;
102
-
103
- case T_ARRAY:
104
- for (size_t i = 0 ; i < RARRAY_LEN(value) ; i++)
105
- {
106
- VALUE item = RARRAY_PTR(value)[i];
107
- if (TYPE(item) != T_STRING)
108
- rb_raise(rb_eArgError, "option arguments should be strings");
109
- option_arg = StringValueCStr(item);
110
- gmt_opts = append_option(session, option_name, option_arg, gmt_opts);
111
- }
60
+ option_arg = NULL;
112
61
  break;
113
62
 
114
63
  default:
115
- rb_raise(rb_eArgError, "option arguments should be strings or arrays");
64
+ rb_raise(rb_eArgError, "option argument should be string or nil");
116
65
  }
66
+ gmt_opts = append_option(session, option_name, option_arg, gmt_opts);
117
67
  }
118
68
 
119
- rhtgo_cb_arg->gmt_opts = gmt_opts;
120
-
121
- return ST_CONTINUE;
122
- }
123
-
124
- extern gmt_option_t* ruby_hash_to_gmt_options(VALUE opts, void *session)
125
- {
126
- gmt_option_t *gmt_opt, *gmt_opts = NULL;
127
- rhtgo_cb_arg_t *rhtgo_cb_arg = ALLOC(rhtgo_cb_arg_t);
128
-
129
- rhtgo_cb_arg->session = session;
130
- rhtgo_cb_arg->gmt_opts = NULL;
131
-
132
- VALUE arg =
133
- Data_Wrap_Struct(rhtgo_cb_arg_class,
134
- NULL,
135
- rhtgo_cb_arg_free,
136
- rhtgo_cb_arg);
137
-
138
-
139
- rb_hash_foreach(opts, rhtgo_cb, arg);
140
-
141
- return rhtgo_cb_arg->gmt_opts;
69
+ return gmt_opts;
142
70
  }
143
71
 
144
72
  extern gmt_option_t* append_inputs_to_gmt_options(VALUE files,
data/ext/gmt/option.h CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  typedef struct GMT_OPTION gmt_option_t;
16
16
 
17
- extern gmt_option_t* ruby_hash_to_gmt_options(VALUE, void*);
17
+ extern gmt_option_t* ruby_array_to_gmt_options(VALUE, void*);
18
18
  extern gmt_option_t* append_inputs_to_gmt_options(VALUE, gmt_option_t*, void*);
19
19
 
20
20
  #endif
data/lib/gmt.rb CHANGED
@@ -99,9 +99,11 @@ class GMT
99
99
  # @see http://gmt.soest.hawaii.edu/doc/latest/$1.html
100
100
  def wrapper_ps(method)
101
101
  define_method(method) do |*args, options|
102
+ options = postscript_options(options)
103
+ fix_append_option!(options)
102
104
  self.send(api_function(method),
103
105
  *string_arguments(args),
104
- postscript_options(options))
106
+ array_options(options))
105
107
  end
106
108
  end
107
109
 
@@ -113,9 +115,10 @@ class GMT
113
115
  # @see http://gmt.soest.hawaii.edu/doc/latest/$1.html
114
116
  def wrapper_other(method)
115
117
  define_method(method) do |*args, options|
118
+ fix_append_option!(options)
116
119
  self.send(api_function(method),
117
120
  *string_arguments(args),
118
- options)
121
+ array_options(options))
119
122
  end
120
123
  end
121
124
 
@@ -135,6 +138,30 @@ class GMT
135
138
  args.map(&:to_s)
136
139
  end
137
140
 
141
+ # handle the :>> option
142
+
143
+ def fix_append_option!(options)
144
+ if file = options.delete(:>>) then
145
+ options[:>] = '>' + file
146
+ end
147
+ end
148
+
149
+ # convert the options hash to an array of pairs
150
+
151
+ def array_options(options)
152
+ options.inject(Array.new) do |result, pair|
153
+ key, values = pair
154
+ if values.respond_to? :each then
155
+ values.each do |value|
156
+ result << [key, value]
157
+ end
158
+ else
159
+ result << [key, values]
160
+ end
161
+ result
162
+ end
163
+ end
164
+
138
165
  # for GMT modules which produce PostScript, convert the
139
166
  # convenience options (:position, :file) to the hash
140
167
  # equivalent of the -K, -O options, and the creation of
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gmt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - J.J. Green
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-03 00:00:00.000000000 Z
11
+ date: 2016-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -101,7 +101,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
- requirements: []
104
+ requirements:
105
+ - ghostscript (gs) for the test-suite
105
106
  rubyforge_project:
106
107
  rubygems_version: 2.2.2
107
108
  signing_key: