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

int LIBCALL
print_x(biop, hlp)
	BlastIoPtr	biop;
	BLAST_HitListPtr	hlp;
{
	FILE	*fp;
	unsigned long	id;
	BLAST_HSPPtr	hp;
	BLAST_StrPtr	dbsp;
	int		i, frame, prevframe;
	register char	*cp, *cpmax;

	fp = biop->fp;

	dbsp = &hlp->str2;
	id = dbsp->id.data.intvalue;

	db_seek(dbfp, id);
	db_get_seq(dbfp, dbsp);

	if (fp != NULL) {
		cp = dbsp->name;
		cpmax = cp + dbsp->namelen;
		while (cp < cpmax && !isspace(*cp))
			++cp;
		while (cp < cpmax && isspace(*cp))
			++cp;
		i = cp - dbsp->name + 1;
		i = MIN(i, 12);
		if (fp != NULL) {
			putc_unlocked('\n', fp);
			putc_unlocked('\n', fp);
			wrap(fp, ">", dbsp->name, dbsp->namelen, 79, i);
			fprintf(fp, "%*sLength = %s\n", i, "", Ltostr((long)dbsp->len,1));
		}
	}

	prevframe = 0;
	for (hp = *hlp->hpp; hp != NULL; hp = hp->next) {
		frame = hp->q_seg.frame;
		if (fp != NULL && SIGN(prevframe) != SIGN(frame)) {
			if (frame > 0)
				fprintf(fp, "\n  Plus");
			else
				fprintf(fp, "\n  Minus");
			fprintf(fp, " Strand HSPs:\n");
		}
		prevframe = frame;
		if (hsp_print(fp, hp, TRUE) != 0)
			return 1;
	}
	return 0;
}
