From 6f94a93c3e70d1d642c3ec870e3af2037b9c06c4 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 19 Nov 2014 06:16:17 +0100 Subject: missed a few macros MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/mds-kbdc/simplify-tree.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/mds-kbdc') diff --git a/src/mds-kbdc/simplify-tree.c b/src/mds-kbdc/simplify-tree.c index 8a20caa..2b8c0bd 100644 --- a/src/mds-kbdc/simplify-tree.c +++ b/src/mds-kbdc/simplify-tree.c @@ -20,6 +20,27 @@ #include +/** + * Wrapper around `asprintf` that makes sure that first + * argument gets set to `NULL` on error and that zero is + * returned on success rather than the number of printed + * characters + * + * @param VAR:char** The output parameter for the string + * @param ...:const char*, ... The format string and arguments + * @return :int Zero on success, -1 on error + */ +#define xasprintf(VAR, ...) \ + (asprintf(&(VAR), __VA_ARGS__) < 0 ? (VAR = NULL, -1) : 0) + + +/** + * Pointer to the beginning of the current line + */ +#define LINE \ + (source_code.lines[line_i]) + + /** * Add an error the to error list * @@ -74,4 +95,6 @@ int simplify_tree(mds_kbdc_tree_t** restrict tree, mds_kbdc_parse_error_t*** res #undef NEW_ERROR +#undef LINE +#undef xasprintf -- cgit v1.2.3-70-g09d2