* [Qemu-devel] [PATCH] qemu-log: wrap long text
@ 2013-06-10 4:28 Mike Frysinger
0 siblings, 0 replies; 2+ messages in thread
From: Mike Frysinger @ 2013-06-10 4:28 UTC (permalink / raw)
To: qemu-devel
The existing help output is a bit hard to read due to the ad-hoc wrapping.
This makes it a bit more programmatic (at least, it wraps it once, but
that should be good enough for now). It's not terribly intelligent (just
sticks a dash in the middle of the broken word) rather than splitting on
whitespace, but not sure how much time we really want to invest here.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
qemu-log.c | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/qemu-log.c b/qemu-log.c
index 797f2af..ba432f5 100644
--- a/qemu-log.c
+++ b/qemu-log.c
@@ -98,7 +98,7 @@ const QEMULogItem qemu_log_items[] = {
{ CPU_LOG_TB_OP, "op",
"show micro ops for each compiled TB" },
{ CPU_LOG_TB_OP_OPT, "op_opt",
- "show micro ops (x86 only: before eflags optimization) and\n"
+ "show micro ops (x86 only: before eflags optimization) and "
"after liveness analysis" },
{ CPU_LOG_INT, "int",
"show interrupts/exceptions in short format" },
@@ -115,7 +115,7 @@ const QEMULogItem qemu_log_items[] = {
{ LOG_UNIMP, "unimp",
"log unimplemented functionality" },
{ LOG_GUEST_ERROR, "guest_errors",
- "log when the guest OS does something invalid (eg accessing a\n"
+ "log when the guest OS does something invalid (eg accessing a "
"non-existent register)" },
{ 0, NULL, NULL },
};
@@ -167,8 +167,26 @@ int qemu_str_to_log_mask(const char *str)
void qemu_print_log_usage(FILE *f)
{
const QEMULogItem *item;
+ int name_len, help_len, wrap_len = 80;
+ bool wrapped;
+ char help[wrap_len + 1];
+
fprintf(f, "Log items (comma separated):\n");
+
+ name_len = 0;
for (item = qemu_log_items; item->mask != 0; item++) {
- fprintf(f, "%-10s %s\n", item->name, item->help);
+ name_len = MAX(strlen(item->name), name_len);
+ }
+ help_len = wrap_len - name_len - 1;
+
+ for (item = qemu_log_items; item->mask != 0; item++) {
+ wrapped = snprintf(help, help_len, "%s", item->help) >= help_len;
+ if (wrapped) {
+ strcat(help, "-");
+ }
+ fprintf(f, "%-*s %s\n", name_len, item->name, help);
+ if (wrapped) {
+ fprintf(f, "%-*s %s\n", name_len, "", item->help + help_len - 1);
+ }
}
}
--
1.8.2.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [Qemu-devel] [PATCH] qemu-log: wrap long text
@ 2013-06-17 6:21 Mike Frysinger
0 siblings, 0 replies; 2+ messages in thread
From: Mike Frysinger @ 2013-06-17 6:21 UTC (permalink / raw)
To: qemu-devel
The existing help output is a bit hard to read due to the ad-hoc wrapping.
This makes it a bit more programmatic (at least, it wraps it once, but
that should be good enough for now). It's not terribly intelligent (just
sticks a dash in the middle of the broken word) rather than splitting on
whitespace, but not sure how much time we really want to invest here.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
qemu-log.c | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/qemu-log.c b/qemu-log.c
index 797f2af..ba432f5 100644
--- a/qemu-log.c
+++ b/qemu-log.c
@@ -98,7 +98,7 @@ const QEMULogItem qemu_log_items[] = {
{ CPU_LOG_TB_OP, "op",
"show micro ops for each compiled TB" },
{ CPU_LOG_TB_OP_OPT, "op_opt",
- "show micro ops (x86 only: before eflags optimization) and\n"
+ "show micro ops (x86 only: before eflags optimization) and "
"after liveness analysis" },
{ CPU_LOG_INT, "int",
"show interrupts/exceptions in short format" },
@@ -115,7 +115,7 @@ const QEMULogItem qemu_log_items[] = {
{ LOG_UNIMP, "unimp",
"log unimplemented functionality" },
{ LOG_GUEST_ERROR, "guest_errors",
- "log when the guest OS does something invalid (eg accessing a\n"
+ "log when the guest OS does something invalid (eg accessing a "
"non-existent register)" },
{ 0, NULL, NULL },
};
@@ -167,8 +167,26 @@ int qemu_str_to_log_mask(const char *str)
void qemu_print_log_usage(FILE *f)
{
const QEMULogItem *item;
+ int name_len, help_len, wrap_len = 80;
+ bool wrapped;
+ char help[wrap_len + 1];
+
fprintf(f, "Log items (comma separated):\n");
+
+ name_len = 0;
for (item = qemu_log_items; item->mask != 0; item++) {
- fprintf(f, "%-10s %s\n", item->name, item->help);
+ name_len = MAX(strlen(item->name), name_len);
+ }
+ help_len = wrap_len - name_len - 1;
+
+ for (item = qemu_log_items; item->mask != 0; item++) {
+ wrapped = snprintf(help, help_len, "%s", item->help) >= help_len;
+ if (wrapped) {
+ strcat(help, "-");
+ }
+ fprintf(f, "%-*s %s\n", name_len, item->name, help);
+ if (wrapped) {
+ fprintf(f, "%-*s %s\n", name_len, "", item->help + help_len - 1);
+ }
}
}
--
1.8.2.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-06-17 6:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-17 6:21 [Qemu-devel] [PATCH] qemu-log: wrap long text Mike Frysinger
-- strict thread matches above, loose matches on Subject: below --
2013-06-10 4:28 Mike Frysinger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).