[BACK]Return to subst.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / builtin

Diff for /OpenXM_contrib2/asir2000/builtin/subst.c between version 1.10 and 1.11

version 1.10, 2015/09/24 04:43:13 version 1.11, 2017/09/06 06:25:26
Line 45 
Line 45 
  * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,   * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
  * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.   * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
  *   *
  * $OpenXM: OpenXM_contrib2/asir2000/builtin/subst.c,v 1.9 2010/01/31 03:25:54 noro Exp $   * $OpenXM: OpenXM_contrib2/asir2000/builtin/subst.c,v 1.10 2015/09/24 04:43:13 noro Exp $
 */  */
 #include "ca.h"  #include "ca.h"
 #include "parse.h"  #include "parse.h"
Line 68  extern Obj VOIDobj;
Line 68  extern Obj VOIDobj;
   
 void Psubstr2np(NODE arg,Obj *rp)  void Psubstr2np(NODE arg,Obj *rp)
 {  {
         Obj a;    Obj a,b;
         P nm,dn,p;    P nm,dn,p,q;
         R r;    R r;
         VL vl,tvl;    VL vl,tvl;
         int nv,i,ac;    int nv,i,ac,j;
         NODE slist,t,ps,u,vlist;    NODE slist,t,ps,u,vlist;
         P s;    P s;
         P *svect;    P *svect;
         V v;    V v;
         V *vvect;    V *vvect;
   
         a = (Obj)ARG0(arg);    a = (Obj)ARG0(arg);
         if ( !a || NUM(a) ) {    if ( !a || NUM(a) ) {
                 *rp = a;      *rp = a;
                 return;      return;
         }    }
         asir_assert(ARG0(arg),O_R,"substr2np");    asir_assert(ARG0(arg),O_R,"substr2np");
         asir_assert(ARG1(arg),O_LIST,"substr2np");    asir_assert(ARG1(arg),O_LIST,"substr2np");
         get_vars(a,&vl);    get_vars(a,&vl);
         for ( i = 0, tvl = vl; tvl; tvl = NEXT(tvl), i++ );    for ( i = 0, tvl = vl; tvl; tvl = NEXT(tvl), i++ );
         nv = i;    nv = i;
         vvect = (V *)MALLOC(nv*sizeof(V));    vvect = (V *)MALLOC((nv)*sizeof(V));
         for ( i = 0, tvl = vl; tvl; tvl = NEXT(tvl), i++ ) vvect[i] = tvl->v;    for ( i = 0, tvl = vl; tvl; tvl = NEXT(tvl), i++ ) vvect[i] = tvl->v;
         svect = (P *)MALLOC(nv*sizeof(P));    svect = (P *)MALLOC((nv)*sizeof(P));
     ac = argc(arg);    ac = argc(arg);
     if ( ac == 2 ) {    if ( ac == 2 ) {
           slist = BDY((LIST)ARG1(arg));      slist = BDY((LIST)ARG1(arg));
           for ( i = 0; i < nv; i++ ) svect[i] = (P)VOIDobj;      for ( i = 0; i < nv; i++ ) svect[i] = (P)VOIDobj;
           for ( t = slist; t; t = NEXT(t) ) {      for ( t = slist; t; t = NEXT(t) ) {
                   ps = BDY((LIST)BDY(t)); p = (P)BDY(ps); s = (P)BDY(NEXT(ps));        ps = BDY((LIST)BDY(t)); p = (P)BDY(ps); s = (P)BDY(NEXT(ps));
                   asir_assert(p,O_P,"substr2np"); asir_assert(s,O_N,"substr2np");        asir_assert(p,O_P,"substr2np"); asir_assert(s,O_P,"substr2np");
                   v = VR(p);        v = VR(p);
                   for ( i = 0; i < nv; i++ ) if ( vvect[i] == v ) break;        for ( i = 0; i < nv; i++ ) if ( vvect[i] == v ) break;
                   svect[i] = s;        svect[i] = s;
           }      }
     } else if ( ac == 3 ) {    } else if ( ac == 3 ) {
           asir_assert(ARG2(arg),O_LIST,"substr2np");      asir_assert(ARG2(arg),O_LIST,"substr2np");
       vlist = BDY((LIST)ARG1(arg));      vlist = BDY((LIST)ARG1(arg));
       slist = BDY((LIST)ARG2(arg));      slist = BDY((LIST)ARG2(arg));
           for ( i = 0; i < nv; i++ ) svect[i] = (P)VOIDobj;      for ( i = 0; i < nv; i++ ) svect[i] = (P)VOIDobj;
       for ( u = vlist, t = slist; u && t; u = NEXT(u), t = NEXT(t) ) {        for ( u = vlist, t = slist; u && t; u = NEXT(u), t = NEXT(t) ) {
         v = VR((P)BDY(u));          v = VR((P)BDY(u));
         for ( i = 0; i < nv; i++ ) if ( vvect[i] == v ) break;          for ( i = 0; i < nv; i++ ) if ( vvect[i] == v ) break;
Line 115  void Psubstr2np(NODE arg,Obj *rp)
Line 115  void Psubstr2np(NODE arg,Obj *rp)
       }        }
     } else      } else
       error("substr2np : argument mismatch");        error("substr2np : argument mismatch");
     for ( i = 0; i < nv; i++ ) {
         switch ( OID(a) ) {      if ( (int)(vvect[i]->attr) == V_PF ) {
                 case O_P:        MKV(vvect[i],p);
                         substpp(vl,(P)a,vvect,svect,nv,&nm); *rp = (Obj)nm;        for ( j = 0; j < nv; j++ )
                         return;          if ( j != i ) {
                 case O_R:            substr(CO,0,(Obj)p,vvect[j],(Obj)svect[j],&b); p = (P)b;
                         substpp(vl,(P)NM((R)a),vvect,svect,nv,&nm);          }
                         substpp(vl,(P)DN((R)a),vvect,svect,nv,&dn);        if ( OID(svect[i]) == O_VOID ) svect[i] = p;
                         if ( !dn )        else if ( arf_comp(CO,(Obj)p,(Obj)svect[i]) )
                                 error("substr2np: division by 0");          error("substr2np : inconsistent values for substitution");
                         else if ( !nm )      }
                                 *rp = 0;    }
                         else if ( NUM(dn) ) {    switch ( OID(a) ) {
                                 divsp(vl,nm,dn,&p);      case O_P:
                                 *rp = (Obj)p;        substpp(CO,(P)a,vvect,svect,nv,&nm); *rp = (Obj)nm;
                         } else {        return;
                                 MKRAT(nm,dn,0,r);      case O_R:
                                 *rp = (Obj)r;        substpp(CO,(P)NM((R)a),vvect,svect,nv,&nm);
                         }        substpp(CO,(P)DN((R)a),vvect,svect,nv,&dn);
                         return;        if ( !dn )
                 default:          error("substr2np: division by 0");
                         error("substr2np: invalid argument");        else if ( !nm )
         }          *rp = 0;
         else if ( NUM(dn) ) {
           divsp(CO,nm,dn,&p);
           *rp = (Obj)p;
         } else {
           MKRAT(nm,dn,0,r);
           *rp = (Obj)r;
         }
         return;
       default:
         error("substr2np: invalid argument");
     }
 }  }
   
 void Psubst(arg,rp)  void Psubst(arg,rp)

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>