/* generic search invoke */ static void node_find_cb(const struct bContext *C, void *UNUSED(arg), const char *str, uiSearchItems *items) { SpaceNode *snode = CTX_wm_space_node(C); bNode *node; for (node = snode->edittree->nodes.first; node; node = node->next) { if (BLI_strcasestr(node->name, str) || BLI_strcasestr(node->label, str)) { char name[256]; if (node->label[0]) BLI_snprintf(name, 256, "%s (%s)", node->name, node->label); else BLI_strncpy(name, node->name, 256); if (false == UI_search_item_add(items, name, node, 0)) break; } } }
static void operator_search_cb(const struct bContext *C, void *UNUSED(arg), const char *str, uiSearchItems *items) { wmOperatorType *ot = WM_operatortype_first(); for(; ot; ot= ot->next) { if(BLI_strcasestr(ot->name, str)) { if(WM_operator_poll((bContext*)C, ot)) { if(0==uiSearchItemAdd(items, ot->name, ot, 0)) break; } } } }
static void operator_search_cb(const struct bContext *C, void *UNUSED(arg), const char *str, uiSearchItems *items) { GHashIterator iter; for (WM_operatortype_iter(&iter); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) { wmOperatorType *ot = BLI_ghashIterator_getValue(&iter); if (BLI_strcasestr(ot->name, str)) { if (WM_operator_poll((bContext *)C, ot)) { if (false == UI_search_item_add(items, ot->name, ot, 0)) break; } } } }
static void operator_search_cb(const struct bContext *C, void *UNUSED(arg), const char *str, uiSearchItems *items) { GHashIterator *iter = WM_operatortype_iter(); for (; !BLI_ghashIterator_isDone(iter); BLI_ghashIterator_step(iter)) { wmOperatorType *ot = BLI_ghashIterator_getValue(iter); if (BLI_strcasestr(ot->name, str)) { if (WM_operator_poll((bContext *)C, ot)) { if (0 == uiSearchItemAdd(items, ot->name, ot, 0)) break; } } } BLI_ghashIterator_free(iter); }
static int file_is_blend_backup(const char *str) { short a, b; int retval= 0; a= strlen(str); b= 7; if (a==0 || b>=a); else { char *loc; if (a > b+1) b++; /* allow .blend1 .blend2 .blend32 */ loc= BLI_strcasestr(str+a-b, ".blend"); if (loc) retval= 1; } return (retval); }
/* would recognize .blend as well */ static bool file_is_blend_backup(const char *str) { const size_t a = strlen(str); size_t b = 7; bool retval = 0; if (a == 0 || b >= a) { /* pass */ } else { const char *loc; if (a > b + 1) b++; /* allow .blend1 .blend2 .blend32 */ loc = BLI_strcasestr(str + a - b, ".blend"); if (loc) retval = 1; } return (retval); }
/* This helper function is called during poselib_preview_poses to find the * pose to preview next (after a change event) */ static void poselib_preview_get_next (tPoseLib_PreviewData *pld, int step) { /* stop if not going anywhere, as we assume that there is a direction to move in */ if (step == 0) return; /* search-string dictates a special approach */ if (pld->searchstr[0]) { TimeMarker *marker; LinkData *ld, *ldn, *ldc; /* free and rebuild if needed (i.e. if search-str changed) */ if (strcmp(pld->searchstr, pld->searchold)) { /* free list of temporary search matches */ BLI_freelistN(&pld->searchp); /* generate a new list of search matches */ for (marker= pld->act->markers.first; marker; marker= marker->next) { /* does the name partially match? * - don't worry about case, to make it easier for users to quickly input a name (or * part of one), which is the whole point of this feature */ if (BLI_strcasestr(marker->name, pld->searchstr)) { /* make link-data to store reference to it */ ld= MEM_callocN(sizeof(LinkData), "PoseMatch"); ld->data= marker; BLI_addtail(&pld->searchp, ld); } } /* set current marker to NULL (so that we start from first) */ pld->marker= NULL; } /* check if any matches */ if (pld->searchp.first == NULL) { pld->marker= NULL; return; } /* find first match */ for (ldc= pld->searchp.first; ldc; ldc= ldc->next) { if (ldc->data == pld->marker) break; } if (ldc == NULL) ldc= pld->searchp.first; /* Loop through the matches in a cyclic fashion, incrementing/decrementing step as appropriate * until step == 0. At this point, marker should be the correct marker. */ if (step > 0) { for (ld=ldc; ld && step; ld=ldn, step--) ldn= (ld->next) ? ld->next : pld->searchp.first; } else { for (ld=ldc; ld && step; ld=ldn, step++) ldn= (ld->prev) ? ld->prev : pld->searchp.last; } /* set marker */ if (ld) pld->marker= ld->data; } else { TimeMarker *marker, *next; /* if no marker, because we just ended searching, then set that to the start of the list */ if (pld->marker == NULL) pld->marker= pld->act->markers.first; /* Loop through the markers in a cyclic fashion, incrementing/decrementing step as appropriate * until step == 0. At this point, marker should be the correct marker. */ if (step > 0) { for (marker=pld->marker; marker && step; marker=next, step--) next= (marker->next) ? marker->next : pld->act->markers.first; } else { for (marker=pld->marker; marker && step; marker=next, step++) next= (marker->prev) ? marker->prev : pld->act->markers.last; } /* it should be fairly impossible for marker to be NULL */ if (marker) pld->marker= marker; } }
/* if strip_number: removes number extensions * note: don't use sizeof() for 'name' or 'from_name' */ void BKE_deform_flip_side_name(char name[MAX_VGROUP_NAME], const char from_name[MAX_VGROUP_NAME], const bool strip_number) { int len; char prefix[MAX_VGROUP_NAME] = ""; /* The part before the facing */ char suffix[MAX_VGROUP_NAME] = ""; /* The part after the facing */ char replace[MAX_VGROUP_NAME] = ""; /* The replacement string */ char number[MAX_VGROUP_NAME] = ""; /* The number extension string */ char *index = NULL; bool is_set = false; /* always copy the name, since this can be called with an uninitialized string */ BLI_strncpy(name, from_name, MAX_VGROUP_NAME); len = BLI_strnlen(from_name, MAX_VGROUP_NAME); if (len < 3) { /* we don't do names like .R or .L */ return; } /* We first check the case with a .### extension, let's find the last period */ if (isdigit(name[len - 1])) { index = strrchr(name, '.'); // last occurrence if (index && isdigit(index[1])) { // doesnt handle case bone.1abc2 correct..., whatever! if (strip_number == false) { BLI_strncpy(number, index, sizeof(number)); } *index = 0; len = BLI_strnlen(name, MAX_VGROUP_NAME); } } BLI_strncpy(prefix, name, sizeof(prefix)); /* first case; separator . - _ with extensions r R l L */ if ((len > 1) && is_char_sep(name[len - 2])) { is_set = true; switch (name[len - 1]) { case 'l': prefix[len - 1] = 0; strcpy(replace, "r"); break; case 'r': prefix[len - 1] = 0; strcpy(replace, "l"); break; case 'L': prefix[len - 1] = 0; strcpy(replace, "R"); break; case 'R': prefix[len - 1] = 0; strcpy(replace, "L"); break; default: is_set = false; } } /* case; beginning with r R l L, with separator after it */ if (!is_set && is_char_sep(name[1])) { is_set = true; switch (name[0]) { case 'l': strcpy(replace, "r"); BLI_strncpy(suffix, name + 1, sizeof(suffix)); prefix[0] = 0; break; case 'r': strcpy(replace, "l"); BLI_strncpy(suffix, name + 1, sizeof(suffix)); prefix[0] = 0; break; case 'L': strcpy(replace, "R"); BLI_strncpy(suffix, name + 1, sizeof(suffix)); prefix[0] = 0; break; case 'R': strcpy(replace, "L"); BLI_strncpy(suffix, name + 1, sizeof(suffix)); prefix[0] = 0; break; default: is_set = false; } } if (!is_set && len > 5) { /* hrms, why test for a separator? lets do the rule 'ultimate left or right' */ if (((index = BLI_strcasestr(prefix, "right")) == prefix) || (index == prefix + len - 5)) { is_set = true; if (index[0] == 'r') { strcpy(replace, "left"); } else { strcpy(replace, (index[1] == 'I') ? "LEFT" : "Left"); } *index = 0; BLI_strncpy(suffix, index + 5, sizeof(suffix)); } else if (((index = BLI_strcasestr(prefix, "left")) == prefix) || (index == prefix + len - 4)) { is_set = true; if (index[0] == 'l') { strcpy(replace, "right"); } else { strcpy(replace, (index[1] == 'E') ? "RIGHT" : "Right"); } *index = 0; BLI_strncpy(suffix, index + 4, sizeof(suffix)); } } (void)is_set; /* quiet warning */ BLI_snprintf(name, MAX_VGROUP_NAME, "%s%s%s%s", prefix, replace, suffix, number); }
/* if strip_number: removes number extensions * note: dont use sizeof() for 'name' or 'from_name' */ void flip_side_name (char name[MAX_VGROUP_NAME], const char from_name[MAX_VGROUP_NAME], int strip_number) { int len; char prefix[MAX_VGROUP_NAME]= ""; /* The part before the facing */ char suffix[MAX_VGROUP_NAME]= ""; /* The part after the facing */ char replace[MAX_VGROUP_NAME]= ""; /* The replacement string */ char number[MAX_VGROUP_NAME]= ""; /* The number extension string */ char *index=NULL; len= BLI_strnlen(from_name, MAX_VGROUP_NAME); if(len<3) return; // we don't do names like .R or .L BLI_strncpy(name, from_name, MAX_VGROUP_NAME); /* We first check the case with a .### extension, let's find the last period */ if(isdigit(name[len-1])) { index= strrchr(name, '.'); // last occurrence if (index && isdigit(index[1]) ) { // doesnt handle case bone.1abc2 correct..., whatever! if(strip_number==0) BLI_strncpy(number, index, sizeof(number)); *index= 0; len= BLI_strnlen(name, MAX_VGROUP_NAME); } } BLI_strncpy(prefix, name, sizeof(prefix)); #define IS_SEPARATOR(a) ((a)=='.' || (a)==' ' || (a)=='-' || (a)=='_') /* first case; separator . - _ with extensions r R l L */ if( IS_SEPARATOR(name[len-2]) ) { switch(name[len-1]) { case 'l': prefix[len-1]= 0; strcpy(replace, "r"); break; case 'r': prefix[len-1]= 0; strcpy(replace, "l"); break; case 'L': prefix[len-1]= 0; strcpy(replace, "R"); break; case 'R': prefix[len-1]= 0; strcpy(replace, "L"); break; } } /* case; beginning with r R l L , with separator after it */ else if( IS_SEPARATOR(name[1]) ) { switch(name[0]) { case 'l': strcpy(replace, "r"); strcpy(suffix, name+1); prefix[0]= 0; break; case 'r': strcpy(replace, "l"); strcpy(suffix, name+1); prefix[0]= 0; break; case 'L': strcpy(replace, "R"); strcpy(suffix, name+1); prefix[0]= 0; break; case 'R': strcpy(replace, "L"); strcpy(suffix, name+1); prefix[0]= 0; break; } } else if(len > 5) { /* hrms, why test for a separator? lets do the rule 'ultimate left or right' */ index = BLI_strcasestr(prefix, "right"); if (index==prefix || index==prefix+len-5) { if(index[0]=='r') strcpy (replace, "left"); else { if(index[1]=='I') strcpy (replace, "LEFT"); else strcpy (replace, "Left"); } *index= 0; strcpy (suffix, index+5); } else { index = BLI_strcasestr(prefix, "left"); if (index==prefix || index==prefix+len-4) { if(index[0]=='l') strcpy (replace, "right"); else { if(index[1]=='E') strcpy (replace, "RIGHT"); else strcpy (replace, "Right"); } *index= 0; strcpy (suffix, index+4); } } } #undef IS_SEPARATOR BLI_snprintf (name, MAX_VGROUP_NAME, "%s%s%s%s", prefix, replace, suffix, number); }