Neo4j-Client

 view release on metacpan or  search on metacpan

build/lib/src/render.c  view on Meta::CPAN

int render_wrap_marker(FILE *stream, uint_fast32_t flags,
        const char * const color[2])
{
    assert(stream != NULL);
    assert(color != NULL);

    const struct border_glifs *glifs = glifs_for_encoding(flags);
    if (fputs(color[0], stream) == EOF)
    {
        return -1;
    }
    if (flags & NEO4J_RENDER_NO_WRAP_MARKERS)
    {
        if (fputc(' ', stream) == EOF)
        {
            return -1;
        }
    }
    else
    {
        if (fputs(glifs->wrap, stream) == EOF)
        {
            return -1;
        }
    }
    if (fputs(color[1], stream) == EOF)
    {
        return -1;
    }
    return 0;
}


int render_overflow(FILE *stream, uint_fast32_t flags,
        const char * const color[2])
{
    assert(stream != NULL);
    assert(color != NULL);

    const struct border_glifs *glifs = glifs_for_encoding(flags);
    if (fputs(color[0], stream) == EOF)
    {
        return -1;
    }
    if (fputs(glifs->overflow, stream) == EOF)
    {
        return -1;
    }
    if (fputs(color[1], stream) == EOF)
    {
        return -1;
    }
    return 0;
}


int render_row(FILE *stream, unsigned int ncolumns,
        const unsigned int *widths, bool undersize, uint_fast32_t flags,
        const struct neo4j_results_table_colors *colors,
        const char * const field_color[2],
        render_row_callback_t callback, void *cdata)
{
    assert(stream != NULL);
    assert(ncolumns == 0 || widths != NULL);
    assert(colors != NULL);

    struct fields
    {
        const char *s;
        size_t n;
        char *dup;
    };

    struct fields *fields = NULL;
    if ((flags & NEO4J_RENDER_WRAP_VALUES) &&
            (fields = calloc(ncolumns, sizeof(struct fields))) == NULL)
    {
        return -1;
    }
    bool wrap = false;

    int err = -1;

    for (unsigned int i = 0; i < ncolumns; ++i)
    {
        if (widths[i] == 0)
        {
            continue;
        }
        if (render_border_line(stream, VERTICAL_LINE, flags, colors) ||
                fputc(' ', stream) == EOF)
        {
            goto cleanup;
        }

        assert(widths[i] >= 2);
        unsigned int value_width = widths[i] - 2;
        ssize_t n = 0;
        const char *s = NULL;
        bool duplicate = false;
        if (callback != NULL && (n = callback(cdata, i, &s, &duplicate)) < 0)
        {
            goto cleanup;
        }
        assert(n == 0 || s != NULL);

        ssize_t consumed = render_field(stream, s, n, value_width, flags,
                field_color);
        if (consumed < 0)
        {
            goto cleanup;
        }

        if (consumed >= n)
        {
            if (fputc(' ', stream) == EOF)
            {
                goto cleanup;
            }
        }
        else
        {
            if (render_wrap_marker(stream, flags, colors->border))
            {
                goto cleanup;
            }

            if (flags & NEO4J_RENDER_WRAP_VALUES)
            {
                s += consumed;
                n -= consumed;
                if (duplicate)
                {
                    if ((fields[i].dup = memdup(s, n)) == NULL)
                    {
                        goto cleanup;
                    }
                    s = fields[i].dup;
                }
                fields[i].s = s;
                fields[i].n = n;
                wrap = true;
            }
        }
    }

    if (render_border_line(stream, VERTICAL_LINE, flags, colors))
    {
        goto cleanup;
    }
    if (undersize && render_overflow(stream, flags, colors->border))
    {
        goto cleanup;
    }
    if (fputc('\n', stream) == EOF)
    {
        goto cleanup;
    }

    while (wrap)
    {



( run in 0.603 second using v1.01-cache-2.11-cpan-7fcb06a456a )