# File rdoc/rdoc.rb, line 181
    def document(argv)

      TopLevel::reset

      options = Options.instance
      options.parse(argv, GENERATORS)
    
      file_info = parse_files(options)

      gen = options.generator
      
      $stderr.puts "\nGenerating #{gen.key.upcase}..." unless options.quiet
      
      require gen.file_name
      
      gen_class = Generators.const_get(gen.class_name)
      
      unless file_info.empty?
        gen = gen_class.for(options)

        pwd = Dir.pwd

        unless options.all_one_file
          setup_output_dir(options.op_dir)
          Dir.chdir(options.op_dir)
        end

        begin
          Diagram.new(file_info, options).draw if options.diagram
          gen.generate(file_info)
        ensure
          Dir.chdir(pwd)
        end

      end
    end