kvm tools: Add ivshmem device
[linux-2.6/next.git] / tools / perf / util / ui / helpline.c
blobf36d2ff509ed285baa5290d6780b3e9d8ca4ae9e
1 #define _GNU_SOURCE
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <newt.h>
6 #include "../debug.h"
7 #include "helpline.h"
8 #include "ui.h"
10 void ui_helpline__pop(void)
12 newtPopHelpLine();
15 void ui_helpline__push(const char *msg)
17 newtPushHelpLine(msg);
20 void ui_helpline__vpush(const char *fmt, va_list ap)
22 char *s;
24 if (vasprintf(&s, fmt, ap) < 0)
25 vfprintf(stderr, fmt, ap);
26 else {
27 ui_helpline__push(s);
28 free(s);
32 void ui_helpline__fpush(const char *fmt, ...)
34 va_list ap;
36 va_start(ap, fmt);
37 ui_helpline__vpush(fmt, ap);
38 va_end(ap);
41 void ui_helpline__puts(const char *msg)
43 ui_helpline__pop();
44 ui_helpline__push(msg);
47 void ui_helpline__init(void)
49 ui_helpline__puts(" ");
52 char ui_helpline__last_msg[1024];
54 int ui_helpline__show_help(const char *format, va_list ap)
56 int ret;
57 static int backlog;
59 pthread_mutex_lock(&ui__lock);
60 ret = vsnprintf(ui_helpline__last_msg + backlog,
61 sizeof(ui_helpline__last_msg) - backlog, format, ap);
62 backlog += ret;
64 if (ui_helpline__last_msg[backlog - 1] == '\n') {
65 ui_helpline__puts(ui_helpline__last_msg);
66 newtRefresh();
67 backlog = 0;
69 pthread_mutex_unlock(&ui__lock);
71 return ret;