aboutsummaryrefslogtreecommitdiffstats
path: root/src/debug.c
blob: 968902880f0bfa622e6386487a6a6bc54173d5e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 * blogc: A blog compiler.
 * Copyright (C) 2015-2016 Rafael G. Martins <rafael@rafaelmartins.eng.br>
 *
 * This program can be distributed under the terms of the BSD License.
 * See the file LICENSE.
 */

#include <stdio.h>

#include "template-parser.h"
#include "utils.h"
#include "debug.h"


static const char*
get_operator(blogc_template_stmt_operator_t op)
{
    if (op & BLOGC_TEMPLATE_OP_NEQ)
        return "!=";
    if (op & BLOGC_TEMPLATE_OP_EQ) {
        if (op & BLOGC_TEMPLATE_OP_LT)
            return "<=";
        else if (op & BLOGC_TEMPLATE_OP_GT)
            return ">=";
        return "==";
    }
    if (op & BLOGC_TEMPLATE_OP_LT)
        return "<";
    else if (op & BLOGC_TEMPLATE_OP_GT)
        return ">";
    return "";
}


void
blogc_debug_template(sb_slist_t *stmts)
{
    for (sb_slist_t *tmp = stmts; tmp != NULL; tmp = tmp->next) {
        blogc_template_stmt_t *data = tmp->data;
        fprintf(stderr, "DEBUG: <TEMPLATE ");
        switch (data->type) {
            case BLOGC_TEMPLATE_IFDEF_STMT:
                fprintf(stderr, "IFDEF: %s", data->value);
                break;
            case BLOGC_TEMPLATE_IFNDEF_STMT:
                fprintf(stderr, "IFNDEF: %s", data->value);
                break;
            case BLOGC_TEMPLATE_IF_STMT:
                fprintf(stderr, "IF: %s %s %s", data->value,
                    get_operator(data->op), data->value2);
                break;
            case BLOGC_TEMPLATE_ELSE_STMT:
                fprintf(stderr, "ELSE");
                break;
            case BLOGC_TEMPLATE_ENDIF_STMT:
                fprintf(stderr, "ENDIF");
                break;
            case BLOGC_TEMPLATE_FOREACH_STMT:
                fprintf(stderr, "FOREACH: %s", data->value);
                break;
            case BLOGC_TEMPLATE_ENDFOREACH_STMT:
                fprintf(stderr, "ENDFOREACH");
                break;
            case BLOGC_TEMPLATE_BLOCK_STMT:
                fprintf(stderr, "BLOCK: %s", data->value);
                break;
            case BLOGC_TEMPLATE_ENDBLOCK_STMT:
                fprintf(stderr, "ENDBLOCK");
                break;
            case BLOGC_TEMPLATE_VARIABLE_STMT:
                fprintf(stderr, "VARIABLE: %s", data->value);
                break;
            case BLOGC_TEMPLATE_CONTENT_STMT:
                fprintf(stderr, "CONTENT: `%s`", data->value);
                break;
        }
        fprintf(stderr, ">\n");
    }
}