/* ** Write the header of the file (minus the prog size) ** init the linked lists storing label definition and reference ** Read every line of the file fd_champ, ** split them into a word tab and send them ** to process_line ** Then launch late_operation ** if any error is encountered during these operations, ** return -1, else return 0 */ int my_parsefile(int fd_champ, int fd_binary) { char *line; char **lexed_line; int j; int fileoffset; t_lateinfo info; my_init_info(&info); if ((fileoffset = write_header(fd_champ, fd_binary)) == -1) return (-1); j = 1; while ((line = get_next_line(fd_champ)) != NULL) { if (line[0] != COMMENT_CHAR && line[0] != '.' && line[0] && line[0]) { if ((lexed_line = my_epur(all_in_tab(line))) == NULL || process_line(lexed_line, fd_binary, &fileoffset, &info) == -1) { my_fprintf(2, "at line %i : \"%s\" ", j, line); return (-1); } } free(line); ++j; } return (late_operation(fd_binary, fileoffset, &info)); }
int ini_and_epur_red_right_for_unique(t_list *list) { if (list->next->cmd == NULL || list->cmd == NULL) return (-1); list->next->cmd = my_epur(list->next->cmd); return (0); }
int get_fd_open_spe(t_list *list) { int fd; fd = 0; list->next->next->cmd = my_epur(list->next->next->cmd); if (list->next->num == 4) if ((fd = open(list->next->next->cmd, O_CREAT | O_APPEND | O_WRONLY, 0644)) < 0) return (-1); if (list->next->num == 2) if ((fd = open(list->next->next->cmd, O_CREAT | O_TRUNC | O_WRONLY, 0644)) < 0) return (-1); return (fd); }
void end_main(t_main *s) { if ((s->cmd = get_cmd(&(s->history), s->term, &(s->stop), s->paths)) != NULL) { if (s->stop == 0 && s->cmd != NULL && s->cmd[0] && (s->cmd = my_epur(s->cmd)) != NULL) globbing_and_such(&(s->cmd), &(s->history), s->my_env, s->paths); if (isatty(0) && (s->cmd == NULL || (s->cmd != NULL && !s->cmd[0]))) my_putchar('\n'); my_free(s->cmd); } else if (isatty(0) && (s->cmd == NULL || s->cmd[0] == '\0')) { my_free(s->cmd); my_putchar('\n'); } free_double_tab(s->paths); }