예제 #1
0
파일: pcarith.c 프로젝트: robocopone/nq-bg
void	WordPrint( word gs )
{
   if ( gs->g != EOW ) {
      if ( gs->g > 0 ) {
         PrintGen( gs->g );
         if ( gs->e > (exp)1 ) 
#ifdef LONGLONG
            printf( "^%Ld", gs->e );
#else
            printf( "^%d", gs->e );
#endif
      }
      else {
         PrintGen( -gs->g );
#ifdef LONGLONG
         printf( "^-%Ld", gs->e );
#else
         printf( "^-%d", gs->e );
#endif
      }
   }
   else {
      printf( "1" );
      return;
   }

   gs++;
    
   while ( gs->g != EOW ) {
      putchar( '*' );
      if ( gs->g > 0 ) {
         PrintGen( gs->g );
         if ( gs->e > (exp)1 )
#ifdef LONGLONG
            printf( "^%Ld", gs->e );
#else
            printf( "^%d", gs->e );
#endif
      }
      else {
         PrintGen( -gs->g );
#ifdef LONGLONG
         printf( "^-%Ld", gs->e );
#else
         printf( "^-%d", gs->e );
#endif
      }
      gs++;
   }
}
예제 #2
0
/*
**    PrintNode() just looks at the type of a node and then calls the
**    appropriate print function.
*/
void    PrintNode(node *n) {
	switch (n->type) {
	case TNUM:
	{ PrintNum(n->cont.n); break; }
	case TGEN:
	{ PrintGen(n->cont.g); break; }
	case TMULT:
	{ PrintMult(n->cont.op.l, n->cont.op.r); break; }
	case TPOW:
	{ PrintPow(n->cont.op.l, n->cont.op.r); break; }
	case TCONJ:
	{ PrintConj(n->cont.op.l, n->cont.op.r); break; }
	case TCOMM:
	{ PrintComm(n->cont.op.l, n->cont.op.r, 1); break; }
	case TREL:
	{ PrintRel(n->cont.op.l, n->cont.op.r); break; }
	case TDRELL:
	{ PrintDRelL(n->cont.op.l, n->cont.op.r); break; }
	case TDRELR:
	{ PrintDRelR(n->cont.op.l, n->cont.op.r); break; }
	case TENGEL: {
		PrintEngel(n->cont.op.l, n->cont.op.r,
		           n->cont.op.e);
		break;
	}
	default:
	{ fprintf(OutFp, "\nunknown node type\n"); exit(5); }
	}
}
예제 #3
0
/*
**    PrintPresentation() prints the presentation stored in the global
**    variable Pres.
*/
void    PrintPresentation(FILE *fp) {
	gen     g;
	int     r;

	InitPrint(fp);

	if (Pres.nragens == 0) return;

	/* Open the presentation. */
	fprintf(OutFp, "< ");

	/* Print the generators first. */
	PrintGen(1);
	for (g = 2; g <= (gen)Pres.nragens; g++) {
		fprintf(OutFp, ", ");
		PrintGen(g);
	}

	if (Pres.nrigens > 0) {
		fprintf(OutFp, "; ");
		PrintGen(Pres.nragens + 1);
		for (g = Pres.nragens + 2; g <= (gen)(Pres.nragens + Pres.nrigens); g++) {
			fprintf(OutFp, ", ");
			PrintGen(g);
		}
	}

	/* Now the delimiter. */
	fprintf(OutFp, " |\n");

	/* Now the relations. */
	if (Pres.rels[0] != (node *)0) {
		fprintf(OutFp, "    ");
		PrintNode(Pres.rels[0]);
	}
	for (r = 1; Pres.rels[r] != (node *)0; r++) {
		fprintf(OutFp, ",\n    ");
		PrintNode(Pres.rels[r]);
	}

	/* And close the presentation. */
	fprintf(OutFp, " >\n");
}