t_get *comment(t_get *w, t_get *prev) { char quote; char *s; if (!w) return (prev); if ((((quote = (w->word)[0]) == '"' || (w->word)[0] == '\'') && !w->inter)) { if ((s = my_strndup(w->word + 1, my_strilen(w->word + 1, quote))) == NULL) if (my_strilen(w->word + 1, quote)) { nullify_next(w->next); free(w); return (NULL); } free(w->word); fill(&(w->word), s); w->inter = TRUE; } if (comment(w->next, w) == NULL) { rm_word(w); return (NULL); } return (w); }
static BOOL check(t_get *link, t_header *head, char *line) { line = link->line; if (NMATCH(NAME_CMD_STRING, line + hempty(line))) head->name = get(NAME_CMD_STRING, line, 0, link->no); else if (NMATCH(COMMENT_CMD_STRING, line + hempty(line))) head->comment = get(COMMENT_CMD_STRING, line, 1, link->no); else { if (nempty(line, my_strilen(line, COMMENT_CHAR))) return (ERROR); else if (nempty(line, my_strilen(line, SCOMMENT_CHAR))) return (ERROR); if (IN(line, COMMENT_CHAR)) { link->line = my_strndup(line, my_strilen(line, COMMENT_CHAR)); free(line); } line = link->line; if (IN(line, SCOMMENT_CHAR)) { link->line = my_strndup(line, my_strilen(line, SCOMMENT_CHAR)); free(line); } return (CLEAN); } return (ERROR); }
BOOL match(const char *s, const char *c) { if (!(s && c)) return (FALSE); if (!FNMATCH(s, c, my_strilen(c, '*'))) return (FALSE); return (recur_match(s + my_strilen(c, '*'), c + my_strilen(c, '*') + IN('*', c), my_strlen(c) - my_strilen(c, '*') - IN('*', c))); }
BOOL nmatch(const char *s, const char *c, size_t n) { if (!(s && c)) return (FALSE); if (n < my_strilen(c, '*') && FNMATCH(s, c, n)) return (TRUE); if (!FNMATCH(s, c, my_strilen(c, '*'))) return (FALSE); return (recur_match(s + my_strilen(c, '*'), c + my_strilen(c, '*') + IN('*', c), n - my_strilen(c, '*') - IN('*', c))); }
size_t subdiv(char *s, char **bad_sintax) { if (NMATCH("||", s) || NMATCH("&&", s) || NMATCH("<<", s) || NMATCH(">>", s)) return (2); if (my_sstrlen(s, "<>") < my_sstrlen(s, " \\\t\"'|&;()`") && (my_sstrlen(s, "<>") == 1 || !my_sstrlen(s, "<>"))) return (redir_lenth(s)); if (s[0] == '"' || s[0] == '\'') return (work_on_quote(s, bad_sintax)); if (IN(s[0], ";|&<>()`")) return (1); if (NMATCH(s + my_strilen(s, '&'), "&&") && my_strilen(s, '&') < my_sstrlen(s, " \\\t\"'|;<>()`")) return (my_strilen(s, '&')); return (my_sstrlen(s, " \\\t\"'|&;<>()`")); }
void scan_export(t_alias **alias) { int no; BOOL c; char *s; FD file; c = TRUE; no = 0; if ((file = open_it()) == -1) return ; while ((s = get_next_line(file)) != NULL && c) { if (NMATCH("export", s)) c = export_env(s + my_strlen("export") + hempty(s + my_strlen("export")), no); else if (NMATCH("alias", s)) c = export_alias(s + my_strlen("export") + hempty(s + my_strlen("export")), alias, no); else if (!nempty(s, my_strilen(s, '#'))) return ; no++; } }
static BOOL fill_it(char *s, char **s1, char **s2, int no) { char get; *s1 = NULL; *s2 = NULL; if (empty(s)) return (FALSE); if ((*s1 = my_strndup(s, my_sstrlen(s, "= \t"))) == NULL) return (TRUE); s += my_sstrlen(s, "= \t") + (IN('=', s) || IN(' ', s) || IN('\t', s)); get = s[0]; if (IN(s[0], "\"'") && !(IN(s[0], s + 1))) printf("error in conf file at line #%d, in %s definition\n", no, *s1); if (IN(s[0], "\"'") && !(IN(s[0], s + 1))) return (FALSE); if (!IN(s[0], "'\"")) get = 0; *s2 = my_strndup(s + IN(s[0], "'\""), my_strilen(s + IN(s[0], "'\""), get)); if (IN(s[0], "'\"") && !empty(s + my_strlen(*s2) + 2 * IN(s[0], "'\""))) printf("error in conf file at line #%d, in %s definition\n", no, *s1); if (IN(s[0], "'\"") && !empty(s + my_strlen(*s2) + 2 * IN(s[0], "'\""))) return (FALSE); return (TRUE); }
static size_t work_on_quote(char *s, char **bad_sintax) { char quote[3]; quote[0] = s[0]; quote[1] = '\''; quote[2] = 0; if (!IN(quote[0], s + 1)) *bad_sintax = my_strcat(UNMATCHED_TOKEN, quote); return (my_strilen(s + 1, quote[0]) + 2); }
static char *get(char *type, char *line, int itype, int n) { int l; l = hempty(line) + my_strlen(type) + hempty(line + hempty(line) + my_strlen(type)); if (line[l] != '"') lerror(INVALID(itype), n); if (!IN(line + l + 1, '"')) lerror(INVALID(itype), n); return (my_strndup(line + l + 1, my_strilen(line + l + 1, '"'))); }
static BOOL recur_match(const char *s, const char *c, size_t n) { size_t l; BOOL k; if ((!s[0] && (!c[0] || MATCH(c, "*"))) || n <= 0) return (TRUE); if (!IN('*', c)) { if (my_strlen(s) < my_strlen(c)) return (FALSE); if (MATCH(c, s + my_strlen(s) - my_strlen(c))) return (TRUE); else return (FALSE); } if (!LS_IN(c, s, my_strilen(c, '*'))) return (FALSE); l = my_strilen(c, '*'); s += my_strnslen(s, c, my_strilen(c, '*')) + my_strilen(c, '*'); c += l + (k = IN('*', c)); return (recur_match(s, c, n - l - k)); }
char *get_env(char *s) { size_t i; i = 0; if (!environ) return (NULL); while (environ[i]) { if (NMATCH(s, environ[i])) return (environ[i] + my_strilen(environ[i], '=') + 1); i++; } return (NULL); }