Method: Efl::EcoreGetopt::REcoreGetopt#create

Defined in:
lib/efl/ecore_getopt.rb

#createObject



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/efl/ecore_getopt.rb', line 183

def create
    @ecore_getopt_st = 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_st[sym] = ( @desc.has_key?(sym) ? FFI::MemoryPointer.from_string(@desc[sym]) : FFI::Pointer::NULL )
    end
    @ecore_getopt_st[:strict] = @desc[:strict] if @desc.has_key? :strict
    @options.each_with_index do |o,i|
        d = @ecore_getopt_st.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] = want_p o[1]
        d[:help] = want_p o[2]
        d[:metavar] = want_p 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]
            st[:def][v[2]] = (v[2]==:strv ?  want_p(v[3]) : v[3] ) unless v[3].nil?
        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
    @ecore_values_st = Native::EcoreGetoptValue.new FFI::MemoryPointer.new Native::EcoreGetoptValue, @values_order.length, false
    @values_order.each_with_index do |k,i|
        vtype, vpointer, *sub_type = @values[k]
        vpointer.write_pointer @ecore_getopt_st.desc_ptr(i)[:action_param][:store][:def][:strv] if vtype==:string
        etype, vfield, pfield = @types[vtype]
        @ecore_values_st.value_ptr(i)[pfield] = vpointer
    end
    self
end