# File vpp, line 533
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'                   # drop on q
      # useful if vpp is used to print or copy data from a scanner:
      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)       # edit request for caller
    when 'c'
      quit(nil,COMPILEEXIT)    # re-compile request for caller
    when 'v'                   # (re)view the ps/pdf data
      view(@viewer,@filename);
      return 'continue'
    when /^x([0-9]+)$/         # x3 -> -#3
      lpropt = "-#"+$1
    when /^o(.*)/              # output to file instead of printer
      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(.*)/            # set printer
      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(.*)$/              # set printer to doublesided (t) or singlesided (f)
      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           # print a5 booklet
    when 't'
      twosided  = true          # print twosided
    when 'a'
      selection += ' -'         # print all
    when '-'
      selection += ' -'         # print all
    when /^((\d+-?\d*|\d*-?\d+),?)+$/ # n-m or n- or -m
      selection += ' '+c.sub(/,$/,'')
    when /^(\?|h)$/
      puts input_options
      return 'continue'
    else
      puts "Illegal specification(s)"
      puts input_options
      return 'continue'
    end
  end
  # pages in range?
  selection = selection.strip.gsub(/ /,',')             # space can be separator
  selection.sub!(/^-/,'1-')             # -m means 1-m
  selection.sub!(/-$/,"-#{@pagecount}") # n- means n-@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