Execute a parse tree.
802 tree_cell *ret = NULL, *ret2 = NULL, *tc1 = NULL, *tc2 = NULL, *tc3 =
803 NULL, *idx = NULL, *args;
805 char *s1 = NULL, *s2 = NULL, *s3 = NULL, *p = NULL;
818 if (st->line_nb != 0)
819 lexic->line_nb = st->line_nb;
821 if (lexic->ret_val != NULL)
824 return lexic->ret_val;
828 if (lexic->break_flag || lexic->cont_flag)
849 #ifdef STOP_AT_FIRST_ERROR 853 if (cell2bool (lexic, ret))
855 else if (st->link[2] != NULL)
866 nasl_perror (lexic,
"Instruction failed. Going on in block\n");
868 if (st->link[1] == NULL || lexic->break_flag || lexic->cont_flag)
877 #ifdef STOP_AT_FIRST_ERROR 885 if (lexic->ret_val != NULL)
888 return lexic->ret_val;
892 if ((ret =
nasl_exec (lexic, st->link[1])) == NULL)
894 flag = cell2bool (lexic, ret);
900 #ifdef STOP_AT_FIRST_ERROR 907 if (lexic->break_flag)
909 lexic->break_flag = 0;
913 lexic->cont_flag = 0;
917 #ifdef STOP_AT_FIRST_ERROR 930 if (lexic->ret_val != NULL)
933 return lexic->ret_val;
936 if ((ret =
nasl_exec (lexic, st->link[0])) == NULL)
938 flag = cell2bool (lexic, ret);
944 #ifdef STOP_AT_FIRST_ERROR 951 if (lexic->break_flag)
953 lexic->break_flag = 0;
956 lexic->cont_flag = 0;
965 if (lexic->ret_val != NULL)
968 return lexic->ret_val;
972 #ifdef STOP_AT_FIRST_ERROR 979 if (lexic->break_flag)
981 lexic->break_flag = 0;
984 lexic->cont_flag = 0;
988 #ifdef STOP_AT_FIRST_ERROR 992 flag = cell2bool (lexic, ret);
1016 #ifdef STOP_AT_FIRST_ERROR 1023 if (lexic->ret_val != NULL)
1026 if (lexic->break_flag)
1028 lexic->break_flag = 0;
1031 lexic->cont_flag = 0;
1047 nasl_perror (lexic,
"Undefined function '%s'\n", st->x.str_val);
1052 printf (
"****************\n");
1054 printf (
"****************\n");
1060 n = cell2intW (lexic, st->link[1]);
1064 #ifdef STOP_AT_FIRST_ERROR 1065 for (tc1 = NULL, i = 1; i <= n; i++)
1068 if ((tc1 =
nasl_exec (lexic, st->link[0])) == NULL)
1073 for (i = 1; i <= n; i++)
1101 lexic->break_flag = 1;
1105 lexic->cont_flag = 1;
1218 x = cell2bool (lexic, st->link[0]);
1220 return bool2cell (0);
1222 y = cell2bool (lexic, st->link[1]);
1223 return bool2cell (y);
1227 x = cell2bool (lexic, st->link[0]);
1229 return bool2cell (x);
1230 y = cell2bool (lexic, st->link[1]);
1231 return bool2cell (y);
1234 x = cell2bool (lexic, st->link[0]);
1235 return bool2cell (!x);
1240 if (st->link[0] == NULL)
1257 if (st->link[0] == NULL)
1266 #ifdef STOP_AT_FIRST_ERROR 1273 #ifdef STOP_AT_FIRST_ERROR 1300 "Horrible type conversion (int -> str) for operator + %s\n",
1308 y = cell2int (lexic, tc2);
1309 ret = int2cell (x + y);
1319 s1 = cell2str (lexic, tc1);
1320 len1 = (s1 == NULL ? 0 : strlen (s1));
1327 s2 = cell2str (lexic, tc2);
1328 len2 = (s2 == NULL ? 0 : strlen (s2));
1332 s3 = g_malloc0 (sz + 1);
1334 memcpy (s3, s1 != NULL ? s1 : tc1->x.str_val, len1);
1336 memcpy (s3 + len1, s2 != NULL ? s2 : tc2->x.str_val, len2);
1355 #ifdef STOP_AT_FIRST_ERROR 1362 #ifdef STOP_AT_FIRST_ERROR 1374 y = cell2int (lexic, tc2);
1375 ret = int2cell (-y);
1400 "Horrible type conversion (int -> str) for operator - %s\n",
1406 x = cell2int (lexic, tc1);
1407 y = cell2int (lexic, tc2);
1408 ret = int2cell (x - y);
1415 p1 = tc1->x.str_val;
1420 p1 = s1 = cell2str (lexic, tc1);
1421 len1 = (s1 == NULL ? 0 : strlen (s1));
1426 p2 = tc2->x.str_val;
1431 p2 = s2 = cell2str (lexic, tc2);
1432 len2 = (s2 == NULL ? 0 : strlen (s2));
1435 if (len2 == 0 || len1 < len2
1436 || (p = memmem (p1, len1, p2, len2)) == NULL)
1438 s3 = g_malloc0 (len1 + 1);
1439 memcpy (s3, p1, len1);
1446 long sz = len1 - len2;
1454 s3 = g_malloc0 (sz + 1);
1456 memcpy (s3, p1, p - p1);
1458 memcpy (s3 + (p - p1), p + len2, sz - (p - p1));
1478 x = cell2intW (lexic, st->link[0]);
1479 y = cell2intW (lexic, st->link[1]);
1480 return int2cell (x * y);
1483 x = cell2intW (lexic, st->link[0]);
1484 y = cell2intW (lexic, st->link[1]);
1486 return int2cell (x / y);
1488 return int2cell (0);
1491 x = cell2intW (lexic, st->link[0]);
1492 y = cell2intW (lexic, st->link[1]);
1493 return int2cell (expo (x, y));
1496 x = cell2intW (lexic, st->link[0]);
1497 y = cell2intW (lexic, st->link[1]);
1499 return int2cell (x % y);
1501 return int2cell (0);
1504 x = cell2intW (lexic, st->link[0]);
1505 y = cell2intW (lexic, st->link[1]);
1506 return int2cell (x & y);
1509 x = cell2intW (lexic, st->link[0]);
1510 y = cell2intW (lexic, st->link[1]);
1511 return int2cell (x | y);
1514 x = cell2intW (lexic, st->link[0]);
1515 y = cell2intW (lexic, st->link[1]);
1516 return int2cell (x ^ y);
1519 x = cell2intW (lexic, st->link[0]);
1520 return int2cell (~x);
1523 x = cell2intW (lexic, st->link[0]);
1524 return int2cell (-x);
1528 x = cell2intW (lexic, st->link[0]);
1529 y = cell2intW (lexic, st->link[1]);
1530 return int2cell (x << y);
1533 x = cell2intW (lexic, st->link[0]);
1534 y = cell2intW (lexic, st->link[1]);
1537 nasl_perror (lexic,
"Warning: Negative count in right shift!\n");
1541 if (x < 0 && z >= 0)
1545 "Warning: arithmetic right shift is buggy! Fixing...\n");
1547 z |= (~0) << (
sizeof (x) * 8 - y);
1550 return int2cell (z);
1553 x = cell2intW (lexic, st->link[0]);
1554 y = cell2intW (lexic, st->link[1]);
1557 nasl_perror (lexic,
"Warning: Negative count in right shift!\n");
1559 z = (unsigned) x >> (
unsigned) y;
1561 if (x < 0 && z <= 0)
1565 "Warning: Logical right shift is buggy! Fixing...\n");
1567 z &= ~((~0) << (
sizeof (x) * 8 - y));
1570 return int2cell (z);
1585 p1 = tc1->x.str_val;
1592 "Horrible type conversion (%s -> str) for operator >< or >!< %s\n",
1595 p1 = s1 = cell2str (lexic, tc1);
1606 p2 = tc2->x.str_val;
1613 "Horrible type conversion (%s -> str) for operator >< or >!< %s\n",
1616 p2 = s2 = cell2str (lexic, tc2);
1621 flag = (memmem (p2, len2, p1, len1) != NULL);
1630 return bool2cell (flag);
1632 return bool2cell (!flag);
1636 if (st->x.ref_val == NULL)
1638 nasl_perror (lexic,
"nasl_exec: bad regex at or near line %d\n",
1642 s1 = cell2str (lexic, st->link[0]);
1645 flag = regexec (st->x.ref_val, s1, 0, NULL, 0);
1648 return bool2cell (flag != REG_NOMATCH);
1650 return bool2cell (flag == REG_NOMATCH);
1653 return bool2cell (
cell_cmp (lexic, st->link[0], st->link[1]) < 0);
1656 return bool2cell (
cell_cmp (lexic, st->link[0], st->link[1]) <= 0);
1659 return bool2cell (
cell_cmp (lexic, st->link[0], st->link[1]) == 0);
1662 return bool2cell (
cell_cmp (lexic, st->link[0], st->link[1]) != 0);
1665 return bool2cell (
cell_cmp (lexic, st->link[0], st->link[1]) > 0);
1668 return bool2cell (
cell_cmp (lexic, st->link[0], st->link[1]) >= 0);
1683 nasl_perror (lexic,
"nasl_exec: unhandled node type %d\n", st->type);
tree_cell * nasl_return(lex_ctxt *ctxt, tree_cell *retv)
void ref_cell(tree_cell *c)
void nasl_dump_tree(const tree_cell *c)
tree_cell * cell2atom(lex_ctxt *lexic, tree_cell *c1)
void deref_cell(tree_cell *c)
tree_cell * nasl_incr_variable(lex_ctxt *, tree_cell *, int, int)
tree_cell * decl_local_variables(lex_ctxt *, tree_cell *)
tree_cell * get_variable_by_name(lex_ctxt *, const char *)
long int cell_cmp(lex_ctxt *lexic, tree_cell *c1, tree_cell *c2)
void nasl_perror(lex_ctxt *lexic, char *msg,...)
tree_cell * nasl_func_call(lex_ctxt *lexic, const nasl_func *f, tree_cell *arg_list)
tree_cell * get_array_elem(lex_ctxt *, const char *, tree_cell *)
nasl_iterator nasl_array_iterator(void *ctxt, tree_cell *c)
tree_cell * nasl_iterate_array(nasl_iterator *it)
tree_cell * alloc_tree_cell(int lnb, char *s)
const char * nasl_type_name(int t)
tree_cell * nasl_read_var_ref(lex_ctxt *, tree_cell *)
char * get_line_nb(const tree_cell *c)
tree_cell * alloc_expr_cell(int lnb, int t, tree_cell *l, tree_cell *r)
tree_cell * decl_global_variables(lex_ctxt *, tree_cell *)
tree_cell * nasl_affect(tree_cell *lval, tree_cell *rval)
nasl_func * get_func_ref_by_name(lex_ctxt *ctxt, const char *name)
tree_cell * nasl_exec(lex_ctxt *lexic, tree_cell *st)
Execute a parse tree.
tree_cell * decl_nasl_func(lex_ctxt *lexic, tree_cell *decl_node)