int restore_term(int tty, int choice, char *read_val, int len) { if (choice && tty) tcsetattr(STDIN_FILENO, TCSANOW, &g_term_data.saved_attr); else if (!choice) { if (read_val[0] == 127 || read_val[0] == 8) { if (g_max_pos > 0) { tputs(tgetstr("le", NULL), 1, my_putchar); g_current_pos--; delete_char(); } } else if (read_val[0] == 27) return (part_case(read_val)); else if (read_val[0] == '\n' || read_val[0] == '\r') return (return_line(read_val, len)); else if (read_val[0] < 27) return (part_case2(read_val)); else add_char(read_val, len); return (1); } return (0); }
int main(int ac, char **av) { int fd; char *line; char **tab; t_asm assembleur; fd = open_asm(ac, av); init_asm(&assembleur); while ((line = return_line(fd))) { assembleur.line += 1; line = suppr_comment(line); if (line && line[0] != '.' && line[0] != COMMENT_CHAR) { tab = ft_strsplit(line, ';'); parse_file(tab[0], &assembleur); } else if (!ft_strncmp(line, NAME_CMD_STRING, ft_strlen(NAME_CMD_STRING))) assembleur.name = give_name(line, assembleur, fd); else if (!ft_strncmp(line, COMMENT_CMD_STRING,\ ft_strlen(COMMENT_CMD_STRING))) assembleur.comment = give_comment(line, assembleur, fd); } fill_label(&assembleur); put_to_file(av[1], assembleur.bytecode, assembleur); return (0); }
void putstr_cmd(t_cursor *curs, int i) { while (curs->line[i]) { curs->cur_col++; display(curs, i); if (curs->cur_col >= curs->max_col) return_line(curs); i++; } }
/*carrega as estcoes do arquivo em um vetor*/ void load_stations(FILE *file, StationVal **station_array){ int i,j,k; char *line = malloc(sizeof(char)*LENGTH); j = count_lines(file); *station_array = malloc(j*sizeof(StationVal)); for(i=0;i<j;i++){ line = return_line(file,i+1); sscanf(&line[0],"%d",&((*station_array)[i].station)); for(k=0; line[k]!=' '; k++); sscanf(&line[k],"%lf",&((*station_array)[i].recx)); for(k++; line[k]!=' '; k++); sscanf(&line[k],"%lf",&((*station_array)[i].recy)); } free(line); }
int get_next_line(int const fd, char **line) { static t_var *get_in[MAX_FD]; if (fd >= MAX_FD || fd < 0 || line == NULL) return (-1); if (get_in[fd] && get_in[fd]->file_lecture == 0) return (0); if (!get_in[fd] && !define(&get_in[fd])) return (-1); while (get_in[fd]->file_lecture > 0 && !((return_line(get_in[fd])))) { while (get_in[fd]->tampon + BUFF_SIZE > get_in[fd]->len) if (!add_memory_size(get_in[fd])) return (-1); get_in[fd]->file_lecture = read(fd, get_in[fd]->memory + get_in[fd]->tampon, BUFF_SIZE); get_in[fd]->tampon = get_in[fd]->tampon + get_in[fd]->file_lecture; } return (return_handle(&get_in[fd], get_in[fd], line)); }
/*retorna um tiro, lido do arquivo de tiros*/ ShotVal *return_shot(FILE *file, int n){ ShotVal *val = malloc(sizeof(ShotVal)); char *line = malloc(sizeof(char)*LENGTH); int k = 0; if (n > count_lines(file)) return NULL; else{ line = return_line(file,n); sscanf(&line[k],"%d",&(val->nshot)); for(k=0; line[k]!=' '; k++); sscanf(&line[k],"%d",&(val->nstation)); for(k++; line[k]!=' '; k++); sscanf(&line[k],"%d",&(val->npattern)); for(k++; line[k]!=' '; k++); for(k++; line[k]!=' '; k++); sscanf(&line[k],"%lf",&(val->recx)); for(k++; line[k]!=' '; k++); sscanf(&line[k],"%lf",&(val->recy)); free(line); return val; } }