Beispiel #1
0
int cmd_process(int flag, int argc, char * const argv[],
		int *repeatable, unsigned long *ticks)
{
	enum command_ret_t rc = CMD_RET_SUCCESS;
	cmd_tbl_t *cmdtp;

	/* Look up command in command table */
	cmdtp = find_cmd(argv[0]);
	if (cmdtp == NULL) {
		printf("Unknown command '%s' - try 'help'\n", argv[0]);
		return 1;
	}

	/* found - check max args */
	if (argc > cmdtp->maxargs)
		rc = CMD_RET_USAGE;

	/* If OK so far, then do the command */
	if (!rc) {
		if (ticks)
			; //*ticks = get_timer(0);
		rc = cmd_call(cmdtp, flag, argc, argv);
		if (ticks)
			; //*ticks = get_timer(*ticks);
		if (!(cmdtp->info & CMD_INFO_REPEATABLE))
			*repeatable = 0;
	}
	if (rc == CMD_RET_USAGE)
		cmd_usage(cmdtp);

	return rc;
}
Beispiel #2
0
enum command_ret_t cmd_process(int flag, int argc, char * const argv[],
			       int *repeatable, ulong *ticks)
{
	enum command_ret_t rc = CMD_RET_SUCCESS;
	cmd_tbl_t *cmdtp;

#if defined(CONFIG_SYS_XTRACE)
	char *xtrace;

	xtrace = env_get("xtrace");
	if (xtrace) {
		puts("+");
		for (int i = 0; i < argc; i++) {
			puts(" ");
			puts(argv[i]);
		}
		puts("\n");
	}
#endif

	/* Look up command in command table */
	cmdtp = find_cmd(argv[0]);
	if (cmdtp == NULL) {
		printf("Unknown command '%s' - try 'help'\n", argv[0]);
		return 1;
	}

	/* found - check max args */
	if (argc > cmdtp->maxargs)
		rc = CMD_RET_USAGE;

#if defined(CONFIG_CMD_BOOTD)
	/* avoid "bootd" recursion */
	else if (cmdtp->cmd == do_bootd) {
		if (flag & CMD_FLAG_BOOTD) {
			puts("'bootd' recursion detected\n");
			rc = CMD_RET_FAILURE;
		} else {
			flag |= CMD_FLAG_BOOTD;
		}
	}
#endif

	/* If OK so far, then do the command */
	if (!rc) {
		int newrep;

		if (ticks)
			*ticks = get_timer(0);
		rc = cmd_call(cmdtp, flag, argc, argv, &newrep);
		if (ticks)
			*ticks = get_timer(*ticks);
		*repeatable &= newrep;
	}
	if (rc == CMD_RET_USAGE)
		rc = cmd_usage(cmdtp);
	return rc;
}
Beispiel #3
0
enum command_ret_t cmd_process(int flag, int argc, char * const argv[],
			       int *repeatable)
{
	enum command_ret_t rc = CMD_RET_SUCCESS;
	cmd_tbl_t *cmdtp;

    WATCHDOG_RESET(); //add by QWB
	/* Look up command in command table */
	cmdtp = find_cmd(argv[0]);
	if (cmdtp == NULL) {
		printf("Unknown command '%s' - try 'help'\n", argv[0]);
		return 1;
	}

	/* found - check max args */
	if (argc > cmdtp->maxargs)
		rc = CMD_RET_USAGE;

#if defined(CONFIG_CMD_BOOTD)
	/* avoid "bootd" recursion */
	else if (cmdtp->cmd == do_bootd) {
		if (flag & CMD_FLAG_BOOTD) {
			puts("'bootd' recursion detected\n");
			rc = CMD_RET_FAILURE;
		} else {
			flag |= CMD_FLAG_BOOTD;
		}
	}
#endif

	/* If OK so far, then do the command */
	if (!rc) {
		rc = cmd_call(cmdtp, flag, argc, argv);
		*repeatable &= cmdtp->repeatable;
	}
	if (rc == CMD_RET_USAGE)
		rc = cmd_usage(cmdtp);
	return rc;
}
Beispiel #4
0
/*
	execute command
*/
EXPORT	INT	exec_cmd(B *cmd)
{
	INT	ac;
	B	*av[N_ARGS];

	ac = setup_param(cmd, av);
	if (ac < 1) return 0;

	if (strcmp(av[0], "date") == 0) {
		cmd_date(ac, av);
	} else if (strcmp(av[0], "attach") == 0) {
		cmd_attach(ac, av);
	} else if (strcmp(av[0], "detach") == 0) {
		cmd_detach(ac, av);
	} else if (strcmp(av[0], "mkdir") == 0) {
		cmd_mkdir(ac, av);
	} else if (strcmp(av[0], "rmdir") == 0) {
		cmd_rmdir(ac, av);
	} else if (strcmp(av[0], "pwd") == 0) {
		cmd_pwd(ac, av);
	} else if (strcmp(av[0], "cd") == 0) {
		cmd_cd(ac, av);
	} else if (strcmp(av[0], "rm") == 0) {
		cmd_rm(ac, av);
	} else if (strcmp(av[0], "mv") == 0) {
		cmd_mv(ac, av);
	} else if (strcmp(av[0], "ls") == 0) {
		cmd_ls(ac, av);
	} else if (strcmp(av[0], "tp") == 0 || strcmp(av[0], "tpx") == 0) {
		cmd_tp(ac, av);
	} else if (strcmp(av[0], "cp") == 0) {
		cmd_cp(ac, av);
	} else if (strcmp(av[0], "trunc") == 0) {
		cmd_trunc(ac, av);
	} else if (strcmp(av[0], "df") == 0) {
		cmd_df(ac, av);
	} else if (strcmp(av[0], "sync") == 0) {
		cmd_sync(ac, av);
	} else if (strcmp(av[0], "chmod") == 0) {
		cmd_chmod(ac, av);
	} else if (strcmp(av[0], "ref") == 0) {
		cmd_ref(ac, av);
	} else if (strcmp(av[0], "load") == 0) {
		cmd_load(ac, av);
	} else if (strcmp(av[0], "loadspg") == 0) {
		cmd_loadspg(ac, av);
	} else if (strcmp(av[0], "unload") == 0) {
		cmd_unload(ac, av);
	} else if (strcmp(av[0], "call") == 0) {
		cmd_call(ac, av);
	} else if (strncmp(av[0], "?", 1) == 0) {
		P("date     [y m d [h m s]]\n");
		P("attach   devnm connm\n");
		P("detach   connm\n");
		P("cd       dir\n");
		P("pwd      \n");
		P("ls       [-t][-l][dir]\n");
		P("mkdir    dir [mode]\n");
		P("rmdir    dir\n");
		P("rm       path\n");
		P("mv       o-path n-path\n");
		P("trunc    path len\n");
		P("df       path\n");
		P("sync     [path [d]]\n");
		P("chmod    path mode\n");
		P("tp       path [ofs len]\n");
		P("tpx      path [ofs len]\n");
		P("cp       s-path d-path/dir [wofs [wlen]]\n");
		P("ref      [item]\n");
		P("call     addr [p1 p2 p3]\n");
		P("load     path\n");
		P("loadspg  path [arg ...]\n");
		P("unload   progid\n");
#ifdef	NET_SAMPLE
		P("net      execute network sample\n");

	} else if (strcmp(av[0], "net") == 0) {
IMPORT	void	net_test(void);
		net_test();
#endif
	} else {
		return 0;
	}
	return 1;
}
Beispiel #5
0
void gera(FILE *f, void **code, funcp *entry){
    int c, i,j;
    int line = 1, 
        idx = 0, 
        funcIdx = -1;
    unsigned char * func[MAX_FUNCS];
    int declaredVars[MAX_FUNCS][MAX_VARS];
    unsigned char *codigo = (unsigned char *) malloc (TAM_COD);
    *code = codigo;

    for(i=0;i<MAX_FUNCS;i++)
         for(j=0;j<MAX_VARS;j++)
            declaredVars[i][j]=0;

    while ((c = fgetc(f)) != EOF) {
    	switch (c){
        	case 'f': {  /* function */
            	char c0;
                if (fscanf(f, "unction%c", &c0) != 1) 
                        error("comando invalido", line);
                printf("function\n");
                cmd_func(func,&funcIdx,codigo,&idx);
                break;
    		}
            case 'e': {  /* end */
                fscanf(f, "nd");
                printf("end\n");
                cmd_end(codigo,&idx);
                break;
            }
            case 'v': 
            case 'p': {  /* atribuicao */
                int i0;
                char v0 = c, c0;

                if (fscanf(f, "%d = %c", &i0, &c0) != 2)
                        error("comando invalido", line);

                if (c0 == 'c') { /* call */
                	int fc, i1;
                    char v1;
                    if (fscanf(f, "all %d %c%d", &fc, &v1, &i1) != 3) 
                        error("comando invalido", line);
                    printf("%c%d = call %d %c%d\n", v0, i0, fc, v1, i1);
                    cmd_call(fc,v1,i1,func,codigo,&idx);
                }
                else { /* operacao aritmetica */
              		int i1, i2;
                    char v1 = c0, v2, op;
                    if (fscanf(f, "%d %c %c%d", &i1, &op, &v2, &i2) != 4)
                        error("comando invalido", line);
                    printf("%c%d = %c%d %c %c%d\n", v0, i0, v1, i1, op, v2, i2);
                    cmd_op(v1,i1,op,v2,i2,codigo,&idx,declaredVars,line,funcIdx);
                }
                cmd_atr(v0,i0,codigo,&idx,declaredVars,funcIdx);
                break;
            }
            case 'r': {  /* ret */
                int i0, i1;
                char v0, v1;
                if (fscanf(f, "et? %c%d %c%d", &v0, &i0, &v1, &i1) != 4)
                    error("comando invalido", line);
                printf("ret? %c%d %c%d\n", v0, i0, v1, i1);
                cmd_ret(v0,i0,v1,i1,codigo,&idx,line);
                break;
            }
            default: 
                error("comando desconhecido", line);
        }
        line++;        
        fscanf(f, " ");
    }

    (*entry) = (funcp) func[funcIdx];
}