Skip to content

Instantly share code, notes, and snippets.

@h4tr3d
Created July 9, 2014 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h4tr3d/aa1238cf707687dd5501 to your computer and use it in GitHub Desktop.
Save h4tr3d/aa1238cf707687dd5501 to your computer and use it in GitHub Desktop.
#!/bin/bash
ver=20131124
url=http://www.tldp.org/manpages/man-html
fn="man-html-$ver.tar.bz2"
indir="man-html-$ver"
tocname="unixman.qhp"
###################################################################################################
# Get & Unpack
###################################################################################################
wget -c $url/$fn || exit 1
rm -rf "$indir"
tar xjf $fn
###################################################################################################
# Fix files
###################################################################################################
for f in index.html index2.html index3.html index7.html
do
cat $indir/$f | sed 's|<div class="navfooter">.*</div>||g;s|<a accesskey="p" href=".\+.html">Prev</a>||g;s|<a accesskey="n" href=".\+.html">Next</a>||g' > tmp.html && mv tmp.html $indir/$f
done
###################################################################################################
# Header
###################################################################################################
cat > $tocname << __EOF
<QtHelpProject version="1.0">
<namespace>linux.man.pages.1.0</namespace>
<virtualFolder>doc</virtualFolder>
<customFilter name="Linux Man Pages 1.0">
<filterAttribute>linux.man.pages</filterAttribute>
<filterAttribute>1.0</filterAttribute>
</customFilter>
<filterSection>
<filterAttribute>linux.man.pages</filterAttribute>
<filterAttribute>1.0</filterAttribute>
<toc>
<section title="Linux manual pages" ref="$indir/index.html">
<section title="Section 2: System calls" ref="$indir/index2.html" />
<section title="Section 3: Library functions" ref="$indir/index3.html" />
<section title="Section 7: Overviews, conventions, standards" ref="$indir/index7.html" />
</section>
</toc>
__EOF
###################################################################################################
# keywords
###################################################################################################
# begin
cat >> $tocname << __EOF
<keywords>
__EOF
# process
for sec in 2 3 7
do
d=$indir/htmlman$sec
ls -1 $d | while read line
do
name=`basename $line .$sec.html`
ref="$d/$line"
cat > $tocname.tmp << __EOF
<keyword name="$name" id="$name" ref="$ref"/>
__EOF
# advanced
cat $ref | awk -v ref=$ref '
BEGIN {
name_section=0;
name_par=0;
name_str="";
}{
if (name_section) {
if (match($0, "</div>")) {
name_section=0;
name_par=0;
name_str="";
}
if (name_section && match($0, "<p>")) {
name_par=1l
}
if (name_par) {
name_str = name_str $0;
if (match($0, "</p>")) {
idx = match(name_str, " — ");
if (idx) {
name_str = substr(name_str, 1, idx);
}
gsub(/[ ]+/, " ", name_str); # remove space duplication
gsub(/^[ ]+/, "", name_str); # remove lead spaces
gsub(/[ ]\+$/, "", name_str); # remove tail spaces
gsub(/^<p>/, "", name_str); # remove lead p
# split
count = split(name_str, name_arr, ", ");
#print("Str: " name_str);
#print("Arr:");
for (i=1; i<=count; i++) {
#print(" " name_arr[i]);
nm = name_arr[i];
gsub(/^[ ]+/, "", nm);
gsub(/[ ]+$/, "", nm);
printf(" <keyword name=\"%s\" id=\"%s\" ref=\"%s\"/>\n", nm, nm, ref);
}
name_par=0;
name_str="";
exit(0);
}
}
} else if (match($0, "<div class=\"refnamediv\">")) {
name_section=1;
}
}' >> $tocname.tmp
cat $tocname.tmp | sort | uniq >> $tocname
done
done
# end
cat >> $tocname << __EOF
</keywords>
__EOF
###################################################################################################
# files
###################################################################################################
# begin
cat >> $tocname << __EOF
<files>
__EOF
# process
cat >> $tocname << __EOF
<file>$indir/index.html</file>
<file>$indir/index2.html</file>
<file>$indir/index3.html</file>
<file>$indir/index7.html</file>
<file>$indir/manpageindex.html</file>
<file>$indir/stylesheet/*</file>
<file>$indir/htmlman2/*</file>
<file>$indir/htmlman3/*</file>
<file>$indir/htmlman7/*</file>
__EOF
# end
cat >> $tocname << __EOF
</files>
__EOF
###################################################################################################
# end
###################################################################################################
cat >> $tocname << __EOF
</filterSection>
</QtHelpProject>
__EOF
echo "Generate Help File..."
qhelpgenerator $tocname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment