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

Diff for /OpenXM_contrib2/asir2000/parse/struct.c between version 1.4 and 1.9

version 1.4, 2000/09/21 09:19:27 version 1.9, 2018/03/29 01:32:54
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/parse/struct.c,v 1.3 2000/08/22 05:04:28 noro Exp $   * $OpenXM: OpenXM_contrib2/asir2000/parse/struct.c,v 1.8 2017/02/07 08:30:31 noro Exp $
 */  */
 #include "ca.h"  #include "ca.h"
 #include "parse.h"  #include "parse.h"
Line 54 
Line 54 
 struct oSS oLSS;  struct oSS oLSS;
 SS LSS = &oLSS;  SS LSS = &oLSS;
   
 int structdef(name,member)  int structdef(char *name,NODE member)
 char *name;  
 NODE member;  
 {  {
         int i,j,k,type;    int i,j;
         SDEF sdef,s;    SDEF sdef,s;
         NODE n,ms;    NODE n;
         char *mname,*sname;    char *mname;
   
         /* search the predefined structure */    /* search the predefined structure */
         for ( s = LSS->sa, i = 0; i < LSS->n; i++ )    for ( s = LSS->sa, i = 0; i < LSS->n; i++ )
                 if ( !strcmp(s[i].name,name) ) {      if ( !strcmp(s[i].name,name) ) {
                         fprintf(stderr,"redeclaration of %s\n",name); break;        fprintf(stderr,"redeclaration of %s\n",name); break;
                 }      }
         if ( !LSS->sa || ((i == LSS->n)&&(LSS->n==LSS->asize)) )    if ( !LSS->sa || ((i == LSS->n)&&(LSS->n==LSS->asize)) )
                 reallocarray((char **)&LSS->sa,(int *)&LSS->asize,(int *)&LSS->n,(int)sizeof(struct oSDEF));      asir_reallocarray((char **)&LSS->sa,(int *)&LSS->asize,(int *)&LSS->n,(int)sizeof(struct oSDEF));
         /* sdef = room for new structure definition */    /* sdef = room for new structure definition */
         sdef = &LSS->sa[i];    sdef = &LSS->sa[i];
         if ( i == LSS->n )    if ( i == LSS->n )
                 LSS->n++;      LSS->n++;
         /* set the name of structure */    /* set the name of structure */
         sdef->name = (char *)MALLOC(strlen(name)+1);    sdef->name = (char *)MALLOC(strlen(name)+1);
         bcopy(name,sdef->name,strlen(name)+1);    bcopy(name,sdef->name,strlen(name)+1);
         /* count the total number of members */    /* count the total number of members */
         for ( j = 0, n = member; n; n = NEXT(n), j++ );    for ( j = 0, n = member; n; n = NEXT(n), j++ );
         sdef->n = j;    sdef->n = j;
         sdef->member = (char **)MALLOC(sdef->n*sizeof(char *));    sdef->member = (char **)MALLOC(sdef->n*sizeof(char *));
         /* set the names of members */    /* set the names of members */
         for ( j = 0, n = member; n; n = NEXT(n), j++ ) {    for ( j = 0, n = member; n; n = NEXT(n), j++ ) {
                 mname = (char *)MALLOC(strlen((char *)BDY(n))+1);      mname = (char *)MALLOC(strlen((char *)BDY(n))+1);
                 bcopy((char *)BDY(n),mname,strlen((char *)BDY(n))+1);      bcopy((char *)BDY(n),mname,strlen((char *)BDY(n))+1);
                 sdef->member[j] = mname;      sdef->member[j] = mname;
         }    }
         return i;    return i;
 }  }
   
 void newstruct(type,rp)  void newstruct(int type,COMP *rp)
 int type;  
 COMP *rp;  
 {  {
         NEWCOMP(*rp,LSS->sa[type].n); (*rp)->type = type;    if ( type < 0 || type >= LSS->n ) error("");
     NEWCOMP(*rp,LSS->sa[type].n); (*rp)->type = type;
 }  }
   
 int structtoindex(name)  int structtoindex(char *name)
 char *name;  
 {  {
         SDEF s;    SDEF s;
         int i;    int i;
   
         for ( s = LSS->sa, i = 0; i < LSS->n; i++ )    for ( s = LSS->sa, i = 0; i < LSS->n; i++ )
                 if ( !strcmp(s[i].name,name) )      if ( !strcmp(s[i].name,name) )
                         break;        break;
         if ( i == LSS->n ) {    if ( i == LSS->n ) {
                 fprintf(stderr,"%s: undefined structure\n",name); return -1; /* XXX */      fprintf(stderr,"%s: undefined structure\n",name); return -1; /* XXX */
         } else    } else
                 return i;      return i;
 }  }
   
 int membertoindex(type,name)  int membertoindex(int type,char *name)
 int type;  
 char *name;  
 {  {
         SDEF s;    SDEF s;
         char **member;    char **member;
         int i;    int i;
   
         s = &LSS->sa[type];    s = &LSS->sa[type];
         for ( member = s->member, i = 0; i < s->n; i++ )    for ( member = s->member, i = 0; i < s->n; i++ )
                 if ( !strcmp(member[i],name) )      if ( !strcmp(member[i],name) )
                         break;        break;
         if ( i == s->n )    if ( i == s->n )
                 return -1;      return -1;
         else    else
                 return i;      return i;
 }  }
   
 int getcompsize(type)  int getcompsize(int type)
 int type;  
 {  {
         return LSS->sa[type].n;    return LSS->sa[type].n;
 }  }
   
 #if 0  Obj memberofstruct(COMP a,char *name)
 void getmember(expr,memp)  
 FNODE expr;  
 Obj *memp;  
 {  {
         int i;    int type,ind;
         FNODE root;    char buf[BUFSIZ];
         COMP t;  
         PV v0;  
         NODE2 mchain;  
   
         root = (FNODE)FA1(expr); mchain = (NODE2)FA2(expr);    if ( !a || OID(a) != O_COMP )
         if ( ID(root) == I_PVAR ) {      error("object is not a structure");
                 i = (int)FA0(root);    type = a->type;
                 v0 = i>=0?&CPVS->va[(unsigned int)i]:&GPVS->va[((unsigned int)i)&~MSB];    ind = membertoindex(type,name);
                 t = (COMP)v0->priv;    if ( ind < 0 ) {
         } else      sprintf(buf,"structure has no member named `%s'",name);
                 t = (COMP)eval(root);      error(buf);
         for ( ; mchain; mchain = NEXT(mchain) )    }
                 t = (COMP)(t->member[(int)BDY1(mchain)]);    return (Obj)a->member[ind];
         *memp = (Obj)t;  
 }  }
   
 void getmemberp(expr,addrp)  void assign_to_member(COMP a,char *name,Obj obj)
 FNODE expr;  
 Obj **addrp;  
 {  {
         int i;    int type,ind;
         FNODE root;    char buf[BUFSIZ];
         COMP t;  
         PV v0;  
         COMP *addr;  
         NODE2 mchain;  
   
         root = (FNODE)FA1(expr); mchain = (NODE2)FA2(expr);    if ( !a || OID(a) != O_COMP )
         if ( ID(root) == I_PVAR ) {      error("object is not a structure");
                 i = (int)FA0(root);    type = a->type;
                 v0 = i>=0?&CPVS->va[(unsigned int)i]:&GPVS->va[((unsigned int)i)&~MSB];    ind = membertoindex(type,name);
                 addr = (COMP *)&v0->priv;    if ( ind < 0 ) {
         } else {      sprintf(buf,"structure has no member named `%s'",name);
                 t = (COMP)eval(root);      error(buf);
                 addr = (COMP *)&t;    }
         }    a->member[ind] = obj;
         for ( ; mchain; mchain = NEXT(mchain) )  
                 addr = (COMP *)&((*addr)->member[(int)BDY1(mchain)]);  
         *addrp = (Obj *)addr;  
 }  
   
 void getarrayp(a,ind,addrp)  
 Obj a;  
 NODE ind;  
 Obj **addrp;  
 {  
         Obj len,row,col;  
         Obj *addr;  
   
         switch ( OID(a) ) {  
                 case O_VECT:  
                         len = (Obj)BDY(ind);  
                         if ( !rangecheck(len,((VECT)a)->len) )  
                                 error("getarrayp : Out of range");  
                         else  
                                 addr = (Obj *)&(BDY((VECT)a)[QTOS((Q)len)]);  
                         break;  
                 case O_MAT:  
                         row = (Obj)BDY(ind); col = (Obj)BDY(NEXT(ind));  
                         if ( !rangecheck(row,((MAT)a)->row)  
                                 || !rangecheck(col,((MAT)a)->col) )  
                                 error("getarrayp : Out of range");  
                         else  
                                 addr = (Obj *)&(BDY((MAT)a)[QTOS((Q)row)][QTOS((Q)col)]);  
                         break;  
                 default:  
                                 addr = 0;  
                         break;  
         }  
         *addrp = addr;  
 }  
 #endif  
   
 Obj memberofstruct(a,name)  
 COMP a;  
 char *name;  
 {  
         NODE2 n,*np;  
         int type,ind;  
         char buf[BUFSIZ];  
   
         if ( !a || OID(a) != O_COMP )  
                 error("object is not a structure");  
         type = a->type;  
         ind = membertoindex(type,name);  
         if ( ind < 0 ) {  
                 sprintf(buf,"structure has no member named `%s'",name);  
                 error(buf);  
         }  
         return (Obj)a->member[ind];  
 }  
   
 void assign_to_member(a,name,obj)  
 COMP a;  
 char *name;  
 Obj obj;  
 {  
         NODE2 n,*np;  
         int type,ind;  
         char buf[BUFSIZ];  
   
         if ( !a || OID(a) != O_COMP )  
                 error("object is not a structure");  
         type = a->type;  
         ind = membertoindex(type,name);  
         if ( ind < 0 ) {  
                 sprintf(buf,"structure has no member named `%s'",name);  
                 error(buf);  
         }  
         a->member[ind] = obj;  
 }  }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.9

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