Esempio n. 1
0
static void initialize_process_state(void)
{
    if(-1U != process_state.cwd_length) return;
    update_cwd();

    const char *root_filter = getenv(ENVVARS_PREFIX "ROOT_FILTER");
    ASSERT(root_filter);

    unsigned len = strlen(root_filter);
    ASSERT(len < sizeof process_state.root_filter);
    memcpy(process_state.root_filter, root_filter, len);
    if(root_filter[len] == '/') {
        len--;
    }
    ASSERT(len < sizeof process_state.root_filter);
    process_state.root_filter[len] = 0;
    process_state.root_filter_length = len;
}
Esempio n. 2
0
int cmdloop(void)
{
    char line[128];

    update_cwd();
    
    while (1) {
	printf("cmd> "); fflush(stdout);
	if (fgets(line, sizeof(line), stdin) == NULL)
	    break;

	if (!isatty(0))
	    printf("%s", line);

	if (line[0] == '#')	/* comment lines */
	    continue;
	
	char *args[10];
	int i, nargs = split(line, args, 10, " \t\n");

	if (nargs == 0)
	    continue;
	if (!strcmp(args[0], "quit") || !strcmp(args[0], "exit"))
	    break;
	if (!strcmp(args[0], "help")) {
	    for (i = 0; cmds[i].name != NULL; i++)
		printf("%s\n", cmds[i].help);
	    continue;
	}
	for (i = 0; cmds[i].name != NULL; i++) 
	    if (!strcmp(args[0], cmds[i].name) && nargs == cmds[i].nargs+1) 
		break;
	if (cmds[i].name == NULL) {
	    if (nargs > 0)
		printf("bad command: %s\n", args[0]);
	}
	else {
	    int err = cmds[i].f(&args[1]);
	    if (err != 0)
		printf("error: %s\n", strerror(-err));
	}
    }
    return 0;
}
Esempio n. 3
0
int do_cd(char *argv[])
{
    char *dir = argv[0];
    int i, nnames;
    char *names[10];
    
    if (!strcmp(dir, "..")) {
	if (depth > 0)
	    depth--;
    }
    else {
	if (dir[0] == '/')
	    depth = 0;
	nnames = split(dir, names, 10, "/");
	for (i = 0; i < nnames; i++, depth++) 
	    strcpy(paths[depth], names[i]);
    }

    update_cwd();
    return 0;
}