Beispiel #1
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() */
Beispiel #2
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


}
Beispiel #3
0
void shell_loop(void)
{
  char *line;
  char **args;
  int status;

  char buffer[1024];
  printf("> ");
  fflush(stdout);
  while (fgets(buffer, 1024, stdin) != NULL){ 
    while (status){
    printf("> ");
    line = shell_read_line();
    args = tokenify(line);
    status = shell_execute(args);

    free(line);
    free(args);
  } 
 }
}
Beispiel #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;
}
Beispiel #5
0
int
shell_prompt (GPParams *params)
{
	int x;
	char cmd[1024], arg[1024], *line;

	/* The stupid readline functions need that global variable. */
	p = params;

	if (!getcwd (cwd, 1023))
		strcpy (cwd, "./");

#ifdef HAVE_RL
	rl_attempted_completion_function = shell_completion_function;
	rl_completion_append_character = '\0';
#endif

	while (!shell_done && !glob_cancel) {
		line = shell_read_line ();
		if (line ==  NULL) {
			/* quit shell on EOF or input error */
			printf("\n");
			fflush(stdout);
			break;
		}
#ifdef HAVE_UNISTD_H
		if (!isatty(fileno(stdin))) {
			/* if non-interactive input, the command has not been
			 * printed yet, so we do that here */
			printf("%s\n", line);
			fflush(stdout);
		}
#endif

		/* If we don't have any command, start from the beginning */
		if (shell_arg_count (line) <= 0) {
			free (line);
			continue;
		}

		shell_arg (line, 0, cmd);
		strcpy (arg, &line[strlen (cmd)]);
		free (line);

		/* Search the command */
		for (x = 0; func[x].function; x++)
			if (!strcmp (cmd, func[x].command))
				break;
		if (!func[x].function) {
			cli_error_print (_("Invalid command."));
			continue;
		}

		/*
		 * If the command requires an argument, complain if this
		 * argument is not given.
		 */
		if (func[x].arg_required && !shell_arg_count (arg)) {
			printf (_("The command '%s' requires "
				  "an argument."), cmd);
			putchar ('\n');
			continue;
		}

		/* Execute the command */
		CHECK_CONT (func[x].function (p->camera, arg));
	}

	return (GP_OK);
}