tpen.c

来自「speech signal process tools」· C语言 代码 · 共 740 行 · 第 1/2 页

C
740
字号
			*x2=temp;			temp= *y1;			*y1= *y2;			*y2=temp;			temp=c1;			c1=c2;			c2=temp;			swap= ~swap;		}		if(c1<4)	/* move endpoint in x */		{			temp=(c1&2?xwmax:xwmin);			*y1= solve(temp,*x1,*y1,*x2,*y2);			*x1=temp;		}		else		/* move endpoint in y */		{			temp=(c1&8?ywmax:ywmin);			*x1= solve(temp,*y1,*x1,*y2,*x2);			*y1=temp;		}		c1=code(*x1,*y1);	}	if( swap )	/* put endpoints in order */	{		temp= *x1; 		*x1= *x2; 		*x2=temp;		temp= *y1; 		*y1= *y2; 		*y2=temp;	}	return(0);}solve(pnot,p1,q1,p2,q2)register int pnot,p1,q1,p2,q2;{	/* floating point version */	double invslope;	register int qnot;	if(pnot==p1) return(q1);	if(pnot==p2) return(q2);	if(q1==q2) return(q1);	invslope= (q1-q2)/( (double) (p1-p2));	qnot= (pnot-p1)*invslope + (double) q1 + 0.5;	return(qnot);}/************** TEXT - process text strings **********/#include	"chars.h"#define DROPBIT 02000#define BS	010#define TAB	011#define CR	015#define NL	012#define US	'U'#define DS	'D'#define USHALF	'u'#define DSHALF	'd'#define GREEK	'g'#define SIZEP	'S'#define SIZEM	's'#define FATP	'F'#define FATM	'f'#define BSPACE	'b'short *symadd;char *symbase;text(size,orient)int size,orient;/* * interpret characters into vectors */{	int tfat, move,vmove,add,drop,xp,yp,grkflag;	char sym,xyw,*symptr;	register int a,b;	symadd= ascii.saddr;	symbase= ascii.svec;	tfat= fat;	grkflag=0;	move= (6*size)*xscale;	vmove= (10*size)*yscale;	while((sym=getc(pltin)))	{		if(sym < 040)		{			switch (sym)	/* standard carriage controls */			{			case -1: 				return;			case BS: 				mov(-move,0,orient); 				break;			case TAB:				switch (orient)				{				case 0: 				case 2:					do mov(move, 0, orient);					while ((abs(xold - xorigin)/move)%8);					break;				case 1: 				case 3:					do mov(move, 0, orient);					while ((abs(yold - yorigin)/move)%8);					break;				}				break;			case NL:				switch(orient)				{				case 0: 					yorigin -= vmove; 					break;				case 1: 					xorigin += vmove; 					break;				case 2: 					yorigin += vmove; 					break;				case 3: 					xorigin -= vmove; 					break;				}			case CR:				xold=	xorigin;				yold=	yorigin;				break;			case ESC:	/* special controls */				switch(sym=getc(pltin))				{				case -1: 				case 0: 					return;				case DS:						mov(0,-vmove,orient); 					break;				case DSHALF:						mov(0,-(vmove/2),orient); 					break;				case US:						mov(0,vmove,orient); 					break;				case USHALF:						mov(0,vmove/2,orient); 					break;				case BSPACE:						mov(-move,0,orient); 					break;				case GREEK:					symadd= greek.saddr;					symbase= greek.svec;					grkflag=1;					break;				case SIZEP:					size++;					move= (6*size)*xscale;					vmove= (10*size)*yscale;					break;				case SIZEM:					size--; 					if(size<1) size=1;					move= (6*size)*xscale;					vmove= (10*size)*yscale;					break;				case FATP:					tfat++;					break;				case FATM:					tfat--; 					if(tfat<0) tfat=0;					break;				}				break;			default:				goto	moveah;			}			continue;		}		if(sym == 040) goto moveah;		add= symadd[sym-040];		symptr= symbase +(add&01777);		drop= (add&DROPBIT ? 2 : 0);		xnew=xold; 		ynew=yold;		do		    {			xyw= *symptr++;			a= (((xyw&0160)>>4)*size)*xscale;			b= (((xyw&07) - drop)*size)*yscale;			switch(orient)			{			case 0: 				xp=xold+a; 				yp=yold+b; 				break;			case 1: 				xp=xold-b; 				yp=yold+a; 				break;			case 2: 				xp=xold-a; 				yp=yold-b; 				break;			case 3: 				xp=xold+b; 				yp=yold-a; 				break;			}			if( !(xyw&0200) ) vector(xnew,ynew,xp,yp,tfat);			xnew=xp; 			ynew=yp;		} 		while( !(xyw&010) );moveah:		switch(orient)		{		case 0: 			xold += move; 			break;		case 1: 			yold += move; 			break;		case 2: 			xold -= move; 			break;		case 3: 			yold -= move; 			break;		}		if(grkflag)		{			symadd= ascii.saddr;			symbase= ascii.svec;			grkflag=0;		}	}}mov(hadd,vadd,orient)register int hadd,vadd,orient;{	switch(orient)	{	case 0: 		xold += hadd; 		yold += vadd; 		break;	case 1: 		xold -= vadd; 		yold += hadd; 		break;	case 2: 		xold -= hadd; 		yold -= vadd; 		break;	case 3: 		xold += vadd; 		yold -= hadd; 		break;	}}area(){	register int i;	int npts;	int xnew, ynew;	char *xypack();	npts= geth(pltin);	(void) geth(pltin);	(void) geth(pltin);	(void) geth(pltin);	if(npts < 3) err(FATAL,"polynomial with less than three vertices");	xnew= GETX; 	ynew= GETY;	/* TEK */	fprintf(stdout, "\033OM%s", dpack((int)npts));	fprintf(stdout, "%s", xypack((int)xnew, (int)ynew));	xold=xnew;		yold=ynew;	for(i=1; i<npts; i++)	{		xnew= GETX; 		ynew= GETY;		fprintf(stdout, "%s", xypack((int)xnew, (int)ynew));		xold=xnew;			yold=ynew;	}	fflush(stdout);}fill() {	register int i;	int npts;	int xnew, ynew;	char *xypack();	npts= geth(pltin);	if(npts < 3) err(FATAL,"polynomial with less than three vertices");	xnew= GETX; 	ynew= GETY;	/* TEK */	fprintf(stdout, "\033OM%s", dpack((int)npts));	fprintf(stdout, "%s", xypack((int)xnew, (int)ynew));	xold=xnew;		yold=ynew;	for(i=1; i<npts; i++)	{		xnew= GETX; 		ynew= GETY;		fprintf(stdout, "%s", xypack((int)xnew, (int)ynew));		xold=xnew;			yold=ynew;	}	/* TEK */	fflush(stdout);}delaykill(){	if (atbreak)	{		exit(1);	}	kyll = 1;}/* * TEK packed integer, and packed coordinate pair */char *dpack(i){	static char s[4];	s[0] = 040 + ((i & 030000) >> 12);	s[1] = 040 + ((i & 007700) >> 6);	s[2] = 040 +  (i & 000077);	s[3] = 0;	return(s);}char *xypack(y,x){	/* TEK 4100 mode */	static char s[6];	y = 3120 - y;	s[0] = 040 | ((y & 07600) >> 7);  /* high order y */	s[1] = 0140 | ((y & 03) << 2) | (x & 03);	/* "extra" byte:					    lowest-order 2 bits of x and y					    for 12-bit addressing */	s[2] = 0140 | ((y & 0174) >> 2);   /* low order y */	s[3] = 040 | ((x & 07600) >> 7);   /* high order x */	s[4] = 0100 | ((x & 0174) >> 2);   /* low order x */	s[5] = 0;   /* end of character string */	return(s);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?