/*-=-=-=-=-=-=-=-=-=-=-=- RCCL/RCI Notice of Copyright -=-=-=-=-=-=-=-=-=-=-*
 *									    *
 *	Copyright (C) 1991 by John E. Lloyd.				    *
 *									    *
 *	Information on copyright permissions, as well as a complete	    *
 *	disclaimer of warranty, is given in the file COPYRIGHT.		    *
 *									    *
 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
/* Program to test the makePosition() function. To operate,
   just run the program; if all is well, it should print 

	ROUTINES OK

   after a while and exit.
*/

#ifdef VXWORKS_CFG
#define main testPos_
#endif

#include "../h/rccl.h"
#include "../h/errorCodes.h"
#include "../rccl/transform.h"
#include <ctype.h>

#define NOSHIFT		0
#define WITHSHIFT	1

main()
{
	TRSF_PTR c1, c2, c3;
	TRSF_PTR h1, h2, h3;
	TRSF_PTR v1, v2, v3;
	TRSF_PTR f1, f2, f3;
	TRSF_PTR A, B, C, D, E, F, G, H;
	TRSF_PTR S, V, X;
	TRSF solve, check, tool, toolI, coord, coordI;

	POS *p, *p1, *p2;
	char pbuf[0x10000];

	c1 = allocTransXyz ("c1", UNDEF, 1.0, 0.0, 0.0);
	c2 = allocTransXyz ("c2", UNDEF, 0.0, 1.0, 0.0);
	c3 = allocTransXyz ("c3", UNDEF, 0.0, 0.0, 1.0);

	h1 = allocTransXyz ("h1", UNDEF, 2.0, 0.0, 0.0);
	h2 = allocTransXyz ("h2", UNDEF, 0.0, 2.0, 0.0);
	h3 = allocTransXyz ("h3", UNDEF, 0.0, 0.0, 2.0);

	v1 = allocTransXyz ("v1", UNDEF, 3.0, 0.0, 0.0);
	v2 = allocTransXyz ("v2", UNDEF, 0.0, 3.0, 0.0);
	v3 = allocTransXyz ("v3", UNDEF, 0.0, 0.0, 3.0);

	f1 = allocTransXyz ("f1", UNDEF, 4.0, 0.0, 0.0);
	f2 = allocTransXyz ("f2", UNDEF, 0.0, 4.0, 0.0);
	f3 = allocTransXyz ("f3", UNDEF, 0.0, 0.0, 4.0);

	setTransVarb (v1);
	setTransVarb (v2);
	setTransVarb (v3);

	setTransVarb (f1);
	setTransVarb (f2);
	setTransVarb (f3);

	CHECKerror (1, ESyntax, 
		    makePosition (NULL,T6,c1,TL,T6));
	clearErrors();
	CHECKerror (3, ESyntax,
		    makePosition (NULL,EQ,T6,c1,h1,TL,c1));
	clearErrors();
	CHECKerror (4, ESyntax,
		    makePosition (NULL,T6,c1,h1,EQ,TL,c1));
	clearErrors();
	CHECKerror (5, ESyntax,
		    makePosition (NULL,T6,c1,EQ,h1,T6,c2,TL,T6));
	clearErrors();
	CHECKerror (6, ESyntax,
		    makePosition (NULL,T6,c1,EQ,h1,c2,EQ,TL,T6));
	clearErrors();
	CHECKerror (7, ESyntax,
		    makePosition (NULL,T6,c1,EQ,c2,TL,h1));
	clearErrors();
	CHECKerror (8, ESyntax,
		    makePosition (NULL,T6,c1,EQ,h1,h2,TL,h1));
	clearErrors();
	CHECKerror (9, ESyntax,
		    makePosition (NULL,T6,EQ,h1,TL,h1));
	clearErrors();

	rcclSetOptions (RCCL_ERROR_EXIT);

	p = makePosition (NULL,
		T6,EQ,c1,TL,T6);
	CHECKposWithT6 (10, p, UNDEF, UNDEF,
		"T6 <TL> = c1");
	CHECKnumOptimizedTerms (11, p, 2, NOSHIFT);
	freePosition (p);

	p = makePosition (NULL,
		T6,c1,h1,h2,EQ,c2,c3,h3,TL,h1);
	CHECKposWithT6 (12, p, UNDEF, UNDEF,
		"T6 c1 h1 <TL> h2 = c2 c3 h3");
	CHECKnumOptimizedTerms (13, p, 3, NOSHIFT);
	freePosition (p);

	p = makePosition (NULL,
		c2,c3,h3,EQ,T6,c1,h1,h2,TL,h1);
	CHECKposWithT6 (14, p, UNDEF, UNDEF,
		"c2 c3 h3 = T6 c1 h1 <TL> h2");
	CHECKnumOptimizedTerms (15, p, 3, NOSHIFT);
	freePosition (p);

	p = makePosition (NULL,
		c3,h3,EQ,c2,c1,T6,h1,h2,TL,h1);
	CHECKposWithT6 (16, p, UNDEF, UNDEF,
		"c3 h3 = c2 c1 T6 h1 <TL> h2");
	CHECKnumOptimizedTerms (17, p, 3, NOSHIFT);
	freePosition (p);

	p = makePosition (NULL,
		c3,h3,c1,EQ,c2,c1,T6,h1,h2,TL,h3);
	CHECKposWithT6 (18, p, UNDEF, UNDEF,
		"c3 h3 <TL> c1 = c2 c1 T6 h1 h2");
	CHECKnumOptimizedTerms (19, p, 3, NOSHIFT);
	freePosition (p);

	p = makePosition (NULL,
		c2,c1,T6,h1,h2,EQ,c3,h3,c1,TL,h3);
	CHECKposWithT6 (20, p, UNDEF, UNDEF,
		"c2 c1 T6 h1 h2 = c3 h3 <TL> c1");
	CHECKnumOptimizedTerms (21, p, 3, NOSHIFT);
	freePosition (p);

	p = makePosition (NULL,
v1,T6,c1,h1,v2,c2,EQ,h1,f1,c1,h1,TL,h1);
	CHECKposWithT6 (22, p, UNDEF, UNDEF,
"v1 T6 c1 h1 <TL> v2 c2 = h1 f1 c1 h1");
	CHECKnumOptimizedTerms (23, p, 7, NOSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, NULL, 7);
	CHECKposWithT6 (24, (POS*)pbuf, 0, 1,
"v1 T6 (c1 h1) <TL> v2 = h1 f1 (c1 h1 c2*)");
	freePosition (p);

	p = makePosition (NULL,
T6,h1,v1,h2,EQ,c1,f1,c2,TL,h2);
	CHECKposWithT6 (25, p, UNDEF, UNDEF,
"T6 h1 v1 h2 <TL> = c1 f1 c2");
	CHECKnumOptimizedTerms (26, p, 7, NOSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, NULL, 7);
	CHECKposWithT6 (27, (POS*)pbuf, 1, 1,
"T6 h1 v1 h2 <TL> = c1 f1 c2");
	freePosition (p);

	p = makePosition (NULL,
T6,v1,h1,v2,EQ,f1,c1,f2,TL,v2);
	CHECKposWithT6 (28, p, UNDEF, UNDEF,
"T6 v1 h1 v2 <TL> = f1 c1 f2");
	CHECKnumOptimizedTerms (29, p, 7, NOSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, NULL, 7);
	CHECKposWithT6 (30, (POS*)pbuf, 1, 1,
"T6 v1 h1 v2 <TL> = f1 c1 f2");
	freePosition (p);

	p = makePosition (NULL,
f1,c1,h2,f2,EQ,T6,v1,h1,c2,c3,v2,TL,v2);
	CHECKposWithT6 (31, p, UNDEF, UNDEF,
"f1 c1 h2 f2 = T6 v1 h1 c2 c3 v2 <TL>");
	CHECKnumOptimizedTerms (32, p, 7, NOSHIFT);
	resetNameBuf();

	makeOptimizedPosition ((POS*)pbuf, p, NULL, 7);
	CHECKposWithT6 (33, (POS*)pbuf, 1, 1,
"f1 (c1 h2) f2 = T6 v1 (h1 c2 c3) v2 <TL>");
	freePosition (p);

	p = makePosition (NULL,
T6,c1,h1,v1,h2,EQ,c3,h3,c1,f1,c2,TL,h2);
	CHECKposWithT6 (34, p, UNDEF, UNDEF,
"T6 c1 h1 v1 h2 <TL> = c3 h3 c1 f1 c2");
	CHECKnumOptimizedTerms (35, p, 7, NOSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, NULL, 7);
	CHECKposWithT6 (36, (POS*)pbuf, 1, 1,
"T6 (c1 h1) v1 h2 <TL> = (c3 h3 c1) f1 c2");
	freePosition (p);

	p = makePosition (NULL,
T6,h1,v1,h2,c2,c3,EQ,c1,f1,c2,h1,TL,c3);
	CHECKposWithT6 (37, p, UNDEF, UNDEF,
"T6 h1 v1 h2 c2 c3 <TL> = c1 f1 c2 h1");
	CHECKnumOptimizedTerms (38, p, 7, NOSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, NULL, 7);
	CHECKposWithT6 (39, (POS*)pbuf, 1, 1,
"T6 h1 v1 (h2 c2 c3) <TL> = c1 f1 (c2 h1)");
	freePosition (p);

	p = makePosition (NULL,
T6,h1,h2,c2,c3,EQ,c1,f1,c2,h1,TL,c3);
	CHECKposWithT6 (40, p, UNDEF, UNDEF,
"T6 h1 h2 c2 c3 <TL> = c1 f1 c2 h1");
	CHECKnumOptimizedTerms (41, p, 5, NOSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, NULL, 5);
	CHECKposWithT6 (42, (POS*)pbuf, 0, 1,
"T6 (h1 h2 c2 c3) <TL> = c1 f1 (c2 h1)");
	freePosition (p);

	p = makePosition (NULL,
T6,h1,v1,h2,c2,c3,EQ,c1,c2,h1,TL,c3);
	CHECKposWithT6 (43, p, UNDEF, UNDEF,
"T6 h1 v1 h2 c2 c3 <TL> = c1 c2 h1");
	CHECKnumOptimizedTerms (44, p, 5, NOSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, NULL, 5);
	CHECKposWithT6 (45, (POS*)pbuf, 1, 0,
"T6 h1 v1 (h2 c2 c3) <TL> = (c1 c2 h1)");
	freePosition (p);

	A = allocTransRpy ("A", UNDEF, 1.0, 1.0, 1.0, 11.0, 0.0, 0.0);
	B = allocTransRpy ("B", UNDEF, 2.0, 2.0, 2.0, 0.0, 22.0, 0.0);
	C = allocTransRpy ("C", UNDEF, 3.0, 3.0, 3.0, 0.0, 0.0, 33.0);
	D = allocTransRpy ("D", UNDEF, 4.0, 4.0, 4.0, 1.0, 2.0, 3.0); 
	E = allocTransRpy ("E", UNDEF, 5.0, 5.0, 5.0, 10.0, 20.0, 30.0); 
	F = allocTransRpy ("F", UNDEF, 6.0, 6.0, 6.0, 40.0, 50.0, 60.0); 
	G = allocTransRpy ("G", UNDEF, 7.0, 7.0, 7.0, 70.0, 80.0, 90.0); 
	H = allocTransRpy ("H", UNDEF, 8.0, 8.0, 8.0, 1.0, 11.0, 111.0); 
	S = allocTransRpy ("S", UNDEF, 9.0, 8.0, 7.0, 5.0, 22.0, 5.0);
	V = allocTransRpy ("V", UNDEF, 11.0, 12.0, 13.0, 0.0, 78.0, 12.0);
	X = allocTransRpy ("X", UNDEF, 1.0, 2.0, 3.0, PI, 2*PI, 3*PI);
	setTransVarb (V);
	setTransVarb (X);

	p = makePosition (NULL, T6, A, B, EQ, C, TL, B);
	CHECKnumOptimizedTerms (46, p, 3, NOSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, NULL, 3);
	CHECKposWithT6 (47, (POS*)pbuf, 0, 0, "T6 (A B) <TL> = C");
	freePosition (p);

	p = makePosition (NULL, T6, A, EQ, C, B, TL, B);
	CHECKnumOptimizedTerms (48, p, 3, NOSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, NULL, 3);
	CHECKposWithT6 (49, (POS*)pbuf, 0, 0, "T6 (A B*) <TL> = C");
	freePosition (p);

	p = makePosition (NULL, B, C, T6, EQ, A, TL, B);
	CHECKnumOptimizedTerms (50, p, 3, NOSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, NULL, 3);
	CHECKposWithT6 (51, (POS*)pbuf, 0, 0, "C T6 = (B* A) <TL>");
	freePosition (p);

	p = makePosition (NULL, T6, EQ, C, B, A, TL, B);
	CHECKnumOptimizedTerms (52, p, 3, NOSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, NULL, 3);
	CHECKposWithT6 (53, (POS*)pbuf, 0, 0, "T6 = C (B A) <TL>");
	freePosition (p);

	p = makePosition (NULL, B, A, T6, EQ, C, TL, C);
	CHECKnumOptimizedTerms (54, p, 3, NOSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, NULL, 3);
	CHECKposWithT6 (55, (POS*)pbuf, 0, 0, "(B A) T6 = C <TL>");
	freePosition (p);

	p = makePosition (NULL, A, T6, C, EQ, B, TL, C);
	CHECKnumOptimizedTerms (56, p, 3, NOSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, NULL, 3);
	CHECKposWithT6 (57, (POS*)pbuf, 0, 0, "(B* A) T6 C <TL> =");
	freePosition (p);

	p = makePosition (NULL, T6, C, B, EQ, A, TL, C);
	CHECKnumOptimizedTerms (58, p, 3, NOSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, NULL, 3);
	CHECKposWithT6 (59, (POS*)pbuf, 0, 0, "T6 C <TL> = (A B*)");
	freePosition (p);

	p = makePosition (NULL, T6, C, EQ, A, B, TL, C);
	CHECKnumOptimizedTerms (60, p, 3, NOSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, NULL, 3);
	CHECKposWithT6 (61, (POS*)pbuf, 0, 0, "T6 C <TL> = (A B)");
	freePosition (p);

	p = makePosition (NULL, C, EQ, T6, A, B, TL, B);
	CHECKnumOptimizedTerms (62, p, 3, NOSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, NULL, 3);
	CHECKposWithT6 (63, (POS*)pbuf, 0, 0, "C = T6 (A B) <TL>");
	freePosition (p);

	p = makePosition (NULL, C, B, EQ, T6, A, TL, B);
	CHECKnumOptimizedTerms (64, p, 3, NOSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, NULL, 3);
	CHECKposWithT6 (65, (POS*)pbuf, 0, 0, "C = T6 (A B*) <TL>");
	freePosition (p);

	p = makePosition (NULL, A, EQ, B, C, T6, TL, B);
	CHECKnumOptimizedTerms (66, p, 3, NOSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, NULL, 3);
	CHECKposWithT6 (67, (POS*)pbuf, 0, 0, "(B* A) <TL> = C T6");
	freePosition (p);

	p = makePosition (NULL, C, B, A, EQ, T6, TL, B);
	CHECKnumOptimizedTerms (68, p, 3, NOSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, NULL, 3);
	CHECKposWithT6 (69, (POS*)pbuf, 0, 0, "C (B A) <TL> = T6");
	freePosition (p);

	p = makePosition (NULL, C, EQ, B, A, T6, TL, C);
	CHECKnumOptimizedTerms (70, p, 3, NOSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, NULL, 3);
	CHECKposWithT6 (71, (POS*)pbuf, 0, 0, "C <TL> = (B A) T6");
	freePosition (p);

	p = makePosition (NULL, B, EQ, A, T6, C, TL, C);
	CHECKnumOptimizedTerms (72, p, 3, NOSHIFT);
	resetNameBuf();	
	makeOptimizedPosition ((POS*)pbuf, p, NULL, 3);
	CHECKposWithT6 (73, (POS*)pbuf, 0, 0, "= (B* A) T6 C <TL>");
	freePosition (p);

	p = makePosition (NULL, A, EQ, T6, C, B, TL, C);
	CHECKnumOptimizedTerms (74, p, 3, NOSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, NULL, 3);
	CHECKposWithT6 (75, (POS*)pbuf, 0, 0, "(A B*) = T6 C <TL>");
	freePosition (p);

	p = makePosition (NULL, A, B, EQ, T6, C, TL, C);
	CHECKnumOptimizedTerms (76, p, 3, NOSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, NULL, 3);
	CHECKposWithT6 (77, (POS*)pbuf, 0, 0, "(A B) = T6 C <TL>");
	freePosition (p);

	/* Now test out making positions, with or without T6, and
	   solving them */

	p = makePosition (NULL, A, B, EQ, C, D, NULL);
	CHECKt6AndToolPtrs (78, p, NULL, NULL);

	rcclClearOptions (RCCL_ERROR_EXIT);

	CHECKerror (79, ERange, 
			solveTrans (&solve, p, E, NULL));
	clearErrors();
	CHECKerror (80, ERange, 
			solveChain (&solve, p, E, A, NULL));
	clearErrors();
	CHECKerror (81, ERange, 
			solveChain (&solve, p, A, E, NULL));
	clearErrors();
	CHECKerror (82, ERange, 
			solveInvChain (&solve, p, E, A, NULL));
	clearErrors();
	CHECKerror (83, ERange, 
			solveInvChain (&solve, p, A, E, NULL));
	clearErrors();

	rcclSetOptions (RCCL_ERROR_EXIT);
	solveTrans (&solve, p, A, NULL);
	CHECKsolve (84, &solve, "C D B*");
	solveTrans (&solve, p, B, NULL);
	CHECKsolve (85, &solve, "A* C D");
	solveTrans (&solve, p, C, NULL);
	CHECKsolve (86, &solve, "A B D*");
	solveTrans (&solve, p, D, NULL);
	CHECKsolve (87, &solve, "C* A B");

	solveChain (&solve, p, A, A, NULL);
	CHECKsolve (88, &solve, "A");
	solveChain (&solve, p, A, B, NULL);
	CHECKsolve (89, &solve, "A B");
	solveChain (&solve, p, A, D, NULL);
	CHECKsolve (90, &solve, "A B D*");
	solveChain (&solve, p, A, C, NULL);
	CHECKsolve (91, &solve, "A B D* C*");

	solveChain (&solve, p, C, C, NULL);
	CHECKsolve (92, &solve, "C*");
	solveChain (&solve, p, C, A, NULL);
	CHECKsolve (93, &solve, "C* A");
	solveChain (&solve, p, C, B, NULL);
	CHECKsolve (94, &solve, "C* A B");
	solveChain (&solve, p, C, D, NULL);
	CHECKsolve (95, &solve, "C* A B D*");

	solveInvChain (&solve, p, A, A, NULL);
	CHECKsolve (96, &solve, "A*");
	solveInvChain (&solve, p, A, B, NULL);
	CHECKsolve (97, &solve, "A* C D B*");
	solveInvChain (&solve, p, A, D, NULL);
	CHECKsolve (98, &solve, "A* C D");
	solveInvChain (&solve, p, A, C, NULL);
	CHECKsolve (99, &solve, "A* C");

	solveInvChain (&solve, p, C, C, NULL);
	CHECKsolve (100, &solve, "C");
	solveInvChain (&solve, p, C, A, NULL);
	CHECKsolve (101, &solve, "C D B* A*");
	solveInvChain (&solve, p, C, B, NULL);
	CHECKsolve (102, &solve, "C D B*");
	solveInvChain (&solve, p, C, D, NULL);
	CHECKsolve (103, &solve, "C D");

	freePosition (p);

	p = makePosition (NULL, A, T6, B, EQ, C, D, NULL);
	CHECKt6AndToolPtrs (104, p, T6, T6);
	freePosition (p);
	p = makePosition (NULL, A, T6, B, EQ, C, D, TL, NULL);
	CHECKt6AndToolPtrs (105, p, T6, T6);
	freePosition (p);
	p = makePosition (NULL, A, T6, B, EQ, C, D, TL, T6);
	CHECKt6AndToolPtrs (106, p, T6, T6);

	rcclClearOptions (RCCL_ERROR_EXIT);

	CHECKerror (107, EBadArg, 
			 solveTrans (&solve, p, A, NULL));
	clearErrors();
	CHECKerror (108, EBadArg, 
			solveChain (&solve, p, A, B, NULL));
	clearErrors();
	CHECKerror (109, EBadArg, 
			solveChain (&solve, p, C, D, NULL));
	clearErrors();
	CHECKerror (110, EBadArg, 
			solveInvChain (&solve, p, B, A, NULL));
	clearErrors();
	CHECKerror (111, EBadArg, 
			solveInvChain (&solve, p, D, C, NULL));
	clearErrors();

	rcclSetOptions (RCCL_ERROR_EXIT);

	solveTrans (&solve, p, A, E);
	CHECKsolve (112, &solve, "C D B* E*");
	solveTrans (&solve, p, B, E);
	CHECKsolve (113, &solve, "E* A* C D");
	solveTrans (&solve, p, C, E);
	CHECKsolve (114, &solve, "A E B D*");
	solveTrans (&solve, p, D, E);
	CHECKsolve (115, &solve, "C* A E B");
	solveTrans (&solve, p, T6, NULL);
	CHECKsolve (116, &solve, "A* C D B*");

	solveChain (&solve, p, A, A, NULL);
	CHECKsolve (117, &solve, "A");
	solveChain (&solve, p, A, T6, E);
	CHECKsolve (118, &solve, "A E");
	solveChain (&solve, p, A, D, E);
	CHECKsolve (119, &solve, "A E B D*");
	solveChain (&solve, p, A, C, E);
	CHECKsolve (120, &solve, "A E B D* C*");

	solveChain (&solve, p, C, C, NULL);
	CHECKsolve (121, &solve, "C*");
	solveChain (&solve, p, C, A, NULL);
	CHECKsolve (122, &solve, "C* A");
	solveChain (&solve, p, C, B, E);
	CHECKsolve (123, &solve, "C* A E B");
	solveChain (&solve, p, C, D, E);
	CHECKsolve (124, &solve, "C* A E B D*");

	solveInvChain (&solve, p, A, A, NULL);
	CHECKsolve (125, &solve, "A*");
	solveInvChain (&solve, p, A, B, NULL);
	CHECKsolve (126, &solve, "A* C D B*");
	solveInvChain (&solve, p, A, D, NULL);
	CHECKsolve (127, &solve, "A* C D");
	solveInvChain (&solve, p, A, C, NULL);
	CHECKsolve (128, &solve, "A* C");
	solveInvChain (&solve, p, A, T6, E);
	CHECKsolve (129, &solve, "A* C D B* E*");

	solveInvChain (&solve, p, C, C, NULL);
	CHECKsolve (130, &solve, "C");
	solveInvChain (&solve, p, C, A, E);
	CHECKsolve (131, &solve, "C D B* E* A*");
	solveInvChain (&solve, p, C, B, NULL);
	CHECKsolve (132, &solve, "C D B*");
	solveInvChain (&solve, p, C, D, NULL);
	CHECKsolve (133, &solve, "C D");

	freePosition(p);

	p = makePosition (NULL, C, D, EQ, A, T6, B, NULL);
	CHECKt6AndToolPtrs (134, p, T6, T6);

	solveTrans (&solve, p, A, E);
	CHECKsolve (135, &solve, "C D B* E*");
	solveTrans (&solve, p, B, E);
	CHECKsolve (136, &solve, "E* A* C D");
	solveTrans (&solve, p, C, E);
	CHECKsolve (137, &solve, "A E B D*");
	solveTrans (&solve, p, D, E);
	CHECKsolve (138, &solve, "C* A E B");
	solveTrans (&solve, p, T6, NULL);
	CHECKsolve (139, &solve, "A* C D B*");

	solveChain (&solve, p, A, A, NULL);
	CHECKsolve (140, &solve, "A*");
	solveChain (&solve, p, A, T6, E);
	CHECKsolve (141, &solve, "A* C D B* E*");
	solveChain (&solve, p, A, D, NULL);
	CHECKsolve (142, &solve, "A* C D");
	solveChain (&solve, p, A, C, NULL);
	CHECKsolve (143, &solve, "A* C");

	solveChain (&solve, p, C, C, NULL);
	CHECKsolve (144, &solve, "C");
	solveChain (&solve, p, C, A, E);
	CHECKsolve (145, &solve, "C D B* E* A*");
	solveChain (&solve, p, C, B, NULL);
	CHECKsolve (146, &solve, "C D B*");
	solveChain (&solve, p, C, D, NULL);
	CHECKsolve (147, &solve, "C D");

	solveInvChain (&solve, p, A, A, NULL);
	CHECKsolve (148, &solve, "A");
	solveInvChain (&solve, p, A, B, E);
	CHECKsolve (149, &solve, "A E B");
	solveInvChain (&solve, p, A, D, E);
	CHECKsolve (150, &solve, "A E B D*");
	solveInvChain (&solve, p, A, C, E);
	CHECKsolve (151, &solve, "A E B D* C*");
	solveInvChain (&solve, p, A, T6, E);
	CHECKsolve (152, &solve, "A E");

	solveInvChain (&solve, p, C, C, NULL);
	CHECKsolve (153, &solve, "C*");
	solveInvChain (&solve, p, C, A, NULL);
	CHECKsolve (154, &solve, "C* A");
	solveInvChain (&solve, p, C, B, E);
	CHECKsolve (155, &solve, "C* A E B");
	solveInvChain (&solve, p, C, D, E);
	CHECKsolve (156, &solve, "C* A E B D*");

	p = makePosition (NULL, T6, EQ, A, NULL);
	solveToolR (&tool, p, 0);
	solveToolInvR (&toolI, p, 0);
	solveCoordR (&coord, p, 0);
	solveCoordInvR (&coordI, p, 0);
	solveT6U (&solve, p);
	CHECKsolve (157, &tool, "");
	CHECKsolve (158, &toolI, "");
	CHECKsolve (159, &coord, "A");
	CHECKsolve (160, &coordI, "A*");
	CHECKsolve (161, &solve, "A");
	freePosition (p);

	p = makePosition (NULL, T6, A, EQ, B, TL, A);
	solveToolR (&tool, p, 0);
	solveToolInvR (&toolI, p, 0);
	solveCoordR (&coord, p, 0);
	solveCoordInvR (&coordI, p, 0);
	solveT6U (&solve, p);
	CHECKsolve (162, &tool, "A");
	CHECKsolve (163, &toolI, "A*");
	CHECKsolve (164, &coord, "B");
	CHECKsolve (165, &coordI, "B*");
	CHECKsolve (166, &solve, "B A*");
	freePosition (p);
	
	p = makePosition (NULL, T6, A, EQ, C, B, TL, B);
	solveToolR (&tool, p, 0);
	solveToolInvR (&toolI, p, 0);
	solveCoordR (&coord, p, 0);
	solveCoordInvR (&coordI, p, 0);
	solveT6U (&solve, p);
	CHECKsolve (167, &tool, "A B*");
	CHECKsolve (168, &toolI, "B A*");
	CHECKsolve (169, &coord, "C");
	CHECKsolve (170, &coordI, "C*");
	CHECKsolve (171, &solve, "C B A*");
	freePosition (p);
	
	p = makePosition (NULL, D, T6, A, B, EQ, C, TL, B);
	solveToolR (&tool, p, 0);
	solveToolInvR (&toolI, p, 0);
	solveCoordR (&coord, p, 0);
	solveCoordInvR (&coordI, p, 0);
	solveT6U (&solve, p);
	CHECKsolve (172, &tool, "A B");
	CHECKsolve (173, &toolI, "B* A*");
	CHECKsolve (174, &coord, "D* C");
	CHECKsolve (175, &coordI, "C* D");
	CHECKsolve (176, &solve, "D* C B* A*");
	freePosition (p);
	
	p = makePosition (NULL, B, T6, EQ, A, TL, A);
	solveToolR (&tool, p, 0);
	solveToolInvR (&toolI, p, 0);
	solveCoordR (&coord, p, 0);
	solveCoordInvR (&coordI, p, 0);
	solveT6U (&solve, p);
	CHECKsolve (177, &tool, "A*");
	CHECKsolve (178, &toolI, "A");
	CHECKsolve (179, &coord, "B*");
	CHECKsolve (180, &coordI, "B");
	CHECKsolve (181, &solve, "B* A");
	freePosition (p);
	
	p = makePosition (NULL, F, D, T6, A, EQ, G, C, B, TL, C);
	solveToolR (&tool, p, 0);
	solveToolInvR (&toolI, p, 0);
	solveCoordR (&coord, p, 0);
	solveCoordInvR (&coordI, p, 0);
	solveT6U (&solve, p);
	CHECKsolve (182, &tool, "A B* C*");
	CHECKsolve (183, &toolI, "C B A*");
	CHECKsolve (184, &coord, "D* F* G");
	CHECKsolve (185, &coordI, "G* F D");
	CHECKsolve (186, &solve, "D* F* G C B A*");
	freePosition (p);
	
	p = makePosition (NULL, F, T6, A, EQ, D, C, B, TL, T6);
	solveToolR (&tool, p, 0);
	solveToolInvR (&toolI, p, 0);
	solveCoordR (&coord, p, 0);
	solveCoordInvR (&coordI, p, 0);
	solveT6U (&solve, p);
	CHECKsolve (187, &tool, "");
	CHECKsolve (188, &toolI, "");
	CHECKsolve (189, &coord, "F* D C B A*");
	CHECKsolve (190, &coordI, "A B* C* D* F");
	CHECKsolve (191, &solve, "F* D C B A*");
	freePosition (p);
	
	p = makePosition (NULL, F, G, T6, A, EQ, D, C, B, TL, F);
	solveToolR (&tool, p, 0);
	solveToolInvR (&toolI, p, 0);
	solveCoordR (&coord, p, 0);
	solveCoordInvR (&coordI, p, 0);
	solveT6U (&solve, p);
	CHECKsolve (192, &tool, "A B* C* D* F");
	CHECKsolve (193, &toolI, "F* D C B A*");
	CHECKsolve (194, &coord, "G*");
	CHECKsolve (195, &coordI, "G");
	CHECKsolve (196, &solve, "G* F* D C B A*");
	freePosition (p);	

	p = makePosition (NULL, A, EQ, T6, NULL);
	solveToolR (&tool, p, 0);
	solveToolInvR (&toolI, p, 0);
	solveCoordR (&coord, p, 0);
	solveCoordInvR (&coordI, p, 0);
	solveT6U (&solve, p);
	CHECKsolve (197, &tool, "");
	CHECKsolve (198, &toolI, "");
	CHECKsolve (199, &coord, "A");
	CHECKsolve (200, &coordI, "A*");
	CHECKsolve (201, &solve, "A");
	freePosition (p);

	hook();
	p = makePosition (NULL, B, EQ, T6, A, TL, A);
	solveToolR (&tool, p, 0);
	solveToolInvR (&toolI, p, 0);
	solveCoordR (&coord, p, 0);
	solveCoordInvR (&coordI, p, 0);
	solveT6U (&solve, p);
	CHECKsolve (202, &tool, "A");
	CHECKsolve (203, &toolI, "A*");
	CHECKsolve (204, &coord, "B");
	CHECKsolve (205, &coordI, "B*");
	CHECKsolve (206, &solve, "B A*");
	freePosition (p);
	
	p = makePosition (NULL, C, B, EQ, T6, A, TL, B);
	solveToolR (&tool, p, 0);
	solveToolInvR (&toolI, p, 0);
	solveCoordR (&coord, p, 0);
	solveCoordInvR (&coordI, p, 0);
	solveT6U (&solve, p);
	CHECKsolve (207, &tool, "A B*");
	CHECKsolve (208, &toolI, "B A*");
	CHECKsolve (209, &coord, "C");
	CHECKsolve (210, &coordI, "C*");
	CHECKsolve (211, &solve, "C B A*");
	freePosition (p);
	
	p = makePosition (NULL, C, EQ, D, T6, A, B, TL, B);
	solveToolR (&tool, p, 0);
	solveToolInvR (&toolI, p, 0);
	solveCoordR (&coord, p, 0);
	solveCoordInvR (&coordI, p, 0);
	solveT6U (&solve, p);
	CHECKsolve (212, &tool, "A B");
	CHECKsolve (213, &toolI, "B* A*");
	CHECKsolve (214, &coord, "D* C");
	CHECKsolve (215, &coordI, "C* D");
	CHECKsolve (216, &solve, "D* C B* A*");
	freePosition (p);
	
	p = makePosition (NULL, A, EQ, B, T6, TL, A);
	solveToolR (&tool, p, 0);
	solveToolInvR (&toolI, p, 0);
	solveCoordR (&coord, p, 0);
	solveCoordInvR (&coordI, p, 0);
	solveT6U (&solve, p);
	CHECKsolve (217, &tool, "A*");
	CHECKsolve (218, &toolI, "A");
	CHECKsolve (219, &coord, "B*");
	CHECKsolve (220, &coordI, "B");
	CHECKsolve (221, &solve, "B* A");
	freePosition (p);
	
	p = makePosition (NULL, G, C, B, EQ, F, D, T6, A, TL, C);
	solveToolR (&tool, p, 0);
	solveToolInvR (&toolI, p, 0);
	solveCoordR (&coord, p, 0);
	solveCoordInvR (&coordI, p, 0);
	solveT6U (&solve, p);
	CHECKsolve (222, &tool, "A B* C*");
	CHECKsolve (223, &toolI, "C B A*");
	CHECKsolve (224, &coord, "D* F* G");
	CHECKsolve (225, &coordI, "G* F D");
	CHECKsolve (226, &solve, "D* F* G C B A*");
	freePosition (p);
	
	p = makePosition (NULL, D, C, B, EQ, F, T6, A, TL, T6);
	solveToolR (&tool, p, 0);
	solveToolInvR (&toolI, p, 0);
	solveCoordR (&coord, p, 0);
	solveCoordInvR (&coordI, p, 0);
	solveT6U (&solve, p);
	CHECKsolve (227, &tool, "");
	CHECKsolve (228, &toolI, "");
	CHECKsolve (229, &coord, "F* D C B A*");
	CHECKsolve (230, &coordI, "A B* C* D* F");
	CHECKsolve (231, &solve, "F* D C B A*");
	freePosition (p);
	
	p = makePosition (NULL, D, C, B, EQ, F, G, T6, A, TL, F);
	solveToolR (&tool, p, 0);
	solveToolInvR (&toolI, p, 0);
	solveCoordR (&coord, p, 0);
	solveCoordInvR (&coordI, p, 0);
	solveT6U (&solve, p);
	CHECKsolve (232, &tool, "A B* C* D* F");
	CHECKsolve (233, &toolI, "F* D C B A*");
	CHECKsolve (234, &coord, "G*");
	CHECKsolve (235, &coordI, "G");
	CHECKsolve (236, &solve, "G* F* D C B A*");
	freePosition (p);	

	p = makePosition (NULL, T6, EQ, A, NULL);
	CHECKnumOptimizedTerms (237, p, 2, WITHSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, S, 2);
	CHECKposWithT6 (238, (POS*)pbuf, 0, 0, "T6 <TL> = (A shift)");
	solveToolR (&tool, (POS*)pbuf, 0);
	solveCoordR (&coord, (POS*)pbuf, 0);
	CHECKsolve (239, &tool, "");
	CHECKsolve (240, &coord, "A S");
	freePosition (p);

	p = makePosition (NULL, T6, EQ, V, NULL);
	CHECKnumOptimizedTerms (241, p, 3, WITHSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, S, 3);
	CHECKposWithT6 (242, (POS*)pbuf, 0, 1, "T6 <TL> = V shift");
	solveToolR (&tool, (POS*)pbuf, 0);
	solveCoordR (&coord, (POS*)pbuf, 0);
	CHECKsolve (243, &tool, "");
	CHECKsolve (244, &coord, "V S");
	freePosition (p);

	p = makePosition (NULL, T6, A, B, EQ, C, TL, A);
	CHECKnumOptimizedTerms (245, p, 3, WITHSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, S, 3);
	CHECKposWithT6 (246, (POS*)pbuf, 0, 0, "T6 A <TL> = (C B* shift)");
	solveToolR (&tool, (POS*)pbuf, 0);
	solveCoordR (&coord, (POS*)pbuf, 0);
	CHECKsolve (247, &tool, "A");
	CHECKsolve (248, &coord, "C B* S");
	freePosition (p);

	p = makePosition (NULL, T6, A, B, EQ, V, TL, A);
	CHECKnumOptimizedTerms (249, p, 4, WITHSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, S, 4);
	CHECKposWithT6 (250, (POS*)pbuf, 0, 1, "T6 A <TL> (shift* B) = V");
	solveToolR (&tool, (POS*)pbuf, 0);
	solveCoordR (&coord, (POS*)pbuf, 0);
	CHECKsolve (251, &tool, "A");
	CHECKsolve (252, &coord, "V B* S");
	freePosition (p);

	p = makePosition (NULL, T6, A, V, EQ, X, TL, A);
	CHECKnumOptimizedTerms (253, p, 5, WITHSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, S, 5);
	CHECKposWithT6 (254, (POS*)pbuf, 0, 1, "T6 A <TL> shift* V = X");
	solveToolR (&tool, (POS*)pbuf, 0);
	solveCoordR (&coord, (POS*)pbuf, 0);
	CHECKsolve (255, &tool, "A");
	CHECKsolve (256, &coord, "X V* S");
	freePosition (p);

	p = makePosition (NULL, A, EQ, T6, NULL);
	CHECKnumOptimizedTerms (257, p, 2, WITHSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, S, 2);
	CHECKposWithT6 (258, (POS*)pbuf, 0, 0, "(A shift) = T6 <TL>");
	solveToolR (&tool, (POS*)pbuf, 0);
	solveCoordR (&coord, (POS*)pbuf, 0);
	CHECKsolve (259, &tool, "");
	CHECKsolve (260, &coord, "A S");
	freePosition (p);

	p = makePosition (NULL, V, EQ, T6, NULL);
	CHECKnumOptimizedTerms (261, p, 3, WITHSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, S, 3);
	CHECKposWithT6 (262, (POS*)pbuf, 0, 1, "V shift = T6 <TL>");
	solveToolR (&tool, (POS*)pbuf, 0);
	solveCoordR (&coord, (POS*)pbuf, 0);
	CHECKsolve (263, &tool, "");
	CHECKsolve (264, &coord, "V S");
	freePosition (p);

	p = makePosition (NULL, C, EQ, T6, A, B, TL, A);
	CHECKnumOptimizedTerms (265, p, 3, WITHSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, S, 3);
	CHECKposWithT6 (266, (POS*)pbuf, 0, 0, "(C B* shift) = T6 A <TL>");
	solveToolR (&tool, (POS*)pbuf, 0);
	solveCoordR (&coord, (POS*)pbuf, 0);
	CHECKsolve (267, &tool, "A");
	CHECKsolve (268, &coord, "C B* S");
	freePosition (p);

	p = makePosition (NULL, V, EQ, T6, A, B, TL, A);
	CHECKnumOptimizedTerms (269, p, 4, WITHSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, S, 4);
	CHECKposWithT6 (270, (POS*)pbuf, 0, 1, "V = T6 A <TL> (shift* B)");
	solveToolR (&tool, (POS*)pbuf, 0);
	solveCoordR (&coord, (POS*)pbuf, 0);
	CHECKsolve (271, &tool, "A");
	CHECKsolve (272, &coord, "V B* S");
	freePosition (p);

	p = makePosition (NULL, X, EQ, T6, A, V, TL, A);
	CHECKnumOptimizedTerms (273, p, 5, WITHSHIFT);
	resetNameBuf();
	makeOptimizedPosition ((POS*)pbuf, p, S, 5);
	CHECKposWithT6 (274, (POS*)pbuf, 0, 1, "X = T6 A <TL> shift* V");
	solveToolR (&tool, (POS*)pbuf, 0);
	solveCoordR (&coord, (POS*)pbuf, 0);
	CHECKsolve (275, &tool, "A");
	CHECKsolve (276, &coord, "X V* S");
	freePosition (p);

	/* finish by checking the location of the tool */

	p = makePosition (NULL, A, T6, B, A, A, EQ, A, TL, A);
	CHECKposWithT6 (277, p, UNDEF, UNDEF, "A T6 B A <TL> A = A");
	solveToolR (&tool, p, 0);
	solveCoordR (&coord, p, 0);
	CHECKsolve (278, &tool, "B A");
	CHECKsolve (279, &coord, "A*");
	freePosition (p);

	p = makePosition (NULL, A, EQ, A, T6, B, A, A, TL, A);
	CHECKposWithT6 (280, p, UNDEF, UNDEF, "A = A T6 B A <TL> A");
	solveToolR (&tool, p, 0);
	solveCoordR (&coord, p, 0);
	CHECKsolve (281, &tool, "B A");
	CHECKsolve (282, &coord, "A*");
	freePosition (p);

	printf ("\nROUTINES OK\n\n");
}

