/*
 * WARNING -- untested
 */

#ifdef	pdp11
#define	SHORT	unsigned
#else
#define	SHORT	unsigned short
#endif

int divtab[] = {
	0,	1,	50,	3100
};

r50toa(buffer, r5vec, r5cnt)
register char		*buffer;	/* Output buffer		*/
SHORT int		*r5vec;		/* Input rad50 vector		*/
int			r5cnt;		/* Number of 16-bit words to do	*/
/*
 * Convert r5cnt words of radix 50 data to Ascii.  All letters will be
 * in upper-case.  The output buffer will not be null-trailed, nor will
 * blank fields be supreessed.
 */
{
	int			*divptr;
	int			ccount;
	SHORT int		r5word;
	char			c;

	while (--r5cnt >= 0) {
		/*
		 * Do each rad50 word.  The code is translated word
		 * for word from macro-11, hence the spaghetti style.
		 * See c5ta.mac for the details.
		 */
		r5word = *r5vec++;
		for (divptr = &divtab[4]; *--divptr != 0;) {
			c = -1;
			if (r5word >= 0174777) goto fourty;
			c = r5word % *divptr;
			r5word /= *divptr;
			if (c == 000) goto fifty;	/* Blank	*/
			if (c >  033) goto sixty;
			if (c == 033) goto seventy;
			if (c == 035) c = -1;		/* Illegal	*/
fourty:			c += 040;			/* Alpha or ?	*/
fifty:			c += 016;			/* Digit	*/
sixty:			c += 011;			/* . or $	*/
seventy:		c += 011;			/* $ or .	*/
			*buffer++ = c;
		}
	}
}
