btrfs-progs: tests: update README, images, coding style
[platform/upstream/btrfs-progs.git] / string-table.c
index d20e6a8..9583376 100644 (file)
  */
 struct string_table *table_create(int columns, int rows)
 {
-       struct string_table *p;
+       struct string_table *tab;
        int size;
 
        size = sizeof(struct string_table) + rows * columns * sizeof(char*);
-       p = calloc(1, size);
+       tab = calloc(1, size);
 
-       if (!p)
+       if (!tab)
                return NULL;
 
-       p->ncols = columns;
-       p->nrows = rows;
+       tab->ncols = columns;
+       tab->nrows = rows;
 
-       return p;
+       return tab;
 }
 
 /*
@@ -49,7 +49,7 @@ struct string_table *table_create(int columns, int rows)
  * be replaced by a '=====' dimensioned on the basis of the column width
  */
 char *table_vprintf(struct string_table *tab, int column, int row,
-                         char *fmt, va_list ap)
+                         const char *fmt, va_list ap)
 {
        int idx = tab->ncols * row + column;
        char *msg = calloc(100, 1);
@@ -69,8 +69,9 @@ char *table_vprintf(struct string_table *tab, int column, int row,
  * This function is like a printf, but store the results in a cell of
  * the table.
  */
+__attribute__ ((format (printf, 4, 5)))
 char *table_printf(struct string_table *tab, int column, int row,
-                         char *fmt, ...)
+                         const char *fmt, ...)
 {
        va_list ap;
        char *ret;
@@ -95,36 +96,36 @@ void table_dump(struct string_table *tab)
                sizes[i] = 0;
                for (j = 0; j < tab->nrows; j++) {
                        int idx = i + j * tab->ncols;
-                       int s;
+                       int len;
 
                        if (!tab->cells[idx])
                                continue;
 
-                       s = strlen(tab->cells[idx]) - 1;
-                       if (s < 1 || tab->cells[idx][0] == '=')
+                       len = strlen(tab->cells[idx]) - 1;
+                       if (len == 0 || tab->cells[idx][0] == '*')
                                continue;
 
-                       if (s > sizes[i])
-                               sizes[i] = s;
+                       if (len > sizes[i])
+                               sizes[i] = len;
                }
        }
 
        for (j = 0; j < tab->nrows; j++) {
                for (i = 0; i < tab->ncols; i++) {
                        int idx = i + j * tab->ncols;
-                       char *s = tab->cells[idx];
+                       char *cell = tab->cells[idx];
 
-                       if (!s || !strlen(s)) {
+                       if (!cell || !strlen(cell)) {
                                printf("%*s", sizes[i], "");
-                       } else if (s && s[0] == '=') {
+                       } else if (cell && cell[0] == '*' && cell[1]) {
                                int k = sizes[i];
 
                                while (k--)
-                                       putchar('=');
+                                       putchar(cell[1]);
                        } else {
                                printf("%*s",
-                                       s[0] == '<' ? -sizes[i] : sizes[i],
-                                       s + 1);
+                                       cell[0] == '<' ? -sizes[i] : sizes[i],
+                                       cell + 1);
                        }
                        if (i != (tab->ncols - 1))
                                putchar(' ');