def ask_selection(com=nil)
prompt='vpp command (? for help): '
com ||= ask(prompt)
output = nil
com.chomp!
return 'continue' if com == ''
booklet,twosided,selection,lpropt = nil,nil,'-',''
help = "Examples of print commands:\n5 to print page 5\n5- to print pages 5 through the end\n5-7 to print pages 5, 6 and 7\n-7 to print the first 7 pages\n5-7,19- to print pages 5, 6, 7 and 19 through the end\na to print the whole document\n- to print the whole document\na x3 to print 3 copies of the document\nx3 the same\n5 x3 to print 3 copies of page 5\nt print the whole document twosided\nt 2- print twosided starting at page 2\nb to print the whole document as an a5 size booklet\nb -12 to print the first 12 pages as an a5 size booklet\nOther commands:\ne (if called by mk) edit the tex source and rerun mk\nc (if called by mk) rerun mk\nv (re)view the ps/pdf file\noxyz send pdf output to file xyz.pdf instead of printer\nh display this help\n? display this help\nq quit\n"
com.split.each do |c|
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 's':
@save = true
return 'continue'
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 =~ /\//
puts("filename may not contain /'s")
return 'continue'
end
@saved = true
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.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