-
Notifications
You must be signed in to change notification settings - Fork 0
/
man2devhelp.sh
executable file
·142 lines (112 loc) · 4.34 KB
/
man2devhelp.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#! /bin/bash
case "$1" in
'install')
if [[ ! -d "book" ]] ; then
echo "Generate book first !!!" ;
exit 1;
fi
sudo mkdir -p /usr/share/devhelp/books/unix-man
sudo cp -r book/* /usr/share/devhelp/books/unix-man/
exit 0;;
'uninstall')
sudo rm -rf /usr/share/devhelp/books/unix-man
exit 0;;
'clear')
rm -rf book ;
rm -f chapter-*.xml ;
rm -f full-index.txt ;
exit 0;;
'generate')
rm -rf book ;
rm -f chapter-*.xml ;
rm -f full-index.txt ;
apropos --long . | sort -i > full-index.txt
declare -A arSections ;
arSections['1']='General commands (tools and utilities)' ;
arSections['2']='System calls and error numbers' ;
arSections['3']='Library functions' ;
arSections['4']='Device drivers' ;
arSections['5']='File formats' ;
arSections['6']='Games' ;
arSections['7']='Miscellaneous information' ;
arSections['8']='System maintenance and operation commands' ;
arSections['9']='Kernel internals' ;
arSections['1P']='Perl commands (tools and utilities)' ;
arSections['3P']='Perl Library functions' ;
arSections['3PERL']='Perl Library functions' ;
arSections['3PM']='Perl M Library functions' ;
arSections['1SSL']='SSL commands (tools and utilities)' ;
arSections['3SSL']='SSL Library functions' ;
arSections['5SSL']='SSL File formats' ;
arSections['7SSL']='SSL Miscellaneous information' ;
mkdir -p book
cat > book/index.html <<EOD
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Unix manual into Devhelp</title>
</head>
<body>
<h1>Unix manual into Devhelp</h1>
</body>
</html>
EOD
cat full-index.txt | while read sLine; do
#echo "$sLine";
sCommand="${sLine%% (*}";
sSection="${sLine#* (}";
sSection="${sSection%%) *}";
sSection="${sSection^^}" ;
sDescription="${sLine##*- }";
echo "Command : ${sCommand} - Section : ${sSection} - Description : ${sDescription}";
sFileSection="book/index-${sSection}.html";
sFileName="${sSection}/${sCommand}-${sSection}.html";
mkdir -p "book/${sSection}"
man -Hcat "${sSection}" "${sCommand}" > "book/${sFileName}" 2>/dev/null ;
echo " <sub name=\"${sCommand}\" link=\"${sFileName}\" />" >> "chapter-${sSection}.xml";
if [[ ! -f "${sFileSection}" ]] ; then
cat > "${sFileSection}" <<EOD
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Section ${sSection} - ${arSections[$sSection]}</title>
</head>
<body>
<h1>Section ${sSection} - ${arSections[$sSection]}</h1>
<h2>list of documented command</h2>
<dl>
EOD
fi
echo " <dt>${sCommand}</dt><dd>${sDescription}</dd>" >> "${sFileSection}" ;
done
cat > book/unix-man.devhelp2 <<EOD
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE book PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<book xmlns="http://www.devhelp.net/book" title="Unix Manuals" link="index.html" base="/usr/share/devhelp/books/unix-man" author="" name="unix-man" version="2" language="unix">
<chapters>
EOD
ls chapter-*.xml | while read sFile; do
sSection="${sFile%%.*}" ;
sSection="${sSection##*-}";
sSection="${sSection^^}" ;
echo " <sub name=\"Section ${sSection}\" link=\"index-${sSection}.html\">" >> book/unix-man.devhelp2 ;
cat $sFile >> book/unix-man.devhelp2 ;
echo " </sub>" >> book/unix-man.devhelp2 ;
sFileSection="book/index-${sSection}.html";
cat >> "${sFileSection}" <<EOD
</dl>
</body>
</html>
EOD
done
cat >> book/unix-man.devhelp2 <<EOD
</chapters>
</book>
EOD
exit 0;;
*)
echo "Usage $0 [clear|generate|install|uninstall]" ;
exit 0;;
esac