main entry point for the index script.

  :param args:      the arguments for this script, as a list of string. Should
                    already have had the script name stripped. That is, if
                    there are no args provided, this should be an empty list.
  :param prog_name: the name of the script; taken from command line args by
                    default, but you can change it if you want.

def main_build_index(args=[], prog_name=sys.argv[0]):
  """
  main entry point for the index script.

  :param args:      the arguments for this script, as a list of string. Should
                    already have had the script name stripped. That is, if
                    there are no args provided, this should be an empty list.
  :param prog_name: the name of the script; taken from command line args by
                    default, but you can change it if you want.
  """
  # get options and arguments
  ui = getUI_build_index(prog_name, args)

  # just run unit tests
  if ui.optionIsSet("test"):
    unittest.main(argv=[sys.argv[0]])
    sys.exit()

  # just show help
  if ui.optionIsSet("help"):
    ui.usage()
    sys.exit()
  verbose = (ui.optionIsSet("verbose") is True) or DEFAULT_VERBOSITY

  # get input file-handle(s); fall back to stdin if none found.
  in_fhs = [open(x) for x in ui.getAllArguments()]
  if in_fhs == []:
    if sys.stdin.isatty():
      sys.stderr.write("[NO INPUT FILE FOUND; WAITING FOR INPUT FROM STDIN]\n")
    in_fhs = [sys.stdin]

  # Get output handle(s). If only one input file, and no output file, output
  # to standard out.
  out_fhs = [sys.stdout]
  if ui.optionIsSet("output"):
    out_fhs = [open(x, "w") for x in ui.getValue("output").split()]
  if len(in_fhs) != len(out_fhs):
    sys.stderr.write("mismatch between number of input files and output files")
    sys.exit(0)

  # figure out which indexer to use and then index each file
  op_val = ui.getValue("type") if ui.optionIsSet("type") else None
  indexer = __get_indexer(ui.getAllArguments(), op_val)

  for in_fh, out_fh in zip(in_fhs, out_fhs):
    indexer(in_fh, out_fh, verbose)