As suggested by Michael in https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=4605 :
[metze/wireshark/wip.git] / ui / packet_list_utils.c
1 /* packet_list_utils.c
2  * Packet list display utilities
3  * Copied from gtk/packet_list.c
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
24  * USA.
25  */
26
27 #include "config.h"
28
29 #include <glib.h>
30
31 #include "packet_list_utils.h"
32
33 #include <epan/column.h>
34 #include <epan/proto.h>
35
36 gboolean
37 right_justify_column (gint col, capture_file *cf)
38 {
39     header_field_info *hfi;
40     gboolean right_justify = FALSE;
41
42     if (!cf) return FALSE;
43
44     switch (cf->cinfo.col_fmt[col]) {
45
46         case COL_NUMBER:
47         case COL_PACKET_LENGTH:
48         case COL_CUMULATIVE_BYTES:
49         case COL_DCE_CALL:
50         case COL_DSCP_VALUE:
51         case COL_UNRES_DST_PORT:
52         case COL_UNRES_SRC_PORT:
53         case COL_DEF_DST_PORT:
54         case COL_DEF_SRC_PORT:
55         case COL_DELTA_TIME:
56         case COL_DELTA_TIME_DIS:
57             right_justify = TRUE;
58             break;
59
60         case COL_CUSTOM:
61             hfi = proto_registrar_get_byname(cf->cinfo.col_custom_field[col]);
62             /* Check if this is a valid field and we have no strings lookup table */
63             if ((hfi != NULL) && ((hfi->strings == NULL) || !get_column_resolved(col))) {
64                 /* Check for bool, framenum and decimal/octal integer types */
65                 if ((hfi->type == FT_BOOLEAN) || (hfi->type == FT_FRAMENUM) ||
66                         (((hfi->display == BASE_DEC) || (hfi->display == BASE_OCT)) &&
67                          (IS_FT_INT(hfi->type) || IS_FT_UINT(hfi->type)))) {
68                     right_justify = TRUE;
69                 }
70             }
71             break;
72
73         default:
74             break;
75     }
76
77     return right_justify;
78 }
79
80 gboolean
81 resolve_column (gint col, capture_file *cf)
82 {
83     header_field_info *hfi;
84     gboolean resolve = FALSE;
85
86     if (!cf) return FALSE;
87
88     switch (cf->cinfo.col_fmt[col]) {
89
90         case COL_CUSTOM:
91             hfi = proto_registrar_get_byname(cf->cinfo.col_custom_field[col]);
92             /* Check if this is a valid field */
93             if (hfi != NULL) {
94                 /* Check if we have an OID or a strings table with integer values */
95                 if ((hfi->type == FT_OID) || (hfi->type == FT_REL_OID) ||
96                         ((hfi->strings != NULL) &&
97                          ((hfi->type == FT_BOOLEAN) || (hfi->type == FT_FRAMENUM) ||
98                           IS_FT_INT(hfi->type) || IS_FT_UINT(hfi->type)))) {
99                     resolve = TRUE;
100                 }
101             }
102             break;
103
104         default:
105             break;
106     }
107
108     return resolve;
109 }
110
111 /*
112  * Editor modelines
113  *
114  * Local Variables:
115  * c-basic-offset: 4
116  * tab-width: 8
117  * indent-tabs-mode: nil
118  * End:
119  *
120  * ex: set shiftwidth=4 tabstop=8 expandtab:
121  * :indentSize=4:tabSize=8:noTabs=true:
122  */