@@ -274,6 +274,14 @@ def header_sort(self, config_file, lines_list, file_name, start, end,
274
274
output_list .append (ifdef )
275
275
break
276
276
elif "#include" in lines_list [i ]:
277
+ include_line = self .header_regex .search (lines_list [i ])
278
+ if not include_line :
279
+ # Write headers and #ifdef blocks if found
280
+ written = self .write_headers (includes , ifdef_blocks )
281
+ if written :
282
+ output_list .extend (written )
283
+ return (output_list , includes_present , i , True )
284
+
277
285
if "NOLINT" in lines_list [i ]:
278
286
# NOLINT is a barrier, so flush includes
279
287
written = self .write_headers (includes )
@@ -292,8 +300,6 @@ def header_sort(self, config_file, lines_list, file_name, start, end,
292
300
continue
293
301
294
302
# Insert header into appropriate list
295
- include_line = self .header_regex .search (lines_list [i ])
296
-
297
303
idx = self .classify_header (config_file , include_line , file_name )
298
304
if idx != - 1 :
299
305
if include_line .group ("comment" ):
@@ -370,10 +376,11 @@ def run_pipeline(self, config_file, name, lines):
370
376
output_list .extend (suboutput )
371
377
372
378
# Remove possible extra newline from #endif
373
- output_list [- 1 ] = output_list [- 1 ].rstrip ()
379
+ if len (output_list ) > 0 :
380
+ output_list [- 1 ] = output_list [- 1 ].rstrip ()
381
+ output_list .append ("" )
374
382
375
383
# Write rest of file
376
- output_list .append ("" )
377
384
output_list .extend (lines_list [i :])
378
385
379
386
output = self .linesep .join (output_list ).rstrip () + self .linesep
0 commit comments