def ask_selection(com=nil)
trap('INT') do puts "exit with q command"; return 'continue' end
prompt='vpp command (? for help): '
com ||= ask(prompt)
output = nil
com.chomp!
return 'continue' if com == ''
booklet,twosided,selection,lpropt = nil,nil,'',''
com = com.split
while c=com.shift
case c
when 'q'
if ENV['VPPCHECKSAVED'] && ! @saved
puts "You requested saving but did not use the o command"
puts "Another q will destroy your copy"
@saved = true
return 'continue'
end
rm_rf(TMP)
return 'quit'
when 'e'
quit(nil,EDITEXIT)
when 'c'
quit(nil,COMPILEEXIT)
when 'v'
view(@viewer,@filename);
return 'continue'
when /^x([0-9]+)$/
lpropt = "-#"+$1
when /^o(.*)/
output = $1.sub(/\~/,ENV['HOME'])
if output == ''
puts("filename must follow o without spacing")
return 'continue'
end
if output =~ /[^A-Za-z0-9_-]/
puts("filename (#{output}) must consist of alphanumeric characters and _ and - only")
return 'continue'
end
@saved = true
when /^p(.*)/
if $1 == ''
puts("p must be followed with a printer name, without spacing")
return 'continue'
end
@printer = "-P#{$1}"
return 'continue' if com.empty?
when /^d(.*)$/
case $1
when 'f'
@doublesided = false
when 't'
@doublesided = true
else
puts("d must be followed by t (true) or f (false)")
return 'continue'
end
return 'continue' if com.empty?
when 'b'
booklet = true
when 't'
twosided = true
when 'a'
selection += ' -'
when '-'
selection += ' -'
when /^((\d+-?\d*|\d*-?\d+),?)+$/
selection += ' '+c.sub(/,$/,'')
when /^(\?|h)$/
puts input_options
return 'continue'
else
puts "Illegal specification(s)"
puts input_options
return 'continue'
end
end
selection = selection.strip.gsub(/ /,',')
selection.sub!(/^-/,'1-')
selection.sub!(/-$/,"-#{@pagecount}")
selection.split(/\D+/).each do |n|
unless n.to_i.between?(1,@pagecount)
puts "Illegal page number #{n}; PDF has #{@pagecount} pages"
return 'continue'
end
end
return selection,booklet,twosided,lpropt,output
end