2022-08-13 20:11:56 +00:00
|
|
|
#!/usr/bin/env python.com
|
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
|
|
|
def GetDeps(path):
|
2022-08-14 00:20:50 +00:00
|
|
|
def Dive(path, depth, visited):
|
|
|
|
sys.stdout.write('%s%s' % ('\t' * depth, path))
|
|
|
|
if path in visited:
|
|
|
|
sys.stdout.write(' cycle\n')
|
2022-08-13 20:11:56 +00:00
|
|
|
return
|
2022-08-14 00:20:50 +00:00
|
|
|
sys.stdout.write('\n')
|
2022-08-13 20:11:56 +00:00
|
|
|
with open(path) as f:
|
|
|
|
code = f.read()
|
|
|
|
for dep in re.findall(r'[.#]include "([^"]+)"', code):
|
2022-08-14 00:20:50 +00:00
|
|
|
Dive(dep, depth + 1, visited + [path])
|
|
|
|
Dive(path, 0, [])
|
2022-08-13 20:11:56 +00:00
|
|
|
sys.stdout.write('\n')
|
|
|
|
|
|
|
|
for arg in sys.argv[1:]:
|
|
|
|
if os.path.isdir(arg):
|
|
|
|
for dirpath, dirs, files in os.walk(arg):
|
|
|
|
for filepath in files:
|
|
|
|
GetDeps(os.path.join(dirpath, filepath))
|
|
|
|
else:
|
|
|
|
GetDeps(arg)
|