static int statoverride_list(const char *const *argv) { struct fileiterator *iter; struct filenamenode *file; const char *thisarg; struct glob_node *glob_list = NULL; int ret = 1; while ((thisarg = *argv++)) { char *pattern = path_cleanup(thisarg); glob_list_prepend(&glob_list, pattern); } if (glob_list == NULL) glob_list_prepend(&glob_list, m_strdup("*")); iter = files_db_iter_new(); while ((file = files_db_iter_next(iter))) { struct glob_node *g; for (g = glob_list; g; g = g->next) { if (fnmatch(g->pattern, file->name, 0) == 0) { statdb_node_print(stdout, file); ret = 0; break; } } } files_db_iter_free(iter); glob_list_free(glob_list); return ret; }
static int statoverride_remove(const char *const *argv) { const char *path = argv[0]; char *filename; if (!path || argv[1]) badusage(_("--%s needs a single argument"), "remove"); filename = path_cleanup(path); if (!statdb_node_remove(filename)) { if (opt_verbose) warning(_("no override present")); if (opt_force) return 0; else return 2; } if (opt_update && opt_verbose) warning(_("--update is useless for --remove")); statdb_write(); free(filename); return 0; }
static int statoverride_add(const char *const *argv) { const char *user = argv[0]; const char *group = argv[1]; const char *mode = argv[2]; const char *path = argv[3]; char *filename; struct file_stat **filestat; if (!user || !group || !mode || !path || argv[4]) badusage(_("--%s needs four arguments"), cipaction->olong); if (strchr(path, '\n')) badusage(_("path may not contain newlines")); filename = path_cleanup(path); filestat = statdb_node_find(filename); if (*filestat != NULL) { if (opt_force) warning(_("an override for '%s' already exists, " "but --force specified so will be ignored"), filename); else ohshit(_("an override for '%s' already exists; " "aborting"), filename); } *filestat = statdb_node_new(user, group, mode); if (opt_update) { struct stat st; if (stat(filename, &st) == 0) { (*filestat)->mode |= st.st_mode & S_IFMT; statdb_node_apply(filename, *filestat); } else if (opt_verbose) { warning(_("--update given but %s does not exist"), filename); } } statdb_write(); free(filename); return 0; }
static int path_continue(i_ctx_t *i_ctx_p) { gs_path_enum *penum = r_ptr(esp, gs_path_enum); gs_point ppts[3]; int code; /* Make sure we have room on the o-stack for the worst case */ /* before we enumerate the next path element. */ check_ostack(6); /* 3 points for curveto */ code = gs_path_enum_next(penum, ppts); switch (code) { case 0: /* all done */ esp -= 6; path_cleanup(i_ctx_p); return o_pop_estack; default: /* error */ return code; case gs_pe_moveto: esp[2] = esp[-4]; /* moveto proc */ pf_push(i_ctx_p, ppts, 1); break; case gs_pe_lineto: esp[2] = esp[-3]; /* lineto proc */ pf_push(i_ctx_p, ppts, 1); break; case gs_pe_curveto: esp[2] = esp[-2]; /* curveto proc */ pf_push(i_ctx_p, ppts, 3); break; case gs_pe_closepath: esp[2] = esp[-1]; /* closepath proc */ break; } push_op_estack(path_continue); ++esp; /* include pushed procedure */ return o_push_estack; }
int path_converter(PyObject *o, void *p) { struct path_arg *path = p; int is_index, is_bytes, is_unicode; PyObject *bytes = NULL; Py_ssize_t length = 0; char *tmp; if (o == NULL) { path_cleanup(p); return 1; } path->object = path->cleanup = NULL; Py_INCREF(o); path->fd = -1; is_index = path->allow_fd && PyIndex_Check(o); is_bytes = PyBytes_Check(o); is_unicode = PyUnicode_Check(o); if (!is_index && !is_bytes && !is_unicode) { _Py_IDENTIFIER(__fspath__); PyObject *func; func = _PyObject_LookupSpecial(o, &PyId___fspath__); if (func == NULL) goto err_format; Py_DECREF(o); o = PyObject_CallFunctionObjArgs(func, NULL); Py_DECREF(func); if (o == NULL) return 0; is_bytes = PyBytes_Check(o); is_unicode = PyUnicode_Check(o); } if (is_unicode) { if (!PyUnicode_FSConverter(o, &bytes)) goto err; } else if (is_bytes) { bytes = o; Py_INCREF(bytes); } else if (is_index) { if (!fd_converter(o, &path->fd)) goto err; path->path = NULL; goto out; } else { err_format: PyErr_Format(PyExc_TypeError, "expected %s, not %s", path->allow_fd ? "string, bytes, os.PathLike, or integer" : "string, bytes, or os.PathLike", Py_TYPE(o)->tp_name); goto err; } length = PyBytes_GET_SIZE(bytes); tmp = PyBytes_AS_STRING(bytes); if ((size_t)length != strlen(tmp)) { PyErr_SetString(PyExc_TypeError, "path has embedded nul character"); goto err; } path->path = tmp; if (bytes == o) Py_DECREF(bytes); else path->cleanup = bytes; path->fd = -1; out: path->length = length; path->object = o; return Py_CLEANUP_SUPPORTED; err: Py_XDECREF(o); Py_XDECREF(bytes); return 0; }
AA_API int aa_rx_mp_plan( struct aa_rx_mp *mp, double timeout, size_t *n_path, double **p_path_all ) { mp->validity_checker->allow(); amino::sgSpaceInformation::Ptr &si = mp->space_information; /* Configure State Validity Checker */ /* Setup Space */ *n_path = 0; *p_path_all = NULL; amino::sgStateSpace *ss = si->getTypedStateSpace(); ompl::base::ProblemDefinitionPtr &pdef = mp->problem_definition; ompl::base::PlannerPtr planner = (NULL == mp->planner.get()) ? ompl::base::PlannerPtr(new ompl::geometric::RRTConnect(si)) : mp->planner; planner->setProblemDefinition(pdef); try { if( mp->lazy_samples ) { fprintf(stderr, "Starting sampling thread\n"); mp->lazy_samples->clear(); mp->lazy_samples->setStart(ss->config_count_all(), mp->config_start); mp->lazy_samples->startSampling(); } planner->solve(timeout); if( mp->lazy_samples ) { fprintf(stderr, "Stopping sampling thread\n"); mp->lazy_samples->stopSampling(); } } catch(...) { return AA_RX_NO_SOLUTION; } if( pdef->hasSolution() ) { const ompl::base::PathPtr &path_ptr = pdef->getSolutionPath(); ompl::geometric::PathGeometric &path = static_cast<ompl::geometric::PathGeometric&>(*path_ptr); path_cleanup(mp, path); /* Allocate a simple array */ *n_path = path.getStateCount(); *p_path_all = (double*)calloc( *n_path * ss->config_count_all(), sizeof(double) ); /* Fill array */ std::vector< ompl::base::State *> &states = path.getStates(); double *ptr = *p_path_all; for( auto itr = states.begin(); itr != states.end(); itr++, ptr += ss->config_count_all() ) { AA_MEM_CPY( ptr, mp->config_start, ss->config_count_all() ); amino::sgSpaceInformation::StateType *state = amino::sgSpaceInformation::state_as(*itr); ss->insert_state( state, ptr ); } return AA_RX_OK; } else { return AA_RX_NO_SOLUTION | AA_RX_NO_MP; } }
void Data::add_search_path(std::string path){ search_path.insert(path_cleanup(path)); }