Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdfmakerからの子プロセス呼び出しを、ベタ文字列ではなく、なるべく配列で渡す #1091

Merged
merged 4 commits into from
Aug 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions lib/review/pdfmaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require 'erb'
require 'tmpdir'
require 'open3'
require 'shellwords'

require 'review/i18n'
require 'review/book'
Expand Down Expand Up @@ -186,47 +187,53 @@ def build_pdf
warn 'command configuration is prohibited in safe mode. ignored.'
texcommand = ReVIEW::Configure.values['texcommand']
dvicommand = ReVIEW::Configure.values['dvicommand']
dvioptions = ReVIEW::Configure.values['dvioptions']
texoptions = ReVIEW::Configure.values['texoptions']
dvioptions = ReVIEW::Configure.values['dvioptions'].shellsplit
texoptions = ReVIEW::Configure.values['texoptions'].shellsplit
makeindex_command = ReVIEW::Configure.values['pdfmaker']['makeindex_command']
makeindex_options = ReVIEW::Configure.values['pdfmaker']['makeindex_options']
makeindex_options = ReVIEW::Configure.values['pdfmaker']['makeindex_options'].shellsplit
makeindex_sty = ReVIEW::Configure.values['pdfmaker']['makeindex_sty']
makeindex_dic = ReVIEW::Configure.values['pdfmaker']['makeindex_dic']
else
texcommand = @config['texcommand'] if @config['texcommand']
dvicommand = @config['dvicommand'] if @config['dvicommand']
dvioptions = @config['dvioptions'] if @config['dvioptions']
texoptions = @config['texoptions'] if @config['texoptions']
unless @config['texcommand'].present?
error "texcommand isn't defined."
end
texcommand = @config['texcommand']
dvicommand = @config['dvicommand']
@config['dvioptions'] = '' unless @config['dvioptions']
dvioptions = @config['dvioptions'].shellsplit
@config['texoptions'] = '' unless @config['texoptions']
texoptions = @config['texoptions'].shellsplit
makeindex_command = @config['pdfmaker']['makeindex_command']
makeindex_options = @config['pdfmaker']['makeindex_options']
@config['pdfmaker']['makeindex_options'] = '' unless @config['pdfmaker']['makeindex_options']
makeindex_options = @config['pdfmaker']['makeindex_options'].shellsplit
makeindex_sty = @config['pdfmaker']['makeindex_sty']
makeindex_dic = @config['pdfmaker']['makeindex_dic']
end

if makeindex_sty.present?
makeindex_sty = File.absolute_path(makeindex_sty, @basedir)
makeindex_options += " -s #{makeindex_sty}" if File.exist?(makeindex_sty)
makeindex_options += ['-s', makeindex_sty] if File.exist?(makeindex_sty)
end
if makeindex_dic.present?
makeindex_dic = File.absolute_path(makeindex_dic, @basedir)
makeindex_options += " -d #{makeindex_dic}" if File.exist?(makeindex_dic)
makeindex_options += ['-d', makeindex_dic] if File.exist?(makeindex_dic)
end

2.times do
system_or_raise("#{texcommand} #{texoptions} #{@mastertex}.tex")
system_or_raise(*[texcommand, texoptions, "#{@mastertex}.tex"].flatten.compact)
end

call_hook('hook_beforemakeindex')
if @config['pdfmaker']['makeindex'] && File.exist?("#{@mastertex}.idx")
system_or_raise("#{makeindex_command} #{makeindex_options} #{@mastertex}")
system_or_raise(*[makeindex_command, makeindex_options, @mastertex].flatten.compact)
end
call_hook('hook_aftermakeindex')

system_or_raise("#{texcommand} #{texoptions} #{@mastertex}")
system_or_raise(*[texcommand, texoptions, "#{@mastertex}.tex"].flatten.compact)
call_hook('hook_aftertexcompile')

if File.exist?("#{@mastertex}.dvi")
system_or_raise("#{dvicommand} #{dvioptions} #{@mastertex}.dvi")
if File.exist?("#{@mastertex}.dvi") && dvicommand.present?
system_or_raise(*[dvicommand, dvioptions, "#{@mastertex}.dvi"].flatten.compact)
call_hook('hook_afterdvipdf')
end
end
Expand Down Expand Up @@ -474,7 +481,7 @@ def call_hook(hookname)
if ENV['REVIEW_SAFE_MODE'].to_i & 1 > 0
warn 'hook configuration is prohibited in safe mode. ignored.'
else
system_or_raise("#{hook} #{Dir.pwd} #{@basedir}")
system_or_raise(hook, Dir.pwd, @basedir)
end
end
end
Expand Down