/*
 *	Miscellaneous support functions for DXFRIEND
 */

/*
 *	Bcopy for non-overlapping memory blocks (megamax doesn't supply one)
 */ 
bcopy(to, from, n)
char *to, *from;
int n;
{
	register int i;
	register char *t, *f;

	t = to; f = from;
	for (i=n; i>0; i--) *t++ = *f++;
}

/*
 *	Compute 7-bit checksum, which is
 *	"the 2's complement of the sum of N bytes"
 */
checksum(buf, nbytes)
char *buf;
int nbytes;
{
	register int csum, i;
	register char *cp;

	csum = 0;
	for (i=0, cp=buf; i<nbytes; cp++, i++) {
		csum += *cp;
	}
	return(-csum & 0x7F);
}

/*
 *	nomerosuffix(n) returns the ordinal suffix string for the digit n.
 *	Normally used in printf("... %d%s ...", n, numerosuffix(n)).
 */
char *
numerosuffix(n)
int n;
{
	n %= 100;

	switch (n) {
	case 1:	return("st");
	case 2: return("nd");
	case 3: return("rd");
	default:
		if (n<=20) return("th");
		else return(numerosuffix(n%10));
	}
}
