Я написал спагети
def find_re_it_in_list(pattern, input, start=0, stop=-1, flags=0):
length = len(input)
if length == 0:
return None
end_it = max(0, length - 1)
if start >= end_it:
return None
if stop<0:
stop = length
if stop <= start:
return None
for it in range(max(0, start), min(stop, length)):
elem = input[it]
match = re.match(pattern, elem, flags)
if match:
return it
def get_includes(self):
args = [self.conf['gcc_path'], '-xc', '-E', '-v', os.devnull]
args.extend(self.env.get('flags', []))
incl_start_regex = r' *#include <\.\.\.> search starts here: *'
incl_end_regex = r' *End of search list\. *'
proc = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT , text=True)
lines = proc.stdout.splitlines()
start_it = find_re_it_in_list(incl_start_regex, lines)
if start_it == None:
return []
end_it = find_re_it_in_list(incl_end_regex, lines, start_it)
if end_it == None:
return []
# theres no paths between them
if (end_it - start_it) == 1:
return []
return lines[start_it+1 : end_it]