~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/ui/browsers/header.c

Version: ~ [ linux-5.4-rc3 ] ~ [ linux-5.3.6 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.79 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.149 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.196 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.196 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.75 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #include "util/cache.h"
  2 #include "util/debug.h"
  3 #include "ui/browser.h"
  4 #include "ui/keysyms.h"
  5 #include "ui/ui.h"
  6 #include "ui/util.h"
  7 #include "ui/libslang.h"
  8 #include "util/header.h"
  9 #include "util/session.h"
 10 
 11 static void ui_browser__argv_write(struct ui_browser *browser,
 12                                    void *entry, int row)
 13 {
 14         char **arg = entry;
 15         char *str = *arg;
 16         char empty[] = " ";
 17         bool current_entry = ui_browser__is_current_entry(browser, row);
 18         unsigned long offset = (unsigned long)browser->priv;
 19 
 20         if (offset >= strlen(str))
 21                 str = empty;
 22         else
 23                 str = str + offset;
 24 
 25         ui_browser__set_color(browser, current_entry ? HE_COLORSET_SELECTED :
 26                                                        HE_COLORSET_NORMAL);
 27 
 28         ui_browser__write_nstring(browser, str, browser->width);
 29 }
 30 
 31 static int list_menu__run(struct ui_browser *menu)
 32 {
 33         int key;
 34         unsigned long offset;
 35         const char help[] =
 36         "h/?/F1        Show this window\n"
 37         "UP/DOWN/PGUP\n"
 38         "PGDN/SPACE\n"
 39         "LEFT/RIGHT    Navigate\n"
 40         "q/ESC/CTRL+C  Exit browser";
 41 
 42         if (ui_browser__show(menu, "Header information", "Press 'q' to exit") < 0)
 43                 return -1;
 44 
 45         while (1) {
 46                 key = ui_browser__run(menu, 0);
 47 
 48                 switch (key) {
 49                 case K_RIGHT:
 50                         offset = (unsigned long)menu->priv;
 51                         offset += 10;
 52                         menu->priv = (void *)offset;
 53                         continue;
 54                 case K_LEFT:
 55                         offset = (unsigned long)menu->priv;
 56                         if (offset >= 10)
 57                                 offset -= 10;
 58                         menu->priv = (void *)offset;
 59                         continue;
 60                 case K_F1:
 61                 case 'h':
 62                 case '?':
 63                         ui_browser__help_window(menu, help);
 64                         continue;
 65                 case K_ESC:
 66                 case 'q':
 67                 case CTRL('c'):
 68                         key = -1;
 69                         break;
 70                 default:
 71                         continue;
 72                 }
 73 
 74                 break;
 75         }
 76 
 77         ui_browser__hide(menu);
 78         return key;
 79 }
 80 
 81 static int ui__list_menu(int argc, char * const argv[])
 82 {
 83         struct ui_browser menu = {
 84                 .entries    = (void *)argv,
 85                 .refresh    = ui_browser__argv_refresh,
 86                 .seek       = ui_browser__argv_seek,
 87                 .write      = ui_browser__argv_write,
 88                 .nr_entries = argc,
 89         };
 90 
 91         return list_menu__run(&menu);
 92 }
 93 
 94 int tui__header_window(struct perf_env *env)
 95 {
 96         int i, argc = 0;
 97         char **argv;
 98         struct perf_session *session;
 99         char *ptr, *pos;
100         size_t size;
101         FILE *fp = open_memstream(&ptr, &size);
102 
103         session = container_of(env, struct perf_session, header.env);
104         perf_header__fprintf_info(session, fp, true);
105         fclose(fp);
106 
107         for (pos = ptr, argc = 0; (pos = strchr(pos, '\n')) != NULL; pos++)
108                 argc++;
109 
110         argv = calloc(argc + 1, sizeof(*argv));
111         if (argv == NULL)
112                 goto out;
113 
114         argv[0] = pos = ptr;
115         for (i = 1; (pos = strchr(pos, '\n')) != NULL; i++) {
116                 *pos++ = '\0';
117                 argv[i] = pos;
118         }
119 
120         BUG_ON(i != argc + 1);
121 
122         ui__list_menu(argc, argv);
123 
124 out:
125         free(argv);
126         free(ptr);
127         return 0;
128 }
129 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp