def main():
    from optparse import OptionParser

    parser = OptionParser(usage = "usage: %prog [options] file(s)",
                          version = __version__)
    parser.add_option(
            "-f", "--file", metavar = "FILE", dest = "tagfile",
            default = "tags",
            help = 'Write tags into FILE (default: "tags").  Use "-" to write '
                   'tags to stdout.')
    parser.add_option(
            "", "--sort", metavar="[yes|foldcase|no]", dest = "sort",
            choices = ["yes", "no", "foldcase"],
            default = "yes",
            help = 'Produce sorted output.  Acceptable values are "yes", '
                   '"no", and "foldcase".  Default is "yes".')

    options, args = parser.parse_args()

    if options.tagfile == '-':
        output = sys.stdout
    else:
        output = open(options.tagfile, 'wb')

    for filename in args:
        f = open(filename, 'rb')
        buf = f.read()

        try:
            buf = buf.decode('utf-8')
        except __HOLE__:
            pass

        lines = buf.splitlines()

        f.close()
        del buf

        sections = findSections(filename, lines)

        genTagsFile(output, sectionsToTags(sections), sort=options.sort)

    output.flush()
    output.close()
dataset/ETHPy150Open jszakmeister/rst2ctags/rst2ctags.py/main