Debian Codegraph @

lab/ccdoc

raw symbols SCIP
1 #! /bin/sh
2
3 #================================================================
4 # ccdoc
5 # Document generator for C/C++ sources
6 #================================================================
7
8
9 # set variables
10 progname='ccdoc'
11 stylefile='ccstyle.css'
12 indexfile='index.html'
13 lang='en'
14 charset='ISO-8859-1'
15 targets=''
16 sufregxp='(\.h|\.c|\.cc|\.cxx|\.cpp)$'
17 outdir='srcdoc'
18 title='Source Documents'
19 overview=''
20 numopt=''
21 dark='no'
22
23
24 # function to show usage and exit
25 usage(){
26 printf 'usage: %s [options] sourcefiles ...\n' "$progname"
27 printf 'options:\n' 2>&1
28 printf ' -l lang assign the language of documents\n' 2>&1
29 printf ' -cs charset assign the charcter set of documents\n' 2>&1
30 printf ' -t title assign the title of the index file\n' 2>&1
31 printf ' -d directory assign the directory in which documents are stored\n' 2>&1
32 printf ' -ov file assign the HTML file for overview\n' 2>&1
33 printf ' -n number all output lines\n' 2>&1
34 printf ' -dark set the style dark\n' 2>&1
35 exit 1;
36 }
37
38
39 # check dependency
40 if source-highlight --version > /dev/null
41 then
42 true
43 else
44 printf '%s: requires GNU source-highlight\n' "$progname" 2>&1
45 exit 1
46 fi
47
48
49 # parse arguments
50 while true
51 do
52 if printf '%s\n' "$1" | grep '^-' > /dev/null
53 then
54 case "$1" in
55 '-l') [ $# -le 1 ] && usage ; shift ; lang="$1" ;;
56 '-cs') [ $# -le 1 ] && usage ; shift ; charset="$1" ;;
57 '-t') [ $# -le 1 ] && usage ; shift ; title="$1" ;;
58 '-d') [ $# -le 1 ] && usage ; shift ; outdir="$1" ;;
59 '-ov') [ $# -le 1 ] && usage ; shift ; overview="$1" ;;
60 '-n') numopt='-n' ;;
61 '-dark') dark='yes' ;;
62 *) usage ;;
63 esac
64 else
65 targets="$targets $1"
66 fi
67 if [ $# -lt 1 ]
68 then
69 break
70 else
71 shift
72 fi
73 done
74 targets=`printf '%s' "$targets" | sed -e 's/^ *//' -e 's/^ *$//'`
75 if [ -z "$targets" ]
76 then
77 usage
78 fi
79
80
81 # find target files
82 printf 'finding targets ... '
83 tfiles=""
84 for file in $targets
85 do
86 if [ -f "$file" ]
87 then
88 tfiles="$tfiles $file"
89 elif [ -d "$file" ]
90 then
91 tfiles="$tfiles `find $file -print | egrep $sufregxp | sed 's/^\.\///' | sort`"
92 else
93 printf '%s: %s: not found\n' "$progname" "$file" 2>&1
94 exit 1
95 fi
96 done
97 printf 'ok\n'
98
99
100 # create the target directory
101 printf 'creating %s ... ' "$outdir"
102 mkdir -p "$outdir"
103 [ $? != 0 ] && exit 1
104 printf 'ok\n'
105
106
107 # create the index file
108 printf 'creating %s ... ' "$outdir/$indexfile"
109 cat << __EOF > "$outdir/$indexfile"
110 <?xml version="1.0"?>
111 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
112 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
113 <html lang="$lang" xml:lang="$lang">
114 <head>
115 <meta http-equiv="content-type" content="text/html; charset=$charset" />
116 <title>$title</title>
117 <link rel="stylesheet" href="$stylefile" type="text/css" />
118 <link rel="contents" href="$indexfile" />
119 </head>
120 <body>
121 <h1>$title</h1>
122 <hr />
123 __EOF
124 if [ -n "$overview" ]
125 then
126 printf '<h2>Overview</h2>\n' >> "$outdir/$indexfile"
127 cat "$overview" >> "$outdir/$indexfile"
128 if [ $? != 0 ]
129 then
130 printf '%s: warning: %s: cannot write overview\n' "$progname" "$outdir/$indexfile" 2>&1
131 fi
132 printf '<hr />\n' >> "$outdir/$indexfile"
133 fi
134 printf '<h2>Sources</h2>\n' >> "$outdir/$indexfile"
135 printf '<ul>\n' >> "$outdir/$indexfile"
136 for file in $tfiles
137 do
138 outfile="$file.html"
139 printf '<li><a href="%s">%s</a></li>\n' "$outfile" "$file" >> "$outdir/$indexfile"
140 done
141 printf '</ul>\n' >> "$outdir/$indexfile"
142 if [ $? != 0 ]
143 then
144 printf '%s: %s: cannot create\n' "$progname" "$outdir/$indexfile" 2>&1
145 exit 1
146 fi
147 version=`source-highlight --version | head -n 1`
148 cat << __EOF >> "$outdir/$indexfile"
149 <hr />
150 <div class="note"><small>Generated by $progname using $version.</small></div>
151 </body>
152 </html>
153 __EOF
154 if [ $? != 0 ]
155 then
156 printf '%s: %s: cannot create\n' "$progname" "$outdir/$indexfile" 2>&1
157 exit 1
158 fi
159 printf 'ok\n'
160
161
162 # create the style file
163 printf 'creating %s ... ' "$outdir/$stylefile"
164 if [ "$dark" = "yes" ]
165 then
166 cat << __EOF > "$outdir/$stylefile"
167 body { background-color: #002222; color: #667788; margin: 0em 0em; padding: 0.5em 0.8em; }
168 p,div { margin: 1em 2em; }
169 p { text-indent: 0.8em; }
170 a:link,a:visited,a:active { text-decoration: none; color: #88aaff; }
171 a:hover { text-decoration: underline; color: #66eeff; }
172 pre { margin: 0em 0em; padding: 0em 0em; }
173 .normal { color: #ddeeff; }
174 .comment { color: #bb1100; }
175 .preproc { color: #884488; }
176 .function { color: #88ddbb; }
177 .keyword { color: #4488ee; }
178 .type { color: #88bbff; }
179 .string { color: #8899aa; }
180 .number,.symbol,.cbracket { color: #ccddee; }
181 .note { text-align: right; margin: 0.2em 0.2em; color: #8899aa; }
182 h1,h2,h3,p,div,li { color: #ddeeff; }
183 strong { color: #eeee99; }
184 __EOF
185 else
186 cat << __EOF > "$outdir/$stylefile"
187 body { background-color: #ffffff; color: #888888; margin: 0em 0em; padding: 0.5em 0.8em; }
188 p,div { margin: 1em 2em; }
189 p { text-indent: 0.8em; }
190 a:link,a:visited,a:active { text-decoration: none; color: #0022aa; }
191 a:hover { text-decoration: underline; color: #0066ff; }
192 pre { margin: 0em 0em; padding: 0em 0em; }
193 .normal { color: #111111; }
194 .comment { color: #119966; }
195 .preproc { color: #cc2200; }
196 .function { color: #5500bb; }
197 .keyword { color: #0022ff; }
198 .type { color: #003399; }
199 .string { color: #555555; }
200 .number,.symbol,.cbracket { color: #333333; }
201 .note { text-align: right; margin: 0.2em 0.2em; color: #555555}
202 h1,h2,h3,p,div,li { color: #111111; }
203 strong { color: #6600bb; }
204 __EOF
205 fi
206 if [ $? != 0 ]
207 then
208 printf '%s: %s: cannot create\n' "$progname" "$outdir/$stylefile" 2>&1
209 exit 1
210 fi
211 printf 'ok\n'
212
213
214 # create documents of targets
215 for file in $tfiles
216 do
217 outfile="$file.html"
218 if printf '%s' "$file" | grep '/' > /dev/null
219 then
220 subdir=`printf '%s' "$file" | sed 's/\/[^\/]*$//'`
221 if [ -d "$outdir/$subdir" ]
222 then
223 [ "$subdir" != "." ] && rm -f "$outdir/$subdir/$stylefile"
224 else
225 mkdir -p "$outdir/$subdir"
226 fi
227 [ -f "$outdir/$subdir/$stylefile" ] || cp -f "$outdir/$stylefile" "$outdir/$subdir"
228 fi
229 printf 'creating %s ... ' "$outdir/$outfile"
230 source-highlight -s cpp -f xhtml -d -T "$file ($title)" -c "$stylefile" $numopt < "$file" |\
231 sed -e "1,13 s/<html>/<html lang=\"$lang\">/" \
232 -e "1,13 s/charset=.*\\/>/charset=$charset\" \\/>/" > "$outdir/$outfile"
233 [ $? != 0 ] && exit 1
234 printf 'ok\n'
235 done
236
237
238 # exit normally
239 printf 'all ok\n'
240 exit 0
241
242
243
244 # END OF FILE