/* get_grid_item: updates the grid_item with fresh data */ void get_grid_item(void) { int x, y; scew_attribute *a = NULL; scew_element *e = NULL; scew_element *sub_e = NULL; scew_element *r = NULL; POINT p; if (!maptree) return; p = get_mouse_pos(); x = p.x - (p.x % TILE_W); y = p.y - (p.y % TILE_H) + map_offset; r = scew_tree_root(maptree); if (mode == TILE_MODE) { e = scew_element_by_name(r, "Tiles"); } else if (mode == SPRITE_MODE) { e = scew_element_by_name(r, "Sprites"); } else return; sub_e = scew_element_next(e, sub_e); while (sub_e) { a = scew_attribute_by_name(sub_e, "x"); if (x == atoi(scew_attribute_value(a))) { a = scew_attribute_by_name(sub_e, "y"); if (y == atoi(scew_attribute_value(a))) { grid_item.x = x; grid_item.y = y; grid_item.mode = mode; a = scew_attribute_by_name(sub_e, "name"); strncpy(grid_item.name, scew_attribute_value(a), NAME_LN); if (mode == TILE_MODE) { a = scew_attribute_by_name(sub_e, "passable"); grid_item.passable = atoi(scew_attribute_value(a)); } else { grid_item.passable = -1; } break; } } sub_e = scew_element_next(e, sub_e); } }
DLLIMPORT char *Attribute_Value( void *_attribute ) { char* ret_val = NULL; if( _attribute != NULL ) { ret_val = (char*)scew_attribute_value( (scew_attribute*)_attribute ); } return ret_val; }
/******************************************************************************* * Function: Element_Attribute * * This function returns a char * representing a pointer to a NULL terminated * character array, which contains the value associated with the attribute, * specified by the _attr input parameter, of the element specified by the * _element input parameter. * * Parameters: * _element: A void * representing a valid pointer to a scew_element * structure. This pointer must have been created previously by * some other function in this library. * _attr: A char * pointing to a NULL terminated character array, which * contains the name of the attribute in _element, for which to * find a value. * * Returns: * char *: Representing a pointer to a NULL terminated character array, which * contains the value of the attribute of _element, if it exists. * A NULL Pointer is returned on error. * ******************************************************************************/ DLLIMPORT char *Element_Attribute( void *_element, char *_attr ) { char *ret_val = NULL; if ( ( _element != NULL ) && ( _attr != NULL ) ) { scew_attribute *temp = scew_attribute_by_name( _element, _attr ); if ( temp != NULL ) ret_val = (char *)scew_attribute_value( temp ); }; return ret_val; }
static void print_attributes (scew_element *element) { if (element != NULL) { /** * Iterates through the element's attribute list, printing the * pair name-value. */ scew_list *list = scew_element_attributes (element); while (list != NULL) { scew_attribute *attribute = scew_list_data (list); scew_printf (_XT(" %s=\"%s\""), scew_attribute_name (attribute), scew_attribute_value (attribute)); list = scew_list_next (list); } } }
m->has_pending_actions = has_pending_actions; m->has_pending_infections = has_pending_infections; m->to_string = to_string; m->printf = local_printf; m->fprintf = local_fprintf; m->free = local_free; /* Make sure the right XML subtree was sent. */ g_assert (strcmp (scew_element_name (params), MODEL_NAME) == 0); #if DEBUG g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "setting contact type"); #endif attr = scew_attribute_by_name (params, "contact-type"); g_assert (attr != NULL); attr_text = scew_attribute_value (attr); if (strcmp (attr_text, "direct") == 0) local_data->contact_type = NAADSM_DirectContact; else if (strcmp (attr_text, "indirect") == 0) local_data->contact_type = NAADSM_IndirectContact; else g_assert_not_reached (); local_data->contact_type_name = NAADSM_contact_type_abbrev[local_data->contact_type]; #if DEBUG g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "setting production types"); #endif local_data->production_types = herds->production_type_names; local_data->production_type = naadsm_read_prodtype_attribute (params, "production-type", herds->production_type_names);
arcus_system *system_from_xml(scew_element *element) { arcus_system *sys; scew_attribute *attr; const char *attr_val; scew_list *list; scew_element *e; const char *contents; if (!element) { set_error_string("system_from_xml: NULL element"); return NULL; } if (strcmp(scew_element_name(element), "system") != 0) { set_error_string("system_from_xml: element name != 'system'"); return NULL; } sys = system_create(); if (!sys) return NULL; // Get system id attr = scew_element_attribute_by_name(element, "id"); if (!attr) { set_error_string("system_from_xml: system without id"); system_destroy(sys); return NULL; } attr_val = scew_attribute_value(attr); if (!attr_val) { set_error_string("system_from_xml: attribute without value (scew bug?)"); system_destroy(sys); return NULL; } sys->id = strdup(attr_val); // Load metric list = scew_element_list_by_name(element, "metric"); if (!list) { set_error_string("system_create: no metric in system"); system_destroy(sys); return NULL; } if (scew_list_size(list) != 1) { set_error_string("system_create: more than one metric in system"); system_destroy(sys); return NULL; } sys->metric = metric_from_xml((scew_element *)scew_list_data(list)); if (!sys->metric) { system_destroy(sys); return NULL; } // Load christoffel symbols sys->cs = christoffel_from_xml(element); if (!sys->cs) { system_destroy(sys); return NULL; } // Load range list = scew_element_list_by_name(element, "range"); if (!list) { set_error_string("system_create: no range in system"); system_destroy(sys); return NULL; } if (scew_list_size(list) != 1) { set_error_string("system_create: more than one range in system"); system_destroy(sys); return NULL; } e = (scew_element *)scew_list_data(list); if (!e || strcmp(scew_element_name(e), "range") != 0) { set_error_string("system_create: no/wrong range element in list (SCEW bug?)"); system_destroy(sys); return NULL; } contents = scew_element_contents(e); if (!contents || !contents[0]) { set_error_string("system_create: no contents in range element"); system_destroy(sys); return NULL; } if (!af_formula_setexpr(sys->range, contents)) { set_error_string("system_create: cannot set range function expression"); system_destroy(sys); return NULL; } return sys; }