[net.sources] CIFSTR: generates characters in CIF

padpowell@wateng.UUCP (PAD Powell[Admin]) (06/24/83)

echo cifstr/Makefile
cat >cifstr/Makefile <<\%#%#EOF%#%#
CFLAGS= -O

all:	cifstr

cifstr:	cifstr.o font.o
	cc -o cifstr cifstr.o font.o

install: all
	install cifstr ${DESTDIR}/usr/bin
clean:
	rm *.o cifstr
%#%#EOF%#%#
echo cifstr/cifstr.1
cat >cifstr/cifstr.1 <<\%#%#EOF%#%#
.TH CIFSTR CAD1 local
.SH NAME
cifstr \- generate CIF for a character string
.SH SYNOPSIS
.B cifstr
[
.B \-l
layer
]
[
.B \-o
x,y
]
[
.B \-s
scale
]
[
string
]
.SH DESCRIPTION
.I Cifstr
generates CIF code to plot alphanumeric text.
Characters are based on a 16 high by 8 wide font.
The following options are available.
.RS 5n
.TP
.B "-l layer"
output code to set layer.
.TP
.B "-s scale"
scale up by the integer scale factor.
.TP
.B "-o x,y"
offset start of output to x,y.
.RE
.PP
If no input string is specified, input defaults to stdin.
.PP
For example, if the current set of design rules specify minimum metal
line widths as 6 microns (600 CIF), then the following will generate
the string "Waterloo" on the metal layer, in 96 micron high letters,
offset from the origin by 100 microns (10000 CIF).
.br
.nf
cifstr -s 600 -o 10000,0 -l LCM "Waterloo"
.fi
.SH AUTHOR
Patrick A.D. Powell, with suggestions from Jim Barby.
VLSI Research Group, U. Waterloo.
%#%#EOF%#%#
echo cifstr/cifstr.c
cat >cifstr/cifstr.c <<\%#%#EOF%#%#
/*
	Program to generate CIF symbols for characters and strings.

	Calling sequence (UNIX):
		cifstr [-s Scale] [-o x,y] [-l layer] [string]
	If the string is not supplied, then input is taken from stdin.
	Options:
		-s Scale:	basic character size is 16 CIF units by
				8 CIF units.  The basic character will
				be scaled by Scale.  Default is 1.
		-o x,y		origin of string (lower left corner) is
				to be at x,y (CIF units).
		-l layer	the layer name (none by default).

	NOTES:
		The idea for this program was unabashadly stolen from
	the "games" portion of the Berkeley UNIX (T.M. Bell Labs)
	distribution, and the "gen" library tables.  Gracious thanks
	to the anonymous person who printed a banner for his office, and
	gave me the idea.

		Jim Barby compelled me to sit down and make it bombproof.

		This was a Sunday Afternoon Haque.

			Patrick Powell, U. Waterloo
			June 19, 1982
*/

#include <stdio.h>

#define	MAXSTR	100	/* input line length */

#define bit(a,b)		(((a) >> (b)) & 1)
#define DEL	0177
#define	GOOD		0	/* printable char */
#define BAD		1	/* unprintable or otherwise ugly char */
#define BACK		2	/* '\b' */
#define WH		3	/* white space: ' ' */
#define EOL		4	/* slew */
#define TAB		5	/* tab: '\t' */
#define	EOF_		6

#define cclass(c)		((c) > DEL ? BAD : (ctab+1)[c])
char ctab[] = {
	EOF_,
	BAD,	BAD,	BAD,	BAD,	BAD,	BAD,	BAD,	BAD,
	BACK,	TAB,	EOL,	EOL,	EOL,	EOL,	BAD,	BAD,
	BAD,	BAD,	BAD,	BAD,	BAD,	BAD,	BAD,	BAD,
	BAD,	BAD,	BAD,	BAD,	BAD,	BAD,	BAD,	BAD,
	WH,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,
	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,
	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,
	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,
	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,
	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,
	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,
	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,
	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,
	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,
	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,
	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	GOOD,	BAD
};
#define BHIEGHT		16		/* hieght of banner chars */
extern char	chrtab[][16];

/*
	External constants
*/
int	origin_x, origin_y, scale=1;
char	*layer;
char	*string;
char	*arg0;

main( argc, argv )
	int argc;
	char *argv[];
    {
	/* get parameters */

	arg0 = argv[0];
	getparms( argc, argv );

	if( string ) putstring( string, scale, layer );
	else {
		char str[MAXSTR];
		while( fgets( str, MAXSTR, stdin ) != NULL ){
			putstring( str, scale, layer );
			origin_y += BHIEGHT*scale;
		}
	}
    }

