Hiroyuki Komatsu
komat****@users*****
2004年 12月 16日 (木) 23:44:10 JST
Index: prime/lib/prime.rb diff -u prime/lib/prime.rb:1.15 prime/lib/prime.rb:1.16 --- prime/lib/prime.rb:1.15 Wed Dec 15 23:12:58 2004 +++ prime/lib/prime.rb Thu Dec 16 23:44:09 2004 @@ -1,5 +1,5 @@ # prime/prime.rb -# $Id: prime.rb,v 1.15 2004/12/15 14:12:58 komatsu Exp $ +# $Id: prime.rb,v 1.16 2004/12/16 14:44:09 komatsu Exp $ # # Copyright (C) 2002, 2003, 2004 Hiroyuki Komatsu <komat****@taiya*****> # All rights reserved. @@ -314,7 +314,14 @@ # words_uniclause) - words_compact = words[0,1] + ## Ruby 1.6 does not keep the class PrimeWordList word[0,1] if the + ## value of word is [], and the class of the result of word[0,1] + ## becomes Array which is a super class of PrimewordList. + if words.empty? then + words_compact = PrimeWordList.new() + else + words_compact = words[0,1] + end if words_compact.length > 0 then predict_with_multi_clauses!(words_compact) Index: prime/lib/prime-japanese.rb diff -u prime/lib/prime-japanese.rb:1.7 prime/lib/prime-japanese.rb:1.8 --- prime/lib/prime-japanese.rb:1.7 Sun Aug 29 22:51:16 2004 +++ prime/lib/prime-japanese.rb Thu Dec 16 23:44:09 2004 @@ -1,5 +1,5 @@ # prime/prime-japnese.rb: Japanese module for PRIME. -# $Id: prime-japanese.rb,v 1.7 2004/08/29 13:51:16 komatsu Exp $ +# $Id: prime-japanese.rb,v 1.8 2004/12/16 14:44:09 komatsu Exp $ # # Copyright (C) 2004 Hiroyuki Komatsu <komat****@taiya*****> # All rights reserved. @@ -417,24 +417,35 @@ return @@suikyo end - if PRIME_ENV['suikyo_use_cache'] and force == false then - threshold_time = [File::mtime(File::expand_path(__FILE__)), - File::mtime(PRIME_CONFIGFILE_GLOBAL), - File::mtime(PRIME_CONFIGFILE_LOCAL)].max + ## lock "suikyo.rbo" + lock_io = File.new(PRIME_USER_DIR) + if lock_io.flock( File::LOCK_EX | File::LOCK_NB ) then + + if PRIME_ENV['suikyo_use_cache'] and force == false then + threshold_time = [File::mtime(File::expand_path(__FILE__)), + File::mtime(PRIME_CONFIGFILE_GLOBAL), + File::mtime(PRIME_CONFIGFILE_LOCAL)].max + else + threshold_time = Time.new() + end + filename_cache = File::join2(PRIME_USER_DIR, "suikyo.rbo") + + suikyo = Marshal::init_file(filename_cache, threshold_time) { + PrimeTypeConv::initialize_suikyo_internal(typing_method) + } + + suikyo.table.table_files.each {|file| + if File::mtime(filename_cache) < File::mtime(file) then + return PrimeTypeConv::initialize_suikyo(true) + end + } + + ## unlock "suikyo.rbo" + lock_io.flock( File::LOCK_UN | File::LOCK_NB ) else - threshold_time = Time.new() + ## If the locking failed, the cache file is not used. + suikyo = PrimeTypeConv::initialize_suikyo_internal(typing_method) end - filename_cache = File::join2(PRIME_USER_DIR, "suikyo.rbo") - suikyo = Marshal::init_file(filename_cache, threshold_time) { - suikyo = Suikyo.new - tables = (PRIME_ENV['suikyo_tables'] or - PRIME_TYPING_TABLE[typing_method] or - []) - tables.each {|table| - suikyo.table.loadfile(table) - } - suikyo - } # Version checking if suikyo.respond_to?('convert_internal') == false then @@ -447,12 +458,6 @@ exit() end - suikyo.table.table_files.each {|file| - if File::mtime(filename_cache) < File::mtime(file) then - return PrimeTypeConv::initialize_suikyo(true) - end - } - PRIME_ENV['suikyo_tables'] = suikyo.table.table_files if PRIME_ENV['suikyo_reverse_tables'].nil? then PRIME_ENV['suikyo_reverse_tables'] = @@ -477,4 +482,16 @@ @@suikyo = suikyo return suikyo end + + ## This initializes the instance of Suikyo. + def PrimeTypeConv::initialize_suikyo_internal (typing_method) + suikyo = Suikyo.new() + tables = (PRIME_ENV['suikyo_tables'] or + PRIME_TYPING_TABLE[typing_method] or + []) + tables.each {|table| + suikyo.table.loadfile(table) + } + return suikyo + end end