# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8

gendefault

etitle "Documentation de ulib"
array_from_lines ulibnames "$(list_files lib/ulib)"
# faire les pages
for ulibname in "${ulibnames[@]}"; do
    awkrun <"lib/ulib/$ulibname" 'BEGIN {
  in_func = 0
  dump_doc = 0
  dumped_doc = 0
  print
}
!in_func && $0 ~ /^function / {
  if (match($0, /function +([^ ]+)\(\)/, vs)) {
    funcname = vs[1]
    if (funcname !~ /^_/) {
      in_func = 1
      dump_doc = 1
      dumped_doc = 0
      print "==== " funcname " ===="
      if ($0 ~ /}$/) {
        in_func = 0
        dump_doc = 0
        dumped_doc = 0
      }
      next
    }
  }
}
in_func && dump_doc && $0 !~ /^ *#/ {
  dump_doc = 0
}
in_func && dump_doc && $0 ~ /^ *#/ {
  if (!dumped_doc) print "<code>"
  gsub(/^ *#+/, "")
  print
  dumped_doc = 1
}
in_func && $0 ~ /}$/ {
  if (dumped_doc) print "</code>"
  in_func = 0
  dump_doc = 0
  dumped_doc = 0
}
END { if (in_func) print "</code>" }
' | setpage "$ulibname" ulib
done
eend

# faire l'entête
addpage start <<EOF
==== Librairies ulib ====
EOF
for ulibname in "${ulibnames[@]}"; do
    addpage start <<EOF
  * [[${ns}ulib:$ulibname]]
EOF
done
