Skip to content

Commit

Permalink
Merge pull request varnamproject#169 from asdofindia/enable-debugging
Browse files Browse the repository at this point in the history
Add a simple debugging option to command line.
  • Loading branch information
subins2000 authored Mar 17, 2021
2 parents 04fab19 + 23976d7 commit f32d681
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions varnamc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions varnamruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit f32d681

Please sign in to comment.