diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-01-07 03:40:44 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-01-07 04:08:54 +0300 |
commit | 848c00f7e70950fa012627f84c89b32bb9a4deaa (patch) | |
tree | c0d26b61c436ffed04059917b034daf046aa9d38 /source | |
parent | 3bd01c60561c5e88f1a9b984852c77b32b7caa72 (diff) |
cleanup: de-duplicate code
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenloader/intern/versioning_legacy.c | 93 | ||||
-rw-r--r-- | source/blender/editors/space_file/filelist.c | 92 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_ops.c | 87 |
3 files changed, 64 insertions, 208 deletions
diff --git a/source/blender/blenloader/intern/versioning_legacy.c b/source/blender/blenloader/intern/versioning_legacy.c index 1a1bc3a55be..6f298923397 100644 --- a/source/blender/blenloader/intern/versioning_legacy.c +++ b/source/blender/blenloader/intern/versioning_legacy.c @@ -515,6 +515,40 @@ static void do_version_free_effects_245(ListBase *lb) } } +static void do_version_constraints_245(ListBase *lb) +{ + bConstraint *con; + bConstraintTarget *ct; + + for (con = lb->first; con; con = con->next) { + if (con->type == CONSTRAINT_TYPE_PYTHON) { + bPythonConstraint *data = (bPythonConstraint *)con->data; + if (data->tar) { + /* version patching needs to be done */ + ct = MEM_callocN(sizeof(bConstraintTarget), "PyConTarget"); + + ct->tar = data->tar; + BLI_strncpy(ct->subtarget, data->subtarget, sizeof(ct->subtarget)); + ct->space = con->tarspace; + + BLI_addtail(&data->targets, ct); + data->tarnum++; + + /* clear old targets to avoid problems */ + data->tar = NULL; + data->subtarget[0] = '\0'; + } + } + else if (con->type == CONSTRAINT_TYPE_LOCLIKE) { + bLocateLikeConstraint *data = (bLocateLikeConstraint *)con->data; + + /* new headtail functionality makes Bone-Tip function obsolete */ + if (data->flag & LOCLIKE_TIP) + con->headtail = 1.0f; + } + } +} + PartEff *blo_do_version_give_parteff_245(Object *ob) { PartEff *paf; @@ -2951,69 +2985,14 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main) if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 7)) { Object *ob; bPoseChannel *pchan; - bConstraint *con; - bConstraintTarget *ct; for (ob = main->object.first; ob; ob = ob->id.next) { if (ob->pose) { for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { - for (con = pchan->constraints.first; con; con = con->next) { - if (con->type == CONSTRAINT_TYPE_PYTHON) { - bPythonConstraint *data = (bPythonConstraint *)con->data; - if (data->tar) { - /* version patching needs to be done */ - ct = MEM_callocN(sizeof(bConstraintTarget), "PyConTarget"); - - ct->tar = data->tar; - BLI_strncpy(ct->subtarget, data->subtarget, sizeof(ct->subtarget)); - ct->space = con->tarspace; - - BLI_addtail(&data->targets, ct); - data->tarnum++; - - /* clear old targets to avoid problems */ - data->tar = NULL; - data->subtarget[0] = '\0'; - } - } - else if (con->type == CONSTRAINT_TYPE_LOCLIKE) { - bLocateLikeConstraint *data = (bLocateLikeConstraint *)con->data; - - /* new headtail functionality makes Bone-Tip function obsolete */ - if (data->flag & LOCLIKE_TIP) - con->headtail = 1.0f; - } - } - } - } - - for (con = ob->constraints.first; con; con = con->next) { - if (con->type == CONSTRAINT_TYPE_PYTHON) { - bPythonConstraint *data = (bPythonConstraint *)con->data; - if (data->tar) { - /* version patching needs to be done */ - ct = MEM_callocN(sizeof(bConstraintTarget), "PyConTarget"); - - ct->tar = data->tar; - BLI_strncpy(ct->subtarget, data->subtarget, sizeof(ct->subtarget)); - ct->space = con->tarspace; - - BLI_addtail(&data->targets, ct); - data->tarnum++; - - /* clear old targets to avoid problems */ - data->tar = NULL; - data->subtarget[0] = '\0'; - } - } - else if (con->type == CONSTRAINT_TYPE_LOCLIKE) { - bLocateLikeConstraint *data = (bLocateLikeConstraint *)con->data; - - /* new headtail functionality makes Bone-Tip function obsolete */ - if (data->flag & LOCLIKE_TIP) - con->headtail = 1.0f; + do_version_constraints_245(&pchan->constraints); } } + do_version_constraints_245(&ob->constraints); if (ob->soft && ob->soft->keys) { SoftBody *sb = ob->soft; diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index d5e29d7905a..bcef0817ffe 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -284,10 +284,8 @@ static bool compare_is_directory(const struct direntry *entry) return false; } -static int compare_name(const void *a1, const void *a2) +static int compare_direntry_generic(const struct direntry *entry1, const struct direntry *entry2) { - const struct direntry *entry1 = a1, *entry2 = a2; - /* type is equal to stat.st_mode */ if (compare_is_directory(entry1)) { @@ -311,35 +309,29 @@ static int compare_name(const void *a1, const void *a2) if (strcmp(entry1->relname, "..") == 0) return (-1); if (strcmp(entry2->relname, "..") == 0) return (1); + return 0; +} + +static int compare_name(const void *a1, const void *a2) +{ + const struct direntry *entry1 = a1, *entry2 = a2; + int ret; + + if ((ret = compare_direntry_generic(entry1, entry2))) { + return ret; + } + return (BLI_natstrcmp(entry1->relname, entry2->relname)); } static int compare_date(const void *a1, const void *a2) { const struct direntry *entry1 = a1, *entry2 = a2; + int ret; - /* type is equal to stat.st_mode */ - - if (compare_is_directory(entry1)) { - if (compare_is_directory(entry2) == 0) return (-1); - } - else { - if (compare_is_directory(entry2)) return (1); - } - if (S_ISREG(entry1->type)) { - if (S_ISREG(entry2->type) == 0) return (-1); - } - else { - if (S_ISREG(entry2->type)) return (1); + if ((ret = compare_direntry_generic(entry1, entry2))) { + return ret; } - if ((entry1->type & S_IFMT) < (entry2->type & S_IFMT)) return (-1); - if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) return (1); - - /* make sure "." and ".." are always first */ - if (strcmp(entry1->relname, ".") == 0) return (-1); - if (strcmp(entry2->relname, ".") == 0) return (1); - if (strcmp(entry1->relname, "..") == 0) return (-1); - if (strcmp(entry2->relname, "..") == 0) return (1); if (entry1->s.st_mtime < entry2->s.st_mtime) return 1; if (entry1->s.st_mtime > entry2->s.st_mtime) return -1; @@ -350,29 +342,11 @@ static int compare_date(const void *a1, const void *a2) static int compare_size(const void *a1, const void *a2) { const struct direntry *entry1 = a1, *entry2 = a2; + int ret; - /* type is equal to stat.st_mode */ - - if (compare_is_directory(entry1)) { - if (compare_is_directory(entry2) == 0) return (-1); - } - else { - if (compare_is_directory(entry2)) return (1); + if ((ret = compare_direntry_generic(entry1, entry2))) { + return ret; } - if (S_ISREG(entry1->type)) { - if (S_ISREG(entry2->type) == 0) return (-1); - } - else { - if (S_ISREG(entry2->type)) return (1); - } - if ((entry1->type & S_IFMT) < (entry2->type & S_IFMT)) return (-1); - if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) return (1); - - /* make sure "." and ".." are always first */ - if (strcmp(entry1->relname, ".") == 0) return (-1); - if (strcmp(entry2->relname, ".") == 0) return (1); - if (strcmp(entry1->relname, "..") == 0) return (-1); - if (strcmp(entry2->relname, "..") == 0) return (1); if (entry1->s.st_size < entry2->s.st_size) return 1; if (entry1->s.st_size > entry2->s.st_size) return -1; @@ -384,6 +358,11 @@ static int compare_extension(const void *a1, const void *a2) const struct direntry *entry1 = a1, *entry2 = a2; const char *sufix1, *sufix2; const char *nil = ""; + int ret; + + if ((ret = compare_direntry_generic(entry1, entry2))) { + return ret; + } if (!(sufix1 = strstr(entry1->relname, ".blend.gz"))) sufix1 = strrchr(entry1->relname, '.'); @@ -392,29 +371,6 @@ static int compare_extension(const void *a1, const void *a2) if (!sufix1) sufix1 = nil; if (!sufix2) sufix2 = nil; - /* type is equal to stat.st_mode */ - - if (compare_is_directory(entry1)) { - if (compare_is_directory(entry2) == 0) return (-1); - } - else { - if (compare_is_directory(entry2)) return (1); - } - if (S_ISREG(entry1->type)) { - if (S_ISREG(entry2->type) == 0) return (-1); - } - else { - if (S_ISREG(entry2->type)) return (1); - } - if ((entry1->type & S_IFMT) < (entry2->type & S_IFMT)) return (-1); - if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) return (1); - - /* make sure "." and ".." are always first */ - if (strcmp(entry1->relname, ".") == 0) return (-1); - if (strcmp(entry2->relname, ".") == 0) return (1); - if (strcmp(entry1->relname, "..") == 0) return (-1); - if (strcmp(entry2->relname, "..") == 0) return (1); - return (BLI_strcasecmp(sufix1, sufix2)); } diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 88e053565df..1cf0316aa06 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -714,88 +714,6 @@ void TEXT_OT_refresh_pyconstraints(wmOperatorType *ot) /******************* paste operator *********************/ -static char *txt_copy_selected(Text *text) -{ - TextLine *tmp, *linef, *linel; - char *buf = NULL; - int charf, charl, length = 0; - - if (!text) return NULL; - if (!text->curl) return NULL; - if (!text->sell) return NULL; - - if (!txt_has_sel(text)) return NULL; - - if (text->curl == text->sell) { - linef = linel = text->curl; - - if (text->curc < text->selc) { - charf = text->curc; - charl = text->selc; - } - else { - charf = text->selc; - charl = text->curc; - } - } - else if (txt_get_span(text->curl, text->sell) < 0) { - linef = text->sell; - linel = text->curl; - - charf = text->selc; - charl = text->curc; - } - else { - linef = text->curl; - linel = text->sell; - - charf = text->curc; - charl = text->selc; - } - - if (linef == linel) { - length = charl - charf; - - buf = MEM_callocN(length + 1, "cut buffera"); - - BLI_strncpy(buf, linef->line + charf, length + 1); - } - else { - length += linef->len - charf; - length += charl; - length++; /* For the '\n' */ - - tmp = linef->next; - while (tmp && tmp != linel) { - length += tmp->len + 1; - tmp = tmp->next; - } - - buf = MEM_callocN(length + 1, "cut bufferb"); - - strncpy(buf, linef->line + charf, linef->len - charf); - length = linef->len - charf; - - buf[length++] = '\n'; - - tmp = linef->next; - while (tmp && tmp != linel) { - strncpy(buf + length, tmp->line, tmp->len); - length += tmp->len; - - buf[length++] = '\n'; - - tmp = tmp->next; - } - strncpy(buf + length, linel->line, charl); - length += charl; - - buf[length] = 0; - } - - return buf; -} - static int text_paste_exec(bContext *C, wmOperator *op) { const bool selection = RNA_boolean_get(op->ptr, "selection"); @@ -876,7 +794,10 @@ static void txt_copy_clipboard(Text *text) { char *buf; - buf = txt_copy_selected(text); + if (!txt_has_sel(text)) + return; + + buf = txt_sel_to_buf(text); if (buf) { WM_clipboard_text_set(buf, 0); |