putstring( str, size, layer )
	char *str, *layer;
	int size;
    {
	int x, y, c;

	x = origin_x;
	y = origin_y;

	if( layer ) putlayer( layer );
	while( (c = *str++) ){
		switch( cclass( c ) ){
			case EOL:
				x = origin_x;
				y += BHIEGHT*size;
				break;
			default:
				putletter( c, x, y, scale );
				x += 8*scale;
				break;
		}
		origin_y = y;
	}
    }

putletter( c, x, y, size )
	char c;
	int x, y, size;
    {
	int i, j, map;
	/*
		scan row.  Table is encoded so that top row is index 0,
		bottom row index BHIEGHT-1
	*/
	for( i=0; i < BHIEGHT; ++i ){
		/* scan column */
		/* make ugly chars look like blots */
		map = cclass(c) == BAD ?
			~0 : chrtab[c - ' '][i];
		for( j=7; j>=0; --j ){
			/* check to see if bit set */
			for (j = 7; j >= 0; j--)
				if( bit(map,j) )
					putblock( x+(7-j)*size,
						y+(BHIEGHT-1-i)*size,
						size );
		}
	}
    }


putblock( x,y,size )
	int x, y, size;
    {
	fprintf( stdout,"B %d %d {%d,%d};\n", size, size, x, y );
    }


putlayer( layer )
	char *layer;
    {
	fprintf( stdout,"Layer %s;\n", layer );
    }
getparms( argc, argv )
	int argc;
	char *argv[];
    {
	int c;
	++argv;
	for( --argc; argc>0; ++argv, --argc ){
		if( argv[0][0] == '-' ) {
			c = argv[0][1];
			if( argv[0][2] || --argc <=0 ) usage();
			++argv;
			switch( c ){
				case 'l':
					layer = *argv;
					break;
				case 'o':
					if( sscanf( argv[0],"%d , %d",
						&origin_x, &origin_y )
						!= 2 ) usage();
					break;
				case 's':
					if( sscanf( argv[0],"%d",
						&scale )
						!= 1 ) usage();
					break;
				default:
					usage();
					break;
			}
		} else if( string == 0 ){
			string = argv[0];
		} else
			usage();
	}
    }
usage()
    {
	static char *msg =
		"%s:  [-o x,y] [-s scale] [string]\n";
	fprintf( stdout, msg, arg0 );
	exit(0);
    }
