#!/usr/bin/awk -f # # scripts/shell/docbook/ - DocBook support shell scripts # # db-get-id - SGML/XML DocBook source modifier # ____________________________________________________________ # # Developed by Lubomir Host # Copyright (c) 2002-2004 Platon SDG, http://platon.sk/ # All rights reserved. # # See README file for more information about this software. # See COPYING file for license information. # # Download the latest version from # http://platon.sk/projects/scripts/ # # $Platon: libcfg+/contrib/docbook/db-html2man,v 1.25 2004/01/12 06:03:07 nepto Exp $ BEGIN { read_id(IDfile); } function read_id(file) { # {{{ while (getline tag < file) { n = split(tag, a, "\t+"); IDs[a[1]] = tag; } } # }}} function get_field(str, i) { # {{{ n = split(IDs[str], a, "\t+"); return a[i]; } # }}} function remove_tag(s, reg) { # {{{ sub(/\t+/, " ", s); reg1 = sprintf("^.*<%s[^>]*> *", reg); reg2 = sprintf(" *.*$", reg); if (!sub(reg1, "", s)) { s = ""; } if (!sub(reg2, "", s)) { s = ""; } return s; } # }}} function complete_xref(str) { # {{{ reg = "]*$"; while (str ~ reg) { # printf "BEFORE = '%s'\n", str; getline; str = sprintf("%s %s", str, $0); # printf "AFTER = '%s'\n", str; } return str; } # }}} function handle_xref(str) { # {{{ while (str ~ " with apropriate ID id = find_id(str); sub(/]*>/, sprintf("%s", get_field(id, 5)), str); } print str; } # }}} # return "endterm" value of tag function find_id(str) { # {{{ sub(/^.*"); for (i = 1; i <= n; i++) { #printf "a[%d] = '%s'\n", i, a[i]; if (a[i] ~ /", a[i]; else printf "%s", a[i]; } } # }}} function handle_multiline_man() { # {{{ while (getline) { if ($0 ~ /^[ \t]*-->$/) break; print; } return; } # }}} function handle_table(str) { # {{{ entries = 0; sub(/]*>/, ""); print; while (getline) { # end of table if (sub(/<\/table>/, "")) { return; } if ($0 ~ //) { remove_lines("^.*"); } sub(/]*>/, ""); sub(/<\/tgroup>/, ""); sub(//, ""); sub(/<\/tbody>/, ""); if (sub(/]*>/, "")) { entries = 0; } if (sub(/<\/row>/, "")) { if (entries > 1) print ""; } if ($0 ~ //) { entries++; if (entries == 1 ) sub(//, ""); else { if (entries == 2) print ""; sub(//, ""); } } if ($0 ~ /<\/entry>/) { if (entries == 1 ) sub(/<\/entry>/, ""); else { sub(/<\/entry>/, ""); } } if ($0 ~ /