// Evaluates all conditional lines and regex mods the loaded masterlist. // This exists so that Load() doesn't need to be called whenever the mods // installed are changed. Evaluation does not take place unless this function // is called. Repeated calls re-evaluate the masterlist from scratch each time, // ignoring the results of any previous evaluations. Paths are case-sensitive // if the underlying filesystem is case-sensitive. LOOT_API unsigned int loot_eval_lists(loot_db * const db, const unsigned int language) { if (db == nullptr) return c_error(loot_error_invalid_args, "Null pointer passed."); if (language != loot_lang_english && language != loot_lang_spanish && language != loot_lang_russian && language != loot_lang_french && language != loot_lang_chinese && language != loot_lang_polish && language != loot_lang_brazilian_portuguese && language != loot_lang_finnish && language != loot_lang_german && language != loot_lang_danish) return c_error(loot_error_invalid_args, "Invalid language code given."); // Clear caches before evaluating conditions. db->ClearCachedConditions(); loot::Masterlist temp = db->rawMetadata; loot::MetadataList userTemp = db->rawUserMetadata; try { // Refresh active plugins before evaluating conditions. temp.EvalAllConditions(*db, language); userTemp.EvalAllConditions(*db, language); } catch (loot::error& e) { return c_error(e); } db->GetMasterlist() = temp; db->GetUserlist() = userTemp; return loot_ok; }
LOOT_API unsigned int loot_sort_plugins(loot_db * const db, const char * const ** const sortedPlugins, size_t * const numPlugins) { if (db == nullptr || sortedPlugins == nullptr || numPlugins == nullptr) return c_error(loot_error_invalid_args, "Null pointer passed."); //Initialise output. *numPlugins = 0; *sortedPlugins = nullptr; try { // Always reload all the plugins. db->LoadPlugins(false); //Sort plugins into their load order. loot::PluginSorter sorter; db->setPluginNames(sorter.Sort(*db, loot::Language::english)); } catch (loot::error &e) { return c_error(e); } catch (std::bad_alloc& e) { return c_error(loot_error_no_mem, e.what()); } if (db->getPluginNames().empty()) return loot_ok; *numPlugins = db->getPluginNames().size(); *sortedPlugins = &db->getPluginNames()[0]; return loot_ok; }
// Explicitly manage database lifetime. Allows clients to free memory when // they want/need to. clientGame sets the game the DB is for, and dataPath // is the path to that game's Data folder, and is case-sensitive if the // underlying filesystem is case-sensitive. This function also checks that // plugins.txt and loadorder.txt (if they both exist) are in sync. If // dataPath == NULL then the API will attempt to detect the data path of // the specified game. LOOT_API unsigned int loot_create_db (loot_db * const db, const unsigned int clientGame, const char * const gamePath) { if (db == NULL || (clientGame != loot_game_tes4 && clientGame != loot_game_tes5 && clientGame != loot_game_fo3 && clientGame != loot_game_fonv)) return c_error(loot_error_invalid_args, "Null pointer passed."); //Set the locale to get encoding conversions working correctly. std::setlocale(LC_CTYPE, ""); std::locale global_loc = std::locale(); std::locale loc(global_loc, new boost::filesystem::detail::utf8_codecvt_facet()); boost::filesystem::path::imbue(loc); //Disable logging or else stdout will get overrun. boost::log::core::get()->set_logging_enabled(false); std::string game_path = ""; if (gamePath != NULL) game_path = gamePath; loot::Game game; try { game = loot::Game(clientGame).SetPath(game_path).Init(); //This also checks to see if the game is installed if game_path is empty and throws an exception if it is not detected. It also creates a folder in %LOCALAPPDATA% and reads the active plugins list, but that shouldn't be an issue. } catch (loot::error& e) { return c_error(e); } loot_db retVal; try { retVal = new _loot_db_int; } catch (std::bad_alloc& e) { return c_error(loot_error_no_mem, e.what()); } retVal->game = game; *db = retVal; return loot_ok; }
// Writes a minimal masterlist that only contains mods that have Bash Tag suggestions, // and/or dirty messages, plus the Tag suggestions and/or messages themselves and their // conditions, in order to create the Wrye Bash taglist. outputFile is the path to use // for output. If outputFile already exists, it will only be overwritten if overwrite is true. LOOT_API unsigned int loot_write_minimal_list (loot_db db, const char * const outputFile, const bool overwrite) { if (db == NULL || outputFile == NULL) return c_error(loot_error_invalid_args, "Null pointer passed."); if (boost::filesystem::exists(outputFile) && !overwrite) return c_error(loot_error_invalid_args, "Output file exists but overwrite is not set to true."); std::list<loot::Plugin> temp = db->metadata; for (std::list<loot::Plugin>::iterator it=temp.begin(), endIt=temp.end(); it != endIt; ++it) { loot::Plugin p(it->Name()); p.Tags(it->Tags()); p.DirtyInfo(it->DirtyInfo()); *it = p; } YAML::Emitter yout; yout.SetIndent(2); yout << YAML::BeginMap << YAML::Key << "plugins" << YAML::Value << temp << YAML::EndMap; boost::filesystem::path p(outputFile); loot::ofstream out(p); if (out.fail()) return c_error(loot_error_invalid_args, "Couldn't open output file"); out << yout.c_str(); out.close(); return loot_ok; }
// Returns an array of the Bash Tags encounterred when loading the masterlist // and userlist, and the number of tags in the returned array. The array and // its contents are static and should not be freed by the client. LOOT_API unsigned int loot_get_tag_map (loot_db db, char *** const tagMap, size_t * const numTags) { if (db == NULL || tagMap == NULL || numTags == NULL) return c_error(loot_error_invalid_args, "Null pointer passed."); //Clear existing array allocation. if (db->extTagMap != NULL) { for (size_t i=0, max=db->bashTagMap.size(); i < max; ++i) { delete [] db->extTagMap[i]; } delete [] db->extTagMap; db->extTagMap = NULL; } //Initialise output. *tagMap = NULL; *numTags = 0; boost::unordered_set<std::string> allTags; for (std::list<loot::Plugin>::iterator it=db->metadata.begin(), endIt=db->metadata.end(); it != endIt; ++it) { std::set<loot::Tag> tags = it->Tags(); for (std::set<loot::Tag>::const_iterator jt=tags.begin(), endJt=tags.end(); jt != endJt; ++jt) { allTags.insert(jt->Name()); } } for (std::list<loot::Plugin>::iterator it=db->userMetadata.begin(), endIt=db->userMetadata.end(); it != endIt; ++it) { std::set<loot::Tag> tags = it->Tags(); for (std::set<loot::Tag>::const_iterator jt=tags.begin(), endJt=tags.end(); jt != endJt; ++jt) { allTags.insert(jt->Name()); } } if (allTags.empty()) return loot_ok; try { db->extTagMap = new char*[allTags.size()]; } catch (std::bad_alloc& e) { return c_error(loot_error_no_mem, e.what()); } unsigned int UID = 0; try { for (boost::unordered_set<std::string>::const_iterator it=allTags.begin(), endIt=allTags.end(); it != endIt; ++it) { db->bashTagMap.emplace(*it, UID); //Also allocate memory. db->extTagMap[UID] = ToNewCString(*it); UID++; } } catch (std::bad_alloc& e) { return c_error(loot_error_no_mem, e.what()); } *tagMap = db->extTagMap; *numTags = allTags.size(); return loot_ok; }
int c_linalg_LU_invert (c_matrix *lu, c_vector_int *p) { int info; if (c_matrix_is_empty (lu)) c_error ("c_linalg_LU_invert", "matrix is empty."); if (c_vector_int_is_empty (p)) c_error ("c_linalg_LU_invert", "permutation is empty."); if (!c_matrix_is_square (lu)) c_error ("c_linalg_LU_invert", "matrix must be square."); info = c_linalg_lapack_dgetri (lu, p); return info; }
void c_linalg_LU_1up (c_matrix *l, c_matrix *u, c_vector_int *p, c_vector *s, c_vector *t) { int m; int n; int ldl; int ldu; double *w; if (c_matrix_is_empty (l)) c_error ("c_linalg_LU_1up", "matrix is empty."); if (c_matrix_is_empty (u)) c_error ("c_linalg_LU_1up", "matrix is empty."); if (c_vector_is_empty (s)) c_error ("c_linalg_LU_1up", "vector *s is empty."); if (c_vector_is_empty (t)) c_error ("c_linalg_LU_1up", "vector *t is empty."); if (c_vector_int_is_empty (p)) c_error ("c_linalg_LU_1up", "permulation is empty."); if (s->size != l->size1) c_error ("c_linalg_LU_1up", "vector and matrix size dose not match."); if (t->size != u->size2) c_error ("c_linalg_LU_1up", "vector and matrix size dose not match."); if (s->stride != 1 || t->stride != 1) c_error ("c_linalg_LU_1up", "cannot tread vector with stride."); m = (int) l->size1; n = (int) u->size2; ldl = (int) l->lda; ldu = (int) u->lda; w = (double *) malloc (l->size1 * sizeof (double)); F77CALL (dlup1up) (&m, &n, l->data, &ldl, u->data, &ldu, p->data, s->data, t->data, w); free (w); return; }
static bool _stat(const char* path,struct stat& s) { std::string tmp; if(path && *path && (path[strlen(path)-1] == '/')) { // trim any trailing / - win32 requires this tmp = path; tmp[strlen(path)-1] = 0; path = tmp.c_str(); } if(stat(path,&s)) { if((ENOENT != errno)&&(ENOTDIR != errno)) c_error("stat("<<path<<")"); c_error("stat("<<path<<")"); return false; } return true; }
LOOT_API unsigned int loot_apply_load_order(loot_db * const db, const char * const * const loadOrder, const size_t numPlugins) { if (db == nullptr || loadOrder == nullptr) return c_error(loot_error_invalid_args, "Null pointer passed."); try { db->SetLoadOrder(loadOrder, numPlugins); } catch (loot::error &e) { return c_error(e); } return loot_ok; }
// Returns the messages attached to the given plugin. Messages are valid until Load, // loot_destroy_db or loot_get_plugin_messages are next called. plugin is case-insensitive. // If no messages are attached, *messages will be NULL and numMessages will equal 0. LOOT_API unsigned int loot_get_plugin_messages (loot_db db, const char * const plugin, loot_message ** const messages, size_t * const numMessages) { if (db == NULL || plugin == NULL || messages == NULL || numMessages == NULL) return c_error(loot_error_invalid_args, "Null pointer passed."); //Clear existing array allocation. if (db->extMessageArray != NULL) { for (size_t i=0; i < db->extMessageArraySize; ++i) { delete [] db->extMessageArray[i].message; } delete [] db->extMessageArray; db->extMessageArray = NULL; } //Initialise output. *messages = NULL; *numMessages = 0; std::list<loot::Message> pluginMessages; std::list<loot::Plugin>::iterator pluginIt = std::find(db->metadata.begin(), db->metadata.end(), loot::Plugin(plugin)); if (pluginIt != db->metadata.end()) { pluginMessages = pluginIt->Messages(); } pluginIt = std::find(db->userMetadata.begin(), db->userMetadata.end(), loot::Plugin(plugin)); if (pluginIt != db->userMetadata.end()) { std::list<loot::Message> temp = pluginIt->Messages(); pluginMessages.insert(pluginMessages.end(), temp.begin(), temp.end()); } db->extMessageArraySize = pluginMessages.size(); try { db->extMessageArray = new loot_message[db->extMessageArraySize]; int i = 0; for (std::list<loot::Message>::const_iterator it=pluginMessages.begin(), endIt=pluginMessages.end(); it != endIt; ++it) { db->extMessageArray[i].type = it->Type(); db->extMessageArray[i].message = ToNewCString(it->ChooseContent(loot::Language::any).Str()); } } catch (std::bad_alloc& e) { return c_error(loot_error_no_mem, e.what()); } *messages = db->extMessageArray; *numMessages = db->extMessageArraySize; return loot_ok; }
// Returns the messages attached to the given plugin. Messages are valid until Load, // loot_destroy_db or loot_get_plugin_messages are next called. plugin is case-insensitive. // If no messages are attached, *messages will be nullptr and numMessages will equal 0. LOOT_API unsigned int loot_get_plugin_messages(loot_db * const db, const char * const plugin, const loot_message ** const messages, size_t * const numMessages) { if (db == nullptr || plugin == nullptr || messages == nullptr || numMessages == nullptr) return c_error(loot_error_invalid_args, "Null pointer passed."); //Initialise output. *messages = nullptr; *numMessages = 0; loot::PluginMetadata p = db->GetMasterlist().FindPlugin(loot::PluginMetadata(plugin)); std::list<loot::Message> pluginMessages(p.Messages()); p = db->GetUserlist().FindPlugin(loot::PluginMetadata(plugin)); std::list<loot::Message> temp(p.Messages()); pluginMessages.insert(pluginMessages.end(), temp.begin(), temp.end()); if (pluginMessages.empty()) return loot_ok; db->setPluginMessages(pluginMessages); *messages = &db->getPluginMessages()[0]; *numMessages = db->getPluginMessages().size(); return loot_ok; }
void c_linalg_LU_unpack (const c_matrix *lu, c_matrix **l, c_matrix **u) { int min_mn; if (c_matrix_is_empty (lu)) c_error ("c_linalg_LU_unpack", "matrix is empty."); min_mn = (int) C_MIN (lu->size1, lu->size2); if (l) { int i; c_matrix *_l = c_matrix_alloc (lu->size1, min_mn); c_matrix_set_zero (_l); c_matrix_lower_triangular_memcpy (_l, lu); for (i = 0; i < min_mn; i++) c_matrix_set (_l, i, i, 1.); *l = _l; } if (u) { c_matrix *_u = c_matrix_alloc (min_mn, lu->size2); c_matrix_set_zero (_u); c_matrix_upper_triangular_memcpy (_u, lu); *u = _u; } return; }
LOOT_API unsigned int loot_get_dirty_info(loot_db * const db, const char * const plugin, unsigned int * const needsCleaning) { if (db == nullptr || plugin == nullptr || needsCleaning == nullptr) return c_error(loot_error_invalid_args, "Null pointer passed."); *needsCleaning = loot_needs_cleaning_unknown; // Is there any dirty info? Testing for applicability happens in loot_eval_lists(). if (!db->GetMasterlist().FindPlugin(loot::PluginMetadata(plugin)).DirtyInfo().empty() || !db->GetUserlist().FindPlugin(loot::PluginMetadata(plugin)).DirtyInfo().empty()) { *needsCleaning = loot_needs_cleaning_yes; } // Is there a message beginning with the substring "Do not clean."? // This isn't a very reliable system, because if the lists have been evaluated in some language // other than English, the strings will be in different languages (and the API can't tell what they'd be) // and the strings may be non-standard and begin with something other than "Do not clean." anyway. std::list<loot::Message> messages(db->GetMasterlist().FindPlugin(loot::PluginMetadata(plugin)).Messages()); std::list<loot::Message> temp(db->GetUserlist().FindPlugin(loot::PluginMetadata(plugin)).Messages()); messages.insert(messages.end(), temp.begin(), temp.end()); for (const auto& message : messages) { if (boost::starts_with(message.ChooseContent(loot::Language::english).Str(), "Do not clean")) { *needsCleaning = loot_needs_cleaning_no; break; } } return loot_ok; }
static void paint_cb(uv_idle_t *idle) { Data *data = idle->data; cg_error_t *error = NULL; const cg_gles2_vtable_t *gles2 = data->gles2_vtable; /* Draw scene with GLES2 */ if (!cg_push_gles2_context( data->dev, data->gles2_ctx, data->fb, data->fb, &error)) { c_error("Failed to push gles2 context: %s\n", error->message); } /* Clear offscreen framebuffer with a random color */ gles2->glClearColor( c_random_double(), c_random_double(), c_random_double(), 1.0f); gles2->glClear(GL_COLOR_BUFFER_BIT); cg_pop_gles2_context(data->dev); /* Draw scene with Cogl */ cg_primitive_draw(data->triangle, data->fb, data->pipeline); cg_onscreen_swap_buffers(CG_ONSCREEN(data->fb)); uv_idle_stop(&data->idle); }
void FILE_stream_t::write(const void* src,size_t bytes) { const size_t ret = fwrite(src,1,bytes,f); if(ret < 0) c_error("could not write "<<bytes<<" to "<<filename); if(bytes != ret) data_error("could not write "<<bytes<<" to "<<filename<<" ("<<ret<<'@'<<ftell(f)<<')'); }
void FILE_stream_t::read(void* dest,size_t bytes) { const size_t ret = fread(dest,1,bytes,f); if(ret < 0) c_error("could not read "<<bytes<<" from "<<filename); if(bytes != ret) data_error("could not read "<<bytes<<" from "<<filename<<" ("<<ret<<'@'<<ftell(f)<<')'); }
FILE_stream_t::FILE_stream_t(fs_file_t& file,const char* filename_,const char* mode): istream_t(file), filename(filename_), f(fopen(filename_,mode)) { if(!f) c_error("could not open "<<filename<<" for "<<mode); }
static void eml_li_find(const emlrtStack *sp, const boolean_T x_data[1224], const int32_T x_size[1], int32_T y_data[1224], int32_T y_size[1]) { int32_T k; const mxArray *y; const mxArray *m25; int32_T i; emlrtStack st; st.prev = sp; st.tls = sp->tls; st.site = &dr_emlrtRSI; k = compute_nones(&st, x_data, x_size[0]); if (k <= x_size[0]) { } else { y = NULL; m25 = mxCreateString("Assertion failed."); emlrtAssign(&y, m25); st.site = &ov_emlrtRSI; c_error(&st, y, &db_emlrtMCI); } emlrtNonNegativeCheckFastR2012b(k, &c_emlrtDCI, sp); y_size[0] = k; k = 0; st.site = &er_emlrtRSI; for (i = 1; i <= x_size[0]; i++) { if (x_data[i - 1]) { y_data[k] = i; st.site = &fr_emlrtRSI; k++; } } }
strings_t fs_t::pimpl_t::list(const std::string& path,bool (*test)(const char*)) { strings_t list; #ifdef WIN32 if(DIR *dir = opendir(path.c_str())) { while(dirent* entry = readdir(dir)) { if((entry->d_name[0] != '.') && test(fs.join(path,entry->d_name).c_str())) list.push_back(entry->d_name); } closedir(dir); } else data_error("list_dirs("<<path<<"): cannot open"); #else struct dirent64 **eps; if(int n = scandir64(path.c_str(),&eps,_one,alphasort64)) { if(-1 == n) c_error("list_dirs("<<path<<")"); for(int i=0; i<n; i++) { if((eps[i]->d_name[0] != '.') && test(fs.join(path,eps[i]->d_name).c_str())) list.push_back(eps[i]->d_name); free(eps[i]); } free(eps); } #endif return list; }
// Outputs a string giving the details of the last time an error or // warning return code was returned by a function. The string exists // until this function is called again or until CleanUpAPI is called. LOOT_API unsigned int loot_get_error_message(const char ** const message) { if (message == nullptr) return c_error(loot_error_invalid_args, "Null message pointer passed."); *message = extMessageStr.c_str(); return loot_ok; }
LOOT_API unsigned int loot_get_build_id(const char ** const revision) { if (revision == nullptr) return c_error(loot_error_invalid_args, "Null message pointer passed."); *revision = loot::g_build_revision; return loot_ok; }
// Loads the masterlist and userlist from the paths specified. // Can be called multiple times. On error, the database is unchanged. // Paths are case-sensitive if the underlying filesystem is case-sensitive. // masterlistPath and userlistPath are files. LOOT_API unsigned int loot_load_lists(loot_db * const db, const char * const masterlistPath, const char * const userlistPath) { if (db == nullptr || masterlistPath == nullptr) return c_error(loot_error_invalid_args, "Null pointer passed."); loot::Masterlist temp; loot::MetadataList userTemp; try { if (boost::filesystem::exists(masterlistPath)) { temp.Load(masterlistPath); } else { return c_error(loot_error_path_not_found, std::string("The given masterlist path does not exist: ") + masterlistPath); } } catch (std::exception& e) { return c_error(loot_error_parse_fail, e.what()); } try { if (userlistPath != nullptr) { if (boost::filesystem::exists(userlistPath)) { userTemp.Load(userlistPath); } else { return c_error(loot_error_path_not_found, std::string("The given userlist path does not exist: ") + userlistPath); } } } catch (YAML::Exception& e) { return c_error(loot_error_parse_fail, e.what()); } //Also free memory. db->clearBashTagMap(); db->clearArrays(); db->GetMasterlist() = temp; db->rawMetadata = temp; db->GetUserlist() = userTemp; db->rawUserMetadata = userTemp; return loot_ok; }
LOOT_API unsigned int loot_get_masterlist_revision(loot_db * const db, const char * const masterlistPath, const bool getShortID, const char ** const revisionID, const char ** const revisionDate, bool * const isModified) { if (db == nullptr || masterlistPath == nullptr || revisionID == nullptr || revisionDate == nullptr || isModified == nullptr) return c_error(loot_error_invalid_args, "Null pointer passed."); *revisionID = nullptr; *revisionDate = nullptr; *isModified = false; bool edited = false; try { loot::Masterlist::Info info = loot::Masterlist::GetInfo(masterlistPath, getShortID); std::string id = info.revision; std::string date = info.date; if (boost::ends_with(id, " (edited)")) { id = id.substr(0, id.length() - 9); date = date.substr(0, date.length() - 9); edited = true; } db->setRevisionIdString(id); db->setRevisionDateString(date); } catch (loot::error &e) { if (e.code() == loot_ok) return loot_ok; else return c_error(e); } catch (std::bad_alloc& e) { return c_error(loot_error_no_mem, e.what()); } *revisionID = db->getRevisionIdString(); *revisionDate = db->getRevisionDateString(); *isModified = edited; return loot_ok; }
// Returns the version string for this version of LOOT. // The string exists until this function is called again or until // CleanUpAPI is called. LOOT_API unsigned int loot_get_version(unsigned int * const versionMajor, unsigned int * const versionMinor, unsigned int * const versionPatch) { if (versionMajor == nullptr || versionMinor == nullptr || versionPatch == nullptr) return c_error(loot_error_invalid_args, "Null pointer passed."); *versionMajor = loot::g_version_major; *versionMinor = loot::g_version_minor; *versionPatch = loot::g_version_patch; return loot_ok; }
// Writes a minimal masterlist that only contains mods that have Bash Tag suggestions, // and/or dirty messages, plus the Tag suggestions and/or messages themselves and their // conditions, in order to create the Wrye Bash taglist. outputFile is the path to use // for output. If outputFile already exists, it will only be overwritten if overwrite is true. LOOT_API unsigned int loot_write_minimal_list(loot_db * const db, const char * const outputFile, const bool overwrite) { if (db == nullptr || outputFile == nullptr) return c_error(loot_error_invalid_args, "Null pointer passed."); if (!boost::filesystem::exists(boost::filesystem::path(outputFile).parent_path())) return c_error(loot_error_invalid_args, "Output directory does not exist."); if (boost::filesystem::exists(outputFile) && !overwrite) return c_error(loot_error_file_write_fail, "Output file exists but overwrite is not set to true."); loot::Masterlist temp = db->GetMasterlist(); std::unordered_set<loot::PluginMetadata> minimalPlugins; for (const auto &plugin : temp.Plugins()) { loot::PluginMetadata p(plugin.Name()); p.Tags(plugin.Tags()); p.DirtyInfo(plugin.DirtyInfo()); minimalPlugins.insert(p); } YAML::Emitter yout; yout.SetIndent(2); yout << YAML::BeginMap << YAML::Key << "plugins" << YAML::Value << minimalPlugins << YAML::EndMap; boost::filesystem::path p(outputFile); try { boost::filesystem::ofstream out(p); if (out.fail()) return c_error(loot_error_file_write_fail, "Couldn't open output file."); out << yout.c_str(); out.close(); } catch (std::exception& e) { return c_error(loot_error_file_write_fail, e.what()); } return loot_ok; }
// Returns an array of the Bash Tags encounterred when loading the masterlist // and userlist, and the number of tags in the returned array. The array and // its contents are static and should not be freed by the client. LOOT_API unsigned int loot_get_tag_map(loot_db * const db, const char * const ** const tagMap, size_t * const numTags) { if (db == nullptr || tagMap == nullptr || numTags == nullptr) return c_error(loot_error_invalid_args, "Null pointer passed."); //Clear existing array allocation. db->clearBashTagMap(); //Initialise output. *tagMap = nullptr; *numTags = 0; std::set<std::string> allTags; for (const auto &plugin : db->GetMasterlist().Plugins()) { for (const auto &tag : plugin.Tags()) { allTags.insert(tag.Name()); } } for (const auto &plugin : db->GetUserlist().Plugins()) { for (const auto &tag : plugin.Tags()) { allTags.insert(tag.Name()); } } if (allTags.empty()) return loot_ok; try { db->addBashTagsToMap(allTags); } catch (std::bad_alloc& e) { return c_error(loot_error_no_mem, e.what()); } *tagMap = &db->getBashTagMap()[0]; *numTags = db->getBashTagMap().size(); return loot_ok; }
LOOT_API unsigned int loot_update_masterlist(loot_db * const db, const char * const masterlistPath, const char * const remoteURL, const char * const remoteBranch, bool * const updated) { if (db == nullptr || masterlistPath == nullptr || remoteURL == nullptr || remoteBranch == nullptr || updated == nullptr) return c_error(loot_error_invalid_args, "Null pointer passed."); if (!boost::filesystem::is_directory(boost::filesystem::path(masterlistPath).parent_path())) return c_error(loot_error_invalid_args, "Given masterlist path \"" + std::string(masterlistPath) + "\" does not have a valid parent directory."); *updated = false; try { loot::Masterlist masterlist; *updated = masterlist.Update(masterlistPath, remoteURL, remoteBranch); } catch (loot::error &e) { return c_error(e); } return loot_ok; }
int c_linalg_LU_solve (c_matrix *a, c_vector *b, c_vector_int **p) { int info; c_matrix *c; c_vector_int *_p = NULL; if (c_matrix_is_empty (a)) c_error ("c_linalg_LU_solve", "matrix is empty."); if (c_vector_is_empty (b)) c_error ("c_linalg_LU_solve", "vector is empty."); if (!c_matrix_is_square (a)) c_error ("c_linalg_LU_solve", "matrix must be square."); if (b->stride != 1) c_error ("c_linalg_LU_solve", "cannot tread vector with stride."); if (b->size != a->size1) c_error ("c_linalg_LU_solve", "matrix and vector size dose not match."); c = c_matrix_view_array (b->size, 1, b->size, b->data); info = c_linalg_lapack_dgesv (a, c, &_p); c_matrix_free (c); if (p) *p = _p; else if (!c_vector_int_is_empty (_p)) c_vector_int_free (_p); return info; }
int main(int argc, char **argv) { cg_onscreen_t *onscreen; cg_error_t *error = NULL; struct demo demo; float fovy, aspect, z_near, z_2d, z_far; uv_loop_t *loop = uv_default_loop(); demo.dev = cg_device_new (); if (!demo.dev || error != NULL) c_error("Failed to create Cogl context\n"); onscreen = cg_onscreen_new(demo.dev, WIDTH, HEIGHT); demo.fb = onscreen; demo.width = cg_framebuffer_get_width(demo.fb); demo.height = cg_framebuffer_get_height(demo.fb); cg_onscreen_show(onscreen); cg_framebuffer_set_viewport(demo.fb, 0, 0, demo.width, demo.height); fovy = 45; aspect = (float)demo.width / (float)demo.height; z_near = 0.1; z_2d = 1000; z_far = 2000; cg_framebuffer_perspective(demo.fb, fovy, aspect, z_near, z_far); c_matrix_init_identity(&demo.view); c_matrix_view_2d_in_perspective(&demo.view, fovy, aspect, z_near, z_2d, demo.width, demo.height); cg_framebuffer_set_modelview_matrix(demo.fb, &demo.view); demo.swap_ready = true; cg_onscreen_add_frame_callback(demo.fb, frame_event_cb, &demo, NULL); init_particle_emitters(&demo); demo.timer = c_timer_new(); demo.spin_rate = 0; demo.angle_between_emitters = 2 * M_PI / C_N_ELEMENTS(demo.emitter); uv_idle_init(loop, &demo.idle); demo.idle.data = &demo; uv_idle_start(&demo.idle, paint_cb); cg_uv_set_mainloop(demo.dev, loop); uv_run(loop, UV_RUN_DEFAULT); return 0; }
// Explicitly manage database lifetime. Allows clients to free memory when // they want/need to. clientGame sets the game the DB is for, and dataPath // is the path to that game's Data folder, and is case-sensitive if the // underlying filesystem is case-sensitive. This function also checks that // plugins.txt and loadorder.txt (if they both exist) are in sync. If // dataPath == nullptr then the API will attempt to detect the data path of // the specified game. LOOT_API unsigned int loot_create_db(loot_db ** const db, const unsigned int clientGame, const char * const gamePath, const char * const gameLocalPath) { if (db == nullptr || (clientGame != loot_game_tes4 && clientGame != loot_game_tes5 && clientGame != loot_game_fo3 && clientGame != loot_game_fonv && clientGame != loot_game_fo4)) return c_error(loot_error_invalid_args, "Null pointer passed."); //Set the locale to get encoding conversions working correctly. std::locale::global(boost::locale::generator().generate("")); boost::filesystem::path::imbue(std::locale()); //Disable logging or else stdout will get overrun. boost::log::core::get()->set_logging_enabled(false); std::string game_path = ""; if (gamePath != nullptr) game_path = gamePath; boost::filesystem::path game_local_path = ""; if (gameLocalPath != nullptr) game_local_path = gameLocalPath; #ifndef _WIN32 else return c_error(loot_error_invalid_args, "A local data path must be supplied on non-Windows platforms."); #endif try { // Check for valid paths. if (gamePath != nullptr && !boost::filesystem::is_directory(gamePath)) return c_error(loot_error_invalid_args, "Given game path \"" + std::string(gamePath) + "\" is not a valid directory."); if (gameLocalPath != nullptr && !boost::filesystem::is_directory(gameLocalPath)) return c_error(loot_error_invalid_args, "Given local data path \"" + std::string(gameLocalPath) + "\" is not a valid directory."); *db = new loot_db(clientGame, game_path, game_local_path); } catch (loot::error& e) { return c_error(e); } catch (std::bad_alloc& e) { return c_error(loot_error_no_mem, e.what()); } catch (std::exception& e) { return c_error(loot_error_invalid_args, e.what()); } return loot_ok; }