CHECKerror (mark, code, p)
int mark;
int code;
POS *p;
{
	if (p != NULL || code != getErrorCode(0))
	 { printf ("(%d) error %d not reported\n", mark, code);
	   exit (-1);
	 }
}

CHECKnumOptimizedTerms (mark, p, num, shiftSet)
int mark;
POS *p;
int num;
int shiftSet;
{
	if (num != numOptimizedTerms(p, shiftSet))
	 { printf ("(%d) numOptimizedTerms = %d vs. %d\n",
		   mark, numOptimizedTerms(p, 0), num);
	   exit (-1);
	 }
}

char *malloc();
char *strcpy();

char *copyStr(s)
{
	return (strcpy (malloc (strlen(s)+1), s));
}

CHECKposWithT6 (mark, p, toolfn, coordfn, eqn)
int mark;
POS *p;
int toolfn, coordfn;
char *eqn;
{
	POS_TERM *t;
	POS_TERM *start;
	POS_TERM *rhs;
	char numTerms;
	char *nameList[32];
	char *toolName;
	int k;
	int eqIndex;
	char *eqncpy;

	eqncpy = copyStr(eqn);

	numTerms = parsePositionName (nameList, &toolName, &eqIndex, eqncpy);

	k = 0;
	for (t = p->startTerm; t->leftSide; t = t->next)
	 { if (cmpName (t, nameList[k++]) != 0)
	    { printf ("(%d) --\n", mark);
	      printPosition (p, /*values=*/0);
	      printf ("%s\n", eqncpy);
	      exit (-1);
	    }
	   if (t->next == p->startTerm)
	    { break;
	    }
	 }
	if (k != eqIndex)
	 { printf ("(%d) -- = sign misplaced\n", mark);
	   printPosition (p, /*values=*/0);
	   printf ("%s\n", eqncpy);
	   exit (-1);
	 }
	for (t = p->startTerm->prev; !t->leftSide; t = t->prev)
	 { if (cmpName (t, nameList[k++]) != 0)
	    { printf ("(%d) --\n", mark);
	      printPosition (p, /*values=*/0);
	      printf ("%s\n", eqncpy);
	      exit (-1);
	    }
	   if (t == p->startTerm)
	    { break;
	    }
	 }
	if (cmpName (p->toolTerm, toolName) != 0)
	 { printf ("(%d) -- tool terms differ\n", mark);
	   exit (-1);
	 }
	if (p->toolfn != toolfn || p->coordfn != coordfn)
	 { printf ("(%d) -- toolfn = %d vs. %d, coordfn = %d vs. %d\n",
		    mark, p->toolfn, toolfn, p->coordfn, coordfn);
	   exit (-1);
	 }
	free (eqncpy);
}

