2626Options:
2727 -a --all import all modules
2828 -h --help print help
29+ -o file
30+ --output file output file
2931'''
3032output_header = '//https://github.com/rust-lang-ja/ac-library-rs\n '
31- opt_list = ['help' , 'all' ]
33+ opt_list = ['help' , 'all' , 'output=' ]
3234output_list_all = ('convolution' , 'dsu' , 'fenwicktree' , 'lazysegtree' , 'math' ,
3335 'maxflow' , 'mincostflow' , 'modint' , 'scc' , 'segtree' ,
3436 'string' , 'twosat' ,
4446 'segtree' : ('internal_bit' , 'internal_type_traits' ,),
4547 'twosat' : ('internal_scc' ,), }
4648src_path = 'src/'
49+ output_path = None
4750
4851
4952def output_file (filename ):
5053 global src_path
5154
5255 res = []
53- with open (src_path + filename + '.rs' , 'r' ) as f :
56+ with open (src_path + filename + '.rs' , 'r' , encoding = 'utf-8' , newline = '' ) as f :
5457 res .append ('pub mod {} {{' .format (filename ))
5558
5659 for line in f :
@@ -61,7 +64,7 @@ def output_file(filename):
6164
6265
6366try :
64- opts , args = getopt .getopt (sys .argv [1 :], 'ah ' , opt_list )
67+ opts , args = getopt .getopt (sys .argv [1 :], 'aho: ' , opt_list )
6568except getopt .GetoptError as e :
6669 print (e )
6770 print (usage )
@@ -77,6 +80,8 @@ def output_file(filename):
7780 sys .exit (0 )
7881 elif o == '--all' or o == '-a' :
7982 args = list (output_list_all )
83+ elif o == '--output' or o == '-o' :
84+ output_path = v
8085
8186output_list = set ()
8287
@@ -108,11 +113,14 @@ def output_file(filename):
108113# rustfmt
109114with tempfile .TemporaryDirectory () as temp_dir :
110115 temp_file = temp_dir + '/output.rs'
111- with open (temp_file , 'w' ) as f :
116+ with open (temp_file , 'w' , encoding = 'utf-8' , newline = '' ) as f :
112117 print (output_header , file = f )
113118 for i in output_data :
114119 print (i , file = f )
115120 output_data = subprocess .run (["rustfmt" , temp_file ], check = True )
116- with open (temp_file , 'r' ) as f :
121+ with open (temp_file , 'r' , encoding = 'utf-8' , newline = '' ) as f :
122+ wf = open (output_path , 'w' , encoding = 'utf-8' , newline = '' ) if output_path is not None else sys .stdout
117123 for line in f :
118- print (line , end = "" )
124+ print (line , end = '' , file = wf )
125+ if output_path is not None :
126+ wf .close ()
0 commit comments