/*
 * Print gothic style banners -- John Buck   7/82
 * Real sucky code, it was done in a couple of hours though.
 */

main(){
	char c , cr , chr[95] , buf[512] , sp[128] , ovrprt[3][128] ,
		set[95][300] , ff;
	char *ptr , *ptr2;
	register i , j , k , l;
	int r , s , m ,n , hold , fd;

	for(i = 0; i < 128; i++){
		sp[i] = ' ';
		ovrprt[0][i] = 'X';
		ovrprt[1][i] = 'O';
		ovrprt[2][i] = '$';
				}
	cr = 13;
	s = 1;
	ff = 12;


	if((fd = open("gothic.dat",0)) == -1){
		write(2,"\n?Data base is missing\n\n",24);
		exit(1);
				}

	write(2,"\n\nMessage? ",11);
	r = read(fd,buf,512);

nxrd:
	i = 0;
nxchr:
	c = buf[i];

	for(j = i + 1; j < r; j++){
		if(buf[j] != c)continue;
		for(k = i + 1; k < j; k++)set[s][k-i-1] = buf[k];
		set[s][k-i-1] = -128;
		chr[s++] = c & 127;
		i = j + 1;
		goto nxchr;
				}

	if(r != 512)goto inp;

	if(i == 0){
		write(2,"\n?Data base is not logical\n\n",28);
		exit(1);
		}

	for(k = i; k < r; k++)buf[k-i] = buf[k];
	k =- i;
	r = read(fd,&buf[k],512-k) + k;
	goto nxrd;

inp:
	chr[s] = 0;
	i = 0;
	while((c = getchar()) != '\n')buf[i++] = c & 127;
	if(i == 0)exit(0);
	buf[i] = 0;
	l = 0;
	ptr2 = buf;
	while(*ptr2){
		if(*ptr2 == ' '){
			ptr2++;
			continue;
				}

		ptr = &chr[1];
		while(*ptr && *ptr != *ptr2)ptr++;
		if(*ptr == 0){
			write(2,ptr2,1);
			write(2,": Not in character set\n",23);
			l = 1;
				}
		ptr2++;
			}
		if(l){
			write(2,"\nErrors in input stream.  Legal characters are:\n\n ",50);
			write(2,&chr[1],s);
			write(2,"\n\nPrint anyway? ",16);
			buf[511] = 0;
			while((c = getchar()) != '\n')if(buf[511] == 0)buf[511] = c;
			if(buf[511] != 'y')goto doagin;
				}



ovr:
	k = 0;
	write(2,"\nNumber of overprints (1-3)? ",29);
	while((c = getchar()) != '\n')k = k * 10 + c - '0';
	if(k < 1 || k > 3)goto ovr;
	write(1,"\n",1);


	write(1,&ff,1);
	for(j = 0; j < i; j++){
		for(r = 1; r < s && chr[r] != buf[j]; r++);
		if(r == s)goto next;

		hold = 0;
		for(l = 0; set[r][l] != -128 && l < 300; l++){
			if(set[r][l] != -1)continue;
			for(m = 0; m < k; m++){
				for(n = hold; n < l; n =+ 2){
					write(1,sp,set[r][n]);
					write(1,&ovrprt[m][0],set[r][n+1]);
							}
				write(1,&cr,1);
					}
			hold = l + 1;
			write(1,"\n",1);
				}

next:
		write(1,"\n\n\n\n",4);
			}

	write(1,&ff,1);
doagin:
	write(2,"\n\nMessage? ",11);
	goto inp;

		}


