void parse_config(char *file, t_conf *conf) { int fd; char *line; int line_nb; if ((fd = open(file, O_RDONLY)) < 0) { fprintf(stderr, "Open failed\n"); return ; } line_nb = 1; while ((line = get_next_line(fd)) != NULL) { replace_comm(line); epur_str(line); if (strlen(line)) { parse_line(line, conf, line_nb); } free(line); ++line_nb; } close(fd); }
int asm_parsing(header_t *header, char **stock, char *name) { int i; t_args *args; t_list *list; i = -1; if (!(args = my_calloc(1, sizeof(*args)))) return (FAILURE); if (!(list = init_list())) return (FAILURE); while (stock[++i]) { stock[i] = epur_str(stock[i]); if (split_list(stock[i], args) == FAILURE) return (FAILURE); if (line_parsing(args, list, name) == FAILURE) return (FAILURE); } double_free(stock); remplace_label(list); get_every_label_value(list); write_in_file(list, header, name); return (SUCCESS); }
int main(int ac, char **av) { if (ac == 2) epur_str(av[1]); my_putchar('\n'); return (0); }
static int login_user(t_info *info, t_rep *rep) { char buffer[512]; t_rep rep_login; if (!(IS_200(rep->code)) || write(1, "User: "******"USER", buffer)) return (0); if (!get_answer(info, &rep_login)) return (0); if (IS_200(rep_login.code)) return (1); if (IS_300(rep_login.code)) return (login_pass(info)); return (0); } else return (0); return (1); }
char *get_line_not_empty(int fd, int *line) { char *str; if ((str = get_next_line(fd)) == NULL || (str = epur_str(str)) == NULL) return (NULL); (*line)++; while (str != NULL && check_empty(str) == 0) { if ((str = get_next_line(fd)) == NULL || (str = epur_str(str)) == NULL) return (NULL); (*line)++; } return (str); }
int main(int argc, char **argv) { char buffer[] = " a b c de f e g "; char *tmp; tmp = epur_str(buffer); printf("%s\n", tmp); printf("%d\n", my_strlen(tmp)); }
char *prompt_dispatcher(t_glob *glob, t_prompt *prompt) { char *str; if (isatty(0) && init_termcaps(glob)) { str = termcap_prompt(glob, prompt); str = epur_str(str, 1, 0); reset_term(); return (str); } else { reset_term(); str = basic_prompt(glob, prompt); str = epur_str(str, 1, 0); return (str); } }
char *get_name(char *line) { int index_start; int index_end; char *name; line = epur_str(line); index_start = get_nindex_of(line, '"', 1); index_end = get_nindex_of(line, '"', 2); name = my_substr(line, index_start, index_end); return (name); }
char *get_comment(char *line) { int index_start; int index_end; char *comment; line = epur_str(line); index_start = get_nindex_of(line, '"', 1); index_end = get_nindex_of(line, '"', 2); comment = my_substr(line, index_start, index_end); return (comment); }
void ft_hp(t_linez *l, t_sh *term) { unlink("hist_cmd"); while (l && l->prev) { if (l->line) ft_strdel(&l->line); l->line = ft_strnew(0); l = l->prev; } l->line = ft_strnew(0); l->ep_l = epur_str(l->line, term); }
void my_cmd(t_list *list, char *s, char **env, int i) { char *epur_s; char **tab; epur_s = epur_str(s); tab = my_str_to_wordtab(epur_s, &i); if ((my_builtin(list, s, tab, env)) == 0 && \ check_redir(epur_s, tab, env, i) == 0) my_fork(tab[0], tab, env); if (check_env(tab, env) == 1) env = env_cpy(list); check_recurs(list, s, env, i - 1); my_mini_free(epur_s, tab); }
static int run_func(t_server *server, t_client *client, char *cmd) { int i; char *ft; i = 0; ft = strtok(strdup(cmd), " \n"); while (i < 11) { if (ft != NULL && strcasecmp(ft, g_funcs[i].cmd) == 0) return (g_funcs[i].p(server, client, epur_str(strdup(&cmd[strlen(ft)])))); i++; } dprintf(client->socket, ":127.0.0.1 421 %s :Unknown command\r\n", ft); return (0); }
static int run_cmd(t_server *server, t_client *client) { int n; char *cmd; char *new; n = 0; cmd = strdup(read_in_ring(client->buffer)); cmd = epur_str(cmd); while ((new = strtok(strdup(&cmd[n]), "\r\n"))) { run_func(server, client, new); n += strlen(new) + 2; } return (0); }
char *wordcpy(char *str, char *sep, int i) { char *word; int j; j = i; while (find_char(str[j], sep) == 1 && str[j] != '\0') j++; if ((word = malloc(sizeof(char) * j - i + 1)) == NULL) return (NULL); j = 0; while (find_char(str[i], sep) == 1 && str[i] != '\0') word[j++] = str[i++]; word[j] = '\0'; word = epur_str(word); return (word); }
void modif_e2(t_sh *t, t_linez *lz, int k, int *j) { char *tmp; int x = 0; if (ft_strncmp("unsetenv", lz->ep_l, 8)) { tmp = ft_strdup(lz->ep_l); t->env = realloc_tb(t->env); if (search_oplen(&lz->ep_l[k], " =", 10000) < search_oplen(&lz->ep_l[k], "<>|&;", 10000)) { if (ft_strchr(&(tmp[k]), '=')) { t->env[++j[1]] = cpy_to(&(tmp[k]), '='); x = strchri(&(tmp[k]), '='); while (tmp[k + x] == ' ' || tmp[k + x] == '=') x++; } else { t->env[++j[1]] = cpy_to(&(tmp[k]), ' '); x = strchri(&(tmp[k]), ' '); while (tmp[k + x] == ' ' || tmp[k + x] == '=') x++; } } else t->env[++j[1]] = ft_strdup(&(tmp[k])); if (x && tmp[k + x]) { replace_char(t->env[j[1]], '=', ' '); t->env[j[1]] = epur_str(t->env[j[1]], t); if (t->env[j[1]][len(t->env[j[1]]) - 1] == ' ') t->env[j[1]][len(t->env[j[1]]) - 1] = '\0'; t->env[j[1]] = ft_strjoin_free(t->env[j[1]], "=", 1); t->env[j[1]] = ft_strjoin_free(t->env[j[1]], &tmp[k + x], 1); } else t->env[j[1]] = ft_strjoin_free(t->env[j[1]], "=", 1); ft_strdel(&tmp); } t->env[++j[1]] = 0; }
int lexer(char *cmd, t_token **token, t_42sh *shell) { char *error; t_lex *lexi; lexi = xmalloc(sizeof(*lexi)); cmd = check_carac(cmd); lexi->cmd = epur_str(strdup(cmd)); if (!(lexi->cmd[0])) return (0); lex(lexi->cmd, token); if ((error = check_token(token, lexi)) != NULL) { printf("42sh : Syntax error near unexpected token `%s`\n", error); return (0); } else return (parser(token, shell)); return (0); }
static int recup_data_loop(t_list *list, t_recup *data) { to_mini(data->str); if ((data->cpy = my_strdup(data->str)) == NULL) return (-1); epur_str(data->cpy); if (my_strcmp(data->cpy, "\0") == 0) { data->flag = 1; if (list->tail) if (check_data(list->tail) == -1) return (-1); } else if (case_add_list(list, &(data->flag), &(data->flag2)) == -1 || data_line(list->tail, data->str) == -1) return (-1); free(data->str); free(data->cpy); return (0); }
int shell(t_shell *sh) { int r; while (42) { sh->i_tree = -1; sh->check = 0; if (find_path(sh) == -1) return (-1); if ((r = read_buffer(sh)) > 1) { if (parsing_main(epur_str(sh->buffer), sh) == -1) return (-1); } else if (r == 0) return (-1); my_free(sh->path); } return (0); }
static int login_pass(t_info *info) { char buffer[512]; t_rep rep; memset(buffer, 0, sizeof(buffer)); if (write(1, "Pass: "******"PASS", buffer)) return (0); if (!get_answer(info, &rep)) return (0); if (!(IS_200(rep.code))) return (0); return (1); } else return (0); return (1); }
char *read_line(int fd) { int nb; char *cmd; char *buffer; buffer = xcalloc(4096, sizeof(char)); nb = xread(0, buffer, 4096); if (nb == 0) { puts("exit"); return ("exit"); } buffer[nb - 1] = '\0'; cmd = strdup(buffer); free(buffer); cmd = epur_str(cmd); if (cmd[nb - 2] == '|' || cmd[nb - 2] == '>') cmd = cat_if_pipe(cmd); write(fd, cmd, strlen(cmd)); write(fd, "\n", 1); return (cmd); }
int word_check(char *str, int i, t_token **token) { char *word; int j; j = 0; word = xmalloc((strlen(str) + 1) * sizeof(char*)); word = memset(word, 0, (strlen(str) + 1)); while (((check_letter(str[i]) != -1) || str[i] == '\t' ) && (str[i] != '\0')) { word[j] = str[i]; j++; i++; } word[i] = '\0'; if (word[0] != '\0') { word = epur_str(word); *token = insert(*token, TOKEN_WORD, strdup(word), i); } free(word); return (i); }