int ft_match(char *s1, char *s2) { if (*s1 != '\0' && *s2 == '*') return (ft_match(s1 + 1, s2) || ft_match(s1, s2 + 1)); if (*s1 == '\0' && *s2 == '*') return (ft_match(s1, s2 + 1)); if (*s1 == *s2 && *s1 != '\0' && *s2 != '\0') return (ft_match(s1 + 1, s2 + 1)); if (*s1 == *s2 && *s1 == '\0' && *s2 == '\0') return (1); return (0); }
// Right Associative version of AND. // ft_bool_term -> ft_bool_factor AND ft_bool_term // | ft_bool_factor static syntree *ft_bool_term (token **lookahead, err_context context) { syntree *left = NULL; syntree *right = NULL; RETURN_NULL_IF_OVER_DEPTH_LIMIT(context); left = ft_bool_factor (lookahead, context); if (left) { if (ft_match (lookahead, TOK_FT_AND)) { right = ft_bool_term (lookahead, context); if (right) { return (ft_and_new (left, right)); } } else { return (left); } } cond_del (left); ASSERT (right == NULL); return (NULL); }
void ft_add_comp_list(char *path, char *to_comp) { DIR *dir; t_dirent *ent; char *new; t_stat file_stats; dir = opendir(path); if (dir) { ent = readdir(dir); ent = readdir(dir); ent = readdir(dir); while (ent) { if (ft_match(ent->d_name, to_comp)) { new = ft_strjoin(path, ent->d_name); stat(new, &file_stats); ft_add_node(ent->d_name, new, file_stats); } ent = readdir(dir); } ft_sort_comp_list(); closedir(dir); }
int ft_match_sub(t_regmatch *rm, int pos, t_regex *cur) { int size; if (cur->next && (size = ft_match(rm, pos, cur->next))) return (size); (void)size; (void)rm; (void)pos; (void)cur; return (1); }
// ft_bool_factor -> opt_negated_query_word // | '(' ft_bool_expr ')' static syntree *ft_bool_factor (token **lookahead, err_context context) { syntree *left = NULL; RETURN_NULL_IF_OVER_DEPTH_LIMIT(context); if ( ft_match (lookahead, TOK_LPAREN)) { left = ft_bool_expr (lookahead, context); if (!left) { gen_cond_err_msg ("Error: Invalid boolean free text expression found inside parenthesis" " inside the contains condition string", context.count); return (NULL); } // Check for matching ')'. if (ft_match (lookahead, TOK_RPAREN)) { return (left); } else { gen_cond_err_msg_s ("Error: expecting a matching ')' inside the CONTAINS condition string, found '%s'.", (*lookahead)->lexeme->contents,context.count); goto cleanup; } } else { return (opt_negated_query_word (lookahead, context)); } cleanup: cond_del (left); return (NULL); }
// ft_bool_expr_sequence -> OR ft_bool_term ft_bool_expr_sequence // | EMPTY static syntree *ft_bool_expr_sequence (token ** lookahead, syntree *left, err_context context, int *status) { int ok; syntree *right = NULL; syntree *tree = NULL; syntree *or_tree = NULL; *status = TMAN_ERROR; RETURN_NULL_IF_OVER_DEPTH_LIMIT(context); if (ft_match (lookahead, TOK_FT_OR)) { right = ft_bool_term (lookahead, context); if (right) { or_tree = ft_or_new (left, right); tree = ft_bool_expr_sequence (lookahead, or_tree, context, &ok); if (ok) { *status = TMAN_OK; return (tree); } } gen_cond_err_msg_s ("Error: expecting a boolean free text term after OR inside the CONTAINS condition string, found '%s'.", \ (*lookahead)->lexeme->contents, context.count); *status = TMAN_ERROR; goto cleanup; } // We did not find anything so return the left tree back to the caller. *status = TMAN_OK; return (left); cleanup: //cond_del (or_tree); cond_del (right); if (or_tree) { tman_free (or_tree); } ASSERT (tree == NULL); return (NULL); }
// ft_vec_spc_expr_tail -> ACCRUE <query_word> ft_vec_spc_expr_tail // | EMPTY static syntree *ft_vec_spc_expr_tail (token **lookahead, syntree *left, err_context context, int *status) { int ok; syntree *right = NULL; syntree *tree = NULL; syntree *accrue_tree = NULL; *status = TMAN_ERROR; RETURN_NULL_IF_OVER_DEPTH_LIMIT(context); if (ft_match (lookahead, TOK_FT_ACCRUE)) { right = opt_negated_query_word (lookahead, context); if (right) { accrue_tree = ft_accrue_new (left, right); tree = ft_vec_spc_expr_tail (lookahead, accrue_tree, context, &ok); if (ok) { *status = TMAN_OK; return (tree); } } gen_cond_err_msg_s ("Error: expecting query word after ACCRUE inside the CONTAINS condition string, found '%s'.",\ (*lookahead)->lexeme->contents, context.count); *status = TMAN_ERROR; goto cleanup; } // We did not find anything so return the left tree back to the caller. *status = TMAN_OK; return (left); cleanup: cond_del (right); if (accrue_tree) { tman_free (accrue_tree); } ASSERT (tree == NULL); return (NULL); }
void ft_puissance4(char *s1, char *s2) { t_tab *obj; int i; int j; obj = NULL; if ((obj = fill_obj(s1, s2, obj)) == NULL) return ; i = ft_atoi(s1); j = ft_atoi(s2); obj->count_max = i * j; welcome(obj); obj->end = 0; ft_match(obj, 0); free_tab(obj->tab); free(obj); return ; }
// opt_negated_query_word -> NOT query_word // | query_word static syntree *opt_negated_query_word (token **lookahead, err_context context) { syntree *left = NULL; RETURN_NULL_IF_OVER_DEPTH_LIMIT(context); if ( ft_match (lookahead, TOK_FT_NOT) ) { left = query_word (lookahead, context); if (left) { return (ft_not_new (left)); } else { gen_cond_err_msg ("Error: The NOT operator can only precede a word or phrase" " inside the CONTAINS condition string.", context.count); return (NULL); } } return (query_word (lookahead, context)); }
// ft_predicate -> ft_expr static syntree *ft_predicate (token **lookahead, err_context context) { syntree *left = NULL; int status = TMAN_OK; int type_expr, subtype_expr; left = ft_expr (lookahead, context); if (left == NULL) { gen_cond_err_msg ("Error: Invalid free text expression found inside the CONTAINS condition string.", context.count); return (NULL); } if (!ft_match (lookahead, TOK_SYSEND)) { gen_cond_err_msg ("Error: Invalid free text expression found inside the CONTAINS condition string.", context.count); cond_del (left); return (NULL); } #ifdef _FT_PROFILER print_tree (left, 0); #endif // Remove the stop words from the contains tree (if they are not preceeded // by + (the compulsory inclusion operator). remove_stop_words(&left); // If the condition string is only made of common words, then signal an error if (left == NULL) { logwrite("Error: empty free text expression found inside the CONTAINS condition string."); status = TMAN_ERROR; return NULL; } // If NOT nodes are not preceded or followed by WORD or PHRASE nodes, then distribute the NOT // node across the operator following or preceding it. distribute_NOT_node(&left); // Form the basic predicates and typecheck, simultaneously. // A basic predicate is formed from a sub-tree of the ft_expr syntax tree. // It contains query-words (may be preceded by NOT) connected by only one of // operators AND, OR or ACCRUE. // If the result returned is not FT_BASIC_PRED_TYPE, we need to form a basic predicate for the whole syntax tree. if ((type_expr = form_basic_preds_and_typecheck (left, &status, &subtype_expr)) == FT_BASIC_PRED_TYPE) { ft_basic_pred *new_left; ASSERT (status == TMAN_OK); if (subtype_expr == FT_NOT_TYPE) { logwrite ("Error: in CONTAINS condition string, you must combine a negated word with at least" " one non-negated word/phrase using AND."); status = TMAN_ERROR; } else { new_left = ft_basic_pred_new (&left, subtype_expr, &status); left = (syntree *) new_left; } } if (status == TMAN_ERROR) { cond_del (left); return (NULL); } #ifdef _FT_PROFILER print_tree (left, 0); #endif return (ft_predicate_new (left, NULL)); }