Example #1
0
void unique_property(bProperty *first, bProperty *prop, int force)
{
	bProperty *p;

	/* set the first if its not set */
	if (first == NULL) {
		first = prop;
		while (first->prev) {
			first = first->prev;
		}
	}

	if (force) {
		/* change other names to make them unique */
		while ((p = get_property__internal(first, prop, prop->name))) {
			unique_property(first, p, 0);
		}
	}
	else {
		/* change our own name until its unique */
		if (get_property__internal(first, prop, prop->name)) {
			/* there is a collision */
			char new_name[sizeof(prop->name)];
			char base_name[sizeof(prop->name)];
			char num[sizeof(prop->name)];
			int i = 0;

			/* strip numbers */
			BLI_strncpy(base_name, prop->name, sizeof(base_name));
			for (i = strlen(base_name) - 1; (i >= 0 && isdigit(base_name[i])); i--) {
				base_name[i] = '\0';
			}
			i = 0;

			do { /* ensure we have enough chars for the new number in the name */
				BLI_snprintf(num, sizeof(num), "%d", i++);
				BLI_strncpy(new_name, base_name, sizeof(prop->name) - strlen(num));
				strcat(new_name, num);
			} while (get_property__internal(first, prop, new_name));

			BLI_strncpy(prop->name, new_name, sizeof(prop->name));
		}
	}
}
Example #2
0
static void rna_GameProperty_name_set(PointerRNA *ptr, const char *value)
{
	bProperty *prop= (bProperty*)(ptr->data);
	BLI_strncpy(prop->name, value, sizeof(prop->name));
	unique_property(NULL, prop, 1);
}