Lines Matching refs:parse
77 static NEOERR *literal_parse (CSPARSE *parse, int cmd, char *arg);
78 static NEOERR *literal_eval (CSPARSE *parse, CSTREE *node, CSTREE **next);
79 static NEOERR *name_parse (CSPARSE *parse, int cmd, char *arg);
80 static NEOERR *name_eval (CSPARSE *parse, CSTREE *node, CSTREE **next);
81 static NEOERR *var_parse (CSPARSE *parse, int cmd, char *arg);
82 static NEOERR *var_eval (CSPARSE *parse, CSTREE *node, CSTREE **next);
83 static NEOERR *evar_parse (CSPARSE *parse, int cmd, char *arg);
84 static NEOERR *lvar_parse (CSPARSE *parse, int cmd, char *arg);
85 static NEOERR *lvar_eval (CSPARSE *parse, CSTREE *node, CSTREE **next);
86 static NEOERR *if_parse (CSPARSE *parse, int cmd, char *arg);
87 static NEOERR *if_eval (CSPARSE *parse, CSTREE *node, CSTREE **next);
88 static NEOERR *else_parse (CSPARSE *parse, int cmd, char *arg);
89 static NEOERR *elif_parse (CSPARSE *parse, int cmd, char *arg);
90 static NEOERR *endif_parse (CSPARSE *parse, int cmd, char *arg);
91 static NEOERR *each_with_parse (CSPARSE *parse, int cmd, char *arg);
92 static NEOERR *each_eval (CSPARSE *parse, CSTREE *node, CSTREE **next);
93 static NEOERR *with_eval (CSPARSE *parse, CSTREE *node, CSTREE **next);
94 static NEOERR *end_parse (CSPARSE *parse, int cmd, char *arg);
95 static NEOERR *include_parse (CSPARSE *parse, int cmd, char *arg);
96 static NEOERR *linclude_parse (CSPARSE *parse, int cmd, char *arg);
97 static NEOERR *linclude_eval (CSPARSE *parse, CSTREE *node, CSTREE **next);
98 static NEOERR *def_parse (CSPARSE *parse, int cmd, char *arg);
99 static NEOERR *skip_eval (CSPARSE *parse, CSTREE *node, CSTREE **next);
100 static NEOERR *call_parse (CSPARSE *parse, int cmd, char *arg);
101 static NEOERR *call_eval (CSPARSE *parse, CSTREE *node, CSTREE **next);
102 static NEOERR *set_parse (CSPARSE *parse, int cmd, char *arg);
103 static NEOERR *set_eval (CSPARSE *parse, CSTREE *node, CSTREE **next);
104 static NEOERR *loop_parse (CSPARSE *parse, int cmd, char *arg);
105 static NEOERR *loop_eval (CSPARSE *parse, CSTREE *node, CSTREE **next);
106 static NEOERR *alt_parse (CSPARSE *parse, int cmd, char *arg);
107 static NEOERR *alt_eval (CSPARSE *parse, CSTREE *node, CSTREE **next);
108 static NEOERR *escape_parse (CSPARSE *parse, int cmd, char *arg);
109 static NEOERR *escape_eval (CSPARSE *parse, CSTREE *node, CSTREE **next);
111 static NEOERR *render_node (CSPARSE *parse, CSTREE *node);
112 static NEOERR *cs_init_internal (CSPARSE **parse, HDF *hdf, CSPARSE *parent);
121 NEOERR* (*parse_handler)(CSPARSE *parse, int cmd, char *arg);
122 NEOERR* (*eval_handler)(CSPARSE *parse, CSTREE *node, CSTREE **next);
204 static void init_node_pos(CSTREE *node, CSPARSE *parse)
206 CS_POSITION *pos = &parse->pos;
209 if (parse->offset < pos->cur_offset) {
212 node->colnum = parse->offset;
220 if (parse->context == NULL) {
225 node->fname = strdup(parse->context);
233 data = parse->context_string;
239 while (pos->cur_offset < parse->offset) {
258 static NEOERR *alloc_node (CSTREE **node, CSPARSE *parse)
272 if (parse->audit_mode) {
273 init_node_pos(my_node, parse);
345 static int find_open_delim (CSPARSE *parse, char *buf, int x, int len)
348 int ws_index = 2+parse->taglen;
354 if (p[1] == '?' && !strncasecmp(&p[2], parse->tag, parse->taglen) &&
370 static NEOERR *_store_error (CSPARSE *parse, NEOERR *err)
384 if (parse->err_list == NULL)
386 parse->err_list = node;
390 ptr = parse->err_list;
399 NEOERR *cs_parse_file (CSPARSE *parse, const char *path)
411 if (parse->fileload)
413 err = parse->fileload(parse->fileload_ctx, parse->hdf, path, &ibuf);
419 err = hdf_search_path (parse->hdf, path, fpath);
420 if (parse->global_hdf && nerr_handle(&err, NERR_NOT_FOUND))
421 err = hdf_search_path(parse->global_hdf, path, fpath);
430 save_context = parse->context;
431 parse->context = path;
432 save_infile = parse->in_file;
433 parse->in_file = 1;
435 if (parse->audit_mode) {
437 memcpy(&pos, &parse->pos, sizeof(CS_POSITION));
439 parse->pos.line = 0;
440 parse->pos.col = 0;
441 parse->pos.cur_offset = 0;
444 err = cs_parse_string(parse, ibuf, strlen(ibuf));
446 if (parse->audit_mode) {
447 memcpy(&parse->pos, &pos, sizeof(CS_POSITION));
450 parse->in_file = save_infile;
451 parse->context = save_context;
456 static char *find_context (CSPARSE *parse, int offset, char *buf, size_t blen)
465 if (offset == -1) offset = parse->offset;
469 if (parse->in_file && parse->context)
473 fp = fopen(parse->context, "r");
475 ne_warn("Unable to open context %s", parse->context);
486 snprintf (buf, blen, "[%s:%d]", parse->context, lineno);
490 data = parse->context_string;
498 if (parse->context)
499 snprintf (buf, blen, "[%s:~%d]", parse->context, lineno);
505 if (parse->context)
506 snprintf (buf, blen, "[%s:%d]", parse->context, offset);
515 if (parse->context)
516 snprintf (buf, blen, "[-E- %s:%d]", parse->context, offset);
551 NEOERR *cs_parse_string (CSPARSE *parse, char *ibuf, size_t ibuf_len)
565 err = uListAppend(parse->alloc, ibuf);
572 initial_stack_depth = uListLength(parse->stack);
573 initial_offset = parse->offset;
574 initial_context = parse->context_string;
576 parse->offset = 0;
577 parse->context_string = ibuf;
581 i = find_open_delim (parse, ibuf, parse->offset, ibuf_len);
586 /* ne_warn ("literal -> %d-%d", parse->offset, i); */
587 err = (*(Commands[0].parse_handler))(parse, 0, &(ibuf[parse->offset]));
589 token = &(ibuf[i+3+parse->taglen]);
596 find_context(parse, i, tmp, sizeof(tmp)), &(ibuf[parse->offset]));
602 find_context(parse, i, tmp, sizeof(tmp)),
605 parse->offset = p - ibuf + 2;
616 err = uListGet (parse->stack, -1, (void *)&entry);
622 find_context(parse, -1, tmp, sizeof(tmp)),
627 /* Need to parse out arg */
629 err = (*(Commands[i].parse_handler))(parse, i, arg);
633 err = (*(Commands[i].parse_handler))(parse, i, NULL);
639 err = uListPop(parse->stack, &ptr);
643 parse->current = entry->next_tree;
645 parse->current = entry->tree;
654 find_context(parse, -1, tmp, sizeof(tmp)));
656 entry->tree = parse->current;
657 entry->location = parse->offset;
659 err = uListGet (parse->stack, -1, (void *)¤t_entry);
665 /* Get the future escape context from parse because when
666 * we parse "escape", the new stack has not yet been established.
668 entry->escape = parse->escaping.next_stack;
669 parse->escaping.next_stack = parse->escaping.global_ctx;
670 err = uListAppend(parse->stack, entry);
683 find_context(parse, -1, tmp, sizeof(tmp)), token);
690 err = (*(Commands[0].parse_handler))(parse, 0, &(ibuf[parse->offset]));
694 /* Should we check the parse stack here? */
695 while (uListLength(parse->stack) > initial_stack_depth)
697 err = uListPop(parse->stack, (void *)&entry);
701 find_context(parse, entry->location, tmp, sizeof(tmp)),
706 parse->offset = initial_offset;
707 parse->context_string = initial_context;
708 parse->escaping.current = NEOS_ESCAPE_NONE;
712 static CS_LOCAL_MAP * lookup_map (CSPARSE *parse, char *name, char **rest)
719 map = parse->locals;
736 static HDF *var_lookup_obj (CSPARSE *parse, char *name)
742 map = lookup_map (parse, name, &c);
755 /* return hdf_get_obj (parse->hdf, name); */
756 ret_hdf = hdf_get_obj (parse->hdf, name);
757 if (ret_hdf == NULL && parse->global_hdf != NULL) {
758 ret_hdf = hdf_get_obj (parse->global_hdf, name);
765 static NEOERR *var_set_value (CSPARSE *parse, char *name, char *value)
770 map = parse->locals;
782 return nerr_pass (hdf_set_value (parse->hdf, map->s, value));
795 err = hdf_set_value(parse->hdf, mapped_name, value);
831 return nerr_pass (hdf_set_value (parse->hdf, name, value));
834 static char *var_lookup (CSPARSE *parse, char *name)
840 map = lookup_map (parse, name, &c);
874 /* return hdf_get_value (parse->hdf, name, NULL); */
875 retval = hdf_get_value (parse->hdf, name, NULL);
876 if (retval == NULL && parse->global_hdf != NULL) {
877 retval = hdf_get_value (parse->global_hdf, name, NULL);
882 long int var_int_lookup (CSPARSE *parse, char *name)
886 vs = var_lookup (parse, name);
937 static NEOERR *parse_tokens (CSPARSE *parse, char *arg, CSTOKEN *tokens,
995 find_context(parse, -1, tmp, sizeof(tmp)), arg);
1012 find_context(parse, -1, tmp, sizeof(tmp)), arg);
1025 find_context(parse, -1, tmp, sizeof(tmp)), arg);
1039 find_context(parse, -1, tmp, sizeof(tmp)), arg);
1068 find_context(parse, -1, tmp, sizeof(tmp)), arg);
1082 find_context(parse, -1, tmp, sizeof(tmp)), MAX_TOKENS, expr);
1164 static NEOERR *parse_expr2 (CSPARSE *parse, CSTOKEN *tokens, int ntokens, int lvalue, CSARG *arg)
1185 find_context(parse, -1, tmp, sizeof(tmp)));
1205 find_context(parse, -1, tmp, sizeof(tmp)), expand_token_type(tokens[0].type, 0));
1217 find_context(parse, -1, tmp, sizeof(tmp)));
1218 err = parse_expr2(parse, tokens + 1, 1, lvalue, arg->expr1);
1245 find_context(parse, -1, tmp, sizeof(tmp)));
1265 find_context(parse, -1, tmp, sizeof(tmp)));
1274 find_context(parse, -1, tmp, sizeof(tmp)),
1288 find_context(parse, -1, tmp, sizeof(tmp)));
1295 find_context(parse, -1, tmp, sizeof(tmp)));
1299 err = parse_expr2(parse, tokens + 1, ntokens-2, lvalue, arg->expr1);
1303 err = parse_expr2(parse, tokens + 1, ntokens-1, lvalue, arg->expr1);
1321 find_context(parse, -1, tmp, sizeof(tmp)));
1322 err = parse_expr2(parse, tokens + x + 1, ntokens-x-1, lvalue, arg->expr1);
1324 err = parse_expr2(parse, tokens, x, lvalue, arg->next);
1336 find_context(parse, -1, tmp, sizeof(tmp)));
1343 find_context(parse, -1, tmp, sizeof(tmp)));
1347 err = parse_expr2(parse, tokens + x + 1, ntokens-x-2, 0, arg->expr2);
1351 err = parse_expr2(parse, tokens + x + 1, ntokens-x-1, lvalue, arg->expr2);
1354 err = parse_expr2(parse, tokens, x, lvalue, arg->expr1);
1373 find_context(parse, -1, tmp, sizeof(tmp)));
1374 err = parse_expr2(parse, tokens + 2, ntokens-3, lvalue, arg->expr1);
1384 find_context(parse, -1, tmp, sizeof(tmp)));
1385 err = parse_expr2(parse, tokens + 1, ntokens-1, lvalue, arg->expr1);
1400 csf = parse->functions;
1413 find_context(parse, -1, tmp, sizeof(tmp)), tokens[0].value);
1419 find_context(parse, -1, tmp, sizeof(tmp)));
1421 err = parse_expr2(parse, tokens + 2, ntokens-3, lvalue, arg->expr1);
1432 find_context(parse, -1, tmp, sizeof(tmp)), tokens[0].value,
1439 find_context(parse, -1, tmp, sizeof(tmp)),
1443 static NEOERR *parse_expr (CSPARSE *parse, char *arg, int lvalue, CSARG *expr)
1450 err = parse_tokens (parse, arg, tokens, &ntokens);
1453 if (parse->audit_mode) {
1458 err = parse_expr2 (parse, tokens, ntokens, lvalue, expr);
1463 static NEOERR *literal_parse (CSPARSE *parse, int cmd, char *arg)
1469 err = alloc_node (&node, parse);
1474 *(parse->next) = node;
1475 parse->next = &(node->next);
1476 parse->current = node;
1481 static NEOERR *literal_eval (CSPARSE *parse, CSTREE *node, CSTREE **next)
1486 err = parse->output_cb (parse->output_ctx, node->arg1.s);
1491 static NEOERR *name_parse (CSPARSE *parse, int cmd, char *arg)
1499 err = alloc_node (&node, parse);
1512 find_context(parse, -1, tmp, sizeof(tmp)),
1518 *(parse->next) = node;
1519 parse->next = &(node->next);
1520 parse->current = node;
1525 static NEOERR *escape_parse (CSPARSE *parse, int cmd, char *arg)
1534 err = alloc_node (&node, parse);
1544 /* Parse the arg - we're expecting a string */
1545 err = parse_expr (parse, arg, 0, &(node->arg1));
1555 find_context(parse, -1, tmp, sizeof(tmp)), arg);
1567 parse->escaping.next_stack = esc_cursor->context;
1575 find_context(parse, -1, tmp, sizeof(tmp)), a);
1578 *(parse->next) = node;
1579 parse->next = &(node->case_0);
1580 parse->current = node;
1584 static NEOERR *name_eval (CSPARSE *parse, CSTREE *node, CSTREE **next)
1592 obj = var_lookup_obj (parse, node->arg1.s);
1596 err = parse->output_cb (parse->output_ctx, v);
1603 static NEOERR *var_parse (CSPARSE *parse, int cmd, char *arg)
1609 err = uListGet (parse->stack, -1, (void *)&entry);
1613 err = alloc_node (&node, parse);
1631 err = parse_expr (parse, arg, 0, &(node->arg1));
1638 *(parse->next) = node;
1639 parse->next = &(node->next);
1640 parse->current = node;
1645 static NEOERR *lvar_parse (CSPARSE *parse, int cmd, char *arg)
1651 err = alloc_node (&node, parse);
1658 err = parse_expr (parse, arg, 0, &(node->arg1));
1665 *(parse->next) = node;
1666 parse->next = &(node->next);
1667 parse->current = node;
1672 static NEOERR *linclude_parse (CSPARSE *parse, int cmd, char *arg)
1678 err = alloc_node (&node, parse);
1685 err = parse_expr (parse, arg, 0, &(node->arg1));
1692 *(parse->next) = node;
1693 parse->next = &(node->next);
1694 parse->current = node;
1699 static NEOERR *alt_parse (CSPARSE *parse, int cmd, char *arg)
1705 err = alloc_node (&node, parse);
1712 err = parse_expr (parse, arg, 0, &(node->arg1));
1719 *(parse->next) = node;
1720 parse->next = &(node->case_0);
1721 parse->current = node;
1726 static NEOERR *evar_parse (CSPARSE *parse, int cmd, char *arg)
1736 err = alloc_node (&node, parse);
1749 find_context(parse, -1, tmp, sizeof(tmp)),
1753 err = hdf_get_copy (parse->hdf, a, &s, NULL);
1763 find_context(parse, -1, tmp, sizeof(tmp)), a);
1768 *(parse->next) = node;
1769 parse->next = &(node->next);
1770 parse->current = node;
1772 save_context = parse->context;
1773 save_infile = parse->in_file;
1774 parse->context = a;
1775 parse->in_file = 0;
1776 if (s) err = cs_parse_string (parse, s, strlen(s));
1777 parse->context = save_context;
1778 parse->in_file = save_infile;
1783 static NEOERR *if_parse (CSPARSE *parse, int cmd, char *arg)
1789 err = alloc_node (&node, parse);
1794 err = parse_expr (parse, arg, 0, &(node->arg1));
1801 *(parse->next) = node;
1802 parse->next = &(node->case_0);
1803 parse->current = node;
1808 char *arg_eval (CSPARSE *parse, CSARG *arg)
1815 return var_lookup (parse, arg->s);
1825 long int arg_eval_num (CSPARSE *parse, CSARG *arg)
1840 v = var_int_lookup (parse, arg->s);
1854 long int arg_eval_bool (CSPARSE *parse, CSARG *arg)
1864 s = var_lookup(parse, arg->s);
1877 return var_int_lookup (parse, arg->s);
1887 char *arg_eval_str_alloc (CSPARSE *parse, CSARG *arg)
1899 s = var_lookup (parse, arg->s);
1904 n_val = arg_eval_num (parse, arg);
1918 static void expand_arg (CSPARSE *parse, int depth, char *where, CSARG *arg)
1939 fprintf(stderr, "%s = %s\n", arg->s, var_lookup(parse, arg->s));
1941 fprintf(stderr, "%s = %ld\n", arg->s, var_int_lookup(parse, arg->s));
1947 static NEOERR *eval_expr_string(CSPARSE *parse, CSARG *arg1, CSARG *arg2, CSTOKEN_TYPE op, CSARG *result)
1953 s1 = arg_eval (parse, arg1);
1954 s2 = arg_eval (parse, arg2);
2039 static NEOERR *eval_expr_num(CSPARSE *parse, CSARG *arg1, CSARG *arg2, CSTOKEN_TYPE op, CSARG *result)
2044 n1 = arg_eval_num (parse, arg1);
2045 n2 = arg_eval_num (parse, arg2);
2091 static NEOERR *eval_expr_bool(CSPARSE *parse, CSARG *arg1, CSARG *arg2, CSTOKEN_TYPE op, CSARG *result)
2096 n1 = arg_eval_bool (parse, arg1);
2097 n2 = arg_eval_bool (parse, arg2);
2118 static NEOERR *eval_expr (CSPARSE *parse, CSARG *expr, CSARG *result)
2129 expand_arg(parse, _depth, "expr", expr);
2139 expand_arg(parse, _depth, "result", result);
2148 return nerr_pass(eval_expr(parse, expr->expr1, result));
2159 err = expr->function->function(parse, expr->function, expr->expr1, result);
2165 parse->escaping.current |= expr->function->escape;
2173 err = eval_expr (parse, expr->expr1, &arg1);
2176 expand_arg(parse, _depth, "arg1", &arg1);
2183 result->n = arg_eval_bool(parse, &arg1) ? 0 : 1;
2188 if (arg_eval(parse, &arg1) == NULL)
2200 result->n = arg_eval_num (parse, &arg1);
2217 err = eval_expr (parse, expr->next, &arg2);
2219 expand_arg(parse, _depth, "arg2", &arg2);
2228 expand_arg(parse, _depth, "result", result);
2235 err = eval_expr (parse, expr->expr2, &arg2);
2237 expand_arg(parse, _depth, "arg2", &arg2);
2249 long int n2 = arg_eval_num (parse, &arg2);
2256 char *s2 = arg_eval (parse, &arg2);
2287 long int n2 = arg_eval_num (parse, &arg2);
2294 char *s2 = arg_eval (parse, &arg2);
2313 err = eval_expr_bool (parse, &arg1, &arg2, expr->op_type, result);
2320 err = eval_expr_num(parse, &arg1, &arg2, expr->op_type, result);
2324 err = eval_expr_string(parse, &arg1, &arg2, expr->op_type, result);
2332 expand_arg(parse, _depth, "result", result);
2338 static NEOERR *var_eval (CSPARSE *parse, CSTREE *node, CSTREE **next)
2343 parse->escaping.current = NEOS_ESCAPE_NONE;
2344 err = eval_expr(parse, &(node->arg1), &val);
2351 n_val = arg_eval_num (parse, &val);
2353 err = parse->output_cb (parse->output_ctx, buf);
2357 char *s = arg_eval (parse, &val);
2360 * Config.VarEscapeMode and parse->escaping.current will have a non-zero
2363 if (s && parse->escaping.current == NEOS_ESCAPE_NONE) /* no explicit escape */
2368 err = neos_var_escape(parse->escaping.when_undef, s, &escaped);
2374 err = parse->output_cb (parse->output_ctx, escaped);
2380 err = parse->output_cb (parse->output_ctx, s);
2390 static NEOERR *lvar_eval (CSPARSE *parse, CSTREE *node, CSTREE **next)
2395 err = eval_expr(parse, &(node->arg1), &val);
2402 n_val = arg_eval_num (parse, &val);
2404 err = parse->output_cb (parse->output_ctx, buf);
2408 char *s = arg_eval (parse, &val);
2429 err = cs_init_internal(&cs, parse->hdf, parse);
2433 err = cs_render(cs, parse->output_ctx, parse->output_cb);
2445 static NEOERR *linclude_eval (CSPARSE *parse, CSTREE *node, CSTREE **next)
2450 err = eval_expr(parse, &(node->arg1), &val);
2457 n_val = arg_eval_num (parse, &val);
2459 err = parse->output_cb (parse->output_ctx, buf);
2463 char *s = arg_eval (parse, &val);
2469 err = cs_init_internal(&cs, parse->hdf, parse);
2477 err = cs_render(cs, parse->output_ctx, parse->output_cb);
2490 static NEOERR *alt_eval (CSPARSE *parse, CSTREE *node, CSTREE **next)
2496 err = eval_expr(parse, &(node->arg1), &val);
2498 eval_true = arg_eval_bool(parse, &val);
2506 n_val = arg_eval_num (parse, &val);
2508 err = parse->output_cb (parse->output_ctx, buf);
2512 char *s = arg_eval (parse, &val);
2516 err = parse->output_cb (parse->output_ctx, s);
2524 err = render_node (parse, node->case_0);
2532 static NEOERR *escape_eval (CSPARSE *parse, CSTREE *node, CSTREE **next)
2536 err = render_node (parse, node->case_0);
2542 static NEOERR *if_eval (CSPARSE *parse, CSTREE *node, CSTREE **next)
2548 err = eval_expr(parse, &(node->arg1), &val);
2550 eval_true = arg_eval_bool(parse, &val);
2555 err = render_node (parse, node->case_0);
2559 err = render_node (parse, node->case_1);
2565 static NEOERR *else_parse (CSPARSE *parse, int cmd, char *arg)
2571 err = uListGet (parse->stack, -1, (void *)&entry);
2574 parse->next = &(entry->tree->case_1);
2575 parse->current = entry->tree;
2579 static NEOERR *elif_parse (CSPARSE *parse, int cmd, char *arg)
2585 err = uListGet (parse->stack, -1, (void *)&entry);
2591 parse->next = &(entry->tree->case_1);
2593 err = if_parse(parse, cmd, arg);
2594 entry->tree = parse->current;
2598 static NEOERR *endif_parse (CSPARSE *parse, int cmd, char *arg)
2604 err = uListGet (parse->stack, -1, (void *)&entry);
2608 parse->next = &(entry->next_tree->next);
2610 parse->next = &(entry->tree->next);
2611 parse->current = entry->tree;
2615 static NEOERR *each_with_parse (CSPARSE *parse, int cmd, char *arg)
2623 err = alloc_node (&node, parse);
2637 find_context(parse, -1, tmp, sizeof(tmp)), Commands[cmd].cmd, arg);
2648 find_context(parse, -1, tmp, sizeof(tmp)), Commands[cmd].cmd, arg);
2662 find_context(parse, -1, tmp, sizeof(tmp)), Commands[cmd].cmd, arg);
2667 err = parse_expr(parse, p, 0, &(node->arg2));
2675 *(parse->next) = node;
2676 parse->next = &(node->case_0);
2677 parse->current = node;
2682 static NEOERR *each_eval (CSPARSE *parse, CSTREE *node, CSTREE **next)
2691 err = eval_expr(parse, &(node->arg2), &val);
2696 var = var_lookup_obj (parse, val.s);
2703 each_map.next = parse->locals;
2706 parse->locals = &each_map;
2717 err = render_node (parse, node->case_0);
2730 parse->locals = each_map.next;
2739 static NEOERR *with_eval (CSPARSE *parse, CSTREE *node, CSTREE **next)
2748 err = eval_expr(parse, &(node->arg2), &val);
2753 var = var_lookup_obj (parse, val.s);
2760 with_map.next = parse->locals;
2762 parse->locals = &with_map;
2763 err = render_node (parse, node->case_0);
2766 parse->locals = with_map.next;
2779 static NEOERR *end_parse (CSPARSE *parse, int cmd, char *arg)
2784 err = uListGet (parse->stack, -1, (void *)&entry);
2787 parse->next = &(entry->tree->next);
2788 parse->current = entry->tree;
2792 static NEOERR *include_parse (CSPARSE *parse, int cmd, char *arg)
2804 err = parse_expr (parse, arg, 0, &arg1);
2808 err = eval_expr(parse, &arg1, &val);
2811 s = arg_eval (parse, &val);
2814 err = cs_parse_file(parse, s);
2824 static NEOERR *def_parse (CSPARSE *parse, int cmd, char *arg)
2837 * setup a dumb var on the parse object to hold the future setting.
2839 parse->escaping.next_stack = NEOS_ESCAPE_UNDEF;
2841 err = alloc_node (&node, parse);
2858 find_context(parse, -1, tmp, sizeof(tmp)), arg);
2862 macro = parse->macros;
2870 find_context(parse, -1, tmp, sizeof(tmp)), arg);
2883 find_context(parse, -1, tmp, sizeof(tmp)), arg);
2894 find_context(parse, -1, tmp, sizeof(tmp)), arg);
2907 find_context(parse, -1, tmp, sizeof(tmp)), arg, *p);
2916 find_context(parse, -1, tmp, sizeof(tmp)), arg);
2924 find_context(parse, -1, tmp, sizeof(tmp)), arg);
2950 if (parse->macros)
2952 macro->next = parse->macros;
2954 parse->macros = macro;
2956 *(parse->next) = node;
2957 parse->next = &(node->case_0);
2958 parse->current = node;
2999 static NEOERR *call_parse (CSPARSE *parse, int cmd, char *arg)
3012 err = uListGet (parse->stack, -1, (void *)&entry);
3015 err = alloc_node (&node, parse);
3033 find_context(parse, -1, tmp, sizeof(tmp)), arg);
3037 macro = parse->macros;
3047 find_context(parse, -1, tmp, sizeof(tmp)), arg);
3048 if (parse->audit_mode) {
3050 return _store_error(parse, err);
3065 find_context(parse, -1, tmp, sizeof(tmp)), arg);
3077 /* Parse arguments case */
3085 find_context(parse, -1, tmp, sizeof(tmp)), arg);
3088 err = parse_expr (parse, s, 0, carg);
3098 find_context(parse, -1, tmp, sizeof(tmp)), macro->n_args, nargs,
3107 *(parse->next) = node;
3108 parse->next = &(node->next);
3109 parse->current = node;
3114 static NEOERR *call_eval (CSPARSE *parse, CSTREE *node, CSTREE **next)
3130 parse->escaping.when_undef = node->escape;
3156 err = eval_expr(parse, carg, &val);
3174 lmap = lookup_map (parse, val.s, &c);
3192 var = var_lookup_obj (parse, val.s);
3207 map->next = parse->locals;
3215 map = parse->locals;
3216 if (macro->n_args) parse->locals = call_map;
3217 err = render_node (parse, macro->tree->case_0);
3218 parse->locals = map;
3230 static NEOERR *set_parse (CSPARSE *parse, int cmd, char *arg)
3237 err = alloc_node (&node, parse);
3248 find_context(parse, -1, tmp, sizeof(tmp)), arg);
3252 err = parse_expr(parse, arg, 1, &(node->arg1));
3259 err = parse_expr(parse, s, 0, &(node->arg2));
3266 *(parse->next) = node;
3267 parse->next = &(node->next);
3268 parse->current = node;
3273 static NEOERR *set_eval (CSPARSE *parse, CSTREE *node, CSTREE **next)
3279 err = eval_expr(parse, &(node->arg1), &set);
3281 err = eval_expr(parse, &(node->arg2), &val);
3296 n_val = arg_eval_num (parse, &val);
3300 err = var_set_value (parse, set.s, buf);
3310 char *s = arg_eval (parse, &val);
3314 err = var_set_value (parse, set.s, s);
3331 static NEOERR *loop_parse (CSPARSE *parse, int cmd, char *arg)
3342 err = alloc_node (&node, parse);
3356 find_context(parse, -1, tmp, sizeof(tmp)), arg);
3367 find_context(parse, -1, tmp, sizeof(tmp)), arg);
3381 find_context(parse, -1, tmp, sizeof(tmp)), arg);
3394 find_context(parse, -1, tmp, sizeof(tmp)), arg);
3411 err = parse_expr (parse, p, 0, carg);
3420 find_context(parse, -1, tmp, sizeof(tmp)), x, arg);
3425 *(parse->next) = node;
3426 parse->next = &(node->case_0);
3427 parse->current = node;
3432 static NEOERR *loop_eval (CSPARSE *parse, CSTREE *node, CSTREE **next)
3446 err = eval_expr(parse, carg, &val);
3448 end = arg_eval_num(parse, &val);
3454 err = eval_expr(parse, carg, &val);
3456 end = arg_eval_num(parse, &val);
3461 err = eval_expr(parse, carg, &val);
3463 step = arg_eval_num(parse, &val);
3486 each_map.next = parse->locals;
3488 parse->locals = &each_map;
3495 err = render_node (parse, node->case_0);
3505 parse->locals = each_map.next;
3512 static NEOERR *skip_eval (CSPARSE *parse, CSTREE *node, CSTREE **next)
3517 static NEOERR *render_node (CSPARSE *parse, CSTREE *node)
3524 err = (*(Commands[node->cmd].eval_handler))(parse, node, &node);
3530 NEOERR *cs_render (CSPARSE *parse, void *ctx, CSOUTFUNC cb)
3534 if (parse->tree == NULL)
3535 return nerr_raise (NERR_ASSERT, "No parse tree exists");
3537 parse->output_ctx = ctx;
3538 parse->output_cb = cb;
3540 node = parse->tree;
3541 return nerr_pass (render_node(parse, node));
3546 NEOERR *cs_register_function(CSPARSE *parse, const char *funcname,
3553 csf = parse->functions;
3577 csf->next = parse->functions;
3578 parse->functions = csf;
3588 NEOERR * cs_arg_parsev(CSPARSE *parse, CSARG *args, const char *fmt,
3599 err = eval_expr(parse, args, &val);
3612 *s = arg_eval_str_alloc(parse, &val);
3622 *i = arg_eval_num(parse, &val);
3636 NEOERR * cs_arg_parse(CSPARSE *parse, CSARG *args, const char *fmt, ...)
3642 err = cs_arg_parsev(parse, args, fmt, ap);
3647 static NEOERR * _builtin_subcount(CSPARSE *parse, CS_FUNCTION *csf, CSARG *args, CSARG *result)
3655 err = eval_expr(parse, args, &val);
3664 obj = var_lookup_obj (parse, val.s);
3681 static NEOERR * _builtin_str_length(CSPARSE *parse, CS_FUNCTION *csf, CSARG *args, CSARG *result)
3687 err = eval_expr(parse, args, &val);
3696 char *s = arg_eval(parse, &val);
3703 static NEOERR * _builtin_str_crc(CSPARSE *parse, CS_FUNCTION *csf, CSARG *args,
3710 err = eval_expr(parse, args, &val);
3719 char *s = arg_eval(parse, &val);
3727 static NEOERR * _builtin_str_find(CSPARSE *parse, CS_FUNCTION *csf, CSARG *args, CSARG *result)
3737 err = cs_arg_parse(parse, args, "ss", &s, &substr);
3755 static NEOERR * _builtin_name(CSPARSE *parse, CS_FUNCTION *csf, CSARG *args, CSARG *result)
3762 err = eval_expr(parse, args, &val);
3770 obj = var_lookup_obj (parse, val.s);
3785 static NEOERR * _builtin_first(CSPARSE *parse, CS_FUNCTION *csf, CSARG *args,
3794 err = eval_expr(parse, args, &val);
3804 map = lookup_map (parse, val.s, &c);
3814 static NEOERR * _builtin_last(CSPARSE *parse, CS_FUNCTION *csf, CSARG *args,
3823 err = eval_expr(parse, args, &val);
3833 map = lookup_map (parse, val.s, &c);
3849 static NEOERR * _builtin_abs (CSPARSE *parse, CS_FUNCTION *csf, CSARG *args,
3857 err = eval_expr(parse, args, &val);
3861 n1 = arg_eval_num(parse, &val);
3869 static NEOERR * _builtin_max (CSPARSE *parse, CS_FUNCTION *csf, CSARG *args,
3879 err = cs_arg_parse(parse, args, "ii", &n1, &n2);
3887 static NEOERR * _builtin_min (CSPARSE *parse, CS_FUNCTION *csf, CSARG *args,
3897 err = cs_arg_parse(parse, args, "ii", &n1, &n2);
3904 static NEOERR * _builtin_str_slice (CSPARSE *parse, CS_FUNCTION *csf, CSARG *args, CSARG *result)
3916 err = cs_arg_parse(parse, args, "sii", &s, &b, &e);
3953 static NEOERR * _builtin_gettext(CSPARSE *parse, CS_FUNCTION *csf, CSARG *args, CSARG *result)
3960 err = eval_expr(parse, args, &val);
3968 s = arg_eval(parse, &val);
3979 static NEOERR * _str_func_wrapper (CSPARSE *parse, CS_FUNCTION *csf, CSARG *args, CSARG *result)
3986 err = eval_expr(parse, args, &val);
3994 s = arg_eval(parse, &val);
4014 NEOERR *cs_register_strfunc(CSPARSE *parse, char *funcname, CSSTRFUNC str_func)
4018 err = cs_register_function(parse, funcname, 1, _str_func_wrapper);
4020 parse->functions->str_func = str_func;
4025 NEOERR *cs_register_esc_strfunc(CSPARSE *parse, char *funcname,
4030 err = cs_register_strfunc(parse, funcname, str_func);
4032 parse->functions->escape = NEOS_ESCAPE_FUNCTION;
4038 NEOERR *cs_init (CSPARSE **parse, HDF *hdf) {
4039 return nerr_pass(cs_init_internal(parse, hdf, NULL));
4042 static NEOERR *cs_init_internal (CSPARSE **parse, HDF *hdf, CSPARSE *parent)
4174 /* BUG: We currently can't copy the macros because they reference the parse
4175 * tree, so if this sub-parse tree adds a macro, the macro reference will
4176 * persist, but the parse tree it points to will be gone when the sub-parse
4183 // eval functions, not globally by the parse handling. This should
4184 // pass the locals down to the new parse context to make locals work with
4193 *parse = my_parse;
4197 void cs_register_fileload(CSPARSE *parse, void *ctx, CSFILELOAD fileload) {
4198 if (parse != NULL) {
4199 parse->fileload_ctx = ctx;
4200 parse->fileload = fileload;
4204 void cs_destroy (CSPARSE **parse)
4206 CSPARSE *my_parse = *parse;
4233 *parse = NULL;
4237 static NEOERR *dump_node (CSPARSE *parse, CSTREE *node, int depth, void *ctx,
4306 err = dump_node (parse, node->case_0, depth+1, ctx, cb, buf, blen);
4314 err = dump_node (parse, node->case_1, depth+1, ctx, cb, buf, blen);
4322 NEOERR *cs_dump (CSPARSE *parse, void *ctx, CSOUTFUNC cb)
4327 if (parse->tree == NULL)
4328 return nerr_raise (NERR_ASSERT, "No parse tree exists");
4330 node = parse->tree;
4331 return nerr_pass (dump_node (parse, node, 0, ctx, cb, buf, sizeof(buf)));
4348 static NEOERR *dump_node_pre_c (CSPARSE *parse, CSTREE *node, FILE *fp)
4357 err = dump_node_pre_c (parse, node->case_0, fp);
4362 err = dump_node_pre_c (parse, node->case_1, fp);
4370 static NEOERR *dump_node_c (CSPARSE *parse, CSTREE *node, FILE *fp)
4403 err = dump_node_c (parse, node->case_0, fp);
4408 err = dump_node_c (parse, node->case_1, fp);
4416 NEOERR *cs_dump_c (CSPARSE *parse, char *path)
4422 if (parse->tree == NULL)
4423 return nerr_raise (NERR_ASSERT, "No parse tree exists");
4436 node = parse->tree;
4437 err = dump_node_pre_c (parse, node, fp);
4439 err = dump_node_c (parse, node, fp);