void parse_name(char *my_line) { int i; char *tmp; char *line; line = ft_strdup(my_line); tmp = line; i = 0; if (g_name != NULL) throw_error(2); while (tmp[i] && ft_isspace(tmp[i])) i++; line = ft_strsub(tmp + i, ft_strlen(NAME_CMD_STRING) , ft_strlen(tmp + i) - ft_strlen(NAME_CMD_STRING)); free(tmp); tmp = line; i = 0; while (tmp[i] && ft_isspace(tmp[i])) i++; if (tmp[i] != '\"') throw_error(1); i++; g_name = ft_strsub(tmp + i, 0, find_endofstring(tmp + i)); free(tmp); if (ft_strlen(g_name) > PROG_NAME_LENGTH) throw_error(3); }
enum e_prompt_status prompt_move_last_word(char *buf) { t_sh *sh; t_list *cur; sh = t_sh_recover(); if (!SHIFT_LEFT) return (TRYING); while (sh->c_prompt->cursor_index > 0) { cur = ft_lstget_at(sh->c_prompt->chars, sh->c_prompt->cursor_index - 1); if (cur && ft_isspace(*(char *)cur->content)) sh->c_prompt->cursor_index--; else break ; } while (sh->c_prompt->cursor_index > 0) { cur = ft_lstget_at( sh->c_prompt->chars, sh->c_prompt->cursor_index - 1); if (cur && !ft_isspace(*(char *)cur->content)) sh->c_prompt->cursor_index--; else break ; } prompt_display(1); return (READING); }
static int ft_count_word(char *str) { int i; int word; i = 0; word = 0; while (str[i]) { while (str[i] && ft_isspace(str[i])) i++; if (str[i]) { word++; while (str[i] && ((!ft_isspace(str[i])) || (ft_isspace(str[i]) && i > 1 && str[i - 1] == '\\'))) { if (((i == 0) || (i > 0 && str[i - 1] != '\\')) && (str[i] == '\"' || str[i] == '\'')) i = ft_search_next_word(str, i, str[i]); else i++; } } } return (word); }
char *ft_strtrim(char const *s) { size_t start; size_t end; size_t i; char *dst; if (!s) return (NULL); start = 0; end = ft_strlen(s); while (ft_isspace(s[start])) start++; while (ft_isspace(s[end - 1])) end--; if ((int)(end - start) < 0) return (""); if (!(dst = ft_strnew(end - start))) return (NULL); if (end - start <= 0) return (ft_strnew(0)); i = -1; while (++i <= end - start - 1) dst[i] = s[start + i]; return (dst); }
static void ft_get_len(char *str, int *len) { int i; int ok; char c; i = -1; ok = 0; while (str[++i] && (!ft_isspace(str[i]) || (ft_isspace(str[i]) && i > 1 && str[i - 1] == '\\'))) { if (str[i] && (str[i] == '\'' || str[i] == '\"') && str[i - 1] != '\\') { c = str[i]; while (!ok && str[++i]) { if (str[i] == c && str[i - 1] != '\\') ok = 1; else (*len)++; } } else (*len)++; } }
char *ft_get_word(char *str) { int len; char *tmp; int i; int j; i = -1; j = 0; len = 0; ft_get_len(str, &len); tmp = ft_strnew(len + 1); while (str[++i] && ((!ft_isspace(str[i]) || (ft_isspace(str[i]) && i > 1 && str[i - 1] == '\\')))) { if (str[i]) { if ((str[i] == '\'' || str[i] == '\"') && ( i == 0 || (i > 1 && str[i - 1] != '\\'))) ft_get_quote(str, &i, &j, &tmp); else if (i > 0 && str[i - 1] == '\\' && --j >= 0) tmp[j++] = str[i]; else tmp[j++] = str[i]; } } return (tmp); }
char *ft_strtrim(char const *s) { char *str; int index; int begin; int size; index = 0; while (ft_isspace(s[index]) == 1 && s[index] != '\0') index++; begin = index; index = (int)ft_strlen(s); while (ft_isspace(s[index - 1]) == 1 && index > 0) index--; size = index - begin; if (size <= 0) size = 0; str = malloc(sizeof(char) * (size) + 1); index = 0; while (index < size) { str[index] = s[begin]; index++; begin++; } str[index] = '\0'; return (str); }
char *ft_strtrim(char const *s) { int len; int i; char *s1; i = 0; if (!s) return (NULL); while (ft_isspace(*s) && *s) s++; len = ft_strlen(s); while (s[i]) i++; i--; while (ft_isspace(s[i]) && i >= 0 && *s) { len--; i--; } if (!(s1 = ft_strnew(len + 1))) return (NULL); ft_strncpy(s1, s, (len)); s1[len + i] = '\0'; return (s1); }
static int lensplit(char const *str) { int len; int inside; int i; F**K; while (str[len]) { if (str[i] == '\"' && inside == 0) { inside = 1; len++; } else if (str[i] == '\"' && inside == 1) { inside = 0; len++; } if (inside == 0 && str[i] && !ft_isspace(str[i])) len++; if (ft_isspace(str[i]) && inside == 0) return (i); i++; } return (len); }
char *ft_strtrim(char const *s) { char *ret; unsigned int i; int b; int c; b = 0; i = 0; if (s == NULL) return (NULL); c = ft_strlen(s) - 1; if (!(ret = (char*)malloc(ft_strlen(s) + 1))) return (NULL); while (ft_isspace(s[i])) i++; if (s[i] == '\0') return (ft_strnew(1)); while (s[b]) { if (ft_isspace(s[c])) c--; b++; } c = c - i + 1; ret = ft_strsub(s, i, c); return (ret); }
static void fill_tab(t_data *data, int *i, int *n, char *s) { if (is_quote(data->line[*i])) { data->error_quote = data->line[*i]; while (data->line[*i]) { s[(*n)++] = data->line[(*i)++]; if (data->line[*i] && *i > 0 && ((data->error_quote == data->line[*i] && data->error_quote != '(') || (data->error_quote == '(' && data->line[*i] == ')'))) { s[(*n)++] = data->line[(*i)++]; break ; } } } if (!data->line[*i]) return ; if (ft_isspace(data->line[*i])) { s[(*n)++] = data->line[(*i)++]; while (data->line[*i] && ft_isspace(data->line[*i])) *i = *i + 1; } else s[(*n)++] = data->line[(*i)++]; }
static int get_total_len(t_data *data) { int i; int n; n = 0; i = 0; while (data->line[i]) { if (is_quote(data->line[i])) i = go_forward(data->line, i, &n); if (ft_isspace(data->line[i])) { i++; n++; while (data->line[i] && ft_isspace(data->line[i])) i++; } else { i++; n++; } } return (n); }
void parse_p_comment(char *my_line) { char *tmp; int i; char *line; line = ft_strdup(my_line); tmp = line; i = 0; if (g_p_comment != NULL) throw_error(2); while (tmp[i] && ft_isspace(tmp[i])) i++; line = ft_strsub(tmp + i, ft_strlen(COMMENT_CMD_STRING) , ft_strlen(tmp + i) - ft_strlen(COMMENT_CMD_STRING)); free(tmp); i = 0; while (line[i] && ft_isspace(line[i])) i++; if (line[i] != '\"') throw_error(1); i++; g_p_comment = ft_strsub(line + i, 0, find_endofstring(line + i)); free(line); if (ft_strlen(g_p_comment) > COMMENT_LENGTH) throw_error(3); }
char *ft_strtrim_p(char const *s) { int i; int j; char *str; if (s == NULL) return (NULL); i = 0; while (*(s + i) && ft_isspace(*(s + i)) == 1) ++i; if (!*(s + i)) { if (!(str = (char *)gmalloc(sizeof(char) * (1)))) return (NULL); *(str + 0) = '\0'; return (str); } j = (int)ft_strlen(s) - 1; while (*(s + j) && ft_isspace(*(s + j)) == 1) --j; if (!(str = (char *)gmalloc(sizeof(char) * (j - i + 1 + 1)))) return (NULL); str = ft_strsub(s, i, j - i + 1); return (str); }
static char *ft_search_path(char *str, int i) { int end; char *path; char *tmp; path = NULL; while (i > 0 && ft_isspace(str[i]) && str[i - 1] != '\\') i--; while (i > 0 && (!ft_isspace(str[i]) || (ft_isspace(str[i]) && str[i - 1] == '\\'))) i--; end = (i > 0 ? ++i : i); while (str[end] && (!ft_isspace(str[end]) || (ft_isspace(str[end]) && str[end - 1] == '\\'))) end++; path = ft_strnrchr(str + i, '/', end - i); if (str[i] == '/') path = ft_strndup(str + i, path - (str + i) + 1); else { tmp = ft_strndup(str + i, path - (str + i) + 1); path = ft_strjoin("./", path ? tmp : ""); ft_strdel(&tmp); } return (path); }
char *ft_strtrim(char const *s) { char *trim; int i; int j; int k; trim = NULL; i = 0; j = 0; if (s == NULL) return (trim); k = ft_strlen(s) - 1; while (ft_isspace(s[i])) i++; while (ft_isspace(s[k])) k--; k = k - i + 1; if (k > 0) { trim = ft_strnew(k + 1); while (j < k) trim[j++] = s[i++]; trim[i] = '\0'; return (trim); } return (trim); }
char *ft_strctrim(char const *s, char c) { char *trim; int i; int j; int k; i = 0; j = 0; k = ft_strlen(s) - 1; while (ft_isspace(s[i]) || s[i] == c) i++; while (ft_isspace(s[k]) || s[i] == c) k--; k = k - i; if (k > 0) { trim = ft_strnew(k + 1); while (j < k) trim[j++] = s[i++]; trim[i] = '\0'; return (trim); } return (""); }
char *ft_strtrim(char const *s) { char *str; char *first; char *last; str = (char *)s; if (!s) return (NULL); else if (*str == '\0') return (ft_strdup("")); while (ft_isspace(*str)) str++; if (*str == '\0') return (ft_strdup("")); first = str; last = first; while (*str != '\0') { if (!(ft_isspace(*str))) last = str; str++; } if (first != last) return (ft_strsub(first, 0, (last - first + 1))); else return (ft_strdup((char *)s)); }
static char *ft_get_name(char *str, int i) { char *name; char *tmp; int end; name = NULL; while (i > 0 && ft_isspace(str[i]) && str[i - 1] != '\\') i--; while (i > 0 && (!ft_isspace(str[i]) || (ft_isspace(str[i]) && str[i - 1] == '\\'))) i--; end = (i > 0 ? ++i : i); while (str[end] && (!ft_isspace(str[end]) || (ft_isspace(str[end]) && str[end - 1] == '\\'))) end++; tmp = ft_strnrchr(str + i, '/', end - i); if (!tmp) name = ft_strndup(str + i, end - i); else { i = tmp - str; name = ft_strndup(str + i + 1, end - i); } return (name); }
int rl_forward_word(t_rl_reader *r, long key) { (void)key; while (r->cursor < r->end && !ft_isspace(r->line[r->cursor])) rl_forward_char(r, 0); while (r->cursor < r->end && ft_isspace(r->line[r->cursor])) rl_forward_char(r, 0); return (0); }
void test_isspace(void) { printf("\n\n ==========[ft_isspace]==========\n"); printf(" ft_isspace(sp) = %d\n", ft_isspace(32)); printf(" ft_isspace(ht) = %d\n", ft_isspace(9)); printf(" ft_isspace(cr) = %d\n", ft_isspace(13)); printf(" ft_isspace('a') = %d\n", ft_isspace(65)); }
int rl_backward_word(t_rl_reader *r, long key) { (void)key; while (r->cursor > 0 && !ft_isspace(r->line[r->cursor])) rl_backward_char(r, 0); while (r->cursor > 0 && ft_isspace(r->line[r->cursor])) rl_backward_char(r, 0); while (r->cursor > 0 && !ft_isspace(r->line[r->cursor - 1])) rl_backward_char(r, 0); return (0); }
char *ft_strtrim(const char *s) { int i; if (!s) return (NULL); while (ft_isspace(*s)) ++s; i = ft_strlen(s) - 1; while (ft_isspace(s[i])) --i; return (ft_strsub(s, 0, i + 1)); }
char *st_get_word(char *cmd, int start) { char *word; int end; end = start; while (cmd[start] && !ft_isspace(cmd[start])) start--; while (cmd[end] && !ft_isspace(cmd[end])) end++; word = ft_strsub(cmd, start, end - start); return (word); }
char *ft_strtrim(char const *s) { int len; if (!s) return (NULL); while (*s && ft_isspace(*s)) s++; len = ft_strlen(s) - 1; while (len > 0 && s[len] && ft_isspace(s[len])) len--; return (ft_strsub(s, 0, len + 1)); }
char *ft_strtrim(char const *s) { int i; int len; i = 0; len = ft_strlen(s) - 1; while (ft_isspace(s[i])) i++; while (ft_isspace(s[len])) len--; return (ft_strsub(s, i, len - i + 1)); }
static size_t ft_strlenchar(const char *s) { size_t i; i = 0; while (ft_isspace(*s) && *s) s++; while (!ft_isspace(*s) && *s) { i++; s++; } return (i); }
/* ** Trim the string 'str' ** (Remove whitespaces before and after the string) */ void ft_stringtrim(t_string *str) { int i; i = str->length - 1; while (i >= 0 && ft_isspace(str->content[i])) i--; i++; ft_stringrem(str, i, str->length - i); i = 0; while (ft_isspace(str->content[i])) i++; ft_stringrem(str, 0, i); }
static size_t ft_get_len(const char *s) { size_t len; len = ft_strlen(s); while (ft_isspace(*s++)) len--; while (*s) s++; s--; while (ft_isspace(*s--)) len--; return (len); }
char *ft_strtrim(char const *s) { size_t i; size_t j; i = 0; j = ft_strlen(s) - 1; while (s[i] && ft_isspace(s[i])) ++i; while (j && ft_isspace(s[j])) --j; if (j < i) return (ft_strnew(0)); return (ft_strsub(s, i, j - i + 1)); }