#define EPSILON 	1e-6

CHECKsolve (mark, result, str)
int mark;
TRSF *result;
char *str;
{
	TRSF check;
	TRSF *trsf;
	char *cp;
	char name[2];

	name[1] = '\0';

	cp = str;
	identTrsf (&check);
	while (*cp != '\0')
	 { if (!isspace (*cp))
	    { name[0] = *cp;
	      trsf = getTransByName (name);
	      if (cp[1] == '*')
	       { multRiTrsf (&check, &check, trsf);
		 cp++;
	       }
	      else
	       { multTrsf (&check, &check, trsf);
	       }
	    }	   
	   cp++;
	 }
	if (cmpTrsf (&check, result) > EPSILON)
	 { printf ("(%d) pos equation does not check:\n", mark);
	   printTrsf ("RESULT = %m\n", result);
	   printTrsf ("CHECK  = %m\n", &check);
	   exit (-1);
	 }
}

CHECKt6AndToolPtrs (mark, p, t6, tool)
int mark;
POS *p;
TRSF *t6;
TRSF *tool;
{
	if (t6)
	 { if (p->t6Term->trsf != t6)
	    { printf ("(%d) T6 = 0x%x vs. 0x%x\n", mark,
		       p->t6Term->trsf, t6);
	      exit (-1);
	    }
	 }
	else
	 { if (p->t6Term)
	    { printf ("(%d) T6 != NULL\n", mark);
	      exit (-1);
	    }
	 }
	if (tool)
	 { if (p->toolTerm->trsf != tool)
	    { printf ("(%d) TOOL = 0x%x vs. 0x%x\n", mark,
		       p->toolTerm->trsf, tool);
	      exit (-1);
	    }
	 }
	else
	 { if (p->toolTerm)
	    { printf ("(%d) TOOL != NULL\n", mark);
	      exit (-1);
	    }
	 }
}


