(unnamed)

text/plain

Filename: (unnamed)
Type: text/plain
Part: 1
Message: Re: Comments on system tables and columns
#!/usr/bin/perl
#
# Generate the system_comments.sql file from sgml/catalogs.sgml
# Copyright (c) 2000-2011, PostgreSQL Global Development Group

use warnings;
use strict;

print "-- autogenerated from /doc/src/sgml/catalogs.sgml, do not edit\n";

open my $catalogs, $ARGV[0] or die;

my $in_view_table = 0;
my $in_struct = 0;
my $in_entry = 0;
my $view_name = '';
my $description = '';

while (<$catalogs>) {
    # In system view table?
    $in_view_table = 1 if (m{id="view-table"});

    if ($in_view_table) {
        # concatenate text, might span lines
        if (m{</?structname>} || $in_struct) {
            $view_name .= $_;
            $description = '';
        } elsif (m{</?entry>} || $in_entry) {
            $description .= $_;
        }

        # update status
        $in_struct = 1 if (m{<structname>});
        $in_struct = 0 if (m{</structname>});
        $in_entry = 1 if (m{<entry>});
        $in_entry = 0 if (m{</entry>});

        if (! $in_struct && ! $in_entry && $view_name && $description) {
            # remove tags, eat newlines as well ("s")
            $view_name =~ s{^.*<structname>([^<]*).*$}{$1}s;
            $description =~ s{^.*<entry>([^<]*).*$}{$1}s;

            # convert whitespaces to one space
            $view_name =~ s/\s+/ /g;
            $description =~ s/\s+/ /g;

            print 'COMMENT ON VIEW ' . $view_name . " IS '" . $description . "';\n";
            $view_name = '';
            $description = '';
        }
    }

    $in_view_table = 0 if (m{</table>});
}

close $catalogs;