RT-11 floppy -- radix50.c
John R Blaker
jrb at wdl1.UUCP
Sat Feb 18 04:52:15 AEST 1984
/*==========================================================================*
* == R A D I X 5 0 == *
*==========================================================================*
* John R Blaker -- Ford Aerospace & Communications Corporation -- Oct 1982 *
*==========================================================================*
* This file contains some routines stolen from the 'rk11' program for *
* dealing with RADIX-50 format of filenames in the directory of an RT11 *
* disc. It also contains some interface routines of my own which have *
* nicer names than those stolen. This file contains the following *
* functions: *
* rt11_to_a() RT11 format to regular ASCII (mine) *
* a_to_rt11() Regular ASCII to RT11 (mine) *
* r502a() RADIX-50 to ASCII (stolen) *
* a2r50() ASCII to RADIX-50 (stolen) *
* code() Convert to ASCII code *
*==========================================================================*
*/
/*
* Include files
*/
#include "rt11.h" /* Global definitions */
/*
* rt11_to_a()
* Translates a RADIX-50 filename to a regular ASCII one
*/
rt11_to_a(fnm1, fnm2, ext, filename)
int fnm1; /* Radix-50 of first 3 characters in filename */
int fnm2; /* Radix-50 of second 3 characters in filename */
int ext; /* Radix-50 of file type extension */
char *filename; /* String to hold filename */
{
char name1[4]; /* ASCII first part of filename */
char name2[4]; /* ASCII second part of filename */
char exten[4]; /* ASCII extension */
r502a(fnm1, name1);
name1[3] = '\0';
r502a(fnm2, name2);
name2[3] = '\0';
r502a(ext, exten);
exten[3] = '\0';
strcpy(filename, name1);
strcat(filename, name2);
strcat(filename, ".");
strcat(filename, exten);
} /* rt11_to_a */
/*
* a_to_rt11()
* Translates an ASCII to a RADIX-50 one
*/
a_to_rt11(name, fnm1, fnm2, ext)
char *name; /* filename to be converted */
int fnm1; /* RADIX-50 of first 3 characters */
int fnm2; /* RADIX-50 of second 3 characters */
int ext; /* RADIX-50 of 3 character extension */
{
char name1[4]; /* String for first 3 characters */
char name2[4]; /* String for second 3 characters */
char exten[4]; /* String for 3 character extension */
int index; /* Loop index */
for (index = 0; index < 4; index++) {
name1[index] = name[index];
name2[index] = name[index + 4];
exten[index] = name[index + 9];
} /* for */
} /* a_to_rt11 */
int ldivr; /* Remainder of long division */
/*
* R502A : rad50 to ascii converter.
*/
r502a(ar50, acp) /*xlate rad50 value to ascii string*/
int ar50; /*rad50 value to be xlated*/
char *acp; /*pointer to target array*/
{
register char *cp;
register char *rp;
cp = acp;
rp = " abcdefghijklmnopqrstuvwxyz$.?0123456789"; /* convert to lower */
*cp++ = *(rp + ldiv(0, ar50, 050*050));
*cp++ = *(rp + ldivr / 050);
*cp = *(rp + ldivr % 050);
} /* r502a */
/*
* A2R50 : ASCII to rad50 conversion.
*/
a2r50(acp, ar50p) /* xlate ascii string to rad50 string */
char *acp; /*points to null-terminated ascii string*/
int *ar50p; /*points to target array*/
{
int i;
register int j;
char *ap;
register char c;
/*
ap = "\
\377\377\377\377\377\377\377\377\
\377\377\377\377\377\377\377\377\
\377\377\377\377\377\377\377\377\
\377\377\377\377\377\377\377\377\
\000\377\377\377\033\377\377\377\ space $
\377\377\377\377\377\377\034\377\ .
\036\037\040\041\042\043\044\045\ 0 - 7
\046\047\377\377\377\377\377\377\ 8 - 9
\377\001\002\003\004\005\006\007\ A -
\010\011\012\013\014\015\016\017\ -
\020\021\022\023\024\025\026\027\ -
\030\031\032\377\377\377\377\377\ - Z
\377\001\002\003\004\005\006\007\ a -
\010\011\012\013\014\015\016\017\ -
\020\021\022\023\024\025\026\027\ -
\030\031\032\377\377\377\377\377"; - z
*/
while (1) {
i = 0;
for (j = 050*050 ; j > 0 ; j =/ 050) {
if ((c = *acp++) == '\0')
return(0);
if ((c = code(c)) < 0)
return(-1);
*ar50p = i =+ j * c;
} /* for */
ar50p++;
} /* while */
} /* a2r50 */
/*
* code()
* This function converts a character to its
* ASCII code
*/
char code(c)
char c;
{
if ( c == ' ')
return('\0');
if ( c == '$')
return('\033');
if ( c == '.')
return('\034');
if ((c >= 'a') && (c <= 'z'))
return((c-'a')+'\01');
if ((c >= 'A') && (c <= 'Z'))
return((c-'A')+'\01');
if ((c >= '0') && (c <= '9'))
return((c-'0')+'\036');
return(0377);
} /* code */
#ifndef PWB
# define MAXINT 16536 /* Maximum int size on PDP-11 */
/*
* ldiv()
* Simulate old V6/PWB 'ldiv()' library function
*/
ldiv(hi, lo, div)
int hi; /* High-byte of dividend */
unsigned lo; /* Low-byte of dividend */
int div; /* Divisor */
{
ldivr = ((hi * MAXINT) + lo) % div;
return(((hi * MAXINT) + lo) / div);
} /* ldiv */
#endif
More information about the Comp.sources.unix
mailing list