cmpName (t, n)
POS_TERM *t;
char *n;
{
	if (TRSF_GETDESC(t->trsf)->source == TRSF_GETDESC(T6))
	 { if (strcmp ("T6", n) != 0)
	    { return (1);
	    }
	 }
	else if (TRSF_GETDESC(t->trsf)->name == NULL)
	 { if (strcmp ("TEMP", n) != 0)
	    { return (1);
	    }
	 }
	else
	 { if (strcmp (TRSF_GETDESC(t->trsf)->name, n) != 0)
	    { return (1);
	    }
	 }	
	return (0);
}

parsePositionName (nl, tool, eqIndex, eqn)
char **nl;
char **tool;
int *eqIndex;
char *eqn;
{
	char *cp;
	char *nameStart;
	char *nameEnd;
	int bracketed;
	int numTerms;

	numTerms = 0;
	*tool = NULL;

	nameStart = NULL;
	nameEnd = NULL;
	cp = eqn;
	do
	 { if (!isspace(*cp) && *cp != '\0')
	    { if (!nameStart)
	       { nameStart = cp;
		 bracketed = (*cp == '(');
	       }
	      else
	       { if (bracketed && *cp == ')')
		  { nameEnd = cp+1;
		  }
	       }
	    }
	   else
	    { if (nameStart)
	       { if (!bracketed)
		  { nameEnd = cp;
		  }
	       }
	    }
	   if (nameStart && nameEnd)
	    { char savec;
	      savec = *nameEnd;
	      *nameEnd = '\0';
	      if (strcmp (nameStart, "<TL>") == 0)
	       { if (*tool)
		  { fatalMsg (-1, "parsePositionName() -- tool given twice\n");
		  }
		 else
		  { *tool = copyStr (nl[numTerms-1]);
		  }
	       }
	      else if (strcmp (nameStart, "=") == 0)
	       { *eqIndex = numTerms;
	       }
	      else
	       { nl[numTerms++] = copyStr (nameStart);
	       }
	      *nameEnd = savec;
	      nameStart = nameEnd = NULL;
	    }
	   if (*cp == '\0')
	    { break;
	    }
	   else
	    { cp++;
	    }
	 }
	while (1);
	return (numTerms);
}

hook()
{
}
