/usr/lib/ruby/vendor_ruby/kakasi/ffi.rb is in ruby-kakasi-ffi 1.0.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | module Kakasi
module Lib
if defined?(Rubinius)
FFI = Rubinius::FFI
else
require 'ffi'
end
extend FFI::Library
require 'kakasi/platform'
try_load { |lib|
ffi_lib lib
}
attach_function 'kakasi_getopt_argv', [:int, :pointer], :int
attach_function 'kakasi_do', [:string], :pointer
attach_function 'kakasi_close_kanwadict', [], :int
attach_function 'kakasi_free', [:pointer], :int
INTERNAL_ENCODING = Encoding::CP932
@mutex = Mutex.new
@options = nil
def kakasi(options, string)
@mutex.synchronize {
if options != @options
kakasi_close_kanwadict() if @options
args = ['kakasi', *options.split]
argc = args.size
argv = FFI::MemoryPointer.new(:pointer, argc).
write_array_of_pointer(args.map { |arg|
FFI::MemoryPointer.from_string(arg)
})
kakasi_getopt_argv(argc, argv).zero? or
raise "failed to initialize kakasi"
@options = options.dup
end
encoding = string.encoding
result = ''.force_encoding(INTERNAL_ENCODING)
string.encode(INTERNAL_ENCODING).split(/(\0+)/).each { |str, nul|
buf = kakasi_do(str)
result << buf.read_string.force_encoding(INTERNAL_ENCODING)
kakasi_free(buf)
result << nul if nul
}
result.encode(encoding)
}
end
module_function :kakasi
end
end
|