File: ccdoc

package info (click to toggle)
qdbm 1.8.78-15
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,076 kB
  • sloc: ansic: 31,454; cpp: 3,623; perl: 2,167; java: 2,079; ruby: 1,690; makefile: 1,315; javascript: 627; sh: 396
file content (244 lines) | stat: -rwxr-xr-x 6,367 bytes parent folder | download | duplicates (11)
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#! /bin/sh

#================================================================
# ccdoc
# Document generator for C/C++ sources
#================================================================


# set variables
progname='ccdoc'
stylefile='ccstyle.css'
indexfile='index.html'
lang='en'
charset='ISO-8859-1'
targets=''
sufregxp='(\.h|\.c|\.cc|\.cxx|\.cpp)$'
outdir='srcdoc'
title='Source Documents'
overview=''
numopt=''
dark='no'


# function to show usage and exit
usage(){
  printf 'usage: %s [options] sourcefiles ...\n' "$progname"
  printf 'options:\n' 2>&1
  printf '  -l lang       assign the language of documents\n' 2>&1
  printf '  -cs charset   assign the charcter set of documents\n' 2>&1
  printf '  -t title      assign the title of the index file\n' 2>&1
  printf '  -d directory  assign the directory in which documents are stored\n' 2>&1
  printf '  -ov file      assign the HTML file for overview\n' 2>&1
  printf '  -n            number all output lines\n' 2>&1
  printf '  -dark         set the style dark\n' 2>&1
  exit 1;
}


# check dependency
if source-highlight --version > /dev/null
then
  true
else
  printf '%s: requires GNU source-highlight\n' "$progname" 2>&1
  exit 1
fi


