xpath MAINTENANCE make print_token() non-static
diff --git a/src/xpath.c b/src/xpath.c
index 49c6a55..494aa37 100644
--- a/src/xpath.c
+++ b/src/xpath.c
@@ -68,14 +68,8 @@
return NULL;
}
-/**
- * @brief Print an XPath token \p tok type.
- *
- * @param[in] tok Token to use.
- * @return Token type string.
- */
-static const char *
-print_token(enum lyxp_token tok)
+const char *
+lyxp_print_token(enum lyxp_token tok)
{
switch (tok) {
case LYXP_TOKEN_PAR1:
@@ -139,7 +133,7 @@
LOGDBG(LY_LDGXPATH, "expression \"%s\":", exp->expr);
for (i = 0; i < exp->used; ++i) {
- sprintf(tmp, "\ttoken %s, in expression \"%.*s\"", print_token(exp->tokens[i]), exp->tok_len[i],
+ sprintf(tmp, "\ttoken %s, in expression \"%.*s\"", lyxp_print_token(exp->tokens[i]), exp->tok_len[i],
&exp->expr[exp->tok_pos[i]]);
if (exp->repeat[i]) {
sprintf(tmp + strlen(tmp), " (repeat %d", exp->repeat[i][0]);
@@ -1787,7 +1781,7 @@
*/
LY_ERR
-lyxp_check_token(const struct ly_ctx *ctx, struct lyxp_expr *exp, uint16_t exp_idx, enum lyxp_token want_tok)
+lyxp_check_token(const struct ly_ctx *ctx, const struct lyxp_expr *exp, uint16_t exp_idx, enum lyxp_token want_tok)
{
if (exp->used == exp_idx) {
if (ctx) {
@@ -1799,7 +1793,7 @@
if (want_tok && (exp->tokens[exp_idx] != want_tok)) {
if (ctx) {
LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_XP_INTOK,
- print_token(exp->tokens[exp_idx]), &exp->expr[exp->tok_pos[exp_idx]]);
+ lyxp_print_token(exp->tokens[exp_idx]), &exp->expr[exp->tok_pos[exp_idx]]);
}
return LY_ENOT;
}
@@ -1822,7 +1816,7 @@
if ((exp->tokens[exp_idx] != want_tok1) && (exp->tokens[exp_idx] != want_tok2)) {
if (ctx) {
LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_XP_INTOK,
- print_token(exp->tokens[exp_idx]), &exp->expr[exp->tok_pos[exp_idx]]);
+ lyxp_print_token(exp->tokens[exp_idx]), &exp->expr[exp->tok_pos[exp_idx]]);
}
return LY_ENOT;
}
@@ -1929,7 +1923,7 @@
LY_CHECK_RET(rc);
if ((exp->tokens[*exp_idx] != LYXP_TOKEN_NAMETEST) && (exp->tokens[*exp_idx] != LYXP_TOKEN_NODETYPE)) {
LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_XP_INTOK,
- print_token(exp->tokens[*exp_idx]), &exp->expr[exp->tok_pos[*exp_idx]]);
+ lyxp_print_token(exp->tokens[*exp_idx]), &exp->expr[exp->tok_pos[*exp_idx]]);
return LY_EVALID;
}
/* fall through */
@@ -1960,7 +1954,7 @@
break;
default:
LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_XP_INTOK,
- print_token(exp->tokens[*exp_idx]), &exp->expr[exp->tok_pos[*exp_idx]]);
+ lyxp_print_token(exp->tokens[*exp_idx]), &exp->expr[exp->tok_pos[*exp_idx]]);
return LY_EVALID;
}
} while (!exp_check_token2(NULL, exp, *exp_idx, LYXP_TOKEN_OPERATOR_PATH, LYXP_TOKEN_OPERATOR_RPATH));
@@ -2293,7 +2287,7 @@
break;
default:
LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_XP_INTOK,
- print_token(exp->tokens[*exp_idx]), &exp->expr[exp->tok_pos[*exp_idx]]);
+ lyxp_print_token(exp->tokens[*exp_idx]), &exp->expr[exp->tok_pos[*exp_idx]]);
return LY_EVALID;
}
@@ -2842,7 +2836,6 @@
/* fill repeat */
LY_CHECK_GOTO(reparse_or_expr(ctx, ret, &exp_idx), error);
if (ret->used > exp_idx) {
- LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_XP_INTOK, "Unknown", &ret->expr[ret->tok_pos[exp_idx]]);
LOGVAL(ctx, LY_VLOG_NONE, NULL, LYVE_XPATH, "Unparsed characters \"%s\" left at the end of an XPath expression.",
&ret->expr[ret->tok_pos[exp_idx]]);
goto error;
@@ -6570,7 +6563,7 @@
/* '[' */
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
if (!set) {
@@ -6691,7 +6684,7 @@
/* ']' */
assert(exp->tokens[*exp_idx] == LYXP_TOKEN_BRACK2);
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
return LY_SUCCESS;
@@ -6715,7 +6708,7 @@
}
}
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
}
@@ -6874,7 +6867,7 @@
LY_ERR rc = LY_SUCCESS;
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
if (!set) {
@@ -7056,19 +7049,19 @@
}
}
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
/* '(' */
assert(exp->tokens[*exp_idx] == LYXP_TOKEN_PAR1);
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
/* ')' */
assert(exp->tokens[*exp_idx] == LYXP_TOKEN_PAR2);
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
/* Predicate* */
@@ -7110,7 +7103,7 @@
all_desc = 1;
}
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
step:
@@ -7119,7 +7112,7 @@
attr_axis = 1;
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
} else {
attr_axis = 0;
@@ -7136,7 +7129,7 @@
}
LY_CHECK_RET(rc);
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
break;
@@ -7149,7 +7142,7 @@
}
LY_CHECK_RET(rc);
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
break;
@@ -7200,7 +7193,7 @@
/* evaluate '/' - deferred */
all_desc = 0;
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
if (lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_NONE)) {
@@ -7224,7 +7217,7 @@
/* evaluate '//' - deferred so as not to waste memory by remembering all the nodes */
all_desc = 1;
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
rc = eval_relative_location_path(exp, exp_idx, all_desc, set, options);
@@ -7367,20 +7360,19 @@
}
if (!xpath_func) {
- LOGVAL(set->ctx, LY_VLOG_LYD, set->ctx_node, LY_VCODE_XP_INTOK, "Unknown", &exp->expr[exp->tok_pos[*exp_idx]]);
LOGVAL(set->ctx, LY_VLOG_LYD, set->ctx_node, LY_VCODE_XP_INFUNC, exp->tok_len[*exp_idx], &exp->expr[exp->tok_pos[*exp_idx]]);
return LY_EVALID;
}
}
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
/* '(' */
assert(exp->tokens[*exp_idx] == LYXP_TOKEN_PAR1);
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
/* ( Expr ( ',' Expr )* )? */
@@ -7404,7 +7396,7 @@
}
while (!lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_COMMA)) {
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
if (set) {
@@ -7429,7 +7421,7 @@
/* ')' */
assert(exp->tokens[*exp_idx] == LYXP_TOKEN_PAR2);
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
if (set) {
@@ -7490,7 +7482,7 @@
}
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
return LY_SUCCESS;
}
@@ -7522,7 +7514,7 @@
/* '(' */
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
/* Expr */
@@ -7532,7 +7524,7 @@
/* ')' */
assert(exp->tokens[*exp_idx] == LYXP_TOKEN_PAR2);
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
parent_pos_pred = 0;
@@ -7597,7 +7589,7 @@
goto predicate;
default:
- LOGVAL(set->ctx, LY_VLOG_LYD, set->ctx_node, LY_VCODE_XP_INTOK, print_token(exp->tokens[*exp_idx]),
+ LOGVAL(set->ctx, LY_VLOG_LYD, set->ctx_node, LY_VCODE_XP_INTOK, lyxp_print_token(exp->tokens[*exp_idx]),
&exp->expr[exp->tok_pos[*exp_idx]]);
return LY_EVALID;
}
@@ -7622,7 +7614,7 @@
}
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
rc = eval_relative_location_path(exp, exp_idx, all_desc, set, options);
@@ -7665,7 +7657,7 @@
for (i = 0; i < repeat; ++i) {
assert(exp->tokens[*exp_idx] == LYXP_TOKEN_OPERATOR_UNI);
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
if (!set) {
@@ -7719,7 +7711,7 @@
assert(!lyxp_check_token(NULL, exp, *exp_idx, LYXP_TOKEN_OPERATOR_MATH) && (exp->expr[exp->tok_pos[*exp_idx]] == '-'));
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
}
@@ -7777,7 +7769,7 @@
assert(exp->tokens[*exp_idx] == LYXP_TOKEN_OPERATOR_MATH);
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
if (!set) {
@@ -7845,7 +7837,7 @@
assert(exp->tokens[*exp_idx] == LYXP_TOKEN_OPERATOR_MATH);
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
if (!set) {
@@ -7915,7 +7907,7 @@
assert(exp->tokens[*exp_idx] == LYXP_TOKEN_OPERATOR_COMP);
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
if (!set) {
@@ -7982,7 +7974,7 @@
assert(exp->tokens[*exp_idx] == LYXP_TOKEN_OPERATOR_COMP);
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (set ? "parsed" : "skipped"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
if (!set) {
@@ -8054,7 +8046,7 @@
for (i = 0; i < repeat; ++i) {
assert(exp->tokens[*exp_idx] == LYXP_TOKEN_OPERATOR_LOG);
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (!set || !set->val.bool ? "skipped" : "parsed"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
/* lazy evaluation */
@@ -8124,7 +8116,7 @@
for (i = 0; i < repeat; ++i) {
assert(exp->tokens[*exp_idx] == LYXP_TOKEN_OPERATOR_LOG);
LOGDBG(LY_LDGXPATH, "%-27s %s %s[%u]", __func__, (!set || set->val.bool ? "skipped" : "parsed"),
- print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
+ lyxp_print_token(exp->tokens[*exp_idx]), exp->tok_pos[*exp_idx]);
++(*exp_idx);
/* lazy evaluation */