示例#1
0
static int cin_get_num(RNum *num, RNumCalc *nc, RNumCalcValue *n) {
	double d;
	char str[R_NUMCALC_STRSZ]; // TODO: move into the heap?
	int i = 0;
	char c;
	str[0] = 0;
	while (cin_get (num, nc, &c)) {
		if (c != '_' && c!=':' && c!='.' && !isalnum ((ut8)c)) {
			cin_putback (num, nc, c);
			break;
		}
		if (i < R_NUMCALC_STRSZ) {
			str[i++] = c;
		}
	}
	str[i] = 0;
	*n = Nset (r_num_get (num, str));
	if (IS_DIGIT (*str) && strchr (str, '.')) {
		if (sscanf (str, "%lf", &d) < 1) {
			return 0;
		}
		if (n->n < d) {
			*n = Nsetf (d);
		}
		n->d = d;
	}
	return 1;
}
示例#2
0
static int cin_get_num(RNum *num, RNumCalc *nc, RNumCalcValue *n) {
	double d;
	char str[R_NUMCALC_STRSZ];
	int i = 0;
	char c;
	str[0] = 0;
	while (cin_get (num, nc, &c)) {
		if (c!=':' && c!='.' && !isalnum ((unsigned char)c)) {
			cin_putback (num, nc, c);
			break;
		}
		if (i<R_NUMCALC_STRSZ) {
			str[i++] = c;
		}
	}
	str[i] = 0;
	*n = Nset (r_num_get (num, str));
	if (*str>='0' && *str<='9' && strchr (str, '.')) {
		if (sscanf (str, "%lf", &d)<1)
			return 0;
		*n = Nsetf (d);
	}
#if 0
// XXX: use r_num_get here
	if (str[0]=='0' && str[1]=='x') {
		ut64 x = 0;
		if (sscanf (str+2, "%llx", &x)<1)
			return 0;
		*n = Nset (x);
	} else
	if (strchr (str, '.')) {
		if (sscanf (str, "%lf", &d)<1)
			return 0;
		*n = Nsetf (d);
	} else {
		ut64 u;
		if (sscanf (str, "%"PFMT64d, &u)<1)
			return 0;
		*n = Nset (u);
	}
#endif
	return 1;
}
示例#3
0
文件: calc.c 项目: ericfode/radare2
static int cin_get_num(NumValue *n) {
	double d;
	char str[128];
	int i = 0;
	char c;
	str[0] = 0;
	while (cin_get (&c)) {
		if (c!=':' && c!='.' && !isalnum (c)) {
			cin_putback (c);
			break;
		}
		if (i<STRSZ)
			str[i++] = c;
	}
	str[i] = 0;
	*n = Nset (r_num_get (calc_num, str));
	if (*str>='0' && *str<='9' && strchr (str, '.')) {
		if (sscanf (str, "%lf", &d)<1)
			return 0;
		*n = Nsetf (d);
	}
#if 0
// XXX: use r_num_get here
	if (str[0]=='0' && str[1]=='x') {
		ut64 x = 0;
		if (sscanf (str+2, "%llx", &x)<1)
			return 0;
		*n = Nset (x);
	} else
	if (strchr (str, '.')) {
		if (sscanf (str, "%lf", &d)<1)
			return 0;
		*n = Nsetf (d);
	} else {
		ut64 u;
		if (sscanf (str, "%"PFMT64d, &u)<1)
			return 0;
		*n = Nset (u);
	}
#endif
	return 1;
}
示例#4
0
static RNumCalcValue prim(RNum *num, RNumCalc *nc, int get) {
	RNumCalcValue v = {0};
	if (get) get_token (num, nc);
	switch (nc->curr_tok) {
	case RNCNUMBER:
		v = nc->number_value;
		get_token (num, nc);
		return v;
	case RNCNAME:
		//fprintf (stderr, "error: unknown keyword (%s)\n", nc->string_value);
		//double& v = table[nc->string_value];
		r_str_chop (nc->string_value);
		v = Nset (r_num_get (num, nc->string_value));
		get_token (num, nc);
		if (nc->curr_tok  == RNCASSIGN) {
			v = expr (num, nc, 1);
		}
		if (nc->curr_tok == RNCINC) Naddi (v, 1);
		if (nc->curr_tok == RNCDEC) Nsubi (v, 1);
		return v;
	case RNCNEG:
		v = nc->number_value;
		get_token (num, nc);
		return Nneg (nc->number_value); //prim (num, nc, 1), 1);
	case RNCINC: return Naddi (prim (num, nc, 1), 1);
	case RNCDEC: return Naddi (prim (num, nc, 1), -1);
	case RNCORR: return Norr (v, prim (num, nc, 1));
	case RNCMINUS: return Nsub (v, prim (num, nc, 1));
	case RNCLEFTP:
		v = expr (num, nc, 1);
		if (nc->curr_tok == RNCRIGHTP) {
			get_token (num, nc);
		} else error (num, nc, " ')' expected");
	case RNCEND:
	case RNCXOR:
	case RNCAND:
	case RNCPLUS:
	case RNCMOD:
	case RNCMUL:
	case RNCDIV:
	case RNCPRINT:
	case RNCASSIGN:
	case RNCRIGHTP:
		return v;
	//default: error (num, nc, "primary expected");
	}
	return v;
}
示例#5
0
文件: calc.c 项目: ericfode/radare2
static NumValue prim(int get) {
	NumValue v = {0};
	if (get) get_token ();
	switch (curr_tok) {
	case NUMBER:
		v = number_value;
		get_token ();
		return v;
	case NAME:
		//fprintf (stderr, "error: unknown keyword (%s)\n", string_value);
		//double& v = table[string_value];
		r_str_chop (string_value);
		v = Nset (r_num_get (calc_num, string_value));
		get_token ();
		if (curr_tok  == ASSIGN) 
			v = expr (1);
		if (curr_tok == INC) Naddi (v, 1);
		if (curr_tok == DEC) Nsubi (v, 1);
		return v;
	case INC: return Naddi (prim (1), 1);
	case DEC: return Naddi (prim (1), -1);
	case MINUS: return Nsub (v, prim (1));
	case LEFTP:
		v = expr (1);
		if (curr_tok == RIGHTP)
			get_token ();
		else error (" ')' expected");
	case END:
	case PLUS:
	case MUL:
	case DIV:
	case PRINT:
	case ASSIGN:
	case RIGHTP:
		return v;
	//default: error ("primary expected");
	}
	return v;
}