Ejemplo n.º 1
0
void shell_loop(void)
{
#ifdef READLINE

    char* input;// shell_prompt[100];
    char **args;
    // Configure readline to auto-complete paths when the tab key is hit.
    rl_bind_key('\t', rl_complete);
    rl_attempted_completion_function = command_completion;

    printf("Bienvenue dans le simulateur MIPS32. N'hésitez pas à utiliser la commande help.\n");
    uint8_t status = 0;
    do {
        input = readline("simips > ");
        if (!input)
            break;
        if (strcmp(input, "") != 0) {
            add_history(input);
        }
        args = shell_split_line(input);
        status = shell_exec(args);
        if (status != OK && status != EMPTY_LINE) {
            printf("%s\n", err_msgs[status]);
        }

        free(input);
        free(args);
    } while (status != QUIT);
    clear_history();
#else
    char *line;
    char **args;

    printf("Bienvenue dans le simulateur MIPS32. N'hésitez pas à utiliser la commande help.\n");
    uint8_t status = 0;
    do {
        printf("simips > ");
        line = shell_read_line();
        args = shell_split_line(line);
        status = shell_exec(args);
        if (status != OK) {
            printf("%s\n", err_msgs[status]);
        }
        free(line);
        free(args);
    } while (status != QUIT);
#endif


}
Ejemplo n.º 2
0
void shell_loop
    (
    void
    )
{
    // Local variables
    char*   line;
    char**  args;
    int     status;
    char    cwd[SHELL_CWD_BUFFER_SIZE];
    char*   printable_cwd;

    do
    {
        // Display the prompt
        getcwd( cwd, sizeof( cwd ) );
        printable_cwd = strrchr( cwd, '/' );
        if( '/' == printable_cwd[0] )
        {
            printable_cwd++;
        }
        printf( "%s::%s> ", SHELL_NAME, printable_cwd );

        line    = shell_read_line();
        args    = shell_split_line( line );
        status  = shell_execute( args );

        free( line );
        free( args );
    }   while( status );

} /* shell_loop() */
Ejemplo n.º 3
0
void shell_main()
{
    char line[SHELL_LINE_MAX_LEN + 1] = { '\0' };

    puts(SHELL_PROMPT "/> ");    

    size_t n = getline(line, SHELL_LINE_MAX_LEN+1); 
    line[n-1] = '\0'; // remove '\r'

#ifdef DEBUG_SHELL
    debug_printf("read %u characters from command line\r\n", n);
    debug_printf("\tline = \"%s\"\r\n", line);
#endif

    if (n > 1) {
        char* argv[SHELL_ARGS_MAX_NB] = { NULL };

        uint8_t argc = shell_split_line(line, argv);

        shell_execute(argc, argv);
    }
}
Ejemplo n.º 4
0
int shell_main(Directory* dir_serv) {
    directory_service = dir_serv;

    fd_init();

    char * line, *cwd;
    char ** token;

    fprintf(stderr, "            FOX Shell Ver 0.000001\n");
    fprintf(stderr, "    built in commands:\n");
    fprintf(stderr, "        ");
    for (int i = 0; i < SH_BUILTIN_COUNT - 1; i++)
    {
        fprintf(stderr, "%s,", builtin_cmds_str[i]);
    }
    fprintf(stderr, "%s\n", builtin_cmds_str[SH_BUILTIN_COUNT - 1]);
    fprintf(stderr, "\n");

    int re = 1;

    while (re) {
        cwd = getcwd(NULL, 0);
        if (cwd == NULL) {
            ERR_ALLO;
        }
        printf("%s $ ", cwd);
        free(cwd);

        line = shell_read_line();
        token = shell_split_line(line);
        re = shell_exec(token);

        free(token);
        free(line);
    }
    return 0;
}