[net.sources] converting ascii for cybers

arnold@gatech.UUCP (Mister Snuffle-upagus) (10/26/84)

This is a cute little program my office mate and I wrote to translate
regular 7 bit ASCII into the escape 6/12 codes that CDC Cybers use.
It may come in useful to the rest of the world.

It does not translate the ascii LF into the ^) combination, since I use
it to prepare input to 'dd', which blocks the records on the tape, and
then the cyber unblocks it and supplies the newline.

Don't forget the .signature (I didn't think it necessary to 'shar'
just one file).

-------------------------------- cut here --------------------------
/* cyber --- map ascii into display code equivalents (ugh) */

/* Jeff Lee and Arnold Robbins, October 1984, Georgia Tech */
/* gatech!jeff && gatech!arnold */

#include <stdio.h>
#include <ctype.h>

char *table[] = {
	"^5",	/* NUL */
	"^6",	/* SOH */
	"^7",	/* STX */
	"^8",	/* ETX */
	"^9",	/* EOT */
	"^+",	/* ENQ */
	"^-",	/* ACK */
	"^*",	/* BEL */

	"^/",	/* BS */
	"^(",	/* HT */
	"\n",	/* LF */	/* ("^)") leave alone: dd will futz with it */
	"^$",	/* VT */
	"^=",	/* FF */
	"^ ",	/* CR */
	"^,",	/* SO */
	"^.",	/* SI */

	"^#",	/* DLE */
	"^[",	/* DC1 */
	"^]",	/* DC2 */
	"^%",	/* DC3 */
	"^\"",	/* DC4 */
	"^_",	/* NAK */
	"^!",	/* SYN */
	"^&",	/* ETB */

	"^'",	/* CAN */
	"^?",	/* EM */
	"^<",	/* SUB */
	"^>",	/* ESC */
	"^@",	/* FS */
	"^\\",	/* GS */
	"^^",	/* RS */
	"^;",	/* US */

	" ",	/* space */
	"!",	/* exclamation point */
	"\"",	/* quote */
	"#",	/* number sign */
	"$",	/* dollar sign */
	"%",	/* percent sign */
	"&",	/* ampersand */
	"'",	/* apostrophe */

	"(",	/* opening parenthesis */
	")",	/* closing parenthesis */
	"*",	/* asterisk */
	"+",	/* plus */
	",",	/* comma */
	"-",	/* dash */
	".",	/* period */
	"/",	/* slant */

	"0",	/* zero */
	"1",	/* one */
	"2",	/* two */
	"3",	/* three */
	"4",	/* four */
	"5",	/* five */
	"6",	/* six */
	"7",	/* seven */

	"8",	/* eight */
	"9",	/* nine */
	"@D",	/* colon (':')  */
	";",	/* semicolon */
	"<",	/* less than */
	"=",	/* equal */
	">",	/* greater than */
	"?",	/* question mark */

	"@A",	/* commercial at ('@') */
	"A",	/* upper case letters go as themselves */
	"B",
	"C",
	"D",
	"E",
	"F",
	"G",

	"H",
	"I",
	"J",
	"K",
	"L",
	"M",
	"N",
	"O",

	"P",
	"Q",
	"R",
	"S",
	"T",
	"U",
	"V",
	"W",

	"X",
	"Y",
	"Z",
	"[",	/* opening bracket */
	"\\",	/* reverse slant */
	"]",	/* closing bracket */
	"@B",	/* circumflex ('^') */
	"_",	/* underline */

	"@G",	/* grave accent ('`') */
	"^A",	/* lower case letters... */
	"^B",
	"^C",
	"^D",
	"^E",
	"^F",
	"^G",

	"^H",
	"^I",
	"^J",
	"^K",
	"^L",
	"^M",
	"^N",
	"^O",

	"^P",
	"^Q",
	"^R",
	"^S",
	"^T",
	"^U",
	"^V",
	"^W",

	"^X",
	"^Y",
	"^Z",
	"^0",	/* opening brace ('{') */
	"^1",	/* vertical line ('|') */
	"^2",	/* closing brace ('}') */
	"^3",	/* tilde ('~') */
	"^4",	/* DEL */
	NULL
	};

main()
{
	register int c, i, j, cnt;
	char ibuf[BUFSIZ], obuf[2 * sizeof ibuf];

	int read(), write();

	/* use raw i/o for speed */
	while ((cnt = read (0, ibuf, sizeof ibuf)) > 0)
	{
		i = j = 0;
		while (i < cnt)
		{
			c = ibuf[i++] & 0177;	/* ensure 7 bits */
			obuf[j++] = table[c][0];
			if (table[c][1])
				obuf[j++] = table[c][1];
		}

		write(1, obuf, j);
	}
}
-- 
Arnold Robbins
CSNET: arnold@gatech	ARPA:	arnold%gatech.csnet@csnet-relay.arpa
UUCP: { akgua, allegra, hplabs, ihnp4 }!gatech!arnold

Can you tell me how to get, how to get to Sesame Street?