Ejemplo n.º 1
0
static int _msh_exec_cmd(char *cmd, rt_size_t length, int *retp)
{
    int argc;
    int cmd0_size = 0;
    cmd_function_t cmd_func;
    char *argv[RT_FINSH_ARG_MAX];

    RT_ASSERT(cmd);
    RT_ASSERT(retp);

    /* find the size of first command */
    while ((cmd[cmd0_size] != ' ' && cmd[cmd0_size] != '\t') && cmd0_size < length)
        cmd0_size ++;
    if (cmd0_size == 0)
        return -RT_ERROR;

    cmd_func = msh_get_cmd(cmd, cmd0_size);
    if (cmd_func == RT_NULL)
        return -RT_ERROR;

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

    /* exec this command */
    *retp = cmd_func(argc, argv);
    return 0;
}
Ejemplo n.º 2
0
static int cmd_proc(void)
{
    sys_sh_proc_t cmd_func;

    cmd_func = cmd_find(cmd_arg[0]);
    
    return cmd_func(cmd_arg_num, cmd_arg);
}
Ejemplo n.º 3
0
void
cmd_show_list (struct cmd_list_element *list, int from_tty, const char *prefix)
{
  struct cleanup *showlist_chain;
  struct ui_out *uiout = current_uiout;

  showlist_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "showlist");
  for (; list != NULL; list = list->next)
    {
      /* If we find a prefix, run its list, prefixing our output by its
         prefix (with "show " skipped).  */
      if (list->prefixlist && !list->abbrev_flag)
	{
	  struct cleanup *optionlist_chain
	    = make_cleanup_ui_out_tuple_begin_end (uiout, "optionlist");
	  char *new_prefix = strstr (list->prefixname, "show ") + 5;

	  if (ui_out_is_mi_like_p (uiout))
	    ui_out_field_string (uiout, "prefix", new_prefix);
	  cmd_show_list (*list->prefixlist, from_tty, new_prefix);
	  /* Close the tuple.  */
	  do_cleanups (optionlist_chain);
	}
      else
	{
	  if (list->theclass != no_set_class)
	    {
	      struct cleanup *option_chain
		= make_cleanup_ui_out_tuple_begin_end (uiout, "option");

	      ui_out_text (uiout, prefix);
	      ui_out_field_string (uiout, "name", list->name);
	      ui_out_text (uiout, ":  ");
	      if (list->type == show_cmd)
		do_show_command ((char *) NULL, from_tty, list);
	      else
		cmd_func (list, NULL, from_tty);
	      /* Close the tuple.  */
	      do_cleanups (option_chain);
	    }
	}
    }
  /* Close the tuple.  */
  do_cleanups (showlist_chain);
}
Ejemplo n.º 4
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);
}
Ejemplo n.º 5
0
int main(int argc, char **argv)
{
	const char *cmd_name;
	int (*cmd_func)(int, char **) = NULL;

	if (argc < 2) {
		fprintf(stderr, "usage: arsc <command> [options]\n");
		exit(1);
	}
	cmd_name = argv[1];

	if (!strcmp(cmd_name, "dump"))
		cmd_func = cmd_dump;
#ifndef NDEBUG
	else if (!strcmp(cmd_name, "test"))
		cmd_func = cmd_test;
#endif

	if (!cmd_func)
		die("no command");

	return cmd_func(argc - 2, argv + 2);
}
Ejemplo n.º 6
0
static
enum cmd_error_code track_untrack_pid(enum cmd_type cmd_type, const char *cmd_str,
		const char *session_name, const char *pid_string,
		int all, struct mi_writer *writer)
{
	int ret, success = 1 , i;
	enum cmd_error_code retval = CMD_SUCCESS;
	int *pid_list = NULL;
	int nr_pids;
	struct lttng_domain dom;
	struct lttng_handle *handle = NULL;
	int (*cmd_func)(struct lttng_handle *handle, int pid);

	switch (cmd_type) {
	case CMD_TRACK:
		cmd_func = lttng_track_pid;
		break;
	case CMD_UNTRACK:
		cmd_func = lttng_untrack_pid;
		break;
	default:
		ERR("Unknown command");
		retval = CMD_ERROR;
		goto end;
	}

	memset(&dom, 0, sizeof(dom));
	if (opt_kernel) {
		dom.type = LTTNG_DOMAIN_KERNEL;
	} else if (opt_userspace) {
		dom.type = LTTNG_DOMAIN_UST;
	} else {
		/* Checked by the caller. */
		assert(0);
	}

	ret = parse_pid_string(pid_string, all, &pid_list, &nr_pids);
	if (ret != CMD_SUCCESS) {
		ERR("Error parsing PID string");
		retval = CMD_ERROR;
		goto end;
	}

	handle = lttng_create_handle(session_name, &dom);
	if (handle == NULL) {
		retval = CMD_ERROR;
		goto end;
	}

	if (writer) {
		/* Open process element */
		ret = mi_lttng_targets_open(writer);
		if (ret) {
			retval = CMD_ERROR;
			goto end;
		}
	}

	for (i = 0; i < nr_pids; i++) {
		DBG("%s PID %d", cmd_str, pid_list[i]);
		ret = cmd_func(handle, pid_list[i]);
		if (ret) {
			switch (-ret) {
			case LTTNG_ERR_PID_TRACKED:
				WARN("PID %i already tracked in session %s",
						pid_list[i], session_name);
				success = 1;
				retval = CMD_SUCCESS;
				break;
			case LTTNG_ERR_PID_NOT_TRACKED:
				WARN("PID %i not tracked in session %s",
						pid_list[i], session_name);
				success = 1;
				retval = CMD_SUCCESS;
				break;
			default:
				ERR("%s", lttng_strerror(ret));
				success = 0;
				retval = CMD_ERROR;
				break;
			}
		} else {
			MSG("PID %i %sed in session %s",
					pid_list[i], cmd_str, session_name);
			success = 1;
		}

		/* Mi */
		if (writer) {
			ret = mi_lttng_pid_target(writer, pid_list[i], 1);
			if (ret) {
				retval = CMD_ERROR;
				goto end;
			}

			ret = mi_lttng_writer_write_element_bool(writer,
					mi_lttng_element_success, success);
			if (ret) {
				retval = CMD_ERROR;
				goto end;
			}

			ret = mi_lttng_writer_close_element(writer);
			if (ret) {
				retval = CMD_ERROR;
				goto end;
			}
		}
	}

	if (writer) {
		/* Close targets element */
		ret = mi_lttng_writer_close_element(writer);
		if (ret) {
			retval = CMD_ERROR;
			goto end;
		}
	}

end:
	if (handle) {
		lttng_destroy_handle(handle);
	}
	free(pid_list);
	return retval;
}
Ejemplo n.º 7
0
Archivo: cmd.c Proyecto: hsanjuan/sar2
/*
 *	Command text input prompt callback.
 *
 *	For executing a command via the text input prompt. This will
 *	parse the command value and call the appropriate SARCmd*()
 *	function.
 */
