#include <stdlib.h>
#include <string.h>
-#include <common/align.h>
-#include <common/compat/errno.h>
-#include <common/compat/string.h>
-
-#include "common/align.h"
-#include "common/bytecode/bytecode.h"
-#include "common/compat/string.h"
-#include "common/macros.h"
-#include "filter-ast.h"
-#include "filter-ir.h"
-
-#ifndef max_t
-#define max_t(type, a, b) ((type) ((a) > (b) ? (a) : (b)))
-#endif
+#include <common/align.hpp>
+#include <common/compat/errno.hpp>
+#include <common/compat/string.hpp>
+
+#include "common/align.hpp"
+#include "common/bytecode/bytecode.hpp"
+#include "common/compat/string.hpp"
+#include "common/macros.hpp"
+#include "common/string-utils/string-utils.hpp"
+#include "filter-ast.hpp"
+#include "filter-ir.hpp"
static
int recursive_visit_gen_bytecode(struct filter_parser_ctx *ctx,
return bytecode_push(&ctx->bytecode, &insn, 1, sizeof(insn));
}
-static
-int append_str(char **s, const char *append)
-{
- char *old_str = *s;
- char *new_str;
- size_t oldlen = (old_str == NULL) ? 0 : strlen(old_str);
- size_t appendlen = strlen(append);
-
- new_str = (char *) calloc(oldlen + appendlen + 1, 1);
- if (!new_str) {
- return -ENOMEM;
- }
- if (oldlen) {
- strcpy(new_str, old_str);
- }
- strcat(new_str, append);
- *s = new_str;
- free(old_str);
- return 0;
-}
-
/*
* 1: match
* 0: no match
switch (op->type) {
case IR_LOAD_EXPRESSION_GET_CONTEXT_ROOT:
*op_type = BYTECODE_OP_GET_CONTEXT_REF;
- if (append_str(symbol, "$ctx.")) {
+ if (strutils_append_str(symbol, "$ctx.")) {
return -ENOMEM;
}
need_dot = false;
break;
case IR_LOAD_EXPRESSION_GET_APP_CONTEXT_ROOT:
*op_type = BYTECODE_OP_GET_CONTEXT_REF;
- if (append_str(symbol, "$app.")) {
+ if (strutils_append_str(symbol, "$app.")) {
return -ENOMEM;
}
need_dot = false;
case IR_LOAD_EXPRESSION_LOAD_FIELD:
goto end;
case IR_LOAD_EXPRESSION_GET_SYMBOL:
- if (need_dot && append_str(symbol, ".")) {
+ if (need_dot && strutils_append_str(symbol, ".")) {
return -ENOMEM;
}
- if (append_str(symbol, op->u.symbol)) {
+ if (strutils_append_str(symbol, op->u.symbol)) {
return -ENOMEM;
}
break;