Пример #1
0
// phrase_word_list -> word+
static syntree *phrase_word_list (token ** lookahead, err_context context)
{
	syntree *left = NULL;
	List *word_list = NULL;
	RETURN_NULL_IF_OVER_DEPTH_LIMIT(context);

	// It has already been tested that the lookahead is a word node.
	left = (syntree *) ft_word_new ((*lookahead)->lexeme->contents);
	advance (lookahead);

	// If more than one word is present, form the list of all the words and 
	// make a phrase.
	if (ft_test (lookahead, TOK_FT_WORD))
	{
		int num_words = 0;
		word_list = List_new ();
		// Add the word already parsed.
		List_insertElement (word_list, left);
		num_words++;
		// Add subsequent words.
		do
		{
			left = (syntree *) ft_word_new ((*lookahead)->lexeme->contents);
			List_insertElement (word_list, left);
			num_words++;
			advance (lookahead);
		} while (ft_test(lookahead, TOK_FT_WORD));

		return ((syntree *)ft_phrase_new (word_list, num_words));
	}

	// Otherwise return a word node.
	return (left);
}
Пример #2
0
int				ft_executable(char *line, char **env)
{
	struct stat		*buf;
	char			*path;
	char			**paths;
	char			**exe;
	int				i;

	i = -1;
	if (!(buf = (struct stat *)gmalloc(sizeof(*buf))))
		return (-1);
	exe = ft_strsplim(line);
	while (env[++i] && ft_strncmp(env[i], "PATH=", 5))
		;
	path = env[i] ? ft_strdup(&env[i][5]) : NULL;
	paths = env[i] ? ft_strsplit(path, ':') : NULL;
	if (path && ft_test(paths, exe, env) != 1)
	{
		gfree((void *)path);
		if (lstat(exe[0], buf) == 0 && buf->st_mode & S_IXUSR)
			return (ft_execution(line, exe, env, buf));
		gfree((void *)buf);
		return (-1 + 0 * (write(2, line, ft_strlen(line))
						+ write(2, ": command not found or permission denied\n"
								, 41)));
	}
	return (0);
}
Пример #3
0
// phrase -> '"' phrase_word_list '"'
static syntree *phrase (token ** lookahead, err_context context)
{
	syntree *tree = NULL;
	token *phrase_head = NULL, *temp = NULL;
	RETURN_NULL_IF_OVER_DEPTH_LIMIT(context);

	// Tokenize the phrase lexeme into words.
	phrase_head = ft_phrase_lex ((*lookahead)->lexeme->contents);

	ASSERT (phrase_head);

	advance (lookahead);
	temp = phrase_head->next;

	if (ft_test (&temp, TOK_FT_WORD))
	{	
		tree = phrase_word_list (&temp, context);
		ASSERT (tree);
		
		free_tokens (phrase_head);
		return (tree);
	}
	else
	{
		gen_cond_err_msg ("Error: Malformed phrase inside the CONTAINS condition string. A phrase should"
						  " contain one or more words separated by whitespace"
						  " enclosed inside double quotes.", context.count);
		goto error;
	}

error:
	free_tokens (phrase_head);
	return (NULL);
}
Пример #4
0
// This routine is used specially for free text token matching
static int ft_match (token **lookahead, enum tokens value)
{
    if (ft_test (lookahead, value))
    {
        advance (lookahead);
        return (1);
    }

    return (0);
}
Пример #5
0
// query_word -> word | phrase
static syntree *query_word (token **lookahead, err_context context)
{
	syntree *node = NULL;
	RETURN_NULL_IF_OVER_DEPTH_LIMIT(context);

	if (ft_test (lookahead, TOK_FT_PHRASE))
	{
		return (phrase (lookahead, context));
	}
	else if (ft_test (lookahead, TOK_FT_WORD))
	{
		node = (syntree *) ft_word_new ((*lookahead)->lexeme->contents);
		if (node)
		{
			advance (lookahead);
		}
	}

	return (node);
}
Пример #6
0
int	main(void)
{
	char *buffer;

	buffer = ft_buffer();
	if (!buffer)
	{
		ft_putstr("Erreur de Malloc");
		return (0);
	}
	ft_test(buffer);
	return (0);
}
Пример #7
0
int		ft_str_is_alpha(char *str)
{
	int cpt;

	cpt = 0;
	while (str[cpt] != '\0')
	{
		if (!(ft_test(str[cpt])))
		{
			return (0);
		}
		cpt++;
	}
	return (1);
}
Пример #8
0
t_l			*ft_read(char **argv)
{
	t_l		*lst;
	int		x;

	x = 0;
	if ((lst = (t_l*)malloc(sizeof(t_l))) == NULL)
		return (NULL);
	while (argv[x + 1])
	{
		lst = ft_do_lst(ft_test(argv[x + 1]), x, lst);
		x++;
	}
	return (lst);
}
Пример #9
0
int		key_hook(int keycode, t_env *e)
{
	if (keycode == MK_C)
		mlx_clear_window(e->mlx, e->win);
	else if (keycode == MK_ESC)
		exit(0);
	else if (keycode == MK_Z)
		ft_test(e);
	else if (keycode == MK_H)
		draw(e);
	else if (keycode == MK_N)
	{
		printf("e->xn\t%d\t\te->yn\t%d\ne->xo\t%d\t\te->yo\t%d\n", e->xn, e->yn, e->xo[e->inc - 1], e->yo[e->inc - 1]);
	}
	return (0);
}
Пример #10
0
// This routine is called only once. After that, the boolean and VS predicates are handled separately.
// ft_expr -> ft_bool_term ft_bool_expr_sequence
//			| query_word ACCRUE ft_vec_spc_expr_tail
static syntree *ft_expr (token **lookahead, err_context context)
{
	int status;
	syntree *left = NULL;
	syntree *node = NULL;

	RETURN_NULL_IF_OVER_DEPTH_LIMIT(context);

	left = ft_bool_term (lookahead, context);

	if (left)
	{
		// If the left term is a query word (may be negated) and the next token is ACCRUE, parse a vector space condition
		// else parse a boolean condition.

		switch (left->type)
		{
		case FT_WORD_TYPE:
		case FT_PHRASE_TYPE:
		case FT_NOT_TYPE:
			if (ft_test (lookahead, TOK_FT_ACCRUE))
			{
				node = ft_vec_spc_expr_tail (lookahead, left, context, &status);
			}
			else
			{
				node = ft_bool_expr_sequence (lookahead, left, context, &status);
			}
			break;
		default:
			node = ft_bool_expr_sequence (lookahead, left, context, &status);
			break;
		}

		if (status == TMAN_OK)
		{
			return (node);
		}
	}

	cond_del (left);
	ASSERT (node == NULL);

	return (NULL);

}
Пример #11
0
static int		ft_pourcent_car(va_list ap, char *str, int car)
{
	int		len;
	int		len2;

	len = 0;
	len2 = 0;
	if (str[car + 1] == '%')
		ft_putchar(37);
	else
	{
		len = ft_test(ap, str, car + 1);
		if (len == -2)
			return (len);
		len2 += len;
	}
	return (len2);
}
Пример #12
0
int		main(int ac, char **av)
{
	char	**tab;
	t_copy	tab2;

	if (ac == 1 && av[0])
	{
		tab = ft_read_file();
		if (tab[0][0])
		{
			tab2 = ft_count(tab);
			ft_test(tab, tab2);
		}
	}
	else
		ft_error("No arguments needed");
	write(1, "\n", 1);
	return (0);
}
Пример #13
0
int		main(int ac, char **av, char **env)
{
	char	**myenv;
	char	*home;
	size_t	len_prompt;

	myenv = tab_dup(env);
	lvlup(&myenv);
	if (ac == 1 && av)
	{
		home = get_elem(env, "PWD=");
		prompt(home);
		len_prompt = ft_strlen(home) + 2;
		ft_test(myenv, len_prompt);
	}
	else
		ft_putendl("No arguments needed.");
	return (0);
}
Пример #14
0
static void			ft_exec(t_stack pa, t_stack pb)
{
	int				nb;

	nb = 0;
	if (ft_issort(pa, 0))
		write (1, "\n", 1);
	ft_print(pa, pb, "not", "not");
	while (!ft_issort(pa, 0))
		ft_test(pa, pb, &nb);
	if (ft_issort(pa, 0))
	{
		if (pa.opt[END] == '1' && pa.opt[VB]++ == '0')
			ft_print(pa, pb, "not", "not");
		if (pa.opt[NB] == '1')
			ft_putnbr(nb);
		ft_putstr((pa.opt[NB] == '1') ? " operations\n" : "");
		exit (0);
	}
}
Пример #15
0
char		*ft_itoa(int n)
{
	int		len;
	int		buf;
	char	*ret;

	len = (n < 0) ? 1 : 0;
	buf = n;
	while (n /= 10)
		len++;
	while (n <= -10)
		len++;
	ret = ft_test(n, len);
	if (!ret)
		return (NULL);
	while (buf >= 10 || buf <= -10)
	{
		ret[len--] = (buf < 0) ? -(buf % 10) + '0' : buf % 10 + '0';
		buf /= 10;
	}
	ret[0] = (buf < 0) ? '-' : buf + '0';
	ret[1] = (buf < 0) ? -buf + '0' : ret[1];
	return (ret);
}