Class: Efl::EcoreGetopt::REcoreGetopt

Inherits:
Object
  • Object
show all
Defined in:
lib/efl/ecore_getopt.rb

Instance Method Summary (collapse)

Constructor Details

- (REcoreGetopt) initialize(desc)

Returns a new instance of REcoreGetopt



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/efl/ecore_getopt.rb', line 88

def initialize desc
    @ecore_getopt = nil
    @desc = desc
    @options = [
        [ 0 ],
    ]
    @values = [
        [ :ptrp, FFI::Pointer::NULL ]
    ]
    @refs = [] # to prevent FFI::MemoryPointer.from_string from beeing GC'ed
end

Instance Method Details

- (Object) <<(o)



106
107
108
# File 'lib/efl/ecore_getopt.rb', line 106

def << o
    @options.insert -2, o
end

- (Object) append(short, long, help, sub_type)



225
226
227
# File 'lib/efl/ecore_getopt.rb', line 225

def append short, long, help, sub_type
    self << [ short, long, help, FFI::Pointer::NULL, :ecore_getopt_action_append, [:append,sub_type] ]
end

- (Object) append_metavar(short, long, help, meta, sub_type)



228
229
230
# File 'lib/efl/ecore_getopt.rb', line 228

def append_metavar short, long, help, meta, sub_type
    self << [ short, long, help, meta, :ecore_getopt_action_append, [:append,sub_type] ]
end

- (Object) callback_args(short, long, help, meta, cb, data = nil)



240
241
242
# File 'lib/efl/ecore_getopt.rb', line 240

def callback_args short, long, help, meta, cb, data=nil
    callback_full short, long, help, meta, cb, data, :ecore_getopt_desc_arg_requirement_yes, FFI::Pointer::NULL
end

- (Object) callback_full(short, long, help, meta, cb, data, arg_req, def_val)



234
235
236
# File 'lib/efl/ecore_getopt.rb', line 234

def callback_full short, long, help, meta, cb, data, arg_req, def_val
    self << [ short, long, help, meta, :ecore_getopt_action_callback, [:callback, [cb, data, arg_req, def_val] ] ]
end

- (Object) callback_noargs(short, long, help, cb, data = nil)



237
238
239
# File 'lib/efl/ecore_getopt.rb', line 237

def callback_noargs short, long, help, cb, data=nil
    callback_full short, long, help, FFI::Pointer::NULL, cb, data, :ecore_getopt_desc_arg_requirement_no, FFI::Pointer::NULL
end

- (Object) choice(short, long, help, choices)



209
210
211
212
213
214
215
216
# File 'lib/efl/ecore_getopt.rb', line 209

def choice short, long, help, choices
    ptr = FFI::MemoryPointer.new(:pointer, choices.length+1)
    choices.each_with_index do |s, i|
        ptr[i].put_pointer 0, p_from_string(s)
    end
    ptr[choices.length].put_pointer 0, FFI::Pointer::NULL
    self << [ short, long, help, FFI::Pointer::NULL, :ecore_getopt_action_choice, [:choices,ptr] ]
end

- (Object) choice_metavar(short, long, help, meta, choices)



217
218
219
220
221
222
223
224
# File 'lib/efl/ecore_getopt.rb', line 217

def choice_metavar short, long, help, meta, choices
    ptr = FFI::MemoryPointer.new(:pointer, choices.length+1)
    choices.each_with_index do |s, i|
        ptr[i].put_pointer 0, p_from_string(s)
    end
    ptr[choices.length].put_pointer 0, FFI::Pointer::NULL
    self << [ short, long, help, meta, :ecore_getopt_action_choice, [:choices,ptr] ]
end


249
250
251
# File 'lib/efl/ecore_getopt.rb', line 249

def copyright short, long
    self << [ short, long, 'show copyright.', FFI::Pointer::NULL, :ecore_getopt_action_copyright, [:dummy,FFI::Pointer::NULL] ]
end

- (Object) count(short, long, help)



231
232
233
# File 'lib/efl/ecore_getopt.rb', line 231

def count short, long, help
    self << [ short, long, help, FFI::Pointer::NULL, :ecore_getopt_action_count, [:dummy,FFI::Pointer::NULL] ]
end

- (Object) create



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/efl/ecore_getopt.rb', line 115

