openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/util-linux/2.33.2-r0/util-linux-2.33.2/libsmartcols/src/table_print.c
static int count_column_width(struct libscols_table* tb,
                              struct libscols_column* cl,
                              struct libscols_buffer* buf)
{
    struct libscols_line* ln;
    struct libscols_iter itr;
    int extreme_count = 0, rc = 0, no_header = 0;
    size_t extreme_sum = 0;

    assert(tb);
    assert(cl);

    cl->width = 0;
    if (!cl->width_min)
    {
        if (cl->width_hint < 1 && scols_table_is_maxout(tb) && tb->is_term)
        {
            cl->width_min = (size_t)(cl->width_hint * tb->termwidth);
            if (cl->width_min && !is_last_column(cl))
                cl->width_min--;
        }
        if (scols_cell_get_data(&cl->header))
        {
            size_t len = mbs_safe_width(scols_cell_get_data(&cl->header));
            cl->width_min = max(cl->width_min, len);
        }
        else
            no_header = 1;

        if (!cl->width_min)
            cl->width_min = 1;
    }

    scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
    while (scols_table_next_line(tb, &itr, &ln) == 0)
    {
        size_t len;
        char* data;

        rc = cell_to_buffer(tb, ln, cl, buf);
        if (rc)
            goto done;

        data = buffer_get_data(buf);

        if (!data)
            len = 0;
        else if (scols_column_is_customwrap(cl))
            len = cl->wrap_chunksize(cl, data, cl->wrapfunc_data);
        else
            len = mbs_safe_width(data);

        if (len == (size_t)-1) /* ignore broken multibyte strings */
            len = 0;
        cl->width_max = max(len, cl->width_max);

        if (cl->is_extreme && cl->width_avg && len > cl->width_avg * 2)
            continue;
        else if (scols_column_is_noextremes(cl))
        {
            extreme_sum += len;
            extreme_count++;
        }
        cl->width = max(len, cl->width);
        if (scols_column_is_tree(cl))
        {
            size_t treewidth = buffer_get_safe_art_size(buf);
            cl->width_treeart = max(cl->width_treeart, treewidth);
        }
    }

    if (extreme_count && cl->width_avg == 0)
    {
        cl->width_avg = extreme_sum / extreme_count;
        if (cl->width_avg && cl->width_max > cl->width_avg * 2)
            cl->is_extreme = 1;
    }

    /* enlarge to minimal width */
    if (cl->width < cl->width_min && !scols_column_is_strict_width(cl))
        cl->width = cl->width_min;

    /* use absolute size for large columns */
    else if (cl->width_hint >= 1 && cl->width < (size_t)cl->width_hint &&
             cl->width_min < (size_t)cl->width_hint)

        cl->width = (size_t)cl->width_hint;

    /* Column without header and data, set minimal size to zero (default is 1)
     */
    if (cl->width_max == 0 && no_header && cl->width_min == 1 && cl->width <= 1)
        cl->width = cl->width_min = 0;

done:
    ON_DBG(COL, dbg_column(tb, cl));
    return rc;
}
/*
 * This function counts column width.
 *
 * For the SCOLS_FL_NOEXTREMES columns it is possible to call this function
 * two times. The first pass counts the width and average width. If the column
 * contains fields that are too large (a width greater than 2 * average) then
 * the column is marked as "extreme". In the second pass all extreme fields
 * are ignored and the column width is counted from non-extreme fields only.
 */
