int main(int ac, char **av) { int err; int i; i = 1; if (ac == 1) { err = ft_print_file(0); if (err == -1) ft_puterror("map error\n"); else if (err == -2) ft_puterror("memory error\n"); } while (i < ac) { err = ft_print_file(av[i]); if (err == -1) ft_puterror("map error\n"); else if (err == -2) ft_puterror("memory error\n"); i++; } return (0); }
void print_help(void) { ft_puterror("Usage: ./ft_ls [-lRartTdpuUc] [file ...]\n"); ft_puterror("List information about the FILEs\n"); ft_puterror("(the current directory by default).\n"); ft_puterror("Sort entries alphabetically if -t is not specified.\n\n"); part1(); bonus(); exit(EXIT_SUCCESS); }
t_termios term_init(struct termios term) { char *term_name; if ((term_name = getenv("TERM")) == NULL) ft_puterror("fatal error: env missing"); if (tgetent(NULL, term_name) == ERR) ft_puterror("fatal error: cant initiate termcap"); if (tcgetattr(0, &term) == -1) ft_puterror("fatal error: cant initiate termcap"); return (term); }
static void ft_continue_child(t_data *d, t_id *tmp) { ft_printf("[%d]\tcontinued\t%s\n", tmp->nb, tmp->cmd); if (tcsetpgrp(d->tty.fd, getpgid(tmp->pid)) < 0) ft_puterror("tcsetpgrp in builtin/ft_fg.c line 23: failed\n"); if (!tmp->run && killpg(tmp->pid, SIGCONT) < 0) ft_puterror("kill in builtin/ft_fg.c line 25: failed\n"); tmp->jobs = 0; tmp->run = 0; waitpid(-tmp->pid, &tmp->id, WUNTRACED); ft_print_process(d, tmp); if (tcsetpgrp(d->tty.fd, getpgrp()) < 0) ft_puterror("tcsetpgrp in builtin/ft_fg.c line 30: failed\n"); }
void ft_read_args(t_options *list, int argc, char **argv) { int i; int ret; DIR *ls_dir; char *path; i = 0; while (++i < argc && argv[i][0] == '-') { if (ft_check_args(argv[i], list) == 0) return ; } while (i < argc) { if ((ret = ft_is_valid_dir(argv[i], &ls_dir, &path)) >= 0) { ft_print_dirname(i, argc, argv[i]); ft_ls_dir(ls_dir, list, ret, path); closedir(ls_dir); } i++; } if (argv[i - 1][0] == '-') ft_ls_current(list); else ft_puterror(argv[argc - 1]); }
size_t nab_next_line(int const fd, char **line, char **spill) { int ret; char buf[BUF_SIZE + 1]; size_t spill_len; size_t line_len; char *spill_temp; spill_temp = *spill; spill_len = ft_strlen(*spill); if ((spill_len > 0) & ((line_len = ft_strlen(*line = str_slice(*spill, '\n'))) < spill_len)) return (line_len); while ((ret = read(fd, buf, BUF_SIZE)) > 0) { buf[ret] = '\0'; if ((ret == 0) || (buf[ret - 1] == '\0' && buf[ret - 2] != '\n')) return (0); if (slice_and_stick(line, &line_len, str_slice(buf, '\n')) < (size_t)ret) break ; } if (ret == -1) exit(ft_puterror("read()", "line N/A")); *spill = ft_strdup(buf); free(spill_temp); return (line_len); }
int ft_unsetenv(char **args, t_env **env) { int res; int i; res = 0; i = 0; if (args[0] && !(args[1])) return (ft_puterror("unsetenv", "Argument Needed")); while (args[0] && (*env)->env[i]) { if (ft_strncmp((*env)->env[i], args[1], ft_strlen(args[0])) == 0) { ft_strdel(&(*env)->env[i]); res = 1; while ((*env)->env[i + 1]) { (*env)->env[i] = (*env)->env[i + 1]; (*env)->env[i + 1] = NULL; ++i; } } ++i; } return (res); }
void open_lst_tetri(t_app *app) { int fd; int rt; unsigned char *data; t_tetri *cursor; rt = 1; fd = ft_open(app->av[1], O_RDONLY); rt = readfile(fd, &data, rt); app->tetri = new_tetri(idfrompiece(lire_piece(data), app->pieces)); ft_free(data); cursor = app->tetri; rt = readfile(fd, &data, rt); while (rt != 0) { cursor = add_tetri(cursor, idfrompiece(lire_piece(data), app->pieces)); ft_free(data); rt = readfile(fd, &data, rt); } close(fd); app->nb_tetri = count_tetri(app->tetri); if (app->nb_tetri > 26) ft_puterror(); app->nb_point = app->nb_tetri * 4; }
int ft_exit(t_param *p, t_list *list, t_termios *term) { (void)p; (void)list; ft_visible_cursor(); ft_putendl("fermeture du programme"); if ((ft_clear_term(p)) == -1) ft_puterror("Erreur: lors du retablissement du terminal"); exit(EXIT_SUCCESS); return (0); }
t_solution *make_solution(t_board *board) { t_solution *new_sol; new_sol = malloc(sizeof(t_solution)); if (!new_sol) exit(ft_puterror("make_solution()", "Not Enough Memory")); new_sol->size = -1; update_solution(new_sol, 0, 0, board); return (new_sol); }
t_param *get_port(t_param *e, char **av, int *i) { *i = *i + 1; if (av[*i] && ft_strncmp(av[*i], "-", 1) != 0) { e->port = ft_atoi(ft_strtrim(av[*i])); *i = *i + 1; } else ft_puterror("you write -p but you don't specify the port number"); return (e); }
t_param *get_hostname(t_param *e, char **av, int *i) { *i = *i + 1; if (av[*i] && ft_strncmp(av[*i], "-", 1) != 0) { e->hostname = ft_strdup(ft_strtrim(av[*i])); *i = *i + 1; } else ft_puterror("you write -n but you don't specify a name of team"); return (e); }
int main(int argc, char *argv) { int fd; t_scene scene; //prepscene(scene); if (argc < 1) { fd = open(argv[1]); if (fd = -1) ft_puterror("Could Not Open File"); else if (-1 = readscene(fd, scene)) ft_puterror("Invalid Scene"); //drawscene //showscene } else ft_puterror("No Arguements Given"); }
int ft_execcmd(char **cmd, char **env) { int pid; if ((pid = fork()) == -1) { ft_puterror("42sh: fork fail, return -1.\n"); return (EXIT_FAILURE); } if (pid > 0) waitpid(pid, 0, 0); if (pid == 0) { execve(cmd[0], cmd, env); if (env) ft_exeinenv(cmd, env); ft_puterror("42sh: command not found: "); ft_puterror(cmd[0]); ft_puterror("\n"); _exit(1); } return (EXIT_SUCCESS); }
char *tell_graphic_machin(int fd, int rsrc) { char *buff; buff = (char *)malloc(sizeof(char) * 1024); if (buff == NULL) ft_puterror("malloc"); buff[0] = '\0'; ft_strcat(buff, "pgt "); ft_strcat(buff, ft_itoa(fd)); ft_strcat(buff, " "); ft_strcat(buff, ft_itoa(rsrc)); ft_strcat(buff, "\n"); return (buff); }
char *ft_get_msg(char **tmp, t_env *env, int *map) { char *buff; buff = (char *)malloc(sizeof(char) * 1024); if (buff == NULL) ft_puterror("malloc error"); buff[0] = '\0'; ft_strcat(buff, "bct "); ft_strcat(buff, tmp[1]); ft_strcat(buff, " "); ft_strcat(buff, tmp[2]); ft_strcat(buff, get_map_rsrc(env, map[0], map[1])); ft_strcat(buff, "\n"); return (buff); }
t_id_piece idfrompiece(t_piece piece, t_piece *tab) { t_id_piece i; long int *p; long int *p_tab; p = (long int *)&piece; p_tab = (long int *)tab; i = 0; while (i < 19) { if (*p == p_tab[i]) return (i); i++; } ft_puterror(); return (-1); }
int main(int ac, char **av) { struct termios term; t_lst *list; list = NULL; if (ac < 2) ft_puterror("need moar arguments!"); much_signal(); term = term_init(term); list = get_args(av, list); tputs(tgetstr("cl", NULL), 0, ft_outc); g_list = list; some_caps(term, list); term.c_lflag = (ICANON | ECHO); tcsetattr(0, 0, &term); return (0); }
static char *ft_pathfile(char *path, char *exec) { char *res; int len; int size; len = ft_strlen(path); size = (path[len - 1] == '/') ? len : len + 1; if ((res = malloc(sizeof(char) * (size + ft_strlen(exec) + 1))) == NULL) ft_puterror("Erreur d'allocation memoire exec.c: ligne 60\n"); res[0] = '\0'; res = ft_strcat(res, path); if (len != size) res[len] = '/'; res[size] = '\0'; res = ft_strcat(res, exec); return (res); }
t_lst *push_list(char *str, t_lst *lst) { t_lst *nw; t_lst *browser; if ((nw = (t_lst *)malloc(sizeof(t_lst))) == NULL) ft_puterror("fatal error: cant malloc"); nw->str = str; nw->chck = 0; nw->next = NULL; if (lst == NULL) { nw->slct = 1; return (nw); } nw->slct = 0; browser = lst; while (browser->next != NULL) browser = browser->next; browser->next = nw; return (lst); }
static void print_tab_err_3(int nb) { if (nb == 24) ft_puterror("Too many open files"); if (nb == 25) ft_puterror("Not a typewriter"); if (nb == 26) ft_puterror("Text file busy"); if (nb == 27) ft_puterror("File too large"); if (nb == 28) ft_puterror("No space left on device"); if (nb == 29) ft_puterror("Illegal seek"); if (nb == 30) ft_puterror("Read-only file system"); if (nb == 31) ft_puterror("Too many links"); if (nb == 32) ft_puterror("Broken pipe"); if (nb == 33) ft_puterror("Math argument out of domain of func"); if (nb == 34) ft_puterror("Math result not representable"); if (nb == 35) ft_puterror("Bad file descriptor"); }
static void print_tab_err_2(int nb) { if (nb == 12) ft_puterror("Out of memory"); if (nb == 13) ft_puterror("Permission denied"); if (nb == 14) ft_puterror("Bad address"); if (nb == 15) ft_puterror("Block device required"); if (nb == 16) ft_puterror("Device or resource busy"); if (nb == 17) ft_puterror("File exists"); if (nb == 18) ft_puterror("Cross-device link"); if (nb == 19) ft_puterror("No such device"); if (nb == 20) ft_puterror("Not a directory"); if (nb == 21) ft_puterror("Is a directory"); if (nb == 22) ft_puterror("Invalid argument"); if (nb == 23) ft_puterror("File table overflow"); }
static void print_tab_err_1(int nb) { if (nb == 0) ft_puterror("Succes"); if (nb == 1) ft_puterror("Operation not permitted"); if (nb == 2) ft_puterror("No such file or directory"); if (nb == 3) ft_puterror("No such process"); if (nb == 4) ft_puterror("Interrupted system call"); if (nb == 5) ft_puterror("I/O error"); if (nb == 6) ft_puterror("No such device or address"); if (nb == 7) ft_puterror("Argument list too long"); if (nb == 8) ft_puterror("Exec format error"); if (nb == 9) ft_puterror("Bad file number"); if (nb == 10) ft_puterror("No child processes"); if (nb == 11) ft_puterror("Try again"); }
static void bonus(void) { ft_puterror(" -T When used with the -l (lowercase letter ``ell'')\n"); ft_puterror(" option, display complete time information for the file,"); ft_puterror("\n"); ft_puterror(" including month, day, hour, minute, second, and year.\n"); ft_puterror("\n"); ft_puterror(" -d Directories are listed as plain files\n"); ft_puterror(" (not searched recursively).\n\n"); ft_puterror(" -p Write a slash (`/') after each filename\n"); ft_puterror(" if that file is a directory.\n\n"); ft_puterror(" -u Use time of last access, instead of last modification\n"); ft_puterror(" of the file for sorting (-t) or long printing (-l).\n"); ft_puterror("\n"); ft_puterror(" -U Use time of file creation, instead of last modification"); ft_puterror("\n"); ft_puterror(" for sorting (-t) or long output (-l).\n\n"); ft_puterror(" -c Use time when file status was last changed\n"); ft_puterror(" for sorting (-t) or long printing (-l).\n\n"); }
static void part1(void) { ft_puterror(" -l List in long format.\n"); ft_puterror(" If the output is to a terminal, a total sum for\n"); ft_puterror(" all the file sizes is output on a line before\n"); ft_puterror(" the long listing.\n\n"); ft_puterror(" -R Recursively list subdirectories encountered.\n\n"); ft_puterror(" -a do not ignore entries starting with .\n\n"); ft_puterror(" -r Reverse the order of the sort to get reverse\n"); ft_puterror(" lexicographical order or the oldest entries first\n"); ft_puterror(" (or largest files last, if combined with sort by size\n"); ft_puterror("\n"); ft_puterror(" -t Sort by time modified (most recently modified first)\n"); ft_puterror(" before sorting the operands by lexicographical order.\n"); ft_puterror("\n"); }
char ft_signal(void) { if (signal(SIGINT, ft_print) == SIG_ERR) ft_puterror("erreur avec le signal dans init.c\n"); return (0); }