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/text-utils/col.c
void flush_line(LINE* l)
{
    CHAR *c, *endc;
    int nchars, last_col, this_col;

    last_col = 0;
    nchars = l->l_line_len;

    if (l->l_needs_sort)
    {
        static CHAR* sorted;
        static int count_size, *count, i, save, sorted_size, tot;

        /*
         * Do an O(n) sort on l->l_line by column being careful to
         * preserve the order of characters in the same column.
         */
        if (l->l_lsize > sorted_size)
        {
            sorted_size = l->l_lsize;
            sorted =
                xrealloc((void*)sorted, (unsigned)sizeof(CHAR) * sorted_size);
        }
        if (l->l_max_col >= count_size)
        {
            count_size = l->l_max_col + 1;
            count = (int*)xrealloc((void*)count,
                                   (unsigned)sizeof(int) * count_size);
        }
        memset(count, 0, sizeof(int) * l->l_max_col + 1);
        for (i = nchars, c = l->l_line; --i >= 0; c++)
            count[c->c_column]++;

        /*
         * calculate running total (shifted down by 1) to use as
         * indices into new line.
         */
        for (tot = 0, i = 0; i <= l->l_max_col; i++)
        {
            save = count[i];
            count[i] = tot;
            tot += save;
        }

        for (i = nchars, c = l->l_line; --i >= 0; c++)
            sorted[count[c->c_column]++] = *c;
        c = sorted;
    }
    else
        c = l->l_line;
    while (nchars > 0)
    {
        this_col = c->c_column;
        endc = c;
        do
        {
            ++endc;
        } while (--nchars > 0 && this_col == endc->c_column);

        /* if -b only print last character */
        if (no_backspaces)
        {
            c = endc - 1;
            if (nchars > 0 && this_col + c->c_width > endc->c_column)
                continue;
        }

        if (this_col > last_col)
        {
            int nspace = this_col - last_col;

            if (compress_spaces && nspace > 1)
            {
                int ntabs;

                ntabs = this_col / 8 - last_col / 8;
                if (ntabs > 0)
                {
                    nspace = this_col & 7;
                    while (--ntabs >= 0)
                        PUTC('\t');
                }
            }
            while (--nspace >= 0)
                PUTC(' ');
            last_col = this_col;
        }

        for (;;)
        {
            if (c->c_set != last_set)
            {
                switch (c->c_set)
                {
                    case CS_NORMAL:
                        PUTC('\017');
                        break;
                    case CS_ALTERNATE:
                        PUTC('\016');
                }
                last_set = c->c_set;
            }
            PUTC(c->c_char);
            if ((c + 1) < endc)
            {
                int i;
                for (i = 0; i < c->c_width; i++)
                    PUTC('\b');
            }
            if (++c >= endc)
                break;
        }
        last_col += (c - 1)->c_width;
    }
}
/*
 * Write a line to stdout taking care of space to tab conversion (-h flag)
 * and character set shifts.
 */
