int update_path(struct path *p, char **argv, int argc) { clear_paths(p); int i; // set count var before potentially returning p->count = argc-1; if(argc == 1) { //no need to allocate space return 0; } // add all new *chars p->paths = malloc((argc-1)*sizeof(char*)); if(p->paths == NULL) { return 1; } for(i = 1; i < argc; i++) { p->paths[i-1] = strdup(argv[i]); if(p->paths[i-1] == NULL) { return 1; } } // successfully allocated memory for all args return 0; }
void downstream_manager::abort(error reason) { CAF_LOG_TRACE(CAF_ARG(reason)); for_each_path([&](outbound_path& x) { auto tmp = reason; about_to_erase(&x, false, &tmp); }); clear_paths(); }
void print_path(int source, int node, std::vector<int> predecessor, Robot* robot, std::vector<Vector2> rand_points, bool& replan, std::vector<Robot *> robots) { if (node == source) { robot->path.push_back(rand_points[source]); std::cout << (char)(node + 97) << ".."; } else if (predecessor[node] == -1) { std::cout << "No path from “<<source<<” to "<< (char)(node + 97) << std::endl; clear_paths(robots); return; } else { print_path(source, predecessor[node], predecessor, robot, rand_points, replan, robots); robot->path.push_back(rand_points[node]); std::cout << (char) (node + 97) << ".."; } replan = false; }