version 1.8, 2017/02/07 08:30:31 |
version 1.9, 2018/03/29 01:32:54 |
|
|
* 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.7 2004/03/17 08:16:24 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" |
|
|
|
|
int structdef(char *name,NODE member) |
int structdef(char *name,NODE member) |
{ |
{ |
int i,j; |
int i,j; |
SDEF sdef,s; |
SDEF sdef,s; |
NODE n; |
NODE n; |
char *mname; |
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)) ) |
asir_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(int type,COMP *rp) |
void newstruct(int type,COMP *rp) |
{ |
{ |
if ( type < 0 || type >= LSS->n ) error(""); |
if ( type < 0 || type >= LSS->n ) error(""); |
NEWCOMP(*rp,LSS->sa[type].n); (*rp)->type = type; |
NEWCOMP(*rp,LSS->sa[type].n); (*rp)->type = type; |
} |
} |
|
|
int structtoindex(char *name) |
int structtoindex(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(int type,char *name) |
int membertoindex(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(int type) |
int getcompsize(int type) |
{ |
{ |
return LSS->sa[type].n; |
return LSS->sa[type].n; |
} |
} |
|
|
Obj memberofstruct(COMP a,char *name) |
Obj memberofstruct(COMP a,char *name) |
{ |
{ |
int type,ind; |
int type,ind; |
char buf[BUFSIZ]; |
char buf[BUFSIZ]; |
|
|
if ( !a || OID(a) != O_COMP ) |
if ( !a || OID(a) != O_COMP ) |
error("object is not a structure"); |
error("object is not a structure"); |
type = a->type; |
type = a->type; |
ind = membertoindex(type,name); |
ind = membertoindex(type,name); |
if ( ind < 0 ) { |
if ( ind < 0 ) { |
sprintf(buf,"structure has no member named `%s'",name); |
sprintf(buf,"structure has no member named `%s'",name); |
error(buf); |
error(buf); |
} |
} |
return (Obj)a->member[ind]; |
return (Obj)a->member[ind]; |
} |
} |
|
|
void assign_to_member(COMP a,char *name,Obj obj) |
void assign_to_member(COMP a,char *name,Obj obj) |
{ |
{ |
int type,ind; |
int type,ind; |
char buf[BUFSIZ]; |
char buf[BUFSIZ]; |
|
|
if ( !a || OID(a) != O_COMP ) |
if ( !a || OID(a) != O_COMP ) |
error("object is not a structure"); |
error("object is not a structure"); |
type = a->type; |
type = a->type; |
ind = membertoindex(type,name); |
ind = membertoindex(type,name); |
if ( ind < 0 ) { |
if ( ind < 0 ) { |
sprintf(buf,"structure has no member named `%s'",name); |
sprintf(buf,"structure has no member named `%s'",name); |
error(buf); |
error(buf); |
} |
} |
a->member[ind] = obj; |
a->member[ind] = obj; |
} |
} |