#NEWLINE# def main( ) : #NEWLINE# #INDENT# from optparse import OptionParser #NEWLINE# parser = OptionParser ( usage = 'usage: %prog [options] file(s)' , version = __version__ ) #NEWLINE# parser . add_option ( '-f' , '--file' , metavar = 'FILE' , dest = 'tagfile' , default = 'tags' , help = 'Write tags into FILE (default: "tags").  Use "-" to write tags to stdout.' ) #NEWLINE# 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".' ) #NEWLINE# ( options , args ) = parser . parse_args ( ) #NEWLINE# if ( options . tagfile == '-' ) : #NEWLINE# #INDENT# output = sys . stdout #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# output = open ( options . tagfile , 'wb' ) #NEWLINE# #UNINDENT# for filename in args : #NEWLINE# #INDENT# f = open ( filename , 'rb' ) #NEWLINE# buf = f . read ( ) #NEWLINE# try : #NEWLINE# #INDENT# buf = buf . decode ( 'utf-8' ) #NEWLINE# #UNINDENT# except UnicodeDecodeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# lines = buf . splitlines ( ) #NEWLINE# f . close ( ) #NEWLINE# del buf #NEWLINE# sections = findSections ( filename , lines ) #NEWLINE# genTagsFile ( output , sectionsToTags ( sections ) , sort = f . sort ) #NEWLINE# #UNINDENT# output . flush ( ) #NEWLINE# output . close ( )