Skip to content

Commit

Permalink
Renaming varnam_get_scheme_details() to varnam_get_all_handles
Browse files Browse the repository at this point in the history
  • Loading branch information
navaneeth committed Apr 25, 2015
1 parent 319ec99 commit d423ed8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
3 changes: 2 additions & 1 deletion api.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ varnam_set_suggestions_dir (const char *dir);
VARNAM_EXPORT extern int
varnam_init(const char *scheme_file, varnam **handle, char **msg);


VARNAM_EXPORT extern varray*
varnam_get_all_scheme_details();
varnam_get_all_handles();

/**
* Gets the scheme file currently used
Expand Down
19 changes: 6 additions & 13 deletions varnam.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,12 @@ destroy_scheme_details(vscheme_details *details)
}

varray*
varnam_get_all_scheme_details()
varnam_get_all_handles()
{
tinydir_dir dir;
tinydir_file file;
varnam *handle;
vscheme_details *details;
varray *schemeDetails = NULL;
varnam *handle = NULL;
varray *handles = NULL;
int rc;
char *msg;

Expand All @@ -509,21 +508,16 @@ varnam_get_all_scheme_details()
if (!file.is_dir && (strcmp("vst", file.extension) == 0)) {
rc = varnam_init(file.path, &handle, &msg);
if (rc == VARNAM_SUCCESS) {
rc = varnam_get_scheme_details(handle, &details);
if (rc == VARNAM_SUCCESS) {
schemeDetails = schemeDetails == NULL ? varray_init() : schemeDetails;
varray_push(schemeDetails, details);
varnam_destroy(handle);
handle = NULL;
}
handles = handles == NULL ? varray_init() : handles;
varray_push(handles, handle);
}
}
}
tinydir_next(&dir);
}

tinydir_close(&dir);
return schemeDetails;
return handles;
}

int
Expand All @@ -540,7 +534,6 @@ varnam_get_scheme_details(varnam *handle, vscheme_details **details)
d = scheme_details_new();
rc = vst_load_scheme_details(handle, d);
if (rc != VARNAM_SUCCESS) {
destroy_scheme_details(d);
return rc;
}

Expand Down
30 changes: 18 additions & 12 deletions varnamc
Original file line number Diff line number Diff line change
Expand Up @@ -1364,20 +1364,26 @@ def stemrules(hash,options={})
end

def display_available_schemes
schemes = VarnamLibrary::varnam_get_all_scheme_details()
unless schemes.nil?
handles = VarnamLibrary::varnam_get_all_handles()
unless handles.nil?
puts "SCHEMES AVAILABLE"
puts "================="
VarnamLibrary::varray_length(schemes).times do |i|
d = VarnamLibrary.varray_get(schemes, i)
item = VarnamLibrary::SchemeDetails.new(d)
puts " Lang code: #{item[:langCode].read_string}"
puts " Identifier: #{item[:identifier].read_string}"
puts " Display name: #{item[:displayName].read_string}"
puts " Author: #{item[:author].read_string}"
puts " Compiled on: #{item[:compiledDate].read_string}"
puts " Stable?: #{item[:isStable] > 0 ? true : false}"
puts "\n\n"
VarnamLibrary::varray_length(handles).times do |i|
handle = VarnamLibrary.varray_get(handles, i)
ptr = FFI::MemoryPointer.new :pointer
done = VarnamLibrary.varnam_get_scheme_details(handle, ptr)
if done != 0
puts "Failed to get scheme details"
else
item = VarnamLibrary::SchemeDetails.new(ptr.get_pointer(0))
puts " Lang code: #{item[:langCode].read_string}"
puts " Identifier: #{item[:identifier].read_string}"
puts " Display name: #{item[:displayName].read_string}"
puts " Author: #{item[:author].read_string}"
puts " Compiled on: #{item[:compiledDate].read_string}"
puts " Stable?: #{item[:isStable] > 0 ? true : false}"
puts "\n\n"
end
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion varnamruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class Word < FFI::Struct
attach_function :varnam_compact_learnings_file, [:pointer], :int
attach_function :varnam_create_token, [:pointer, :string, :string, :string, :string, :string, :int, :int, :int, :int, :int], :int
attach_function :varnam_set_scheme_details, [:pointer, :pointer], :int
attach_function :varnam_get_all_scheme_details, [], :pointer
attach_function :varnam_get_all_handles, [], :pointer
attach_function :varnam_get_scheme_details, [:pointer, :pointer], :int
attach_function :varnam_get_last_error, [:pointer], :string
attach_function :varnam_flush_buffer, [:pointer], :int
attach_function :varnam_config, [:pointer, :int, :varargs], :int
Expand Down

0 comments on commit d423ed8

Please sign in to comment.