int my_while(int nb) { int n; int nbc; nbc = -1; n = nb; while (n != 0) { n = n / 10; nbc = nbc + 1; } nbc = my_power_it(10, nbc); while (nbc != 0) { n = nb / nbc; n = n % 10; my_putchar(n + 48); nbc = nbc / 10; } return (0); }
void disp_stdarg(char *s, ...) { int i; va_list ap; i = 0; va_start(ap, s); while (s[i] != '\0') { if (s[i] == 'c') my_putchar(va_arg(ap, int)); else if (s[i] == 's') my_putstr(va_arg(ap, char *)); else if (s[i] == 'i') my_put_nbr(va_arg(ap, int)); else write(2, "Not a type\n", 11); my_putchar('\n'); i = i + 1; } va_end(ap); }
void print_updated_board_game(t_pp *pp) { pp->toto = pp->li = 4; pp->rap = (pp->toto - 1); pp->z = pp->i = 0; if ((pp->tab = malloc(sizeof(char *) * (pp->toto * 2))) == NULL) return ; while (pp->i++ < pp->li) { pp->tab[pp->i] = malloc(sizeof(char) * ((pp->li * 2))); while (pp->z++ < pp->rap); while (pp->z <= pp->toto) pp->tab[pp->i][pp->z++] = '|'; pp->tab[pp->i][pp->z] = '\0'; pp->z = 0; pp->rap--; pp->toto++; } up_down(2 * pp->li); tab_maxi(pp->li, pp->tab, pp->line, pp->nb_matches); up_down(2 * pp->li); my_putchar('\n'); }
int my_put_nbr(int nb) { int c; int nb2; c = 0; if (nb == -2147483648) { b(); } if (nb < 0 && nb != -2147483648) { nb = nb * (-1); nb2 = nb; my_putchar('-'); a(nb, nb2, c); } else { nb2 = nb; a(nb, nb2, c); } }
int my_echo(t_shell *shell, char **cmd) { t_echo *echo; int i; (void)shell; if ((echo = my_xmalloc(sizeof(*echo))) == NULL) return (-1); echo->opt_n = 0; echo->opt_e = 0; i = 1; while (cmd[i] != NULL) { i = get_opt_n(cmd, i, echo); i = get_opt_e(cmd, i, echo); i++; } if (do_echo(cmd, echo) == -1) return (-1); if (echo->opt_n != 1) my_putchar('\n'); return (0); }
int my_history() { t_hist *hist; char *s; hist = get_hist(NULL); if (hist == NULL) return (1); while (hist->prev != NULL) hist = hist->prev; if (hist->next != NULL) hist = hist->next; else return (0); while (hist != NULL) { my_putstr((s = take_cmd(hist->edit, 0, 0))); free(s); my_putchar('\n'); hist = hist->next; } return (1); }
int flag_S(va_list list, int output, char *ptr) { char *str; str = va_arg(list, char *); while (*str) { if (*str < 32 || *str >= 127) { if (*str < 7) output = output + my_putstr("\\00"); else if (*str > 7 && *str < 32) output = output + my_putstr("\\0"); else if (*str >= 127) output = output + my_putstr("\\"); output = output + my_putnbr_base(*str, "01234567"); } else output = output + my_putchar(*str); str = str + 1; } return (output); }
int a(int nb, int nb2, int c) { int i; while (nb2 >= 10) { nb2 = nb2 / 10; c++; } while (c >= 0) { i = c; nb2 = nb; while (i > 0) { nb2 = nb2 / 10; i--; } nb2 = nb2 % 10; my_putchar(48 + nb2); c--; } }
int main(int argc, char **argv) { t_list *first; t_list *len; if (argc > 1) { first = new_list(NULL); ord_alphlong(first, argv[1]); sort_list(first, &my_alphstr_cmp); len = new_list(NULL); ord_lenlist(first, len); while (len != NULL) { if (len->data != NULL) print_alphlong(first, *(int *)(len->data)); len = len->next; } } else my_putchar('\n'); return (0); }
void my_putnbr_base(int nb, char *base) { int len_base; int i; int power; if (nb < 0) nb = nb * -1; power = 1; len_base = my_strlen(base); while (nb / power != 0) power *= len_base; power /= len_base; while (power != 0){ i = 0; while ((i < len_base) && (power * i <= nb)) ++i; --i; my_putchar(base[i]); nb %= power; power /= len_base; } }
void adapt_client(t_client *client, int actual_pid) { client->msg = add_char(client->msg, client->c); if (client->msg == NULL) exit(msg_error("server: error: malloc failed (msg).\n")); if (client->c == 0) { my_putstr("client "); my_put_nbr(client->queue[0]); my_putstr(" :\n"); my_putstr(client->msg); my_putchar('\n'); if (!my_strcmp(client->msg, "#kill server")) my_exit(client->msg, client->queue); free(client->msg); client->msg = NULL; client->queue = remove_client(client->queue, actual_pid); if (client->queue) client->c = 1; } else client->c = 0; }
void check_validfrigo(char **frigo) { int i; int j; int a; i = -1; while (++i < my_strlen2(frigo) && frigo[i][0]) { my_putchar('\n'); if (count_pointcoma(frigo[i]) != 1) error_message(" : In frigo_Robby : mistake with \';\'"); j = go_to_pc(frigo[i]) + 1; check_afterpcomakitchen(frigo[i], &j); a = 0; while (a < my_strlen2(frigo) && frigo[a][0]) { if (my_strncmp(frigo[i], frigo[a], j) == 0 && a != i) error_message("frigo: 2 * the same ingredient(add them between)"); a++; } } }
char save_tkp(t_tekpaint *tekpaint) { char *buffer; int readv; if (NULL == (buffer = bunny_malloc(sizeof(char)*101))) return (0); clean_buffer(buffer, 101); my_putstr("Entrez le chemin du fichier à sauvegarder : "); readv = read(0, buffer, 100); remove_carriage_return(buffer); buffer = my_strcat(buffer, ".tkp"); if (save_pixelarray(buffer, tekpaint->workplan.buffer) && readv > 0) { my_putstr("Fichier sauvegardé vers : "); my_putstr(buffer); my_putchar('\n'); } else my_putstr("Erreur durant la sauvegarde, try again\n"); bunny_free(buffer); return (1); }
static void bg_process(char *dir, t_gen *gen) { int i; DIR *ptr_dir; char **rec; rec = NULL; if ((ptr_dir = try_open_dir(dir, gen))) { try_read_dir(ptr_dir, dir, gen); closedir(ptr_dir); } show_files(gen); rec = set_folder_recursive(gen->elem, gen->opts); gen->elem = free_list(gen->elem); my_putchar('\n'); for (i = 0; rec && rec[i]; i++) { bg_process(rec[i], gen); free(rec[i]); } if (rec) free(rec); }
void recompose(int signum, t_elem *client) { int bit; if (signum == SIGUSR1) bit = 1; else if (signum == SIGUSR2) bit = 0; client->client_data.c += (bit << (client->client_data.i)++); if (client->client_data.i > 7) { client->client_data.flag = 1; if (client->client_data.c == -1) { my_putstr(client->client_data.message); my_putchar('\n'); my_remove_client(client->client_data.pid); } else add_to_message(client); client->client_data.c = 0; client->client_data.i = 0; } }
/* ** Display a tray of `rows' rows. */ void display_tray(int rows, int height, int width) { int pipes; int i; pipes = 1; while (pipes < rows * 2) { i = 0; move_cursor(width, height); if (pipes == 1) { my_putstr("\033[31m|\033[0m"); launch_termcap(SAVE_CURSOR); } else while (i++ < pipes) my_putchar('|'); width = width - 1; height = height + 1; pipes = pipes + 2; } launch_termcap(RESTORE_CURSOR); }
int my_put_nbr_base(int nbr, char *base) { int len; int a; long p; int i; len = my_len_base(base); i = 0; p = 1; a = 0; while (nbr >= p) p = p * len; p = p / len; while (p > 0) { a = nbr / p; a = a % len; my_putchar(base[a]); p = p / len; i = i + 1; } return (i); }
/* ** If string received from my_read contains delimitor ('\n'): ** => return line (without '\n'). ** Else while there isn't a '\n' it appends string with next string. ** Display line before to return it. */ char *get_next_line(int fd) { char *str; char *tmp; str = my_read(fd); if (str == NULL) return (NULL); while (str[end_of_line(str)] != '\n' && my_strlen(str) < BUFF_SIZE * 10) { tmp = my_read(fd); if (tmp == NULL) return (NULL); str = my_strcatdup(str, tmp); if (str == NULL) return (NULL); } str[end_of_line(str)] = '\0'; if (my_str_isprintable(str)) return (str); my_putstr(str); my_putchar('\n'); return (str); }
int my_ls2(char *name) { struct dirent *d; DIR *dir; dir = opendir(name); if (dir == NULL) { perror("ls"); return (-1); } else { while ((d = readdir(dir)) != NULL) { if (d->d_name[0] != '.') { my_putstr(d->d_name); my_putchar('\n'); } } } return (0); }
int main(int ac, char **av) { char *options; t_list *f_list; t_list *ptr; f_list = NULL; ptr = malloc(sizeof(*ptr)); options = malloc(sizeof(*options) * 4); options = "ldr1"; options = find_options(av, options, 0, 1); f_list = create_list(f_list, av, 0, 1); ptr = f_list; if (my_list_size(f_list) == 1) { my_ls(".", options); if (find_in_tab(options, 'd') == 0) my_putchar('\n'); } else launch_ls(f_list, ptr, options, 1); // free(options); return (0); }
void my_sort_int_tab(int *tab, int size) { int chang; int compt; chang = 1; while (chang != 0) { compt = 0; chang = 0; while (compt != (size)) { if (*(tab + compt) < *((tab + compt) + 1)) { my_swap((tab + compt), ((tab + compt) + 1)); chang = chang + 1; } compt = compt + 1; my_put_nbr(*(tab + compt)); my_put_nbr(*(tab + compt + 1)); my_putchar('\n'); } } }
int serv_loop(char *client_pid) { while (1) { if (recep.pbit == 8 && recep.client_cond == 0) client_pid = recep_pid(client_pid); if (recep.pbit == 8 && recep.client_cond == -1) { recep = fill_union(recep); if (recep.byte.u8loctet == 0) { recep.pbit = -1; client_pid = initstr(client_pid); recep.client_cond = 0; } my_putchar(recep.byte.u8loctet); } if (recep.pbit == -1) recep.pbit = 0; while (recep.cond != 1); recep.cond = 0; } return (0); }
int my_printf(const char *format, ...) { va_list ap; int t; t = 0; va_start(ap, format); if (format == 0) return (-1); while (format[t] != '\0') { if (format[t] == '%') { t = t + 1; call_flags(format, format[t], ap); } else { my_putchar(format[t]); } t = t + 1; } va_end(ap); }
int my_put_nbr(int nb) { my_putnbr_base(nb, "0123456789"); my_putchar('\n'); return (0); }
int pointeur(va_list print) { my_putstr("Les pointeurs fonctionnent"); my_putchar('\n'); }
void my_putspecial(char c, int *i) { my_putchar('%', i); my_putchar(c, i); }
void lex_error(char *msg) { my_putstr("Error: "); my_putstr(msg); my_putchar('\n'); }
void my_putnbr(int nb) { if (nb >= 10) my_putnbr(nb / 10); my_putchar((nb % 10) + '0'); }
void my_outc(int c) { my_putchar(c); }
void my_put_unsign(unsigned int nb) { if (nb / 10 != 0) my_put_unsign(nb / 10); my_putchar((nb % 10) + '0'); }