def create
    @ecore_getopt = Native::EcoreGetopt.new( FFI::MemoryPointer.new( :uchar, Native::EcoreGetopt.size+Native::EcoreGetoptDesc.size*@options.length) )
    [:prog,:usage,:version,:copyright,:license,:description].each do |sym|
        @ecore_getopt[sym] = ( @desc.has_key?(sym) ? FFI::MemoryPointer.from_string(@desc[sym]) : FFI::Pointer::NULL )
    end
    @ecore_getopt[:strict] = @desc[:strict] if @desc.has_key? :strict
    @options.each_with_index do |o,i|
        d = @ecore_getopt.desc_ptr i
        if o[0]==0
            d[:shortname] = d[:longname] = d[:help] = d[:metavar] = d[:action] = d[:action_param][:dummy] = 0
            break
        end
        d[:shortname] = o[0].to_s.bytes.first
        d[:longname] = p_from_string o[1]
        d[:help] = p_from_string o[2]
        d[:metavar] = o[3]
        d[:action] = o[4]
        k, v = o[5]
        case k
        when :dummy
            d[:action_param][:dummy] = v
        when :callback
            cb = d[:action_param][:callback]
            cb[:func] = v[0]
            cb[:data] = v[1]
            cb[:arg_req] = v[2]
            cb[:def] = v[3]
        when :store
            st = d[:action_param][:store]
            st[:type] = v[0]
            st[:arg_req] = v[1]
            if not v[2].nil?
                if v[2][0]==:strv
                    st[:def][:strv] = p_from_string v[2][1]
                else
                    st[:def][v[2][0]] = v[2][1]
                end
            end
        when :store_const
            d[:action_param][:store_const] = v
        when :choices
            d[:action_param][:choices] = v
        when :append
            d[:action_param][:append_type] = v
        else
            d[:action_param][:dummy] = FFI::Pointer::NULL
        end
    end
    @values_p = FFI::MemoryPointer.new Native::EcoreGetoptValue, @values.length, false
    @values.each_with_index do |v,i|
        Native::EcoreGetoptValue.new(@values_p+(i*Native::EcoreGetoptValue.size))[v[0]] = v[1]
    end
end

- (Object) debug

def sentinel

    self << [ 0, FFI::Pointer::NULL, FFI::Pointer::NULL, FFI::Pointer::NULL, 0, {:dummy=>FFI::Pointer::NULL} ]
end


259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/efl/ecore_getopt.rb', line 259

def debug
    r = ''
    r << "#{self.class} : #{@ecore_getopt.to_ptr}\n"
    [:prog,:usage,:version,:copyright,:license,:description].each do |sym|
        r<< "  #{sym.to_s} : #{@ecore_getopt[sym]==FFI::Pointer::NULL ? 'NULL' : @ecore_getopt[sym].read_string}\n"
    end
    r << "  strict : #{@ecore_getopt[:strict]}\n"
    i=0
    while true
        d = @ecore_getopt.desc_ptr i
        break if d[:shortname]==0 and d[:longname] == FFI::Pointer::NULL
        r << "    desc #{d.to_ptr}\n"
        r << "     short: #{d[:shortname].chr}\n" unless d[:shortname]==0
        r << "     long:  #{d[:longname].read_string}\n" unless d[:longname]==FFI::Pointer::NULL
        r << "     help:  #{d[:help].read_string}\n" unless d[:help]==FFI::Pointer::NULL
        i+=1
    end
    r
end

- (Object) help(short, long)



243
244
245
# File 'lib/efl/ecore_getopt.rb', line 243

def help short, long
    self << [ short, long, 'show this message.', FFI::Pointer::NULL, :ecore_getopt_action_help, [:dummy,FFI::Pointer::NULL] ]
end

- (Object) license(short, long)



252
253
254
# File 'lib/efl/ecore_getopt.rb', line 252

def license short, long
    self << [ short, long, 'show license.', FFI::Pointer::NULL, :ecore_getopt_action_license, [:dummy,FFI::Pointer::NULL] ]
end

- (Object) parse(argv)



168
169
170
171
172
173
174
175
# File 'lib/efl/ecore_getopt.rb', line 168

