The AI version considers .dep file lines with length >= 4 to be relevant. I think this is an error. A line in .dep file with length == 4 (a line that contains, for example, nothing but ".tcz") should be ignored. I think testing for length > 4 is what we want.
Here's what I think is our final version:
#!/usr/bin/awk -f
# treegen.awk v3.5 (May 6, 2026)
# usage example: $ treegen.awk vlc-dev.tcz
BEGIN {
LINUX_VERSION = "6.18.2-tinycore64"
MIRROR_PATH = "/mnt/usb/http/tinycorelinux/17.x/x86_64/tcz/"
get_dependencies(ARGV[1], 0)
}
# Cache:
# loaded[pkg] = 1 once pkg.dep has been read (even if empty/missing)
# ndeps[pkg] = number of deps found
# deps[pkg, i] = ith dep (1..ndeps[pkg])
function load_depfile(pkg, depfile, line, n) {
if (loaded[pkg]) return
loaded[pkg] = 1
depfile = MIRROR_PATH pkg ".dep"
n = 0
while (getline line < depfile > 0) {
gsub(/[ \t\r]+/, "", line)
if (line == "") continue
# endswith ".tcz" is faster/stricter than /\.tcz/
L = length(line)
if (L > 4 && substr(line, L-3) == ".tcz")
deps[pkg, ++n] = line
}
close(depfile)
ndeps[pkg] = n
}
function get_dependencies(tczname, depth, i, n) {
gsub(/KERNEL/, LINUX_VERSION, tczname)
printf("%"depth"s%s\n", "", tczname)
load_depfile(tczname)
n = ndeps[tczname]
for (i = 1; i <= n; i++) {
get_dependencies(deps[tczname, i], depth + 3)
}
}