nutools/doc/update-twp

157 lines
3.6 KiB
Plaintext
Raw Normal View History

2013-08-27 15:14:44 +04:00
#!/bin/bash
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
2014-07-07 22:06:38 +04:00
source "$(dirname "$0")/../lib/ulib/ulib" || exit 1
urequire DEFAULTS
2013-08-27 15:14:44 +04:00
function display_help() {
uecho "$scriptname: Mettre à jour la documentation pour les outils de nutools
USAGE
$scriptname [options]
OPTIONS
2016-05-11 07:30:14 +04:00
-t, --tools
Ne générer la documentation que pour les outils
-l, --ulib
Ne générer la documentation que pour ulib
-s, --sync
Synchroniser avec nutools.html après la génération de la documentation
2013-08-27 15:14:44 +04:00
Par défaut, la documentation est (re)générée pour les outils et pour ulib"
}
function dump_content() {
local twpage="$1" content="$2"
if [ -f "$twpage" ]; then
awk '
BEGIN { dump = 0 }
!dump && ($0 == "" || $0 ~ /^[^#]/) { dump = 1 }
dump { print }' <"$twpage" >"$content"
else
>"$content"
fi
}
function write_twpage() {
local oldcontent="$1" title="$2" newcontent="$3" twpage="$4"
if testdiff "$oldcontent" "$newcontent"; then
local created="$(date +"%d/%m/%Y %H:%M")"
echo "# -*- coding: utf-8 mode: markdown -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
##@creator: $USER
##@created: $created
##@modifier: $USER
##@changecount: 1
2015-08-20 07:58:17 +04:00
##@tags:
2013-08-27 15:14:44 +04:00
##@title: $title" >"$twpage"
cat "$newcontent" >>"$twpage"
fi
}
auto=1
tools=
ulib=
sync=
force=
parse_opts "${PRETTYOPTS[@]}" \
--help '$exit_with display_help' \
2016-05-11 07:30:14 +04:00
-t,--tools '$auto=; tools=1' \
-l,--ulib '$auto=; ulib=1' \
-s,--sync '$auto=; sync=1' \
2013-08-27 15:14:44 +04:00
--force force=1 \
@ args -- "$@" && set -- "${args[@]}" || die "$args"
[ -n "$auto" ] && {
tools=1
ulib=1
sync=1
}
ac_set_tmpfile oldcontent
ac_set_tmpfile newcontent
cd "$scriptdir"
if [ -n "$tools" ]; then
if [ -n "$*" ]; then
cmds=("$@")
else
array_lsfiles cmds ..
fi
2015-08-20 07:58:17 +04:00
2013-08-27 15:14:44 +04:00
for cmd in "${cmds[@]}"; do
cmdname="$(basename "$cmd")"
twpage="$cmdname.twp"
[ -x "$cmd" ] || continue
estep "$cmdname"
dump_content "$twpage" "$oldcontent"
echo "
{{{
$("$cmd" --help)
}}}" >"$newcontent"
2015-08-20 07:58:17 +04:00
2013-08-27 15:14:44 +04:00
write_twpage "$oldcontent" "$cmdname" "$newcontent" "$twpage"
done
fi
if [ -n "$ulib" ]; then
2014-07-07 22:06:38 +04:00
array_from_lines ulibnames "$(list_files ../lib/ulib)"
2013-08-27 15:14:44 +04:00
# faire l'entête
dump_content ulib.twp "$oldcontent"
echo "
!Liste des librairies de ulib" >"$newcontent"
for ulibname in "${ulibnames[@]}"; do
echo "* [[ulib/$ulibname]]" >>"$newcontent"
done
write_twpage "$oldcontent" ulib "$newcontent" ulib.twp
# faire les pages
for ulibname in "${ulibnames[@]}"; do
2014-07-07 22:06:38 +04:00
ulib="../lib/ulib/$ulibname"
2013-08-27 15:14:44 +04:00
twpage="ulib_$ulibname.twp"
title="ulib/$ulibname"
dump_content "$twpage" "$oldcontent"
awkrun '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 "{{{"
gsub(/^ *#+ */, "")
print
dumped_doc = 1
}
in_func && $0 ~ /}$/ {
if (dumped_doc) print "}}}"
in_func = 0
dump_doc = 0
dumped_doc = 0
}
END { if (in_func) print "}}}" }
' <"$ulib" >"$newcontent"
write_twpage "$oldcontent" "$title" "$newcontent" "$twpage"
done
fi
if [ -n "$sync" ]; then
../twsync ${force:+--force}
fi