summaryrefslogtreecommitdiffstats
path: root/libdm/libdm-report.c
diff options
context:
space:
mode:
authorAlasdair Kergon <agk@redhat.com>2008-04-20 00:11:08 +0000
committerAlasdair Kergon <agk@redhat.com>2008-04-20 00:11:08 +0000
commitc791f186ce6b9966e2cd8fd0a3ee50ea140ee7c4 (patch)
tree4124efc08ace563c3a46c1d80f37e1d87f2d5415 /libdm/libdm-report.c
parentf44e3ff46aab56c4ffcd4e86f4786ed06bf82a02 (diff)
downloadlvm2-c791f186ce6b9966e2cd8fd0a3ee50ea140ee7c4.tar.gz
lvm2-c791f186ce6b9966e2cd8fd0a3ee50ea140ee7c4.tar.xz
lvm2-c791f186ce6b9966e2cd8fd0a3ee50ea140ee7c4.zip
Add field name prefix option to reporting functions.
Diffstat (limited to 'libdm/libdm-report.c')
-rw-r--r--libdm/libdm-report.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/libdm/libdm-report.c b/libdm/libdm-report.c
index 71004dd1..f5758b63 100644
--- a/libdm/libdm-report.c
+++ b/libdm/libdm-report.c
@@ -17,6 +17,8 @@
#include "list.h"
#include "log.h"
+#include <ctype.h>
+
/*
* Internal flags
*/
@@ -27,6 +29,7 @@ struct dm_report {
struct dm_pool *mem;
uint32_t report_types;
+ const char *output_field_name_prefix;
const char *field_prefix;
uint32_t flags;
const char *separator;
@@ -551,6 +554,31 @@ void dm_report_free(struct dm_report *rh)
dm_free(rh);
}
+static char *_toupperstr(char *str)
+{
+ char *u = str;
+
+ do
+ *u = toupper(*u);
+ while (*u++);
+
+ return str;
+}
+
+int dm_report_set_output_field_name_prefix(struct dm_report *rh, const char *output_field_name_prefix)
+{
+ char *prefix;
+
+ if (!(prefix = dm_pool_strdup(rh->mem, output_field_name_prefix))) {
+ log_error("dm_report_set_output_field_name_prefix: dm_pool_strdup failed");
+ return 0;
+ }
+
+ rh->output_field_name_prefix = _toupperstr(prefix);
+
+ return 1;
+}
+
/*
* Create a row of data for an object
*/
@@ -771,6 +799,7 @@ int dm_report_output(struct dm_report *rh)
struct row *row = NULL;
struct dm_report_field *field;
const char *repstr;
+ char *field_id;
char buf[4096];
int32_t width;
uint32_t align;
@@ -798,6 +827,30 @@ int dm_report_output(struct dm_report *rh)
if (field->props->flags & FLD_HIDDEN)
continue;
+ if (rh->flags & DM_REPORT_OUTPUT_FIELD_NAME_PREFIX) {
+ if (!(field_id = strdup(rh->fields[field->props->field_num].id))) {
+ log_error("dm_report: Failed to copy field name");
+ goto bad;
+ }
+
+ if (!dm_pool_grow_object(rh->mem, rh->output_field_name_prefix, 0)) {
+ log_error("dm_report: Unable to extend output line");
+ goto bad;
+ }
+
+ if (!dm_pool_grow_object(rh->mem, _toupperstr(field_id), 0)) {
+ log_error("dm_report: Unable to extend output line");
+ goto bad;
+ }
+
+ free(field_id);
+
+ if (!dm_pool_grow_object(rh->mem, "=\"", 2)) {
+ log_error("dm_report: Unable to extend output line");
+ goto bad;
+ }
+ }
+
repstr = field->report_string;
width = field->props->width;
if (!(rh->flags & DM_REPORT_OUTPUT_ALIGNED)) {
@@ -832,6 +885,12 @@ int dm_report_output(struct dm_report *rh)
}
}
+ if (rh->flags & DM_REPORT_OUTPUT_FIELD_NAME_PREFIX)
+ if (!dm_pool_grow_object(rh->mem, "\"", 1)) {
+ log_error("dm_report: Unable to extend output line");
+ goto bad;
+ }
+
if (!list_end(&row->fields, fh))
if (!dm_pool_grow_object(rh->mem, rh->separator, 0)) {
log_error("dm_report: Unable to extend output line");