Exemple #1
0
char* print_prompt(char string[]){

        char **token_array;
        int status;
        token_array = (char **)malloc(1024*sizeof(char *));
        status = parse_ps1(string, token_array);
	printf("status : %d\n", status);
        if ( status == 0 )
                return NULL;
        int pos=0;
        char* ret_str = (char *)malloc(100*sizeof(char ));
	//char *pd;
	int ret_pos = 0;
	int count = 0;
        while( token_array[pos] != NULL )
        {       /*Out of Bound error in getcwd system call, running fine on local machine
                if ((token_array[pos][0] == 'w') && (token_array[pos][1] == '\0')){
                        pd = print_dir();
			printf("%s\n", pd);
			 while(pd[count] != '\0') {
                        ret_str[ret_pos++] = pd[count];
                        count++;
                	}
			count = 0;
                        pos++;
			free(pd);
                        continue;
                } */
                //Implementation dependent on getlogin and gethostname,will be done at later stages.
               /* if ((token_array[pos][0] == 'h') && (token_array[pos][1] == '\0')) {
                        gethostname(buffer,10240);
                        printf("%s",buffer);
                        pos++;
                        continue;
                
                if ((token_array[pos][0] == 'u') && (token_array[pos][1] == '\0')){
                        printf("%s", getlogin());
                        pos++;
                        continue;
                } */
		while(token_array[pos][count] != '\0') {
			ret_str[ret_pos++] = token_array[pos][count];
			count++;
		}
		count=0;
		free(token_array[pos]);
		pos++;
		
        }
	ret_str[ret_pos++] = '$';
	ret_str[ret_pos] = '\0';


        free(token_array);

	return ret_str;
}
Exemple #2
0
t_cmd	*sh_wait_new_commande(t_env *env, t_cmd *cmd)
{
	int		ret;
	t_term	*term;
	char	buff[6];

	ret = 0;
	init_term();
	term = recup_term();
		parse_ps1(env);
	term->ps1_len = env->ps1_len;
	term->hist = add_or_clean(term->hist);
	ft_bzero(buff, 5);
	while (ft_stomp(buff, term))
	{
		ft_bzero(buff, 5);
		ret = read(term->fd, buff, 5);
		buff[ret + 1] = '\0';
	}
	cmd = ft_parse_cmd(term->hist->buff);
	close_term();
	return (cmd);
}