void Thesaurus::OnLanguageChanged() { impl.reset(); auto language = OPT_GET("Tool/Thesaurus/Language")->GetString(); if (language.empty()) return; agi::fs::path idx, dat; auto path = config::path->Decode(OPT_GET("Path/Dictionary")->GetString() + "/"); if (!check_path(path, language, idx, dat)) { path = config::path->Decode("?data/dictionaries/"); if (!check_path(path, language, idx, dat)) return; } LOG_I("thesaurus/file") << "Using thesaurus: " << dat; agi::dispatch::Background().Async([=]{ try { auto thes = agi::util::make_unique<agi::Thesaurus>(dat, idx); agi::dispatch::Main().Sync([&]{ impl = std::move(thes); }); } catch (agi::Exception const& e) { LOG_E("thesaurus") << e.GetChainedMessage(); } }); }
// "path" is the path to lookup; will advance this pointer beyond the volume name. // Returns logical drive number (-1 means invalid path). int ff_get_ldnumber (const TCHAR **path) { if (!(*path)) { return -1; } if (**path != '/') { #if _FS_RPATH return ff_CurrVol; #else return -1; #endif } if (check_path(path, "/flash", 6)) { return PD_FLASH; } else { for (mp_uint_t i = 0; i < MP_STATE_PORT(mount_obj_list).len; i++) { os_fs_mount_t *mount_obj = ((os_fs_mount_t *)(MP_STATE_PORT(mount_obj_list).items[i])); if (check_path(path, mount_obj->path, mount_obj->pathlen)) { return mount_obj->vol; } } } return -1; }
void ft_cd(char *buf, t_params *p) { char **av; char *new_dir; int ret; int size; ret = 0; av = ft_split(buf); new_dir = NULL; size = av_size(av); if (size > 2) ft_putendl("cd: syntax error"); else if (size == 1 || (size == 2 && !ft_strcmp(av[1], "~"))) new_dir = ft_strdup(p->home); else new_dir = get_newdir(p, av[1]); if (new_dir && !(ret = check_path(new_dir)) && !chdir(new_dir)) update_env(p, new_dir); else if (new_dir && !(ret = check_path(new_dir)) && chdir(new_dir) == -1) ft_print_error("cd: not a directory: ", av[1]); if (new_dir && ret && av[1]) improper_path(ret, av[1]); ft_strdel(&new_dir); del_av(av); }
void Util::detectCclive( QString& path, QString& version, QString& libVersion, QString& libName, bool *isCcliveFlag) { const QStringList env = QProcess::systemEnvironment(); QRegExp re("^PATH=(.*)", Qt::CaseInsensitive); env.indexOf(re); const QString capt = re.capturedTexts()[1].simplified(); QStringList paths = capt.split(":"); if (paths.size() < 2) // w32 paths = capt.split(";"); if (paths.size() < 2) return; path = check_path(paths, "cclive"); if (path.isEmpty()) path = check_path(paths, "clive"); if (path.isEmpty()) { // Detection from $PATH failed. Prompt user // to specify the path in preferences manually. throw NoCcliveException( QObject::tr( "Neither cclive or clive not was found in the path.\n" "Please specify the path to either command in the\n" "preferences." ) ); } else { // Check --version output. verify_version_output( path, version, libVersion, libName, isCcliveFlag ); } }
/* on windows, data files should always be in [base directory]/data */ char *obs_find_plugin_file(const char *file) { struct dstr path; dstr_init(&path); if (check_path(file, "data/obs-plugins/", &path)) return path.array; if (check_path(file, "../../data/obs-plugins/", &path)) return path.array; dstr_free(&path); return NULL; }
/* on windows, points to [base directory]/libobs */ char *find_libobs_data_file(const char *file) { struct dstr path; dstr_init(&path); if (check_path(file, "data/libobs/", &path)) return path.array; if (check_path(file, "../../data/libobs/", &path)) return path.array; dstr_free(&path); return NULL; }
int main(int argc, char *argv[]) { void *fdt; test_init(argc, argv); fdt = load_blob_arg(argc, argv); check_path(fdt, "/"); check_path(fdt, "/subnode@1"); check_path(fdt, "/subnode@2"); check_path(fdt, "/subnode@1/subsubnode"); check_path(fdt, "/subnode@2/subsubnode@0"); PASS(); }
static void compact(char *bundle) { check_path(bundle, "token"); check_path(bundle, "Info.plist"); check_path(bundle, "bands"); char *bands = strdup(buf); DIR *dir = opendir(bands); if (!dir) die("Can't open band dir"); struct dirent *de; while ((de = readdir(dir))) { if (de->d_name[0] == '.') continue; fprintf(stdout, "%5s ", de->d_name); if (snprintf(buf, PATH_MAX, "%s/%s", bands, de->d_name) >= PATH_MAX) die("Paths too long"); int fd = open(buf, O_RDWR); if (!fd) die("Can't open band"); ssize_t size = lseek(fd, 0, SEEK_END); if (size == -1) die("Can't seek"); char *bytes = mmap(NULL, size, PROT_READ, MAP_FILE | MAP_SHARED, fd, 0); if (bytes == MAP_FAILED) die("Can't mmap"); size_t nz = size; for (; nz > 0 && !bytes[nz - 1]; --nz) ; munmap(bytes, size); if (nz > 0 && nz < size) { fprintf(stdout, "saving %ld", size - nz); if (ftruncate(fd, nz) != 0) die("Can't truncate"); } close(fd); if (nz == 0) { fprintf(stdout, "removing"); if (unlink(buf) != 0) die("Can't unlink"); } fprintf(stdout, "\n"); } free(bands); closedir(dir); }
int check_path_from_xpath(xmlXPathContextPtr xpath_ctx, const char *log_string, const xmlChar *path_xexpr) { int status = 0; xmlXPathObjectPtr xpath_obj; char* temp_char = NULL; xpath_obj = xmlXPathEvalExpression(path_xexpr, xpath_ctx); if(xpath_obj == NULL) { dual_log("ERROR: unable to evaluate xpath expression: %s", path_xexpr); return 1; } if (xpath_obj->nodesetval != NULL && xpath_obj->nodesetval->nodeNr > 0) { temp_char = (char*) xmlXPathCastToString(xpath_obj); status = check_path(temp_char, log_string); StrFree(temp_char); } else { /* Not set; return -1 so that we can test the default path */ xmlXPathFreeObject(xpath_obj); return -1; } xmlXPathFreeObject(xpath_obj); return status; }
MuError mu_index_stats (MuIndex *index, const char *path, MuIndexStats *stats, MuIndexMsgCallback cb_msg, MuIndexDirCallback cb_dir, void *user_data) { MuIndexCallbackData cb_data; g_return_val_if_fail (index, MU_ERROR); g_return_val_if_fail (cb_msg, MU_ERROR); if (!check_path (path)) return MU_ERROR; if (stats) memset (stats, 0, sizeof(MuIndexStats)); cb_data._idx_msg_cb = cb_msg; cb_data._idx_dir_cb = cb_dir; cb_data._stats = stats; cb_data._user_data = user_data; cb_data._dirstamp = 0; return mu_maildir_walk (path, (MuMaildirWalkMsgCallback)on_stats_maildir_file, NULL, FALSE, &cb_data); }
static int global_physics_sweep_col_mesh (lua_State *L) { TRY_START int base_line = 7; check_args_min(L, base_line); std::string col_mesh_name = check_path(L, 1); DiskResource *col_mesh_ = disk_resource_get_or_make(col_mesh_name); CollisionMesh *col_mesh = dynamic_cast<CollisionMesh*>(col_mesh_); Quaternion q = check_quat(L, 2); Vector3 start = check_v3(L, 3); Vector3 ray = check_v3(L, 4); bool nearest_only = check_bool(L, 5); unsigned long flags = check_t<unsigned long>(L, 6); if (lua_type(L, 7) != LUA_TFUNCTION) my_lua_error(L, "Parameter 5 should be a function."); LuaSweepCallback lcb(nearest_only, flags); init_cast_blacklist(L, base_line, lcb); physics_sweep_col_mesh(start, q, start + ray, q, lcb, col_mesh); push_cfunction(L, my_lua_error_handler); int error_handler = lua_gettop(L); lcb.pushResults(L, 7, error_handler); return 0; TRY_END }
static int global_physics_test (lua_State *L) { TRY_START LuaTestCallback lcb; push_cfunction(L, my_lua_error_handler); int error_handler = lua_gettop(L); if (lua_gettop(L)==5) { float radius = lua_tonumber(L, 1); Vector3 pos = check_v3(L, 2); bool only_dyn = check_bool(L, 3); if (lua_type(L, 4) != LUA_TFUNCTION) my_lua_error(L, "Parameter 4 should be a function."); physics_test_sphere(radius, pos, only_dyn, lcb); lcb.pushResults(L, 4, error_handler); } else { check_args(L, 6); std::string col_mesh_name = check_path(L, 1); DiskResource *col_mesh_ = disk_resource_get_or_make(col_mesh_name); CollisionMesh *col_mesh = dynamic_cast<CollisionMesh*>(col_mesh_); if (col_mesh==NULL) my_lua_error(L, "Not a collision mesh: \""+col_mesh_name+"\""); if (!col_mesh->isLoaded()) my_lua_error(L, "Not loaded: \""+col_mesh_name+"\""); Vector3 pos = check_v3(L, 2); Quaternion quat = check_quat(L, 3); bool only_dyn = check_bool(L, 4); if (lua_type(L, 5) != LUA_TFUNCTION) my_lua_error(L, "Parameter 5 should be a function."); physics_test(col_mesh, pos, quat, only_dyn, lcb); lcb.pushResults(L, 5, error_handler); } lua_pop(L, 1); // error handler return 0; TRY_END }
int path_finder(char **map, int number_path, t_server *server) { int index_position_y; int index_position_x; int position[3]; int find_path; find_path = 0; for (index_position_y = 0; index_position_y < server->map.height; index_position_y++) { for (index_position_x = 0; index_position_x < server->map.width; index_position_x++) { position[0] = index_position_x; position[1] = index_position_y; position[2] = 0; if (map[index_position_y][index_position_x] == number_path && check_path(map, position, number_path, server) != 0) find_path = 1; } } return (find_path); }
static int rbody_ranged_scatter (lua_State *L) { TRY_START check_args(L, 12); GET_UD_MACRO(RigidBody, self, 1, RBODY_TAG); std::string mat = check_path(L, 2); GET_UD_MACRO(GfxRangedInstancesPtr, gri, 3, GFXRANGEDINSTANCES_TAG); float density = check_float(L, 4); float min_slope = check_float(L, 5); float max_slope = check_float(L, 6); float min_elevation = check_float(L, 7); float max_elevation = check_float(L, 8); bool no_z = check_bool(L, 9); bool rotate = check_bool(L, 10); bool align_slope = check_bool(L, 11); unsigned seed = check_t<unsigned>(L, 12); SimpleTransform world_trans(self.getPosition(), self.getOrientation()); self.colMesh->scatter(phys_mats.getMaterial(mat)->id, world_trans, density, min_slope, max_slope, min_elevation, max_elevation, no_z, rotate, align_slope, seed, *gri); return 0; TRY_END }
MuError mu_index_run (MuIndex *index, const char *path, gboolean reindex, MuIndexStats *stats, MuIndexMsgCallback msg_cb, MuIndexDirCallback dir_cb, void *user_data) { MuIndexCallbackData cb_data; MuError rv; g_return_val_if_fail (index && index->_store, MU_ERROR); g_return_val_if_fail (msg_cb, MU_ERROR); if (!check_path (path)) return MU_ERROR; if (!reindex && index->_needs_reindex) { g_warning ("database not up-to-date; needs full reindex"); return MU_ERROR; } init_cb_data (&cb_data, index->_store, reindex, index->_max_filesize, stats, msg_cb, dir_cb, user_data); rv = mu_maildir_walk (path, (MuMaildirWalkMsgCallback)on_run_maildir_msg, (MuMaildirWalkDirCallback)on_run_maildir_dir, reindex, /* re-index, ie. do a full update */ &cb_data); mu_store_flush (index->_store); return rv; }
void Dialog::on_lineEdit_target_product_textChanged(const QString &arg1) { if(check_path() == false) ui->pushButton_edit_path->setDisabled(true); else ui->pushButton_edit_path->setDisabled(false); }
int get_requests(int fd) { char *buf; char *destroylist[256]; int dll; int i; dll = 0; while(1) { if(dll >= 255) break; buf = calloc(REQSZ, 1); if(read(fd, buf, REQSZ) != REQSZ) break; if(strncmp(buf, "FSRD", 4) != 0) break; check_path(buf + 4); dll++; } for(i = 0; i < dll; i++) { write(fd, "Process OK\n", strlen("Process OK\n")); free(destroylist[i]); } }
static int check_path(t_env *data, int step) { int i; t_room *ptr; i = 0; ptr = data->rooms; if (step > data->nb_room) return (0); while (ptr) { if (ptr->weight == step - 1) { while (ptr->link && ptr->link[i]) { if (!(ptr->link[i]->weight)) ptr->link[i]->weight = step; i++; } i = 0; } ptr = ptr->next; } if (complete_path(data)) return (1); return (check_path(data, step + 1)); }
int nghttp2_http_on_request_headers(nghttp2_stream *stream, nghttp2_frame *frame) { if (stream->http_flags & NGHTTP2_HTTP_FLAG_METH_CONNECT) { if ((stream->http_flags & NGHTTP2_HTTP_FLAG__AUTHORITY) == 0) { return -1; } stream->content_length = -1; } else { if ((stream->http_flags & NGHTTP2_HTTP_FLAG_REQ_HEADERS) != NGHTTP2_HTTP_FLAG_REQ_HEADERS || (stream->http_flags & (NGHTTP2_HTTP_FLAG__AUTHORITY | NGHTTP2_HTTP_FLAG_HOST)) == 0) { return -1; } if (!check_path(stream)) { return -1; } } if (frame->hd.type == NGHTTP2_PUSH_PROMISE) { /* we are going to reuse data fields for upcoming response. Clear them now, except for method flags. */ stream->http_flags &= NGHTTP2_HTTP_FLAG_METH_ALL; stream->content_length = -1; } return 0; }
/* PRINT FILE */ void show(char *filename) { int fd , n; char buf [128]; char *fname = 0; fname = malloc(strlen(glpath) + strlen(filename) + 2); sprintf(fname, "%s/%s", glpath, filename); if (!check_path(fname)) sprintf(fname, "/%s", filename); if ((fd = open(fname, O_RDONLY)) != -1) { while ((n = read(fd, buf, sizeof(buf))) > 0) printf("%.*s", n, buf); close(fd); } else { sprintf(fname, "/%s", filename); if ((fd = open(fname, O_RDONLY)) != -1) { while ((n = read(fd, buf, sizeof(buf))) > 0) printf("%.*s", n, buf); close(fd); } } free(fname); }
void first_hotplug(rdpdrPlugin* rdpdr) { int i; char drive_path[5] = { 'c', ':', '\\', '\0' }; DWORD unitmask = GetLogicalDrives(); for (i = 0; i < 26; i++) { if (unitmask & 0x01) { RDPDR_DRIVE* drive; drive_path[0] = 'A' + i; drive_path[1] = ':'; if (check_path(drive_path)) { drive = (RDPDR_DRIVE*)malloc(sizeof(RDPDR_DRIVE)); ZeroMemory(drive, sizeof(RDPDR_DRIVE)); drive->Type = RDPDR_DTYP_FILESYSTEM; drive->Path = _strdup(drive_path); drive_path[1] = '\0'; drive->Name = _strdup(drive_path); devman_load_device_service(rdpdr->devman, (RDPDR_DEVICE*)drive, rdpdr->rdpcontext); } } unitmask = unitmask >> 1; } }
int path_exists(int *maze, int rows, int columns, int x1, int y1, int x2, int y2){ if (rows < 0 || columns < 0 || x1 < 0 || y1 < 0 || x2 < 0 || y2 < 0 || x1 >= rows || x2 >= rows || y1 >= columns || y2 >= columns) return 0; else return check_path(maze, rows, columns, x1, y1, x2, y2); }
int deal_with_command(t_lst *node, char **arg) { char **path; char *right_path; char **env; env = get_env(node); path = (char **)malloc(sizeof(char *) * 7); if (!path) return (-1); path = split_path(node); if (path && *arg && env) { right_path = check_path(path, *arg); if (right_path) { exec_right_path(node, arg, env, right_path); return (-1); } } if (*arg && env) { right_path = ""; check_command(node, arg, right_path, env); ft_strdel(arg); } return (-1); }
/* * Setup a watch. The "name" of the watch in userspace will be the <path> to * the watch. When this potential watch reaches the kernel, it will resolve * down to <name> (of terminating file or directory). * Returns a 1 on success & -1 on failure. */ static int audit_setup_watch_name(struct audit_rule_data **rulep, char *path) { int type = AUDIT_WATCH; size_t len; struct stat buf; if (check_path(path)) return -1; // Trim trailing '/' should they exist len = strlen(path); if (len > 2 && path[len-1] == '/') { while (path[len-1] == '/' && len > 1) { path[len-1] = 0; len--; } } if (stat(path, &buf) == 0) { if (S_ISDIR(buf.st_mode)) type = AUDIT_DIR; } /* FIXME: might want to check to see that rule is empty */ if (audit_add_watch_dir(type, rulep, path)) return -1; return 1; }
int check_path(int *maze, int rows, int columns, int x1, int y1, int x2, int y2) { if (x1 == x2 && y1 == y2 && *(maze + (x1*columns + y1)) == 1) return 1; if (x1 < 0 || y1 < 0 || x1 >= rows || y1 >= columns || *(maze + (x1 * columns) + y1) == 0) return 0; if (*(maze + (x1 * columns + y1)) == 1) { *(maze + (x1 * columns + y1)) = 0; if (check_path(maze, rows, columns, x1, y1 + 1, x2, y2)) return 1; if (check_path(maze, rows, columns, x1 + 1, y1, x2, y2)) return 1; if (check_path(maze, rows, columns, x1, y1 - 1, x2, y2)) return 1; if (check_path(maze, rows, columns, x1 - 1, y1, x2, y2)) return 1; *(maze + (x1 * columns + y1)) = 1; } return 0; }
void set_current_working_directory(char *path){ /* Gets the current working directory */ if ( getcwd(path, MAX_PATH) == NULL){ fatal_error("Error when try to obtain the current working directory \n"); } check_path(path); }
/* This program tries to mount /dev/sd1 on /mnt/fat and /dev/sd2 * on /mnt/wfs. */ int main(int argc, char **argv) { /* First, perform some unsafe checks if the necessary paths exist * (in theory they can disappear before we get to mount them.) */ if (check_path("/mnt_fat") < 0 || check_path("/mnt_wfs") < 0) return -1; if (umount("/mnt_fat") < 0) puts("Error: Couldn't unmount /dev/sd1."); if (umount("/mnt_wfs") < 0) puts("Error: Couldn't unmount /dev/sd2."); return 0; }
//! //! Destroy the backing store for a given instance //! //! @param[in] instance the instance identifier for which we will destroy the backing store //! @param[in] do_destroy_files set to TRUE if we need to destroy the content otherwise set to FALSE. //! //! @return EUCA_OK on success //! //! @pre The instance parameter must not be NULL and do_destroy_files must be a valid boolean. //! //! @note //! int destroy_instance_backing(ncInstance * instance, boolean do_destroy_files) { int i = 0; int ret = EUCA_OK; char path[EUCA_MAX_PATH] = ""; char work_regex[1024] = ""; // {userId}/{instanceId}/.* char scURL[512] = ""; if (get_localhost_sc_url(scURL) != EUCA_OK || strlen(scURL) == 0) { LOGWARN("[%s] could not obtain SC URL (is SC enabled?)\n", instance->instanceId); scURL[0] = '\0'; } // find and detach iSCSI targets, if any for (i = 0; i < EUCA_MAX_VOLUMES; ++i) { ncVolume *volume = &instance->volumes[i]; if (!is_volume_used(volume)) continue; if (disconnect_ebs_volume (scURL, localhost_config.use_ws_sec, localhost_config.ws_sec_policy_file, volume->attachmentToken, volume->connectionString, localhost_config.ip, localhost_config.iqn) != 0) { LOGERROR("[%s][%s] failed to disconnect volume\n", instance->instanceId, volume->volumeId); } } // see if instance directory is there (sometimes startup fails before it is created) set_path(path, sizeof(path), instance, NULL); if (check_path(path)) return (ret); if (do_destroy_files) { set_id2(instance, "/.*", work_regex, sizeof(work_regex)); if (blobstore_delete_regex(work_bs, work_regex) == -1) { LOGERROR("[%s] failed to remove some artifacts in %s\n", instance->instanceId, path); } for (i = 0; i < EUCA_MAX_VOLUMES; ++i) { ncVolume *volume = &instance->volumes[i]; snprintf(path, sizeof(path), EUCALYPTUS_VOLUME_XML_PATH_FORMAT, instance->instancePath, volume->volumeId); unlink(path); } // delete all non-blob files in the directory if (blobstore_delete_nonblobs(work_bs, instance->instancePath) < 0) { LOGERROR("[%s] failed to delete some non-blob files under %s\n", instance->instanceId, instance->instancePath); } } // Finally try to remove the directory. If either the user or our code introduced // any new files, this last step will fail. set_path(path, sizeof(path), instance, NULL); if (rmdir(path) && do_destroy_files) { LOGERROR("[%s] failed to remove backing directory %s\n", instance->instanceId, path); } return (ret); }
static int global_class_del (lua_State *L) { TRY_START check_args(L,1); std::string name = check_path(L,1); class_del(L,class_get(name)); return 0; TRY_END }
static int global_class_has (lua_State *L) { TRY_START check_args(L,1); std::string name = check_path(L,1); lua_pushboolean(L,class_has(name)); return 1; TRY_END }