void SARCmdTextInputCB(const char *value, void *data)
{
	char *s;
	const char *arg;
	Boolean matched_command = False;
	unsigned long flags =	SAR_CMD_FLAG_VERBOSE |
				SAR_CMD_FLAG_ISUSER;
	char cmd[SAR_CMD_MAX];
	const cmd_ref_struct *cmd_list_ptr, cmd_list[] = SAR_CMD_FUNC_REF_LIST;	
	void (*cmd_func)(SAR_CMD_PROTOTYPE);
	sar_core_struct *core_ptr = SAR_CORE(data);
	if((value == NULL) || (core_ptr == NULL))
	    return;


	/* Parse command and value */

	/* Get command */
	strncpy(cmd, value, sizeof(cmd));
	cmd[sizeof(cmd) - 1] = '\0';
	s = strchr(cmd, ' ');
	if(s == NULL)
	    s = strchr(cmd, '\t');
	if(s != NULL)
	    *s = '\0';

	/* Get argument */
	arg = strchr(value, ' ');
	if(arg == NULL)
	{
	    arg = "";
	}
	else
	{
	    while(ISBLANK(*arg))
		arg++;
	}

	/* Iterate through list of SARCmd*() functions to see which
	 * command matches the command tagent from the value string
	 */
	for(cmd_list_ptr = cmd_list;
	    cmd_list_ptr->name != NULL;
	    cmd_list_ptr++
	)
	{
	    const char *cmd_name = cmd_list_ptr->name;
	    cmd_func = cmd_list_ptr->func;

	    if(STRISEMPTY(cmd_name) || (cmd_func == NULL))
		break;

	    /* Commands match? */
	    if(!strcasecmp(cmd_name, cmd))
	    {
		/* Call the function */
		cmd_func(core_ptr, arg, flags);
		matched_command = True;
		break;
	    }
	}

	/* Did not match command? */
	if(!matched_command)
	{
	    if(SAR_CMD_IS_VERBOSE(flags))
	    {
		char *s = (char *)malloc(
		    (80 + STRLEN(cmd)) * sizeof(char)
		);
		sprintf(
		    s,
		    "%s: No such command.",
		    cmd
		);
		SARMessageAdd(core_ptr->scene, s);
		free(s);
	    }
	}
}
Ejemplo n.º 8
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];
}