<commit_before>/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   history.c                                          :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: sle-guil <<EMAIL>>          +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2015/03/05 17:43:17 by sle-guil          #+#    #+#             */
/*   Updated: 2015/03/05 18:41:21 by sle-guil         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "minishell.h"

/*!
 *	@name : History
 *	@brief : Manage the list of command enter by the user into the shell
 *	@param : A string (can be NULL) and an action defined in minishell.h
 *	@return : NULL if the function is called to save a new entry.
 *				else, it returns the ligne pointed by indice.
 *
 *	H_SAVE :		Copy the string in line into a new element.
 *	H_RESET :		Set the indice ptr to the begining of lst.
 */
char	*history(char const *line, int action)
{
	static t_list	*lst = NULL;
	static t_list	*indice = NULL;
	char			*ret;

	ret = NULL;
	if (action == H_SAVE)
		ft_lstadd(&lst, ft_lstnew(line, ft_strlen(line) + 1));
	if (action == H_RESET || action == H_SAVE)
		indice = lst;
	return (ret);
}<commit_msg>history update : no empty line stored<commit_after>/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   history.c                                          :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: sle-guil <<EMAIL>.fr>          +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2015/03/05 17:43:17 by sle-guil          #+#    #+#             */
/*   Updated: 2015/03/11 17:47:40 by sle-guil         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "minishell.h"

/*!
 *	@name : History
 *	@brief : Manage the list of command enter by the user into the shell
 *	@param : A string (can be NULL) and an action defined in minishell.h
 *	@return : NULL if the function is called to save a new entry.
 *				else, it returns the ligne pointed by indice.
 *
 *	H_SAVE :		Copy the string in line into a new element.
 *	H_RESET :		Set the indice ptr to the begining of lst.
 */

int		st_testempty(char const *s)
{
	while (*s)
	{
		if (!ft_isspace(*s))
			return (1);
		s++;
	}
	return (0);
}

char	*history(char const *line, int action)
{
	static t_list	*lst = NULL;
	static t_list	*indice = NULL;
	char			*ret;

	ret = NULL;
	if (action == H_SAVE && st_testempty(line))
		ft_lstadd(&lst, ft_lstnew(&line, sizeof(char *)));
	if (action == H_RESET || action == H_SAVE)
		indice = lst;
	return (ret);
}
{'fraction_non_alphanumeric': 0.22326674500587543, 'fraction_numerical': 0.017332549941245595, 'mean_word_length': 1.3353909465020577, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5781736', 'n_tokens_mistral': 1026, 'n_tokens_neox': 946, 'n_words': 256}