/*
* TODO: - make right and centered alignment possible
*/
/*
parted - a frontend to libparted
Copyright (C) 2006-2010 Free Software Foundation, Inc.
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <wchar.h>
#include <string.h>
#include "xalloc.h"
#include "strlist.h"
#ifdef ENABLE_NLS
#else
#endif
typedef struct
{
unsigned int ncols;
unsigned int nrows;
int* widths;
} Table;
{
t->nrows = 0;
return t;
}
{
unsigned int r, c;
assert (t);
for (r = 0; r < t->nrows; ++r)
{
for (c = 0; c < t->ncols; ++c)
}
free (t);
}
static int max (int x, int y)
{
return x > y ? x : y;
}
{
unsigned int r, c;
assert(t);
if (!t->widths)
for (c = 0; c < t->ncols; ++c)
t->widths[c] = 0;
for (r = 0; r < t->nrows; ++r)
for (c = 0; c < t->ncols; ++c)
{
MAX_WIDTH) );
}
}
/*
* add a row which is a string array of ncols elements.
* 'row' will get freed by table_destroy; you must not free it
* yourself.
*/
{
assert(t);
/*unsigned int i;
fputs ("adding row: ", stdout);
for (i = 0; i < t->ncols; ++i)
printf("[%s]", row[i]);
putchar ('\n');*/
++t->nrows;
}
{
int i = 0;
while (list)
{
xalloc_die ();
++i;
}
table_add_row (t, row);
}
/* render a row */
{
assert(t);
for (i = 0; i < ncols; ++i)
for (i = 0; i < ncols; ++i)
{
if (ncols <= i + 1)
break;
int j;
0);
for (j = 0; j < nspaces; ++j)
pad[j] = L' ';
if (i + 1 < ncols)
}
/* Remove any trailing blanks. */
wchar_t *p = *s;
--k;
p[k] = L_('\0');
}
/*
* Render the rows.
* \p s must be a null-terminated string.
*/
{
unsigned int i;
for (i = 0; i < t->nrows; ++i)
table_render_row (t, i, t->ncols, s);
}
/*
* Render the table to a string.
* You are responsible for freeing the returned string.
*/
{
*s = L_('\0');
table_render_rows (t, &s);
return s;
}