Write a line to stdout taking care of space to tab conversion (-h flag)
and character set shifts.
Write a line to stdout taking care of space to tab conversion ( - h flag ) and character set shifts .
void flush_line(LINE* l)
{
    CHAR *c, *endc;
    int nchars, last_col, this_col;
    last_col = 0;
    nchars = l->l_line_len;
    if (l->l_needs_sort)
    {
        static CHAR* sorted;
        static int count_size, *count, i, save, sorted_size, tot;
        if (l->l_lsize > sorted_size)
        {
            sorted_size = l->l_lsize;
            sorted =
                xrealloc((void*)sorted, (unsigned)sizeof(CHAR) * sorted_size);
        }
        if (l->l_max_col >= count_size)
        {
            count_size = l->l_max_col + 1;
            count = (int*)xrealloc((void*)count,
                                   (unsigned)sizeof(int) * count_size);
        }
        memset(count, 0, sizeof(int) * l->l_max_col + 1);
        for (i = nchars, c = l->l_line; --i >= 0; c++)
            count[c->c_column]++;
        for (tot = 0, i = 0; i <= l->l_max_col; i++)
        {
            save = count[i];
            count[i] = tot;
            tot += save;
        }
        for (i = nchars, c = l->l_line; --i >= 0; c++)
            sorted[count[c->c_column]++] = *c;
        c = sorted;
    }
    else
        c = l->l_line;
    while (nchars > 0)
    {
        this_col = c->c_column;
        endc = c;
        do
        {
            ++endc;
        } while (--nchars > 0 && this_col == endc->c_column);
        if (no_backspaces)
        {
            c = endc - 1;
            if (nchars > 0 && this_col + c->c_width > endc->c_column)
                continue;
        }
        if (this_col > last_col)
        {
            int nspace = this_col - last_col;
            if (compress_spaces && nspace > 1)
            {
                int ntabs;
                ntabs = this_col / 8 - last_col / 8;
                if (ntabs > 0)
                {
                    nspace = this_col & 7;
                    while (--ntabs >= 0)
                        PUTC('\t');
                }
            }
            while (--nspace >= 0)
                PUTC(' ');
            last_col = this_col;
        }
        for (;;)
        {
            if (c->c_set != last_set)
            {
                switch (c->c_set)
                {
                    case CS_NORMAL:
                        PUTC('\017');
                        break;
                    case CS_ALTERNATE:
                        PUTC('\016');
                }
                last_set = c->c_set;
            }
            PUTC(c->c_char);
            if ((c + 1) < endc)
            {
                int i;
                for (i = 0; i < c->c_width; i++)
                    PUTC('\b');
            }
            if (++c >= endc)
                break;
        }
        last_col += (c - 1)->c_width;
    }
}
void flush_line ( LINE * l ) { CHAR * c , * endc ; int nchars , last_col , this_col ; last_col = 0 ; nchars = l -> l_line_len ; if ( l -> l_needs_sort ) { static CHAR * sorted ; static int count_size , * count , i , save , sorted_size , tot ; if ( l -> l_lsize > sorted_size ) { sorted_size = l -> l_lsize ; sorted = xrealloc ( ( void * ) sorted , ( unsigned ) sizeof ( CHAR ) * sorted_size ) ; } if ( l -> l_max_col >= count_size ) { count_size = l -> l_max_col + 1 ; count = ( int * ) xrealloc ( ( void * ) count , ( unsigned ) sizeof ( int ) * count_size ) ; } memset ( count , 0 , sizeof ( int ) * l -> l_max_col + 1 ) ; for ( i = nchars , c = l -> l_line ; -- i >= 0 ; c ++ ) count [ c -> c_column ] ++ ; for ( tot = 0 , i = 0 ; i <= l -> l_max_col ; i ++ ) { save = count [ i ] ; count [ i ] = tot ; tot += save ; } for ( i = nchars , c = l -> l_line ; -- i >= 0 ; c ++ ) sorted [ count [ c -> c_column ] ++ ] = * c ; c = sorted ; } else c = l -> l_line ; while ( nchars > 0 ) { this_col = c -> c_column ; endc = c ; do { ++ endc ; } while ( -- nchars > 0 && this_col == endc -> c_column ) ; if ( no_backspaces ) { c = endc - 1 ; if ( nchars > 0 && this_col + c -> c_width > endc -> c_column ) continue ; } if ( this_col > last_col ) { int nspace = this_col - last_col ; if ( compress_spaces && nspace > 1 ) { int ntabs ; ntabs = this_col / 8 - last_col / 8 ; if ( ntabs > 0 ) { nspace = this_col & 7 ; while ( -- ntabs >= 0 ) PUTC ( ' \t ' ) ; } } while ( -- nspace >= 0 ) PUTC ( ' ' ) ; last_col = this_col ; } for ( ; ; ) { if ( c -> c_set != last_set ) { switch ( c -> c_set ) { case CS_NORMAL : PUTC ( ' \017 ' ) ; break ; case CS_ALTERNATE : PUTC ( ' \016 ' ) ; } last_set = c -> c_set ; } PUTC ( c -> c_char ) ; if ( ( c + 1 ) < endc ) { int i ; for ( i = 0 ; i < c -> c_width ; i ++ ) PUTC ( ' \b ' ) ; } if ( ++ c >= endc ) break ; } last_col += ( c - 1 ) -> c_width ; } }
Write a line to stdout taking care of space to tab conversion (-h flag)
 and character set shifts.
Write a line to stdout taking care of space to tab conversion ( - h flag ) and character set shifts .
/*
         * Do an O(n) sort on l->l_line by column being careful to
         * preserve the order of characters in the same column.
         */ /*
         * calculate running total (shifted down by 1) to use as
         * indices into new line.
         */ /* if -b only print last character */