@@ -988,7 +988,6 @@ def print_block(self, block):
988988 dsl_name = block .dsl_name
989989 write = self .f .write
990990
991- assert (not input ) or (input .endswith ('\n ' ))
992991 assert not ((dsl_name == None ) ^ (output == None )), "you must specify dsl_name and output together, dsl_name " + repr (dsl_name )
993992
994993 if not dsl_name :
@@ -1122,12 +1121,16 @@ def parse_file(filename, *, verify=True, output=None, encoding='utf-8'):
11221121 clinic = Clinic (language , verify = verify , filename = filename )
11231122
11241123 with open (filename , 'r' , encoding = encoding ) as f :
1125- text = clinic .parse (f .read ())
1124+ raw = f .read ()
1125+
1126+ cooked = clinic .parse (raw )
1127+ if cooked == raw :
1128+ return
11261129
11271130 directory = os .path .dirname (filename ) or '.'
11281131
11291132 with tempfile .TemporaryDirectory (prefix = "clinic" , dir = directory ) as tmpdir :
1130- bytes = text .encode (encoding )
1133+ bytes = cooked .encode (encoding )
11311134 tmpfilename = os .path .join (tmpdir , os .path .basename (filename ))
11321135 with open (tmpfilename , "wb" ) as f :
11331136 f .write (bytes )
@@ -2619,6 +2622,7 @@ def main(argv):
26192622 cmdline .add_argument ("-f" , "--force" , action = 'store_true' )
26202623 cmdline .add_argument ("-o" , "--output" , type = str )
26212624 cmdline .add_argument ("--converters" , action = 'store_true' )
2625+ cmdline .add_argument ("--make" , action = 'store_true' )
26222626 cmdline .add_argument ("filename" , type = str , nargs = "*" )
26232627 ns = cmdline .parse_args (argv )
26242628
@@ -2697,6 +2701,23 @@ def main(argv):
26972701 print ("All return converters also accept (doc_default=None)." )
26982702 sys .exit (0 )
26992703
2704+ if ns .make :
2705+ if ns .output or ns .filename :
2706+ print ("Usage error: can't use -o or filenames with --make." )
2707+ print ()
2708+ cmdline .print_usage ()
2709+ sys .exit (- 1 )
2710+ for root , dirs , files in os .walk ('.' ):
2711+ for rcs_dir in ('.svn' , '.git' , '.hg' ):
2712+ if rcs_dir in dirs :
2713+ dirs .remove (rcs_dir )
2714+ for filename in files :
2715+ if not filename .endswith ('.c' ):
2716+ continue
2717+ path = os .path .join (root , filename )
2718+ parse_file (path , verify = not ns .force )
2719+ return
2720+
27002721 if not ns .filename :
27012722 cmdline .print_usage ()
27022723 sys .exit (- 1 )
0 commit comments