# pg_isok A query centered monitoring tool for PostgreSQL
# Copyright (C) 2025 The Meme Factory, Inc., http://www.karlpinc.com/
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
#
# Karl O. Pinc
# DO NOT EDIT THIS FILE. It was automatically generated. Edit
# the *.m4 files instead. (Files _should_ be re-created by
# typing 'make', with the appropriate target, at the command line.)
function fold(line, words, word, fragment, len, i) {
split(line, words, " ");
fragment = "";
len = 0;
for (i in words) {
word = words[i];
if (len + length(word) + 1 > MAX_CHARS) {
# The fragment is "full", output it
if (len == 0) {
# The word won't fit on a line
printf "%s%s", word, "\n";
} else {
printf "%s%s", fragment, "\n";
fragment = word;
len = length(fragment)
}
} else {
# Add the word to the fragment
if (len == 0) {
fragment = word;
len = length(word);
} else {
fragment = fragment " " word;
len += length(word) + 1;
}
}
}
if (len != 0)
printf "%s", fragment;
}
BEGIN {
# This works by splitting the text on the dollar quote used in the SQL,
# to separate the comment text from everything else.
RS = "[$]isok_comment[$]";
ORS = "$isok_comment$";
MAX_CHARS = 50;
}
{
half = NR/2;
if (half == int(half)) {
# Even numbered record. These contain the text of the comment.
# Replace whitespace runs with a single space.
print fold(gensub(/([^;])[[:space:]][[:space:]]+/,"\\1 ","g"));
} else {
print $0;
}
}