int sh_execute(char **args, int argc)
{
    int i;
    char ***cmd;
    int cmdn;
    if(argc > 2){
        // printf("%d\n", argc);
        cmd = split_multiple(argc, args, &cmdn);
        return fork_pipes(cmdn, cmd);
    }

    if (args[0] == NULL) {
        // An empty command was entered.
        return 1;
    }

    for (i = 0; i < sh_num_builtins(); i++) {
        if (strcmp(args[0], builtin_str[i]) == 0) {
            return (*builtin_func[i])(args);
        }
    }


    return sh_launch(args);
}
Example #2
0
File: shell.c Project: ak9999/yash
int sh_execute(char ** args)
{
    if(args[0] == NULL) // Empty command.
    {
        return 1;
    }
    return sh_launch(args);
}
Example #3
0
int				sh_exec(t_info *info, char **env, char **args)
{
	int			i;

	if (info->args[0] == NULL)
		return (1);
	i = 0;
	while (i < sh_nb_builtin())
	{
		if (ft_strcmp(info->args[0], g_builtin_str[i]) == 0)
			return ((*g_builtin_fct[i])(info, env, &args[0]));
		i++;
	}
	return (sh_launch(info, env, &args[0]));
}
Example #4
0
File: shell.c Project: ak9999/yash
// Our shell main loop
void sh_loop(void)
{
    char * line;
    char ** args;
    int status;

    do
    {
        char hostname[HOST_NAME_MAX + 1];
		char pathname[PATH_MAX + 1];
		struct passwd * p = getpwuid(getuid());
		if(p == NULL) // If we can't get the user_id we should quit.
		{
			fprintf(stderr, "Could not get username.\n");
			exit(EXIT_FAILURE);
		}

		// Set process effective ID to user ID.
		setreuid(getuid(), getuid());
		gethostname(hostname, sizeof(hostname)); // Get the hostname.
		char * username = p->pw_name;
		char * current_dir = getcwd(pathname, sizeof(pathname));
		/* Print prompt in the format:
		 * [username@hostname current_working_directory] %
		 */
        // If the current working directory is the user's home directory
        // we should just print ~ to let them know they are home.
        if(strcmp(current_dir, p->pw_dir) == 0)
        {
            print_userhost(username, hostname, "~");
        }
        else { print_userhost(username, hostname, current_dir); }
        line = sh_get_cmd();
        args = sh_tokenize_cmd(line);
        status = sh_launch(args);

        // Free the memory we used.
        free(line);
        free(args);
    } while(status);
}