#! /usr/bin/awk -f function strip(text){ gsub("^ *<[a-zA-Z0-9]*[^>]*>", "", text) gsub(" *$", "", text) return text } function unescape(text){ gsub("<", "<", text) gsub(">", ">", text) gsub(""", "\"", text) gsub("&", "\\&", text) gsub("-", "\\-", text) return text } BEGIN { date = strftime("%Y-%m-%d") printf(".TH \"%s\" %d \"%s\" \"%s\" \"%s\"\n\n", "INTRO", 3, date, "Man Page", "Tokyo Cabinet") } / *]*>.*<\/h[1-3]> *$/ { text = $0 text = strip(text) text = unescape(text) text = toupper(text) printf("\n") printf(".SH %s\n", text) } / *

]*>.*<\/p> *$/ { text = $0 text = strip(text) text = gensub("]*>([^<]*)", "\\\\fB\\1\\\\fR", "g", text) text = gensub("]*>([^<]*)", "\\\\fI\\1\\\\fR", "g", text) gsub("<[^>]*>", "", text) text = unescape(text) printf(".PP\n") printf("%s\n", text) } / *

]*> *$/ { printf(".PP\n") printf(".RS\n") } / *<\/dl> *$/ { printf(".RE\n") } / *
]*>.*<\/dt> *$/ { text = $0 text = strip(text) text = gensub("]*>([^<]*)", "\\\\fI\\1\\\\fB", "g", text) gsub("<[^>]*>", "", text) gsub("[\\||\\[|\\]]", "\\fR&\\fB", text) text = unescape(text) printf(".br\n") printf("\\fB%s\\fR\n", text) } / *
]*>.*<\/dd> *$/ { text = $0 text = strip(text) text = gensub("]*>([^<]*)", "\\\\fB\\1\\\\fR", "g", text) text = gensub("]*>([^<]*)", "\\\\fI\\1\\\\fR", "g", text) gsub("<[^>]*>", "", text) text = unescape(text) printf(".RS\n") printf("%s\n", text) printf(".RE\n") } / *
    ]*> *$/ { printf(".PP\n") printf(".RS\n") } / *<\/ul> *$/ { printf(".RE\n") } / *
  • ]*>.*<\/li> *$/ { text = $0 text = strip(text) text = gensub("]*>(.*)", "\\\\fB\\1\\\\fR", "g", text) text = gensub("]*>([^<]*)", "\\\\fI\\1\\\\fR", "g", text) gsub("<[^>]*>", "", text) text = unescape(text) printf("%s\n", text) printf(".br\n") } END { printf("\n") printf(".SH SEE ALSO\n") printf(".PP\n") printf(".BR tcutil (3),\n") printf(".BR tchdb (3),\n") printf(".BR tcbdb (3),\n") printf(".BR tcfdb (3),\n") printf(".BR tctdb (3),\n") printf(".BR tcadb (3)\n") printf(".PP\n") printf("Please see\n") printf(".I http://1978th.net/tokyocabinet/\n") printf("for detail.\n") }