Exemple #1
0
static int edit_do_setmem()
{
  LONG addr,value;
  int bits = 32;
  char size;
  char dst[1024],*tmp;

  if(strlen(edit.text) == 0) return EDIT_FAILURE;
  if(strchr(edit.text, '=') != strrchr(edit.text, '=')) return EDIT_FAILURE;

  strcpy(dst, edit.text);
  tmp = strchr(dst, '=');
  if(tmp) {
    tmp[0] = '\0';
    tmp++;
    if(strlen(tmp) == 0) return EDIT_FAILURE;
  } else {
    return EDIT_FAILURE;
  }

  if(dst[strlen(dst)-2] == '.') {
    size = dst[strlen(dst)-1];
    if(size == 'b' || size == 'B' || size == 's' || size == 'S') {
      bits = 8;
    }
    if(size == 'w' || size == 'W') {
      bits = 16;
    }
    if(size == 'l' || size == 'L') {
      bits = 32;
    }
    dst[strlen(dst)-2] = '\0';
  }
  
  if(expr_parse(&addr, dst) == EXPR_FAILURE)
    return EDIT_FAILURE;

  if(expr_parse(&value, tmp) == EXPR_FAILURE)
    return EDIT_FAILURE;

  if(bits == 8) {
    bus_write_byte(addr, value&0xff);
  }
  if(bits == 16) {
    bus_write_word(addr, value&0xffff);
  }
  if(bits == 32) {
    bus_write_long(addr, value);
  }
  
  return EDIT_SUCCESS;
}
gboolean
conscience_srvtype_set_type_expression(struct conscience_srvtype_s * srvtype,
	GError ** err, const gchar * expr_str)
{
	struct expr_s *pE;

	if (!srvtype || !expr_str) {
		GSETCODE(err, ERRCODE_PARAM, "Invalid parameter");
		return FALSE;
	}

	pE = NULL;
	if (expr_parse(expr_str, &pE)) {
		GSETCODE(err, CODE_INTERNAL_ERROR, "Failed to parse the expression");
		return FALSE;
	}

	/*replaces the string */
	if (srvtype->score_expr_str)
		g_free(srvtype->score_expr_str);
	if (srvtype->score_expr)
		expr_clean(srvtype->score_expr);

	srvtype->score_expr_str = g_strdup(expr_str);
	srvtype->score_expr = pE;
	return TRUE;
}
Exemple #3
0
const char *attmap_get_value(MYLDAP_ENTRY *entry, const char *attr,
                             char *buffer, size_t buflen)
{
  const char **values;
  /* check and clear buffer */
  if ((buffer == NULL) || (buflen <= 0))
    return NULL;
  buffer[0] = '\0';
  /* for simple values just return the attribute */
  if (attr[0] != '"')
  {
    values = myldap_get_values(entry, attr);
    if ((values == NULL) || (values[0] == NULL))
      return NULL;
    strncpy(buffer, values[0], buflen);
    buffer[buflen - 1] = '\0';
    return buffer;
    /* TODO: maybe warn when multiple values are found */
  }
  /* we have an expression, try to parse */
  if ((attr[strlen(attr) - 1] != '"') ||
      (expr_parse(attr + 1, buffer, buflen, entry_expand, (void *)entry) == NULL))
  {
    log_log(LOG_ERR, "attribute mapping %s is invalid", attr);
    buffer[0] = '\0';
    return NULL;
  }
  /* strip trailing " */
  if (buffer[strlen(buffer) - 1] == '"')
    buffer[strlen(buffer) - 1] = '\0';
  return buffer;
}
int main(int argc, char* argv[]) {
  if(argc !=2 ) {
    fprintf(stderr,"usage: expr-parser FILE\n");
    exit(1);
  }
  
  Expr* expr = expr_parse(argv[1]);
  printf("expr = ");
  expr_print(expr);
  printf("\n%d\n", expr_interpret(expr));
}
Exemple #5
0
static int edit_do_setreg()
{
  LONG addr;
  char text[80],*tmp;
  
  if(strlen(edit.text) == 0) return EDIT_FAILURE;
  if(strchr(edit.text, '=') != strrchr(edit.text, '=')) return EDIT_FAILURE;

  strcpy(text, edit.text);

  tmp = strchr(text, '=');
  if(!tmp) return EDIT_FAILURE;
  tmp[0] = '\0';
  tmp++;
  if(strlen(tmp) == 0) return EDIT_FAILURE;
  if((strlen(text) != 2) && 
     strcasecmp("ssp", text) &&
     strcasecmp("usp", text))
    return EDIT_FAILURE;

  if(expr_parse(&addr, tmp) == EXPR_FAILURE)
    return EDIT_FAILURE;

  if(!strcasecmp("ssp", text)) {
    cpu->ssp = addr;
    if(CHKS) cpu->a[7] = addr;
  } else if(!strcasecmp("usp", text)) {
    cpu->usp = addr;
    if(!CHKS) cpu->a[7] = addr;
  } else if(edit_match_areg(text)) {
    cpu->a[text[1]-'0'] = addr;
  } else if(edit_match_dreg(text)) {
    cpu->d[text[1]-'0'] = addr;
  } else if(edit_match_win(text)) {
    win[text[1]-'0'].addr = addr;
  } else if(!strcasecmp("pc", text)) {
    cpu->pc = addr;
  } else if(!strcasecmp("sr", text)) {
    cpu->sr = addr&0xffff;
  } else {
    return EDIT_FAILURE;
  }

  return EDIT_SUCCESS;
}
Exemple #6
0
void eval_print(data_t a, data_t b, int nsteps, struct parse_options po,
		struct expr_environ *env, struct input inp, data_t *ans_data)
{
	struct objcode *oc;
	struct compile_error ce;
	
