projects
/
platform
/
upstream
/
btrfs-progs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
btrfs-progs: Beautify owner when printing leaf/nodes
[platform/upstream/btrfs-progs.git]
/
string-table.c
diff --git
a/string-table.c
b/string-table.c
index
701f214
..
9583376
100644
(file)
--- a/
string-table.c
+++ b/
string-table.c
@@
-26,19
+26,19
@@
*/
struct string_table *table_create(int columns, int rows)
{
*/
struct string_table *table_create(int columns, int rows)
{
- struct string_table *
p
;
+ struct string_table *
tab
;
int size;
int size;
- size = sizeof( struct string_table ) +
- rows * columns* sizeof(char *);
- p = calloc(1, size);
+ size = sizeof(struct string_table) + rows * columns * sizeof(char*);
+ tab = calloc(1, size);
- if (!p) return NULL;
+ if (!tab)
+ return NULL;
-
p
->ncols = columns;
-
p
->nrows = rows;
+
tab
->ncols = columns;
+
tab
->nrows = rows;
- return
p
;
+ return
tab
;
}
/*
}
/*
@@
-49,10
+49,10
@@
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,
* 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)
+ c
onst c
har *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;
if (!msg)
return NULL;
@@
-65,13
+65,13
@@
char *table_vprintf(struct string_table *tab, int column, int row,
return msg;
}
return msg;
}
-
/*
* This function is like a printf, but store the results in a cell of
* the table.
*/
/*
* 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 *table_printf(struct string_table *tab, int column, int row,
- char *fmt, ...)
+ c
onst c
har *fmt, ...)
{
va_list ap;
char *ret;
{
va_list ap;
char *ret;
@@
-89,68
+89,63
@@
char *table_printf(struct string_table *tab, int column, int row,
*/
void table_dump(struct string_table *tab)
{
*/
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;
sizes[i] = 0;
- for (j = 0
; j < tab->nrows
; j++) {
- int idx = i + j
*
tab->ncols;
- int
s
;
+ for (j = 0
; j < tab->nrows
; j++) {
+ int idx = i + j
*
tab->ncols;
+ int
len
;
if (!tab->cells[idx])
continue;
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;
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 *cell = tab->cells[idx];
- 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 (!cell || !strlen(cell)) {
printf("%*s", sizes[i], "");
printf("%*s", sizes[i], "");
- } else if (
s && s[0] == '='
) {
+ } else if (
cell && cell[0] == '*' && cell[1]
) {
int k = sizes[i];
int k = sizes[i];
- while(k--)
- putchar('=');
+
+ while (k--)
+ putchar(cell[1]);
} else {
printf("%*s",
} 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(' ');
}
putchar('\n');
}
}
if (i != (tab->ncols - 1))
putchar(' ');
}
putchar('\n');
}
-
}
/*
}
/*
- * Deallocate a tab
ular and all
its content
+ * Deallocate a tab
le and all of
its content
*/
*/
-
void table_free(struct string_table *tab)
{
void table_free(struct string_table *tab)
{
-
- int i, count;
+ int i, count;
count = tab->ncols * tab->nrows;
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);
if (tab->cells[i])
free(tab->cells[i]);
free(tab);
-
}
}