/* A short program to display MS Kermit VT320 emulation character sets */
/* Writes output to stdout, so best redirect it to a file for replaying */
/* From Joe Doupnik, 27 June 1989 */

#include <stdio.h>
#define SO 14
#define SI 15
#define ESC 27

/*		Nat  ASCII Latin Su G   Sp G  UPSS  Tech  Alt-Rom */
char *set[] =  {" ", ")B", "-A", ")%5", ")0", ")<", ")>", ")1"};

main()
{
	int i, j;
	void showtable(), at();

	fputc(ESC, stdout); fputs("!c", stdout);	/* master reset */
	at(1,2);
	fputs("\n    National  ASCII    Latin-1  Sup Gr   Spc Gr", stdout);
	fputs("    UPSS     Tech    Alt-Rom", stdout);
	fputs("\n                B        A        %5       0   ", stdout);
	fputs("     <        >        1", stdout);

	fputs("\n     ", stdout);
	for(i = 0; i < 8; i++)				/* label columns */
		{
		for (j = 2; j < 8; j++)
			printf("%#1d", j);
		fputs("   ", stdout);
		}
	for (i = 0; i < 16; i++)			/* label rows */
		{
		at(2, 6 + i);
		printf("%#2d: ", i);
		}

	fputc(ESC, stdout); fputs("[?42h", stdout); /* National Repl Chars */
	showtable(6, 6);
	fputc(ESC, stdout); fputs("[?42l", stdout); /* Disable NRCs */

	for (i = 1; i < 8; i++)			/* do the other char sets */
		{
		fputc(ESC, stdout); fputs(set[i], stdout);
		showtable(6+i*9, 6);
		}
	at(1, 23);				/* nail down cursor */
}

void
showtable(c, r)
int c, r;		/* display 96 characters in column format */
{
	int column, row;

	fputc(ESC, stdout); fputc('7', stdout);		/* save cursor */
	fputc(SO, stdout);				/* GL to G1 */
	for (column = 2; column < 8; column++)		/* cols 2..7 */
		for (row = 0; row < 16; row++)		/* rows 0..15 */
			{
			at(c+column-2, r+row);		/* position cursor */
			fputc(row + column * 16, stdout); /* show GL char */
			}
	fputc(SI, stdout);				/* GL to G0 */
	fputc(ESC, stdout); fputc('8', stdout);		/* restore cursor */
}
void
at(col, row)
int col, row;			/* position cursor at row, column */
{
	fputc(ESC, stdout);
	printf("[%d;%dH", row, col);		/* move to row, col */ 
}
/* the end */
