/****************************************************************************/
/*                                                                          */
/*                      Chaine de CAO & VLSI   Alliance                     */
/*                                                                          */
/*    Produit : DESB  v2.n                                                  */
/*    Fichier : path_para.c                                                 */
/*                                                                          */
/*    (c) copyright 1991 Laboratoire MASI equipe CAO & VLSI                 */
/*    Tous droits reserves                                                  */
/*    Support : e-mail cao-vlsi@masi.ibp.fr                                 */
/*                                                                          */
/*    Auteur(s) : Pascal Remy                           le : 06/09/1991     */
/*                                                                          */
/*    Modifie par :                                     le : ../../....     */
/*    Modifie par :                                     le : ../../....     */
/*    Modifie par :                                     le : ../../....     */
/*                                                                          */
/****************************************************************************/

#include "declar.h"

/****************************************************************************
 *                         fonction test_parallel();                        *
 ****************************************************************************/

short           test_parallel(ptlist0, ptlist1)

list_list      *ptlist0, *ptlist1;

{
link_list      *ptlink0, *ptlink1;
short           parallel = 0;

   for (ptlink0 = (link_list*)ptlist0->DATA; ptlink0 != NULL;
       ptlink0 = ptlink0->NEXT)
   {
   parallel = 0;
      for (ptlink1 = (link_list*)ptlist1->DATA; ptlink1 != NULL;
         ptlink1 = ptlink1->NEXT)
      {
         if ((((ptlink1->TYPE & IN) == IN)
         && ((ptlink0->TYPE & IN)== IN))
         || (((ptlink1->TYPE & INOUT) == INOUT)
         && ((ptlink0->TYPE & INOUT) == INOUT)))
         {
            if (((locon_list*)ptlink1->TRANS)->NAME==((locon_list*)ptlink0->TRANS)->NAME)
            {
            parallel = 1;
            break;
            }
         }
         else if ((((ptlink1->TYPE & TP) == TP) && ((ptlink0->TYPE & TP) == TP))
             || (((ptlink1->TYPE & TN) == TN) && ((ptlink0->TYPE & TN) == TN)))
         {
         if (ptlink1->TRANS->GRID == ptlink0->TRANS->GRID)
            {
            parallel = 1;
            break;
            }
         }
      }
      if (parallel == 0) { break; }
   }
return parallel;
}


/****************************************************************************
 *                         fonction detect_path_para();                     *
 ****************************************************************************/

long            detect_path_para(ptcone)

cone_list      *ptcone;

{
list_list      *ptlist0, *ptlist1;
chain_list     *ptchain0, *ptchain1;
ptype_list     *pttype;
short           parallel = 0;
long            count_path_para0 = 0, count_path_para1;


/*----------------------------------------------------------------------------*
 | Nettoyage des chaps USER PATH_PARA                                         |
 *----------------------------------------------------------------------------*/

ptcone->TYPE = (ptcone->TYPE & ~PATH_PARA);
   if ((pttype = getptype(ptcone->USER, (short)PATH_PARA)) != NULL)
   {
      for (ptchain0 = (chain_list*)pttype->DATA; ptchain0 != NULL;
         ptchain0 = ptchain0->NEXT)
      { freechain((chain_list*)ptchain0->DATA); }
   freechain((chain_list*)pttype->DATA);
   ptcone->USER = delptype(ptcone->USER, (short)PATH_PARA);
   }

   for (ptlist0 = ptcone->PATH; ptlist0 != NULL; ptlist0 = ptlist0->NEXT)
   { ptlist0->USER = NULL; }

/*----------------------------------------------------------------------------*
 | On commence detect_path_para proprement dit                                |
 *----------------------------------------------------------------------------*/

ptchain0 = NULL;
   for (ptlist0 = ptcone->PATH; ptlist0 != NULL; ptlist0 = ptlist0->NEXT)
   {
   count_path_para1 = 0; ptchain1 = NULL; parallel = 0;
      if (ptlist0->USER == NULL)
      {
         for (ptlist1 = ptlist0->NEXT; ptlist1 != NULL; ptlist1 = ptlist1->NEXT)
         {
            if (ptlist1->USER == NULL)
            {
               if (((((ptlist1->TYPE & VDD) == VDD)
                 && ((ptlist0->TYPE & VDD) == VDD))
                 || (((ptlist1->TYPE & VSS) == VSS)
                 && ((ptlist0->TYPE & VSS) == VSS))
                 || (((ptlist1->TYPE & EXT) == EXT)
                 && ((ptlist0->TYPE & EXT) == EXT)))
                 && ((ptlist0->TYPE & BLEEDER)!= BLEEDER)
                 && ((ptlist1->TYPE & BLEEDER)!= BLEEDER) )
               {
               parallel = test_parallel(ptlist0, ptlist1);
                  if (parallel == 1)
                  {
                  parallel = test_parallel(ptlist1, ptlist0);
                     if (parallel == 1)
                     {
                     count_path_para0++; count_path_para1++;
                     ptlist1->USER = (ptype_list*)1;
                        if (count_path_para1 == 1)
                        {
                        count_path_para0++; count_path_para1++;
                        ptchain1 = addchain(ptchain1, (void*)ptlist0);
                        ptchain1 = addchain(ptchain1, (void*)ptlist1);
                        }
                        else
                        { ptchain1 = addchain(ptchain1, (void*)ptlist1); }
                     }
                  }
               }
            }
         }
      }
      if (count_path_para1 != 0)
      {
      ptchain0 = addchain(ptchain0, (void*)ptchain1);
      ptchain1 = NULL;
      }
   }
   if (count_path_para0 != 0)
   {
   ptcone->TYPE = (ptcone->TYPE | PATH_PARA);
   ptcone->USER = addptype(ptcone->USER, PATH_PARA, (void*)ptchain0);
   }
return count_path_para0;
}
