🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.chess
Article #770

Re: filter to generate boards for troff

#770
From: Andy Tannenbaum
Date: Tue, 02 Apr 1985 17:43
72 lines
2710 bytes
I decided after posting the message which this one follows that I
should write the filter I requested, for a program which takes human
readable chess board listings as input, and puts out troff chess font
output.

	Andy Tannenbaum   Masscomp  Westford, MA   (617) 692-6200 x274
<<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>>
/*
 * cbtpp - chess board troff preprocessor
 * Andy Tannenbaum MASSCOMP 4/1/85
 *
 *	maps		to
 *
 *	HTTTTTTTTX	HTTTTTTTTX
 *	VrnbqkbnrF	VrmblkansF
 *	VppppppppF	VopopopopF
 *	V........F	V0Z0Z0Z0ZF
 *	V........F	VZ0Z0Z0Z0F
 *	V........F	V0Z0Z0Z0ZF
 *	V........F	VZ0Z0Z0Z0F
 *	V........F	V0Z0Z0Z0ZF
 *	V........F	VZ0Z0Z0Z0F
 *	VPPPPPPPPF	VPOPOPOPOF
 *	VRNBQKBNRF	VSNAQJBMRF
 *	WUUUUUUUUG	WUUUUUUUUG
 *
 * Reads stdin, writes stdout.
 * CAPS are white pieces, dots are blank squares.
 * It doesn't add borders, it will filter them properly.
 * You might want to write a separate filter which calls
 * cbtpp on a buffer bracketed by a .CS/.CE pair a la eqn or tbl.
 *
 */

#include <stdio.h>
#define BLACK 0
#define WHITE 1
#define flip(x) (x ^= 1)

/*
 * \n is part of these arrays so that it will cause
 * the square color to flip at end of line, this assumes a
 * board of even width.  The border characters are in here
 * so that there will always be an even number of mapped
 * characters output before the first white square, whether
 * you include borders or not.
 */

char in[] = "rnbqkp.RNBQKPHTXFGUWV\n";	/* input tokens */
char wh[] = "rnbqkp0RNBQKPHTXFGUWV\n";	/* mappings for white squares */
char bl[] = "smaljoZSMALJOHTXFGUWV\n";	/* mappings for black squares */

/*
 * Get a character c, if it's in the in[] array, then put a character
 * from wh[] or bl[], depending on the current square color, and flip
 * square color.  If c isn't in in[], then just echo it.
 */

main(){
	int c, i, square = BLACK;

	while ((c = getchar()) != EOF)
		putchar(
			((i = strchr(in, c)) == NULL) ?
			 c :
			 (
			  ((flip(square)) == BLACK) ?
			   bl :
			   wh
			 )[i - (int)in]
		       );
}
Technical Details
Message-ID: <655@masscomp.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!bonnie!masscomp!trb
References: <651@masscomp.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site masscomp.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!bonnie!masscomp!trb
From: trb@masscomp.UUCP (Andy Tannenbaum)
Newsgroups: net.chess
Subject: Re: filter to generate boards for troff
Message-ID: <655@masscomp.UUCP>
Date: Tue, 2-Apr-85 12:43:56 EST
Article-I.D.: masscomp.655
Posted: Tue Apr  2 12:43:56 1985
Date-Received: Wed, 3-Apr-85 01:12:48 EST
References: <651@masscomp.UUCP>
Reply-To: trb@masscomp.UUCP (Andy Tannenbaum)
Distribution: net
Organization: Masscomp - Westford, MA
Lines: 72