char *get_next_command(t_shell *shell) { if (shell->edit->prompt) ft_strdel(&(shell->edit)->prompt); shell->edit->prompt = print_prompt(shell, &shell->edit->prompt_len); ft_printf_fd(shell->edit->term->fd, "%s", shell->edit->prompt); if (get_input(shell->edit, &handle_key) == 0) clean_exit(shell->edit->term, 1, shell); if (shell->edit->term->term_name) { while (!is_closed(shell->edit->input, "\"'`([{") && interrupt(-1) == 0) complete_line(shell->edit); } if (!search_in_hist(shell->edit)) { goto_end_list(shell->edit); ft_strdel(&(shell->edit->hist)->line); return (NULL); } hist_update(shell->edit, 0); if (shell->edit->input && interrupt(-1) != 1) append_hist(shell->edit); return (shell->edit->input); }
int main(void) { int i, position_x, position_y; /* Declaration of the needed data structures. */ grid_t * certainty_grid; range_measure_t measure[MEASUREMENTS]; hist_t * polar_histogram; control_signal_t control_signal; /* ** Initialization of the grid and the histogram. */ certainty_grid = grid_init(50, 10); polar_histogram = hist_init(2, 20, 10, 5); /* Are the initializations ok? */ if (certainty_grid == NULL) return -1; if (certainty_grid->cells == NULL) return -1; if (polar_histogram == NULL) return -1; if (polar_histogram->densities == NULL) return -1; /* ** Fake measures. */ printf("Measures\n"); for (i = 0; i < MEASUREMENTS; ++i) { measure[i].direction = (int) ((360.0 * rand()) / RAND_MAX); /* [degrees] */ measure[i].distance = (int) (((130.0 * rand()) / RAND_MAX) + 20); /* [cm] */ if (i < 50) printf("\t%2d: %3d [cm], %3d [degrees]\n", i, (int) measure[i].distance, measure[i].direction); } if (i > 50) printf("\t...\n"); /* Let's assume the 'robot' is in the middle of the grid. */ position_x = position_y = (certainty_grid->dimension + 1) / 2; printf("\nPosition of the robot: (%d, %d)\n", position_x, position_y); /* Add the information from the measures to the grid. */ printf("\nUpdating the certainty grid...\n"); for (i = 0; i < MEASUREMENTS; ++i) { grid_update(certainty_grid, position_x, position_y, measure[i]); } /* ** Calculating the control signals. */ /* Generate the histogram for the current grid. */ printf("\nUpdating the polar histogram...\n"); hist_update(polar_histogram, certainty_grid); /* What's the next direction? */ control_signal.direction = calculate_direction(polar_histogram, OBJECTIVE_DIRECTION); printf("\nNext direction: %d [degrees]\n", control_signal.direction); free(certainty_grid); free(polar_histogram); certainty_grid = NULL; polar_histogram = NULL; return 0; }