File: evalx.c

package info (click to toggle)
ht 2.0.20-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,324 kB
  • sloc: cpp: 97,563; ansic: 17,183; sh: 3,811; lex: 226; makefile: 213; yacc: 127
file content (50 lines) | stat: -rw-r--r-- 1,165 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "evaltype.h"
#include "eval.h"
#include "lex.h"

extern int yyparse(eval_scalar *result);
	
int eval(eval_scalar *r, const char *str, eval_func_handler func_handler, eval_symbol_handler symbol_handler, void *context)
{
	void *oldbuffer = lex_current_buffer();
	void *strbuffer;
	eval_scalar result;
/*     if (get_helpmode()) {
		eval_scalar *hs = get_helpstring();
		scalar_create_str_c(hs, "");
		strbuffer = lex_scan_string_buffer("NaF()");
	} else {*/
		strbuffer = lex_scan_string_buffer(str);
/*     }*/

	DEBUG_DUMP("evaluating \"%s\":", str);
	DEBUG_DUMP_INDENT_IN;
	
	clear_eval_error();
	
	eval_set_context(context);
	eval_set_func_handler(func_handler);
	eval_set_symbol_handler(symbol_handler);

	result.type=SCALAR_NULL;
	yyparse(&result);
	
	lex_delete_buffer(strbuffer);
	if (oldbuffer) lex_switch_buffer(oldbuffer);
	
/*     if (get_helpmode()) {
		eval_scalar *hs = get_helpstring();
		*r = *hs;
		hs->type = SCALAR_NULL;
		clear_eval_error();
	} else {*/
		if (result.type == SCALAR_NULL) return 0;
		*r = result;
		if (get_eval_error(0, 0)) return 0;
/*	}*/
	
	DEBUG_DUMP_INDENT_OUT;
	DEBUG_DUMP_SCALAR(r, "eval result:");

	return 1;
}