]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/termtable.c
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[mirror_frr.git] / lib / termtable.c
index fb16e5dba1d00dd41cd919b826b132e5205a5885..4f5f9ff218ef724de1e9e40c3b6966b3c21d57ea 100644 (file)
@@ -31,48 +31,60 @@ struct ttable_style ttable_styles[] = {
                .corner = '+',
                .rownums_on = false,
                .indent = 1,
-               .border.top = '-',
-               .border.bottom = '-',
-               .border.left = '|',
-               .border.right = '|',
-               .border.top_on = true,
-               .border.bottom_on = true,
-               .border.left_on = true,
-               .border.right_on = true,
-               .cell.lpad = 1,
-               .cell.rpad = 1,
-               .cell.align = LEFT,
-               .cell.border.bottom = '-',
-               .cell.border.bottom_on = true,
-               .cell.border.top = '-',
-               .cell.border.top_on = false,
-               .cell.border.right = '|',
-               .cell.border.right_on = true,
-               .cell.border.left = '|',
-               .cell.border.left_on = false,
+               .border = {
+                       .top = '-',
+                       .bottom = '-',
+                       .left = '|',
+                       .right = '|',
+                       .top_on = true,
+                       .bottom_on = true,
+                       .left_on = true,
+                       .right_on = true,
+               },
+               .cell = {
+                       .lpad = 1,
+                       .rpad = 1,
+                       .align = LEFT,
+                       .border = {
+                               .bottom = '-',
+                               .bottom_on = true,
+                               .top = '-',
+                               .top_on = false,
+                               .right = '|',
+                               .right_on = true,
+                               .left = '|',
+                               .left_on = false,
+                       },
+               },
        }, {    // blank, suitable for plaintext alignment
                .corner = ' ',
                .rownums_on = false,
                .indent = 1,
-               .border.top = ' ',
-               .border.bottom = ' ',
-               .border.left = ' ',
-               .border.right = ' ',
-               .border.top_on = false,
-               .border.bottom_on = false,
-               .border.left_on = false,
-               .border.right_on = false,
-               .cell.lpad = 0,
-               .cell.rpad = 3,
-               .cell.align = LEFT,
-               .cell.border.bottom = ' ',
-               .cell.border.bottom_on = false,
-               .cell.border.top = ' ',
-               .cell.border.top_on = false,
-               .cell.border.right = ' ',
-               .cell.border.right_on = false,
-               .cell.border.left = ' ',
-               .cell.border.left_on = false,
+               .border = {
+                       .top = ' ',
+                       .bottom = ' ',
+                       .left = ' ',
+                       .right = ' ',
+                       .top_on = false,
+                       .bottom_on = false,
+                       .left_on = false,
+                       .right_on = false,
+               },
+               .cell = {
+                       .lpad = 0,
+                       .rpad = 3,
+                       .align = LEFT,
+                       .border = {
+                               .bottom = ' ',
+                               .bottom_on = false,
+                               .top = ' ',
+                               .top_on = false,
+                               .right = ' ',
+                               .right_on = false,
+                               .left = ' ',
+                               .left_on = false,
+                       },
+               }
    }
 };
 /* clang-format on */
@@ -123,15 +135,13 @@ static struct ttable_cell *ttable_insert_row_va(struct ttable *tt, int i,
        assert(i >= -1 && i < tt->nrows);
 
        char *res, *orig, *section;
-       const char *f;
        struct ttable_cell *row;
        int col = 0;
        int ncols = 0;
 
        /* count how many columns we have */
-       f = format;
-       for (; f[ncols]; f[ncols] == '|' ? ncols++ : *f++)
-               ;
+       for (int j = 0; format[j]; j++)
+               ncols += !!(format[j] == '|');
        ncols++;
 
        if (tt->ncols == 0)
@@ -338,7 +348,7 @@ char *ttable_dump(struct ttable *tt, const char *newline)
        /* calculate number of lines en total */
        nlines = tt->nrows;
        nlines += tt->style.border.top_on ? 1 : 0;
-       nlines += tt->style.border.bottom_on ? 1 : 1; // makes life easier
+       nlines += 1; // tt->style.border.bottom_on ? 1 : 1; makes life easier
        for (int i = 0; i < tt->nrows; i++) {
                /* if leftmost cell has top / bottom border, whole row does */
                nlines += tt->table[i][0].style.border.top_on ? 1 : 0;
@@ -351,7 +361,7 @@ char *ttable_dump(struct ttable *tt, const char *newline)
        rsize = nl_len + (tt->style.border.right_on ? 1 : 0);
        right = XCALLOC(MTYPE_TTABLE, rsize);
 
-       memset (left, ' ', lsize);
+       memset(left, ' ', lsize);
 
        if (tt->style.border.left_on)
                left[lsize - 1] = tt->style.border.left;
@@ -385,7 +395,7 @@ char *ttable_dump(struct ttable *tt, const char *newline)
                        memcpy(&buf[pos], left, lsize);
                        pos += lsize;
 
-                       for (size_t i = 0; i < width - lsize - rsize; i++)
+                       for (size_t l = 0; l < width - lsize - rsize; l++)
                                buf[pos++] = row[0].style.border.top;
 
                        pos -= width - lsize - rsize;
@@ -411,7 +421,7 @@ char *ttable_dump(struct ttable *tt, const char *newline)
                                buf[pos++] = row[j].style.border.left;
 
                        /* print left padding */
-                       for (int i = 0; i < row[j].style.lpad; i++)
+                       for (int k = 0; k < row[j].style.lpad; k++)
                                buf[pos++] = ' ';
 
                        /* calculate padding for sprintf */
@@ -433,7 +443,7 @@ char *ttable_dump(struct ttable *tt, const char *newline)
                        pos += sprintf(&buf[pos], fmt, abspad, row[j].text);
 
                        /* print right padding */
-                       for (int i = 0; i < row[j].style.rpad; i++)
+                       for (int k = 0; k < row[j].style.rpad; k++)
                                buf[pos++] = ' ';
 
                        /* if right border && not last col print right border */
@@ -449,7 +459,7 @@ char *ttable_dump(struct ttable *tt, const char *newline)
                        memcpy(&buf[pos], left, lsize);
                        pos += lsize;
 
-                       for (size_t i = 0; i < width - lsize - rsize; i++)
+                       for (size_t l = 0; l < width - lsize - rsize; l++)
                                buf[pos++] = row[0].style.border.bottom;
 
                        pos -= width - lsize - rsize;
@@ -473,7 +483,7 @@ char *ttable_dump(struct ttable *tt, const char *newline)
                memcpy(&buf[pos], left, lsize);
                pos += lsize;
 
-               for (size_t i = 0; i < width - lsize - rsize; i++)
+               for (size_t l = 0; l < width - lsize - rsize; l++)
                        buf[pos++] = tt->style.border.bottom;
 
                memcpy(&buf[pos], right, rsize);