Skip to content

Commit

Permalink
modified various parts to correctly handle encoding issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
KojiNakamaru committed Aug 25, 2014
1 parent 280cfdc commit 432a6b0
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 12 deletions.
3 changes: 2 additions & 1 deletion build/win/LWFS/.a/start-remote.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set JRUBY_OPTS="--server -J-Djruby.jit.threshold=30"
set TZ=
set LWFS_USE_REMOTE_SERVER=1
set LWFS_LOG_FILE=../../lwfs.log
for /f "usebackq tokens=*" %%i in (`ruby -e "puts Encoding.default_external"`) do @set LWFS_EXTERNAL_ENCODING=%%i
cd lwfs

if "%LWFS_DATA_FOLDER%" == "." goto :setdatafolder
Expand All @@ -13,7 +14,7 @@ ver | find "XP"
if %errorlevel% EQU 0 goto :winxp

:run
ruby "%~dp0ruby19\bin\rackup" lwfs.ru
ruby -Ku "%~dp0ruby19\bin\rackup" lwfs.ru
exit

:setdatafolder
Expand Down
3 changes: 2 additions & 1 deletion build/win/LWFS/.a/start.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set JRUBY_OPTS="--server -J-Djruby.jit.threshold=30"
set TZ=
set LWFS_USE_REMOTE_SERVER=0
set LWFS_LOG_FILE=../../lwfs.log
for /f "usebackq tokens=*" %%i in (`ruby -e "puts Encoding.default_external"`) do @set LWFS_EXTERNAL_ENCODING=%%i
cd lwfs

if "%LWFS_DATA_FOLDER%" == "." goto :setdatafolder
Expand All @@ -13,7 +14,7 @@ ver | find "XP"
if %errorlevel% EQU 0 goto :winxp

:run
ruby "%~dp0ruby19\bin\rackup" lwfs.ru
ruby -Ku "%~dp0ruby19\bin\rackup" lwfs.ru
exit

:setdatafolder
Expand Down
Binary file modified build/win/ruby19.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion gems/rb-img/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.7
0.0.8
14 changes: 14 additions & 0 deletions gems/rb-img/ext/img/img.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
* img.c
*/

#ifdef __MINGW32__
#include <windows.h>
#endif
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -61,6 +64,9 @@ VALUE img_save(
int dst_num_bytes;
FILE *fp = NULL;
char *err_msg = NULL;
#ifdef __MINGW32__
WCHAR fname_w[MAX_PATH + 1];
#endif
rb_check_type(fname_, RUBY_T_STRING);
rb_check_type(width_, RUBY_T_FIXNUM);
rb_check_type(height_, RUBY_T_FIXNUM);
Expand Down Expand Up @@ -92,7 +98,15 @@ VALUE img_save(
err_msg = "unsupported format";
goto end;
}
#ifdef __MINGW32__
if (MultiByteToWideChar(CP_UTF8, 0, fname, strlen(fname) + 1, NULL, 0) > MAX_PATH + 1) {
goto end;
}
MultiByteToWideChar(CP_UTF8, 0, fname, strlen(fname) + 1, fname_w, MAX_PATH + 1);
fp = _wfopen(fname_w, L"wb");
#else
fp = fopen(fname, "wb");
#endif
if (! fp) {
err_msg = "failed to open the file.";
goto end;
Expand Down
2 changes: 1 addition & 1 deletion gems/rb-img/lib/rb-img.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
require 'img.so'

module Img
VERSION = '0.0.7'
VERSION = '0.0.8'
end
2 changes: 1 addition & 1 deletion gems/rb-img/rb-img.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |s|
s.name = %q{rb-img}
s.version = "0.0.7"
s.version = "0.0.8"
s.description = "ruby img extension."
s.license = "zlib"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
Expand Down
3 changes: 3 additions & 0 deletions lib/glob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ def glob(filter, ignored_pattern = nil)
filter = filter.encode(Encoding::UTF_8)
end
Dir.glob(filter).each do |e|
if RbConfig::CONFIG['host_os'].downcase =~ /darwin/
e.encode!(Encoding::UTF_8, Encoding::UTF_8_MAC)
end
entries.push(e) unless e =~ ignored_pattern
end
entries.sort
Expand Down
Binary file removed lib/swf2lwf/gems/rb-img-0.0.7.gem
Binary file not shown.
8 changes: 4 additions & 4 deletions lib/watch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
callback = Proc.new do |modified, added, removed|
$mutex.synchronize do
(modified + added + removed).each do |entry|
entry = entry.encode(Encoding::UTF_8,
Encoding.default_external,
:invalid => :replace,
:undef => :replace)
# entry = entry.encode(Encoding::UTF_8,
# Encoding.default_external,
# :invalid => :replace,
# :undef => :replace)
prefix = ''
if entry =~ /^([A-Z][A-Z0-9_\-]*)((\/[A-Z][A-Z0-9_\-]*)*)(\/?)/
# fully captal characters represent projects and allow nested folders.
Expand Down
7 changes: 4 additions & 3 deletions lwfs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def defineDirs(prefix)
defineDirs(ENV['HOME'])
end

$external_encoding = (ENV['LWFS_EXTERNAL_ENCODING'].nil?) ? Encoding.default_external : ENV['LWFS_EXTERNAL_ENCODING']
$log = Logger.new((ENV['LWFS_LOG_FILE'].nil?) ? STDOUT : ENV['LWFS_LOG_FILE'], 10)
$lwfsconf = {
'REMOTE_SERVER' => 'remote.server.name',
Expand Down Expand Up @@ -265,19 +266,19 @@ def needUpdate?(src, dst)
while not postUpdate(PORT)
sleep(1.0)
end
$watcher = spawn(RUBY_COMMAND, WATCH_SCRIPT, SRC_DIR.encode(Encoding::default_external), PORT, IS_RUNNING, IGNORED_PATTERN.to_s)
$watcher = spawn(RUBY_COMMAND, WATCH_SCRIPT, SRC_DIR.encode($external_encoding), PORT, IS_RUNNING, IGNORED_PATTERN.to_s)
end
end

get '/locate/*' do |path|
if File.directory?("#{SRC_DIR}/#{path}") or File.file?("#{SRC_DIR}/#{path}")
if RbConfig::CONFIG['host_os'].downcase =~ /darwin/
path = "#{SRC_DIR}/#{path}"
path.encode!(Encoding.default_external)
path.encode!($external_encoding)
`open -R "#{path}"`
elsif RbConfig::CONFIG['host_os'].downcase =~ /mswin(?!ce)|mingw|cygwin|bccwin/
path = "#{SRC_DIR}/#{path}".gsub(/\//, '\\')
path.encode!(Encoding.default_external)
path.encode!($external_encoding)
`start explorer /select,#{path}`
else
# not supported
Expand Down
Binary file removed vendor/cache/rb-img-0.0.7.gem
Binary file not shown.

0 comments on commit 432a6b0

Please sign in to comment.