#include <ncbi.h>
#include <gishlib.h>
#include "blastapp.h"

/* Print all HitLists where the smallest pvalue in the list is below a cutoff */
int
print_HSPs(biop, hlp, maxpval, print_hit)
	BlastIoPtr	biop;
	register BLAST_HitListPtr	hlp;
	register double	maxpval;
	int		(*print_hit) PROTO((BlastIoPtr,BLAST_HitListPtr));
{
	register BLAST_HSPPtr	hp;
	long	cnt, noprt, unsatisfactory;

	if (showblast == 0)
		return 0;

	/* For each HitList in the linked list... */
	for (unsatisfactory = cnt = 0; hlp != NULL; hlp = hlp->next) {
		if (hlp->best_hsp->pvalue <= maxpval) {
			if (cnt < showblast || showblast < 0) {
				++cnt;
				for (hp = *hlp->hpp; hp != NULL; hp = hp->next) {
					++ctx[hp->context].wfstats.reported;
				}
				if ((*print_hit)(biop, hlp) != 0)
					return -1;
			}
		}
		else
			++unsatisfactory;
	}
	noprt = hasHSP - cnt - unsatisfactory;
	if (showblast > 0 && noprt > 0) {
		if (biop->fp != NULL)
			putc_unlocked('\n', biop->fp);
		warning("HSPs involving %s database sequences were not reported due to the limiting value of parameter B = %ld.",
				Ltostr(noprt,1),
				showblast);
	}
	return 0;
}
