1cf118a656f5fd210787908b845362077fc507f8Evan Hunt#!/usr/bin/perl
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt#
93ca8abdf86dfe69d40c0bc5389151e0672780afTinderbox User# Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt#
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt# This Source Code Form is subject to the terms of the Mozilla Public
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt# License, v. 2.0. If a copy of the MPL was not distributed with this
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt# file, You can obtain one at http://mozilla.org/MPL/2.0/.
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt
1cf118a656f5fd210787908b845362077fc507f8Evan Huntuse warnings;
1cf118a656f5fd210787908b845362077fc507f8Evan Huntuse strict;
1cf118a656f5fd210787908b845362077fc507f8Evan Huntuse Time::Piece;
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt
1cf118a656f5fd210787908b845362077fc507f8Evan Huntif (@ARGV < 2) {
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt print STDERR <<'END';
1cf118a656f5fd210787908b845362077fc507f8Evan Huntusage:
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt perl docbook-options.pl options_file section > section.grammar.xml
1cf118a656f5fd210787908b845362077fc507f8Evan HuntEND
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt exit 1;
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt}
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt
1cf118a656f5fd210787908b845362077fc507f8Evan Huntmy $FILE = shift;
1cf118a656f5fd210787908b845362077fc507f8Evan Huntmy $SECTION = shift;
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt
1cf118a656f5fd210787908b845362077fc507f8Evan Huntopen (FH, "<", $FILE) or die "Can't open $FILE";
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt
1cf118a656f5fd210787908b845362077fc507f8Evan Huntmy $t = Time::Piece->new();
1cf118a656f5fd210787908b845362077fc507f8Evan Huntmy $year = $t->year;
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt
1cf118a656f5fd210787908b845362077fc507f8Evan Huntprint <<END;
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt<!--
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt - Copyright (C) 2004-$year Internet Systems Consortium, Inc. ("ISC")
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt -
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt - This Source Code Form is subject to the terms of the Mozilla Public
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt - License, v. 2.0. If a copy of the MPL was not distributed with this
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt - file, You can obtain one at http://mozilla.org/MPL/2.0/.
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt-->
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt<!-- Generated by doc/misc/docbook-options.pl -->
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt<programlisting>
1cf118a656f5fd210787908b845362077fc507f8Evan HuntEND
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt# skip preamble
1cf118a656f5fd210787908b845362077fc507f8Evan Huntmy $preamble = 0;
1cf118a656f5fd210787908b845362077fc507f8Evan Huntwhile (<FH>) {
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt if (m{^\s*$}) {
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt last if $preamble > 0;
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt } else {
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt $preamble++;
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt }
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt}
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt
1cf118a656f5fd210787908b845362077fc507f8Evan Huntmy $display = 0;
1cf118a656f5fd210787908b845362077fc507f8Evan Huntwhile (<FH>) {
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt if (m{^$SECTION\b}) {
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt $display = 1
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt }
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt if (m{// not.*implemented} || m{// obsolete} || m{// test.*only}) {
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt next;
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt }
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt s{ // not configured}{};
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt s{ // non-operational}{};
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt s{ // may occur multiple times}{};
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt s{<([a-z0-9_-]+)>}{<replaceable>$1</replaceable>}g;
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt s{^(\s*)([a-z0-9_-]+)\b}{$1<command>$2</command>};
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt s{[[]}{[}g;
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt s{[]]}{]}g;
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt s{ }{\t}g;
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt if (m{^\s*$} && $display) {
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt last;
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt }
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt if ($display) {
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt print;
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt }
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt}
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt
1cf118a656f5fd210787908b845362077fc507f8Evan Huntprint <<END;
1cf118a656f5fd210787908b845362077fc507f8Evan Hunt</programlisting>
1cf118a656f5fd210787908b845362077fc507f8Evan HuntEND