#!/bin/rc nl=' '; fn readlinks { awk ' function isurl(s) { return s ~ /^\.\/|^\.\.\/|^http:\/\/|^https:\/\/|^gemini:\/\// } # Image: [xpx] () Source: /^(Image|Banner|Icon): [^ ]+ \[[0-9]+x[0-9]+px\]/ && isurl((url = $2)) { print url; next; } # Video: [xpx] () /^Video: [^ ]+ \[[0-9]+x[0-9]+px\] \(Preview: [^ )]+\)/ && isurl((url = $2)) && isurl((previewurl = substr($5, 1, length($5) - 1))) { print url; print previewurl; next; } # Audio: /^Audio: [^ ]+$/ && isurl((url = $2)) { print url; next; } # : (: ) match($0, /: [^ ]+ \(/) && (altend = RSTART) && (xaltstart = RSTART + RLENGTH) && isurl((url = substr($0, RSTART + 2, RLENGTH - 4))) && match($0, /: [^ ]+\)$/) && (xaltend = RSTART) && isurl((xurl = substr($0, RSTART + 2, RLENGTH - 3))) { print url; print xurl; next; } # : () match($0, /: [^ ]+ \(/) && isurl((url = substr($0, RSTART + 2, RLENGTH - 4))) && /\)$/ { print url; next; } # (: ) match($0, /^[^ ]+ \(/) && (xaltstart = RLENGTH + 1) && match($0, /: [^ ]+\)$/) && (xaltend = RSTART) && isurl((url = $1)) && isurl((xurl = substr($NF, 1, length($NF) - 1))) { print url; print xurl; next; } # () — /^[^ ]+ \(/ && match($0, /\) — /) && isurl((url = $1)) { print url; next; } # () /^[^ ]+ \(/ && /\)$/ && isurl((url = $1)) { print url; next; } # isurl((url = $0)) { print url; next; } # See also: # Further reading: # For more details, see: /(See also|Further reading|For more details, see): [^ ]+$/ && isurl((url = $NF)) { print url; next; } # - : # .* forces last occurrence. match($0, /- .*: /) && isurl((url = substr($0, RLENGTH + 1))) { print url; next; } # - /^- / && isurl((url = substr($0, 3))) { print url; next; } # : # .* forces last occurrence. match($0, /.*: /) && isurl((url = substr($0, RLENGTH + 1))) { print url; next; } # — , /^— / && /, [^ ]+$/ && isurl((url = $NF)) { print url; next; } ' $1 } echo 'strict graph {'; echo ' layout=fdp' echo ' node [label="" shape=circle width=0.1 height=0.1 fixedsize=true style=filled fillcolor=white]' for (dir in `{ walk -d }) { if (test -e `$nl{ echo $dir^/index.txt }) echo ' '"$dir/"; if not echo ' '"$dir/" '[style="filled,dotted"]'; } for (dir in `{ walk -d }) { if (test ! -e `$nl{ echo $dir^/index.txt }) { for (subdir in `{ walk -d -n1,1 $dir }) { echo ' '"$dir/" '--' "$subdir/" '[style="filled,dotted"]'; } } } for (file in `{ walk -f | grep '(^|/)index.txt$' }) { for (url in `$nl{ readlinks $file }) { if (~ $url ./* ../*) { if (~ $url */index.txt */) { relurl=`$nl{ cleanname `$nl{ basename -d $file }^/`$nl{ echo $url } }; if (~ $relurl */index.txt) echo ' '"`{ basename -d $file }^/" '--' "`{ basename -d $relurl }^/"; if not echo ' '"`{ basename -d $file }^/" '--' "$relurl/" '[style="filled,dotted"]'; } } } } echo '}'