void CALifeMonsterMovementManager::update () { switch (path_type()) { case MovementManager::ePathTypeGamePath : { detail().update (); break; }; case MovementManager::ePathTypePatrolPath : { patrol().update (); detail().target ( patrol().target_game_vertex_id(), patrol().target_level_vertex_id(), patrol().target_position() ); detail().update (); break; }; case MovementManager::ePathTypeNoPath : { break; }; default : NODEFAULT; }; }
void canonical () { ADD_TESTS(1 + sizeof(canonical_data)/sizeof(canonical_data[0]) - 1); TEST_OK(path_type().canonical() == path_type()); canonical_data_t * p = & canonical_data[0]; while (!p->path_str.empty()) { std::ostringstream oss; path_type canonical = path_type(p->path_str).canonical(); oss << "'" << canonical.str() << "' is canonical for '" << p->path_str << "'"; bool result = canonical == path_type(p->canonical); if (!result) { oss << "' but expected '" << p->canonical << "'"; } TEST_OK2(result, oss.str().c_str()); ++p; } }
void for_each( const Tree& tree, Function fn, const typename Tree::path_type& parent_path = typename Tree::path_type()) { using path_type = typename Tree::path_type; for (auto&& value_pair: tree) { auto current_path = parent_path / path_type(value_pair.first); fn(current_path, value_pair.second); for_each(value_pair.second, fn, current_path); } }
/** * @brief generate snap file path with requested localpath and requested remote uri * * @see * @note * return the hash result from xor_hash(uri, strlen(uri), 0) * the snap file path is stored in snap_fpath * @return 0 for error * uri_hash for succ * @author auxten <*****@*****.**> * @date 2011-8-1 **/ unsigned gen_snap_fpath(char *snap_fpath, const char * localpath, const char * uri) { if (!snap_fpath || !localpath || !uri) { GKOLOG(FATAL, "%s %s passed NULL p", __FILE__, __func__); return 0; } char out_path[MAX_PATH_LEN] = {'\0'}; strncpy(out_path, localpath, MAX_PATH_LEN); inplace_strip_tailing_slash(out_path); if (!cwd_path_to_abs_path(snap_fpath, out_path)) { GKOLOG(WARNING, "cwd_path_to_abs_path failed '%s' '%s'", snap_fpath, out_path); return 0; } /** cut the tailing file in path **/ if (!(path_type(snap_fpath) & GKO_DIR)) { int idx; if ((idx = get_base_name_index(NULL, snap_fpath)) < 0) { GKOLOG(WARNING, "gen_snap_fpath failed '%s' '%s' '%s'", snap_fpath, out_path, uri); return 0; } *(snap_fpath + idx) = '\0'; } int snap_fpath_len = strlen(snap_fpath); unsigned uri_hash = xor_hash(uri, strlen(uri), 0); snprintf(snap_fpath + snap_fpath_len, MAX_PATH_LEN - snap_fpath_len, "/%s%u", GKO_SNAP_FILE, uri_hash); GKOLOG(NOTICE, "gko.snap_fpath: '%s'", snap_fpath); return uri_hash; }
FILE *dgen_freopen(const char *relative, const char *file, unsigned int mode, FILE *f) { size_t size; size_t file_size; char *tmp; int e = errno; const char *fmode = fopen_mode(mode); char *path = NULL; if ((file == NULL) || (file[0] == '\0') || (fmode == NULL)) goto error; /* Try to open the file in the current directory if DGEN_CURRENT is specified. */ if (mode & DGEN_CURRENT) { FILE *fd; if (f == NULL) fd = fopen(file, fmode); else fd = freopen(file, fmode, f); if (fd != NULL) return fd; } if (path_type(file, ~0u) != PATH_TYPE_UNSPECIFIED) size = 0; else if ((relative == NULL) || (path_type(relative, ~0u) == PATH_TYPE_UNSPECIFIED)) { if ((path = dgen_dir(NULL, &size, relative)) == NULL) goto error; } else { if ((path = strdup(relative)) == NULL) goto error; size = strlen(path); } if (mode & (DGEN_WRITE | DGEN_APPEND)) mkdir(path, 0777); /* XXX make that recursive */ file_size = strlen(file); if ((tmp = realloc(path, (size + !!size + file_size + 1))) == NULL) goto error; path = tmp; if (size) path[(size++)] = DGEN_DIRSEP[0]; memcpy(&path[size], file, file_size); size += file_size; path[size] = '\0'; errno = e; if (f == NULL) f = fopen(path, fmode); else f = freopen(path, fmode, f); e = errno; free(path); errno = e; return f; error: free(path); errno = EACCES; return NULL; }
/** * @brief convert the remote path recv from JOIN to local path * * @see * @note * @author auxten <*****@*****.**> * @date 2011-8-1 **/ int process_path(s_job_t * jo) { char out_path[MAX_PATH_LEN] = {'\0'}; strncpy(out_path, jo->path, MAX_PATH_LEN); inplace_strip_tailing_slash(out_path); int out_type = path_type(out_path); if (out_type & GKO_NONE) {/** non-existed dest or dest is symlink to non-existed **/ if (out_type & GKO_LINK) {/** dest is symlink to non-existed **/ GKOLOG(FATAL, "destination: '%s' is a symlink to non-exist", out_path); return -1; } else if ((jo->file_count == 1 && jo->files->size >= 0) && (jo->path)[strlen(jo->path) - 1] == '/') {/** dest is a non existed dir path like './non/' but job is a singal file **/ GKOLOG(FATAL, "downloading a file to non existed path '%s'", jo->path); return -1; } else { /** non-existed dest **/ /** determine if the base dir is existed **/ char out_base_path[MAX_PATH_LEN]; //strncpy(out_base_path, out_path, MAX_PATH_LEN); cwd_path_to_abs_path(out_base_path, out_path); int base_idx = get_base_name_index(NULL, out_base_path); if (base_idx < 0) { GKOLOG(FATAL, "process_path failed"); return -1; } out_base_path[base_idx] = '\0'; int out_base_type = path_type(out_base_path); if (out_base_type & GKO_DIR) {/** out base path is a dir or symlink to dir **/ for (int i = 0; i < jo->file_count; i++) { if (FAIL_CHECK( change_to_local_path((jo->files + i)->name, jo->uri, out_path, 0))) { GKOLOG( FATAL, "change to local path error, name: '%s', uri: '%s', path: '%s'", (jo->files + i)->name, jo->uri, out_path); return -1; } //GKOLOG(NOTICE, "path: '%s'", (jo->files + i)->name); } return 0; } else {/** out base path is not dir, nor symlink to dir **/ GKOLOG(FATAL, "base path: '%s' is non-dir", out_base_path); return -1; } } } else {/** dest path existed **/ if (out_type & GKO_FILE) {/** dest path is file or symlink to file **/ if (jo->file_count == 1) { if ((jo->files)->size == -1) {/** dest path is dir **/ GKOLOG(FATAL, "can't overwrite dir: '%s' on file: '%s'", (jo->files)->name, out_path); return -1; } else if ((jo->files)->size == -2) {/** dest path is symlink **/ GKOLOG(FATAL, "can't overwrite symlink: '%s' on file: '%s'", (jo->files)->name, out_path); return -1; } else {/** dest path is file **/ strncpy((jo->files)->name, out_path, MAX_PATH_LEN); return 0; } } else { /** file count != 1, indicating that job is a dir, dest is a existed file **/ GKOLOG(FATAL, "can't overwrite dir: '%s' on file: '%s'", (jo->files)->name, out_path); return -1; } } else if (out_type & GKO_DIR) {/** dest is a existed dir **/ for (int i = 0; i < jo->file_count; i++) { if (FAIL_CHECK(change_to_local_path((jo->files + i)->name, jo->uri, out_path, 1))) { GKOLOG( FATAL, "change to local path error, name: '%s', uri: '%s', path: '%s'", (jo->files + i)->name, jo->uri, out_path); return -1; } } return 0; } else {/** dest is non-regular file or dir **/ GKOLOG(FATAL, "the dest: '%s' is non-regular file or dir", out_path); return -1; } } return 0; }