	ce = expr_parse(inp, env, po, &oc);
	
	if (ce.type == -E_OK) {
		struct expr *ex;
		
		if ((ex = expr_assemble(oc)) != NULL) {
			data_t *rets = NULL;
			int r;
			
			if (!nsteps) {
				r = expr_eval(ex, &rets, NULL);
				if (r == -E_OK) {
					*ans_data = expr_get_ret(rets, 0);
				} else {
					EE("Eval failed\n");
				}
				free(rets);
			} else {
				*ans_data = rect_int(a, b, nsteps, ex);
			}
			printf("%g ;", *ans_data);
			putchar('\n');
			
			destroy_expr(ex);
		} else {
			EE("Assembly failed\n");
		}
		destroy_oc(oc);
	} else {
		char *s;
		s = ce_to_str(ce,1,1);
		fputs(s, stderr);
		fputc('\n', stderr);
		free(s);
	}
	
	destroy_ce(&ce);
}
Exemple #7
0
static int edit_do_setaddr()
{
  LONG addr;
  int selwin;

  selwin = win_get_selected();

  addr = 0;

  if(strlen(edit.text) == 0) return EDIT_FAILURE;

  if(expr_parse(&addr, edit.text) == EXPR_SUCCESS) {
    win[selwin].addr = addr;
    if(win[selwin].type == TYPE_DIS)
      win[selwin].addr = (win[selwin].addr+1)&0xfffffe;
    return EDIT_SUCCESS;
  }

  return EDIT_FAILURE;
}
Exemple #8
0
static int edit_do_setbrk()
{
  LONG addr;
  int cnt;
  char text[80],*tmp;
  
  if(strlen(edit.text) == 0) return EDIT_FAILURE;
  if(strchr(edit.text, ',') != strrchr(edit.text, ',')) return EDIT_FAILURE;

  strcpy(text, edit.text);

  tmp = strchr(text, ',');
  if(tmp) {
    tmp[0] = '\0';
    tmp++;
    if(strlen(tmp) == 0) return EDIT_FAILURE;
    if(tmp[0] == '-') {
      cnt = 0;
    } else if((tmp[0] >= '0') && (tmp[0] <= '9')) {
      cnt = strtol(tmp, NULL, 10);
    } else {
      return EDIT_FAILURE;
    }
  } else {
    cnt = -1;
  }

  if(expr_parse(&addr, text) == EXPR_FAILURE)
    return EDIT_FAILURE;

  if(cnt == 0) {
    if(cpu_unset_breakpoint(addr))
      return EDIT_FAILURE;
    return EDIT_SUCCESS;
  } else if(cnt) {
    cpu_set_breakpoint(addr, cnt);
    return EDIT_SUCCESS;
  }
  
  return EDIT_FAILURE;
}
Exemple #9
0
static uint16_t if_define_replace(bstring define)
{
    // Search through all of the defines to find one where
    // the name matches.
    size_t i = 0;
    match_t* match;
    struct expr* tree;
    for (i = 0; i < list_size(&replace_state->handlers); i++)
    {
        match = list_get_at(&replace_state->handlers, i);
        if (biseq(match->text.ref, define))
        {
            // Found a match.
            tree = expr_parse(match->userdata);
            if (tree == NULL)
                dhalt(ERR_PP_DEFINE_NOT_EXPRESSION, ppimpl_get_location(replace_state));
            return expr_evaluate(tree, &if_define_replace, &dhalt_expression_exit_handler);
        }
    }
    dhalt(ERR_PP_DEFINE_NOT_FOUND, ppimpl_get_location(replace_state));
    return 0;
}
Exemple #10
0
static int edit_do_label()
{
  LONG addr;
  char text[80],*tmp;
  
  if(strlen(edit.text) == 0) return EDIT_FAILURE;
  if(strchr(edit.text, ',') != strrchr(edit.text, ',')) return EDIT_FAILURE;

  strcpy(text, edit.text);

  tmp = strchr(text, ',');
  if(!tmp) return EDIT_FAILURE;

  tmp[0] = '\0';
  tmp++;
  if(strlen(tmp) == 0) return EDIT_FAILURE;

  if(expr_parse(&addr, tmp) == EXPR_FAILURE)
    return EDIT_FAILURE;

  cprint_set_label(addr, strdup(text));
  return EDIT_SUCCESS;
}
Exemple #11
0
int ausearch_add_expression(auparse_state_t *au, const char *expression,
			    char **error, ausearch_rule_t how)
{
	struct expr *expr;

	if (how < AUSEARCH_RULE_CLEAR || how > AUSEARCH_RULE_AND)
		goto err_einval;

	expr = expr_parse(expression, error);
	if (expr == NULL) {
		errno = EINVAL;
		return -1;
	}

	if (add_expr(au, expr, how) != 0)
		goto err; /* expr is freed by add_expr() */
	return 0;

err_einval:
	errno = EINVAL;
err:
	*error = NULL;
	return -1;
}
Exemple #12
0
/* save the current scanner context and parse the given expression */
struct Expr *parse_expr(char *expr_text)
{
	Expr *expr;
	int num_errors;

	save_scan_state();
	{
		src_push();
		{
			SetTemporaryLine(expr_text);
			num_errors = get_num_errors();
			EOL = FALSE;
			scan_expect_operands();
			GetSym();
			expr = expr_parse();		/* may output error */
			if (sym.tok != TK_END && num_errors == get_num_errors())
				error_syntax();
		}
		src_pop();
	}
	restore_scan_state();
	
	return expr;
}