[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::languages

Title:Languages
Notice:Speaking In Tongues
Moderator:TLE::TOKLAS::FELDMAN
Created:Sat Jan 25 1986
Last Modified:Wed May 21 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:394
Total number of notes:2683

144.0. "Convert ASCII to RAD50 in MACRO-11?" by GENRAL::RINESMITH (GOD never says OOPS!) Fri Jun 26 1987 11:04

    Does anyone know how, (or if it can be done) to convert an
    ASCII string to RAD50 notation in MACRO-11 on RT-11?
    
    I need to be able to convert any ASCII string at run-time.
    
    Thanks
T.RTitleUserPersonal
Name
DateLines
144.1exYIPPEE::DELISLEFri Jun 26 1987 11:297
    Well, you can't convert just 'any old' ASCII string to RAD50 since
    the definition of RAD50 is a subset of the ASCII character set.
    It consists of the capital letters A through Z, the digits 0 through
    9, and few specials like dollar sign, dot, etc.  It was used to
    store things like filenames so the subset worked well.  If you can
    live with that I know I have the routines around somewhere to go
    in both directions RAD50 to ASCII and ASCII to RAD50.
144.2Check the libraryTOOK::APPELLOFCarl Appellof LAT/VMSFri Jun 26 1987 14:593
    Dredging up knowledge from my days as an RT11 support specialist
    at the CSC:  I believe that there are routines in the RT11 SYSLIB
    to convert from ascii to RAD50 and back again.
144.3Routines in C3D::VESPERI have a � for NotesMon Jun 29 1987 11:28162
From Martin Minow's VAXLIB package:

Note that because `ascr50' defines `output' as an `int *', this will
only work as expected on a PDP-11.  I think it should be defined as
a `short *' and then it will work on both 16 and 32 bit machines.

Andy V

/*
 *
 *	ascr50(count, input, output)
 *	int		count;
 *	int		*output;
 *	char		*input;
 *
 * Description
 *
 *	Convert 'count' characters from ascii to Radix 50.  If there aren't a
 *	multiple of 3 characters, blanks are padded on the end.  The ascii
 *	string is moved to the output when finished.  The input and output
 *	areas may be the same since three input characters are read for
 *	every two bytes of output.
 */

struct table {
	char	low, high;
	int	magic;
};

struct table r50tab[] = {
	{ 'a',	'z',	-0140	},
	{ 'A',	'Z',	-0100	},
	{ '0',	'9',	-0022	},
	{ ' ',	' ',	-0040	},
	{ '$',	'$',	-0011	},
	{ '.',	'.',	-0022	},
	{ 0,	0, 	0	},
};
	
ascr50(count, input, output)
int		count;		/* Characters to convert		*/
char		*input;		/* Input string (ascii)			*/
int		*output;	/* Output vector (rad50)		*/
{
	register char		*wp;	/* Work area pointer		*/
	register int		byte;	/* Working byte			*/
	register struct table	*rp;	/* Rad50 table pointer		*/
	int			result;	/* Rad50 work -- gets value	*/
	char	work[3+1];		/* Gets next three bytes	*/

	for (;;) {
		work[0] = work[1] = work[2] = ' ';
		for (wp = work; --count >= 0;) {
			*wp++ = *input++;	/* Get one input byte	*/
			if (wp >= &work[3])
				break;
		}
		if (wp == work)
			return;			/* Nothing left to do	*/
		/*
		 * Convert 3 bytes (in word) to rad50
		 */
		result = 0;
		for (wp = work; wp < &work[3];) {
			byte = *wp++ & 0377;
			for (rp = r50tab; rp->low > 0; rp++) {
				if (byte >= rp->low && byte <= rp->high)
					break;
			}
			if (rp->low == 0)
				byte == 0;
			byte += rp->magic;
			result <<= 3;
			byte += result;
			result <<= 2;
			result += byte;
		}
		*output++ = result;
	}
}

/*
 *			r 5 0 t o a . c
 */

/*)LIBRARY
*/

#ifdef	DOCUMENTATION

title	r50toa	Convert Radix-50 to Ascii
Index		Convert radix-50 to Ascii

synopsis
	.s.nf
	r50toa(buff, r5vec, r5cnt);
	char		*buff;	/* Output text buffer	*/
	int		*r5vec;	/* Input rad50 buffer	*/
	int		r5cnt;	/* How many rad50 words	*/
	.s.f
description:

	Convert r5cnt words of radix 50 data to Ascii.  All letters
	will be in lower-case.  The output buffer will not be
	null-trailed, nor will blank fields be supressed.

bugs

#endif


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

/*
 * Dave Conroy's algorithm
 */


/*
 * Convert `nr50' words worth of
 * RADIX 50 data, pointed to by the argument
 * r5vec, into `3*nr50' bytes of Ascii and
 * store the characters into the buffer
 * pointed to by the `cp' argument. The output
 * string is in lower case. The illegal code
 * in RADIX 50 is converted to a `?'.
 */

static char     ctable[] = {
	" abcdefghijklmnopqrstuvwxyz$.?0123456789"
};

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 lower-case.  The output buffer will not be null-trailed, nor will
 * blank fields be supreessed.
 */
{
        register unsigned	r50;
        register char		*cp;

	while (--r5cnt >= 0) {
	    r50 = *r5vec++;
	    for (cp = ctable; r50 >= 03100; cp++) {
		r50 -= 03100;
	    }
	    *buffer++ = *cp;
	    for (cp = ctable; r50 >= 00050; cp++) {
		r50 -= 050;
	    }
	    *buffer++ = *cp;
	    *buffer++ = ctable[r50];
	}
}
144.4It's in the book...CRVAX1::KAPLOW16 bit paleontologistWed Jul 08 1987 16:387
        The routines you need are described in the RT-11 Programmer's
        Reference Manual, section 3. Specifically, look at: 
        
        IRAD50	- converts ascii characters to rad50 
        RAD50	- converts 6 ascii characters (file name) to rad50 

        R50ASC	- converts rad50 strings back to ascii
144.5AUTHOR::WELLCOMESteveTue Jul 28 1987 15:575
    There's a RAD50-to-ASCII subroutine given as a sample MACRO-11 program
    in Appendix H of the MACRO-11 manual (AA-V027A-TC).  The conversion
    (in either direction) is not very hard.  The SYSLIB routines are
    probably your best bet if you don't want to figure out the MACRO
    code yourself.