Merge branch 'linus' into x86/urgent
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / tools / perf / util / ui / helpline.c
CommitLineData
5575536f
ACM
1#define _GNU_SOURCE
2#include <stdio.h>
3#include <stdlib.h>
4#include <newt.h>
5
1e6dd077 6#include "../debug.h"
5575536f 7#include "helpline.h"
5c35d69f 8#include "ui.h"
5575536f
ACM
9
10void ui_helpline__pop(void)
11{
12 newtPopHelpLine();
13}
14
15void ui_helpline__push(const char *msg)
16{
17 newtPushHelpLine(msg);
18}
19
59e8fe32 20void ui_helpline__vpush(const char *fmt, va_list ap)
5575536f
ACM
21{
22 char *s;
23
24 if (vasprintf(&s, fmt, ap) < 0)
25 vfprintf(stderr, fmt, ap);
26 else {
27 ui_helpline__push(s);
28 free(s);
29 }
30}
31
32void ui_helpline__fpush(const char *fmt, ...)
33{
34 va_list ap;
35
36 va_start(ap, fmt);
37 ui_helpline__vpush(fmt, ap);
38 va_end(ap);
39}
40
41void ui_helpline__puts(const char *msg)
42{
43 ui_helpline__pop();
44 ui_helpline__push(msg);
45}
1e6dd077
ACM
46
47void ui_helpline__init(void)
48{
49 ui_helpline__puts(" ");
50}
51
52char ui_helpline__last_msg[1024];
53
54int ui_helpline__show_help(const char *format, va_list ap)
55{
56 int ret;
57 static int backlog;
58
5c35d69f
ACM
59 pthread_mutex_lock(&ui__lock);
60 ret = vsnprintf(ui_helpline__last_msg + backlog,
1e6dd077
ACM
61 sizeof(ui_helpline__last_msg) - backlog, format, ap);
62 backlog += ret;
63
64 if (ui_helpline__last_msg[backlog - 1] == '\n') {
65 ui_helpline__puts(ui_helpline__last_msg);
66 newtRefresh();
67 backlog = 0;
68 }
5c35d69f 69 pthread_mutex_unlock(&ui__lock);
1e6dd077
ACM
70
71 return ret;
72}