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

resource* res_new ( resourcetype restype,
char *  name 
)

Add a new resource to a resource type.

After the first resource was added, any calls to restype_new() have unspecified effects.

Parameters:
restype Pointer to a resource type structure.
name Name of the resource to add.
Returns:
Pointer to the resource struct on success and NULL on failure.

Definition at line 506 of file data.c.

References resourcetype_t::conflicts, dat_tuplenum, error(), resource_t::name, resourcetype_t::res, RES_ALLOC_CHUNK, res_findid(), resource_t::resid, resourcetype_t::resnum, resource_t::restype, and resourcetype_t::type.

Referenced by parser_resource(), and res_new_matrix().

{
      resource *dest;
      int n;

      assert(restype!=NULL);
      assert(restype->resnum>=0);
      assert(name!=NULL);
      assert(dat_tuplenum==0);

      if(res_findid(restype, name)!=INT_MIN) {
            error(_("Duplicate resource definition (type %s): %s"), 
                                          restype->type, name);
            return(NULL);
      }

      if(restype->resnum%RES_ALLOC_CHUNK==0) {
            n=sizeof(*restype->res)*(restype->resnum+RES_ALLOC_CHUNK);
            restype->res=realloc(restype->res, n);
            if(restype->res==NULL) return(NULL);
      }

      dest=&restype->res[restype->resnum];

      /* Fill in resource struct */

      dest->name=strdup(name);
      dest->restype=restype;

      dest->resid=restype->resnum;

      /* Update resourcetype struct */

      restype->conflicts=realloc(restype->conflicts, 
                  sizeof(*restype->conflicts)*(restype->resnum+1));
      if(restype->conflicts==NULL) {
            free(dest->name);
            return(NULL);
      }
      restype->conflicts[restype->resnum]=NULL;

      for(n=0;n<(restype->resnum+1);n++) {
            restype->conflicts[n]=realloc(restype->conflicts[n],
                  sizeof(*restype->conflicts[n])*(restype->resnum+1));
            if(restype->conflicts[n]==NULL) {
                  free(dest->name);
                  return(NULL);
            }
      }

      for(n=0;n<(restype->resnum+1);n++) {
            restype->conflicts[n][restype->resnum]=0;
            restype->conflicts[restype->resnum][n]=0;
      }

      restype->conflicts[restype->resnum][restype->resnum]=1;

      restype->resnum++;

      return(dest);
}


Generated by  Doxygen 1.6.0   Back to index