summaryrefslogtreecommitdiff
path: root/string-table.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2015-11-03 00:46:52 +0100
committerDavid Sterba <dsterba@suse.com>2015-11-03 00:55:20 +0100
commit7a9159277538f010b9de0da4ed2134434acd4593 (patch)
tree55e685a92a9e2236b2beffe2aef26f889e31e384 /string-table.c
parent952251481e3ebc9e98204701db5fd4ec2f9ec0f6 (diff)
btrfs-progs: string table: fix whitespace damage
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'string-table.c')
-rw-r--r--string-table.c46
1 files changed, 20 insertions, 26 deletions
diff --git a/string-table.c b/string-table.c
index 701f2147..d20e6a82 100644
--- a/string-table.c
+++ b/string-table.c
@@ -29,11 +29,11 @@ struct string_table *table_create(int columns, int rows)
struct string_table *p;
int size;
- size = sizeof( struct string_table ) +
- rows * columns* sizeof(char *);
+ size = sizeof(struct string_table) + rows * columns * sizeof(char*);
p = calloc(1, size);
- if (!p) return NULL;
+ if (!p)
+ return NULL;
p->ncols = columns;
p->nrows = rows;
@@ -51,8 +51,8 @@ struct string_table *table_create(int columns, int rows)
char *table_vprintf(struct string_table *tab, int column, int row,
char *fmt, va_list ap)
{
- int idx = tab->ncols*row+column;
- char *msg = calloc(100, sizeof(char));
+ int idx = tab->ncols * row + column;
+ char *msg = calloc(100, 1);
if (!msg)
return NULL;
@@ -65,7 +65,6 @@ char *table_vprintf(struct string_table *tab, int column, int row,
return msg;
}
-
/*
* This function is like a printf, but store the results in a cell of
* the table.
@@ -89,13 +88,13 @@ char *table_printf(struct string_table *tab, int column, int row,
*/
void table_dump(struct string_table *tab)
{
- int sizes[tab->ncols];
- int i, j;
+ int sizes[tab->ncols];
+ int i, j;
- for (i = 0 ; i < tab->ncols ; i++) {
+ for (i = 0; i < tab->ncols; i++) {
sizes[i] = 0;
- for (j = 0 ; j < tab->nrows ; j++) {
- int idx = i + j*tab->ncols;
+ for (j = 0; j < tab->nrows; j++) {
+ int idx = i + j * tab->ncols;
int s;
if (!tab->cells[idx])
@@ -110,47 +109,42 @@ void table_dump(struct string_table *tab)
}
}
-
- for (j = 0 ; j < tab->nrows ; j++) {
- for (i = 0 ; i < tab->ncols ; i++) {
-
- int idx = i + j*tab->ncols;
+ 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];
- if (!s|| !strlen(s)) {
+ if (!s || !strlen(s)) {
printf("%*s", sizes[i], "");
} else if (s && s[0] == '=') {
int k = sizes[i];
- while(k--)
+
+ while (k--)
putchar('=');
} else {
printf("%*s",
s[0] == '<' ? -sizes[i] : sizes[i],
- s+1);
+ s + 1);
}
if (i != (tab->ncols - 1))
putchar(' ');
}
putchar('\n');
}
-
}
/*
- * Deallocate a tabular and all its content
+ * Deallocate a table and all of its content
*/
-
void table_free(struct string_table *tab)
{
-
- int i, count;
+ int i, count;
count = tab->ncols * tab->nrows;
- for (i=0 ; i < count ; i++)
+ for (i = 0; i < count; i++)
if (tab->cells[i])
free(tab->cells[i]);
free(tab);
-
}