void ft_command_line(t_env *env) { char *buf; int ret; pid_t pid; ft_display_prompt(); while ((ret = get_next_line(0, &buf)) > 0) { pid = fork(); if (pid > 0) { wait(&pid); ft_display_prompt(); } else ft_read_command(ft_strtrim(buf), env); } }
void readmap(char *file, t_info *info) { int y; int fd; char **map; y = 0; if ((fd = open(file, O_RDONLY)) == -1) ft_printerr("Error reading from file %s\n", file); if (!(map = (char **)malloc(sizeof(char *) * info->rows + 1))) ft_printerr("Error assigning memory for map\n"); while (y < info->rows) { if (get_next_line(fd, &map[y]) == -1) ft_printerr("Error reading map\n"); y++; } info->map = map; }
static void pipe_left(t_node *tree, int *pipe_fd, t_data *data) { char *line; close(pipe_fd[0]); get_tmpfd(&data->tmp_pipein, "/.temp_pipein"); read_tree(tree->left); lseek(data->tmp_pipein, 0, SEEK_SET); while (get_next_line(data->tmp_pipein, &line) > 0) { ft_putendl_fd(line, pipe_fd[1]); ft_strdel(&line); } remove_tmp("/.temp_pipein"); if (g_pid.built == 0 || WEXITSTATUS(g_pid.id) != 0) exit(EXIT_FAILURE); else exit(EXIT_SUCCESS); }
static void parse_scene(int file) { char *line; t_parser parser; int line_number; line_number = 0; init_scene_parser(&parser); parser.last_type = LAST_NONE; while (get_next_line(file, &line)*1) { remove_comments(line); if (!is_empty_line(line)) parse_line(&parser, count_indentation(line, line_number), line, line_number); line_number++; free(line); } }
int get_info(t_var *var, char *str, int i) { char *s; int choice; if (i % 2 == 0) { my_putstr(var->j1); my_putstr(str); } else { my_putstr(var->j2); my_putstr(str); } while ((s = get_next_line(0)) == NULL); choice = my_getnbr(s); return (choice); }
int ft_askcolumn(int fd) { int ret; char *line; int pcolumn; pcolumn = 0; while (pcolumn > g_h + 1 || !pcolumn) { ft_putstr("which column do you want to play ? (1 to lenght)\n"); ret = get_next_line(fd, &line); if (ret == -1) return (-1); pcolumn = ft_atoi(line); if (pcolumn > g_le + 1 || !pcolumn) ft_putstr("ERROR, lenght must be between 1 and lenght\n"); } return (pcolumn); }
int main() { t_lidar lidar; int i; i = 0; lidar.speed = 0.3; lidar.wheels = 0; write(1, "start_simulation\n", 17); lidar.forward = get_next_line(0); lidar.backwards = lidar.forward; lidar.wheel = lidar.forward; forward(lidar.speed, &lidar); while (i == 0) checkpoint(&lidar, &i); forward(0, &lidar); write(1, "stop_simulation\n", 16); return (0); }
void populate_piece(t_env *e) { int y; char *line; int x; y = 0; while (y < e->piece_h) { get_next_line(0, &line); x = 0; while (x < e->piece_w) { e->piece[y][x] = line[x]; x++; } y++; } }
int main(int argc, char **argv) { int fd; int ret; char *line; fd = open(argv[1], O_RDONLY); if (argc != 2) return (-1); while ((ret = get_next_line(fd, &line)) == 1) { ft_putnbr(ret); ft_putchar('\t'); ft_putendl(line); } ft_putnbr(ret); ft_putchar('\n'); return (0); }
int check_line(t_env s) { int i; char *line; i = 0; while (get_next_line(s.fd, &line) > 0) { free(line); i++; } if (i == 0) { usage(3); exit(1); } free(line); return (i); }
void init_champ(int fd, char *s, t_hexa *hexa, int f) { while ((s = get_next_line(fd))) { if (my_strlen(s) > 0 && s != NULL) { if (hexa->last_line == 0) { if (s[0] == '.' && s[1] == 'c' && s[2] == 'o' && s[3] == 'd' && s[4] == 'e') hexa->last_line = 1; } hexa->pos = check_inst_1(s, hexa, f); if (hexa->pos == 42) my_printf("%s\n", s); } free(s); } }
static void pars_scene(int file) { char *line; t_pars pars; int nb_line; nb_line = 0; init_pars_scene(&parser); parser.last_type = LAST_NONE; while (get_next_line(file, &line)) { remove_com(line); if (!is_empty(line)) pars_line(&pars, count_indent(line, nb_line), \ line, nb_line); nb_line++; free(line); } }
t_obj *my_spot(t_obj *obj, int fd, int *cmp) { t_tmp *tmp; char *s; tmp = new_tmp(); tmp->name = "spot"; while ((s = get_next_line(fd)) && my_strcmp(s, "</SPOT>")) { if (s[0] && s[0] != COMMENT_CHAR) tmp = parse_str(tmp, s, cmp); (*cmp)++; free(s); } obj = append_obj(obj, tmp); free(s); free(tmp); return (obj); }
int main(int ac, char **av, char **envp) { char *cmd; init_env(envp); add_lvl(); signal(SIGINT, sig_handler); while (g_running) { ft_putstr(hash_getset(&g_env, "MSP", "$> ", 4)->value); get_next_line(0, &cmd); exec_cmds(cmd); ft_memdel((void **)&cmd); } hash_del(&g_env, del_hash); (void)ac; (void)av; return (0); }
void fill_obj(int fd, t_overview *over) { t_obj *obj; char *trim; char *str; obj = (t_obj*)malloc(sizeof(t_obj)); obj->next = NULL; obj->specular = 0; while (get_next_line(fd, &str)) { trim = ft_strtrim(str); if (object_to_fill(trim, obj) == FALSE) break ; } if (obj->specular) obj->specular = 1.0f - obj->diffuse; over->l = add_obj(over->l, obj); }
int main(int ac, char **av, char **envp) { char *line; t_env *env; int ret; (void)ac; (void)av; env = init_env(envp); ret = 1; while (ret) { ft_putstr("$> "); if ((ret = get_next_line(0, &line)) == -1) break ; exec_cmd(line, env); } return (0); }
int raw_layout_test(struct dm_disk_if *d, FILE *fp) { int i; int lbn; char junk[1024]; struct dm_pbn p; int count; struct dm_pbn p2; int errors = 0; // fetch off the header stuff fgets(junk, sizeof(junk), fp); fgets(junk, sizeof(junk), fp); fgets(junk, sizeof(junk), fp); // for(i = 0; i < 85000; i++) get_next_line(fp, &lbn, &p, &count); while(get_next_line(fp, &lbn, &p, &count)) { for(i = 0; i < count; i++) { dm_ptol_result_t rc = d->layout->dm_translate_ltop(d, lbn+i, MAP_FULL, &p2, 0); if((p.cyl != p2.cyl) || (p.head != p2.head) || ((p.sector + i) != p2.sector)) { printf("*** layout_raw: %d -> (%d,%d,%d) <> (%d,%d,%d)\n", lbn+i, p.cyl, p.head, p.sector+i, p2.cyl, p2.head, p2.sector); fflush(stdout); errors++; } } } return errors; }
int main(void) { char *line; int fd; int ret; int count_lines; char *filename; int errors; filename = "gnl3_3.txt"; fd = open(filename, O_RDONLY); if (fd > 2) { count_lines = 0; errors = 0; line = NULL; while ((ret = get_next_line(fd, &line)) > 0) { if (count_lines == 0 && strcmp(line, "1234567890abcde") != 0) errors++; if (count_lines == 1 && strcmp(line, "fghijklmnopqrst") != 0) errors++; if (count_lines == 2 && strcmp(line, "edcba0987654321") != 0) errors++; if (count_lines == 3 && strcmp(line, "tsrqponmlkjihgf") != 0) errors++; count_lines++; if (count_lines > 50) break ; } close(fd); if (count_lines != 4) printf("-> must have returned '1' four times instead of %d time(s)\n", count_lines); if (errors > 0) printf("-> must have read \"1234567890abcde\", \"fghijklmnopqrst\", \"edcba0987654321\" and \"tsrqponmlkjihgf\"\n"); if (count_lines == 4 && errors == 0) printf("OK\n"); } else printf("An error occured while opening file %s\n", filename); return (0); }
int main(void) { char *line; int fd; int ret; int count_lines; char *filename; int errors; filename = "gnl7_3.txt"; fd = open(filename, O_RDONLY); if (fd > 2) { count_lines = 0; errors = 0; line = NULL; while ((ret = get_next_line(fd, &line)) > 0) { if (count_lines == 0 && strcmp(line, "1234567") != 0) errors++; if (count_lines == 1 && strcmp(line, "abcdefg") != 0) errors++; if (count_lines == 2 && strcmp(line, "4567890") != 0) errors++; if (count_lines == 3 && strcmp(line, "defghijk") != 0) errors++; count_lines++; if (count_lines > 50) break ; } close(fd); if (count_lines != 4) printf("-> must have returned '1' four times instead of %d time(s)\n", count_lines); if (errors > 0) printf("-> must have read \"1234567\", \"abcdefg\", \"4567890\" and \"defghijk\"\n"); if (count_lines == 4 && errors == 0) printf("OK\n"); } else printf("An error occured while opening file %s\n", filename); return (0); }
// WARNING: // // If you call this function from a handler function, // do not forget to set 'next_line' to the proper value // (else, it could think EOT has been reached !) // // Generally: call this function if you know what your doing ! // Else call 'parse_sdp_line' // inline bool parse_sdp_line_ex( AmSdp* sdp_msg, char*& s, char discr, bool optional, bool (*parse_func)(AmSdp*,char*&,char*&), bool only_one, char*& next_line) { while(true){ if((*s == '\0') && !optional){ ERROR("parse_sdp_line : unexpected end of text while looking for '%c'\n",discr); return true; } if(*s == discr) { if( *(++s) != '=' ){ ERROR("parse_sdp_line : expected '=' but " "<%c> found \n",*s); return true; } s++; next_line = get_next_line(s); bool ret=false; if(parse_func) ret = (*parse_func)(sdp_msg,s,next_line); s = next_line; if(only_one || (*s != discr)) return ret; continue; } else if(!optional){ ERROR(" parse_sdp_line : parameter '%c=' was " "not found\n",discr); return true; } // token is optional and has not been found. return false; } }
static void wait_get(int sock, char *command) { char *line; char *file_name; int fd; if (wait_server_pass(sock)) return ; file_name = get_file_name(command); if ((fd = open(file_name, O_CREAT | O_WRONLY | O_APPEND, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) == -1) return ; while (get_next_line(sock, &line) > 0 && ft_strcmp(line, "\033")) { ft_putendl_fd(line, fd); free(line); } free(file_name); close(fd); }
void ft_open_map(t_a *a, char *name) { if ((a->fd1 = open(name, O_RDONLY)) == -1) ft_error("File Not Present / No Rights"); while (get_next_line(a->fd1, &a->line) > 0) { if (a->max_y == 0) a->max_x = count_carac(a->line); if (a->max_y != 0) if (a->max_x != count_carac(a->line)) ft_error("The Map is Invalid"); a->max_y++; free(a->line); } free(a->line); if (a->max_x == 0 || a->max_y == 0) ft_error("The Map is Invalid"); ft_creat_map(a); ft_read_map(a, name); }
char *read_cmd(char *prompt, t_param *param, t_history **history) { int tty; param->str_prompt = prompt; if ((tty = isatty(0)) == 0) param->fallback = 0; else if (check_perror("stdin", tty) == -1) return (NULL); if (param->fallback == 0) { if (isatty(0)) my_putstr(prompt, 1, -1); return (get_next_line(0)); } param->cmd = NULL; if ((param->cmd = init_read_cmd(param->cmd, param)) == NULL) return (NULL); return (loop_cmd(param, history)); }
int ft_get_line_size(t_env *env, int fd, char *line) { int size; size = 0; while (get_next_line(fd, &line)) { if (!ft_only_digit(line) || !line[0]) { free(line); ft_error(env, 2); } size++; free(line); } if (!size) ft_error(env, 2); free(line); return (size); }
int get_move(int player, t_grid *grid) { int move; char *line; line = NULL; move = 0; if (player == 1 || player == 1) { if (get_next_line(0, &line) < 0 || line == NULL) return (-1); move = ft_atoi(line); free(line); } else { move = ft_ai(grid); } return (move); }
int get_lemin_nb(void) { char *tmp; int i; i = 0; if (get_next_line(0, &tmp) > 0) { ft_printf("%s\n", tmp); if (tmp[0] == '#') i = get_lemin_nb(); else if (tmp[9]) i = 0; else if (tmp[0] == '-') i = 0; else i = ft_atoi(tmp); } return (i); }
int ft_shell(t_list **lenv) { char *line; int ret; while (1) { write(1, "$> ", 3); while ((ret = get_next_line(0, &line)) == -1) ; if (!ret) { write(1, "logout\n", 7); return (0); } ft_parse_stdin(line, lenv); free(line); } return (0); }
void get_map(char *filename, t_env *env) { int fd; int gnl; char *line; fd = open_file(filename); env->max_x_map = -1; while ((gnl = get_next_line(fd, &line))) { if (gnl == -1) ft_err_filename(filename, "Read error"); do_split(line, env); if (env->max_x_map != -1 && env->max_x_map != env->px.x) ft_err_filename(filename, "Map invalid"); env->max_x_map = env->px.x; env->px.y++; } env->max_y_map = env->px.y; }
static int history_fill_list(t_history **history, char *tmp, int fd, int id_command) { t_history *element; if ((element = xmalloc(sizeof(*element))) == NULL) return (-1); element->time = my_strdup(tmp); free(tmp); if ((tmp = get_next_line(fd)) == NULL) { close(fd); return (1); } history_put_list(element, tmp, id_command, history); if (*history) (*history)->next = element; *history = element; return (EXIT_SUCCESS); }
t_history *history_create_list(t_config *config, t_history **history) { int fd; char *tmp; int id_command; int flag; id_command = 0; if ((fd = xopen(".history", O_RDONLY, 0, NO)) != -1) while ((tmp = get_next_line(fd))) { if ((flag = history_fill_list(history, tmp, fd, id_command)) == -1) return (NULL); else if (flag == 1) return (history_list_config(config, *history, 0)); id_command++; } close(fd); return (history_list_config(config, *history, 0)); }