Skip to content

Commit

Permalink
Not use WrapExcel::Cygwin when ruby platform is not cywgin.
Browse files Browse the repository at this point in the history
Not run when not install cygwin.
  • Loading branch information
tomiacannondale committed Feb 19, 2012
1 parent 7b30f25 commit 1bc314e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 40 deletions.
40 changes: 1 addition & 39 deletions lib/wrap_excel.rb
Expand Up @@ -3,47 +3,9 @@
require File.join(File.dirname(__FILE__), 'wrap_excel/sheet')
require File.join(File.dirname(__FILE__), 'wrap_excel/cell')
require File.join(File.dirname(__FILE__), 'wrap_excel/range')
require File.join(File.dirname(__FILE__), 'wrap_excel/cygwin') if RUBY_PLATFORM =~ /cygwin/
require "wrap_excel/version"

module WrapExcel

module Cygwin
require 'Win32API'

@conv_to_full_posix_path =
Win32API.new('cygwin1.dll', 'cygwin_conv_to_full_posix_path', 'PP', 'I')
@conv_to_posix_path =
Win32API.new('cygwin1.dll', 'cygwin_conv_to_posix_path', 'PP', 'I')
@conv_to_full_win32_path =
Win32API.new('cygwin1.dll', 'cygwin_conv_to_full_win32_path', 'PP', 'I')
@conv_to_win32_path =
Win32API.new('cygwin1.dll', 'cygwin_conv_to_win32_path', 'PP', 'I')

def cygpath(options, path)
absolute = shortname = false
func = nil
options.delete(" \t-").chars {|opt|
case opt
when ?u
func = [@conv_to_full_posix_path, @conv_to_posix_path]
when ?w
func = [@conv_to_full_win32_path, @conv_to_win32_path]
when ?a
absolute = true
when ?s
shortname = true
end
}
raise "first argument must contain -u or -w" if func.nil?
func = absolute ? func[0] : func[1]
buf = "\0" * 300
if func.Call(path, buf) == -1
raise "cannot convert path name"
end
buf.delete!("\0")
buf
end
module_function :cygpath
end

end
40 changes: 40 additions & 0 deletions lib/wrap_excel/cygwin.rb
@@ -0,0 +1,40 @@
module WrapExcel
module Cygwin
require 'Win32API'

@conv_to_full_posix_path =
Win32API.new('cygwin1.dll', 'cygwin_conv_to_full_posix_path', 'PP', 'I')
@conv_to_posix_path =
Win32API.new('cygwin1.dll', 'cygwin_conv_to_posix_path', 'PP', 'I')
@conv_to_full_win32_path =
Win32API.new('cygwin1.dll', 'cygwin_conv_to_full_win32_path', 'PP', 'I')
@conv_to_win32_path =
Win32API.new('cygwin1.dll', 'cygwin_conv_to_win32_path', 'PP', 'I')

def cygpath(options, path)
absolute = shortname = false
func = nil
options.delete(" \t-").chars {|opt|
case opt
when ?u
func = [@conv_to_full_posix_path, @conv_to_posix_path]
when ?w
func = [@conv_to_full_win32_path, @conv_to_win32_path]
when ?a
absolute = true
when ?s
shortname = true
end
}
raise "first argument must contain -u or -w" if func.nil?
func = absolute ? func[0] : func[1]
buf = "\0" * 300
if func.Call(path, buf) == -1
raise "cannot convert path name"
end
buf.delete!("\0")
buf
end
module_function :cygpath
end
end
2 changes: 1 addition & 1 deletion spec/cygwin_spec.rb
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
require File.join(File.dirname(__FILE__), './spec_helper')

describe WrapExcel::Cygwin, :if => RUBY_PLATFORM =~ /cygwin/ do
describe "on cygwin", :if => RUBY_PLATFORM =~ /cygwin/ do
describe ".cygpath" do
context "cygwin path is '/cygdrive/c/Users'" do
context "with '-w' options" do
Expand Down

0 comments on commit 1bc314e

Please sign in to comment.