1 #include <gtk/gtk.h>
2 #include <gtk/gtkx.h>
3 #include <stdio.h>
4 #include <string.h>
5
6 char USAGE[] =
7 "is a helper utility for rendering the GNUplot graphs in a GTK window. This allows to real time resizing, scrolling, and cursor positioning features while viewing the graph. This utility also provides options to hide graphs using check buttons.\n \
8 \n \
9 Usage:\n \
10 -h, --help Show this help menu\n \
11 \n \
12 NOTE: This utility is not meant to be used standalone. Never run this utility directly. Always run afl-plot, which will, in turn, invoke this utility (when run using `-g` or `--graphical` flag).\n \
13 ";
14
15 static void plot_toggled(GtkWidget *caller, gpointer data);
16
main(int argc,char ** argv)17 int main(int argc, char **argv) {
18
19 if (argc == 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "-help"))) {
20
21 printf("%s %s", argv[0], USAGE);
22 return EXIT_SUCCESS;
23
24 }
25
26 GtkWidget *window;
27 GtkWidget *main_vbox;
28
29 GtkWidget *cbuttons_frame;
30 GtkWidget *cbuttons_hbox;
31
32 GtkWidget *separator_top;
33 GtkWidget *pane1, *pane2, *pane3;
34
35 GtkWidget *plots_vbox;
36 GtkWidget *plot_edges_frame, *plot_exec_speed_frame, *plot_high_freq_frame,
37 *plot_low_freq_frame;
38 GtkWidget *plot_edges, *plot_exec_speed, *plot_high_freq, *plot_low_freq;
39
40 gtk_init(&argc, &argv);
41
42 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
43 gtk_window_set_title(GTK_WINDOW(window), "Graph drawing");
44 gtk_container_set_border_width(GTK_CONTAINER(window), 10);
45
46 main_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
47
48 cbuttons_frame = gtk_frame_new("Select the plots");
49 gtk_container_set_border_width(GTK_CONTAINER(cbuttons_frame), 5);
50
51 cbuttons_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1);
52
53 GtkWidget *cbutton_edges, *cbutton_exec_speed, *cbutton_high_freq,
54 *cbutton_low_freq;
55
56 cbutton_edges = gtk_check_button_new_with_label("Edges");
57 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbutton_edges), TRUE);
58 g_signal_connect(cbutton_edges, "toggled", G_CALLBACK(plot_toggled),
59 &plot_edges_frame);
60
61 cbutton_exec_speed = gtk_check_button_new_with_label("Execution Speed");
62 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbutton_exec_speed), TRUE);
63 g_signal_connect(cbutton_exec_speed, "toggled", G_CALLBACK(plot_toggled),
64 &plot_exec_speed_frame);
65
66 cbutton_high_freq = gtk_check_button_new_with_label("High Frequency");
67 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbutton_high_freq), TRUE);
68 g_signal_connect(cbutton_high_freq, "toggled", G_CALLBACK(plot_toggled),
69 &plot_high_freq_frame);
70
71 cbutton_low_freq = gtk_check_button_new_with_label("Low Frequency");
72 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbutton_low_freq), TRUE);
73 g_signal_connect(cbutton_low_freq, "toggled", G_CALLBACK(plot_toggled),
74 &plot_low_freq_frame);
75
76 gtk_box_pack_start(GTK_BOX(cbuttons_hbox), cbutton_edges, TRUE, TRUE, 1);
77 gtk_box_pack_start(GTK_BOX(cbuttons_hbox), cbutton_exec_speed, TRUE, TRUE, 1);
78 gtk_box_pack_start(GTK_BOX(cbuttons_hbox), cbutton_high_freq, TRUE, TRUE, 1);
79 gtk_box_pack_start(GTK_BOX(cbuttons_hbox), cbutton_low_freq, TRUE, TRUE, 1);
80
81 gtk_container_add(GTK_CONTAINER(cbuttons_frame), cbuttons_hbox);
82 gtk_box_pack_start(GTK_BOX(main_vbox), cbuttons_frame, FALSE, TRUE, 1);
83
84 separator_top = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
85 gtk_box_pack_start(GTK_BOX(main_vbox), separator_top, FALSE, TRUE, 1);
86
87 plots_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
88
89 plot_edges_frame = gtk_frame_new("Edges");
90 gtk_frame_set_shadow_type(GTK_FRAME(plot_edges_frame), GTK_SHADOW_IN);
91 gtk_container_set_border_width(GTK_CONTAINER(plot_edges_frame), 10);
92 plot_edges = gtk_socket_new();
93 gtk_widget_set_size_request(plot_edges, -1, 100);
94 gtk_container_add(GTK_CONTAINER(plot_edges_frame), plot_edges);
95
96 plot_exec_speed_frame = gtk_frame_new("Exec Speed");
97 gtk_frame_set_shadow_type(GTK_FRAME(plot_exec_speed_frame), GTK_SHADOW_IN);
98 gtk_container_set_border_width(GTK_CONTAINER(plot_exec_speed_frame), 10);
99 plot_exec_speed = gtk_socket_new();
100 gtk_widget_set_size_request(plot_exec_speed, -1, 100);
101 gtk_container_add(GTK_CONTAINER(plot_exec_speed_frame), plot_exec_speed);
102
103 plot_high_freq_frame = gtk_frame_new("High Frequency");
104 gtk_frame_set_shadow_type(GTK_FRAME(plot_high_freq_frame), GTK_SHADOW_IN);
105 gtk_container_set_border_width(GTK_CONTAINER(plot_high_freq_frame), 10);
106 plot_high_freq = gtk_socket_new();
107 gtk_widget_set_size_request(plot_high_freq, -1, 100);
108 gtk_container_add(GTK_CONTAINER(plot_high_freq_frame), plot_high_freq);
109
110 plot_low_freq_frame = gtk_frame_new("Low Frequency");
111 gtk_frame_set_shadow_type(GTK_FRAME(plot_low_freq_frame), GTK_SHADOW_IN);
112 gtk_container_set_border_width(GTK_CONTAINER(plot_low_freq_frame), 10);
113 plot_low_freq = gtk_socket_new();
114 gtk_widget_set_size_request(plot_low_freq, -1, 100);
115 gtk_container_add(GTK_CONTAINER(plot_low_freq_frame), plot_low_freq);
116
117 pane1 = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
118 pane2 = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
119 pane3 = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
120
121 gtk_paned_pack1(GTK_PANED(pane1), plot_edges_frame, TRUE, FALSE);
122 gtk_paned_pack2(GTK_PANED(pane1), plot_exec_speed_frame, TRUE, FALSE);
123
124 gtk_paned_pack1(GTK_PANED(pane2), pane1, TRUE, FALSE);
125 gtk_paned_pack2(GTK_PANED(pane2), plot_high_freq_frame, TRUE, FALSE);
126
127 gtk_paned_pack1(GTK_PANED(pane3), pane2, TRUE, FALSE);
128 gtk_paned_pack2(GTK_PANED(pane3), plot_low_freq_frame, TRUE, FALSE);
129
130 gtk_box_pack_start(GTK_BOX(plots_vbox), pane3, TRUE, TRUE, 0);
131
132 gtk_box_pack_start(GTK_BOX(main_vbox), plots_vbox, TRUE, TRUE, 1);
133
134 gtk_container_add(GTK_CONTAINER(window), main_vbox);
135
136 guint id_edges = gtk_socket_get_id(GTK_SOCKET(plot_edges));
137 guint id_exec_speed = gtk_socket_get_id(GTK_SOCKET(plot_exec_speed));
138 guint id_high_freq = gtk_socket_get_id(GTK_SOCKET(plot_high_freq));
139 guint id_low_freq = gtk_socket_get_id(GTK_SOCKET(plot_low_freq));
140
141 printf("%x\n%x\n%x\n%x\n", id_edges, id_exec_speed, id_high_freq,
142 id_low_freq);
143
144 fclose(stdout);
145
146 g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit),
147 NULL);
148 gtk_widget_show_all(window);
149 gtk_window_maximize(GTK_WINDOW(window));
150 gtk_main();
151
152 return EXIT_SUCCESS;
153
154 }
155
plot_toggled(GtkWidget * caller,gpointer data)156 static void plot_toggled(GtkWidget *caller, gpointer data) {
157
158 gboolean state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(caller));
159
160 GtkWidget *widget = *(GtkWidget **)data;
161
162 if (state) {
163
164 gtk_widget_show(widget);
165
166 } else {
167
168 gtk_widget_hide(widget);
169
170 }
171
172 }
173
174