From 23976d752bd95cc3efa304a0aafc2732b0cdd232 Mon Sep 17 00:00:00 2001 From: Akshay S Dinesh Date: Mon, 15 Feb 2021 12:53:26 +0530 Subject: [PATCH] feat: option to do debugging --- varnamc | 19 +++++++++++++++++++ varnamruby.rb | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/varnamc b/varnamc index e15bcf6..97b3f17 100755 --- a/varnamc +++ b/varnamc @@ -105,6 +105,11 @@ optparse = OptionParser.new do |opts| $options[:verbose] = true end + $options[:debug] = false + opts.on('-z', '--debug', 'Enable debugging') do + $options[:debug] = true + end + opts.on('-t', '--transliterate TEXT', 'Transliterate the given text') do |text| set_action('transliterate') $options[:text_to_transliterate] = text @@ -313,6 +318,16 @@ def initialize_varnam_handle exit(1) end + if ($options[:debug]) + puts "Turning debug on" + done = VarnamLibrary.varnam_enable_logging($varnam_handle.get_pointer(0), Varnam::VARNAM_LOG_DEBUG, DebugCallback); + if done != 0 + error_message = VarnamLibrary.varnam_get_last_error($varnam_handle.get_pointer(0)) + puts "Unable to turn debugging on. #{error_message}" + exit(1) + end + end + end def get_file_path(fname) @@ -1088,6 +1103,10 @@ ExportCallback = FFI::Function.new(:void, [:int, :int, :string]) do |total_words $stdout.flush end +DebugCallback = FFI::Function.new(:void, [:string]) do |message| + puts message +end + def learn_from_file if $options[:learn_from].nil? puts "Nothing to learn" diff --git a/varnamruby.rb b/varnamruby.rb index d8e59ba..a384c02 100644 --- a/varnamruby.rb +++ b/varnamruby.rb @@ -67,6 +67,7 @@ class Word < FFI::Struct attach_function :varnam_import_learnings_from_file, [:pointer, :string, :pointer], :int attach_function :varnam_create_stemrule, [:pointer, :string, :string], :int attach_function :varnam_create_stem_exception, [:pointer, :string, :string], :int + attach_function :varnam_enable_logging, [:pointer, :int, :pointer], :int end VarnamToken = Struct.new(:type, :pattern, :value1, :value2, :value3, :tag, :match_type, :priority, :accept_condition, :flags) @@ -117,6 +118,9 @@ module Varnam VARNAM_EXPORT_WORDS = 0 VARNAM_EXPORT_FULL = 1 + + VARNAM_LOG_DEFAULT = 1 + VARNAM_LOG_DEBUG = 2 # Language codes LANG_CODES = {VARNAM_LANG_CODE_UNKNOWN => 'Unknown',