%#%#EOF%#%#
echo cifstr/font.c
cat >cifstr/font.c <<\%#%#EOF%#%#
char	chrtab[][16] = {
0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, sp, */
0010,0010,0010,0010,0010,0010,0010,0010,0000,0000,0010,0000,0000,0000,0000,0000, /*, !, */
0024,0024,0024,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ", */
0000,0000,0000,0044,0044,0176,0044,0044,0176,0044,0044,0000,0000,0000,0000,0000, /*, #, */
0000,0010,0010,0010,0076,0101,0100,0076,0001,0101,0076,0010,0010,0000,0000,0000, /*, $, */
0000,0000,0000,0141,0142,0004,0010,0010,0020,0043,0103,0000,0000,0000,0000,0000, /*, %, */
0000,0000,0070,0104,0110,0060,0060,0111,0106,0106,0071,0000,0000,0000,0000,0000, /*, &, */
0004,0010,0020,0040,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ', */
0000,0004,0010,0020,0040,0040,0040,0040,0040,0040,0020,0010,0004,0000,0000,0000, /*, (, */
0000,0040,0020,0010,0004,0004,0004,0004,0004,0004,0010,0020,0040,0000,0000,0000, /*, ), */
0000,0000,0000,0010,0111,0052,0034,0177,0034,0052,0111,0010,0000,0000,0000,0000, /*, *, */
0000,0000,0000,0000,0010,0010,0010,0177,0010,0010,0010,0000,0000,0000,0000,0000, /*, +, */
0000,0000,0000,0000,0000,0000,0000,0000,0000,0030,0030,0010,0020,0000,0000,0000, /*, ,, */
0000,0000,0000,0000,0000,0000,0000,0176,0000,0000,0000,0000,0000,0000,0000,0000, /*, -, */
0000,0000,0000,0000,0000,0000,0000,0000,0000,0030,0030,0000,0000,0000,0000,0000, /*, ., */
0000,0000,0001,0002,0004,0010,0010,0010,0020,0040,0100,0000,0000,0000,0000,0000, /*, /, */
0000,0030,0044,0102,0102,0102,0102,0102,0102,0044,0030,0000,0000,0000,0000,0000, /*, 0, */
0000,0010,0030,0010,0010,0010,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, 1, */
0000,0070,0104,0004,0004,0010,0020,0040,0100,0100,0174,0000,0000,0000,0000,0000, /*, 2, */
0000,0176,0004,0004,0010,0014,0002,0002,0002,0104,0070,0000,0000,0000,0000,0000, /*, 3, */
0000,0004,0014,0024,0044,0104,0176,0004,0004,0004,0004,0000,0000,0000,0000,0000, /*, 4, */
0000,0174,0100,0100,0130,0144,0002,0002,0102,0044,0030,0000,0000,0000,0000,0000, /*, 5, */
0000,0074,0102,0100,0130,0144,0102,0102,0102,0044,0030,0000,0000,0000,0000,0000, /*, 6, */
0000,0176,0004,0004,0010,0010,0020,0020,0040,0040,0040,0000,0000,0000,0000,0000, /*, 7, */
0000,0034,0042,0101,0042,0076,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, 8, */
0000,0034,0042,0101,0101,0101,0043,0036,0004,0010,0020,0040,0000,0000,0000,0000, /*, 9, */
0000,0000,0000,0000,0000,0000,0030,0030,0000,0030,0030,0000,0000,0000,0000,0000, /*, :, */
0000,0000,0000,0000,0000,0000,0030,0030,0000,0030,0030,0020,0040,0000,0000,0000, /*, ;, */
0002,0004,0010,0020,0040,0100,0040,0020,0010,0004,0002,0000,0000,0000,0000,0000, /*, <, */
0000,0000,0000,0000,0177,0000,0177,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, =, */
0100,0040,0020,0010,0004,0002,0004,0010,0020,0040,0100,0000,0000,0000,0000,0000, /*, >, */
0000,0030,0044,0102,0001,0002,0004,0010,0010,0000,0010,0000,0000,0000,0000,0000, /*, ?, */
0000,0074,0102,0101,0115,0123,0121,0121,0121,0111,0046,0000,0000,0000,0000,0000, /*, @, */
0000,0010,0024,0042,0101,0101,0177,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, A, */
0000,0176,0101,0101,0101,0176,0101,0101,0101,0101,0176,0000,0000,0000,0000,0000, /*, B, */
0000,0076,0101,0100,0100,0100,0100,0100,0100,0101,0076,0000,0000,0000,0000,0000, /*, C, */
0000,0176,0101,0101,0101,0101,0101,0101,0101,0101,0176,0000,0000,0000,0000,0000, /*, D, */
0000,0176,0100,0100,0100,0170,0100,0100,0100,0100,0177,0000,0000,0000,0000,0000, /*, E, */
0000,0177,0100,0100,0100,0174,0100,0100,0100,0100,0100,0000,0000,0000,0000,0000, /*, F, */
0000,0076,0101,0100,0100,0117,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, G, */
0000,0101,0101,0101,0101,0176,0101,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, H, */
0000,0034,0010,0010,0010,0010,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, I, */
0000,0016,0004,0004,0004,0004,0004,0004,0104,0104,0070,0000,0000,0000,0000,0000, /*, J, */
0000,0101,0102,0104,0110,0120,0160,0110,0104,0102,0101,0000,0000,0000,0000,0000, /*, K, */
0000,0100,0100,0100,0100,0100,0100,0100,0100,0100,0177,0000,0000,0000,0000,0000, /*, L, */
0000,0101,0143,0125,0111,0101,0101,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, M, */
0000,0101,0141,0121,0111,0105,0103,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, N, */
0000,0076,0101,0101,0101,0101,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, O, */
0000,0176,0101,0101,0101,0176,0100,0100,0100,0100,0100,0000,0000,0000,0000,0000, /*, P, */
0000,0076,0101,0101,0101,0101,0101,0101,0131,0105,0076,0002,0001,0000,0000,0000, /*, Q, */
0000,0176,0101,0101,0101,0176,0104,0102,0101,0101,0101,0000,0000,0000,0000,0000, /*, R, */
0000,0076,0101,0100,0100,0076,0001,0001,0001,0101,0076,0000,0000,0000,0000,0000, /*, S, */
0000,0177,0010,0010,0010,0010,0010,0010,0010,0010,0010,0000,0000,0000,0000,0000, /*, T, */
0000,0101,0101,0101,0101,0101,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, U, */
0000,0101,0101,0101,0101,0101,0101,0101,0042,0024,0010,0000,0000,0000,0000,0000, /*, V, */
0000,0101,0101,0101,0101,0111,0111,0125,0143,0101,0101,0000,0000,0000,0000,0000, /*, W, */
0000,0101,0101,0042,0024,0010,0024,0042,0101,0101,0101,0000,0000,0000,0000,0000, /*, X, */
0000,0101,0042,0024,0010,0010,0010,0010,0010,0010,0010,0000,0000,0000,0000,0000, /*, Y, */
0000,0177,0001,0002,0004,0010,0020,0040,0100,0100,0177,0000,0000,0000,0000,0000, /*, Z, */
0000,0034,0020,0020,0020,0020,0020,0020,0020,0020,0020,0034,0000,0000,0000,0000, /*, [, */
0000,0000,0100,0040,0020,0010,0010,0010,0004,0002,0001,0000,0000,0000,0000,0000, /*, , \, */
0000,0070,0010,0010,0010,0010,0010,0010,0010,0010,0010,0070,0000,0000,0000,0000, /*, ], */
0010,0024,0042,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ^, */
0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0377,0000,0000, /*, _, */
0040,0020,0010,0004,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, `, */
0000,0000,0000,0000,0000,0074,0002,0076,0102,0102,0076,0000,0000,0000,0000,0000, /*, a, */
0000,0100,0100,0100,0100,0174,0102,0102,0102,0102,0174,0000,0000,0000,0000,0000, /*, b, */
0000,0000,0000,0000,0000,0074,0102,0100,0100,0102,0074,0000,0000,0000,0000,0000, /*, c, */
0002,0002,0002,0002,0002,0076,0102,0102,0102,0102,0076,0000,0000,0000,0000,0000, /*, d, */
0000,0000,0000,0000,0000,0074,0102,0174,0100,0102,0074,0000,0000,0000,0000,0000, /*, e, */
0000,0016,0020,0020,0020,0176,0020,0020,0020,0020,0020,0000,0000,0000,0000,0000, /*, f, */
0000,0000,0000,0000,0000,0076,0102,0102,0102,0102,0076,0002,0002,0102,0076,0000, /*, g, */
0000,0100,0100,0100,0100,0174,0102,0102,0102,0102,0102,0000,0000,0000,0000,0000, /*, h, */
0000,0000,0000,0010,0000,0030,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, i, */
0000,0000,0000,0010,0000,0030,0010,0010,0010,0010,0010,0010,0010,0050,0020,0000, /*, j, */
0000,0100,0100,0100,0100,0106,0110,0120,0160,0110,0106,0000,0000,0000,0000,0000, /*, k, */
0000,0030,0010,0010,0010,0010,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, l, */
0000,0000,0000,0000,0000,0166,0111,0111,0111,0111,0111,0000,0000,0000,0000,0000, /*, m, */
0000,0000,0000,0000,0100,0174,0102,0102,0102,0102,0102,0000,0000,0000,0000,0000, /*, n, */
0000,0000,0000,0000,0000,0074,0102,0102,0102,0102,0074,0000,0000,0000,0000,0000, /*, o, */
0000,0000,0000,0000,0000,0174,0102,0102,0102,0102,0174,0100,0100,0100,0100,0000, /*, p, */
0000,0000,0000,0000,0000,0076,0102,0102,0102,0102,0076,0002,0002,0002,0002,0000, /*, q, */
0000,0000,0000,0000,0000,0134,0142,0100,0100,0100,0100,0000,0000,0000,0000,0000, /*, r, */
0000,0000,0000,0000,0000,0076,0100,0074,0002,0102,0074,0000,0000,0000,0000,0000, /*, s, */
0000,0020,0020,0020,0020,0176,0020,0020,0020,0020,0014,0000,0000,0000,0000,0000, /*, t, */
0000,0000,0000,0000,0000,0102,0102,0102,0102,0102,0075,0000,0000,0000,0000,0000, /*, u, */
0000,0000,0000,0000,0000,0101,0101,0101,0042,0024,0010,0000,0000,0000,0000,0000, /*, v, */
0000,0000,0000,0000,0000,0111,0111,0111,0111,0111,0066,0000,0000,0000,0000,0000, /*, w, */
0000,0000,0000,0000,0000,0102,0044,0030,0030,0044,0102,0000,0000,0000,0000,0000, /*, x, */
0000,0000,0000,0000,0000,0102,0102,0102,0042,0024,0010,0020,0040,0100,0000,0000, /*, y, */
0000,0000,0000,0000,0000,0176,0004,0010,0020,0040,0176,0000,0000,0000,0000,0000, /*, z, */
0000,0014,0020,0020,0020,0020,0040,0020,0020,0020,0020,0014,0000,0000,0000,0000, /*, {, */
0000,0010,0010,0010,0010,0000,0000,0010,0010,0010,0010,0000,0000,0000,0000,0000, /*, |, */
0000,0030,0010,0010,0010,0010,0004,0010,0010,0010,0010,0030,0000,0000,0000,0000, /*, }, */
0020,0052,0004,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ~, */
0000,0176,0176,0176,0176,0176,0176,0176,0176,0176,0176,0000,0000,0000,0000,0000, /*, del, */
};
%#%#EOF%#%#