# parse arguments
while true
do
  if printf '%s\n' "$1" | grep '^-' > /dev/null
  then
    case "$1" in
    '-l') [ $# -le 1 ] && usage ; shift ; lang="$1" ;;
    '-cs') [ $# -le 1 ] && usage ; shift ; charset="$1" ;;
    '-t') [ $# -le 1 ] && usage ; shift ; title="$1" ;;
    '-d') [ $# -le 1 ] && usage ; shift ; outdir="$1" ;;
    '-ov') [ $# -le 1 ] && usage ; shift ; overview="$1" ;;
    '-n') numopt='-n' ;;
    '-dark') dark='yes' ;;
    *) usage ;;
    esac
  else
    targets="$targets $1"
  fi
  if [ $# -lt 1 ]
  then
    break
  else
    shift
  fi
done
targets=`printf '%s' "$targets" | sed -e 's/^ *//' -e 's/^ *$//'`
if [ -z "$targets" ]
then
  usage
fi


# find target files
printf 'finding targets ... '
tfiles=""
for file in $targets
do
  if [ -f "$file" ]
  then
    tfiles="$tfiles $file"
  elif [ -d "$file" ]
  then
    tfiles="$tfiles `find $file -print | egrep $sufregxp | sed 's/^\.\///' | sort`"
  else
    printf '%s: %s: not found\n' "$progname" "$file"  2>&1
    exit 1
  fi
done
printf 'ok\n'


# create the target directory
printf 'creating %s ... ' "$outdir"
mkdir -p "$outdir"
[ $? != 0 ] && exit 1
printf 'ok\n'


# create the index file
printf 'creating %s ... ' "$outdir/$indexfile"
cat << __EOF > "$outdir/$indexfile"
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="$lang" xml:lang="$lang">
<head>
<meta http-equiv="content-type" content="text/html; charset=$charset" />
<title>$title</title>
<link rel="stylesheet" href="$stylefile" type="text/css" />
<link rel="contents" href="$indexfile" />
</head>
<body>
<h1>$title</h1>
<hr />
__EOF
if [ -n "$overview" ]
then
  printf '<h2>Overview</h2>\n' >> "$outdir/$indexfile"
  cat "$overview" >> "$outdir/$indexfile"
  if [ $? != 0 ]
  then
    printf '%s: warning: %s: cannot write overview\n' "$progname" "$outdir/$indexfile" 2>&1
  fi
  printf '<hr />\n' >> "$outdir/$indexfile"
fi
printf '<h2>Sources</h2>\n' >> "$outdir/$indexfile"
printf '<ul>\n' >> "$outdir/$indexfile"
for file in $tfiles
do
  outfile="$file.html"
  printf '<li><a href="%s">%s</a></li>\n' "$outfile" "$file" >> "$outdir/$indexfile"
done
printf '</ul>\n' >> "$outdir/$indexfile"
if [ $? != 0 ]
then
  printf '%s: %s: cannot create\n' "$progname" "$outdir/$indexfile" 2>&1
  exit 1
fi
version=`source-highlight --version | head -n 1`
cat << __EOF >> "$outdir/$indexfile"
<hr />
<div class="note"><small>Generated by $progname using $version.</small></div>
</body>
</html>
__EOF
if [ $? != 0 ]
then
  printf '%s: %s: cannot create\n' "$progname" "$outdir/$indexfile" 2>&1
  exit 1
fi
printf 'ok\n'


# create the style file
printf 'creating %s ... ' "$outdir/$stylefile"
if [ "$dark" = "yes" ]
then
cat << __EOF > "$outdir/$stylefile"
body { background-color: #002222; color: #667788; margin: 0em 0em; padding: 0.5em 0.8em; }
p,div { margin: 1em 2em; }
p { text-indent: 0.8em; }
a:link,a:visited,a:active { text-decoration: none; color: #88aaff; }
a:hover { text-decoration: underline; color: #66eeff; }
pre { margin: 0em 0em; padding: 0em 0em; }
.normal { color: #ddeeff; }
.comment { color: #bb1100; }
.preproc { color: #884488; }
.function { color: #88ddbb; }
.keyword { color: #4488ee; }
.type { color: #88bbff; }
.string { color: #8899aa; }
.number,.symbol,.cbracket { color: #ccddee; }
.note { text-align: right; margin: 0.2em 0.2em; color: #8899aa; }
h1,h2,h3,p,div,li { color: #ddeeff; }
strong { color: #eeee99; }
__EOF
else
cat << __EOF > "$outdir/$stylefile"
body { background-color: #ffffff; color: #888888; margin: 0em 0em; padding: 0.5em 0.8em; }
p,div { margin: 1em 2em; }
p { text-indent: 0.8em; }
a:link,a:visited,a:active { text-decoration: none; color: #0022aa; }
a:hover { text-decoration: underline; color: #0066ff; }
pre { margin: 0em 0em; padding: 0em 0em; }
.normal { color: #111111; }
.comment { color: #119966; }
.preproc { color: #cc2200; }
.function { color: #5500bb; }
.keyword { color: #0022ff; }
.type { color: #003399; }
.string { color: #555555; }
.number,.symbol,.cbracket { color: #333333; }
.note { text-align: right; margin: 0.2em 0.2em; color: #555555}
h1,h2,h3,p,div,li { color: #111111; }
strong { color: #6600bb; }
__EOF
fi
if [ $? != 0 ]
then
  printf '%s: %s: cannot create\n' "$progname" "$outdir/$stylefile" 2>&1
  exit 1
fi
printf 'ok\n'


# create documents of targets
for file in $tfiles
do
  outfile="$file.html"
  if printf '%s' "$file" | grep '/' > /dev/null
  then
    subdir=`printf '%s' "$file" | sed 's/\/[^\/]*$//'`
    if [ -d "$outdir/$subdir" ]
    then
      [ "$subdir" != "." ] && rm -f "$outdir/$subdir/$stylefile"
    else
      mkdir -p "$outdir/$subdir"
    fi
    [ -f "$outdir/$subdir/$stylefile" ] || cp -f "$outdir/$stylefile" "$outdir/$subdir"
  fi
  printf 'creating %s ... ' "$outdir/$outfile"
  source-highlight -s cpp -f xhtml -d -T "$file ($title)" -c "$stylefile" $numopt < "$file" |\
    sed -e "1,13 s/<html>/<html lang=\"$lang\">/" \
      -e "1,13 s/charset=.*\\/>/charset=$charset\" \\/>/" > "$outdir/$outfile"
  [ $? != 0 ] && exit 1
  printf 'ok\n'
done


# exit normally
printf 'all ok\n'
exit 0



# END OF FILE