summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2009-03-05 15:18:02 +0100
committerJim Meyering <meyering@redhat.com>2009-03-05 16:05:14 +0100
commit8f3560f0ac95db4e72f54adf38df604ea0e4de34 (patch)
treefcb6644c725a983063b23a62579bfcb1a365dcd0
parent87ed16c5469a8a1af88414609215cbbf1a107965 (diff)
downloadparted-8f3560f0ac95db4e72f54adf38df604ea0e4de34.tar.gz
adjust "parted -s dev print" not to emit trailing spaces
* parted/table.c (table_render_row): Don't append trailing spaces or delimiter after final field, and trim any other trailing spaces. * tests/t5000-tags.sh: Remove trailing spaces from expected output.
-rw-r--r--parted/table.c18
-rwxr-xr-xtests/t5000-tags.sh6
2 files changed, 17 insertions, 7 deletions
diff --git a/parted/table.c b/parted/table.c
index 83f9cb5..6bc7f9c 100644
--- a/parted/table.c
+++ b/parted/table.c
@@ -3,7 +3,7 @@
*/
/*
parted - a frontend to libparted
- Copyright (C) 2006-2008 Free Software Foundation, Inc.
+ Copyright (C) 2006-2009 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -173,7 +173,7 @@ void table_add_row_from_strlist (Table* t, StrList* list)
static void table_render_row (Table* t, int rownum, int ncols, wchar_t** s)
{
wchar_t** row = t->rows[rownum];
- int len = 1, i;
+ size_t len = 1, i;
size_t newsize;
assert(t);
@@ -189,6 +189,10 @@ static void table_render_row (Table* t, int rownum, int ncols, wchar_t** s)
for (i = 0; i < ncols; ++i)
{
+ wcscat (*s, row[i]);
+ if (ncols <= i + 1)
+ break;
+
int j;
int nspaces = max(t->widths[i] - wcswidth(row[i], MAX_WIDTH),
0);
@@ -199,15 +203,21 @@ static void table_render_row (Table* t, int rownum, int ncols, wchar_t** s)
pad[nspaces] = L_('\0');
- wcscat (*s, row[i]);
wcscat (*s, pad);
if (i + 1 < ncols)
wcscat (*s, DELIMITER);
free (pad);
- pad = NULL;
}
+ /* Remove any trailing blanks. */
+ wchar_t *p = *s;
+ size_t k = wcslen (p);
+ while (k && p[k-1] == L_(' '))
+ --k;
+ p[k] = L_('\0');
+
+
wcscat (*s, COLSUFFIX);
}
diff --git a/tests/t5000-tags.sh b/tests/t5000-tags.sh
index bb4c6d3..6a89729 100755
--- a/tests/t5000-tags.sh
+++ b/tests/t5000-tags.sh
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2007,2008 Free Software Foundation, Inc.
+# Copyright (C) 2007-2009 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -59,14 +59,14 @@ Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
- 1 17.4kB 48.6kB 31.2kB primary
+ 1 17.4kB 48.6kB 31.2kB primary
Model: (file)
Disk .../$dev: 65.5kB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
-Number Start End Size File system Name Flags
+Number Start End Size File system Name Flags
1 17.4kB 48.6kB 31.2kB primary bios_grub
EOF