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

static void parser_resource ( xmlNodePtr  cur,
resourcetype restype 
) [static]

Parse all resources in a resource type.

Parameters:
cur Pointer to the <resourcetype> node.
restype Pointer to the resource type struct for this resource type.

Definition at line 553 of file xmlsup.c.

References FAIL, fatal(), INVPROP, parser_getprop_int(), parser_getprop_str(), parser_newprop_int(), res_find(), res_new(), res_new_matrix(), and resource_t::resid.

Referenced by parser_resources().

{
      char *name, *prefix, *postfix, *fullname;
      int from, to;
      int width, height;
      int n;
      resource *dest;

      while(cur!=NULL) {
            if(!strcmp(cur->name, "resource")) {
                        name=parser_getprop_str(cur, "name");

                        dest=res_find(restype, name);
                        if(dest==NULL) {
                        dest=res_new(restype, name);
                        if(dest==NULL) {
                              fatal(_("Can't allocate memory"));
                        }
                        parser_newprop_int(cur, "resid", dest->resid);
                  } else {
                        FAIL("Resource already defined", cur);
                  }

                  free(name);
                } else if(!strcmp(cur->name, "linear")) {
                        name=parser_getprop_str(cur, "name");
                  from=parser_getprop_int(cur, "from");
                  to=parser_getprop_int(cur, "to");

                  if(from>to) FAIL("Value in 'from' property must be"
                              "smaller than the value in 'to'"
                              "property", cur);

                  postfix=name;
                  prefix=strsep(&postfix, "#");
                  if(postfix==NULL) {
                        FAIL("'name' property must contain '#'", cur);
                  }

                  fullname=malloc(sizeof(*fullname)*LINEBUFFSIZE);
                  if(fullname==NULL) fatal(_("Can't allocate memory"));

                  for(n=from;n<=to;n++) {
                        snprintf(fullname, LINEBUFFSIZE, "%s%d%s", 
                                          prefix, n, postfix);

                        dest=res_new(restype, fullname);
                        if(dest==NULL) {
                              fatal(_("Can't allocate memory"));
                        }
                        if(n==from) {
                              parser_newprop_int(cur, "resid-from", 
                                                dest->resid);
                        } else if(n==to) {
                              parser_newprop_int(cur, "resid-to", 
                                                dest->resid);
                        }
                  }


                  free(fullname);
                  free(name);
                } else if(!strcmp(cur->name, "matrix")) {
                  width=parser_getprop_int(cur, "width");
                  if(width<=0) INVPROP("width", cur);

                  height=parser_getprop_int(cur, "height");
                  if(height<=0) INVPROP("height", cur);

                  dest=res_new_matrix(restype, width, height);

                  if(dest==NULL) {
                        fatal(_("Can't allocate memory"));
                  }

                  parser_newprop_int(cur, "resid-from", 
                                    dest->resid-(height*width)+1);
                  parser_newprop_int(cur, "resid-to", dest->resid);
            }
            cur=cur->next;
      }
}


Generated by  Doxygen 1.6.0   Back to index