kde-workspace/kioslave/man/kde-man2html
2015-05-01 21:53:41 +00:00

70 lines
2 KiB
Bash
Executable file

#!/bin/sh
header='<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="kde-man2html">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
p { margin-top: 0; margin-bottom: 0; vertical-align: top }
pre { margin-top: 0; margin-bottom: 0; vertical-align: top }
table { margin-top: 0; margin-bottom: 0; vertical-align: top }
h1 { text-align: center }
</style>
<title>KDE-MAN2HTML</title>
</head>
<body>
'
if [ -z "$1" ];then
echo "$header <p>Nothing to do.</p>"
exit 1
elif ! type -p zcat &>/dev/null || ! type -p groff &>/dev/null;then
echo "$header <p>Either zcat or groff is not present.</p>"
exit 2
fi
base="$(basename "$1")"
case "$base" in
[1-9])
# section to display
secpath=""
for p in "/man" "/share/man";do
tmppath="$p/man$base"
if [ -d "$tmppath" ];then
secpath="$tmppath"
elif [ -d "/usr$tmppath" ];then
secpath="/usr$tmppath"
elif [ -d "/usr/local$tmppath" ];then
secpath="/usr/local$tmppath"
fi
done
if [ -z "$secpath" ];then
echo "$header <p>Manual page section for <b>$base</b> not found."
exit 3
fi
content=""
# FIXME: will break on spaces
for page in $(find "$secpath" ! -type d);do
tmpbase="$(basename "$page")"
content="$content <p><a href='man:/$tmpbase'>$tmpbase</a></p>"
done
echo "$header $content"
;;
*)
# actual page to display
page="$(man -w "$base" 2>/dev/null)"
if [ -z "$page" ];then
echo "$header <p>Manual page for <b>$base</b> not found."
exit 3
fi
zcat "$page" | groff -mandoc -c -Thtml 2>/dev/null
;;
esac
exit 0;