summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2016-06-03 12:30:21 +0200
committerMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2016-06-03 12:30:58 +0200
commita531f185872495afa49f52ac84c1d3929113a692 (patch)
treeb48e5cae0bd1fa72282c70ea8253fa39d39f7d68
parentb1924292b42a5084c5269cda908601495be2451f (diff)
downloadlibuca-a531f185872495afa49f52ac84c1d3929113a692.tar.gz
libuca-a531f185872495afa49f52ac84c1d3929113a692.tar.bz2
libuca-a531f185872495afa49f52ac84c1d3929113a692.tar.xz
libuca-a531f185872495afa49f52ac84c1d3929113a692.zip
info: size name column according to longest name
-rw-r--r--bin/tools/info.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/bin/tools/info.c b/bin/tools/info.c
index 42e73f0..ec264cd 100644
--- a/bin/tools/info.c
+++ b/bin/tools/info.c
@@ -16,6 +16,7 @@
Franklin St, Fifth Floor, Boston, MA 02110, USA */
#include <glib-object.h>
+#include <string.h>
#include "uca-plugin-manager.h"
#include "uca-camera.h"
@@ -60,11 +61,18 @@ print_properties (UcaCamera *camera)
{
GObjectClass *oclass;
GParamSpec **pspecs;
+ gchar *fmt_string;
guint n_props;
+ guint max_length = 0;
oclass = G_OBJECT_GET_CLASS (camera);
pspecs = g_object_class_list_properties (oclass, &n_props);
+ for (guint i = 0; i < n_props; i++)
+ max_length = MAX (max_length, strlen (g_param_spec_get_name (pspecs[i])));
+
+ fmt_string = g_strdup_printf (" %%s | %%-%us | %%s\n", max_length);
+
for (guint i = 0; i < n_props; i++) {
GParamSpec *pspec;
GValue value= { 0, { { 0 } } };
@@ -78,12 +86,13 @@ print_properties (UcaCamera *camera)
g_object_get_property (G_OBJECT (camera), name, &value);
value_string = g_strdup_value_contents (&value);
- g_print (" %s | %-26s | %s\n", get_flags_description (pspec), name, value_string);
+ g_print (fmt_string, get_flags_description (pspec), name, value_string);
g_free (value_string);
g_value_unset (&value);
}
+ g_free (fmt_string);
g_free (pspecs);
}