add STREQ macro (commonly used macro like CLAMP, MAX2, STRINGIFY). Use for some areas of the python api, bmesh.
This commit is contained in:
@@ -103,7 +103,7 @@ static int builtin_font_size = 0;
|
||||
|
||||
bool BKE_vfont_is_builtin(struct VFont *vfont)
|
||||
{
|
||||
return (strcmp(vfont->name, FO_BUILTIN_NAME) == 0);
|
||||
return STREQ(vfont->name, FO_BUILTIN_NAME);
|
||||
}
|
||||
|
||||
void BKE_vfont_builtin_register(void *mem, int size)
|
||||
@@ -188,7 +188,7 @@ VFont *BKE_vfont_load(Main *bmain, const char *name)
|
||||
PackedFile *temp_pf = NULL;
|
||||
int is_builtin;
|
||||
|
||||
if (strcmp(name, FO_BUILTIN_NAME) == 0) {
|
||||
if (STREQ(name, FO_BUILTIN_NAME)) {
|
||||
BLI_strncpy(filename, name, sizeof(filename));
|
||||
|
||||
pf = get_builtin_packedfile();
|
||||
|
||||
@@ -89,9 +89,11 @@ static IDType *idtype_from_name(const char *str)
|
||||
{
|
||||
int i = nidtypes;
|
||||
|
||||
while (i--)
|
||||
if (strcmp(str, idtypes[i].name) == 0)
|
||||
while (i--) {
|
||||
if (STREQ(str, idtypes[i].name)) {
|
||||
return &idtypes[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -451,7 +451,7 @@ void IDP_ReplaceGroupInGroup(IDProperty *dest, IDProperty *src)
|
||||
IDProperty *loop, *prop;
|
||||
for (prop = src->data.group.first; prop; prop = prop->next) {
|
||||
for (loop = dest->data.group.first; loop; loop = loop->next) {
|
||||
if (strcmp(loop->name, prop->name) == 0) {
|
||||
if (STREQ(loop->name, prop->name)) {
|
||||
IDProperty *copy = IDP_CopyProperty(prop);
|
||||
|
||||
BLI_insertlinkafter(&dest->data.group, loop, copy);
|
||||
|
||||
@@ -856,7 +856,7 @@ static void seqbase_unique_name(ListBase *seqbasep, SeqUniqueInfo *sui)
|
||||
{
|
||||
Sequence *seq;
|
||||
for (seq = seqbasep->first; seq; seq = seq->next) {
|
||||
if (sui->seq != seq && strcmp(sui->name_dest, seq->name + 2) == 0) {
|
||||
if ((sui->seq != seq) && STREQ(sui->name_dest, seq->name + 2)) {
|
||||
/* SEQ_NAME_MAXSTR - 2 for prefix, -1 for \0, -4 for the number */
|
||||
BLI_snprintf(sui->name_dest, sizeof(sui->name_dest), "%.59s.%03d", sui->name_src, sui->count++);
|
||||
sui->match = 1; /* be sure to re-scan */
|
||||
@@ -3861,7 +3861,7 @@ Sequence *BKE_sequence_get_by_name(ListBase *seqbase, const char *name, int recu
|
||||
Sequence *rseq = NULL;
|
||||
|
||||
for (iseq = seqbase->first; iseq; iseq = iseq->next) {
|
||||
if (strcmp(name, iseq->name + 2) == 0)
|
||||
if (STREQ(name, iseq->name + 2))
|
||||
return iseq;
|
||||
else if (recursive && (iseq->seqbase.first) && (rseq = BKE_sequence_get_by_name(&iseq->seqbase, name, 1))) {
|
||||
return rseq;
|
||||
|
||||
@@ -326,6 +326,22 @@ typedef bool _BLI_Bool;
|
||||
#define STRINGIFY_APPEND(a, b) "" a #b
|
||||
#define STRINGIFY(x) STRINGIFY_APPEND("", x)
|
||||
|
||||
/* generic strcmp macros */
|
||||
#define STREQ(a, b) (strcmp(a, b) == 0)
|
||||
#define STRNEQ(a, b) (!STREQ(a, b))
|
||||
|
||||
#define STRCASEEQ(a, b) (strcasecmp(a, b) == 0)
|
||||
#define STRCASENEQ(a, b) (!STRCASEEQ(a, b))
|
||||
|
||||
#define STREQLEN(a, b, n) (strncmp(a, b, n) == 0)
|
||||
#define STRNEQLEN(a, b, n) (!STREQLEN(a, b, n))
|
||||
|
||||
#define STRCASEEQLEN(a, b, n) (strncasecmp(a, b, n) == 0)
|
||||
#define STRCASENEQLEN(a, b, n) (!STRCASEEQLEN(a, b, n))
|
||||
|
||||
#define STRPREFIX(a, b) (strncmp((a), (b), strlen(b)) == 0)
|
||||
|
||||
|
||||
/* useful for debugging */
|
||||
#define AT __FILE__ ":" STRINGIFY(__LINE__)
|
||||
|
||||
|
||||
@@ -1521,7 +1521,7 @@ static int bmo_name_to_slotcode(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char
|
||||
int i = 0;
|
||||
|
||||
while (slot_args->slot_name) {
|
||||
if (strncmp(identifier, slot_args->slot_name, MAX_SLOTNAME) == 0) {
|
||||
if (STREQLEN(identifier, slot_args->slot_name, MAX_SLOTNAME)) {
|
||||
return i;
|
||||
}
|
||||
slot_args++;
|
||||
@@ -1546,7 +1546,7 @@ static int bmo_opname_to_opcode(const char *opname)
|
||||
int i;
|
||||
|
||||
for (i = 0; i < bmo_opdefines_total; i++) {
|
||||
if (!strcmp(opname, bmo_opdefines[i]->opname)) {
|
||||
if (STREQ(opname, bmo_opdefines[i]->opname)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4664,7 +4664,7 @@ static int edbm_sort_elements_draw_check_prop(PointerRNA *ptr, PropertyRNA *prop
|
||||
int action = RNA_enum_get(ptr, "type");
|
||||
|
||||
/* Only show seed for randomize action! */
|
||||
if (strcmp(prop_id, "seed") == 0) {
|
||||
if (STREQ(prop_id, "seed")) {
|
||||
if (action == SRT_RANDOMIZE)
|
||||
return TRUE;
|
||||
else
|
||||
@@ -4672,7 +4672,7 @@ static int edbm_sort_elements_draw_check_prop(PointerRNA *ptr, PropertyRNA *prop
|
||||
}
|
||||
|
||||
/* Hide seed for reverse and randomize actions! */
|
||||
if (strcmp(prop_id, "reverse") == 0) {
|
||||
if (STREQ(prop_id, "reverse")) {
|
||||
if (ELEM(action, SRT_RANDOMIZE, SRT_REVERSE))
|
||||
return FALSE;
|
||||
else
|
||||
|
||||
@@ -1053,7 +1053,7 @@ static int object_select_menu_exec(bContext *C, wmOperator *op)
|
||||
CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
|
||||
{
|
||||
/* this is a bit dodjy, there should only be ONE object with this name, but library objects can mess this up */
|
||||
if (strcmp(name, base->object->id.name + 2) == 0) {
|
||||
if (STREQ(name, base->object->id.name + 2)) {
|
||||
ED_base_object_activate(C, base);
|
||||
ED_base_object_select(base, BA_SELECT);
|
||||
changed = 1;
|
||||
|
||||
@@ -444,7 +444,7 @@ static void rna_pose_bgroup_name_index_set(PointerRNA *ptr, const char *value, s
|
||||
int a;
|
||||
|
||||
for (a = 1, grp = pose->agroups.first; grp; grp = grp->next, a++) {
|
||||
if (strcmp(grp->name, value) == 0) {
|
||||
if (STREQ(grp->name, value)) {
|
||||
*index = a;
|
||||
return;
|
||||
}
|
||||
@@ -459,7 +459,7 @@ static void rna_pose_pgroup_name_set(PointerRNA *ptr, const char *value, char *r
|
||||
bActionGroup *grp;
|
||||
|
||||
for (grp = pose->agroups.first; grp; grp = grp->next) {
|
||||
if (strcmp(grp->name, value) == 0) {
|
||||
if (STREQ(grp->name, value)) {
|
||||
BLI_strncpy(result, value, maxlen);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ static PyObject *bpy_bmesh_ops_fakemod_getattro(PyObject *UNUSED(self), PyObject
|
||||
const char *opname = _PyUnicode_AsString(pyname);
|
||||
|
||||
for (i = 0; i < tot; i++) {
|
||||
if (strcmp(bmo_opdefines[i]->opname, opname) == 0) {
|
||||
if (STREQ(bmo_opdefines[i]->opname, opname)) {
|
||||
return bpy_bmesh_op_CreatePyObject(opname);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -751,7 +751,7 @@ void *PyC_RNA_AsPointer(PyObject *value, const char *type_name)
|
||||
PyObject *as_pointer;
|
||||
PyObject *pointer;
|
||||
|
||||
if (!strcmp(Py_TYPE(value)->tp_name, type_name) &&
|
||||
if (STREQ(Py_TYPE(value)->tp_name, type_name) &&
|
||||
(as_pointer = PyObject_GetAttrString(value, "as_pointer")) != NULL &&
|
||||
PyCallable_Check(as_pointer))
|
||||
{
|
||||
@@ -804,7 +804,7 @@ char *PyC_FlagSet_AsString(PyC_FlagSet *item)
|
||||
int PyC_FlagSet_ValueFromID_int(PyC_FlagSet *item, const char *identifier, int *value)
|
||||
{
|
||||
for ( ; item->identifier; item++) {
|
||||
if (strcmp(item->identifier, identifier) == 0) {
|
||||
if (STREQ(item->identifier, identifier)) {
|
||||
*value = item->value;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -153,10 +153,10 @@ static PyObject *bpy_user_resource(PyObject *UNUSED(self), PyObject *args, PyObj
|
||||
return NULL;
|
||||
|
||||
/* stupid string compare */
|
||||
if (!strcmp(type, "DATAFILES")) folder_id = BLENDER_USER_DATAFILES;
|
||||
else if (!strcmp(type, "CONFIG")) folder_id = BLENDER_USER_CONFIG;
|
||||
else if (!strcmp(type, "SCRIPTS")) folder_id = BLENDER_USER_SCRIPTS;
|
||||
else if (!strcmp(type, "AUTOSAVE")) folder_id = BLENDER_USER_AUTOSAVE;
|
||||
if (STREQ(type, "DATAFILES")) folder_id = BLENDER_USER_DATAFILES;
|
||||
else if (STREQ(type, "CONFIG")) folder_id = BLENDER_USER_CONFIG;
|
||||
else if (STREQ(type, "SCRIPTS")) folder_id = BLENDER_USER_SCRIPTS;
|
||||
else if (STREQ(type, "AUTOSAVE")) folder_id = BLENDER_USER_AUTOSAVE;
|
||||
else {
|
||||
PyErr_SetString(PyExc_ValueError, "invalid resource argument");
|
||||
return NULL;
|
||||
@@ -197,9 +197,9 @@ static PyObject *bpy_resource_path(PyObject *UNUSED(self), PyObject *args, PyObj
|
||||
return NULL;
|
||||
|
||||
/* stupid string compare */
|
||||
if (!strcmp(type, "USER")) folder_id = BLENDER_RESOURCE_PATH_USER;
|
||||
else if (!strcmp(type, "LOCAL")) folder_id = BLENDER_RESOURCE_PATH_LOCAL;
|
||||
else if (!strcmp(type, "SYSTEM")) folder_id = BLENDER_RESOURCE_PATH_SYSTEM;
|
||||
if (STREQ(type, "USER")) folder_id = BLENDER_RESOURCE_PATH_USER;
|
||||
else if (STREQ(type, "LOCAL")) folder_id = BLENDER_RESOURCE_PATH_LOCAL;
|
||||
else if (STREQ(type, "SYSTEM")) folder_id = BLENDER_RESOURCE_PATH_SYSTEM;
|
||||
else {
|
||||
PyErr_SetString(PyExc_ValueError, "invalid resource argument");
|
||||
return NULL;
|
||||
|
||||
@@ -1265,9 +1265,11 @@ static int icon_id_from_name(const char *name)
|
||||
int id;
|
||||
|
||||
if (name[0]) {
|
||||
for (item = icon_items, id = 0; item->identifier; item++, id++)
|
||||
if (strcmp(item->name, name) == 0)
|
||||
for (item = icon_items, id = 0; item->identifier; item++, id++) {
|
||||
if (STREQ(item->name, name)) {
|
||||
return item->value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -1353,7 +1355,7 @@ static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, i
|
||||
tmp.value = i;
|
||||
}
|
||||
|
||||
if (def && def_used == 0 && strcmp(def_cmp, tmp.identifier) == 0) {
|
||||
if (def && def_used == 0 && STREQ(def_cmp, tmp.identifier)) {
|
||||
*defvalue = tmp.value;
|
||||
def_used++; /* only ever 1 */
|
||||
}
|
||||
|
||||
@@ -1427,7 +1427,9 @@ int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const cha
|
||||
{
|
||||
arg_name = RNA_property_identifier(prop);
|
||||
|
||||
if (strcmp(arg_name, "rna_type") == 0) continue;
|
||||
if (STREQ(arg_name, "rna_type")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (kw == NULL) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
@@ -2223,7 +2225,7 @@ static int pyrna_prop_collection_subscript_str_lib_pair_ptr(BPy_PropertyRNA *sel
|
||||
RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop)
|
||||
{
|
||||
ID *id = itemptr.data; /* always an ID */
|
||||
if (id->lib == lib && (strncmp(keyname, id->name + 2, sizeof(id->name) - 2) == 0)) {
|
||||
if (id->lib == lib && (STREQLEN(keyname, id->name + 2, sizeof(id->name) - 2))) {
|
||||
found = true;
|
||||
if (r_ptr) {
|
||||
*r_ptr = itemptr;
|
||||
@@ -3463,7 +3465,7 @@ static PyObject *pyrna_struct_getattro(BPy_StructRNA *self, PyObject *pyname)
|
||||
}
|
||||
else if (name[0] == '_') { /* rna can't start with a "_", so for __dict__ and similar we can skip using rna lookups */
|
||||
/* annoying exception, maybe we need to have different types for this... */
|
||||
if ((strcmp(name, "__getitem__") == 0 || strcmp(name, "__setitem__") == 0) && !RNA_struct_idprops_check(self->ptr.type)) {
|
||||
if ((STREQ(name, "__getitem__") || STREQ(name, "__setitem__")) && !RNA_struct_idprops_check(self->ptr.type)) {
|
||||
PyErr_SetString(PyExc_AttributeError, "bpy_struct: no __getitem__ support for this type");
|
||||
ret = NULL;
|
||||
}
|
||||
@@ -4939,7 +4941,7 @@ static PyObject *small_dict_get_item_string(PyObject *dict, const char *key_look
|
||||
|
||||
while (PyDict_Next(dict, &pos, &key, &value)) {
|
||||
if (PyUnicode_Check(key)) {
|
||||
if (strcmp(key_lookup, _PyUnicode_AsString(key)) == 0) {
|
||||
if (STREQ(key_lookup, _PyUnicode_AsString(key))) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -5139,7 +5141,7 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject
|
||||
RNA_parameter_list_begin(&parms, &iter);
|
||||
for (; iter.valid; RNA_parameter_list_next(&iter)) {
|
||||
parm = iter.parm;
|
||||
if (strcmp(arg_name, RNA_property_identifier(parm)) == 0) {
|
||||
if (STREQ(arg_name, RNA_property_identifier(parm))) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
@@ -6937,7 +6939,7 @@ static int bpy_class_validate_recursive(PointerRNA *dummyptr, StructRNA *srna, v
|
||||
/* Sneaky workaround to use the class name as the bl_idname */
|
||||
|
||||
#define BPY_REPLACEMENT_STRING(rna_attr, py_attr) \
|
||||
(strcmp(identifier, rna_attr) == 0) { \
|
||||
(STREQ(identifier, rna_attr)) { \
|
||||
item = PyObject_GetAttr(py_class, py_attr); \
|
||||
if (item && item != Py_None) { \
|
||||
if (pyrna_py_to_prop(dummyptr, prop, NULL, \
|
||||
|
||||
@@ -829,10 +829,10 @@ static PyObject *C_Matrix_Shear(PyObject *cls, PyObject *args)
|
||||
mat[0] = 1.0f;
|
||||
mat[3] = 1.0f;
|
||||
|
||||
if (strcmp(plane, "X") == 0) {
|
||||
if (STREQ(plane, "X")) {
|
||||
mat[2] = factor;
|
||||
}
|
||||
else if (strcmp(plane, "Y") == 0) {
|
||||
else if (STREQ(plane, "Y")) {
|
||||
mat[1] = factor;
|
||||
}
|
||||
else {
|
||||
@@ -855,15 +855,15 @@ static PyObject *C_Matrix_Shear(PyObject *cls, PyObject *args)
|
||||
mat[4] = 1.0f;
|
||||
mat[8] = 1.0f;
|
||||
|
||||
if (strcmp(plane, "XY") == 0) {
|
||||
if (STREQ(plane, "XY")) {
|
||||
mat[6] = factor[0];
|
||||
mat[7] = factor[1];
|
||||
}
|
||||
else if (strcmp(plane, "XZ") == 0) {
|
||||
else if (STREQ(plane, "XZ")) {
|
||||
mat[3] = factor[0];
|
||||
mat[5] = factor[1];
|
||||
}
|
||||
else if (strcmp(plane, "YZ") == 0) {
|
||||
else if (STREQ(plane, "YZ")) {
|
||||
mat[1] = factor[0];
|
||||
mat[2] = factor[1];
|
||||
}
|
||||
|
||||
@@ -1704,7 +1704,7 @@ static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *UNUSED(ar
|
||||
uiItemStringO(col, IFACE_("Blender Website"), ICON_URL, "WM_OT_url_open", "url", "http://www.blender.org");
|
||||
uiItemStringO(col, IFACE_("User Community"), ICON_URL, "WM_OT_url_open", "url",
|
||||
"http://www.blender.org/community/user-community");
|
||||
if (strcmp(STRINGIFY(BLENDER_VERSION_CYCLE), "release") == 0) {
|
||||
if (STREQ(STRINGIFY(BLENDER_VERSION_CYCLE), "release")) {
|
||||
BLI_snprintf(url, sizeof(url), "http://www.blender.org/documentation/blender_python_api_%d_%d"
|
||||
STRINGIFY(BLENDER_VERSION_CHAR) "_release",
|
||||
BLENDER_VERSION / 100, BLENDER_VERSION % 100);
|
||||
|
||||
Reference in New Issue
Block a user