# Removes what's obsolete in a list of catalogs
# However, issule the list of obsolete stuff
#   if otherwise nothing would come out...
#  n = number of paragraphs already issued
#  o = 1 if catalog is obsoleted.

# Print a paragraph of keep it in memory
function show_par() {
    if ((obsolete == 0) && (p != "")) { print p; n++ }
    else if (p != "") { 
	if (stuff == "") stuff = p;
	else stuff = stuff "\n" p ;
	nstuf++
    }
}

# End of a paragraph
/^$/ {
    show_par();
    parno += 1;
    obsolete = 0
    p = "";
    next
}

# Indicates an obsolete cat.
/^%D.*OBSOL/ { obsolete = 1 }

{  
    #printf "(parno=%d)%s\n", parno, $0
    if (parno>0) p = p "\n" $0 
}

# End: be sure the list is finalized
END { 
    show_par();
    if ((n == 0) && (stuff != "")) {
        print "# (only obsoleted catalogs were found)"
	print stuff
    }
    else if (nstuf>0) printf \
         "# (use -old option to list %d obsoleted catalogs)\n", nstuf;
}
