Beispiel #1
0
int msh_exec(char *cmd, rt_size_t length)
{
    int cmd_ret;

    /* strim the beginning of command */
    while (*cmd  == ' ' || *cmd == '\t')
    {
        cmd++;
        length--;
    }

    if (length == 0)
        return 0;

    /* Exec sequence:
     * 1. built-in command
     * 2. module(if enabled)
     * 3. chdir to the directry(if possible)
     */
    if (_msh_exec_cmd(cmd, length, &cmd_ret) == 0)
    {
        return cmd_ret;
    }
#ifdef RT_USING_MODULE
    if (msh_exec_module(cmd, length) == 0)
    {
        return 0;
    }
#endif

#if defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR)
    if (msh_exec_script(cmd, length) == 0)
    {
        return 0;
    }

    /* change to this directory */
    if (chdir(cmd) == 0)
    {
        return 0;
    }
#endif

    /* truncate the cmd at the first space. */
    {
        char *tcmd;
        tcmd = cmd;
        while (*tcmd != ' ' && *tcmd != '\0')
        {
            tcmd++;
        }
        *tcmd = '\0';
    }
    rt_kprintf("%s: command not found.\n", cmd);
    return -1;
}
Beispiel #2
0
int msh_exec(char* cmd, rt_size_t length)
{
    int argc;
    char *argv[RT_FINSH_ARG_MAX];
    int cmd0_size = 0;
    cmd_function_t cmd_func;

	/* strim the beginning of command */
    while(*cmd  == ' ' || *cmd == '\t'){cmd++; length--;}
	/* find the size of first command */
    while ((cmd[cmd0_size] != ' ' && cmd[cmd0_size] != '\t') && cmd0_size < length)
        cmd0_size ++;
    if (cmd0_size == 0) return -1; /* no command found */

    /* try to get built-in command */
    cmd_func = msh_get_cmd(cmd, cmd0_size);
    if (cmd_func == RT_NULL)
    {
#ifdef RT_USING_MODULE
        msh_exec_module(cmd, length);
#else
        argv[0] = cmd;
        while(*cmd != ' ')
        {
            if (*cmd == 0) break;
            cmd++;
        }
        if (*cmd == ' ') *cmd = 0;
        rt_kprintf("%s: command not found.\n", argv[0]);
#endif
        return -1;
    }

    /* split arguments */
    memset(argv, 0x00, sizeof(argv));
    argc = msh_split(cmd, length, argv);
    if (argc == 0) return -1;

    /* exec this command */
    return cmd_func(argc, argv);
}
Beispiel #3
0
int system(const char *command)
{
    return msh_exec_module(command, rt_strlen(command));
}