Exemple #1
0
int		main(int ac, char **av, char **envp)
{
	char		*line;
	t_tree		*cmd;

	(void)ac;
	(void)av;
	line = NULL;
	g_env = sh_init_env(envp);
	sh_init_winsize(&g_winsize);
	if (!g_env)
		sh_error(1, NULL);
	sh_signal();
	while (sh_prompt(&line))
	{
		if (line && *line)
			cmd = sh_analyze(line);
		if (cmd)
			sh_exec_tree(cmd);
		if (line && line[0] != '\0')
			sh_deltree(&cmd);
		ft_strdel(&line);
	}
	return (1);
}
Exemple #2
0
int main(int argc,const string_t* argv){
	sh_prompt_update();
	//linenoiseHistorySetMaxLen(10);
	sh_initAutoComplete();
	string_t line;
	sds prcdLn;
	while((line = linenoise(sh_prompt())) != NULL) {
		linenoiseHistoryAdd(line);
		//prcdLn = sh_expand_string(line);
		sh_system(line);
		free(cPTR line);
		//sh_system(prcdLn);
		//sdsfree(prcdLn);
	}
}
/* Shell Mode */
int shell_mode()
{
	//Call interactive mode shell
	
//	printf("SHELL MODE\n");
	struct command execcmd;
	struct command* cmd = &execcmd;

	//Print the shell prompt, accept the command and check for the length
	while(1){   //strcmp(cmd->type, "exit") != 0
		cmd = sh_prompt(cmd);

		//If command length is correct, tokenize and parse the commands
		cmd = cmd_parse(cmd);
		
		char* home = getenv("HOME");
		//If no command is found in exec_args[0] then wrong command is entered
		if(cmd->opt_cnt != 0){
			if(cmd->cmd_flag == 0)
				error(4);
			else if( strcmp(cmd->type, "exit") == 0)
				exit(0);
			else if (strcmp(cmd->type, "cd") == 0)
			{
				int derror =0;
				if(cmd->opt_cnt ==1)
					derror = chdir(home);
				else
					derror = chdir(cmd ->eargv[1]);
				if(derror <0)
					error(5);
			}
			else{
				//If command present, then parse the options
				int ret_e = exec_cmd(cmd);
				if (ret_e != 0)
					error(6);
			}
		}

	}

	return 0;
}
Exemple #4
0
int			main(int ac, char **av, char **env)
{
	if (ac != 1)
	{
		ft_dprintf(STDERR_FILENO, "shell: argument invalid: %s\n", av[1]);
		return (0);
	}
	sh_set_env(env);
	if (sh_get_term_fildes() < 0)
		return (main_minishell());
	if (sh_set_term() < 0)
		return (main_input());
	while (42)
	{
		if (sh_prompt() < 0)
		{
			ft_free_tab(g_env);
			sh_reset_term();
			return (0);
		}
	}
	return (0);
}
Exemple #5
0
int			main(int argc, const char **argv)
{
	t_sh_env		env;
	int				error;
	t_ckbt			*tree;
	t_cks			line;

	if (sh_init_env(&env, argc, argv) == 0)
	{
		g_sh_env = &env;
		while ((sh_prompt(&env), (line = cks_get_line(0))) != NULL)
		{
			tree = ckbt_new(t_sh_command);
			error = sh_parse(line, tree);
			if (!error)
				sh_exec(&env, tree);
			else
				printf("42sh: syntax error\n");
			cks_free(line);
		}
	}
	return (0);
}
Exemple #6
0
int main(int argc, char** argv, char** env) {
    
    static struct option long_options[] = {
        { "command", required_argument, NULL, 'c'},
        { "help", no_argument, NULL, 'h'},
        { "version", no_argument, NULL, 'v'},
        { NULL, 0, NULL, 0 }
    };


    
    char* command = NULL;

    int c, idx;
    while((c = getopt_long(argc, argv, "c:hv", long_options, &idx)) != -1) {
        switch(c) {
            case 'c':
                if(strcmp(optarg, "-c") != 0)
                    command = strdup(optarg);
                else
                    command = strdup(argv[optind]);
                break;
            case 'v':
                show_version(argc, argv);
                break;
            case 'h':
            case '?':
                show_usage(argc, argv);
                break;
            default:
                abort();
        }
    }


    char buf[BUFSIZ];
    setenv("PWD", getcwd(buf, BUFSIZ), 1);


    if(command)
        sh_exec(command);

    
    setsid();
    sh_reset_tty();



    char* user = getuser();
    char* host = gethost();


    int e = 0;
    do {
        char line[BUFSIZ];
        memset(line, 0, sizeof(line));

        if(!sh_prompt(line, user, host, e))
            continue;
        
        sh_history_add(line);
        e = sh_exec(line);
    } while(1);

    return 0;
}