def parse argv
    ptr = FFI::MemoryPointer.new(:pointer, argv.length+1)
    argv.each_with_index do |s, i|
        ptr[i].put_pointer 0, p_from_string(s)
    end
    ptr[argv.length].put_pointer 0, FFI::Pointer::NULL
    Native.ecore_getopt_parse @ecore_getopt, @values_p, argv.length, ptr
end

- (Object) store(short, long, help, type)



179
180
181
# File 'lib/efl/ecore_getopt.rb', line 179

def store short, long, help, type
    store_full short, long, help, FFI::Pointer::NULL, type, :ecore_getopt_desc_arg_requirement_yes, nil
end

- (Object) store_const(short, long, help, value)



200
201
202
# File 'lib/efl/ecore_getopt.rb', line 200

def store_const short, long, help, value
    self << [ short, long, help, FFI::Pointer::NULL, :ecore_getopt_action_store_const, [:store_const, value] ]
end

- (Object) store_def(short, long, help, type, def_val)



191
192
193
# File 'lib/efl/ecore_getopt.rb', line 191

def store_def short, long, help, type, def_val
    store_full short, long, help, FFI::Pointer::NULL, type, :ecore_getopt_desc_arg_requirement_optional, def_val
end

- (Object) store_def_type(type, short, long, help, def_val)



194
195
196
# File 'lib/efl/ecore_getopt.rb', line 194

def store_def_type type, short, long, help, def_val
    store_def short, long, help, ('ecore_getopt_type_'+type.to_s).to_sym, [ (type.to_s+'v').to_sym, def_val ]
end

- (Object) store_false(short, long, help)



206
207
208
# File 'lib/efl/ecore_getopt.rb', line 206

def store_false short, long, help
    self << [ short, long, help, FFI::Pointer::NULL, :ecore_getopt_action_store_false, [:dummy,FFI::MemoryPointer::NULL] ]
end

- (Object) store_full(short, long, help, meta, type, arg_req, def_val)



176
177
178
# File 'lib/efl/ecore_getopt.rb', line 176

def store_full short, long, help, meta, type, arg_req, def_val
    self << [ short, long, help, meta, :ecore_getopt_action_store, [:store, [type,arg_req, def_val] ] ]
end

- (Object) store_full_type(type, short, long, help, meta, arg_req, def_val)



197
198
199
# File 'lib/efl/ecore_getopt.rb', line 197

def store_full_type type, short, long, help, meta, arg_req, def_val
    store_full short, long, help, meta, ('ecore_getopt_type_'+type.to_s).to_sym, arg_req, [ (type.to_s+'v').to_sym, def_val ]
end

- (Object) store_meta_type(type, short, long, help, meta)



188
189
190
# File 'lib/efl/ecore_getopt.rb', line 188

def store_meta_type type, short, long, help, meta
    store_metavar short, long, help, meta, ('ecore_getopt_type_'+type.to_s).to_sym
end

- (Object) store_metavar(short, long, help, meta, type)



185
186
187
# File 'lib/efl/ecore_getopt.rb', line 185

def store_metavar short, long, help, meta, type
    store_full short, long, help, meta, type, :ecore_getopt_desc_arg_requirement_yes, nil
end

- (Object) store_true(short, long, help)



203
204
205
# File 'lib/efl/ecore_getopt.rb', line 203

def store_true short, long, help
    self << [ short, long, help, FFI::Pointer::NULL, :ecore_getopt_action_store_true, [:dummy,FFI::MemoryPointer::NULL] ]
end

- (Object) store_type(type, short, long, help)



182
183
184
# File 'lib/efl/ecore_getopt.rb', line 182

def store_type type, short, long, help
    store short, long, help, ('ecore_getopt_type_'+type.to_s).to_sym
end

- (Object) to_ptr



112
113
114
# File 'lib/efl/ecore_getopt.rb', line 112

def to_ptr
    @ecore_getopt.to_ptr
end

- (Object) value(type, ptr)



109
110
111
# File 'lib/efl/ecore_getopt.rb', line 109

def value type, ptr
    @values.insert -2, [ type, ptr ]
end

- (Object) version(short, long)



246
247
248
# File 'lib/efl/ecore_getopt.rb', line 246

def version short, long
    self << [ short, long, 'show program version.', FFI::Pointer::NULL, :ecore_getopt_action_version, [:dummy,FFI::Pointer::NULL] ]
end