void put_bin(unsigned char *str) { int k; while (*str) { k = 256; while (k >>= 1) (k & *str) ? ft_putchar('1') : ft_putchar('0'); ft_putchar(' '); if (*str < 10) ft_putstr("00"); else if (*str < 100) ft_putchar('0'); ft_put_char_int(*str); ft_putchar(' '); if (ft_isprint(*str)) ft_putchar(*str); ft_putchar('\n'); ++str; } }
void ft_putnbrhexa(unsigned long n) { if (n >= 16) ft_putnbrhexa(n / 16); if ((n % 16) < 10) ft_putchar((n % 16) + '0'); else { if ((n % 16) == 10) ft_putchar('a'); else if ((n % 16) == 11) ft_putchar('b'); else if ((n % 16) == 12) ft_putchar('c'); else if ((n % 16) == 13) ft_putchar('d'); else if ((n % 16) == 14) ft_putchar('e'); else if ((n % 16) == 15) ft_putchar('f'); } }
void print_line(int tab[], int x, int y, int tmp[]) { int tmp_y; int tmp_x; tmp_x = tmp[1]; tmp_y = tmp[0]; if (tmp_y == 0 && tmp_x == 0) ft_putchar(tab[0]); else if (tmp_y == 0 && tmp_x == x - 1) ft_putchar(tab[1]); else if (tmp_y == y - 1 && tmp_x == 0) ft_putchar(tab[2]); else if (tmp_y == y - 1 && tmp_x == x - 1) ft_putchar(tab[3]); else if (tmp_y == 0 || tmp_y == y - 1) ft_putchar(tab[4]); else if (tmp_x == 0 || tmp_x == x - 1) ft_putchar(tab[5]); else ft_putchar(' '); }
int unload4(t_print *gl, char t, long long int i) { if (i == 0 && gl->p == 0) { if (gl->temp > 0) ft_putchar(' '); else gl->space--; } else { if (t == 'i') ft_putunbr((unsigned int)i); if (t == 'l') ft_putunbr((unsigned long int)i); if (t == 'L') ft_putunbr((unsigned long long int)i); if (t == 's') ft_putunbr((unsigned short)i); if (t == 'c') ft_putunbr((unsigned char)i); } return (gl->space + ft_strlen(gl->s) + gl->i + gl->neg); }
int main(int argc, char **argv) { int i; i = 1; while (i < argc - 1) { if (ft_strcmp(argv[i], argv[i + 1]) > 0) { ft_swap(&argv[i], &argv[i + 1]); i = 1; } else i++; } i = 1; while (i < argc) { ft_putstr(argv[i]); ft_putchar('\n'); i++; } return (0); }
int ft_printf(const char *format, ...) { va_list myva; t_main *main; main = (t_main *)malloc(sizeof(t_main) * 1); main->sizeword = 0; main->i = 0; main->totalsize = 0; main->chaine = format; //initializzzzzze VA va_start(myva, format); while(format[main->i] != '\0') { if(format[main->i] != '%') { ft_putchar(format[main->i]); main->sizeword++; // main->i++; } else if(format[main->i + 1] != '\0') { init_main(main); if(main->chaine[main->i + 1] != '%') main->elem = va_arg(myva, void *); flag_fiel(main); my_width(main, &myva); my_accurate(main, &myva); lenght_fiel(main); manage_arg(main); add_mini(main); ft_putstr(main->print); main->totalsize += main->size; } main->i++; }
unsigned int ft_putwchar(long long n) { char *mask_unicode; int *bin; int index; int dec; if (0 <= n && n <= 255) { ft_putchar(n); return (1); } dec = 0; index = 0; mask_unicode = ft_mask_unicode(n); bin = ft_convert_binary(mask_unicode); while (bin[index] != -42) { dec = ft_bin_to_dec(bin[index]); write(1, &dec, 1); index++; } return (index); }
void ft_capitalize(char *str) { int i; i = 0; str = ft_strtolower(str); if (str[0] >= 'a' && str[0] <= 'z') str[0] -= 32; while (str[i] != '\0') { if ((str[i - 1] >= 32 && str[i - 1] <= 38) || (str[i - 1] >= 40 && str[i - 1] <= 44) || (str[i - 1] >= 46 && str[i - 1] <= 47) || (str[i - 1] >= 58 && str[i - 1] <= 64) || (str[i - 1] >= 91 && str[i - 1] <= 96) || (str[i - 1] >= 123 && str[i - 1] <= 126)) { if (str[i] >= 'a' && str[i] <= 'z') str[i] -= 32; } ft_putchar(str[i]); i++; } }
static int get_opt(t_opt *options, int ac, char **av) { int i; int j; i = 1; while (i < ac && av[i][0] == '-') { j = 1; while (av[i][j]) { if (!get_one_opt(options, av[i][j])) { ft_putstr("ft_ls: illegal option -- "); ft_putchar(av[i][j]); ft_putstr("\nusage: ft_ls [-Ralrt] [file ...]\n"); return (-1); } ++j; } ++i; } return (i); }
void cut_check_p3(char *str, char *str2, int *tab, int i) { if (ft_strcmp(str, "\0") == 0) { ft_putstr_fd("No params for function : ", 2); ft_putstr_fd(str2, 2); ft_putchar('\n'); exit(0); } if (is_number(str) == 1) { if (is_in_tab(T_IND, tab, i)) ; else exit_prgm_type_ind(str2, str); } else if (str[0] == LABEL_CHAR) if (is_in_tab(T_IND, tab, i)) ; else exit_prgm_type_ind(str2, str); else exit_prgm_nbr(str2, str); }
void ft_putlst(t_list *lst) { int i; i = 0; while (1) { ft_putstr("lst["); ft_putstr(ft_itoa(i)); ft_putstr("] : "); if (ft_isreadable(lst->content, lst->content_size)) ft_putstr(lst->content); else ft_putnbr(*(int *)lst->content); ft_putstr(" / size = "); ft_putnbr(lst->content_size); ft_putchar('\n'); if (lst->next == NULL) return ; else lst = lst->next; i++; } }
void print_ls_l(t_dir_item *items, char *params, int only_dirs) { int *spaces; int total; t_list *container; container = NULL; total = 0; while (items) { ft_lstpush(&container, ft_lstnew(print_list_item(items, &total, params), sizeof(t_litem))); items = items->next; } if (container && only_dirs) { ft_putstr("total "); ft_putnbr((total)); ft_putchar('\n'); } spaces = max_size_elem(container); print_padded_item(container, spaces); free(spaces); }
int print_p_option(size_t n, t_flags flags) { int length; int tmp; tmp = 0; length = 3; if (!flags.field_width) write(1, "0x", 2); while (n > 15) { n /= 16; length++; } while (flags.field_width > length && !flags.minus) { ft_putchar(' '); length++; tmp--; } if (flags.field_width) write(1, "0x", 2); return (length); }
int main(int ac, char **av) { t_map *map; int fd; if (ac == 3) { fd = open(av[1], O_RDONLY); map = ft_get_maps(fd, ft_atoi(av[2])); while (map) { ft_putstr(map->content); //ft_putnbr(map->x); ft_putchar('\n'); //ft_putnbr(map->y); //ft_putchar('\n'); //ft_putchar('\n'); map = map->nxt_map; } close(fd); } return (0); }
void colle(int x, int y) { int count_y; count_y = 1; while (count_y <= y) { if (count_y == 1) { ft_print_begin(x); } else if (count_y == y) { ft_print_end(x); } else { ft_print_empty_line(x); } if (x > 0) ft_putchar('\n'); count_y++; } }
int ft_checkp1a(t_numb *e, char *s1) { int cnt; cnt = 0; if (e->indzero == 1) { ft_putstr("0x"); ft_putstrad2(e->pr, s1); while ((e->w - (e->g + 2)) > 0) { cnt++; ft_putchar('0'); (e->w)--; } } else cnt = cnt + ft_checkp1a1(e, s1); if (e->pr > (int)ft_strlen(s1)) cnt = cnt + e->pr + 2; else cnt = cnt + ft_strlen(s1) + 2; return (cnt); }
void ft_dir_in_wl(char *s, int *tab) { char **files; int i; int nb; struct stat buf; nb = 0; ft_putstr("\n\n"); i = 3; files = ft_simple_ls(s); while (files[i]) { stat(files[i], &buf); if (buf.st_size > 0) nb += 4; i++; } ft_putstr(s); ft_putstr(":\ntotal "); ft_putstr(ft_itoa(i * 4)); ft_putchar('\n'); ft_treat_wtl(tab, files); }
int main(int argc, char *argv[]) { int end; int i; int j; i = 3; j = 0; end = ft_atoi(argv[2]); while (argv[i]) { if (argc > 4) { if (j++) ft_putchar('\n'); ft_putstr("==> "); ft_putstr(argv[i]); ft_putstr(" <==\n"); } ft_tail(argv[i], end); i++; } return (0); }
int ft_printf_o(va_list args, t_env *env) { int size; unsigned int tmp; int size_tmp; size = 0; tmp = va_arg(args, int); get_size_octal(tmp, &size); size_tmp = size + 1; if (env->minus == 1) { if (env->sharp == 1 && env->precision->value <= size_tmp && tmp != 0) size += ft_putchar('0'); size += print_precision_o(tmp, size_tmp, env); size += print_width(env->width->value - size - 1, env); } else { size = zero_handling(env, size, size_tmp, tmp); size += print_precision_o(tmp, size_tmp, env); } return (size + 1); }
int main(int ac, char **av, char **envs) { char *line; int red; char **env; av = av; env = ((envs[0]) ? ft_copy_tab(envs) : NULL); signal(SIGINT, sig); while (42) { ft_putstr("$>"); if ((red = get_next_line(0, &line))) { if ((ft_strlen(line)) > 0) { env = mainter(ac, env, line); } ((red < 0) ? exit (0) : 0); } ((red == 0) ? (ft_putchar('\n'), exit (0)) : 0); } return (0); }
int ft_checks22b1(t_numb *e) { int cnt; int i; char sn[7]; ft_fullsn(sn); cnt = 0; if (e->pr > 0) { e->prbegi = e->pr; i = 0; while (i < 6 && e->pr > 0) { ft_putchar(sn[i]); cnt++; i++; (e->pr)--; } e->pr = e->prbegi; } cnt = cnt + ft_checks22b1a(e); return (cnt); }
void print_file(t_app *app) { t_p_arg *tmp; t_lst_elem lst; struct dirent d; tmp = app->first_p_arg; ft_bzero(&lst, sizeof(t_lst_elem)); lst.no_total = 1; while (tmp) { if (tmp->type == 1) { ft_strcpy(d.d_name, tmp->path); d.d_namlen = ft_strlen(d.d_name); insert_elm(app, &lst, &d); } tmp = tmp->next; } if (app->have_file) app->print(app, &lst); if (app->have_file && app->have_dir) ft_putchar('\n'); }
int ft_atoi(char *str) { int i; int rslt; int temp; temp = 0; i = 0; rslt = 0; while (str[i] != '\0') { if ((str[i] >= '0' && str[i] <= '9') || str[i] == '-') { if (str[i] == '-') ft_putchar('-'); else rslt = rslt * 10 + (str[i] - 48); i++; } else return (rslt); } return (rslt); }
void ft_get_group_spaces(t_infos *entry_list, int i, int j) { static int nb; int k; int tmp; if (!nb) { k = 0; while (k <= i) { if ((tmp = ft_spacelen(entry_list[k].group)) > nb) nb = tmp; k++; } } tmp = ft_spacelen(entry_list[j].group); ft_putstr(entry_list[j].group); while (tmp < nb) { ft_putchar(' '); tmp++; } }
void return_selected(t_env *env) { t_item_list *lst; int printed; terminal_normal_mode(); ft_putstr(tgetstr("te", 0)); ft_putstr(tgetstr("ve", 0)); printed = 0; lst = env->items; while (lst) { if (lst->item->selected) { if (printed) ft_putchar(' '); else printed = 1; ft_putstr(lst->item->name); } lst = lst->next; } exit(0); }
int draw(int longueur, int largeur) { int i; i = largeur - 1; while(i != -1) { if(i == largeur - 1) out(longueur); else if (i <= 0) { out(longueur); return(0); } else if(i < largeur - 1 && i != 0) { reste(longueur); ft_putchar('\n'); } else out(longueur); i--; } return(0); }
void write_uint(t_env *e, va_list ap) { void *d; int lng; d = va_arg(ap, void *); d = caste_normal_type(e, d); if (e->precision.p == 0 && (int)d == 0) return ; if (d == UINT_MAX + 1 && d != 0) { ft_putchar('0'); e->written++; } lng = ft_lenuint((unsigned long long int)d) - 1; if (e->precision.p > 0 && e->convert.flags[BASE] != 1) wr_prec(e, lng); if (e->convert.flags[BASE] == 1) wr_justify(e, lng); ft_putunbr((unsigned long long int)d); e->written += ft_lenuint((unsigned long long int)d); if (e->convert.flags[LEFT_JUSTIFY] == 1 && e->width.w > lng) wl_justify(e, lng); }
void rl_clear_screen(t_rl_ctx *ctx) { t_dlst *tmp; t_uint len; t_uint tpos; tputs(tgetstr("cl", NULL), 0, rl_putchar); rl_putheader(ctx); tmp = ctx->line; if (tmp) { while (tmp->prev) tmp = tmp->prev; while (tmp) { ft_putchar(*((char*)tmp->data)); tmp = tmp->next; } len = ctx->line ? ft_dlstlen(ctx->line) : 0; tpos = ctx->pos; while (tpos++ < len) tputs(tgetstr("le", NULL), 0, rl_putchar); } }
static int ft_prec_o(t_printf **ges, const char *s) { int i; int ret; i = 0; ret = 0; ret += ft_prec_init_ret(ges, s); if ((*ges)->lng && ft_strlen(s) < (unsigned long)(*ges)->lng) { while (i < (*ges)->lng - (int)ft_strlen(s) - (*ges)->sharp) { ft_putchar('0'); i++; } if ((*ges)->sharp) ret--; } else if ((*ges)->lng) ret -= 1 + ft_strlen(ft_itoa((*ges)->lng)); if ((*ges)->lng == 1 && (*ges)->sharp) ret++; return (ret); }
int main(int argc, char **argv) { int x; int **tab; tab = allocate_tab(); if (error(1, 0, argv, argc) == 0) { tab = init(argv, tab); if (*init(argv, tab) != 0) { checking(tab, 0); x = 0; while (x < argc - 1) { ft_putnbr(tab[x]); ft_putchar('\n'); x++; } free(tab); } } return (0); }