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

resource* res_new_matrix ( resourcetype restype,
int  width,
int  height 
)

Adds a matrix of resources to a resource type.

This function adds width * height new resources to the specified resource type. New resources have names "x y", where x goes from 0 to width -1 and y goes from 0 to height -1. Resources are ordered first by y and then by x.

For example:

 x=resid/height;
 y=resid%height;

If there were no resources added to the resource type before the res_new_matrix() function was called, x now holds the x coordinate and y the y coordinate of the resource with resid resource ID in the matrix.

Parameters:
restype Pointer to a resource type structure.
width Width of the matrix.
height Height of the matrix.
Returns:
Pointer to the last resource struct in the matrix on success and NULL on failure.

Definition at line 592 of file data.c.

References res_new().

Referenced by parser_resource().

{
      char *name;
      int n,m,result;
      resource *dest=NULL;

      assert(restype!=NULL);
      assert(width>0);
      assert(height>0);

      name=malloc(LINEBUFFSIZE*sizeof(*name));
      if(name==NULL) return(NULL);

      for(n=0;n<width;n++) {
            for(m=0;m<height;m++) {
                  result=snprintf(name, LINEBUFFSIZE, "%d %d", n, m);
                  if(result>=LINEBUFFSIZE) {
                        free(name);
                        return(NULL);
                  }
                  dest=res_new(restype, name);
                  if(dest==NULL) return(NULL);
            }
      }
      free(name);
      
      return(dest);
}


Generated by  Doxygen 1.6.0   Back to index