diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-12-26 16:26:11 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-12-26 16:26:11 +0400 |
commit | e17fd46c71e0401fefecf22fa8975fc5826d8fe9 (patch) | |
tree | 7c8afe24927c1dfdb5cf14a8deeb61691e1ec0c3 /source/blender/python/generic/bpy_internal_import.c | |
parent | f48fb385ea8dc6b12e12a6ec46a0c0b55d2dfcc4 (diff) |
formatting edits only to use more consisted style
Diffstat (limited to 'source/blender/python/generic/bpy_internal_import.c')
-rw-r--r-- | source/blender/python/generic/bpy_internal_import.c | 94 |
1 files changed, 48 insertions, 46 deletions
diff --git a/source/blender/python/generic/bpy_internal_import.c b/source/blender/python/generic/bpy_internal_import.c index d9183261329..db3519a3056 100644 --- a/source/blender/python/generic/bpy_internal_import.c +++ b/source/blender/python/generic/bpy_internal_import.c @@ -51,7 +51,7 @@ #include "BKE_text.h" /* txt_to_buf */ #include "BKE_main.h" -static Main *bpy_import_main= NULL; +static Main *bpy_import_main = NULL; /* 'builtins' is most likely PyEval_GetBuiltins() */ void bpy_import_init(PyObject *builtins) @@ -59,13 +59,13 @@ void bpy_import_init(PyObject *builtins) PyObject *item; PyObject *mod; - PyDict_SetItemString(builtins, "__import__", item=PyCFunction_New(&bpy_import_meth, NULL)); Py_DECREF(item); + PyDict_SetItemString(builtins, "__import__", item = PyCFunction_New(&bpy_import_meth, NULL)); Py_DECREF(item); /* move reload here * XXX, use import hooks */ - mod= PyImport_ImportModuleLevel((char *)"imp", NULL, NULL, NULL, 0); + mod = PyImport_ImportModuleLevel((char *)"imp", NULL, NULL, NULL, 0); if (mod) { - PyDict_SetItemString(PyModule_GetDict(mod), "reload", item=PyCFunction_New(&bpy_reload_meth, NULL)); Py_DECREF(item); + PyDict_SetItemString(PyModule_GetDict(mod), "reload", item = PyCFunction_New(&bpy_reload_meth, NULL)); Py_DECREF(item); Py_DECREF(mod); } else { @@ -79,7 +79,7 @@ static void free_compiled_text(Text *text) if (text->compiled) { Py_DECREF((PyObject *)text->compiled); } - text->compiled= NULL; + text->compiled = NULL; } struct Main *bpy_import_main_get(void) @@ -89,18 +89,18 @@ struct Main *bpy_import_main_get(void) void bpy_import_main_set(struct Main *maggie) { - bpy_import_main= maggie; + bpy_import_main = maggie; } /* returns a dummy filename for a textblock so we can tell what file a text block comes from */ void bpy_text_filename_get(char *fn, size_t fn_len, Text *text) { - BLI_snprintf(fn, fn_len, "%s%c%s", ID_BLEND_PATH(bpy_import_main, &text->id), SEP, text->id.name+2); + BLI_snprintf(fn, fn_len, "%s%c%s", ID_BLEND_PATH(bpy_import_main, &text->id), SEP, text->id.name + 2); } PyObject *bpy_text_import(Text *text) { - char *buf= NULL; + char *buf = NULL; char modulename[24]; int len; @@ -108,8 +108,8 @@ PyObject *bpy_text_import(Text *text) char fn_dummy[256]; bpy_text_filename_get(fn_dummy, sizeof(fn_dummy), text); - buf= txt_to_buf(text); - text->compiled= Py_CompileString(buf, fn_dummy, Py_file_input); + buf = txt_to_buf(text); + text->compiled = Py_CompileString(buf, fn_dummy, Py_file_input); MEM_freeN(buf); if (PyErr_Occurred()) { @@ -121,21 +121,21 @@ PyObject *bpy_text_import(Text *text) } } - len= strlen(text->id.name+2); - BLI_strncpy(modulename, text->id.name+2, len); - modulename[len - 3]= '\0'; /* remove .py */ + len = strlen(text->id.name + 2); + BLI_strncpy(modulename, text->id.name + 2, len); + modulename[len - 3] = '\0'; /* remove .py */ return PyImport_ExecCodeModule(modulename, text->compiled); } PyObject *bpy_text_import_name(const char *name, int *found) { Text *text; - char txtname[MAX_ID_NAME-2]; - int namelen= strlen(name); -//XXX Main *maggie= bpy_import_main ? bpy_import_main:G.main; - Main *maggie= bpy_import_main; + char txtname[MAX_ID_NAME - 2]; + int namelen = strlen(name); +//XXX Main *maggie = bpy_import_main ? bpy_import_main:G.main; + Main *maggie = bpy_import_main; - *found= 0; + *found = 0; if (!maggie) { printf("ERROR: bpy_import_main_set() was not called before running python. this is a bug.\n"); @@ -143,17 +143,17 @@ PyObject *bpy_text_import_name(const char *name, int *found) } /* we know this cant be importable, the name is too long for blender! */ - if (namelen >= (MAX_ID_NAME-2) - 3) return NULL; + if (namelen >= (MAX_ID_NAME - 2) - 3) return NULL; memcpy(txtname, name, namelen); memcpy(&txtname[namelen], ".py", 4); - text= BLI_findstring(&maggie->text, txtname, offsetof(ID, name) + 2); + text = BLI_findstring(&maggie->text, txtname, offsetof(ID, name) + 2); if (!text) return NULL; else - *found= 1; + *found = 1; return bpy_text_import(text); } @@ -168,32 +168,32 @@ PyObject *bpy_text_reimport(PyObject *module, int *found) Text *text; const char *name; char *filepath; - char *buf= NULL; -//XXX Main *maggie= bpy_import_main ? bpy_import_main:G.main; - Main *maggie= bpy_import_main; + char *buf = NULL; +//XXX Main *maggie = bpy_import_main ? bpy_import_main:G.main; + Main *maggie = bpy_import_main; if (!maggie) { printf("ERROR: bpy_import_main_set() was not called before running python. this is a bug.\n"); return NULL; } - *found= 0; + *found = 0; /* get name, filename from the module itself */ - if ((name= PyModule_GetName(module)) == NULL) + if ((name = PyModule_GetName(module)) == NULL) return NULL; - if ((filepath= (char *)PyModule_GetFilename(module)) == NULL) + if ((filepath = (char *)PyModule_GetFilename(module)) == NULL) return NULL; /* look up the text object */ - text= BLI_findstring(&maggie->text, BLI_path_basename(filepath), offsetof(ID, name) + 2); + text = BLI_findstring(&maggie->text, BLI_path_basename(filepath), offsetof(ID, name) + 2); /* uh-oh.... didn't find it */ if (!text) return NULL; else - *found= 1; + *found = 1; /* if previously compiled, free the object */ /* (can't see how could be NULL, but check just in case) */ @@ -202,8 +202,8 @@ PyObject *bpy_text_reimport(PyObject *module, int *found) } /* compile the buffer */ - buf= txt_to_buf(text); - text->compiled= Py_CompileString(buf, text->id.name+2, Py_file_input); + buf = txt_to_buf(text); + text->compiled = Py_CompileString(buf, text->id.name + 2, Py_file_input); MEM_freeN(buf); /* if compile failed.... return this error */ @@ -224,20 +224,22 @@ static PyObject *blender_import(PyObject *UNUSED(self), PyObject *args, PyObject { PyObject *exception, *err, *tb; char *name; - int found= 0; - PyObject *globals= NULL, *locals= NULL, *fromlist= NULL; - int level= -1; /* relative imports */ + int found = 0; + PyObject *globals = NULL, *locals = NULL, *fromlist = NULL; + int level = -1; /* relative imports */ PyObject *newmodule; //PyObject_Print(args, stderr, 0); - static const char *kwlist[]= {"name", "globals", "locals", "fromlist", "level", NULL}; + static const char *kwlist[] = {"name", "globals", "locals", "fromlist", "level", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kw, "s|OOOi:bpy_import_meth", (char **)kwlist, - &name, &globals, &locals, &fromlist, &level)) + &name, &globals, &locals, &fromlist, &level)) + { return NULL; + } /* import existing builtin modules or modules that have been imported already */ - newmodule= PyImport_ImportModuleLevel(name, globals, locals, fromlist, level); + newmodule = PyImport_ImportModuleLevel(name, globals, locals, fromlist, level); if (newmodule) return newmodule; @@ -245,7 +247,7 @@ static PyObject *blender_import(PyObject *UNUSED(self), PyObject *args, PyObject PyErr_Fetch(&exception, &err, &tb); /* get the python error incase we cant import as blender text either */ /* importing from existing modules failed, see if we have this module as blender text */ - newmodule= bpy_text_import_name(name, &found); + newmodule = bpy_text_import_name(name, &found); if (newmodule) {/* found module as blender text, ignore above exception */ PyErr_Clear(); @@ -254,7 +256,7 @@ static PyObject *blender_import(PyObject *UNUSED(self), PyObject *args, PyObject Py_XDECREF(tb); /* printf("imported from text buffer...\n"); */ } - else if (found==1) { /* blender text module failed to execute but was found, use its error message */ + else if (found == 1) { /* blender text module failed to execute but was found, use its error message */ Py_XDECREF(exception); Py_XDECREF(err); Py_XDECREF(tb); @@ -276,18 +278,18 @@ static PyObject *blender_import(PyObject *UNUSED(self), PyObject *args, PyObject static PyObject *blender_reload(PyObject *UNUSED(self), PyObject *module) { PyObject *exception, *err, *tb; - PyObject *newmodule= NULL; - int found= 0; + PyObject *newmodule = NULL; + int found = 0; /* try reimporting from file */ - newmodule= PyImport_ReloadModule(module); + newmodule = PyImport_ReloadModule(module); if (newmodule) return newmodule; /* no file, try importing from memory */ PyErr_Fetch(&exception, &err, &tb); /*restore for probable later use */ - newmodule= bpy_text_reimport(module, &found); + newmodule = bpy_text_reimport(module, &found); if (newmodule) {/* found module as blender text, ignore above exception */ PyErr_Clear(); Py_XDECREF(exception); @@ -295,7 +297,7 @@ static PyObject *blender_reload(PyObject *UNUSED(self), PyObject *module) Py_XDECREF(tb); /* printf("imported from text buffer...\n"); */ } - else if (found==1) { /* blender text module failed to execute but was found, use its error message */ + else if (found == 1) { /* blender text module failed to execute but was found, use its error message */ Py_XDECREF(exception); Py_XDECREF(err); Py_XDECREF(tb); @@ -310,5 +312,5 @@ static PyObject *blender_reload(PyObject *UNUSED(self), PyObject *module) return newmodule; } -PyMethodDef bpy_import_meth= {"bpy_import_meth", (PyCFunction)blender_import, METH_VARARGS | METH_KEYWORDS, "blenders import"}; -PyMethodDef bpy_reload_meth= {"bpy_reload_meth", (PyCFunction)blender_reload, METH_O, "blenders reload"}; +PyMethodDef bpy_import_meth = {"bpy_import_meth", (PyCFunction)blender_import, METH_VARARGS | METH_KEYWORDS, "blenders import"}; +PyMethodDef bpy_reload_meth = {"bpy_reload_meth", (PyCFunction)blender_reload, METH_O, "blenders reload"}; |