void RE_engine_update_stats(RenderEngine *engine, const char *stats, const char *info) { Render *re= engine->re; /* stats draw callback */ if (re) { re->i.statstr= stats; re->i.infostr= info; re->stats_draw(re->sdh, &re->i); re->i.infostr= NULL; re->i.statstr= NULL; } /* set engine text */ if (engine->text) { MEM_freeN(engine->text); engine->text= NULL; } if (stats && stats[0] && info && info[0]) engine->text= BLI_sprintfN("%s | %s", stats, info); else if (info && info[0]) engine->text= BLI_strdup(info); else if (stats && stats[0]) engine->text= BLI_strdup(stats); }
static GHashKey *_ghashutil_keyalloc(const void *msgctxt, const void *msgid) { GHashKey *key = MEM_mallocN(sizeof(GHashKey), "Py i18n GHashKey"); key->msgctxt = BLI_strdup(BLT_is_default_context(msgctxt) ? BLT_I18NCONTEXT_DEFAULT_BPYRNA : msgctxt); key->msgid = BLI_strdup(msgid); return key; }
FontBLF *blf_font_new(const char *name, const char *filename) { FontBLF *font; FT_Error err; char *mfile; font = (FontBLF *)MEM_callocN(sizeof(FontBLF), "blf_font_new"); err = FT_New_Face(ft_lib, filename, 0, &font->face); if (err) { MEM_freeN(font); return NULL; } err = FT_Select_Charmap(font->face, ft_encoding_unicode); if (err) { printf("Can't set the unicode character map!\n"); FT_Done_Face(font->face); MEM_freeN(font); return NULL; } mfile = blf_dir_metrics_search(filename); if (mfile) { err = FT_Attach_File(font->face, mfile); if (err) { fprintf(stderr, "FT_Attach_File failed to load '%s' with error %d\n", filename, (int)err); } MEM_freeN(mfile); } font->name = BLI_strdup(name); font->filename = BLI_strdup(filename); blf_font_fill(font); return font; }
int IMB_metadata_add_field(struct ImBuf* img, const char* key, const char* field) { ImMetaData *info; ImMetaData *last; if (!img) return 0; if (!img->metadata) { img->metadata = MEM_callocN(sizeof(ImMetaData), "ImMetaData"); info = img->metadata; } else { info = img->metadata; last = info; while (info) { last = info; info = info->next; } info = MEM_callocN(sizeof(ImMetaData), "ImMetaData"); last->next = info; } info->key = BLI_strdup(key); info->value = BLI_strdup(field); return 1; }
static char *rna_VertexPaint_path(PointerRNA *ptr) { Scene *scene = (Scene *)ptr->id.data; ToolSettings *ts = scene->toolsettings; if (ptr->data == ts->vpaint) { return BLI_strdup("tool_settings.vertex_paint"); } else { return BLI_strdup("tool_settings.weight_paint"); } }
char *rna_ImageUser_path(PointerRNA *ptr) { if (ptr->id.data) { // ImageUser *iuser= ptr->data; switch(GS(((ID *)ptr->id.data)->name)) { case ID_TE: return BLI_strdup("image_user"); } } return BLI_strdup(""); }
static char *strip_last_slash(const char *dir) { char *result = BLI_strdup(dir); BLI_del_slash(result); return result; }
/* Some font have additional file with metrics information, * in general, the extension of the file is: .afm or .pfm */ char *blf_dir_metrics_search(const char *filename) { char *mfile; char *s; mfile = BLI_strdup(filename); s = strrchr(mfile, '.'); if (s) { if (BLI_strnlen(s, 4) < 4) { MEM_freeN(mfile); return NULL; } s++; s[0] = 'a'; s[1] = 'f'; s[2] = 'm'; /* first check .afm */ if (BLI_exists(mfile)) return mfile; /* and now check .pfm */ s[0] = 'p'; if (BLI_exists(mfile)) return mfile; } MEM_freeN(mfile); return NULL; }
FontBLF *blf_font_new_from_mem(const char *name, const unsigned char *mem, int mem_size) { FontBLF *font; FT_Error err; font = (FontBLF *)MEM_callocN(sizeof(FontBLF), "blf_font_new_from_mem"); err = FT_New_Memory_Face(ft_lib, mem, mem_size, 0, &font->face); if (err) { MEM_freeN(font); return NULL; } err = FT_Select_Charmap(font->face, ft_encoding_unicode); if (err) { printf("Can't set the unicode character map!\n"); FT_Done_Face(font->face); MEM_freeN(font); return NULL; } font->name = BLI_strdup(name); font->filename = NULL; blf_font_fill(font); return font; }
void wm_read_history(void) { char name[FILE_MAX]; LinkNode *l, *lines; struct RecentFile *recent; char *line; int num; const char * const cfgdir = BLI_get_folder(BLENDER_USER_CONFIG, NULL); if (!cfgdir) return; BLI_make_file_string("/", name, cfgdir, BLENDER_HISTORY_FILE); lines = BLI_file_read_as_lines(name); G.recent_files.first = G.recent_files.last = NULL; /* read list of recent opened files from recent-files.txt to memory */ for (l = lines, num = 0; l && (num < U.recent_files); l = l->next) { line = l->link; if (line[0] && BLI_exists(line)) { recent = (RecentFile *)MEM_mallocN(sizeof(RecentFile), "RecentFile"); BLI_addtail(&(G.recent_files), recent); recent->filepath = BLI_strdup(line); num++; } } BLI_file_free_lines(lines); }
void wm_history_file_read(void) { char name[FILE_MAX]; LinkNode *l, *lines; struct RecentFile *recent; const char *line; int num; const char * const cfgdir = BKE_appdir_folder_id(BLENDER_USER_CONFIG, NULL); if (!cfgdir) return; BLI_make_file_string("/", name, cfgdir, BLENDER_HISTORY_FILE); lines = BLI_file_read_as_lines(name); BLI_listbase_clear(&G.recent_files); /* read list of recent opened files from recent-files.txt to memory */ for (l = lines, num = 0; l && (num < U.recent_files); l = l->next) { line = l->link; /* don't check if files exist, causes slow startup for remote/external drives */ if (line[0]) { recent = (RecentFile *)MEM_mallocN(sizeof(RecentFile), "RecentFile"); BLI_addtail(&(G.recent_files), recent); recent->filepath = BLI_strdup(line); num++; } } BLI_file_free_lines(lines); }
static char *rna_NlaStrip_path(PointerRNA *ptr) { NlaStrip *strip = (NlaStrip *)ptr->data; AnimData *adt = BKE_animdata_from_id(ptr->id.data); /* if we're attached to AnimData, try to resolve path back to AnimData */ if (adt) { NlaTrack *nlt; NlaStrip *nls; for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) { for (nls = nlt->strips.first; nls; nls = nls->next) { if (nls == strip) { /* XXX but if we animate like this, the control will never work... */ char name_esc_nlt[sizeof(nlt->name) * 2]; char name_esc_strip[sizeof(strip->name) * 2]; BLI_strescape(name_esc_nlt, nlt->name, sizeof(name_esc_nlt)); BLI_strescape(name_esc_strip, strip->name, sizeof(name_esc_strip)); return BLI_sprintfN("animation_data.nla_tracks[\"%s\"].strips[\"%s\"]", name_esc_nlt, name_esc_strip); } } } } /* no path */ return BLI_strdup(""); }
/* Get locale's elements (if relevant pointer is not NULL and element actually exists, e.g. if there is no variant, * *variant and *language_variant will always be NULL). * Non-null elements are always MEM_mallocN'ed, it's the caller's responsibility to free them. * NOTE: Keep that one always available, you never know, may become useful even in no-WITH_INTERNATIONAL context... */ void BLT_lang_locale_explode( const char *locale, char **language, char **country, char **variant, char **language_country, char **language_variant) { char *m1, *m2, *_t = NULL; m1 = strchr(locale, '_'); m2 = strchr(locale, '@'); if (language || language_variant) { if (m1 || m2) { _t = m1 ? BLI_strdupn(locale, m1 - locale) : BLI_strdupn(locale, m2 - locale); if (language) *language = _t; } else if (language) { *language = BLI_strdup(locale); } } if (country) { if (m1) *country = m2 ? BLI_strdupn(m1 + 1, m2 - (m1 + 1)) : BLI_strdup(m1 + 1); else *country = NULL; } if (variant) { if (m2) *variant = BLI_strdup(m2 + 1); else *variant = NULL; } if (language_country) { if (m1) *language_country = m2 ? BLI_strdupn(locale, m2 - locale) : BLI_strdup(locale); else *language_country = NULL; } if (language_variant) { if (m2) *language_variant = m1 ? BLI_strdupcat(_t, m2) : BLI_strdup(locale); else *language_variant = NULL; } if (_t && !language) { MEM_freeN(_t); } }
static char *rna_ImageUser_path(PointerRNA *ptr) { if (ptr->id.data) { /* ImageUser *iuser = ptr->data; */ switch (GS(((ID *)ptr->id.data)->name)) { case ID_TE: { return BLI_strdup("image_user"); } case ID_NT: { return rna_Node_ImageUser_path(ptr); } } } return BLI_strdup(""); }
char *unpackFile(ReportList *reports, const char *abs_name, const char *local_name, PackedFile *pf, int how) { char *newname = NULL; const char *temp = NULL; // char newabs[FILE_MAX]; // char newlocal[FILE_MAX]; if (pf != NULL) { switch (how) { case -1: case PF_KEEP: break; case PF_REMOVE: temp = abs_name; break; case PF_USE_LOCAL: /* if file exists use it */ if (BLI_exists(local_name)) { temp = local_name; break; } /* else create it */ /* fall-through */ case PF_WRITE_LOCAL: if (writePackedFile(reports, local_name, pf, 1) == RET_OK) { temp = local_name; } break; case PF_USE_ORIGINAL: /* if file exists use it */ if (BLI_exists(abs_name)) { BKE_reportf(reports, RPT_INFO, "Use existing file (instead of packed): %s", abs_name); temp = abs_name; break; } /* else create it */ /* fall-through */ case PF_WRITE_ORIGINAL: if (writePackedFile(reports, abs_name, pf, 1) == RET_OK) { temp = abs_name; } break; default: printf("unpackFile: unknown return_value %d\n", how); break; } if (temp) { newname = BLI_strdup(temp); } } return newname; }
static void write_history(void) { struct RecentFile *recent, *next_recent; char name[FILE_MAX]; const char *user_config_dir; FILE *fp; int i; /* no write history for recovered startup files */ if (G.main->name[0] == 0) return; /* will be NULL in background mode */ user_config_dir = BLI_get_folder_create(BLENDER_USER_CONFIG, NULL); if (!user_config_dir) return; BLI_make_file_string("/", name, user_config_dir, BLENDER_HISTORY_FILE); recent = G.recent_files.first; /* refresh recent-files.txt of recent opened files, when current file was changed */ if (!(recent) || (BLI_path_cmp(recent->filepath, G.main->name) != 0)) { fp = BLI_fopen(name, "w"); if (fp) { /* add current file to the beginning of list */ recent = (RecentFile *)MEM_mallocN(sizeof(RecentFile), "RecentFile"); recent->filepath = BLI_strdup(G.main->name); BLI_addhead(&(G.recent_files), recent); /* write current file to recent-files.txt */ fprintf(fp, "%s\n", recent->filepath); recent = recent->next; i = 1; /* write rest of recent opened files to recent-files.txt */ while ((i < U.recent_files) && (recent)) { /* this prevents to have duplicities in list */ if (BLI_path_cmp(recent->filepath, G.main->name) != 0) { fprintf(fp, "%s\n", recent->filepath); recent = recent->next; } else { next_recent = recent->next; MEM_freeN(recent->filepath); BLI_freelinkN(&(G.recent_files), recent); recent = next_recent; } i++; } fclose(fp); } /* also update most recent files on System */ GHOST_addToSystemRecentFiles(G.main->name); } }
static void node_dynamic_register_type(bNode *node) { nodeRegisterType(&node_all_shaders, node->typeinfo); /* nodeRegisterType copied it to a new one, so we * free the typeinfo itself, but not what it * points to: */ MEM_freeN(node->typeinfo); node->typeinfo = node_dynamic_find_typeinfo(&node_all_shaders, node->id); MEM_freeN(node->typeinfo->name); node->typeinfo->name = BLI_strdup(node->name); }
static ConsoleLine *console_lb_add_str__internal(ListBase *lb, char *str, bool own) { ConsoleLine *ci = MEM_callocN(sizeof(ConsoleLine), "ConsoleLine Add"); if (own) ci->line = str; else ci->line = BLI_strdup(str); ci->len = ci->len_alloc = strlen(str); BLI_addtail(lb, ci); return ci; }
static void rna_ksPath_RnaPath_set(PointerRNA *ptr, const char *value) { KS_Path *ksp = (KS_Path *)ptr->data; if (ksp->rna_path) MEM_freeN(ksp->rna_path); if (value[0]) ksp->rna_path = BLI_strdup(value); else ksp->rna_path = NULL; }
void RE_engine_set_error_message(RenderEngine *engine, const char *msg) { Render *re = engine->re; if (re != NULL) { RenderResult *rr = RE_AcquireResultRead(re); if (rr->error != NULL) { MEM_freeN(rr->error); } rr->error = BLI_strdup(msg); RE_ReleaseResult(re); } }
static void rna_FCurve_RnaPath_set(PointerRNA *ptr, const char *value) { FCurve *fcu= (FCurve *)ptr->data; if (fcu->rna_path) MEM_freeN(fcu->rna_path); if (strlen(value)) fcu->rna_path= BLI_strdup(value); else fcu->rna_path= NULL; }
static void rna_Text_filename_set(PointerRNA *ptr, const char *value) { Text *text= (Text*)ptr->data; if(text->name) MEM_freeN(text->name); if(value[0]) text->name= BLI_strdup(value); else text->name= NULL; }
void BLF_dir_add(const char *path) { DirBLF *dir; dir = blf_dir_find(path); if (dir) /* already in the list ? just return. */ return; dir = (DirBLF *)MEM_callocN(sizeof(DirBLF), "BLF_dir_add"); dir->path = BLI_strdup(path); BLI_addhead(&global_font_dir, dir); }
static void rna_DriverTarget_RnaPath_set(PointerRNA *ptr, const char *value) { DriverTarget *dtar= (DriverTarget *)ptr->data; // XXX in this case we need to be very careful, as this will require some new dependencies to be added! if (dtar->rna_path) MEM_freeN(dtar->rna_path); if (strlen(value)) dtar->rna_path= BLI_strdup(value); else dtar->rna_path= NULL; }
char *blf_dir_search(const char *file) { DirBLF *dir; char full_path[FILE_MAX]; char *s = NULL; for (dir = global_font_dir.first; dir; dir = dir->next) { BLI_join_dirfile(full_path, sizeof(full_path), dir->path, file); if (BLI_exists(full_path)) { s = BLI_strdup(full_path); break; } } if (!s) { /* check the current directory, why not ? */ if (BLI_exists(file)) s = BLI_strdup(file); } return s; }
static char *rna_ColorRamp_path(PointerRNA *ptr) { /* handle the cases where a single datablock may have 2 ramp types */ if (ptr->id.data) { ID *id= ptr->id.data; switch (GS(id->name)) { case ID_MA: /* material has 2 cases - diffuse and specular */ { Material *ma= (Material*)id; if (ptr->data == ma->ramp_col) return BLI_strdup("diffuse_ramp"); else if (ptr->data == ma->ramp_spec) return BLI_strdup("specular_ramp"); } break; } } /* everything else just uses 'color_ramp' */ return BLI_strdup("color_ramp"); }
/** * Generate an empty PreviewImage, if not yet existing. */ PreviewImage *BKE_previewimg_cached_ensure(const char *name) { PreviewImage *prv = NULL; void **key_p, **prv_p; if (!BLI_ghash_ensure_p_ex(gCachedPreviews, name, &key_p, &prv_p)) { *key_p = BLI_strdup(name); *prv_p = BKE_previewimg_create(); } prv = *prv_p; BLI_assert(prv); return prv; }
/** * Generate a PreviewImage from given file path, using thumbnails management, if not yet existing. */ PreviewImage *BKE_previewimg_cached_thumbnail_read( const char *name, const char *path, const int source, bool force_update) { PreviewImage *prv = NULL; void **prv_p; prv_p = BLI_ghash_lookup_p(gCachedPreviews, name); if (prv_p) { prv = *prv_p; BLI_assert(prv); } if (prv && force_update) { const char *prv_deferred_data = PRV_DEFERRED_DATA(prv); if (((int)prv_deferred_data[0] == source) && STREQ(&prv_deferred_data[1], path)) { /* If same path, no need to re-allocate preview, just clear it up. */ BKE_previewimg_clear(prv); } else { BKE_previewimg_free(&prv); } } if (!prv) { /* We pack needed data for lazy loading (source type, in a single char, and path). */ const size_t deferred_data_size = strlen(path) + 2; char *deferred_data; prv = previewimg_create_ex(deferred_data_size); deferred_data = PRV_DEFERRED_DATA(prv); deferred_data[0] = source; memcpy(&deferred_data[1], path, deferred_data_size - 1); force_update = true; } if (force_update) { if (prv_p) { *prv_p = prv; } else { BLI_ghash_insert(gCachedPreviews, BLI_strdup(name), prv); } } return prv; }
void modifier_setError(ModifierData *md, const char *format, ...) { char buffer[512]; va_list ap; va_start(ap, format); vsnprintf(buffer, sizeof(buffer), format, ap); va_end(ap); buffer[sizeof(buffer) - 1]= '\0'; if (md->error) MEM_freeN(md->error); md->error = BLI_strdup(buffer); }
void BLT_lang_init(void) { #ifdef WITH_INTERNATIONAL const char * const messagepath = BKE_appdir_folder_id(BLENDER_DATAFILES, "locale"); #endif /* Make sure LANG is correct and wouldn't cause std::rumtime_error. */ #ifndef _WIN32 /* TODO(sergey): This code only ensures LANG is set properly, so later when * Cycles will try to use file system API from boost there'll be no runtime * exception generated by std::locale() which _requires_ having proper LANG * set in the environment. * * Ideally we also need to ensure LC_ALL, LC_MESSAGES and others are also * set to a proper value, but currently it's not a huge deal and doesn't * cause any headache. * * Would also be good to find nicer way to check if LANG is correct. */ const char *lang = getenv("LANG"); if (lang != NULL) { char *old_locale = setlocale(LC_ALL, NULL); /* Make a copy so subsequenct setlocale() doesn't interfere. */ old_locale = BLI_strdup(old_locale); if (setlocale(LC_ALL, lang) == NULL) { setenv("LANG", "C", 1); printf("Warning: Falling back to the standard locale (\"C\")\n"); } setlocale(LC_ALL, old_locale); MEM_freeN(old_locale); } #endif #ifdef WITH_INTERNATIONAL if (messagepath) { bl_locale_init(messagepath, TEXT_DOMAIN_NAME); fill_locales(); } else { printf("%s: 'locale' data path for translations not found, continuing\n", __func__); } #else #endif }