void netloc_dc_pretty_print(netloc_data_collection_handle_t *handle) { int p; struct netloc_dt_lookup_table_iterator *hti = NULL; const char * key = NULL; netloc_edge_t **path = NULL; int path_len; struct netloc_dt_lookup_table_iterator *htin = NULL; netloc_node_t *cur_node = NULL; htin = netloc_dt_lookup_table_iterator_t_construct(handle->node_list); while( !netloc_lookup_table_iterator_at_end(htin) ) { cur_node = (netloc_node_t*)netloc_lookup_table_iterator_next_entry(htin); if( NULL == cur_node ) { break; } display_node(cur_node, strdup("")); printf("Physical Paths\n"); printf("--------------\n"); // Display all of the paths from this node to other nodes (if any) hti = netloc_dt_lookup_table_iterator_t_construct(cur_node->physical_paths); while( !netloc_lookup_table_iterator_at_end(hti) ) { key = netloc_lookup_table_iterator_next_key(hti); if( NULL == key ) { break; } path = (netloc_edge_t**)netloc_lookup_table_access(cur_node->physical_paths, key); path_len = 0; for(p = 0; NULL != path[p]; ++p) { ++path_len; } display_path(cur_node->physical_id, key, path_len, path, strdup("\t")); } printf("Logical Paths\n"); printf("--------------\n"); // Display all of the paths from this node to other nodes (if any) hti = netloc_dt_lookup_table_iterator_t_construct(cur_node->logical_paths); while( !netloc_lookup_table_iterator_at_end(hti) ) { key = netloc_lookup_table_iterator_next_key(hti); if( NULL == key ) { break; } path = (netloc_edge_t**)netloc_lookup_table_access(cur_node->logical_paths, key); path_len = 0; for(p = 0; NULL != path[p]; ++p) { ++path_len; } display_path(cur_node->physical_id, key, path_len, path, strdup("\t")); } } netloc_dt_lookup_table_iterator_t_destruct(htin); }
void display_deps(environment const & env, std::ostream & out, char const * fname) { std::ifstream in(fname); if (in.bad() || in.fail()) throw exception(sstream() << "failed to open file '" << fname << "'"); scanner s(in, fname); while (consume_until_import(env, s)) { while (true) { auto t = s.scan(env); if (t != scanner::token_kind::Identifier) break; std::string m_name = find_file(name_to_file(s.get_name_val()), {".lean", ".olean", ".lua"}); int last_idx = m_name.find_last_of("."); std::string rawname = m_name.substr(0, last_idx); std::string ext = m_name.substr(last_idx); if (ext == ".lean") { m_name = rawname + ".olean"; } display_path(out, m_name); out << "\n"; } } }
// This function is called once, from main.c. void maze_solve() { // Loop until we have solved the maze. while(1) { // FIRST MAIN LOOP BODY follow_segment(); // Drive straight a bit. This helps us in case we entered the // intersection at an angle. // Note that we are slowing down - this prevents the robot // from tipping forward too much. set_motors(50,50); delay_ms(50); // These variables record whether the robot has seen a line to the // left, straight ahead, and right, whil examining the current // intersection. unsigned char found_left=0; unsigned char found_straight=0; unsigned char found_right=0; // Now read the sensors and check the intersection type. unsigned int sensors[5]; read_line(sensors,IR_EMITTERS_ON); // Check for left and right exits. if(sensors[0] > 100) found_left = 1; if(sensors[4] > 100) found_right = 1; // Drive straight a bit more - this is enough to line up our // wheels with the intersection. set_motors(40,40); delay_ms(200); // Check for a straight exit. read_line(sensors,IR_EMITTERS_ON); if(sensors[1] > 200 || sensors[2] > 200 || sensors[3] > 200) found_straight = 1; // Check for the ending spot. // If all three middle sensors are on dark black, we have // solved the maze. if(sensors[1] > 600 && sensors[2] > 600 && sensors[3] > 600) break; // Intersection identification is complete. // If the maze has been solved, we can follow the existing // path. Otherwise, we need to learn the solution. unsigned char dir = select_turn(found_left, found_straight, found_right); // Make the turn indicated by the path. turn(dir); // Store the intersection in the path variable. path[path_length] = dir; path_length ++; // You should check to make sure that the path_length does not // exceed the bounds of the array. We'll ignore that in this // example. // Simplify the learned path. simplify_path(); // Display the path on the LCD. display_path(); } // Solved the maze! // Now enter an infinite loop - we can re-run the maze as many // times as we want to. while(1) { // Beep to show that we finished the maze. set_motors(0,0); play(">>a32"); // Wait for the user to press a button, while displaying // the solution. while(!button_is_pressed(BUTTON_B)) { if(get_ms() % 2000 < 1000) { clear(); print("Solved!"); lcd_goto_xy(0,1); print("Press B"); } else display_path(); delay_ms(30); } while(button_is_pressed(BUTTON_B)); delay_ms(1000); // Re-run the maze. It's not necessary to identify the // intersections, so this loop is really simple. int i; for(i=0;i<path_length;i++) { // SECOND MAIN LOOP BODY follow_segment(); // Drive straight while slowing down, as before. set_motors(50,50); delay_ms(50); set_motors(40,40); delay_ms(200); // Make a turn according to the instruction stored in // path[i]. turn(path[i]); } // Follow the last segment up to the finish. follow_segment(); // Now we should be at the finish! Restart the loop. } }
bool display_deps(environment const & env, std::ostream & out, std::ostream & err, char const * fname) { name import("import"); name prelude("prelude"); name period("."); std::ifstream in(fname); if (in.bad() || in.fail()) { err << "failed to open file '" << fname << "'" << std::endl; return false; } scanner s(in, fname); optional<unsigned> k; std::string base = dirname(fname); bool import_prefix = false; bool import_args = false; bool ok = true; bool is_prelude = false; auto display_dep = [&](optional<unsigned> const & k, name const & f) { import_args = true; try { std::string m_name = find_file(base, k, name_to_file(f), {".lean", ".hlean", ".olean", ".lua"}); int last_idx = m_name.find_last_of("."); std::string rawname = m_name.substr(0, last_idx); std::string ext = m_name.substr(last_idx); if (ext == ".lean" || ext == ".hlean") m_name = rawname + ".olean"; display_path(out, m_name); import_prefix = true; out << "\n"; } catch (exception & new_ex) { err << "error: file '" << name_to_file(s.get_name_val()) << "' not found in the LEAN_PATH" << std::endl; ok = false; } }; while (true) { scanner::token_kind t = scanner::token_kind::Identifier; try { t = s.scan(env); } catch (exception &) { continue; } if (t == scanner::token_kind::Eof) { if (!is_prelude) display_dep(optional<unsigned>(), name("init")); return ok; } else if (t == scanner::token_kind::CommandKeyword && s.get_token_info().value() == prelude) { is_prelude = true; } else if (t == scanner::token_kind::CommandKeyword && s.get_token_info().value() == import) { k = optional<unsigned>(); import_prefix = true; } else if (import_prefix && t == scanner::token_kind::Keyword && s.get_token_info().value() == period) { if (!k) k = 0; else k = *k + 1; } else if ((import_prefix || import_args) && t == scanner::token_kind::Identifier) { display_dep(k, s.get_name_val()); k = optional<unsigned>(); } else { import_args = false; import_prefix = false; } } }
int first_main_loop() { /* This function returns 1 when it finds "something interesting" * Otherwise, it just lets itself finish. It will be run until * something "truthy" is returned */ follow_segment(); // Drive straight a bit. This helps us in case we entered the // intersection at an angle. // Note that we are slowing down - this prevents the robot // from tipping forward too much. set_motors(50,50); delay_ms(50); // These variables record whether the robot has seen a line to the // left, straight ahead, and right, while examining the current // intersection. unsigned char found_left=0; unsigned char found_straight=0; unsigned char found_right=0; // Now read the sensors and check the intersection type. unsigned int sensors[5]; read_line(sensors,IR_EMITTERS_ON); // Check for left and right exits. if(sensors[0] > 100) found_left = 1; if(sensors[4] > 100) found_right = 1; // Drive straight a bit more - this is enough to line up our // wheels with the intersection. set_motors(40,40); delay_ms(200); // Check for a straight exit. read_line(sensors,IR_EMITTERS_ON); if(sensors[1] > 200 || sensors[2] > 200 || sensors[3] > 200) found_straight = 1; // Check for the ending spot. // If all three middle sensors are on dark black, we have // solved the maze. if(sensors[1] > 400 && sensors[2] > 400 && sensors[3] > 400) return 1; // Intersection identification is complete. // If the maze has been solved, we can follow the existing // path. Otherwise, we need to learn the solution. // from `turn.c` unsigned char dir = select_turn(found_left, found_straight, found_right); // Make the turn indicated by the path. // from `turn.c` turn(dir); // Store the intersection in the path variable. if(path_length < 100){ path[path_length] = dir; path_length ++; } else{ //throw it away for now } // Display the path on the LCD. display_path(); return 0; }