1 #include "gramm_fctn.h"
2 #include "gtk_domain.h"
3 #include "visutypes.h"
4 
5 G_LOCK_DEFINE(verrou_domains);	/* mutex: 'verrou_domains' protects DomainList */
6 
7 /************************/
8 /* DomainList fonctions */
9 /************************/
10 
insert_domain_in_list(char * name,ChainList lv,Polyhedron * pol,Domain * LD)11 Domain *insert_domain_in_list (char *name, ChainList lv, Polyhedron *pol, Domain *LD)
12 {
13   gboolean test_black;
14   GdkColor Black;
15   Domain *tmp;
16   char c;
17   char new_name[50];
18   char **pname;
19 
20 
21   if (DEBUG == 1)
22     {
23       printf ("DOMAIN LIST AVANT : \n");
24       print_domain_list(LD);
25     }
26 
27   /* if name already exists : overwrite or rename new domain */
28   if (name_already_exists (name, LD))
29     {
30       printf ("> Overwrite (o) , Choose another name (n) ?");
31       c = fgetc (stdin);
32 
33       while ((c != 'o') && (c != 'n'))
34 	{
35 	  printf ("> Please answer 'o' (overwrite) or 'n' (choose another name) !\n");
36 	  c = fgetc(stdin);
37 	}
38 
39       if (c == 'o')    // overwrite
40 	{
41 	  printf("> OK : overwrite '%s'\n", name);
42 	  LD = delete_domain_in_list (name, LD);
43 	}
44       else
45 	if (c == 'n')   // rename
46 	{
47 	  printf("> OK : rename : Please enter new name : ");
48 	  fscanf(stdin, "%s", new_name);
49 	  name = (char *) malloc ((strlen(new_name)+1)*sizeof(char));
50 	  strcpy (name, new_name);
51 	}
52     } /* name already exists */
53 
54 
55   /* insertion en tete du nouveau domain */
56   tmp = (Domain *)malloc(sizeof(Domain));
57 
58   tmp->name = (char *) malloc ((strlen(name)+1)*sizeof(char));
59   strcpy (tmp->name, name);
60   tmp->v_list = lv;
61   tmp->Pdomain = pol;
62 
63   pname = chaintochar (lv);
64   fprintf (stdout, "> %s := ", name);
65   VP_Print_Domain (stdout, pol, pname);
66 
67   test_black = gdk_color_black (gdk_colormap_get_system (), &Black);
68   if (!test_black)
69     {
70       tmp->color = NULL;
71       Warn ("Problem with allocation of colors!");
72     }
73   else
74     {
75       tmp->color = gdk_color_copy (&Black);
76     }
77 
78   tmp->visual = NULL;
79   tmp->next = LD; /* insertion en tete */
80 
81 
82   if (DEBUG == 1)
83     {
84       printf ("DOMAIN LIST APRES : \n");
85       print_domain_list(tmp);
86     }
87 
88   /* returns new DomainList */
89   return tmp;
90 
91 } /* insert_domain_in_list */
92 
93 
94 // retire un Domain de la liste
delete_domain_in_list(char * name,Domain * l)95 Domain *delete_domain_in_list (char *name, Domain *l)
96 {
97   char errmsg[100];
98   Domain *tmp;
99   Domain *cell; // pointeur sur l'element a supprimer
100 
101   if (l == NULL)
102     {
103       sprintf (errmsg, "delete_domain_in_list: Domain %s undeclared!", name);
104       yyerror (errmsg);
105       return l;
106     }
107 
108   tmp = l; // pointe sur le debut de la liste
109 
110   //si c'est le premier elt qu'on doit supprimer
111   if (strcmp(name, tmp->name) == 0)
112     {
113       l = l->next;
114       Domain_Cell_Free (tmp);
115 
116       if (GTK_IS_WIDGET (clist))
117 	graphic_list_delete (tmp);
118 
119       return l;
120     }
121 
122 
123   //cas general
124   while ((tmp->next) && (strcmp(name, (tmp->next)->name) != 0))
125     tmp = tmp->next;
126 
127   if (tmp->next == NULL)
128     {
129       sprintf (errmsg, "delete_domain_in_list: Domain %s undeclared!", name);
130       yyerror (errmsg);
131       return l;
132     }
133 
134   // maintenant, tmp pointe sur le bon domain (a supprimer)
135   cell = tmp->next; // on memorise le pointeur sur l'elt a supprimer
136 
137 	// efface le domain de la liste graphique
138 	if (GTK_IS_WIDGET (clist))
139 		graphic_list_delete (cell);
140 
141 	tmp->next = tmp->next->next; // raccord de la liste
142 
143 	Domain_Cell_Free (cell);
144 
145   return l;
146 
147 } // delete_domain_in_list
148 
149 
Domain_Cell_Free(Domain * cell)150 void Domain_Cell_Free (Domain * cell)
151 {
152   free (cell->name);
153   Domain_Free (cell->Pdomain);
154   free_l (cell->v_list);
155   //il doit manquer la liberation des champs geres par Gilles : color, visual.
156 }
157 
158 
search_domain_in_list(char * name,Domain * l)159 Domain *search_domain_in_list (char *name, Domain *l)
160 {
161   Domain *tmp;
162 
163   if (l == NULL)
164     return NULL;
165 
166   tmp = l;
167   while (tmp)
168     {
169       if (strcmp(name, tmp->name) == 0)
170 	return tmp;
171       tmp = tmp->next;
172     }
173 
174   return NULL;
175 
176 } // search_domain_in_list
177 
178 
179 // check if the name is already used for another domain
name_already_exists(char * name,Domain * l)180 int name_already_exists (char *name, Domain *l)
181 {
182 
183   while (l)
184     {
185       if (strcmp(name, l->name) == 0)
186 	{
187 	  fprintf (stdout, "Warning : identifier '%s' is already used for another domain !\n", name);
188 	  return true;
189 	}
190       l = l->next;
191     }
192 
193   return false;
194 } /* name_already_exists */
195 
196 
197 
print_domain_list(Domain * l)198 void print_domain_list (Domain *l)
199 {
200 
201   if (l == NULL)
202     printf ("Domain List Empty !\n");
203 
204   while (l)
205     {
206       printf ("\n %s : \t", l->name);
207       Affiche_liste (l->v_list);
208       Polyhedron_Print(stdout,"%d ",l->Pdomain);
209       printf ("\n");
210       l = l->next;
211     }
212   return;
213 }
214 
215 
216 
217 /***********************/
218 /* ChainLlist fonctions */
219 /***********************/
220 
221 /* ajoute en tete */
add_var_to_list(char * id,ChainList l)222 ChainList add_var_to_list (char *id, ChainList l)
223 {
224 
225   ChainList p, tmp;
226 
227   //check if there is no doublons
228   tmp = l;
229   while (tmp)
230     {
231       if (strcmp (id, tmp->Id) == 0)
232 	{
233 	  fprintf(stdout, "> more than one variable '%s' in polyhedron declaration - Action cancelled !\n", id);
234 	  input_error = true;
235 	  return l;
236 	}
237       tmp = tmp->suiv;
238     }
239 
240   if (DEBUG == 1)
241     printf ("l_add : ajoute %s dans VarList\n", id);
242 
243   p = (ChainList) malloc (sizeof(t_ChainList));
244   p->Id = (char*) malloc ((strlen(id)+1)*sizeof(char));
245   strcpy (p->Id, id);
246   p->suiv = l;
247   p->pos = dim;
248   dim ++;
249 
250   if (DEBUG == 1)
251     Affiche_liste(p);
252 
253   return (p);
254 
255 } /* add_var_to_list */
256 
257 
search_var_in_list(char * Id,ChainList l)258 IndList search_var_in_list (char *Id, ChainList l)
259 {
260   IndList res;
261   ChainList tmp = l;
262 
263   if (DEBUG == 1)
264     printf(" entree dans cherche\n : cherche %s dans varlist\n", Id);
265 
266   if (l == NULL)
267     {
268       yyerror ("id pas dans la liste\n");
269       return NULL;
270     }
271 
272   while (tmp)
273     {
274       if (strcmp (tmp->Id, Id) == 0)
275 	{
276 	  res = (IndList)malloc(sizeof(t_IndList));
277 	  res->pos = tmp->pos;
278 	  res->val = 1;
279 	  res->suiv = NULL;
280 	  return (res);
281 	}
282       tmp = tmp->suiv;
283     }
284 
285   yyerror ("there is an undeclared variable used in constraints !!\n");
286   return NULL;
287 } /* search_var_in_list */
288 
289 
free_l(ChainList l)290 ChainList free_l (ChainList l)
291 {
292 
293   ChainList tmp;
294 
295   while (l)
296     {
297       free (l->Id);
298       tmp = l->suiv;
299       free (l);
300       l = tmp;
301     }
302 
303   return NULL;
304 
305 } /* free_l */
306 
307 
Affiche_liste(ChainList l)308 void Affiche_liste(ChainList l)
309 {
310   ChainList tmp = l;
311 
312   printf("Liste : ");
313   if (l == NULL)
314     {
315       printf("liste vide \n");
316       return;
317     }
318   while (tmp != NULL)
319     {
320       printf(" %s : %d \t", tmp->Id, tmp->pos);
321       tmp = tmp->suiv;
322     }
323   printf("\n");
324 } /* Affiche_liste */
325 
326 
327 /* transforme un chainlist en char ** (pour les besoins de Print_Domain) */
chaintochar(ChainList l)328 char ** chaintochar (ChainList l)
329 {
330 
331   int i=0;
332   char **res;
333   ChainList tmp = l;
334 
335 if (DEBUG == 1)
336   printf ("entree dans chaintochar\n");
337 
338   if (l == NULL)
339     return NULL;
340 
341   // recherche de la taille du tableau
342   while (tmp)
343     {
344       i++;
345       tmp = tmp->suiv;
346     }
347 
348   res = (char **)malloc ((i+1)*sizeof(char*));
349 
350   // fin du tableau
351   res[i] = NULL;
352 
353   // copie des elements
354   tmp = l;
355   i--;
356   for ( ; i>=0; i--)
357     {
358       if (DEBUG == 1)
359 	printf ("copie de l'elet %d\n", i);
360 
361       res[i] = (char *)malloc ((strlen (tmp->Id)+1)*sizeof(char));
362       strcpy (res[i], tmp->Id);
363       tmp = tmp->suiv;
364     }
365 
366   if (DEBUG == 1)
367     printf(" sortie de chaintochar\n");
368 
369   return res;
370 } // chaintochar
371 
372 
373 
374 
375 /*********************/
376 /* IndList fonctions */
377 /*********************/
378 
concat(IndList l,IndList m)379 IndList concat (IndList l, IndList m)
380 {
381 
382   IndList tmp;
383 
384   if (l == NULL)
385     return m;
386 
387   if (m == NULL)
388     return l;
389 
390   for(tmp=l; tmp->suiv!=NULL; tmp=tmp->suiv); /* Recherche queue l */
391 
392   tmp->suiv = m; /* Concatenation */
393   return(l);
394 
395 } /* concat */
396 
397 
mult(IndList l,Value v)398 IndList mult (IndList l, Value v)
399 {
400   IndList tmp = l;
401 
402   if (l == NULL)
403     return NULL;
404 
405   while (l)
406     {
407       l->val = v * l->val;
408       l = l->suiv;
409     }
410   return tmp;
411 }// mult
412 
413 
neg(IndList l)414 IndList neg (IndList l)
415 {
416   IndList tmp = l;
417 
418   while (l)
419     {
420       l->val = - l->val;
421       l = l->suiv;
422     }
423   return tmp;
424 }// neg
425 
426 
Affiche_listeInd(IndList l)427 void Affiche_listeInd (IndList l)
428 {
429   IndList tmp = l;
430 
431   printf("IndListe : ");
432   if (l == NULL)
433     {
434       printf("liste vide \n");
435       return;
436     }
437   while (tmp != NULL)
438     {
439       printf(" %d : " P_VALUE_FMT " \t", tmp->pos, tmp->val);
440       tmp = tmp->suiv;
441     }
442   printf("\n");
443 } /* Affiche_listeInd */
444 
445 
446 
447 
448 /********************/
449 /* Matrix fonctions */
450 /********************/
451 
add_matrix_to_list(char * name,ChainMatrix * l)452 ChainMatrix *add_matrix_to_list (char *name, ChainMatrix *l)
453 {
454   ChainMatrix *res;
455   char c;
456   char new_name[50];
457 
458 if (input_error == false)
459   {
460     /* chercher si nom existe deja*/
461     if (mat_name_already_exists (name, l) == true)
462       {
463 	printf ("Warning : identifier %s is already used for another matrix\n",name);
464 	printf ("Overwrite (o) , Choose another name (n) ?");
465 	c = fgetc (stdin);
466 
467 	while ((c != 'o') && (c != 'n'))
468 	  {
469 	    printf ("Please answer 'o' (overwrite)  or 'n' (choose another name) !\n");
470 	    c = fgetc(stdin);
471 	  }
472 
473 	if (c == 'o')    // overwrite
474 	  {
475 	    printf("OK : overwrite '%s'\n", name);
476 	    l = delete_matrix_in_list (name, l);
477 	    // signaler a gilles que cette matrice est detruite
478 		 }
479 
480 	else
481 	  if (c == 'n')   // rename
482 	  {
483 	    printf("Please enter new name :\n");
484 	    fscanf(stdin, "%s", new_name);
485 	    name = (char *) malloc ((strlen(new_name)+1)*sizeof(char));
486 	    strcpy (name, new_name);
487 	  }
488       } // name already exists
489 
490 	     // ajout de la nouvelle matrice
491 	     res = (ChainMatrix *)malloc(sizeof(ChainMatrix));
492       res->name = (char *)malloc((strlen(name)+1)*sizeof(char));
493       strcpy(res->name, name);
494       res->M = curr_matrix;
495       res->M->NbRows = curr_constr_num;
496       curr_constr_num = 0;
497       dim = 1;
498       res->next = l;
499       curr_matrix = NULL; /* est ce bien propre ?... */
500 
501 //      fprintf (stdout, "> Succeded ! Matrix '%s' is now in Matrix List !\n", name);
502 
503       return res;
504   }
505 
506   fprintf (stdout, "> error in matrix declaration\n");
507   input_error = false;
508   curr_constr_num = 0;
509   dim = 1;
510 
511   return l;
512 
513 } // add_matrix_to_list
514 
515 
mat_name_already_exists(char * name,ChainMatrix * l)516 int mat_name_already_exists (char *name, ChainMatrix *l)
517 {
518 
519   while (l)
520     {
521       if (strcmp(name, l->name) == 0)
522 	return true;
523 
524       l = l->next;
525     }
526   return false;
527 } /* name_already_exists */
528 
529 
search_matrix_in_list(char * name,ChainMatrix * l)530 Matrix *search_matrix_in_list (char *name, ChainMatrix *l)
531 {
532   ChainMatrix *tmp;
533 
534   if (l == NULL)
535     return NULL;
536 
537   tmp = l;
538   while (tmp)
539     {
540       if (strcmp(name, tmp->name) == 0)
541 	return tmp->M;
542       tmp = tmp->next;
543     }
544 
545   return NULL;
546 
547 } // search_matrix_in_list
548 
549 
550 // retire une matrice de la liste
delete_matrix_in_list(char * name,ChainMatrix * l)551 ChainMatrix *delete_matrix_in_list (char *name, ChainMatrix *l)
552 {
553   char errmsg[100];
554   ChainMatrix *tmp;
555   ChainMatrix *cell; // pointeur sur l'element a supprimer
556 
557   // cas liste vide
558   if (l == NULL)
559     {
560       sprintf (errmsg, "delete matrix : Domain %s undeclared : DomainList empty !", name);
561       yyerror (errmsg);
562       return l;
563     }
564 
565   tmp = l; // pointe sur le debut de la liste
566 
567   //cas ou c'est le premier elt qu'il faut supprimer
568   if (strcmp(name, tmp->name) == 0)
569     {
570       l = l->next;
571       if (tmp->M)
572 	{
573 	  Matrix_Free (tmp->M);
574 	  free (tmp->name);
575 	}
576       return l;
577     }
578 
579 
580   //cas general
581   while ((tmp->next) && (strcmp(name, (tmp->next)->name) != 0))
582     tmp = tmp->next;
583 
584   // maintenant, tmp pointe sur le bon nmo
585 
586   cell = tmp->next; // on memorise le pointeur sur l'elt a supprimer
587   tmp->next = tmp->next->next; // raccord de la liste
588 
589   if (cell->M)
590     {
591       Matrix_Free (cell->M);
592       free (cell->name);
593     }
594 
595   return l;
596 
597 } // delete_matrix_in_list
598 
599 
print_matrix_list(ChainMatrix * l)600 void print_matrix_list (ChainMatrix *l)
601 {
602   if (l == NULL)
603     {
604       printf ("\nMatrix List Empty !!\n");
605       return;
606     }
607 
608   printf ("\n MATRIX LIST :\n\n");
609   while (l)
610     {
611       printf("\t %s\n", l->name);
612       Matrix_Print (stdout, "%d ", l->M);
613       l = l->next;
614     }
615 
616   return;
617 }
618 
619 
620 /***************************/
621 /***************************/
622 
polyhedron_declaration(char * name,ChainList lv,Domain * LD)623 Domain * polyhedron_declaration (char *name, ChainList lv, Domain *LD)
624 {
625   Polyhedron *pol;
626 
627   if (input_error == false)
628     {
629       if (lv != NULL)
630 	{
631 	  curr_matrix->NbRows = curr_constr_num ;
632 	  if (DEBUG == 1)
633 	    Matrix_Print(stdout, "%d ",curr_matrix);
634 	  pol = Constraints2Polyhedron (curr_matrix,100);
635 	}
636       else  /* empty polyhedron */
637 	pol = Empty_Polyhedron (0);
638 
639       LD = insert_domain_in_list (name, lv, pol, LD);
640     }
641   else
642     VarList = free_l (VarList);
643 
644   init_curr_vars();
645 
646   return LD;
647 
648 }// declaration_pol
649 
650 
651 /* reinit current vars */
init_curr_vars()652 void init_curr_vars ()
653 {
654   if (curr_matrix)
655     {
656       Matrix_Free (curr_matrix);
657       curr_matrix = NULL;
658     }
659   VarList = NULL;       /* pointer init */
660   dim = 1;              /* dim init */
661   curr_constr_num = 0;  /* current constraint number init */
662   input_error = false;
663 
664 }
665 
666 
667 // generate operations on polyhedrons
gen_binop_pol(char * id1,char * id2,char * id3,char * polyhedron_operator,Domain * LD)668 Domain *gen_binop_pol (char *id1, char *id2, char *id3, char *polyhedron_operator, Domain *LD)
669 {
670   Polyhedron *tmp;
671   Domain *P2;
672   Domain *P3;
673   char errmsg[100];
674 
675 
676   /* check if P3 and P3 exist */
677   P2 = (Domain *)malloc (sizeof(Domain));
678   P3 = (Domain *)malloc (sizeof(Domain));
679   P2 = search_domain_in_list (id2, LD);
680   P3 = search_domain_in_list (id3, LD);
681   if (P2 && P3)
682     {
683       if (strcmp(polyhedron_operator, "union") == 0)
684 	tmp = DomainUnion(P2->Pdomain, P3->Pdomain, 100);
685       else if (strcmp(polyhedron_operator, "inter") == 0)
686 	tmp = DomainIntersection(P2->Pdomain, P3->Pdomain, 100);
687       else if (strcmp(polyhedron_operator, "diff") == 0)
688 	tmp = DomainDifference(P2->Pdomain, P3->Pdomain, 100);
689       else
690 	{
691 	  yyerror ("gen_pol_binop : pas possible d'etre ici!!!\n");
692 	  return LD;
693 	}
694 
695 
696       // ici : insert_domain
697       LD = insert_domain_in_list (id1, P2->v_list, tmp, LD);
698 
699       return LD;
700     }
701 
702   /* polyhedron does not exist */
703   sprintf (errmsg, "%s : command ignored\n", polyhedron_operator);
704   yyerror (errmsg);
705   return LD;
706 
707 }
708 
709 
gen_image(char * name,char * id_pol,char * id_mat,char * operation,Domain * LD)710 Domain *gen_image (char *name, char *id_pol, char *id_mat, char *operation, Domain *LD)
711 {
712 
713   Domain *pol;
714   Polyhedron *tmp;
715   Matrix *mat;
716 
717   //check if polyhedron and matrix exist
718   pol = search_domain_in_list (id_pol, LD);
719   mat = search_matrix_in_list (id_mat, MatrixList);
720   if ((pol == NULL) || (mat == NULL))
721     {
722       fprintf (stdout, "%s : command ignored - polyhedron '%s' or matrix '%s' does not exist !\n", operation, id_pol, id_mat);
723 		return( LD );
724     }
725   else // ok : image et insertion dans DomainList
726     {
727       if (strcmp (operation, "image") == 0)
728 	tmp = DomainImage (pol->Pdomain, mat, 20);
729       else if (strcmp (operation, "preimage") == 0)
730 	{
731 		tmp = DomainPreimage (pol->Pdomain, mat, 20);
732 	}
733       else
734 	{
735 	  yyerror ("pas possible d'etre la !!\n");
736 	  return LD;
737 	}
738 
739       //insertion
740       if (tmp)
741       {
742 	      if( tmp->Dimension == pol->Pdomain->Dimension )
743 			LD = insert_domain_in_list (name, pol->v_list, tmp, LD);
744 	      else
745 	      {
746 		      ChainList cl;
747 		      int i;
748 		      char s[10];
749 		      cl = NULL;
750   			dim = 1;              /* dim init, pouah!!!! */
751 		      for( i=0 ; i<tmp->Dimension ; i++ )
752 		      {
753 			      sprintf(s, "%c", 'i'+i );
754 			      cl = add_var_to_list( s, cl );
755 		      }
756 		      LD = insert_domain_in_list (name, cl, tmp, LD);
757   			dim = 1;              /* dim init, pouah!!!! */
758 	      }
759       }
760 
761       return LD;
762     }
763 
764 }//gen_image
765 
766 
gen_disjoint(char * name,char * id_pol,Domain * LD)767 Domain *gen_disjoint (char *name, char *id_pol, Domain *LD)
768 {
769   Domain *P;
770   Polyhedron *tmp;
771 
772   P = (Domain *)malloc (sizeof(Domain));
773   P = search_domain_in_list (id_pol, LD);
774   if (P)
775     {
776       tmp = Disjoint_Domain(P->Pdomain, 0, 100);
777       LD = insert_domain_in_list (name, P->v_list, tmp, LD);
778       return LD;
779     }
780 
781   fprintf (stdout, "> DD : domain '%s' does not exist ! Command ignored\n", id_pol);
782   return LD;
783 }
784 
gen_convex(char * name,char * id_pol,Domain * LD)785 Domain *gen_convex (char *name, char *id_pol, Domain *LD)
786 {
787   Domain *P;
788   Polyhedron *tmp;
789 
790   P = (Domain *)malloc (sizeof(Domain));
791   P = search_domain_in_list (id_pol, LD);
792   if (P)
793     {
794       tmp = DomainConvex (P->Pdomain, 100);
795       LD = insert_domain_in_list (name, P->v_list, tmp, LD);
796       return LD;
797     }
798 
799   fprintf (stdout, "> Convex : domain '%s' does not exist ! Command ignored\n", id_pol);
800   return LD;
801 
802 }//gen_convex
803 
804 
gen_ehrhart(char * id_pol,char * id_context,Domain * LD)805 void gen_ehrhart (char *id_pol, char *id_context, Domain *LD)
806 {
807   Domain *P, *Context;
808   Enumeration *en, *ehrhart;
809   char **pname;
810 
811   P = search_domain_in_list (id_pol, LD);
812   Context = search_domain_in_list (id_context, LD);
813   if (P && Context)
814     {
815       ehrhart = Polyhedron_Enumerate(Polyhedron_Copy(P->Pdomain), Context->Pdomain, 100, NULL);
816       for( en=ehrhart ; en ; en=en->next )
817 	{
818 	  pname = chaintochar (Context->v_list);
819 	  Print_Domain(stdout,en->ValidityDomain, pname);
820 	  print_evalue(stdout,&en->EP, pname);
821 	  printf( "\n-----------------------------------\n" );
822 	}
823       return;
824     }
825 
826   fprintf (stdout, "> Ehrhart : '%s' or '%s' undeclared - command ignored\n", id_pol,id_context);
827   return;
828 
829 }//gen_ehrhart
830 
831 
gen_vert(char * id_pol,char * id_context,Domain * LD)832 void gen_vert (char *id_pol, char *id_context, Domain *LD)
833 {
834 	Domain *P, *Context;
835 	Param_Polyhedron *PA;
836 	Param_Domain *L;
837 	Param_Vertices *V;
838 	char **pname;
839 
840 	P = search_domain_in_list (id_pol, LD);
841 	Context = search_domain_in_list (id_context, LD);
842 	if (P && Context)
843 	{
844 		PA = Polyhedron2Param_Domain(Polyhedron_Copy(P->Pdomain), Context->Pdomain, 100);
845 		pname = chaintochar (Context->v_list);
846 		  /*****************************/
847 		  /* Scan the validity domains */
848 		for(L=PA->D;L;L=L->next)
849 		{
850 
851 			/* prints current val. dom. */
852 			printf( "---------------------------------------\n" );
853 			printf( "Domain :\n");
854 			Print_Domain( stdout, L->Domain, pname );
855 
856 			/* scan the vertices */
857 			printf( "Vertices :\n");
858 			FORALL_PVertex_in_ParamPolyhedron(V,L,PA) {
859 
860 				/* prints each vertex */
861 				Print_Vertex( stdout, V->Vertex, pname );
862 				printf( "\n" );
863 			}
864 			END_FORALL_PVertex_in_ParamPolyhedron;
865 		}
866 		    /*****************************/
867 	}
868 	else
869 		fprintf (stdout, "> Vertices : '%s' or '%s' undeclared - command ignored\n", id_pol,id_context);
870 	return;
871 }//gen_vert
872 
873 
874 
875 
help_print(void)876 void help_print (void)
877 {
878   char c[100];
879 
880   fprintf(stdout, " \t ---------- COMMANDS - SYNTAX ----------\n\n");
881 
882   while (strcmp (c, "q") != 0)
883     {
884       fprintf(stdout, "\n> Type 'l' for command list, <command_name> for synopsis, 'q' to quit help menu\n");
885       fprintf(stdout, " ? ");
886       scanf ("%s", c);
887 
888       if (strcmp (c, "l") == 0)
889 	{
890 	  fprintf (stdout, "Command list :\n");
891 	  fprintf (stdout, "\t union (+), inter (.), diff (-), image, preimage, convex, ehrhart, list,\n ");
892 	  fprintf (stdout, "\t del, initvisu, visu, print, PLprint, PLcons, PLrays, help, quit\n");
893 	  fprintf(stdout, "\t declarations (polyhedra and matrices)\n");
894 	}
895 
896       else if (strcmp (c, "union") == 0)
897 	{
898 	  fprintf(stdout, "> union - Description: union between two domains\n");
899 	  fprintf (stdout, " \t <name_union> := <dom_P1> [union|+] <dom_P2> ;\n");
900 	}
901 
902       else if (strcmp (c, "inter") == 0)
903 	{
904 	  fprintf(stdout, "> inter - Description: intersection between two domains\n");
905 	  fprintf (stdout, " \t <name_inter> := <dom_P1> [inter|.]   <dom_P2> ;\n");
906 	}
907 
908       else if (strcmp (c, "diff") == 0)
909 	{
910 	  fprintf(stdout, "> diff - Description: difference between two domains\n");
911 	  fprintf (stdout, " \t <name_diff> := <dom_P1> [diff|-]  <dom_P2> ;\n");
912 	}
913 
914       else if (strcmp (c, "image") == 0)
915 	{
916 	  fprintf(stdout, "> image - Description: transformation of a domain by a matrix\n");
917 	  fprintf (stdout, " \t <name> := image ( <dom_domain> , <mat_trans> ) ;\n");
918 	}
919 
920       else if (strcmp (c, "preimage") == 0)
921 	{
922 	  fprintf(stdout, "> preimage - Description: inverse transformation of a domain by a matrix\n");
923 	  fprintf (stdout, " \t <name> := preimage ( <dom_domain> , <mat_trans> ) ;\n");
924 	}
925 
926       else if (strcmp (c, "print") == 0)
927 	{
928 	  fprintf(stdout, "> print - Description: print a domain\n");
929 	  fprintf (stdout, " \t print <dom_domain> ;\n");
930 	}
931 
932       else if (strcmp (c, "PLprint") == 0)
933 	{
934 	  fprintf(stdout, "> PLprint - Description: print a domain or matrix (PolyLib format)\n");
935 	  fprintf (stdout, " \t PLprint <name> ;\n");
936 	}
937       else if (strcmp (c, "PLcons") == 0)
938 	{
939 	  fprintf(stdout, "> PLcons - Description: print the constraints matrices\n");
940 	  fprintf (stdout, " \t PLcons <dom_domain> ;\n");
941 	}
942       else if (strcmp (c, "PLrays") == 0)
943 	{
944 	  fprintf(stdout, "> PLrays - Description: print the rays matrices (rays, lines, vertices)\n");
945 	  fprintf (stdout, " \t PLrays <dom_domain> ;\n");
946 	}
947 
948       else if (strcmp (c, "initvisu") == 0)
949 	{
950 	  fprintf(stdout, "> initvisu - Description: initialize the visualisation window\n");
951 	  fprintf (stdout, " \t initvisu ( <int_dimension> , <pol_context> ) ;\n");
952 	}
953 
954       else if (strcmp (c, "visu") == 0)
955 	{
956 	  fprintf(stdout, "> visu - Description: visualize a domain\n");
957 	  fprintf (stdout, " \t visu ( <dom_domain> ) ;\n");
958 	}
959 
960       else if (strcmp (c, "quit") == 0)
961 	{
962 	  fprintf(stdout, "> quit - Description: quit the application\n");
963 	  fprintf (stdout, " \t quit\n");
964 	}
965 
966       else if (strcmp (c, "ehrhart") == 0)
967 	{
968 	  fprintf(stdout, "> ehrhart - Description: compute the number of integer points of a domain in a given context\n");
969 	  fprintf (stdout, " \t Syntax : ehrhart ( <dom_domain>, <pol_context> ) ;\n");
970 	}
971 
972       else if (strcmp (c, "convex") == 0)
973 	{
974 	  fprintf(stdout, "> convex - Description: compute the convex hull of a domain\n");
975 	  fprintf (stdout, " \t Syntax : <pol_CHull> := convex <dom_domain> ;\n");
976 	}
977 
978       else if (strcmp (c, "list") == 0)
979 	{
980 	  fprintf(stdout, "> list - Description: display the full list of domains and matrix in memory\n");
981 	  fprintf (stdout, " \t list ;");
982 	}
983 
984       else if (strcmp (c, "del") == 0)
985 	{
986 	  fprintf(stdout, "> del - Description: removes a domain (matrix) from Domain List (Matrix List)\n");
987 	  fprintf (stdout, " \t del <name> ;");
988 	}
989 
990       else if (strncmp (c, "decl", 4) == 0)
991 	{
992 	  fprintf (stdout, " \t <pol_P> := { <var_list> | <constraints_list> } ;\n");
993 	  fprintf (stdout, " \t    with <var_list>     : i, j, k, M, N...\n");
994 	  fprintf (stdout, " \t         <constraints>  : i<2j+2N , 0>k>=3*(i-j)+M , ...\n");
995 	  fprintf (stdout, " \t <mat_M> := ( (a1,b1,c1,...) , (a2,b2,c2,...) , ... , (an,bn,cn,...) ) ;\n");
996 
997     }
998 	  else if( strcmp (c, "q") != 0 )
999 		  fprintf (stdout, " \t Unknown command\n");
1000 	}
1001 
1002 } // help_print
1003 
1004 
1005 
1006 
writeOneSideDomain(Polyhedron * D,int i,FILE * f,int s,char ** param)1007 static int writeOneSideDomain(Polyhedron *D, int i, FILE *f, int s, char **param)
1008 {
1009 	int premier, j;
1010 
1011 	premier = 1;
1012 	for( j=0 ; j<D->Dimension ; ++j )
1013 	{	if( D->Constraint[i][1+j] != 0 && s*D->Constraint[i][1+j] > 0 )
1014 		{
1015 			if( !premier )
1016 				fprintf( f, "+" );
1017 			else
1018 				premier = 0;
1019 			if( s*D->Constraint[i][1+j] != 1 )
1020 				fprintf( f, "%lld", s*D->Constraint[i][1+j] );
1021 			fprintf( f, "%s", param[j] );
1022 		}
1023 	}
1024 	return( premier );
1025 }
1026 
1027 /* affiche une matrice */
VP_Print_Matrix(FILE * f,Matrix * M)1028 void VP_Print_Matrix (FILE *f, Matrix *M )
1029 {
1030 	int i,j;
1031 	fprintf( f, "(\n" );
1032 	for( i=0 ; i<M->NbRows ; i++ )
1033 	{
1034 		fprintf( f, "             ( " );
1035 		for( j=0 ; j<M->NbColumns-1 ; j++ )
1036 			fprintf( f, P_VALUE_FMT ",", M->p[i][j] );
1037 		fprintf( f, P_VALUE_FMT " )", M->p[i][j] );
1038 		if( i!=M->NbRows-1 )
1039 			fprintf( f, ",\n" );
1040 	}
1041 	fprintf( f, "   )\n" );
1042 
1043 }
1044 
1045 /* affiche un domaine (parametre) */
VP_Print_Domain(FILE * f,Polyhedron * D,char ** param)1046 void VP_Print_Domain (FILE *f, Polyhedron *D, char **param )
1047 {
1048 	int i, p;
1049 
1050 	if( D->Dimension == 0 )
1051 	{
1052 		fprintf( f, "{ | }\n");
1053 		return;
1054 	}
1055 	fprintf( f, "  { %s", param[0] );
1056 	for( i=1 ; i<D->Dimension ; i++ )
1057 		fprintf( f, ", %s", param[i] );
1058 	fprintf( f, " | " );
1059 	for( i=0 ; i<D->NbConstraints ; ++i )
1060 	{
1061 		int j, s;
1062 
1063 		/* s = sens de l'inegalite >= ou <= */
1064 		s = 1;
1065 		for( j=0 ; j<D->Dimension ; ++j )
1066 		{	if( D->Constraint[i][1+j] )
1067 			{	if( D->Constraint[i][1+j]<0 )
1068 					s = -1;
1069 				break;		/* on s'arrete au premier !=0 rencontre */
1070 			}
1071 		}
1072 		if( j==D->Dimension && D->Constraint[i][1+j]==1 && D->Constraint[i][0]==1)
1073 			continue;
1074 			/* c'est la positivity constraint... on ne l'affiche pas */
1075 
1076 		if( i>0 )
1077 			fprintf( f, ", " );
1078 
1079 		/* affichage */
1080 		/* terme gauche */
1081 		if( writeOneSideDomain(D, i, f, s, param) )
1082 			fprintf( f, "0" );
1083 
1084 		/* operateur */
1085 		if( D->Constraint[i][0] )
1086 		{	/* inegalite dans le sens de s */
1087 			if( s>0 )
1088 				fprintf( f, " >= " );
1089 			else
1090 				fprintf( f, " <= " );
1091 		}
1092 		else
1093 			/* egalite */
1094 			fprintf( f, " = " );
1095 
1096 
1097 		/* terme droit + constante */
1098 		if( (p=writeOneSideDomain(D, i, f, -s, param)) ||
1099 				D->Constraint[i][1+D->Dimension]!=0 )
1100 		{
1101 			if( s*D->Constraint[i][1+D->Dimension]>0 )
1102 				fprintf( f, "-" );
1103 			else if( !p )
1104 				fprintf( f, "+" );
1105 			fprintf( f, "%d", abs(D->Constraint[i][1+D->Dimension]) );
1106 		}
1107 	}
1108 	fprintf( f, " }\n" );
1109 
1110 	if( D->next )
1111 	{
1112 		printf( "UNION " );
1113 		VP_Print_Domain( f, D->next, param );
1114 	}
1115 }
1116 
1117 
1118 
Constraints_Print(FILE * f,char * format,Polyhedron * D)1119 void Constraints_Print ( FILE *f, char *format, Polyhedron *D )
1120 {
1121 	for( ; D ; D=D->next )
1122 	{
1123 		Matrix *m;
1124 		m = Polyhedron2Constraints( D );
1125 		Matrix_Print (stdout, "%4d ", m);
1126 		Matrix_Free( m );
1127 	}
1128 }
Rays_Print(FILE * f,char * format,Polyhedron * D)1129 void Rays_Print ( FILE *f, char *format, Polyhedron *D )
1130 {
1131 	for( ; D ; D=D->next )
1132 	{
1133 		Matrix *m;
1134 		m = Polyhedron2Rays( D );
1135 		Matrix_Print (stdout, "%4d ", m);
1136 		Matrix_Free( m );
1137 	}
1138 }
1139 
1140 
graphic_actualize()1141 void graphic_actualize()
1142 {
1143   gdk_threads_enter ();
1144   if (domain_frame)
1145     {
1146       graphic_list_insert ( DomainList);
1147       if (strcmp (DomainList->name, ContextName) == 0)
1148 	reinit = TRUE;
1149     }
1150 
1151   /* Reinitialisation si le contexte a ete modifie */
1152   if (reinit == TRUE)
1153   {
1154     G_UNLOCK (verrou_domains);
1155     init_visu ();
1156 	 G_LOCK (verrou_domains);
1157   }
1158   gdk_threads_leave ();
1159 }
1160