This function counts column width.
For the SCOLS_FL_NOEXTREMES columns it is possible to call this function
two times. The first pass counts the width and average width. If the column
contains fields that are too large (a width greater than 2 * average) then
the column is marked as "extreme". In the second pass all extreme fields
are ignored and the column width is counted from non-extreme fields only.
This function counts column width . For the SCOLS_FL_NOEXTREMES columns it is possible to call this function two times . The first pass counts the width and average width . If the column contains fields that are too large ( a width greater than 2 * average ) then the column is marked as " extreme " . In the second pass all extreme fields are ignored and the column width is counted from non - extreme fields only .
static int count_column_width(struct libscols_table* tb,
                              struct libscols_column* cl,
                              struct libscols_buffer* buf)
{
    struct libscols_line* ln;
    struct libscols_iter itr;
    int extreme_count = 0, rc = 0, no_header = 0;
    size_t extreme_sum = 0;
    assert(tb);
    assert(cl);
    cl->width = 0;
    if (!cl->width_min)
    {
        if (cl->width_hint < 1 && scols_table_is_maxout(tb) && tb->is_term)
        {
            cl->width_min = (size_t)(cl->width_hint * tb->termwidth);
            if (cl->width_min && !is_last_column(cl))
                cl->width_min--;
        }
        if (scols_cell_get_data(&cl->header))
        {
            size_t len = mbs_safe_width(scols_cell_get_data(&cl->header));
            cl->width_min = max(cl->width_min, len);
        }
        else
            no_header = 1;
        if (!cl->width_min)
            cl->width_min = 1;
    }
    scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
    while (scols_table_next_line(tb, &itr, &ln) == 0)
    {
        size_t len;
        char* data;
        rc = cell_to_buffer(tb, ln, cl, buf);
        if (rc)
            goto done;
        data = buffer_get_data(buf);
        if (!data)
            len = 0;
        else if (scols_column_is_customwrap(cl))
            len = cl->wrap_chunksize(cl, data, cl->wrapfunc_data);
        else
            len = mbs_safe_width(data);
        if (len == (size_t)-1) 
            len = 0;
        cl->width_max = max(len, cl->width_max);
        if (cl->is_extreme && cl->width_avg && len > cl->width_avg * 2)
            continue;
        else if (scols_column_is_noextremes(cl))
        {
            extreme_sum += len;
            extreme_count++;
        }
        cl->width = max(len, cl->width);
        if (scols_column_is_tree(cl))
        {
            size_t treewidth = buffer_get_safe_art_size(buf);
            cl->width_treeart = max(cl->width_treeart, treewidth);
        }
    }
    if (extreme_count && cl->width_avg == 0)
    {
        cl->width_avg = extreme_sum / extreme_count;
        if (cl->width_avg && cl->width_max > cl->width_avg * 2)
            cl->is_extreme = 1;
    }
    if (cl->width < cl->width_min && !scols_column_is_strict_width(cl))
        cl->width = cl->width_min;
    else if (cl->width_hint >= 1 && cl->width < (size_t)cl->width_hint &&
             cl->width_min < (size_t)cl->width_hint)
        cl->width = (size_t)cl->width_hint;
    if (cl->width_max == 0 && no_header && cl->width_min == 1 && cl->width <= 1)
        cl->width = cl->width_min = 0;
done:
    ON_DBG(COL, dbg_column(tb, cl));
    return rc;
}
static int count_column_width ( struct libscols_table * tb , struct libscols_column * cl , struct libscols_buffer * buf ) { struct libscols_line * ln ; struct libscols_iter itr ; int extreme_count = 0 , rc = 0 , no_header = 0 ; size_t extreme_sum = 0 ; assert ( tb ) ; assert ( cl ) ; cl -> width = 0 ; if ( ! cl -> width_min ) { if ( cl -> width_hint < 1 && scols_table_is_maxout ( tb ) && tb -> is_term ) { cl -> width_min = ( size_t ) ( cl -> width_hint * tb -> termwidth ) ; if ( cl -> width_min && ! is_last_column ( cl ) ) cl -> width_min -- ; } if ( scols_cell_get_data ( & cl -> header ) ) { size_t len = mbs_safe_width ( scols_cell_get_data ( & cl -> header ) ) ; cl -> width_min = max ( cl -> width_min , len ) ; } else no_header = 1 ; if ( ! cl -> width_min ) cl -> width_min = 1 ; } scols_reset_iter ( & itr , SCOLS_ITER_FORWARD ) ; while ( scols_table_next_line ( tb , & itr , & ln ) == 0 ) { size_t len ; char * data ; rc = cell_to_buffer ( tb , ln , cl , buf ) ; if ( rc ) goto done ; data = buffer_get_data ( buf ) ; if ( ! data ) len = 0 ; else if ( scols_column_is_customwrap ( cl ) ) len = cl -> wrap_chunksize ( cl , data , cl -> wrapfunc_data ) ; else len = mbs_safe_width ( data ) ; if ( len == ( size_t ) -1 ) len = 0 ; cl -> width_max = max ( len , cl -> width_max ) ; if ( cl -> is_extreme && cl -> width_avg && len > cl -> width_avg * 2 ) continue ; else if ( scols_column_is_noextremes ( cl ) ) { extreme_sum += len ; extreme_count ++ ; } cl -> width = max ( len , cl -> width ) ; if ( scols_column_is_tree ( cl ) ) { size_t treewidth = buffer_get_safe_art_size ( buf ) ; cl -> width_treeart = max ( cl -> width_treeart , treewidth ) ; } } if ( extreme_count && cl -> width_avg == 0 ) { cl -> width_avg = extreme_sum / extreme_count ; if ( cl -> width_avg && cl -> width_max > cl -> width_avg * 2 ) cl -> is_extreme = 1 ; } if ( cl -> width < cl -> width_min && ! scols_column_is_strict_width ( cl ) ) cl -> width = cl -> width_min ; else if ( cl -> width_hint >= 1 && cl -> width < ( size_t ) cl -> width_hint && cl -> width_min < ( size_t ) cl -> width_hint ) cl -> width = ( size_t ) cl -> width_hint ; if ( cl -> width_max == 0 && no_header && cl -> width_min == 1 && cl -> width <= 1 ) cl -> width = cl -> width_min = 0 ; done : ON_DBG ( COL , dbg_column ( tb , cl ) ) ; return rc ; }
This function counts column width.
This function counts column width .
/* ignore broken multibyte strings */ /* enlarge to minimal width */ /* use absolute size for large columns */ /* Column without header and data, set minimal size to zero (default is 1)
     */