int main() { char t1[2]; int fd = open("main.c", O_RDONLY); char buf[9]; ft_bzero(buf, 9); ft_strcat(buf, "Ba"); ft_strcat(buf, "j"); ft_strcat(buf, "our."); printf("%s\n", buf); t1[0] = '1'; t1[1] = '\0'; printf("bzero test : %s\n", t1); printf("strlen test : %zu\n", ft_strlen("asd")); printf("strcat test : %s\n", ft_strcat(t1, "ab")); printf("isalpha test : yes %d no %d yes %d no %d\n", ft_isalpha('z'), ft_isalpha('`'), ft_isalpha('A'), ft_isalpha(125)); printf("isdigit test : yes %d no %d yes %d no %d\n", ft_isdigit('1'), ft_isdigit('/'), ft_isdigit('9'), ft_isdigit(':')); printf("isalnum test : yes %d no %d\n", ft_isalnum('1'), ft_isalnum('~')); printf("isascii test : yes %d no %d yes %d no %d\n", ft_isascii('\0'), ft_isascii(-12), ft_isascii(127), ft_isascii(200)); printf("isprint test : yes %d no %d\n", ft_isprint(32), ft_isprint(127)); printf("tolower test : A %c Z %c a %c ~ %c\n", ft_tolower('A'), ft_tolower('Z'), ft_tolower('a'), ft_tolower('~')); printf("toupper test : a %c z %c A %c ~ %c\n", ft_toupper('a'), ft_toupper('z'), ft_toupper('A'), ft_toupper('~')); ft_puts("Hello World"); ft_puts("aaa\n(null)\n"); ft_puts("aaa"); ft_puts(NULL); ft_cat(fd); return (0); }
char *ft_strtrim(char const *s) { char *trim; size_t len; size_t i; size_t start; if (!s) return (NULL); start = 0; while ((!ft_isprint(s[start]) || s[start] == 32) && s[start] != '\0') ++start; len = ft_strlen((char *)s); while ((!ft_isprint(s[len]) || s[len] == 32) && len > start) --len; len -= start - 1; if (!(trim = ft_strnew(len))) return (NULL); i = 0; while (i < len) { trim[i] = s[i + start]; ++i; } trim[i] = '\0'; return (trim); }
void test_isprint(void) { int c = 0; printf("\n\n ==========[is_print]==========\n"); while (c < 127) { if (ft_isprint(c)) printf("'%c' : %d\n", c, ft_isprint(c)); c++; } }
void check_isprint() { int i = 0; printf( "--------\nTest ft_isprint:\n" ); for ( i = MIN; i < MAX; i++ ) { if ( ft_isprint( i ) != isprint( i ) ) { printf("[%d] -> result: %d, expected result: %d\n", i, ft_isprint( i ), isprint( i ) ); exit( 0 ); } } printf("\033[32mOk\n\033[0m"); }
void print_line_on_shell(t_shprop *shell, char *line) { t_term *term; char to_print; int i; term = shell->term; i = 0; while (line[i]) { to_print = line[i]; if (ft_isprint(to_print)) { ft_putchar_fd(to_print, shell->term->fd); shell->curs_pos = (int)shell->input_len; } i++; } if ((shell->curs_pos + shell->prompt_len) % shell->term->ws.ws_col == 0) { T_PRINT(" "); key_move_left(shell); key_move_right(shell); } }
void add_char_input(t_shprop *shell, int key) { t_term *term; term = shell->term; if (ft_isprint(key)) { ft_putchar_fd(key, term->fd); shell->input_len++; cur_pos_char_insert(shell, key); if (shell->hist && !shell->hist->prev) ft_str_renew(&(shell->hist)->line, ft_strdup(shell->input)); shell->curs_pos++; if (shell->curs_pos >= (int)shell->input_len) if ((shell->curs_pos + shell->prompt_len) % term->ws.ws_col == 0) { T_PRINT(" "); key_move_left(shell); key_move_right(shell); } if (shell->input_len + shell->prompt_len > term->ws.ws_col && shell->curs_pos < (int)shell->input_len) fill_lines(shell); } }
char *ft_work_with_unprintable(char *str, size_t len) { size_t k; size_t i; size_t j; char *res; i = 0; j = 0; k = 0; res = ft_strdup(""); while (len) { if (!ft_isprint(str[k])) { res = ft_strjoin_free(res, ft_unprint_to_print(str, j, i), 3); j = k; i = 0; } len--; k++; i++; } if (j < ft_strlen(str)) res = ft_strjoin_free(res, &str[j], 1); return (res); }
char *ft_prompt_readkey(t_datas *datas) { char key[7]; if (!FLAG_ISNOENV(datas->flags) && FLAG_ISCOLOR(datas->flags)) ft_putstr(FTSH_HWHITE); while (42) { ft_bzero(key, 7); read(0, key, 6); if (ft_isprint(key[0]) == 1 && key[1] == 0 && key[2] == 0) ft_prompt_addchar(datas, datas->prompt.line, key[0]); else if (key[0] == 127 && key[1] == 0 && key[2] == 0) ft_prompt_delchar(datas, datas->prompt.line, 0); else if (key[0] == 27 && key[1] == 91 && key[2] == 51 && key[3] == 126) ft_prompt_delchar(datas, datas->prompt.line, 1); else if (key[0] == 10 && key[1] == 0 && key[2] == 0) { if (ft_prompt_nl(datas, datas->prompt.line) == 0) return (ft_prompt_return(datas, datas->prompt.line)); } else ft_prompt_readkey_handler(datas, key); } return (NULL); }
static void ft_read(char **line, int *position, int *autocomp) { int ret; char *buf; ret = 1; buf = ft_memalloc(42); g_env.saved_line = line; while (!ft_strchr(buf, '\n') && ret > 0) { ft_bzero(buf, 42); ret = read(0, buf, 1024); buf[ret] = '\0'; if (ft_isprint(*buf)) { *autocomp = 0; ft_putchar(*buf); ft_add_char(line, *position, *buf); (*position)++; if ((*position + g_prompt_len + 1) % g_ws.ws_col == 1) tputs(tgetstr("sf", NULL), 1, ft_put); } else if (*buf != '\n') ft_check_key(buf, line, position, autocomp); } free(buf); }
void add_stars(t_cmds **cmd, char *dir, t_shell *shell) { int i; int len; char **tmp; char *tm; if (dir[0] == '\0') dir = ft_strdup(shell->get_pwd); if (!is_directory(dir)) return ; process_key(*cmd, DELETE, "del", shell); if (!(i = 0) && ft_strcmp(shell->get_pwd, dir) != 0) while (dir[i++]) process_key(*cmd, DELETE, "del", shell); tmp = get_in_dir(dir, shell); i = -1; while (tmp[++i]) { len = 0; while (tmp[i][len] && ft_isprint(tmp[i][len]) && (tm = ft_strnew(2))) { tm[0] = tmp[i][len]; process_key(*cmd, tmp[i][len++], tm, shell); } process_key(*cmd, ' ', " ", shell); } }
void test_ft_isprint(void) { int i = -1; int res = 0; int ft_res = 0; while (++i < 127) { res += isprint(i); ft_res += ft_isprint(i); if (res != ft_res) break; } if (i == 127) { ft_putstr("\033[32mAll test OK \033[m"); ft_putstr("\n"); } else { ft_putstr("\033[31mFAIL test "); printf("%d\n", i); ft_putstr("\033[m"); } }
char *get_input(char *prompt) { t_line l; if (init_heredoc(&l, prompt) == 1) return (NULL); ft_putstr(prompt); while (1) { ft_bzero(l.buffer, 6); if (read(0, l.buffer, 6) == -1) return (clean_return(&l)); if (l.buffer[0] == 4 && l.buffer[1] == 0 && l.str[0] == '\0' && g_heredoc_expected) return (eof_ret()); if (l.buffer[0] != 10) actions(&l); if (l.buffer[0] != 10 && ft_isprint(l.buffer[0]) ==\ 1) ft_print_key(&l); if (l.buffer[0] == 10) break ; } return (clean_return(&l)); }
int cmp_key(char *key, int *cursor, t_line *list, t_ctrl_h *h) { int i; static t_key tbl[7] = { {UP, &ft_up}, {LEFT, &ft_left}, {RIGHT, &ft_right}, {DOWN, &ft_down}, {DEL, &ft_del}, {SUPR, &ft_supr}, {0, 0} }; i = 0; while (tbl[i].key) { if (*(unsigned int *)key == (unsigned int)tbl[i].key) { tbl[i].f(key, cursor, list, h); return (1); } i++; } i = ft_isprint(key[0]) || key[0] == '\n' ? 0 : 1; return (i); }
int ft_atoi(const char *str) { int i; int semn; int nr; i = 0; nr = 0; if (ft_verify(str[i])) return (0); while (str[i] != '\0' && (str[i] == ' ' || ft_isprint(str[i]) == 0)) i++; if (ft_isdigit(str[i]) == 0 && str[i] != '-' && str[i] != '+') return (0); if (ft_isdigit(str[i]) == 1) semn = 1; else { if (str[i++] == '+') semn = 1; else semn = -1; } while (ft_isdigit(str[i]) != 0) nr = nr * 10 + str[i++] - '0'; nr = nr * semn; return (nr); }
static void checkinputs_splitted(char input, char *buff, char **ptr, t_history *history) { if (input == 127) mvbackspace(buff, ptr); else if (input == 126) { ft_putchar('~'); **ptr = '~'; (*ptr)++; } else if (input == 9) completion(buff, ptr); else if (input < 0) copycutpaste(input, buff, ptr); else if (input == 1) mvcstart(buff, ptr); else if (input == 5) mvcend(ptr); else if (input == 27) mvcursor(buff, ptr, history); else if (ft_isprint(input)) { ft_memmove((*ptr) + 1, (*ptr), ft_strlen((*ptr))); (*ptr)[0] = input; ft_putstr(*ptr); mvcleft(ft_strlen((*ptr)++) - 1); } }
int analyse_rd(int *i, t_env *env, char **arg, int *k) { int j; j = ((char)*(unsigned int *)(env->rd) == '\t') ? srchsmtg(arg, *k, i) : 0; if (*(unsigned int *)(env->rd) == 127 && (j = 1) && (*i) > 0) delete(&arg, k, i); else if ((char)*(unsigned int *)(env->rd) == '\n' && \ (arg[*k][ft_strlen(arg[*k])] = *(unsigned int *)(env->rd))) return (0); else if (*(unsigned int *)(env->rd) == 4479771 && (j = 1)) left(arg, i, k); else if (*(unsigned int *)(env->rd) == 4414235) j = right(j, arg, i, k) > 0 ? 1 : 2; else if (*(unsigned int *)(env->rd) == 4348699) j = down(arg, k, j, i) > 0 ? 1 : 2; else if (*(unsigned int *)(env->rd) == 4283163) j = up(arg, k, j, i) > 0 ? 1 : 2; else if (j != 0) erase_c(4, &(env->term)); else j = ft_isprint((char)*(unsigned int *)env->rd) - 1; move_curs(arg, k, i, &(env->term)); if (j != 0) return (0); return (1); }
char *in_while(char *buffer, int choice) { char *result; int i; int v; int j; i = 0; result = NULL; while (1) { j = 0; if (!result) i = 0; v = 0; buffer = init_buffer(buffer); read(0, buffer, 3); while (ft_isprint(buffer[j])) result = change_cmd(i++, result, buffer[j++]); if (j == 0) i = distrib_buttons(i, &result, buffer, &v); if (i == -2) break ; if (v == 0 && result) result = print_line(result, choice, i); } return (result); }
static void test_3(void) { printf("\ttest 3: ft_isprint(128): "); if (ft_isprint(128) == isprint(128)) puts(SUCCESS); else puts(ERROR); }
static void test_1(void) { printf("\ttest 1: ft_isprint(-1): "); if (ft_isprint(-1) == isprint(-1)) puts(SUCCESS); else puts(ERROR); }
static void ft_check_isprint(void) { int i; i = -1; while (++i < 128) printf("Value: %d, Ret: %d, char: %c\n", i, ft_isprint(i), i); }
int ft_strisprint(const char *str) { int i; i = 0; while (str[i] != '\0') { if (!ft_isprint(str[i])) return (0); } return (1); }
static int test_case(char *arg1, int exp) { int res; int exp; res = ft_isprint(arg1); exp = isprint(arg1); if (res == exp) return (1); log(arg1, exp, res); return (0); }
static int test_alpha(char *str) { char c; while (*str != '\0') { c = *str; if (ft_isprint(c) == 0) error(); str++; } return (0); }
void insert_line_on_shell(t_shprop *shell, const char *line) { char to_print; int i; i = 0; while (line[i]) { to_print = line[i]; if (ft_isprint(to_print)) add_char_input(shell, to_print); i++; } }
int is_ascii(char *key) { if (ft_isascii(key[0]) && key[1] == 0 && key[2] == 0 && key[3] == 0) { if (ft_isprint(key[0])) { ascii(key[0]); if (data()->cur == NONE) data()->cur = CURRENT; return (1); } } return (0); }
void ft_error(char *line, t_env *env) { char **tmp; if (ft_isprint(line[0])) { tmp = ft_strsplit(line, ' '); ft_putstr_color_fd("\033[0;35m", "ft_minishell1 : command not found: " , env->client_socket); ft_putstr_color_fd("\033[0;36m", tmp[0], env->client_socket); ft_putstr_fd("\n", env->client_socket); free(tmp); } }
void ft_putnstr(char *str, unsigned int offset) { if (str && *str) { if (offset) { if (ft_isprint(*str)) write(1, str, 1); else write(1, ".", 1); ft_putnstr(str + 1, offset - 1); } } }
t_bool ft_vcmd(char *cmd) { int i; i = -1; while (cmd[++i]) { if (!ft_isprint(cmd[i]) && !ft_isblank(cmd[i])) { ft_sherror("Invalid command", NULL, FALSE); return (FAILURE); } } return (SUCCESS); }
static void test_isprint(void) { int i, test[1024], ctrl[1024]; print_test_name("------------ISPRINT------------"); i = 0; while (i < 1024) { ctrl[i] = isprint(i); test[i] = ft_isprint(i); ++i; } test_hard(); print_test_results_summary(test, ctrl, 1024); printf("\n"); }
static int ft_manage_inputs(t_env *e, char *inputs) { int value; if ((inputs[0] == 4 || inputs[0] == 10) && inputs[1] == 0 && inputs[2] == 0 && inputs[3] == 0 && inputs[4] == 0 && inputs[5] == 0 && inputs[6] == 0) return (ft_quit(e, inputs)); else if (!ft_delete(e, inputs)) if (!ft_arrows(e, inputs)) if (!ft_clear(e, inputs)) if (ft_isprint(inputs[0]) || inputs[0] == 9) if ((value = ft_process_char(e, inputs)) != 2) return (value); return (-1); }