#!/bin/sh # # Interface to a glimpse search of the man pages. # Michael Hamilton # QUOTE="'" export QUOTE type glimpse > /dev/null 2> /dev/null || { cat <<-EOF Content-type: text/html Glimpse not installed

Glimpse not installed

Search is only enabled if the Glimpse package is installed. You may download it from the Debian site. EOF exit 0 } exec awk ' function removeopts(string) { gsub(/^[ \t]/, "", string); # Remove leading spaces gsub(/[ \t]$/, "", string); # Remove trailing spaces gsub(/[ \t\\];/, ";", string); # Remove spaces before ; gsub(/[ \t];/, ",", string); # Remove spaces before , # print "---" string "---" > "/dev/stderr" while (match(string, /^-[FLBwk1-8]/)) { if (match(string, /^-[FL]( |.)[^ \t]+[ \t]+/)) { # Option with arg options = options " " substr(string, RSTART, RLENGTH); string = substr(string, RSTART + RLENGTH); } else if (match(string, /^-[Bwk1-8][ \t]+/)) { # Option without arg options = options " " substr(string, RSTART, RLENGTH); string = substr(string, RSTART + RLENGTH); } else if (match(string, /^-[^ \t]/)) { # Remove it string = substr(string, RSTART + RLENGTH); } } return string; } BEGIN { quote = ENVIRON["QUOTE"]; truncate_at = 11; # Single page display match limit. glimpse_cmd = "glimpse -z -H /var/cache/man2html -y -W -i " for (i = 1; i < ARGC; i++) { # print "---" i "---" ARGV[i] "---" > "/dev/stderr" string = string " " ARGV[i]; } # Have to be carefull to single quote this # string later. string = removeopts(string); gsub(/[^a-zA-Z0-9-_+ \t\/@%;,$*|]/, " ", string); print "Content-type: text/html"; print ""; searchdocument = "/usr/doc/man2html/html/mansearch.html"; if (!string) { while (getline line < searchdocument) { print line; } exit; } print ""; print ""; print "Manual Pages - Search Results: " string ""; print ""; print ""; print "

Manual Pages - Search Results

"; print "

Target text: " options " " string "

"; print ""; print "Perform another search"; print "
"; print ""; print "Return to Main Contents"; print ""; print "
"; print "
"; # Unless you like being hacked, the single # forward quotes are most important. cmd = glimpse_cmd " " options " " quote string quote " 2>&1" ; #print cmd > "/dev/stderr" while (cmd | getline matchline) { if (split(matchline, part, ":") == 1) { continue; } else { fullname = part[1]; } if (fullname == "glimpse") { print "
"fullname":"; } else if (fullname != last_fullname) { mcount++; tcount = 0; last_fullname = fullname ; last_text = ""; if (match(fullname, ".*/")) { dirname = substr(fullname, 1, RLENGTH); filename = substr(fullname, RLENGTH + 1); if (dirname != last_dirname) { last_dirname = dirname; print "
"; print "

Location: " dirname "

"; print "
"; } } else { filename = fullname; } if (match(filename, /\.[^.]+$/)) { ref = substr(filename, 1, RSTART - 1) "+" substr(filename, RSTART + 1); } else { ref = filename; } print "
"; textname = filename; sub(/\.(gz)|Z|z$/, "", textname); sub(/\./, "(", textname); textname = textname ")"; print textname; print ""; } text = substr(matchline, length(fullname) + 2); tcount++; if (tcount < truncate_at) { sub(/^ *.[^ ]+ /, "", text); sub(/ +$/, "", text); gsub(/\\f./, "", text); gsub(/\\&/, "", text); gsub(/\\/, "", text); print "
" text; } else if (tcount == truncate_at) { print "
...additional matches not shown."; } } print "
"; if (mcount == 0) { print "No matches found."; } else { print "
\n

" mcount " matches found." } print ""; print ""; exit; }' "$@"