From d423ed8d0d954b68ea3b041a40bab7d0ec49adc0 Mon Sep 17 00:00:00 2001 From: Navaneeth K N Date: Sat, 25 Apr 2015 07:14:13 +0530 Subject: [PATCH] Renaming varnam_get_scheme_details() to varnam_get_all_handles --- api.h | 3 ++- varnam.c | 19 ++++++------------- varnamc | 30 ++++++++++++++++++------------ varnamruby.rb | 3 ++- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/api.h b/api.h index 9da44cf..e48cec2 100644 --- a/api.h +++ b/api.h @@ -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 diff --git a/varnam.c b/varnam.c index 217f4cc..3333c19 100644 --- a/varnam.c +++ b/varnam.c @@ -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; @@ -509,13 +508,8 @@ 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); } } } @@ -523,7 +517,7 @@ varnam_get_all_scheme_details() } tinydir_close(&dir); - return schemeDetails; + return handles; } int @@ -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; } diff --git a/varnamc b/varnamc index 150b2a3..ec0bb74 100755 --- a/varnamc +++ b/varnamc @@ -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 diff --git a/varnamruby.rb b/varnamruby.rb index 678942e..0691d4d 100644 --- a/varnamruby.rb +++ b/varnamruby.rb @@ -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