📄 ccdoc
字号:
#! /bin/sh#================================================================# ccdoc# Document generator for C/C++ sources#================================================================# setting variablesprogname='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 exitusage(){ 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 dependencyif source-highlight --version > /dev/nullthen trueelse printf '%s: requires GNU source-highlight\n' "$progname" 2>&1 exit 1fi# parse argumentswhile truedo 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 fidonetargets=`printf '%s' "$targets" | sed -e 's/^ *//' -e 's/^ *$//'`if [ -z "$targets" ]then usagefi# find target filesprintf 'finding targets ... 'tfiles=""for file in $targetsdo 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 fidoneprintf 'ok\n'# create the target directoryprintf 'creating %s ... ' "$outdir"mkdir -p "$outdir"[ $? != 0 ] && exit 1printf 'ok\n'# create the index fileprintf '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 />__EOFif [ -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"fiprintf '<h2>Sources</h2>\n' >> "$outdir/$indexfile"printf '<ul>\n' >> "$outdir/$indexfile"for file in $tfilesdo outfile="$file.html" printf '<li><a href="%s">%s</a></li>\n' "$outfile" "$file" >> "$outdir/$indexfile"doneprintf '</ul>\n' >> "$outdir/$indexfile"if [ $? != 0 ]then printf '%s: %s: cannot create\n' "$progname" "$outdir/$indexfile" 2>&1 exit 1fiversion=`source-highlight --version | head -n 1`cat << __EOF >> "$outdir/$indexfile"<hr /><div class="note"><small>Generated by $progname using $version.</small></div></body></html>__EOFif [ $? != 0 ]then printf '%s: %s: cannot create\n' "$progname" "$outdir/$indexfile" 2>&1 exit 1fiprintf 'ok\n'# create the style fileprintf 'creating %s ... ' "$outdir/$stylefile"if [ "$dark" = "yes" ]thencat << __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; }__EOFelsecat << __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; }__EOFfiif [ $? != 0 ]then printf '%s: %s: cannot create\n' "$progname" "$outdir/$stylefile" 2>&1 exit 1fiprintf 'ok\n'# create documents of targetsfor file in $tfilesdo 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 normallyprintf 'all ok\n'exit 0# END OF FILE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -