Esempio n. 1
0
int cmd_test(int argc, CmdArg* argv) {
    printf("aes_crypto_cmd: 0x%08x\n", find_function("aes_crypto_cmd", TARGET_BASEADDR, TARGET_BASEADDR));
    printf("free: 0x%08x\n", find_function("free", TARGET_BASEADDR, TARGET_BASEADDR));
    printf("cmd_ramdisk: 0x%08x\n", find_function("cmd_ramdisk", TARGET_BASEADDR, TARGET_BASEADDR));
    printf("fs_mount: 0x%08x\n", find_function("fs_mount", TARGET_BASEADDR, TARGET_BASEADDR));
    return 0;
}
Esempio n. 2
0
int
main (int argc, char **argv)
{
	mainfunc toolmain;
	char *tmp;
	int loop;

	tmp = strrchr(argv[0], '/');
	tmp = tmp? tmp + 1: argv[0];

	if ((toolmain = find_function (tmp)))
	{
		return toolmain (argc, argv);
	}

	if (argc > 1 && (toolmain = find_function (argv[1])))
	{
		return toolmain (argc - 1, argv + 1);
	}

	fprintf (stderr, "%s %s\n", PACKAGE, VERSION);
	fprintf (stderr, "Usage: %s <function> <args> or <function> <args>\n", argv[0]);
	fprintf (stderr, "Available functions:\n");
	for (loop = 0; funcs[loop].name; loop++)
		fprintf (stderr, "  %-10s%s\n", funcs[loop].name, funcs[loop].desc);
	fprintf (stderr, "For help on a particular function: %s <function> -h\n", argv[0]);
	return 1;
}
Esempio n. 3
0
void
where_is (char * name)
{
  struct line seqname;
  int vec;
  int code;
  struct cmd_func * cmd;
  
  if (!find_function (&vec, &cmd, name, strlen(name)))
    code = cmd - the_funcs[vec];
  else if (map_id (name) >= 0)
    {
      code = map_id (name);
      vec = -1;
    }
  else
    io_error_msg ("%s is not a function.", name); /* no return */
  code = cmd - the_funcs[vec];
  init_line (&seqname);
  set_line (&seqname, "");
  
  if (!search_map_for_cmd (&seqname, the_cmd_frame->top_keymap, vec, code))
    io_info_msg ("%s is not on any keys.", name);
  else
    io_info_msg ("%s is bound to %s.", name, seqname.buf);
  
  free_line (&seqname);
}
Esempio n. 4
0
/**
 * \brief Execute a method from the class from its name and its arguments as
 *        passed as strings.
 * \param n The name of the method to call.
 * \param c The argument_converter used to convert the arguments.
 */
void bear::text_interface::base_exportable::execute
( const std::string& n, const auto_converter& c )
{
  method_caller const* f = find_function(n);

  if (f!=NULL)
    f->execute(this, c.get_arguments(), c);
} // base_exportable::execute()
Esempio n. 5
0
/**
 * \brief Execute a method from the class from its name and its arguments as
 *        passed as strings.
 * \param n The name of the method to call.
 * \param args The string representation of the value of the arguments of the
 *        method.
 * \remark The call is make without any context, which mean that some argument
 *         conversion may not work.
 */
void bear::text_interface::base_exportable::execute
( const std::string& n, const std::vector<std::string>& args )
{
  method_caller const* f = find_function(n);

  if (f!=NULL)
    f->execute(this, args, argument_converter());
} // base_exportable::execute()
Esempio n. 6
0
void next_token(state *s) {
    s->type = TOK_NULL;

    if (!*s->next){
        s->type = TOK_END;
        return;
    }

    do {

        /* Try reading a number. */
        if ((s->next[0] >= '0' && s->next[0] <= '9') || s->next[0] == '.') {
            s->value = strtod(s->next, (char**)&s->next);
            s->type = TOK_NUMBER;
        } else {
            /* Look for a variable or builtin function call. */
            if (s->next[0] >= 'a' && s->next[0] <= 'z') {
                const char *start;
                start = s->next;
                while (s->next[0] >= 'a' && s->next[0] <= 'z') s->next++;

                const double *var = find_var(s, start, s->next - start);
                if (var) {
                    s->type = TOK_VARIABLE;
                    s->var = var;
                } else {
                    if (s->next - start > 15) {
                        s->type = TOK_ERROR;
                    } else {
                        s->type = TOK_FUNCTION1;
                        const builtin *f = find_function(start, s->next - start);
                        if (!f) {
                            s->type = TOK_ERROR;
                        } else {
                            s->f1 = f->f1;
                        }
                    }
                }

            } else {
                /* Look for an operator or special character. */
                switch (s->next++[0]) {
                    case '+': s->type = TOK_FUNCTION2; s->f2 = add; break;
                    case '-': s->type = TOK_FUNCTION2; s->f2 = sub; break;
                    case '*': s->type = TOK_FUNCTION2; s->f2 = mul; break;
                    case '/': s->type = TOK_FUNCTION2; s->f2 = divide; break;
                    case '^': s->type = TOK_FUNCTION2; s->f2 = pow; break;
                    case '%': s->type = TOK_FUNCTION2; s->f2 = fmod; break;
                    case '(': s->type = TOK_OPEN; break;
                    case ')': s->type = TOK_CLOSE; break;
                    case ' ': case '\t': case '\n': case '\r': break;
                    default: s->type = TOK_ERROR; break;
                }
            }
        }
    } while (s->type == TOK_NULL);
}
Esempio n. 7
0
static node_t *get_pow(token_stack_t *stack, GError **err)
{
    const token_t *token;
    node_t *node;
    token_type_t type;
    GError *tmp_err = NULL;
    double x;
    double (*fun)(double x);
    char msg[128];

    token = token_peak(stack);

    type = (token) ? token->type : TOK_NULL;
    switch (type) {
    case TOK_LPAREN:
        node = get_parentised_expr(stack, &tmp_err);
        if (tmp_err)
            g_propagate_error(err, tmp_err);
        break;
    case TOK_NUMBER:
        node = get_number(stack, &tmp_err);
        if (tmp_err)
            g_propagate_error(err, tmp_err);
        break;
    case TOK_IDENTIFIER:
        token = token_pop(stack);
        if (find_constant(token->val.id, &x)) {
            node = g_malloc(sizeof(node_t));
            node->type = NODE_NUMBER;
            node->val.num = x;
            node->left = node->right = NULL;
        } else if (find_function(token->val.id, &fun)) {
            node = g_malloc(sizeof(node_t));
            node->type = NODE_FUNCTION;
            node->val.fun = fun;
            node->left = NULL;
            node->right = get_parentised_expr(stack, &tmp_err);
            if (tmp_err)
                g_propagate_error(err, tmp_err);
            break;
        } else {
            g_snprintf(msg,sizeof(msg),"Unknown identifier '%s'",token->val.id);
            set_error(err, msg, token);
            node = NULL;
        }
        break;
    default:
        set_error(err,"Expected '(', number, constant or function",token);
        node = NULL;
    }
    return node;
}
Esempio n. 8
0
mainfunc
find_function (char *name)
{
	int loop;

	for (loop = 0; funcs[loop].name; loop++)
		if (!strcasecmp (funcs[loop].name, name))
			return funcs[loop].main;

	if (!strncmp (name, "mfs", 3))
		return find_function (name + 3);

	return 0;
}
static const char *parse_symbol(opstack ** stack, const char *in,
    const void *userdata)
    /* in is the symbol name and following text, starting after the $
     * result goes on the stack
     */
{
    bool braces = false;
    char symbol[32];
    char *cp = symbol;            /* current position */

    if (*in == '{') {
        braces = true;
        ++in;
    }
    while (isalnum(*in) || *in == '.')
        *cp++ = *in++;
    *cp = '\0';
    /* symbol will now contain the symbol name */
    if (*in == '(') {
        /* it's a function we need to parse, start by reading the parameters */
        evalfun foo;

        while (*in != ')') {
            in = parse(stack, ++in, userdata);        /* will push the result on the stack */
            if (in == NULL)
                return NULL;
        }
        ++in;
        foo = find_function(symbol);
        if (foo == NULL) {
            log_error("parser does not know about \"%s\" function.\n", symbol);
            return NULL;
        }
        foo(stack, userdata);        /* will pop parameters from stack (reverse order!) and push the result */
    }
    else {
        variable *var = find_variable(symbol);
        if (braces && *in == '}') {
            ++in;
        }
        /* it's a constant (variable is a misnomer, but heck, const was taken;)) */
        if (var == NULL) {
            log_error("parser does not know about \"%s\" variable.\n", symbol);
            return NULL;
        }
        opush(stack, var->value);
    }
    return in;
}
Esempio n. 10
0
void fn_colon(char **args)
{
	char *cmd, *p, *line = NULL;
	int i;

	if (args) {
	    cmd = args[0];
	    args++;
	}
	else {
	    line = p = read_string(": ", 1);
	    if (line == NULL || line[0] == '\0') {
		free(line);
		disp_status(DISP_STATUS, "");
		return;
	    }

	    if ((cmd=rc_token(&p)) == NULL) {
		disp_status(DISP_STATUS, "no function");
		return;
	    }
	}
	
	if ((i=find_function(cmd)) < 0) {
	    disp_status(DISP_STATUS, "unknown function: %s", cmd);
	    if (line)
		free(line);
	    return;
	}

	if (line) {
	    args = rc_list(p);
	}

	disp_status(DISP_STATUS, "");
	
	if (functions[i].fn)
	    functions[i].fn(args);

	if (line) {
	    free(line);
	    if (args) {
		for (i=0; args[i]; i++)
		    free(args[i]);
		free(args);
	    }
	}
}
Esempio n. 11
0
/***
 * <cmd> <n1> <n2> <op>
 *
 * Ex.:
 *   <cmd> 5.0 4.0 sum
 *
 */
int main(int argc, char** argv) {
  const char* operand_0 = argv[1];
  const char* operand_1 = argv[2];
  const char* funcName = argv[3];

  double result;

  char*                         funcNames[] = { "sum", "rest" };
  double (*functionArray[])(double, double) = { &sum,  &rest  };

  if  ( argc != 4 ) {
    usage();
    return 1;
  }

  int index = find_function( funcNames, funcName, sizeof(funcNames) / sizeof(char*) );
  double (*f)(double, double) = functionArray[index];


  if ( index == -1 ) {
    printf("Unknown <op>: %s\n", funcName);
    return 1;
  }


  result = (*f)( atof(operand_0), atof(operand_1) );
  
#if 0
  if ( strcmp( funcName, "sum") == 0 ) {
    result = sum( atof(operand_0), atof(operand_1) );
  }
  else if ( strcmp( funcName, "rest") == 0 ) {
    result = rest( atof(operand_0), atof(operand_1) );
  }
#endif


  printf(" %s %s %s: %lf\n", operand_0, funcName, operand_1, result); 



}
Esempio n. 12
0
void* find_printf() {
	int i = 0;
	int j = 0;
	unsigned int sp;
	unsigned int* stack = &sp;
	void(*default_block_write)(void) = find_function("default_block_write", TARGET_BASEADDR, TARGET_BASEADDR);
	default_block_write();
	for(i = 0; i < 0x100; i += 4) {
		unsigned int value = *(stack - i);
		if((value & TARGET_BASEADDR) == TARGET_BASEADDR) {
			for(j = 0; j < 0x100; j++) {
				unsigned short* instruction = (unsigned short*)(value + j);
				if(*instruction == 0xB40F) {
					return (void*) value + (j+1);
				}
			}
		}
	}
	return 0;
}
void translate(Node* h)
{
	if(h==NULL)return;
	switch(h->type)
	{
		case Specifier:return;
		case FunDec:
		{
			func_d* temp=find_function(h->child[0]->name);
			add_code(3,"FUNCTION",h->child[0]->name,":");
			for(int i=0;i<temp->parameter_count;i++)
				add_code(2,"PARAM",temp->parameter_list[i]->name);
			current_func=temp;
			break;
		}
		case Dec:
		{
			Node* p=h->child[0]->child[0];
			if(p->type!=_ID)
			{
				p=p->child[0];
				if(p->type!=_ID)
				{
					printf("Cannot translate: Code contains variables of multi-dimensional \
					array type or parameters of array type.\n");
					exit(0);
				}
			}
			val_d* temp=find_value(p->name);
			if(temp->kind==USER_DEFINED)
			{
				char length[8];
				itoa(struct_get_size(temp->val_type),length,10);
				add_code(3,"DEC",temp->name,length);
			}
			if(h->child_count==3)
			{
				translate_exp(h->child[2],temp->name,1);
			}
			break;
		}
Esempio n. 14
0
var_t
function_call(const char func_name[], const call_info_t *call_info)
{
	function_t *function = find_function(func_name);
	if(function == NULL)
	{
		text_buffer_addf("%s: %s", "Unknown function", func_name);
		return var_error();
	}
	if(call_info->argc < function->arg_count)
	{
		text_buffer_addf("%s: %s", "Not enough arguments for function", func_name);
		return var_error();
	}
	if(call_info->argc > function->arg_count)
	{
		text_buffer_addf("%s: %s", "Too many arguments for function", func_name);
		return var_error();
	}
	return function->ptr(call_info);
}
Esempio n. 15
0
/* Look up a user-provided callback function. */
int
mpibash_find_callback_function (WORD_LIST *list, SHELL_VAR **user_func)
{
  char *funcname;     /* Name of the user-defined function. */

  /* If no argument was provided, nullify the callback function. */
  if (list == NULL) {
    *user_func = NULL;
    return EXECUTION_SUCCESS;
  }

  /* Get the callback function. */
  funcname = list->word->word;
  list = list->next;
  no_args(list);
  *user_func = find_function(funcname);
  if (*user_func == NULL) {
    builtin_error(_("function %s not found"), funcname);
    return EXECUTION_FAILURE;
  }
  return EXECUTION_SUCCESS;
}
Esempio n. 16
0
void
describe_function (char * name)
{
  int vector;
  struct cmd_func * cmd;
  if (!(   !find_function (&vector, &cmd, name, strlen(name))
	&& cmd->func_doc))
    io_error_msg ("%s is not a function.", name); /* no return */
  
  {
    struct info_buffer * ib_disp = find_or_make_info ("help-buffer");
    clear_info (ib_disp);
    print_info (ib_disp, "");
    print_info (ib_disp, "%s", name);
    {
      struct info_buffer ib;
/* FIXME:
 * Something is screwed up here.  ib.len is wrongly identified
 * for help texts defined through name-macro-string.  Looks
 * like it should always be 1.  I _really_ don't know what I am
 * doing here.  This is a hack.  And probably stoopid.  But for
 * now it's better than the current core-dump-on-help behaviour.
 * 
 * 
 *    for (ib.len = 0; cmd->func_doc[ib.len]; ++ib.len) ;
 */
      ib.len = 1;
      ib.text = cmd->func_doc;
      ib.name = name;
      expand_help_msg (ib_disp, &ib);
    }
  }

  {
    static char buf[] = "{view-info help-buffer}";
    run_string_as_macro (buf);
  }
}
Esempio n. 17
0
static int execute_bash_trampoline(ffi_cif *cif, void *retval, void **args, char **proto)
{
    SHELL_VAR *function;
    WORD_LIST *params;
    char *result;

    // Decode parameters
    // callback hello pointer pointer int int
    // FIXME this is really ugly, do it properly and check cif->argtypes
    //
    if (!(function = find_function(*proto))) {
        fprintf(stderr, "error: unable to resolve function %s in thunk", *proto);
        return -1;
    }

    params = NULL;

    for (unsigned i = 0; i < cif->nargs; i++) {
        char parameter[1024];
        ffi_raw *p = args[i];

        // Decode the parameters
        snprintf(parameter, sizeof parameter, proto[i+1], p->ptr);

        params = make_word_list(make_word(parameter), params);
    }

    // The first parameter should be the return location
    asprintf(&result, "pointer:%p", retval);

    params = make_word_list(make_word(result), params);
    params = make_word_list(make_word(*proto), params);

    execute_shell_function(function, params);

    free(result);
    return 0;
}
Esempio n. 18
0
void c_optimize() {
   inst_t current = instList;
    int size=0;
    while(current->next != NULL) {
        size++;
        current=current->next;
    }
    live_range *live;
    block_array cfg;
    //ddg_t ddg;
    /* file pointer to dump output code */
    FILE *fptr = fopen(outfile, "w");

    codegen_entry(fptr);

    yywrap();
    yyparse();

    if (num_errors > 0)
        return;

    if (verbose)
        print_list(stdout, instList);

    find_function(); /* remove extra instructions needed for simulation */
    cfg = generate_cfg();
   // ddg = generate_ddg();
    live=liveness(size);
    live->dead++;
    live->dead--;
    cfg.num_of_labels++;
    cfg.num_of_labels--;
    /************************************************************************/
    /************************************************************************/
    /************************************************************************/
    /************************************************************************/
    /*    Call your implementation from here                                */

    /* Find single basic block loops and perform Iterative Modulo Scheduling */

  multiOpSetup(instList);
	
  if (flag_regalloc)
    {
      // perform register allocation
      printf("Perform register allocation.\n"); // REMOVE ME
    }

    if (flag_sched) {
        // perform scheduling      
        printf("Perform scheduling.\n"); // REMOVE ME      
    }


    /************************************************************************/
    /************************************************************************/
    /************************************************************************/
    /************************************************************************/

    print_list(fptr, instList); /* dump code to output file */

    codegen_exit(fptr);
    fclose(fptr); /* close file */
}
Esempio n. 19
0
void* find_load_ramdisk() {
    return find_function("cmd_ramdisk", TARGET_BASEADDR, TARGET_BASEADDR);
}
Esempio n. 20
0
void handle_command(char *cmdstr) /* {{{ */
{
	/* accept a command string, determine what action to take, and execute */
	char *command, *args, *modestr, *pos;
	funcmap *fmap;
	prog_mode mode;
	int ret = 0;

	/* parse args */
	pos = strchr(cmdstr, '\n');
	if (pos != NULL)
		*pos = 0;
	tnc_fprintf(logfp, LOG_DEBUG, "command received: %s", cmdstr);
	if (cmdstr != NULL)
		ret = sscanf(cmdstr, "%ms %m[^\n]", &command, &args);
	if (ret < 1)
	{
		statusbar_message(cfg.statusbar_timeout, "failed to parse command");
		tnc_fprintf(logfp, LOG_ERROR, "failed to parse command: [%d] (%s)", ret, cmdstr);
		return;
	}

	/* determine mode */
	if (pager != NULL)
	{
		modestr = "pager";
		mode = MODE_PAGER;
	}
	else if (tasklist != NULL)
	{
		modestr = "tasklist";
		mode = MODE_TASKLIST;
	}
	else
	{
		modestr = "none";
		mode = MODE_ANY;
	}

	/* log command */
	tnc_fprintf(logfp, LOG_DEBUG_VERBOSE, "command: %s - %s (%s)", modestr, command, args);

	/* handle command & arguments */
	/* try for exposed command */
	fmap = find_function(command, mode);
	if (fmap!=NULL)
	{
		(fmap->function)(str_trim(args));
		goto cleanup;
	}
	/* version: print version string */
	if (str_eq(command, "version"))
		statusbar_message(cfg.statusbar_timeout, "%s %s by %s\n", PROGNAME, PROGVERSION, PROGAUTHOR);
	/* quit/exit: exit tasknc */
	else if (str_eq(command, "quit") || str_eq(command, "exit"))
		done = true;
	/* reload: force reload of task list */
	else if (str_eq(command, "reload"))
	{
		reload = true;
		statusbar_message(cfg.statusbar_timeout, "task list reloaded");
	}
	/* redraw: force redraw of screen */
	else if (str_eq(command, "redraw"))
		redraw = true;
	/* dump: write all displayed tasks to log file */
	else if (str_eq(command, "dump"))
	{
		task *this = head;
		int counter = 0;
		while (this!=NULL)
		{
			tnc_fprintf(logfp, 0, "uuid: %s", this->uuid);
			tnc_fprintf(logfp, 0, "description: %s", this->description);
			tnc_fprintf(logfp, 0, "project: %s", this->project);
			tnc_fprintf(logfp, 0, "tags: %s", this->tags);
			this = this->next;
			counter++;
		}
		tnc_fprintf(logfp, 0, "dumped %d tasks", counter);
	}
	/* scrdump: do an ncurses scr_dump */
	else if (str_eq(command, "scrdump"))
	{
		const char *dumppath = "nc_dump";
		scr_dump(dumppath);
		tnc_fprintf(logfp, LOG_DEBUG, "ncurses dumped to '%s'", dumppath);
	}
	else
	{
		statusbar_message(cfg.statusbar_timeout, "error: command %s not found", command);
		tnc_fprintf(logfp, LOG_ERROR, "error: command %s not found", command);
	}
	goto cleanup;

cleanup:
	/* clean up */
	free(command);
	free(args);
} /* }}} */
Esempio n. 21
0
void* find_kernel_load() {
	return find_function("kernel_load", gBaseaddr, gBaseaddr);
}
Esempio n. 22
0
void
expand_help_msg (struct info_buffer * out, struct info_buffer * in)
{
  int x;
  struct line line;
  struct line seq_buf;
  int out_offset;
  int rel_map = the_cmd_frame->top_keymap;

  if (the_cmd_frame->cmd && (the_cmd_arg.style == &keyseq_style))
    rel_map = the_cmd_arg.val.key.cmd.code;

  print_info (out, "");
  out_offset = out->len;
  out->len += in->len;
  out->text = (char **)ck_remalloc (out->text, out->len * sizeof (char *));
  init_line (&line);
  init_line (&seq_buf);
  for (x = 0; x < in->len; ++x)
    {
      char * next_burst = in->text[x];
      char * end_burst = index (next_burst, '[');
      set_line (&line, "");
      set_line (&seq_buf, "");
      while (end_burst)
	{
	  char * fn_start = end_burst + 1;
	  char * fn_end = index (fn_start, ']');
	  int vec;
	  struct cmd_func * cmd;
	  if (fn_end && (*fn_start == '[') && fn_end[1] == ']')
	    {
	      int map = map_idn (fn_start + 1, fn_end - fn_start - 1);
	      if (map < 0)
		map = map_id ("universal");
	      rel_map = map;
	      catn_line (&line, next_burst, end_burst - next_burst);
	      next_burst = fn_end + 2;
	      end_burst = index (next_burst, '[');
	    }
	  else if (   fn_end
		   && !find_function (&vec, &cmd, fn_start, fn_end - fn_start))
	    {
	      catn_line (&line, next_burst, end_burst - next_burst);
	      if (search_map_for_cmd (&seq_buf, rel_map, vec,
				      cmd - the_funcs[vec])) 
		{
		  catn_line (&line, seq_buf.buf, strlen (seq_buf.buf));
		  set_line (&seq_buf, "");
		}
	      else
		{
		  catn_line (&line, "M-x ", 4);
		  catn_line (&line, fn_start, fn_end - fn_start);
		}
	      next_burst = fn_end + 1;
	      end_burst = index (next_burst, '[');
	    }
	  else if (fn_end)
	    end_burst = index (fn_end + 1, '[');
	}
      catn_line (&line, next_burst, strlen(next_burst));
      out->text[x + out_offset] = line.buf;
      init_line (&line);
    }
  free_line (&seq_buf);
  free_line (&line);
}
Esempio n. 23
0
void run_command_bind(char *args) /* {{{ */
{
	/**
	 * create a new keybind
	 * syntax - mode key function [funcarg]
	 */
	int key, ret = 0;
	char *function = NULL, *arg = NULL, *keystr = NULL, *modestr = NULL, *keyname = NULL;
	void (*func)();
	funcmap *fmap;
	prog_mode mode;

	/* parse command */
	if (args != NULL)
		ret = sscanf(args, "%ms %ms %ms %m[^\n]", &modestr, &keystr, &function, &arg);
	if (ret < 3)
	{
		statusbar_message(cfg.statusbar_timeout, "syntax: bind <mode> <key> <function> <args>");
		tnc_fprintf(logfp, LOG_ERROR, "syntax: bind <mode> <key> <function> <args> [%d](%s)", ret, args);
		goto cleanup;
	}

	/* parse mode string */
	if (str_eq(modestr, "tasklist"))
		mode = MODE_TASKLIST;
	else if (str_eq(modestr, "pager"))
		mode = MODE_PAGER;
	else
	{
		tnc_fprintf(logfp, LOG_ERROR, "bind: invalid mode (%s)", modestr);
		goto cleanup;
	}

	/* parse key */
	key = parse_key(keystr);

	/* map function to function call */
	fmap = find_function(function, mode);
	if (fmap==NULL)
	{
		tnc_fprintf(logfp, LOG_ERROR, "bind: invalid function specified (%s)", args);
		goto cleanup;
	}
	func = fmap->function;

	/* error out if there is no argument specified when required */
	if (fmap->argn>0 && arg==NULL)
	{
		statusbar_message(cfg.statusbar_timeout, "bind: argument required for function %s", function);
		goto cleanup;
	}

	/* add keybind */
	add_keybind(key, func, arg, mode);
	keyname = name_key(key);
	statusbar_message(cfg.statusbar_timeout, "key %s (%d) bound to %s - %s", keyname, key, modestr, name_function(func));
	goto cleanup;

cleanup:
	free(function);
	free(arg);
	free(keystr);
	free(modestr);
	free(keyname);
	return;
} /* }}} */
Esempio n. 24
0
static void
pr_unidiff_hunk (struct change *hunk)
{
  lin first0, last0, first1, last1;
  lin i, j, k;
  struct change *next;
  char const *function;
  FILE *out;

  /* Determine range of line numbers involved in each file.  */

  if (! analyze_hunk (hunk, &first0, &last0, &first1, &last1))
    return;

  /* Include a context's width before and after.  */

  i = - files[0].prefix_lines;
  first0 = MAX (first0 - context, i);
  first1 = MAX (first1 - context, i);
  if (last0 < files[0].valid_lines - context)
    last0 += context;
  else
    last0 = files[0].valid_lines - 1;
  if (last1 < files[1].valid_lines - context)
    last1 += context;
  else
    last1 = files[1].valid_lines - 1;

  /* If desired, find the preceding function definition line in file 0.  */
  function = 0;
  if (function_regexp.fastmap)
    function = find_function (files[0].linbuf, first0);

  begin_output ();
  out = outfile;

  fprintf (out, "@@ -");
  print_unidiff_number_range (&files[0], first0, last0);
  fprintf (out, " +");
  print_unidiff_number_range (&files[1], first1, last1);
  fprintf (out, " @@");

  if (function)
    print_context_function (out, function);

  putc ('\n', out);

  next = hunk;
  i = first0;
  j = first1;

  while (i <= last0 || j <= last1)
    {

      /* If the line isn't a difference, output the context from file 0. */

      if (!next || i < next->line0)
	{
	  putc (initial_tab ? '\t' : ' ', out);
	  print_1_line (0, &files[0].linbuf[i++]);
	  j++;
	}
      else
	{
	  /* For each difference, first output the deleted part. */

	  k = next->deleted;
	  while (k--)
	    {
	      putc ('-', out);
	      if (initial_tab)
		putc ('\t', out);
	      print_1_line (0, &files[0].linbuf[i++]);
	    }

	  /* Then output the inserted part. */

	  k = next->inserted;
	  while (k--)
	    {
	      putc ('+', out);
	      if (initial_tab)
		putc ('\t', out);
	      print_1_line (0, &files[1].linbuf[j++]);
	    }

	  /* We're done with this hunk, so on to the next! */

	  next = next->link;
	}
    }
}
Esempio n. 25
0
Error Expression::_get_token(Token &r_token) {

	while (true) {
#define GET_CHAR() (str_ofs >= expression.length() ? 0 : expression[str_ofs++])

		CharType cchar = GET_CHAR();
		if (cchar == 0) {
			r_token.type = TK_EOF;
			return OK;
		}

		switch (cchar) {

			case 0: {
				r_token.type = TK_EOF;
				return OK;
			} break;
			case '{': {

				r_token.type = TK_CURLY_BRACKET_OPEN;
				return OK;
			};
			case '}': {

				r_token.type = TK_CURLY_BRACKET_CLOSE;
				return OK;
			};
			case '[': {

				r_token.type = TK_BRACKET_OPEN;
				return OK;
			};
			case ']': {

				r_token.type = TK_BRACKET_CLOSE;
				return OK;
			};
			case '(': {

				r_token.type = TK_PARENTHESIS_OPEN;
				return OK;
			};
			case ')': {

				r_token.type = TK_PARENTHESIS_CLOSE;
				return OK;
			};
			case ',': {

				r_token.type = TK_COMMA;
				return OK;
			};
			case ':': {

				r_token.type = TK_COLON;
				return OK;
			};
			case '$': {

				r_token.type = TK_INPUT;
				int index = 0;
				do {
					if (!_is_number(expression[str_ofs])) {
						_set_error("Expected number after '$'");
						r_token.type = TK_ERROR;
						return ERR_PARSE_ERROR;
					}
					index *= 10;
					index += expression[str_ofs] - '0';
					str_ofs++;

				} while (_is_number(expression[str_ofs]));

				r_token.value = index;
				return OK;
			};
			case '=': {

				cchar = GET_CHAR();
				if (cchar == '=') {
					r_token.type = TK_OP_EQUAL;
				} else {
					_set_error("Expected '='");
					r_token.type = TK_ERROR;
					return ERR_PARSE_ERROR;
				}
				return OK;
			};
			case '!': {

				if (expression[str_ofs] == '=') {
					r_token.type = TK_OP_NOT_EQUAL;
					str_ofs++;
				} else {
					r_token.type = TK_OP_NOT;
				}
				return OK;
			};
			case '>': {

				if (expression[str_ofs] == '=') {
					r_token.type = TK_OP_GREATER_EQUAL;
					str_ofs++;
				} else if (expression[str_ofs] == '>') {
					r_token.type = TK_OP_SHIFT_RIGHT;
					str_ofs++;
				} else {
					r_token.type = TK_OP_GREATER;
				}
				return OK;
			};
			case '<': {

				if (expression[str_ofs] == '=') {
					r_token.type = TK_OP_LESS_EQUAL;
					str_ofs++;
				} else if (expression[str_ofs] == '<') {
					r_token.type = TK_OP_SHIFT_LEFT;
					str_ofs++;
				} else {
					r_token.type = TK_OP_LESS;
				}
				return OK;
			};
			case '+': {
				r_token.type = TK_OP_ADD;
				return OK;
			};
			case '-': {
				r_token.type = TK_OP_SUB;
				return OK;
			};
			case '/': {
				r_token.type = TK_OP_DIV;
				return OK;
			};
			case '*': {
				r_token.type = TK_OP_MUL;
				return OK;
			};
			case '%': {
				r_token.type = TK_OP_MOD;
				return OK;
			};
			case '&': {

				if (expression[str_ofs] == '&') {
					r_token.type = TK_OP_AND;
					str_ofs++;
				} else {
					r_token.type = TK_OP_BIT_AND;
				}
				return OK;
			};
			case '|': {

				if (expression[str_ofs] == '|') {
					r_token.type = TK_OP_OR;
					str_ofs++;
				} else {
					r_token.type = TK_OP_BIT_OR;
				}
				return OK;
			};
			case '^': {

				r_token.type = TK_OP_BIT_XOR;

				return OK;
			};
			case '~': {

				r_token.type = TK_OP_BIT_INVERT;

				return OK;
			};
			case '"': {

				String str;
				while (true) {

					CharType ch = GET_CHAR();

					if (ch == 0) {
						_set_error("Unterminated String");
						r_token.type = TK_ERROR;
						return ERR_PARSE_ERROR;
					} else if (ch == '"') {
						break;
					} else if (ch == '\\') {
						//escaped characters...

						CharType next = GET_CHAR();
						if (next == 0) {
							_set_error("Unterminated String");
							r_token.type = TK_ERROR;
							return ERR_PARSE_ERROR;
						}
						CharType res = 0;

						switch (next) {

							case 'b': res = 8; break;
							case 't': res = 9; break;
							case 'n': res = 10; break;
							case 'f': res = 12; break;
							case 'r': res = 13; break;
							case 'u': {
								//hexnumbarh - oct is deprecated

								for (int j = 0; j < 4; j++) {
									CharType c = GET_CHAR();

									if (c == 0) {
										_set_error("Unterminated String");
										r_token.type = TK_ERROR;
										return ERR_PARSE_ERROR;
									}
									if (!(_is_number(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) {

										_set_error("Malformed hex constant in string");
										r_token.type = TK_ERROR;
										return ERR_PARSE_ERROR;
									}
									CharType v;
									if (_is_number(c)) {
										v = c - '0';
									} else if (c >= 'a' && c <= 'f') {
										v = c - 'a';
										v += 10;
									} else if (c >= 'A' && c <= 'F') {
										v = c - 'A';
										v += 10;
									} else {
										ERR_PRINT("BUG");
										v = 0;
									}

									res <<= 4;
									res |= v;
								}

							} break;
							//case '\"': res='\"'; break;
							//case '\\': res='\\'; break;
							//case '/': res='/'; break;
							default: {
								res = next;
								//r_err_str="Invalid escape sequence";
								//return ERR_PARSE_ERROR;
							} break;
						}

						str += res;

					} else {
						str += ch;
					}
				}

				r_token.type = TK_CONSTANT;
				r_token.value = str;
				return OK;

			} break;
			default: {

				if (cchar <= 32) {
					break;
				}

				CharType next_char = (str_ofs >= expression.length()) ? 0 : expression[str_ofs];
				if (_is_number(cchar) || (cchar == '.' && _is_number(next_char))) {
					//a number

					String num;
#define READING_SIGN 0
#define READING_INT 1
#define READING_DEC 2
#define READING_EXP 3
#define READING_DONE 4
					int reading = READING_INT;

					CharType c = cchar;
					bool exp_sign = false;
					bool exp_beg = false;
					bool is_float = false;

					while (true) {

						switch (reading) {
							case READING_INT: {

								if (_is_number(c)) {
									//pass
								} else if (c == '.') {
									reading = READING_DEC;
									is_float = true;
								} else if (c == 'e') {
									reading = READING_EXP;
								} else {
									reading = READING_DONE;
								}

							} break;
							case READING_DEC: {

								if (_is_number(c)) {

								} else if (c == 'e') {
									reading = READING_EXP;

								} else {
									reading = READING_DONE;
								}

							} break;
							case READING_EXP: {

								if (_is_number(c)) {
									exp_beg = true;

								} else if ((c == '-' || c == '+') && !exp_sign && !exp_beg) {
									if (c == '-')
										is_float = true;
									exp_sign = true;

								} else {
									reading = READING_DONE;
								}
							} break;
						}

						if (reading == READING_DONE)
							break;
						num += String::chr(c);
						c = GET_CHAR();
					}

					str_ofs--;

					r_token.type = TK_CONSTANT;

					if (is_float)
						r_token.value = num.to_double();
					else
						r_token.value = num.to_int();
					return OK;

				} else if ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_') {

					String id;
					bool first = true;

					while ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_' || (!first && _is_number(cchar))) {

						id += String::chr(cchar);
						cchar = GET_CHAR();
						first = false;
					}

					str_ofs--; //go back one

					if (id == "in") {
						r_token.type = TK_OP_IN;
					} else if (id == "null") {
						r_token.type = TK_CONSTANT;
						r_token.value = Variant();
					} else if (id == "true") {
						r_token.type = TK_CONSTANT;
						r_token.value = true;
					} else if (id == "false") {
						r_token.type = TK_CONSTANT;
						r_token.value = false;
					} else if (id == "PI") {
						r_token.type = TK_CONSTANT;
						r_token.value = Math_PI;
					} else if (id == "TAU") {
						r_token.type = TK_CONSTANT;
						r_token.value = Math_TAU;
					} else if (id == "INF") {
						r_token.type = TK_CONSTANT;
						r_token.value = Math_INF;
					} else if (id == "NAN") {
						r_token.type = TK_CONSTANT;
						r_token.value = Math_NAN;
					} else if (id == "not") {
						r_token.type = TK_OP_NOT;
					} else if (id == "or") {
						r_token.type = TK_OP_OR;
					} else if (id == "and") {
						r_token.type = TK_OP_AND;
					} else if (id == "self") {
						r_token.type = TK_SELF;
					} else {

						for (int i = 0; i < Variant::VARIANT_MAX; i++) {
							if (id == Variant::get_type_name(Variant::Type(i))) {
								r_token.type = TK_BASIC_TYPE;
								r_token.value = i;
								return OK;
							}
						}

						BuiltinFunc bifunc = find_function(id);
						if (bifunc != FUNC_MAX) {
							r_token.type = TK_BUILTIN_FUNC;
							r_token.value = bifunc;
							return OK;
						}

						r_token.type = TK_IDENTIFIER;
						r_token.value = id;
					}

					return OK;

				} else if (cchar == '.') {
					// Handled down there as we support '.[0-9]' as numbers above
					r_token.type = TK_PERIOD;
					return OK;

				} else {
					_set_error("Unexpected character.");
					r_token.type = TK_ERROR;
					return ERR_PARSE_ERROR;
				}
			}
		}
#undef GET_CHAR
	}

	r_token.type = TK_ERROR;
	return ERR_PARSE_ERROR;
}
Esempio n. 26
0
static void
pr_context_hunk (struct change *hunk)
{
  lin first0, last0, first1, last1, i;
  char const *prefix;
  char const *function;
  FILE *out;

  /* Determine range of line numbers involved in each file.  */

  enum changes changes = analyze_hunk (hunk, &first0, &last0, &first1, &last1);
  if (! changes)
    return;

  /* Include a context's width before and after.  */

  i = - files[0].prefix_lines;
  first0 = MAX (first0 - context, i);
  first1 = MAX (first1 - context, i);
  if (last0 < files[0].valid_lines - context)
    last0 += context;
  else
    last0 = files[0].valid_lines - 1;
  if (last1 < files[1].valid_lines - context)
    last1 += context;
  else
    last1 = files[1].valid_lines - 1;

  /* If desired, find the preceding function definition line in file 0.  */
  function = NULL;
  if (function_regexp.fastmap)
    function = find_function (files[0].linbuf, first0);

  begin_output ();
  out = outfile;

  fputs ("***************", out);

  if (function)
    print_context_function (out, function);

  putc ('\n', out);
  set_color_context (LINE_NUMBER_CONTEXT);
  fputs ("*** ", out);
  print_context_number_range (&files[0], first0, last0);
  fputs (" ****", out);
  set_color_context (RESET_CONTEXT);
  putc ('\n', out);

  if (changes & OLD)
    {
      struct change *next = hunk;

      if (first0 <= last0)
        set_color_context (DELETE_CONTEXT);

      for (i = first0; i <= last0; i++)
	{
	  /* Skip past changes that apply (in file 0)
	     only to lines before line I.  */

	  while (next && next->line0 + next->deleted <= i)
	    next = next->link;

	  /* Compute the marking for line I.  */

	  prefix = " ";
	  if (next && next->line0 <= i)
            {
              /* The change NEXT covers this line.
                 If lines were inserted here in file 1, this is "changed".
                 Otherwise it is "deleted".  */
              prefix = (next->inserted > 0 ? "!" : "-");
            }
	  print_1_line_nl (prefix, &files[0].linbuf[i], true);
          if (i == last0)
            set_color_context (RESET_CONTEXT);
          if (files[0].linbuf[i + 1][-1] == '\n')
            putc ('\n', out);
	}
    }

  set_color_context (LINE_NUMBER_CONTEXT);
  fputs ("--- ", out);
  print_context_number_range (&files[1], first1, last1);
  fputs (" ----", out);
  set_color_context (RESET_CONTEXT);
  putc ('\n', out);

  if (changes & NEW)
    {
      struct change *next = hunk;

      if (first1 <= last1)
        set_color_context (ADD_CONTEXT);

      for (i = first1; i <= last1; i++)
	{
	  /* Skip past changes that apply (in file 1)
	     only to lines before line I.  */

	  while (next && next->line1 + next->inserted <= i)
	    next = next->link;

	  /* Compute the marking for line I.  */

	  prefix = " ";
	  if (next && next->line1 <= i)
            {
              /* The change NEXT covers this line.
                 If lines were deleted here in file 0, this is "changed".
                 Otherwise it is "inserted".  */
              prefix = (next->deleted > 0 ? "!" : "+");
            }
	  print_1_line_nl (prefix, &files[1].linbuf[i], true);
          if (i == last1)
            set_color_context (RESET_CONTEXT);
          if (files[1].linbuf[i + 1][-1] == '\n')
            putc ('\n', out);
	}
    }
}
Esempio n. 27
0
/* Checks whether function with specified name exists or not.  Returns non-zero
 * if function with specified name is already registered. */
static int
function_registered(const char func_name[])
{
	return find_function(func_name) != NULL;
}
Esempio n. 28
0
void* find_free() {
	return find_function("free", TARGET_BASEADDR, TARGET_BASEADDR);
}
Esempio n. 29
0
static void
pr_unidiff_hunk (struct change *hunk)
{
  lin first0, last0, first1, last1;
  lin i, j, k;
  struct change *next;
  char const *function;
  FILE *out;

  /* Determine range of line numbers involved in each file.  */

  if (! analyze_hunk (hunk, &first0, &last0, &first1, &last1))
    return;

  /* Include a context's width before and after.  */

  i = - files[0].prefix_lines;
  first0 = MAX (first0 - context, i);
  first1 = MAX (first1 - context, i);
  if (last0 < files[0].valid_lines - context)
    last0 += context;
  else
    last0 = files[0].valid_lines - 1;
  if (last1 < files[1].valid_lines - context)
    last1 += context;
  else
    last1 = files[1].valid_lines - 1;

  /* If desired, find the preceding function definition line in file 0.  */
  function = NULL;
  if (function_regexp.fastmap)
    function = find_function (files[0].linbuf, first0);

  begin_output ();
  out = outfile;

  set_color_context (LINE_NUMBER_CONTEXT);
  fputs ("@@ -", out);
  print_unidiff_number_range (&files[0], first0, last0);
  fputs (" +", out);
  print_unidiff_number_range (&files[1], first1, last1);
  fputs (" @@", out);
  set_color_context (RESET_CONTEXT);

  if (function)
    print_context_function (out, function);

  putc ('\n', out);

  next = hunk;
  i = first0;
  j = first1;

  while (i <= last0 || j <= last1)
    {

      /* If the line isn't a difference, output the context from file 0. */

      if (!next || i < next->line0)
	{
	  char const *const *line = &files[0].linbuf[i++];
	  if (! (suppress_blank_empty && **line == '\n'))
	    putc (initial_tab ? '\t' : ' ', out);
	  print_1_line (NULL, line);
	  j++;
	}
      else
	{
	  /* For each difference, first output the deleted part. */

	  k = next->deleted;
          if (k)
            set_color_context (DELETE_CONTEXT);

	  while (k--)
	    {
	      char const * const *line = &files[0].linbuf[i++];
	      putc ('-', out);
	      if (initial_tab && ! (suppress_blank_empty && **line == '\n'))
		putc ('\t', out);
	      print_1_line_nl (NULL, line, true);

              if (!k)
                set_color_context (RESET_CONTEXT);

              if (line[1][-1] == '\n')
                putc ('\n', out);
	    }

	  /* Then output the inserted part. */

	  k = next->inserted;
          if (k)
            set_color_context (ADD_CONTEXT);

          while (k--)
	    {
	      char const * const *line = &files[1].linbuf[j++];
	      putc ('+', out);
	      if (initial_tab && ! (suppress_blank_empty && **line == '\n'))
		putc ('\t', out);
	      print_1_line_nl (NULL, line, true);

              if (!k)
                set_color_context (RESET_CONTEXT);

              if (line[1][-1] == '\n')
                putc ('\n', out);
	    }

	  /* We're done with this hunk, so on to the next! */

	  next = next->link;
	}
    }
}
Esempio n. 30
0
void* find_fsboot() {
    return find_function("fsboot", TARGET_BASEADDR, TARGET_BASEADDR);
}