Skip to content

Commit

Permalink
xpath UPDATE do not use memstream
Browse files Browse the repository at this point in the history
Not supported on Windows.
  • Loading branch information
michalvasko committed Nov 1, 2023
1 parent 400cf3c commit 1696178
Showing 1 changed file with 50 additions and 14 deletions.
64 changes: 50 additions & 14 deletions src/xpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,39 +219,75 @@ str2axis(const char *str, uint32_t str_len)
}

/**
* @brief Print the whole expression \p exp to debug output.
* @brief Append a string to a dynamic string variable.
*
* @param[in,out] str String to use.
* @param[in,out] size String size.
* @param[in,out] used String used size excluding terminating zero.
* @param[in] format Message format.
* @param[in] ... Message format arguments.
*/
static void
print_expr_str(char **str, size_t *size, size_t *used, const char *format, ...)
{
int p;
va_list ap;

va_start(ap, format);

/* try to append the string */
p = vsnprintf(*str + *used, *size - *used, format, ap);

if ((unsigned)p >= *size - *used) {
/* realloc */
*str = ly_realloc(*str, *size + p + 1);
*size += p + 1;

/* restart ap */
va_end(ap);
va_start(ap, format);

/* print */
p = vsnprintf(*str + *used, *size - *used, format, ap);
}

*used += p;
va_end(ap);
}

/**
* @brief Print the whole expression @p exp to debug output.
*
* @param[in] exp Expression to use.
*/
static void
print_expr_struct_debug(const struct lyxp_expr *exp)
{
char *tmp;
char *buf = NULL;
uint32_t i, j;
FILE *fp;
size_t s;
size_t size = 0, used = 0;

if (!exp || (ly_ll < LY_LLDBG)) {
return;
}

LOGDBG(LY_LDGXPATH, "expression \"%s\":", exp->expr);
for (i = 0; i < exp->used; ++i) {
fp = open_memstream(&tmp, &s);
fprintf(fp, "\ttoken %s, in expression \"%.*s\"", lyxp_token2str(exp->tokens[i]), exp->tok_len[i],
&exp->expr[exp->tok_pos[i]]);
print_expr_str(&buf, &size, &used, "\ttoken %s, in expression \"%.*s\"",
lyxp_token2str(exp->tokens[i]), exp->tok_len[i], &exp->expr[exp->tok_pos[i]]);

if (exp->repeat && exp->repeat[i]) {
fprintf(fp, " (repeat %d", exp->repeat[i][0]);
print_expr_str(&buf, &size, &used, " (repeat %d", exp->repeat[i][0]);
for (j = 1; exp->repeat[i][j]; ++j) {
fprintf(fp, ", %d", exp->repeat[i][j]);
print_expr_str(&buf, &size, &used, ", %d", exp->repeat[i][j]);
}
fprintf(fp, ")");
print_expr_str(&buf, &size, &used, ")");
}
fflush(fp);
LOGDBG(LY_LDGXPATH, tmp);
fclose(fp);
free(tmp);
LOGDBG(LY_LDGXPATH, buf);
used = 0;
}

free(buf);
}

#ifndef NDEBUG
Expand Down

0 comments on commit 1696178

Please sign in to comment.