Detect clang and llvm-gcc.
[obnox/wireshark/wip.git] / gtk / packet_history.c
1 /* packet_history.c
2  * packet history related functions   2004 Ulf Lamping
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <stdio.h>
30
31 #include <gtk/gtk.h>
32
33 #include "../file.h"
34 #include "../globals.h"
35
36 #include "gtk/menus.h"
37 #include "gtk/packet_history.h"
38
39
40 GList *history_current = NULL;
41 GList *history_list = NULL;
42 gboolean ignore_jump = FALSE;
43
44
45 #if 0
46 /* print the complete packet history to console */
47 static void history_print(void) {
48     GList *current = g_list_first(history_list);
49
50     printf(" List:\n");
51
52     while(current) {
53         if(current == history_current) {
54             printf(" Row: %u *\n", GPOINTER_TO_INT(current->data));
55         } else {
56             printf(" Row: %u\n", GPOINTER_TO_INT(current->data));
57         }
58         current = g_list_next(current);
59     }
60 }
61 #endif
62
63
64 /* adjust menu and toolbar sensitivity depending on the history entries */
65 static void adjust_menus(void) {
66
67     if(history_current) {
68         set_menus_for_packet_history(
69             (g_list_previous(history_current) != NULL),
70             (g_list_next(history_current) != NULL));
71     } else {
72         /* we don't have any history */
73         set_menus_for_packet_history(FALSE, FALSE);
74     }
75
76     /* history_print(); */
77 }
78
79
80 /* clear the history list from the given entry to the end of the list */
81 static void clear_list(GList *current) {
82     GList *next_packet;
83
84
85     while(current) {
86         next_packet = g_list_next(current);
87         history_list = g_list_remove(history_list, current->data);
88         current = next_packet;
89     }
90 }
91
92
93 /* add an entry to the history list */
94 void packet_history_add(gint row) {
95
96     if(row < 1) {
97         /* Not a valid row number */
98         return;
99     }
100
101     if(ignore_jump) {
102         /* we jumping back and forward in history, so don't change list */
103         return;
104     }
105
106     if (history_current) {
107         /* clear list behind current position */
108         clear_list(g_list_next(history_current));
109
110         /* ignore duplicates */
111         if(GPOINTER_TO_INT(history_current->data) == row) {
112             adjust_menus();
113             return;
114         }
115     }
116
117     /* add row */
118     history_list = g_list_append(history_list, GINT_TO_POINTER(row));
119     history_current = g_list_last(history_list);
120
121     adjust_menus();
122 }
123
124
125 void packet_history_clear(void) {
126     
127     /* clear "old" list */
128     clear_list(history_list);
129     history_current = NULL;
130
131     /* add the currently selected first row */
132     packet_history_add(0);
133
134     adjust_menus();
135 }
136
137
138 static void packet_history_back(void) {
139     GList *previous;
140
141     if(history_current) {
142         previous = g_list_previous(history_current);
143
144         /* do we have a previous entry */
145         if(previous) {
146             history_current = previous;
147
148             /* goto that packet but don't change history */
149             ignore_jump = TRUE;
150             cf_goto_frame(&cfile, GPOINTER_TO_INT(previous->data));
151             ignore_jump = FALSE;
152         }
153     }
154
155     adjust_menus();
156 }
157
158
159 static void packet_history_forward(void) {
160     GList *next;
161
162     if(history_current) {
163         next = g_list_next(history_current);
164
165         /* do we have a forward entry? */
166         if(next) {
167             history_current = next;
168
169             /* goto that packet but don't change history */
170             ignore_jump = TRUE;
171             cf_goto_frame(&cfile, GPOINTER_TO_INT(next->data));
172             ignore_jump = FALSE;
173         }
174     }
175
176     adjust_menus();
177 }
178
179
180 void history_forward_cb(GtkWidget *widget _U_, gpointer data _U_) {
181     packet_history_forward();
182 }
183
184
185 void history_back_cb(GtkWidget *widget _U_, gpointer data _U_) {
186     packet_history_back();
187 }
188