char *ft_stradd(char **s1, char **s2) { char *str; void *b; int i; i = ft_strlen(*s1) + ft_strlen(*s2); if ((str = (char *)malloc(sizeof(char) * (i + 1))) == NULL) return (NULL); b = str; i = 0; while ((*s1)[i]) *str++ = (*s1)[i++]; i = 0; while ((*s2)[i]) *str++ = (*s2)[i++]; *str = '\0'; if (*s1) ft_strdel(s1); if (*s2) ft_strdel(s2); return (b); }
int gnl_copy(char **line, char *str, int ret) { int len; if (*line != NULL) ft_strdel(line); if (ft_strchr(str, '\n')) { *line = ft_strcdup(str, '\n'); len = ft_strlen(*line); ft_memmove(str, str + len + 1, ft_strlen(str) - len); } else if (ret == 0) { *line = ft_strdup(str); if (str) ft_strdel(&str); return (1); } if (str == NULL && ret <= 0) return (0); return (1); }
static void ft_gnltest(char ***line, char **save) { if (!ft_strchr(*save, '\n')) { **line = ft_strdup(*save); ft_strdel(save); } else { **line = ft_strsub(*save, 0, ft_strchr(*save, '\n') - *save); *save = ft_strsub(*save, ((ft_strchr(*save, '\n') - *save) + 1), ft_strlen(*save)); } }
int ft_read(int const fd, char *buff_rd, char *full[fd]) { char *temp_rd; char *latent; int read_ret; read_ret = 0; while (!(latent = ft_strchr(full[fd], '\n')) && (read_ret = read(fd, buff_rd, BUFFER)) > 0) { buff_rd[read_ret] = '\0'; temp_rd = full[fd]; full[fd] = ft_strjoin(temp_rd, buff_rd); ft_strdel(&temp_rd); } ft_strdel(&buff_rd); free(buff_rd); if (read_ret < 0) return (-1); if (read_ret == 0 && !latent) return (0); return (1); }
void ft_lstdel(t_list **alst) { t_list *elem; t_list *tnext; elem = *alst; while (elem) { tnext = elem->next; ft_strdel((char **)&(elem->content)); elem = tnext; } *alst = NULL; }
int maj_dlst(t_dlst *dlst, t_double *elem) { if (!elem->next && elem->prev) { dlst->tail = elem->prev; dlst->tail->next = NULL; ft_strdel(&elem->s); } else if (!elem->prev && elem->next) { dlst->head = elem->next; dlst->head->prev = NULL; ft_strdel(&elem->s); } else { elem->prev->next = elem->next; elem->next->prev = elem->prev; ft_strdel(&elem->s); } dlst->lenght--; return (1); }
int get_ants(void) { char *str; int ants; if (get_next_line(0, &str) < 1) return (exit_error("Error while reading file")); if (ft_strcheck(str, ft_isdigit) == FAILURE) return (exit_error("The first line of the file" "is the NUMBER of ants you dumbass")); ants = ft_atoi(str); ft_strdel(&str); return (ants); }
t_tree *sh_analyze(char *line) { t_tree *tree; t_auto autom; int i; int size; size = ft_strlen(line); if (!sh_initauto(&autom, size)) return (0); i = -1; while (++i <= size) { if (!sh_automaton(&autom, line[i])) { ft_strdel(&(autom.buf)); return (0); } } ft_strdel(&(autom.buf)); tree = sh_pars(autom.l_lex); return (tree); }
static int pathisdir_next(char **files, char *dos, char *tmp, char *path) { int count; int ret; count = -1; ret = 0; while (files[++count]) if (ft_strcmp(dos, files[count]) == 0) ret = 1; ft_tabstrdel(&files); ft_strdel(&dos); ft_strdel(&tmp); if (ret == 1) { files = ft_getdirtab(path, NULL); if (!files) ret = 0; else ft_tabstrdel(&files); } return (ret); }
static int set_line(char **line, t_fd *fd_list, char *tmp) { if (tmp) { *tmp++ = '\0'; tmp = ft_strdup(tmp); *line = ft_strdup(fd_list->current); ft_strdel(&fd_list->current); fd_list->current = tmp; } else { if ((tmp = ft_strchr(fd_list->current, '\0'))) tmp = ft_strdup(tmp + 1); *line = ft_strdup(fd_list->current); if (tmp) { ft_strdel(&fd_list->current); fd_list->current = tmp; } } return (1); }
static t_lex *free_all(t_lex *main_lst) { t_lex *main_tmp; while (main_lst) { ft_strdel(&main_lst->str); free_detail(main_lst->lst); main_tmp = main_lst->next; free(main_lst); main_lst = main_tmp; } return (NULL); }
static int join_line_buf_shifted(char **line, char *buf, char *to_join) { char *tmp; char *posn; posn = ft_strchr(buf, '\n'); tmp = ft_strnjoin(to_join, buf, posn - buf); if (!tmp) return (-1); ft_strdel(line); *line = tmp; ft_strncpy(buf, posn + 1, ft_strlen(buf) - (posn - buf)); return (1); }
void destroy_gen(void) { t_gen *gen; gen = recup_gen(); erase_list(gen->builtin); gen->ret = 0; gen->status = 0; gen->pid_fork = 0; if (gen->ps1) { if (gen->ps1->aff) ft_strdel(&(gen->ps1->aff)); if (gen->ps1->env) ft_strdel(&(gen->ps1->env)); gen->ps1->len = 0; free(gen->ps1); gen->ps1 = NULL; } destroy_gen_term(gen); destroy_gen_hist(gen); ft_freetmpenv(gen); }
void ft_putendl_fd(char const *s, int fd) { char *tmp; int len; if (!s) write(fd, "\n", 1); len = ft_strlen(s); tmp = ft_strnew(len + 2); tmp = ft_memcpy(tmp, s, len + 1); tmp[len] = '\n'; write(fd, tmp, len + 1); ft_strdel(&tmp); }
static int ft_send_fd(int sock) { char *buff; int ret; buff = ft_strnew(4096); ret = read(sock, buff, 4096); if (ret <= 0) return (-1); buff[ret] = '\0'; ft_putstr(buff); ft_strdel(&buff); return (0); }
static void cut_env(t_all *all, char ***env_dup) { char *name; int ret; ret = 0; name = get_name(all->ch_arg[2]); ret = name_search(ft_strdup(name), all); if (ret != -1) { write_value(env_dup, ret); ft_strdel(&name); } }
static void register_conversion(t_prf *env, t_specs *specs, int to_copy, int save) { char *tmp; tmp = ft_strsub(env->format, save, to_copy); ft_strcpy(specs->conversion, tmp); ft_strdel(&tmp); specs->format = specs->conversion[to_copy - 1]; if (specs->format == 'o' || specs->format == 'O') specs->base = 8; else if (specs->format == 'x' || specs->format == 'X' || specs->format == 'p') specs->base = 16; }
void free_arr(char ***arr) { int i; i = 0; if (!arr) return ; while ((*arr)[i]) { ft_strdel(*arr + i); i++; } free(*arr); *arr = NULL; }
int ft_read(t_data *data, const int fd, char **line) { char buf[BUFF_SIZE + 1]; while ((data->ret = read(fd, buf, BUFF_SIZE)) > 0) { buf[data->ret] = '\0'; if (!(data->rest)) data->rest = ft_strdup(""); data->str = ft_strjoin(data->rest, buf); ft_strdel(&(data->rest)); if (ft_find(data, line) == 1) return (1); } if (data->ret == -1) { if (data->rest) ft_strdel(&(data->rest)); return (-1); } if (data->ret == 0 && data->rest) return (ft_helper(data, line)); return (0); }
t_map *split_tab(t_map *map, int fd) { char **split; char *line; int i; int j; i = 0; while (get_next_line(fd, &line) == 1) { j = 0; map->tab[i] = (int *)malloc(sizeof(int *) * (map->nb_col)); split = ft_strsplit(line, ' '); while (split[j] != NULL) { map->tab[i][j] = ft_atoi(split[j]); ft_strdel(&split[j]); j++; } ft_strdel(&line); i++; } return (map); }
void ft_do_padding_switch_5(t_conv *conv, char **ret, int offset, char *padding) { char *tmp2; char *tmp; tmp2 = NULL; tmp = NULL; if (ft_strchr(conv->flag, '-') != NULL) ft_do_padding_switch_5_1(ret, offset, padding); else { if (**ret == '+') *ret = ft_strjoin_free(ft_strdup("+"), ft_strjoin( tmp = padding, (tmp2 = *ret) + offset + 1)); else *ret = ft_strjoin( tmp = padding, (tmp2 = *ret) + offset); ft_strdel(&tmp); ft_strdel(&tmp2); } }
int group_max_len(t_llist *root, int ret, int temp, t_param *param) { char *tmp; t_list *list; t_stat s; char *str; list = root->start; while (list != NULL) { tmp = ft_strjoin(root->path, "/"); str = ft_strjoin(tmp, list->str); if (lstat(str, &s) == 0 && file_ok(list, param) == 1) { temp = ft_strlen(get_group(s)); if (temp > ret) ret = temp; } list = list->next; ft_strdel(&str); ft_strdel(&tmp); } return (ret); }
void update_score(t_map *m, char c) { char *convert_score; int i; if ((convert_score = ft_itoa(m->score)) == NULL) ft_error_system(); i = 0; if (c == '.') m->score += 5; tputs(tgoto(tgetstr("cm", NULL), (m->nb_char + 13), calcul_pos(m->nb_line, 1)), 1, myputc); ft_strcolor_fd(convert_score, H_RED, 2, 1); ft_strdel(&(convert_score)); }
int pf_print_u_hh(unsigned int n, t_pf_flag *fl) { int i; char *s; int len; i = 0; s = ft_itoa_unsign_short((unsigned char)n); len = ft_strlen(s); i += pf_print_u_before(fl, len, s); i += ft_putstr(s); ft_strdel(&s); i += pf_print_u_after(fl, len); return (i); }
static char *ft_str_expand(char *str, int addlen) { int oldlen; int newlen; char *newstr; if (!str) return (NULL); oldlen = ft_strlen(str); newlen = oldlen + addlen; newstr = ft_strnew(newlen + 1); newstr = ft_strcpy(newstr, str); ft_strdel(&str); return (newstr); }
int get_next_line_split(char *all, char **line) { int index; index = 0; while (all[index] != '\n' && all[index]) { index++; } if (!all[index] && !index && all[0] != '\n') index = -1; ft_strdel(line); *line = ft_strsub(all, 0, index); return (index); }
void ft_clean_line(t_term *term) { ft_go_end(term); if (term->cmdlength == 0) return ; while (term->cmdlength-- > 0) { ft_left_arrow(term); tputs(tgetstr("dc", NULL), 0, ft_outchar); tputs(tgetstr("cd", NULL), 0, ft_outchar); } term->cmdlength = 0; if (term->cmdactual) ft_strdel(&(term->cmdactual)); }
char *serch_coment(char *lin) { int i; char *src; i = -1; while (lin[++i] && lin[i] != COMMENT_CHAR && lin[i] != ';') ; if (lin[i] == '\0') return (lin); src = ft_strndup(lin, (size_t)i); src[i] = '\0'; ft_strdel(&lin); return (src); }
static void reader_and_save(int fd, char *buf, t_gnl *cur) ////// { int bytes; char *tmp; while (!(ft_strchr(cur->str, '\n')) \ && (bytes = read(fd, buf, BUFF_SIZE)) > 0) { tmp = cur->str; buf[bytes] = '\0'; cur->str = ft_strjoin(cur->str, buf); //printf("//// %s\n", cur->str); ft_strdel(&tmp); } }
void complete_line(t_shprop *shell) { char *save_input; char *new_input; ft_strdel(&shell->prompt); shell->prompt = ft_strdup("> "); ft_putstr_fd(shell->prompt, shell->term->fd); shell->prompt_len = 2; save_input = ft_strdup(shell->input); ft_strdel(&shell->input); new_input = NULL; shell->curs_pos = 0; get_input(shell, &handle_edit_keys); if (shell->input) { new_input = ft_strjoin(save_input, shell->input); ft_strdel(&shell->input); } else if (interrupt(-1) == 0) new_input = ft_strdup(save_input); ft_strdel(&save_input); shell->input = new_input; }