Logo Search packages:      
Sourcecode: tablix2 version File versions  Download package

slist* slist_new ( slist **  list,
int  vartype 
)

Allocate a new slist struct in a linked list.

Linked list is first searched for an identical slist struct. If such a structure is found, only a pointer to it is returned and the linked is is not changed. If no such structure exists, a new structure is allocated and inserted at the beginning of the linked list.

Parameters:
list Pointer to the linked list.
vartype Variable resource type id.
Returns:
Pointer to the new slist struct or NULL on error.

Definition at line 1156 of file data.c.

References dat_tuplenum, dat_typenum, slist_t::next, resourcetype_t::resnum, slist_t::tupleid, slist_t::tuplenum, slist_t::var_typeid, and slist_t::varnum.

Referenced by fitness_request_slist().

{
      slist *cur;
      int n,m;

      assert(list!=NULL);
      assert(vartype<dat_typenum);

      cur=*list;

      while(cur!=NULL) {
            if(cur->var_typeid==vartype) {
                  return(cur);
            }
            cur=cur->next;
      }

      cur=malloc(sizeof(*cur));
      if(cur==NULL) return(NULL);

      cur->var_typeid=vartype;
      cur->varnum=dat_restype[vartype].resnum;

      cur->tuplenum=malloc(sizeof(*cur->tuplenum)*cur->varnum);
      if(cur->tuplenum==NULL) {
            free(cur);
            return(NULL);
      }

      cur->tupleid=malloc(sizeof(*cur->tupleid)*cur->varnum);
      if(cur->tupleid==NULL) {
            free(cur->tuplenum);
            free(cur);
            return(NULL);
      }

      for(n=0;n<cur->varnum;n++) {
            cur->tuplenum[n]=0;
            cur->tupleid[n]=malloc(sizeof(*cur->tupleid[n])*dat_tuplenum);
            if(cur->tupleid[n]==NULL) {
                  for(m=0;m<n;m++) free(cur->tupleid[m]);
                  free(cur->tuplenum);
                  free(cur->tupleid);
                  free(cur);
                  return(NULL);
            }
      }

      cur->next=*list;
      *list=cur;

      return(cur);
}


Generated by  Doxygen 1.6.0   Back to index