[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49384] branches/ge_components/source/ blender: Style cleanup:

Mitchell Stokes mogurijin at gmail.com
Mon Jul 30 09:31:31 CEST 2012


Revision: 49384
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49384
Author:   moguri
Date:     2012-07-30 07:31:31 +0000 (Mon, 30 Jul 2012)
Log Message:
-----------
Style cleanup:
  * Switched to K&R bracing for loops and ifs.
  * Changed C++ style comments to C style comments in C code.

Modified Paths:
--------------
    branches/ge_components/source/blender/blenkernel/intern/python_component.c
    branches/ge_components/source/blender/editors/space_logic/logic_ops.c

Modified: branches/ge_components/source/blender/blenkernel/intern/python_component.c
===================================================================
--- branches/ge_components/source/blender/blenkernel/intern/python_component.c	2012-07-30 07:23:38 UTC (rev 49383)
+++ branches/ge_components/source/blender/blenkernel/intern/python_component.c	2012-07-30 07:31:31 UTC (rev 49384)
@@ -26,18 +26,16 @@
 
 	list = PyObject_GetAttrString(cls, "__bases__");
 
-	for (i=0; i<PyTuple_Size(list); ++i)
-	{
+	for (i=0; i<PyTuple_Size(list); ++i) {
 		item = PyObject_GetAttrString(PyTuple_GetItem(list, i), "__name__");
 		name = _PyUnicode_AsString(item);
 
 
-		// We don't want to decref until after the comprison
+		/* We don't want to decref until after the comparison */
 		comp = strcmp("KX_PythonComponent", name);
 		Py_DECREF(item);
 
-		if (comp == 0)
-		{
+		if (comp == 0) {
 			Py_DECREF(list);
 			return 1;
 		}
@@ -54,44 +52,40 @@
 	char cls[64], path[64];
 	int i, last_dot;
 
-	// Don't bother with an empty string
+	/* Don't bother with an empty string */
 	if (strcmp(import, "") == 0)
 		return NULL;
 
-	// Split the class and module
+	/* Split the class and module */
 	last_dot_str = strrchr(import, '.');
 	last_dot = (int)(last_dot_str-import) + 1;
 
 
-	if(last_dot > 0)
-	{
+	if(last_dot > 0) {
 		BLI_strncpy(path, import, last_dot);
 		strcpy(cls, import+last_dot);
 	}
-	else
-	{
+	else {
 		printf("No component class was specified, only the module was.\n");
 		return NULL;
 	}
 
-	// Try to load up the module
+	/* Try to load up the module */
 	mod = PyImport_ImportModule(path);
 
-	if (mod)
-	{
-		// Get the list of objects in the module
+	if (mod) {
+		/* Get the list of objects in the module */
 		mod_list = PyDict_Values(PyModule_GetDict(mod));
 
-		// Now iterate the list
-		for (i=0; i<PyList_Size(mod_list); ++i)
-		{
+		/* Now iterate the list */
+		for (i=0; i<PyList_Size(mod_list); ++i)	{
 			item = PyList_GetItem(mod_list, i);
 
-			// We only want to bother checking type objects
+			/* We only want to bother checking type objects */
 			if (!PyType_Check(item))
 				continue;
 			
-			// Make sure the name matches
+			/* Make sure the name matches */
 			py_name = PyObject_GetAttrString(item, "__name__");
 			name = _PyUnicode_AsString(py_name);
 			Py_DECREF(py_name);
@@ -99,14 +93,12 @@
 			if (strcmp(name, cls) != 0)
 				continue;
 
-			// Check the subclass with our own function since we don't have access to the KX_PythonComponent type object
-			if (!verify_class(item))
-			{
+			/* Check the subclass with our own function since we don't have access to the KX_PythonComponent type object */
+			if (!verify_class(item)) {
 				printf("A %s type was found, but it was not a valid subclass of KX_PythonComponent\n", cls);
 			}
-			else
-			{
-				// We have a valid class, return it
+			else {
+				/* We have a valid class, return it */
 				if (cls_r) strcpy(cls_r, cls);
 				if (path_r) strcpy(path_r, path);
 				pyclass = item;
@@ -114,18 +106,17 @@
 		}
 
 		if (!pyclass)
-			// If we got here, then we didn't find a suitable class
+			/* If we got here, then we didn't find a suitable class */
 			printf("No suitable class was found for a component at %s\n", import);
 
-		// Take the module out of the module list so it's not cached by Python (this allows for simpler reloading of components)
+		/* Take the module out of the module list so it's not cached by Python (this allows for simpler reloading of components) */
 		PyDict_DelItemString(PyImport_GetModuleDict(), path);
 
-		// Cleanup our Python objects
+		/* Cleanup our Python objects */
 		Py_DECREF(mod);
 		Py_DECREF(mod_list);
 	}
-	else
-	{
+	else {
 		PyErr_Print();
 		printf("Unable to load component from %s\n", import);
 	}
@@ -142,8 +133,7 @@
 
 	cprop = pc->properties.first;
 
-	while (cprop)
-	{
+	while (cprop) {
 		if (cprop->type == CPROP_TYPE_INT)
 			value = PyLong_FromLong(cprop->data);
 		else if (cprop->type == CPROP_TYPE_FLOAT)
@@ -170,8 +160,7 @@
 
 	cprop = MEM_mallocN(sizeof(ComponentProperty), "ComponentProperty");
 
-	if (cprop)
-	{
+	if (cprop) {
 		BLI_strncpy(cprop->name, name, sizeof(cprop->name));
 		cprop->type = type;
 
@@ -186,8 +175,7 @@
 			cprop->data = data;
 		else if (type == CPROP_TYPE_STRING)
 			cprop->poin = poin;
-		else if (type == CPROP_TYPE_SET)
-		{
+		else if (type == CPROP_TYPE_SET) {
 			cprop->poin = poin;
 			cprop->data = 0;
 		}
@@ -198,8 +186,7 @@
 
 static void free_component_property(ComponentProperty *cprop)
 {
-	if (cprop->type == CPROP_TYPE_SET && cprop->poin)
-	{
+	if (cprop->type == CPROP_TYPE_SET && cprop->poin) {
 		int i;
 		for (i=0; ((char**)cprop->poin)[i]; ++i)
 			MEM_freeN(((char**)cprop->poin)[i]);
@@ -230,26 +217,25 @@
 
 	args_dict = PyObject_GetAttrString(cls, "args");
 
-	// If there is no args dict, then we are already done
-	if (args_dict == NULL || !PyDict_Check(args_dict))
-	{
+	/* If there is no args dict, then we are already done */
+	if (args_dict == NULL || !PyDict_Check(args_dict)) {
 		Py_XDECREF(args_dict);
 		return;
 	}
 
-	// Otherwise, parse the dict:
-	// key => value
-	// key = property name
-	// value = default value
-	// type(value) = property type
+	/**
+	 * Otherwise, parse the dict:
+	 * key => value
+	 * key = property name
+	 * value = default value
+	 * type(value) = property type
+	 */
 	items = PyMapping_Items(args_dict);
 
 	/* First clear out any unused properties */
 	cprop = pycomp->properties.first;
-	while (cprop)
-	{
-		if (!PyMapping_HasKeyString(args_dict, cprop->name))
-		{
+	while (cprop) {
+		if (!PyMapping_HasKeyString(args_dict, cprop->name)) {
 			oldprop = cprop;
 			cprop = cprop->next;
 			BLI_remlink(&pycomp->properties, oldprop);
@@ -261,56 +247,48 @@
 	}
 
 	/* Then add new ones */
-	for (i=0; i<PyList_Size(items); ++i)
-	{
+	for (i=0; i<PyList_Size(items); ++i) {
 		item = PyList_GetItem(items, i);
 		key = PyTuple_GetItem(item, 0);
 		value = PyTuple_GetItem(item, 1);
 
-		// Make sure type(key) == string
-		if (!PyUnicode_Check(key))
-		{
+		/* Make sure type(key) == string */
+		if (!PyUnicode_Check(key)) {
 			printf("Non-string key found in the args dictionary, skipping\n");
 			continue;
 		}
 
 		BLI_strncpy(name, _PyUnicode_AsString(key), sizeof(name));
 
-		// Determine the type and default value
-		if (PyBool_Check(value))
-		{
+		/* Determine the type and default value */
+		if (PyBool_Check(value)) {
 			type = CPROP_TYPE_BOOLEAN;
 			data = PyLong_AsLong(value) != 0;
 		}
-		else if (PyLong_Check(value))
-		{
+		else if (PyLong_Check(value)) {
 			type = CPROP_TYPE_INT;
 			data = PyLong_AsLong(value);
 		}
-		else if (PyFloat_Check(value))
-		{
+		else if (PyFloat_Check(value)) {
 			type = CPROP_TYPE_FLOAT;
 			*((float*)&data) = (float)PyFloat_AsDouble(value);
 		}
-		else if (PyUnicode_Check(value))
-		{
+		else if (PyUnicode_Check(value)) {
 			type = CPROP_TYPE_STRING;
 			poin = MEM_callocN(MAX_PROPSTRING, "ComponentProperty string");
 			BLI_strncpy((char*)poin, _PyUnicode_AsString(value), MAX_PROPSTRING);
 		}
-		else if (PySet_Check(value))
-		{
+		else if (PySet_Check(value)) {
 			int len = PySet_Size(value), i=0;
 			char **items;
 			PyObject *iterator = PyObject_GetIter(value), *v=NULL;
 			char *str;
 			type = CPROP_TYPE_SET;
 
-			// Create an EnumPropertyItem array
+			/* Create an EnumPropertyItem array */
 			poin = MEM_callocN(sizeof(char*)*(len+1), "ComponentProperty set");
 			items = (char**)poin;
-			while (v = PyIter_Next(iterator))
-			{
+			while (v = PyIter_Next(iterator)) {
 
 				str = MEM_callocN(MAX_PROPSTRING, "ComponentProperty set string");
 				BLI_strncpy(str, _PyUnicode_AsString(v), MAX_PROPSTRING);
@@ -321,22 +299,18 @@
 
 			data = 0;
 		}
-		else
-		{
-			// Unsupported type
+		else {
+			/* Unsupported type */
 			printf("Unsupported type found for args[%s], skipping\n", name);
 			continue;
 		}
 
 		/* Check to see if we already have this property, if so, so if we need to update it */
 		cprop = pycomp->properties.first;
-		while (cprop)
-		{
-			if (strcmp(cprop->name, name) == 0)
-			{
+		while (cprop) {
+			if (strcmp(cprop->name, name) == 0)	{
 				/* double check the type */
-				if (cprop->type != type)
-				{
+				if (cprop->type != type) {
 					BLI_remlink(&pycomp->properties, cprop);
 					free_component_property(cprop);
 					cprop = NULL;
@@ -348,14 +322,13 @@
 			cprop = cprop->next;
 		}
 
-		if (!cprop)
-		{
+		if (!cprop)	{
 			cprop = create_property(name, type, data, poin);
 
 			if (cprop)
 				BLI_addtail(&pycomp->properties, cprop);
 			else
-				// Cleanup poin if it's set
+				/* Cleanup poin if it's set */
 				if (poin) MEM_freeN(poin);
 		}
 	}
@@ -373,15 +346,14 @@
 	char cls[64], path[64];
 	state = PyGILState_Ensure();
 
-	if (pyclass = get_class_from_import(import, cls, path))
-	{
+	if (pyclass = get_class_from_import(import, cls, path))	{
 	
 		pc = MEM_callocN(sizeof(PythonComponent), "PythonComponent");
 
 		strcpy(pc->module, path);
 		strcpy(pc->name, cls);
 
-		// Setup the properties
+		/* Setup the properties */
 		create_properties(pc, pyclass);
 	}
 
@@ -399,8 +371,7 @@
 
 	state = PyGILState_Ensure();
 
-	if (pyclass = get_class_from_import(import, NULL, NULL))
-	{
+	if (pyclass = get_class_from_import(import, NULL, NULL)) {
 		create_properties(pc, pyclass);
 	}
 

Modified: branches/ge_components/source/blender/editors/space_logic/logic_ops.c
===================================================================
--- branches/ge_components/source/blender/editors/space_logic/logic_ops.c	2012-07-30 07:23:38 UTC (rev 49383)
+++ branches/ge_components/source/blender/editors/space_logic/logic_ops.c	2012-07-30 07:31:31 UTC (rev 49384)
@@ -816,13 +816,11 @@
 	if(!ob)
 		return OPERATOR_CANCELLED;
 
-	if (index > 0)
-	{
+	if (index > 0) {
 		prev_pc= BLI_findlink(&ob->components, index-1);
 		pc = prev_pc->next;
 	}
-	else
-	{
+	else {
 		/* pc is at the head */
 		pc = BLI_findlink(&ob->components, index);
 	}




More information about the Bf-blender-cvs mailing list