]> Sergey Matveev's repositories - zk.zsh.git/blobdiff - zk.zsh
Simplify iteration over the hash
[zk.zsh.git] / zk.zsh
diff --git a/zk.zsh b/zk.zsh
index 5a46d999208819990a59ed9c152d83c38debec84..6073bb1edd5533ae450d23f65f2ed446de2d47d5 100755 (executable)
--- a/zk.zsh
+++ b/zk.zsh
@@ -26,7 +26,7 @@ for f (**(.)) pages[$f]=1
 typeset -A links
 typeset -A backs
 for p (${(k)pages}) {
-    for w (`cat $p`) {
+    for w (`< $p`) {
         [[ $w =~ "^[([{].*" ]] && w=${MATCH[2,-2]}
         [[ ${pages[$w]} ]] || continue
         links[$p]="$w ${links[$p]}"
@@ -34,19 +34,14 @@ for p (${(k)pages}) {
 }
 
 # Deduplicate all references
-typeset -A ws
-for p (${(k)links}) {
-    ws=()
-    for w (${=${links[$p]}}) {
-        ws[$w]=1
-        backs[$w]="$p ${backs[$w]}"
-    }
-    links[$p]=${(k)ws}
+for p w (${(kv)links}) {
+    local ws=(${(u)=w})
+    links[$p]=${(j: :)ws}
+    for w ($ws) backs[$w]="$p ${backs[$w]}"
 }
-for p (${(k)backs}) {
-    ws=()
-    for w (${=${backs[$p]}}) ws[$w]=1
-    backs[$p]=${(k)ws}
+for p w (${(kv)backs}) {
+    local ws=(${(u)=w})
+    backs[$p]=${(j: :)ws}
 }
 
 autoload -U relative
@@ -72,25 +67,22 @@ getrel() {
 genhtml() {
     local page=$1
     local data
-    [[ $# -eq 1 ]] && data="`cat $page`" || data=$2
-    local tgt
+    [[ $# -eq 1 ]] && data=`< $page` || data=$2
     data="${data//&/&amp;}"
     data="${data//</&lt;}"
     data="${data//>/&gt;}"
     for p (${(k)pages}) {
-        [[ $p = ALL ]] && continue
         [[ $p = index ]] && continue
-        tgt=`getrel $page $p`
-        data="${data//${p}/<a href=\"${tgt}.html\">$p</a>}"
+        getrel $page $p
+        data="${data//${p}/<a href=\"${REPLY}.html\">$p</a>}"
     }
     print "<\!DOCTYPE html>
 <html><head><title>$page</title></head><body><pre>
 $data
 </pre><hr/><ul>"
     for p (${(oi)=${backs[$page]}}) {
-        [[ $p = ALL ]] && continue
-        tgt=`getrel $page $p`
-        print "<li><a href=\"${tgt}.html\">$p</a></li>"
+        getrel $page $p
+        print "<li><a href=\"${REPLY}.html\">$p</a></li>"
     }
     print "</ul></body></html>"
 }