Change W->E for now removed functions.
[metze/wireshark/wip.git] / tools / checkAPIs.pl
1 #!/usr/bin/env perl
2
3 #
4 # Copyright 2006, Jeff Morriss <jeff.morriss[AT]ulticom.com>
5 #
6 # A simple tool to check source code for function calls that should not
7 # be called by Wireshark code and to perform certain other checks.
8 #
9 # Usage:
10 # checkAPIs.pl [-M] [-g group1] [-g group2] [-s summary-group1] [-s summary-group2] [--nocheck-value-string-array-null-termination] file1 file2 ...
11 #
12 # $Id$
13 #
14 # Wireshark - Network traffic analyzer
15 # By Gerald Combs <gerald@wireshark.org>
16 # Copyright 1998 Gerald Combs
17 #
18 # This program is free software; you can redistribute it and/or
19 # modify it under the terms of the GNU General Public License
20 # as published by the Free Software Foundation; either version 2
21 # of the License, or (at your option) any later version.
22 #
23 # This program is distributed in the hope that it will be useful,
24 # but WITHOUT ANY WARRANTY; without even the implied warranty of
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26 # GNU General Public License for more details.
27 #
28 # You should have received a copy of the GNU General Public License
29 # along with this program; if not, write to the Free Software
30 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #
32
33 use strict;
34 use Getopt::Long;
35
36 my %APIs = (
37         # API groups.
38         # # Group name, e.g. 'prohibited'
39         # '<name>' => {
40         #   'count_errors'    => 1,                     # 1 if these are errors, 0 if warnings
41         #   'functions'       => [ 'f1', 'f2', ...],    # Function array
42         #   'function-counts' => {'f1',0, 'f2',0, ...}, # Function Counts hash (initialized in the code)
43         # }
44         #
45         # APIs that MUST NOT be used in Wireshark
46         'prohibited' => { 'count_errors' => 1, 'functions' => [
47                 # Memory-unsafe APIs
48                 # Use something that won't overwrite the end of your buffer instead
49                 # of these:
50                 'gets',
51                 'sprintf',
52                 'vsprintf',
53                 'strcpy',
54                 'strncpy',
55                 'strcat',
56                 'strncat',
57                 'cftime',
58                 'ascftime',
59                 ### non-portable APIs
60                 # use glib (g_*) versions instead of these:
61                 'ntohl',
62                 'ntohs',
63                 'htonl',
64                 'htons',
65                 'strdup',
66                 'strndup',
67                 ### non-ANSI C
68                 # use memset, memcpy, memcmp instead of these:
69                 'bzero',
70                 'bcopy',
71                 'bcmp',
72                 # use ep_*, se_*, or g_* functions instead of these:
73                 # (One thing to be aware of is that space allocated with malloc()
74                 # may not be freeable--at least on Windows--with g_free() and
75                 # vice-versa.)
76                 'malloc',
77                 'calloc',
78                 'realloc',
79                 'valloc',
80                 'free',
81                 'cfree',
82                 # Locale-unsafe APIs
83                 # These may have unexpected behaviors in some locales (e.g.,
84                 # "I" isn't always the upper-case form of "i", and "i" isn't
85                 # always the lower-case form of "I").  Use the g_ascii_* version
86                 # instead.
87                 'strcasecmp',
88                 'strncasecmp',
89                 'g_strcasecmp',
90                 'g_strncasecmp',
91                 'g_strup',
92                 'g_strdown',
93                 'g_string_up',
94                 'g_string_down',
95                 # Use the ws_* version of these:
96                 # (Necessary because on Windows we use UTF8 for throughout the code
97                 # so we must tweak that to UTF16 before operating on the file.  Code
98                 # using these functions will work unless the file/path name contains
99                 # non-ASCII chars.)
100                 'open',
101                 'rename',
102                 'mkdir',
103                 'stat',
104                 'unlink',
105                 'remove',
106                 'fopen',
107                 'freopen',
108                 # Misc
109                 'tmpnam'            # use mkstemp
110                 ] },
111
112         # APIs that SHOULD NOT be used in Wireshark (any more)
113         'deprecated' => { 'count_errors' => 1, 'functions' => [
114                 'perror',                            # Use strerror() and report messages in whatever
115                                                      #  fashion is appropriate for the code in question.
116                 ### Deprecated glib functions
117                 # (The list is based upon the GLib 2.20.1 documentation; Some of 
118                 #  the entries are are commented out since they are currently 
119                 #  being used in Wireshark and since the replacement functionality
120                 #  is not available in all the GLib versions that Wireshark
121                 #  currently supports (ie: versions starting with GLib 2.4).
122                 'g_async_queue_ref_unlocked',        # g_async_queue_ref()   (OK since 2.8)
123                 'g_async_queue_unref_and_unlock',    # g_async_queue_unref() (OK since 2.8)
124                 'g_string_sprintf',                  # use g_string_printf() instead
125                 'g_string_sprintfa',                 # use g_string_append_printf instead
126                 'g_tree_traverse',
127                 'g_basename',
128                 'g_cache_value_foreach',             # g_cache_key_foreach() 
129                 'g_date_set_time',                   # g_date_set_time_t (avail since 2.10)
130                 'g_dirname',
131                 'g_hash_table_freeze',
132                 'g_hash_table_thaw',
133                 'G_HAVE_GINT64',
134                 'g_io_channel_close',
135                 'g_io_channel_read',
136                 'g_io_channel_seek',
137                 'g_io_channel_write',
138                 'g_main_destroy',
139                 'g_main_is_running',
140                 'g_main_iteration',
141                 'g_main_new',
142                 'g_main_pending',
143                 'g_main_quit',
144                 'g_main_run',
145                 'g_main_set_poll_func',
146                 'g_scanner_add_symbol',
147                 'g_scanner_remove_symbol',
148                 'g_scanner_foreach_symbol',
149                 'g_scanner_freeze_symbol_table',
150                 'g_scanner_thaw_symbol_table',
151                 'G_WIN32_DLLMAIN_FOR_DLL_NAME',
152                 'g_win32_get_package_installation_directory',
153                 'g_win32_get_package_installation_subdirectory',
154 ##
155 ## Deprecated as of GLib 2.10; to be replaced only when Wireshark requires GLib 2.10 or later
156 ## 2.10         'g_allocator_free',                  # "use slice allocator" (avail since 2.10,2.14)
157 ## 2.10         'g_allocator_new',                   # "use slice allocator" (avail since 2.10,2.14)
158 ## 2.10         'g_blow_chunks',                     # "use slice allocator" (avail since 2.10,2.14)
159 ## 2.10         'g_chunk_free',                      # g_slice_free (avail since 2.10)
160 ## 2.10         'g_chunk_new',                       # g_slice_new  (avail since 2.10)
161 ## 2.10         'g_chunk_new0',                      # g_slice_new0 (avail since 2.10)
162 ## 2.10         'g_list_pop_allocator',              # "does nothing since 2.10"
163 ## 2.10         'g_list_push_allocator',             # "does nothing since 2.10"
164 ## 2.10         'g_mem_chunk_alloc',                 # "use slice allocator" (avail since 2.10)
165 ## 2.10         'g_mem_chunk_alloc0',                # "use slice allocator" (avail since 2.10)
166 ## 2.10         'g_mem_chunk_clean',                 # "use slice allocator" (avail since 2.10)
167 ## 2.10         'g_mem_chunk_create',                # "use slice allocator" (avail since 2.10)
168 ## 2.10         'g_mem_chunk_destroy',               # "use slice allocator" (avail since 2.10)
169 ## 2.10         'g_mem_chunk_free',                  # "use slice allocator" (avail since 2.10)
170 ## 2.10         'g_mem_chunk_info',                  # "use slice allocator" (avail since 2.10)
171 ## 2.10         'g_mem_chunk_new',                   # "use slice allocator" (avail since 2.10)
172 ## 2.10         'g_mem_chunk_print',                 # "use slice allocator" (avail since 2.10)
173 ## 2.10         'g_mem_chunk_reset',                 # "use slice allocator" (avail since 2.10)
174 ## 2.10         'g_node_pop_allocator',              # "does nothing since 2.10"
175 ## 2.10         'g_node_push_allocator',             # "does nothing since 2.10"
176 ## 2.10         'g_slist_pop_allocator',             # "does nothing since 2.10"
177 ## 2.10         'g_slist_push_allocator',            # "does nothing since 2.10"
178                 ] },
179
180         # APIs that make the program exit. Dissectors shouldn't call these
181         'abort' => { 'count_errors' => 1, 'functions' => [
182                 'abort',
183                 'exit',
184                 'g_assert',
185                 'g_error',
186                 ] },
187
188         # APIs that print to the terminal. Dissectors shouldn't call these
189         'termoutput' => { 'count_errors' => 0, 'functions' => [
190                 'printf',  
191                 ] },
192
193         # Deprecated GTK APIs
194         #  which SHOULD NOT be used in Wireshark (any more).
195         #  (Filled in from 'E' entries in %deprecatedGtkFunctions below)
196         'deprecated-gtk' => { 'count_errors' => 1, 'functions' => [
197                 ] },
198
199         # Deprecated GTK APIs yet to be replaced
200         #  (Filled in from 'W' entries in %deprecatedGtkFunctions below)
201         'deprecated-gtk-todo' => { 'count_errors' => 0, 'functions' => [
202                 ] },
203
204 );
205
206 # Deprecated GTK functions with (E)rror or (W)arning flag:
207 # (The list is based upon the GTK+ 2.16.0 documentation; Some of 
208 #  the entries are are commented out since they are currently 
209 #  being used in Wireshark and since the replacement functionality
210 #  is not available in all the GTK+ versions that Wireshark
211 #  currently supports (ie: versions starting with GTK+ 2.4).
212 # E: There should be no current Wireshark usage so Error if seen;
213 # W: Not all usages yet fixed so Warn if seen; (Change to E as fixed)
214 my %deprecatedGtkFunctions = (
215                 'gtk_about_dialog_get_name',                   'E',
216                 'gtk_about_dialog_set_name',                   'E',
217                 'gtk_accel_group_ref',                         'E',
218                 'gtk_accel_group_unref',                       'E',
219                 'gtk_action_block_activate_from',              'E',
220                 'gtk_action_unblock_activate_from',            'E',
221                 'gtk_binding_entry_add',                       'E',
222                 'gtk_binding_entry_add_signall',               'E',
223                 'gtk_binding_entry_clear',                     'E',
224                 'gtk_binding_parse_binding',                   'E',
225                 'gtk_box_pack_end_defaults',                   'E',
226                 'gtk_box_pack_start_defaults',                 'E',
227                 'gtk_button_box_get_child_ipadding',           'E',
228                 'gtk_button_box_get_child_size',               'E',
229                 'gtk_button_box_get_spacing',                  'E',
230                 'gtk_button_box_set_child_ipadding',           'E', # style properties child-internal-pad-x/-y
231                 'gtk_button_box_set_child_size',               'E', # style properties child-min-width/-height
232                 'gtk_button_box_set_spacing',                  'E', # gtk_box_set_spacing [==]
233                 'gtk_calendar_display_options',                'E',
234                 'gtk_calendar_freeze',                         'E',
235                 'gtk_calendar_thaw',                           'E',
236                 'GTK_CELL_PIXMAP',                             'E', # GtkTreeView (& related) ...
237                 'GTK_CELL_PIXTEXT',                            'E',
238                 'gtk_cell_renderer_editing_canceled',          'E',
239                 'GTK_CELL_TEXT',                               'W',
240                 'GTK_CELL_WIDGET',                             'E',
241                 'GTK_CHECK_CAST',                              'E', # >>> G_TYPE_CHECK_INSTANCE_CAST [==]
242                 'GTK_CHECK_CLASS_CAST',                        'E', # >>> G_TYPE_CHECK_CLASS_CAST [==]
243                 'GTK_CHECK_CLASS_TYPE',                        'E', # >>> G_TYPE_CHECK_CLASS_TYPE [==]
244                 'GTK_CHECK_GET_CLASS',                         'E', # >>> G_TYPE_INSTANCE_GET_CLASS [==]
245                 'gtk_check_menu_item_set_show_toggle',         'W', # ?? 
246                 'gtk_check_menu_item_set_state',               'E',
247                 'GTK_CHECK_TYPE',                              'E', # >>> G_TYPE_CHECK_INSTANCE_TYPE [==]
248                 'GTK_CLASS_NAME',                              'E',
249                 'GTK_CLASS_TYPE',                              'E',
250                 'GTK_CLIST_ADD_MODE',                          'E', # GtkTreeView (& related) ...
251                 'gtk_clist_append',                            'W',
252                 'GTK_CLIST_AUTO_RESIZE_BLOCKED',               'E',
253                 'GTK_CLIST_AUTO_SORT',                         'E',
254                 'gtk_clist_clear',                             'W',
255                 'gtk_clist_column_title_active',               'E',
256                 'gtk_clist_column_title_passive',              'E',
257                 'gtk_clist_column_titles_active',              'E',
258                 'gtk_clist_column_titles_hide',                'E',
259                 'gtk_clist_column_titles_passive',             'W',
260                 'gtk_clist_column_titles_show',                'W',
261                 'gtk_clist_columns_autosize',                  'W',
262                 'GTK_CLIST_DRAW_DRAG_LINE',                    'E',
263                 'GTK_CLIST_DRAW_DRAG_RECT',                    'E',
264                 'gtk_clist_find_row_from_data',                'W',
265                 'GTK_CLIST_FLAGS',                             'E',
266                 'gtk_clist_freeze',                            'W',
267                 'gtk_clist_get_cell_style',                    'E',
268                 'gtk_clist_get_cell_type',                     'E',
269                 'gtk_clist_get_column_title',                  'E',
270                 'gtk_clist_get_column_widget',                 'E',
271                 'gtk_clist_get_hadjustment',                   'E',
272                 'gtk_clist_get_pixmap',                        'E',
273                 'gtk_clist_get_pixtext',                       'E',
274                 'gtk_clist_get_row_data',                      'W',
275                 'gtk_clist_get_row_style',                     'E',
276                 'gtk_clist_get_selectable',                    'E',
277                 'gtk_clist_get_selection_info',                'W',
278                 'gtk_clist_get_text',                          'W',
279                 'gtk_clist_get_vadjustment',                   'W',
280                 'GTK_CLIST_IN_DRAG',                           'E',
281                 'gtk_clist_insert',                            'W',
282                 'gtk_clist_moveto',                            'W',
283                 'gtk_clist_new',                               'W',
284                 'gtk_clist_new_with_titles',                   'W',
285                 'gtk_clist_optimal_column_width',              'E',
286                 'gtk_clist_prepend',                           'E',
287                 'gtk_clist_remove',                            'W',
288                 'GTK_CLIST_REORDERABLE',                       'E',
289                 'GTK_CLIST_ROW',                               'E',
290                 'GTK_CLIST_ROW_HEIGHT_SET',                    'E',
291                 'gtk_clist_row_is_visible',                    'W',
292                 'gtk_clist_row_move',                          'E',
293                 'gtk_clist_select_all',                        'W',
294                 'gtk_clist_select_row',                        'W',
295                 'gtk_clist_set_auto_sort',                     'E',
296                 'gtk_clist_set_background',                    'W',
297                 'gtk_clist_set_button_actions',                'E',
298                 'gtk_clist_set_cell_style',                    'E',
299                 'gtk_clist_set_column_auto_resize',            'W',
300                 'gtk_clist_set_column_justification',          'W',
301                 'gtk_clist_set_column_max_width',              'E',
302                 'gtk_clist_set_column_min_width',              'E',
303                 'gtk_clist_set_column_resizeable',             'W',
304                 'gtk_clist_set_column_title',                  'W',
305                 'gtk_clist_set_column_visibility',             'W',
306                 'gtk_clist_set_column_widget',                 'W',
307                 'gtk_clist_set_column_width',                  'W',
308                 'gtk_clist_set_compare_func',                  'W',
309                 'GTK_CLIST_SET_FLAG',                          'E',
310                 'gtk_clist_set_foreground',                    'W',
311                 'gtk_clist_set_hadjustment',                   'E',
312                 'gtk_clist_set_pixmap',                        'E',
313                 'gtk_clist_set_pixtext',                       'E',
314                 'gtk_clist_set_reorderable',                   'E',
315                 'gtk_clist_set_row_data',                      'W',
316                 'gtk_clist_set_row_data_full',                 'E',
317                 'gtk_clist_set_row_height',                    'E',
318                 'gtk_clist_set_row_style',                     'E',
319                 'gtk_clist_set_selectable',                    'W',
320                 'gtk_clist_set_selection_mode',                'W',
321                 'gtk_clist_set_shadow_type',                   'W',
322                 'gtk_clist_set_shift',                         'E',
323                 'gtk_clist_set_sort_column',                   'W',
324                 'gtk_clist_set_sort_type',                     'W',
325                 'gtk_clist_set_text',                          'W',
326                 'gtk_clist_set_use_drag_icons',                'E',
327                 'gtk_clist_set_vadjustment',                   'E',
328                 'GTK_CLIST_SHOW_TITLES',                       'E',
329                 'gtk_clist_sort',                              'W',
330                 'gtk_clist_swap_rows',                         'W',
331                 'gtk_clist_thaw',                              'W',
332                 'gtk_clist_undo_selection',                    'E',
333                 'gtk_clist_unselect_all',                      'W',
334                 'gtk_clist_unselect_row',                      'E',
335                 'GTK_CLIST_UNSET_FLAG',                        'E',
336                 'GTK_CLIST_USE_DRAG_ICONS',                    'E',
337                 'gtk_color_selection_get_color',               'E',
338                 'gtk_color_selection_set_change_palette_hook', 'E', 
339                 'gtk_color_selection_set_color',               'E',
340                 'gtk_color_selection_set_update_policy',       'E',
341                 'gtk_combo_disable_activate',                  'W', # GtkComboBox ... (avail since 2.4/2.6/2.10/2.14)
342                 'gtk_combo_new',                               'W',
343                 'gtk_combo_set_case_sensitive',                'W',
344                 'gtk_combo_set_item_string',                   'E',
345                 'gtk_combo_set_popdown_strings',               'W',
346                 'gtk_combo_set_use_arrows',                    'E',
347                 'gtk_combo_set_use_arrows_always',             'E',
348                 'gtk_combo_set_value_in_list',                 'E',
349                 'gtk_container_border_width',                  'E', # gtk_container_set_border_width [==]
350                 'gtk_container_children',                      'E', # gtk_container_get_children [==]
351                 'gtk_container_foreach_full',                  'E',
352                 'gtk_ctree_collapse',                          'E',
353                 'gtk_ctree_collapse_recursive',                'E',
354                 'gtk_ctree_collapse_to_depth',                 'E',
355                 'gtk_ctree_expand',                            'E',
356                 'gtk_ctree_expand_recursive',                  'E',
357                 'gtk_ctree_expand_to_depth',                   'E',
358                 'gtk_ctree_export_to_gnode',                   'E',
359                 'gtk_ctree_find',                              'E',
360                 'gtk_ctree_find_all_by_row_data',              'E',
361                 'gtk_ctree_find_all_by_row_data_custom',       'E',
362                 'gtk_ctree_find_by_row_data',                  'E',
363                 'gtk_ctree_find_by_row_data_custom',           'E',
364                 'gtk_ctree_find_node_ptr',                     'E',
365                 'GTK_CTREE_FUNC',                              'E',
366                 'gtk_ctree_get_node_info',                     'E',
367                 'gtk_ctree_insert_gnode',                      'E',
368                 'gtk_ctree_insert_node',                       'E',
369                 'gtk_ctree_is_ancestor',                       'E',
370                 'gtk_ctree_is_hot_spot',                       'E',
371                 'gtk_ctree_is_viewable',                       'E',
372                 'gtk_ctree_last',                              'E',
373                 'gtk_ctree_move',                              'E',
374                 'gtk_ctree_new',                               'E',
375                 'gtk_ctree_new_with_titles',                   'E',
376                 'GTK_CTREE_NODE',                              'E',
377                 'gtk_ctree_node_get_cell_style',               'E',
378                 'gtk_ctree_node_get_cell_type',                'E',
379                 'gtk_ctree_node_get_pixmap',                   'E',
380                 'gtk_ctree_node_get_pixtext',                  'E',
381                 'gtk_ctree_node_get_row_data',                 'E',
382                 'gtk_ctree_node_get_row_style',                'E',
383                 'gtk_ctree_node_get_selectable',               'E',
384                 'gtk_ctree_node_get_text',                     'E',
385                 'gtk_ctree_node_is_visible',                   'E',
386                 'gtk_ctree_node_moveto',                       'E',
387                 'GTK_CTREE_NODE_NEXT',                         'E',
388                 'gtk_ctree_node_nth',                          'E',
389                 'GTK_CTREE_NODE_PREV',                         'E',
390                 'gtk_ctree_node_set_background',               'E',
391                 'gtk_ctree_node_set_cell_style',               'E',
392                 'gtk_ctree_node_set_foreground',               'E',
393                 'gtk_ctree_node_set_pixmap',                   'E',
394                 'gtk_ctree_node_set_pixtext',                  'E',
395                 'gtk_ctree_node_set_row_data',                 'E',
396                 'gtk_ctree_node_set_row_data_full',            'E',
397                 'gtk_ctree_node_set_row_style',                'E',
398                 'gtk_ctree_node_set_selectable',               'E',
399                 'gtk_ctree_node_set_shift',                    'E',
400                 'gtk_ctree_node_set_text',                     'E',
401                 'gtk_ctree_post_recursive',                    'E',
402                 'gtk_ctree_post_recursive_to_depth',           'E',
403                 'gtk_ctree_pre_recursive',                     'E',
404                 'gtk_ctree_pre_recursive_to_depth',            'E',
405                 'gtk_ctree_real_select_recursive',             'E',
406                 'gtk_ctree_remove_node',                       'E',
407                 'GTK_CTREE_ROW',                               'E',
408                 'gtk_ctree_select',                            'E',
409                 'gtk_ctree_select_recursive',                  'E',
410                 'gtk_ctree_set_drag_compare_func',             'E',
411                 'gtk_ctree_set_expander_style',                'E',
412                 'gtk_ctree_set_indent',                        'E',
413                 'gtk_ctree_set_line_style',                    'E',
414                 'gtk_ctree_set_node_info',                     'E',
415                 'gtk_ctree_set_reorderable',                   'E',
416                 'gtk_ctree_set_show_stub',                     'E',
417                 'gtk_ctree_set_spacing',                       'E',
418                 'gtk_ctree_sort_node',                         'E',
419                 'gtk_ctree_sort_recursive',                    'E',
420                 'gtk_ctree_toggle_expansion',                  'E',
421                 'gtk_ctree_toggle_expansion_recursive',        'E',
422                 'gtk_ctree_unselect',                          'E',
423                 'gtk_ctree_unselect_recursive',                'E',
424                 'gtk_drag_set_default_icon',                   'E',
425                 'gtk_draw_arrow',                              'E',
426                 'gtk_draw_box',                                'E',
427                 'gtk_draw_box_gap',                            'E',
428                 'gtk_draw_check',                              'E',
429                 'gtk_draw_diamond',                            'E',
430                 'gtk_draw_expander',                           'E',
431                 'gtk_draw_extension',                          'E',
432                 'gtk_draw_flat_box',                           'E',
433                 'gtk_draw_focus',                              'E',
434                 'gtk_draw_handle',                             'E',
435                 'gtk_draw_hline',                              'E',
436                 'gtk_draw_layout',                             'E',
437                 'gtk_draw_option',                             'E',
438                 'gtk_draw_polygon',                            'E',
439                 'gtk_draw_resize_grip',                        'E',
440                 'gtk_draw_shadow',                             'E',
441                 'gtk_draw_shadow_gap',                         'E',
442                 'gtk_draw_slider',                             'E',
443                 'gtk_draw_string',                             'E',
444                 'gtk_draw_tab',                                'E',
445                 'gtk_draw_vline',                              'E',
446                 'gtk_drawing_area_size',                       'W', # >> g_object_set() [==] ? 
447                                                                     #    gtk_widget_set_size_request() [==?]
448                 'gtk_entry_append_text',                       'W', # >> gtk_editable_insert_text() [==?]
449                 'gtk_entry_new_with_max_length',               'E', # gtk_entry_new(); gtk_entry_set_max_length()
450                 'gtk_entry_prepend_text',                      'E',
451                 'gtk_entry_select_region',                     'E',
452                 'gtk_entry_set_editable',                      'W', # >> gtk_editable_set_editable() [==?]
453                 'gtk_entry_set_position',                      'E',
454                 'gtk_exit',                                    'W', # exit() [==?]
455                 'gtk_file_chooser_button_new_with_backend',    'E',
456                 'gtk_file_chooser_dialog_new_with_backend',    'E',
457                 'gtk_file_chooser_widget_new_with_backend',    'E',
458                 'gtk_file_selection_complete',                 'E',
459                 'gtk_file_selection_get_filename',             'E', # GtkFileChooser ...
460                 'gtk_file_selection_get_select_multiple',      'E',
461                 'gtk_file_selection_get_selections',           'E',
462                 'gtk_file_selection_hide_fileop_buttons',      'E',
463                 'gtk_file_selection_new',                      'E',
464                 'gtk_file_selection_set_filename',             'E',
465                 'gtk_file_selection_set_select_multiple',      'E',
466                 'gtk_file_selection_show_fileop_buttons',      'E',
467                 'gtk_font_selection_dialog_get_apply_button',  'E',
468                 'gtk_font_selection_dialog_get_font',          'E',
469                 'gtk_font_selection_get_font',                 'E', # gtk_font_selection_get_font_name [!=]
470                 'GTK_FUNDAMENTAL_TYPE',                        'E',
471                 'gtk_hbutton_box_get_layout_default',          'E',
472                 'gtk_hbutton_box_get_spacing_default',         'E',
473                 'gtk_hbutton_box_set_layout_default',          'E',
474                 'gtk_hbutton_box_set_spacing_default',         'E',
475                 'gtk_idle_add',                                'E',
476                 'gtk_idle_add_full',                           'E',
477                 'gtk_idle_add_priority',                       'E',
478                 'gtk_idle_remove',                             'E',
479                 'gtk_idle_remove_by_data',                     'E',
480                 'gtk_image_get',                               'E',
481                 'gtk_image_set',                               'E',
482                 'gtk_input_add_full',                          'W', # >>> g_io_add_watch_full()
483                 'gtk_input_remove',                            'W', # >>> g_source_remove()
484                 'GTK_IS_ROOT_TREE',                            'E',
485                 'gtk_item_factories_path_delete',              'E', # GtkUIManager (avail since 2.4) ...
486                 'gtk_item_factory_add_foreign',                'E',
487                 'gtk_item_factory_construct',                  'E',
488                 'gtk_item_factory_create_item',                'W',
489                 'gtk_item_factory_create_items',               'E',
490                 'gtk_item_factory_create_items_ac',            'W',
491                 'gtk_item_factory_create_menu_entries',        'E',
492                 'gtk_item_factory_delete_entries',             'E',
493                 'gtk_item_factory_delete_entry',               'E',
494                 'gtk_item_factory_delete_item',                'E',
495                 'gtk_item_factory_from_path',                  'E',
496                 'gtk_item_factory_from_widget',                'E',
497                 'gtk_item_factory_get_item',                   'E',
498                 'gtk_item_factory_get_item_by_action',         'E',
499                 'gtk_item_factory_get_widget',                 'W',
500                 'gtk_item_factory_get_widget_by_action',       'E',
501                 'gtk_item_factory_new',                        'W',
502                 'gtk_item_factory_path_from_widget',           'E',
503                 'gtk_item_factory_popup',                      'E',
504                 'gtk_item_factory_popup_data',                 'E',
505                 'gtk_item_factory_popup_data_from_widget',     'E',
506                 'gtk_item_factory_popup_with_data',            'E',
507                 'gtk_item_factory_set_translate_func',         'E',
508                 'gtk_label_get',                               'E', # gtk_label_get_text() [!=]
509                 'gtk_label_parse_uline',                       'E',
510                 'gtk_label_set',                               'E', # gtk_label_set_text() [==]
511                 'gtk_layout_freeze',                           'E',
512                 'gtk_layout_thaw',                             'E',
513                 'gtk_list_append_items',                       'E',
514                 'gtk_list_child_position',                     'E',
515                 'gtk_list_clear_items',                        'E',
516                 'gtk_list_end_drag_selection',                 'E',
517                 'gtk_list_end_selection',                      'E',
518                 'gtk_list_extend_selection',                   'E',
519                 'gtk_list_insert_items',                       'E',
520                 'gtk_list_item_deselect',                      'E',
521                 'gtk_list_item_new',                           'E',
522                 'gtk_list_item_new_with_label',                'E',
523                 'gtk_list_item_select',                        'E',
524                 'gtk_list_new',                                'E',
525                 'gtk_list_prepend_items',                      'E',
526                 'gtk_list_remove_items',                       'E',
527                 'gtk_list_remove_items_no_unref',              'E',
528                 'gtk_list_scroll_horizontal',                  'E',
529                 'gtk_list_scroll_vertical',                    'E',
530                 'gtk_list_select_all',                         'E',
531                 'gtk_list_select_child',                       'E',
532                 'gtk_list_select_item',                        'E',
533                 'gtk_list_set_selection_mode',                 'E',
534                 'gtk_list_start_selection',                    'E',
535                 'gtk_list_toggle_add_mode',                    'E',
536                 'gtk_list_toggle_focus_row',                   'E',
537                 'gtk_list_toggle_row',                         'E',
538                 'gtk_list_undo_selection',                     'E',
539                 'gtk_list_unselect_all',                       'E',
540                 'gtk_list_unselect_child',                     'E',
541                 'gtk_list_unselect_item',                      'E',
542                 'gtk_menu_append',                             'E', # gtk_menu_shell_append() [==?]
543                 'gtk_menu_bar_append',                         'E',
544                 'gtk_menu_bar_insert',                         'E',
545                 'gtk_menu_bar_prepend',                        'E',
546                 'gtk_menu_insert',                             'E',
547                 'gtk_menu_item_remove_submenu',                'E',
548                 'gtk_menu_item_right_justify',                 'E',
549                 'gtk_menu_prepend',                            'E', # gtk_menu_shell_prepend() [==?]
550                 'gtk_menu_tool_button_set_arrow_tooltip',      'E',
551                 'gtk_notebook_current_page',                   'E',
552                 'gtk_notebook_get_group_id',                   'E',
553                 'gtk_notebook_set_group_id',                   'E',
554                 'gtk_notebook_set_homogeneous_tabs',           'E',
555                 'gtk_notebook_set_page',                       'E', # gtk_notebook_set_current_page() [==]
556                 'gtk_notebook_set_tab_border',                 'E',
557                 'gtk_notebook_set_tab_hborder',                'E',
558                 'gtk_notebook_set_tab_vborder',                'E',
559                 'gtk_object_add_arg_type',                     'E',
560                 'gtk_object_data_force_id',                    'E',
561                 'gtk_object_data_try_key',                     'E',
562                 'GTK_OBJECT_FLOATING',                         'E',
563                 'gtk_object_get',                              'E',
564                 'gtk_object_get_data',                         'E',
565                 'gtk_object_get_data_by_id',                   'E',
566                 'gtk_object_get_user_data',                    'E',
567                 'gtk_object_new',                              'E',
568                 'gtk_object_ref',                              'E',
569                 'gtk_object_remove_data',                      'E',
570                 'gtk_object_remove_data_by_id',                'E',
571                 'gtk_object_remove_no_notify',                 'E',
572                 'gtk_object_remove_no_notify_by_id',           'E',
573                 'gtk_object_set',                              'E',
574                 'gtk_object_set_data',                         'E',
575                 'gtk_object_set_data_by_id',                   'E',
576                 'gtk_object_set_data_by_id_full',              'E',
577                 'gtk_object_set_data_full',                    'E',
578                 'gtk_object_set_user_data',                    'E',
579                 'gtk_object_sink',                             'E',
580                 'gtk_object_unref',                            'E',
581                 'gtk_object_weakref',                          'E',
582                 'gtk_object_weakunref',                        'E',
583                 'gtk_old_editable_changed',                    'E',
584                 'gtk_old_editable_claim_selection',            'E',
585                 'gtk_option_menu_get_history',                 'E', # GtkComboBox ... (avail since 2.4/2.6/2.10/2.14)
586                 'gtk_option_menu_get_menu',                    'W',
587                 'gtk_option_menu_new',                         'W',
588                 'gtk_option_menu_remove_menu',                 'W',
589                 'gtk_option_menu_set_history',                 'W',
590                 'gtk_option_menu_set_menu',                    'W',
591                 'gtk_paint_string',                            'E',
592                 'gtk_paned_gutter_size',                       'E', # gtk_paned_set_gutter_size()
593                 'gtk_paned_set_gutter_size',                   'E', # "does nothing"
594                 'gtk_pixmap_get',                              'E', # GtkImage ...
595                 'gtk_pixmap_new',                              'W',
596                 'gtk_pixmap_set',                              'E',
597                 'gtk_pixmap_set_build_insensitive',            'E',
598                 'gtk_preview_draw_row',                        'E',
599                 'gtk_preview_get_cmap',                        'E',
600                 'gtk_preview_get_info',                        'E',
601                 'gtk_preview_get_visual',                      'E',
602                 'gtk_preview_new',                             'E',
603                 'gtk_preview_put',                             'E',
604                 'gtk_preview_reset',                           'E',
605                 'gtk_preview_set_color_cube',                  'E',
606                 'gtk_preview_set_dither',                      'E',
607                 'gtk_preview_set_expand',                      'E',
608                 'gtk_preview_set_gamma',                       'E',
609                 'gtk_preview_set_install_cmap',                'E',
610                 'gtk_preview_set_reserved',                    'E',
611                 'gtk_preview_size',                            'E',
612                 'gtk_preview_uninit',                          'E',
613                 'gtk_progress_bar_new_with_adjustment',        'E',
614                 'gtk_progress_bar_set_activity_blocks',        'E',
615                 'gtk_progress_bar_set_activity_step',          'E',
616                 'gtk_progress_bar_set_bar_style',              'E',
617                 'gtk_progress_bar_set_discrete_blocks',        'E',
618                 'gtk_progress_bar_update',                     'W', # >>> "gtk_progress_set_value() or 
619                                                                     #    gtk_progress_set_percentage()" 
620                                                                     ##  Actually: GtkProgress is deprecated so the 
621                                                                     ##  right answer appears to be to use 
622                                                                     ##  gtk_progress_bar_set_fraction()
623                 'gtk_progress_configure',                      'E',
624                 'gtk_progress_get_current_percentage',         'E',
625                 'gtk_progress_get_current_text',               'E',
626                 'gtk_progress_get_percentage_from_value',      'E',
627                 'gtk_progress_get_text_from_value',            'E',
628                 'gtk_progress_get_value',                      'E',
629                 'gtk_progress_set_activity_mode',              'E',
630                 'gtk_progress_set_adjustment',                 'E',
631                 'gtk_progress_set_format_string',              'E',
632                 'gtk_progress_set_percentage',                 'E',
633                 'gtk_progress_set_show_text',                  'E',
634                 'gtk_progress_set_text_alignment',             'E',
635                 'gtk_progress_set_value',                      'E',
636                 'gtk_radio_button_group',                      'E', # gtk_radio_button_get_group() [==]
637                 'gtk_radio_menu_item_group',                   'E',
638                 'gtk_rc_add_class_style',                      'E',
639                 'gtk_rc_add_widget_class_style',               'E',
640                 'gtk_rc_add_widget_name_style',                'E',
641                 'gtk_rc_style_ref',                            'E',
642                 'gtk_rc_style_unref',                          'E',
643                 'gtk_recent_chooser_get_show_numbers',         'E',
644                 'gtk_recent_chooser_set_show_numbers',         'E',
645                 'gtk_recent_manager_get_for_screen',           'E',
646                 'gtk_recent_manager_set_screen',               'E',
647                 'GTK_RETLOC_BOOL',                             'E',
648                 'GTK_RETLOC_BOXED',                            'E',
649                 'GTK_RETLOC_CHAR',                             'E',
650                 'GTK_RETLOC_DOUBLE',                           'E',
651                 'GTK_RETLOC_ENUM',                             'E',
652                 'GTK_RETLOC_FLAGS',                            'E',
653                 'GTK_RETLOC_FLOAT',                            'E',
654                 'GTK_RETLOC_INT',                              'E',
655                 'GTK_RETLOC_LONG',                             'E',
656                 'GTK_RETLOC_OBJECT',                           'E',
657                 'GTK_RETLOC_POINTER',                          'E',
658                 'GTK_RETLOC_STRING',                           'E',
659                 'GTK_RETLOC_UCHAR',                            'E',
660                 'GTK_RETLOC_UINT',                             'E',
661                 'GTK_RETLOC_ULONG',                            'E',
662                 'gtk_selection_clear',                         'E',
663                 'gtk_signal_connect',                          'E', # GSignal ...
664                 'gtk_signal_connect_after',                    'E',
665                 'gtk_signal_connect_full',                     'E',
666                 'gtk_signal_connect_object',                   'E',
667                 'gtk_signal_connect_object_after',             'E',
668                 'gtk_signal_connect_object_while_alive',       'E',
669                 'gtk_signal_connect_while_alive',              'E',
670                 'gtk_signal_default_marshaller',               'E',
671                 'gtk_signal_disconnect',                       'E',
672                 'gtk_signal_disconnect_by_data',               'E',
673                 'gtk_signal_disconnect_by_func',               'E',
674                 'gtk_signal_emit',                             'E',
675                 'gtk_signal_emit_by_name',                     'E',
676                 'gtk_signal_emit_stop',                        'E',
677                 'gtk_signal_emit_stop_by_name',                'E',
678                 'gtk_signal_emitv',                            'E',
679                 'gtk_signal_emitv_by_name',                    'E',
680                 'GTK_SIGNAL_FUNC',                             'E',
681                 'gtk_signal_handler_block',                    'E',
682                 'gtk_signal_handler_block_by_data',            'E',
683                 'gtk_signal_handler_block_by_func',            'E',
684                 'gtk_signal_handler_pending',                  'E',
685                 'gtk_signal_handler_pending_by_func',          'E',
686                 'gtk_signal_handler_unblock',                  'E',
687                 'gtk_signal_handler_unblock_by_data',          'E',
688                 'gtk_signal_handler_unblock_by_func',          'E',
689                 'gtk_signal_lookup',                           'E',
690                 'gtk_signal_name',                             'E',
691                 'gtk_signal_new',                              'E',
692                 'gtk_signal_newv',                             'E',
693                 'GTK_SIGNAL_OFFSET',                           'E',
694                 'gtk_socket_steal',                            'E',
695                 'gtk_spin_button_get_value_as_float',          'E', # gtk_spin_button_get_value() [==]
696                 'GTK_STRUCT_OFFSET',                           'E',
697                 'gtk_style_apply_default_pixmap',              'E',
698                 'gtk_style_get_font',                          'E',
699                 'gtk_style_ref',                               'E',
700                 'gtk_style_set_font',                          'E',
701                 'gtk_style_unref',                             'E', # g_object_unref() [==?]
702                 'gtk_text_backward_delete',                    'E',
703                 'gtk_text_forward_delete',                     'E',
704                 'gtk_text_freeze',                             'E',
705                 'gtk_text_get_length',                         'E',
706                 'gtk_text_get_point',                          'E',
707                 'GTK_TEXT_INDEX',                              'E',
708                 'gtk_text_insert',                             'W', # GtkTextView (GtkText "known to be buggy" !)
709                 'gtk_text_new',                                'E',
710                 'gtk_text_set_adjustments',                    'E',
711                 'gtk_text_set_editable',                       'E',
712                 'gtk_text_set_line_wrap',                      'E',
713                 'gtk_text_set_point',                          'E',
714                 'gtk_text_set_word_wrap',                      'E',
715                 'gtk_text_thaw',                               'E',
716                 'gtk_timeout_add',                             'E', # g_timeout_add()
717                 'gtk_timeout_add_full',                        'E',
718                 'gtk_timeout_remove',                          'E', # g_source_remove()
719                 'gtk_tips_query_new',                          'E',
720                 'gtk_tips_query_set_caller',                   'E',
721                 'gtk_tips_query_set_labels',                   'E',
722                 'gtk_tips_query_start_query',                  'E',
723                 'gtk_tips_query_stop_query',                   'E',
724                 'gtk_toggle_button_set_state',                 'E', # gtk_toggle_button_set_active [==]
725                 'gtk_toolbar_append_element',                  'E',
726                 'gtk_toolbar_append_item',                     'E',
727                 'gtk_toolbar_append_space',                    'W', # Use gtk_toolbar_insert() instead
728                 'gtk_toolbar_append_widget',                   'W', # ??
729                 'gtk_toolbar_get_tooltips',                    'E',
730                 'gtk_toolbar_insert_element',                  'E',
731                 'gtk_toolbar_insert_item',                     'E',
732                 'gtk_toolbar_insert_space',                    'E',
733                 'gtk_toolbar_insert_stock',                    'E',
734                 'gtk_toolbar_insert_widget',                   'E',
735                 'gtk_toolbar_prepend_element',                 'E',
736                 'gtk_toolbar_prepend_item',                    'E',
737                 'gtk_toolbar_prepend_space',                   'E',
738                 'gtk_toolbar_prepend_widget',                  'E',
739                 'gtk_toolbar_remove_space',                    'E',
740                 'gtk_toolbar_set_tooltips',                    'E',
741                 'gtk_tree_append',                             'E',
742                 'gtk_tree_child_position',                     'E',
743                 'gtk_tree_clear_items',                        'E',
744                 'gtk_tree_insert',                             'E',
745                 'gtk_tree_item_collapse',                      'E',
746                 'gtk_tree_item_deselect',                      'E',
747                 'gtk_tree_item_expand',                        'E',
748                 'gtk_tree_item_new',                           'E',
749                 'gtk_tree_item_new_with_label',                'E',
750                 'gtk_tree_item_remove_subtree',                'E',
751                 'gtk_tree_item_select',                        'E',
752                 'gtk_tree_item_set_subtree',                   'E',
753                 'GTK_TREE_ITEM_SUBTREE',                       'E',
754                 'gtk_tree_model_get_iter_root',                'E',
755                 'gtk_tree_new',                                'E',
756                 'gtk_tree_path_new_root',                      'E',
757                 'gtk_tree_prepend',                            'E',
758                 'gtk_tree_remove_item',                        'E',
759                 'gtk_tree_remove_items',                       'E',
760                 'GTK_TREE_ROOT_TREE',                          'E',
761                 'gtk_tree_select_child',                       'E',
762                 'gtk_tree_select_item',                        'E',
763                 'GTK_TREE_SELECTION_OLD',                      'E',
764                 'gtk_tree_set_selection_mode',                 'E',
765                 'gtk_tree_set_view_lines',                     'E',
766                 'gtk_tree_set_view_mode',                      'E',
767                 'gtk_tree_unselect_child',                     'E',
768                 'gtk_tree_unselect_item',                      'E',
769                 'gtk_tree_view_tree_to_widget_coords',         'E',
770                 'gtk_tree_view_widget_to_tree_coords',         'E',
771                 'gtk_type_class',                              'E', # g_type_class_peek() or g_type_class_ref()
772                 'GTK_TYPE_CTREE_NODE',                         'E',
773                 'gtk_type_enum_find_value',                    'E',
774                 'gtk_type_enum_get_values',                    'E',
775                 'gtk_type_flags_find_value',                   'E',
776                 'gtk_type_flags_get_values',                   'E',
777                 'gtk_type_from_name',                          'E',
778                 'gtk_type_init',                               'E',
779                 'gtk_type_is_a',                               'E',
780                 'GTK_TYPE_IS_OBJECT',                          'E',
781                 'gtk_type_name',                               'E',
782                 'gtk_type_new',                                'E',
783                 'gtk_type_parent',                             'E',
784                 'gtk_type_unique',                             'E',
785                 'GTK_VALUE_BOOL',                              'E',
786                 'GTK_VALUE_BOXED',                             'E',
787                 'GTK_VALUE_CHAR',                              'E',
788                 'GTK_VALUE_DOUBLE',                            'E',
789                 'GTK_VALUE_ENUM',                              'E',
790                 'GTK_VALUE_FLAGS',                             'E',
791                 'GTK_VALUE_FLOAT',                             'E',
792                 'GTK_VALUE_INT',                               'E',
793                 'GTK_VALUE_LONG',                              'E',
794                 'GTK_VALUE_OBJECT',                            'E',
795                 'GTK_VALUE_POINTER',                           'E',
796                 'GTK_VALUE_SIGNAL',                            'E',
797                 'GTK_VALUE_STRING',                            'E',
798                 'GTK_VALUE_UCHAR',                             'E',
799                 'GTK_VALUE_UINT',                              'E',
800                 'GTK_VALUE_ULONG',                             'E',
801                 'gtk_vbutton_box_get_layout_default',          'E',
802                 'gtk_vbutton_box_get_spacing_default',         'E',
803                 'gtk_vbutton_box_set_layout_default',          'E',
804                 'gtk_vbutton_box_set_spacing_default',         'E',
805                 'gtk_widget_draw',                             'W', # gtk_widget_queue_draw_area(): 
806                                                                     #  "in general a better choice if you want
807                                                                     #  to draw a region of a widget."
808                 'gtk_widget_pop_visual',                       'E',
809                 'gtk_widget_push_visual',                      'E',
810                 'gtk_widget_queue_clear',                      'E',
811                 'gtk_widget_queue_clear_area',                 'E',
812                 'gtk_widget_ref',                              'E', # g_object_ref() [==]
813                 'gtk_widget_restore_default_style',            'E',
814                 'gtk_widget_set',                              'E', # g_object_set() [==]
815                 'gtk_widget_set_default_visual',               'E',
816                 'gtk_widget_set_rc_style',                     'E',
817                 'gtk_widget_set_uposition',                    'W', # ?? (see GTK documentation)
818                 'gtk_widget_set_usize',                        'E', # gtk_widget_set_size_request()
819                 'gtk_widget_set_visual',                       'E',
820                 'gtk_widget_unref',                            'E',
821                 'gtk_window_position',                         'E',
822                 'gtk_window_set_policy',                       'W', # >>? gtk_window_set_resizable()
823 ##
824 ## Deprecated as of GTK+ 2.12 but to be replaced only when Wireshark requires GTK+ 2.12 or later
825 ## 2.12         'gtk_tooltips_data_get',                       'E', # new API: GtkToolTip (avail since 2.12) ...
826 ##              'gtk_tooltips_disable',                        'E',
827 ##              'gtk_tooltips_enable',                         'E',
828 ##              'gtk_tooltips_force_window',                   'E',
829 ##              'gtk_tooltips_get_info_from_tip_window',       'E',
830 ##              'gtk_tooltips_new',                            'W',
831 ##              'gtk_tooltips_set_delay',                      'E',
832 ##              'gtk_tooltips_set_tip',                        'W',
833 ## 2.12         'gtk_tool_item_set_tooltip',                   'W', # gtk_tool_item_set_tooltip_text() (avail since 2.12)
834 ##
835 ## Deprecated as of GTK+ 2.16 but to be replaced only when Wireshark requires GTK+ 2.16 or later
836 ##              'gtk_action_connect_proxy',                    'E', # gtk_activatable_set_related_action() (avail since 2.16)
837 ##              'gtk_action_disconnect_proxy',                 'E', # gtk_activatable_set_related_action() (avail since 2.16)
838 ##              'gtk_scale_button_get_orientation',            'E', # gtk_orientable_get_orientation()     (avail since 2.16)
839 ##              'gtk_scale_button_set_orientation',            'E', # gtk_orientable_set_orientation()     (avail since 2.16)
840 ##              'gtk_toolbar_get_orientation',                 'E', # gtk_orientable_get_orientation()     (avail since 2.16)
841 ##              'gtk_toolbar_set_orientation',                 'W', # gtk_orientable_set_orientation()     (avail since 2.16)
842 ##              'gtk_status_icon_set_tooltip',                 'E', # gtk_status_icon_set_tooltip_text()   (avail since 2.16)
843 ##              'gtk_widget_get_action',                       'E', # gtk_activatable_get_related_action() (avail since 2.16)
844 );
845
846 @{$APIs{'deprecated-gtk'}->{'functions'}}      = grep {$deprecatedGtkFunctions{$_} eq 'E'} keys %deprecatedGtkFunctions;
847 @{$APIs{'deprecated-gtk-todo'}->{'functions'}} = grep {$deprecatedGtkFunctions{$_} eq 'W'} keys %deprecatedGtkFunctions;
848
849
850
851 # Given a ref to a hash containing "functions" and "functions_count" entries:
852 # Determine if the any of the list of APIs contained in the array referenced by "functions"
853 # exists in the file.
854 # For each API which appears in the file: 
855 #     Push the API onto the provided list;
856 #     Add the number of times the API appears in the file to the total count
857 #      for the API (stored as the value of the API key in the hash referenced by "function_counts").
858
859 sub findAPIinFile($$$)
860 {
861         my ($groupHashRef, $fileContentsRef, $foundAPIsRef) = @_;
862
863         for my $api ( @{$groupHashRef->{functions}} )
864         {
865                 my $cnt = 0;
866                 while (${$fileContentsRef} =~ m/ \W $api \W* \( /gx)
867                 {
868                         $cnt += 1;
869                 }
870                 if ($cnt > 0) {
871                         push @{$foundAPIsRef}, $api;
872                         $groupHashRef->{function_counts}->{$api} += 1;
873                 }
874         }
875 }
876
877 # The below Regexp are based on those from:
878 # http://aspn.activestate.com/ASPN/Cookbook/Rx/Recipe/59811
879 # They are in the public domain.
880
881 # 1. A complicated regex which matches C-style comments.
882 my $CComment = qr{ / [*] [^*]* [*]+ (?: [^/*] [^*]* [*]+ )* / }x;
883
884 # 1.a A regex that matches C++-style comments.
885 #my $CppComment = qr{ // (.*?) \n }x;
886
887 # 2. A regex which matches double-quoted strings.
888 #    ?s added so that strings containing a 'line continuation' 
889 #    ( \ followed by a new-line) will match.
890 my $DoubleQuotedStr = qr{ (?: ["] (?s: \\. | [^\"\\])* ["]) }x;
891
892 # 3. A regex which matches single-quoted strings.
893 my $SingleQuotedStr = qr{ (?: \' (?: \\. | [^\'\\])* [']) }x;
894
895 # 4. Now combine 1 through 3 to produce a regex which
896 #    matches _either_ double or single quoted strings
897 #    OR comments. We surround the comment-matching
898 #    regex in capturing parenthesis to store the contents
899 #    of the comment in $1.
900 #    my $commentAndStringRegex = qr{(?:$DoubleQuotedStr|$SingleQuotedStr)|($CComment)|($CppComment)};
901
902 # 4. Wireshark is strictly a C program so don't take out C++ style comments
903 #    since they shouldn't be there anyway...
904 #    Also: capturing the comment isn't necessary.
905 my $commentAndStringRegex = qr{ (?: $DoubleQuotedStr | $SingleQuotedStr | $CComment) }x;
906
907 #### Regex for use when searching for value-string definitions
908 my $StaticRegex             = qr/ static \s+                                                       /xs;
909 my $ConstRegex              = qr/ const  \s+                                                       /xs;
910 my $Static_andor_ConstRegex = qr/ (?: $StaticRegex $ConstRegex | $StaticRegex | $ConstRegex)       /xs;
911 my $ValueStringRegex        = qr/ $Static_andor_ConstRegex value_string [^;*]+ = [^;]+ [{] [^;]+ ; /xs;
912
913 #
914 # MAIN
915 #
916 my $errorCount = 0;
917 # The default list, which can be expanded.
918 my @apiGroups = qw(prohibited deprecated);
919 my @apiSummaryGroups = ();
920 my $check_value_string_array_null_termination = 1; # default: enabled
921 my $machine_readable_output = 0;                   # default: disabled
922 my $debug_flag = 0;
923
924 my $result = GetOptions(
925                         'group=s' => \@apiGroups, 
926                         'summary-group=s' => \@apiSummaryGroups, 
927                         'check-value-string-array-null-termination!' => \$check_value_string_array_null_termination,
928                         'Machine-readable' => \$machine_readable_output,
929                         'debug' => \$debug_flag
930                        );
931 if (!$result) {
932         print "Usage: checkAPIs.pl [-M] [-g group1] [-g group2] [-s group1] [-s group2] [--nocheck-value-string-array-null-termination] file1 file2 ..\n";
933
934         print STDERR "   Groups:             ", join (", ", sort keys %APIs), "\n";
935         print STDERR "   Default Groups[-g]: ", join (", ", sort @apiGroups), "\n";
936         exit(1);
937 }
938
939 # Add a 'function_count' anonymous hash to each of the 'apiGroup' entries in the %APIs hash.
940 for my $apiGroup (keys %APIs) {
941         my @functions = @{$APIs{$apiGroup}{functions}};
942
943         $APIs{$apiGroup}->{function_counts}   = {};
944         @{$APIs{$apiGroup}->{function_counts}}{@functions} = ();  # Add fcn names as keys to the anonymous hash
945 }
946
947
948 # Read through the files; do various checks
949 while ($_ = $ARGV[0])
950 {
951         shift;
952         my $filename = $_;
953         my $fileContents = '';
954         my @foundAPIs = ();
955
956         die "No such file: \"$filename\"" if (! -e $filename);
957
958         # delete leading './'
959         $filename =~ s{ ^ \. / } {}xo;
960
961         # Read in the file (ouch, but it's easier that way)
962         open(FC, $filename) || die("Couldn't open $filename");
963         while (<FC>) { $fileContents .= $_; }
964         close(FC);
965
966         if ($fileContents =~ m{ [\x80-\xFF] }xo)
967         {
968                 print STDERR "Warning: Found non-ASCII characters in " .$filename."\n";
969 #               Treat as warning
970 #               $errorCount++;
971         }
972
973         if ($fileContents =~ m{ %ll }xo)
974         {
975                 # use G_GINT64_MODIFIER instead of ll
976                 print STDERR "Error: Found %ll in " .$filename."\n";
977                 $errorCount++;
978         }
979
980         if (! ($fileContents =~ m{ \$Id .* \$ }xo))
981         {
982                 print STDERR "Warning: ".$filename." does not have an SVN Id tag.\n";
983         }
984
985         # Remove all the C-comments and strings
986         $fileContents =~ s {$commentAndStringRegex} []xog;
987
988         if ($fileContents =~ m{ // }xo)
989         {
990                 print STDERR "Error: Found C++ style comments in " .$filename."\n";
991                 $errorCount++;
992         }
993
994         # Brute force check for value_string arrays which are not NULL terminated
995         if ($check_value_string_array_null_termination) {
996                 #  Assumption: definition is of form (pseudo-Regex):
997                 #    " (static const|static|const) value_string .+ = { .+ ;" (possibly over multiple lines) 
998                 while ($fileContents =~ / ( $ValueStringRegex ) /xsog) {
999                         # value_string array definition found; check if NULL terminated
1000                         my $vs = my $vsx = $1;
1001                         if ($debug_flag) {
1002                                 $vsx =~ / ( .+ value_string [^=]+ ) = /xo;
1003                                 printf STDERR "==> %-35.35s: %s\n", $filename, $1;
1004                                 printf STDERR "%s\n", $vs;
1005                         }
1006                         $vs =~ s{ \s } {}xg;
1007                         # README.developer says 
1008                         #  "Don't put a comma after the last tuple of an initializer of an array"
1009                         # However: since this usage is present in some number of cases, we'll allow for now
1010                         if ($vs !~ / , NULL [}] ,? [}] ; $/xo) {
1011                                 $vsx =~ /( value_string [^=]+ ) = /xo;
1012                                 printf STDERR "Error: %-35.35s: Not terminated: %s\n", $filename, $1;
1013                                 $errorCount++;
1014                         }
1015                         if ($vs !~ / (static)? const value_string /xo)  {
1016                                 $vsx =~ /( value_string [^=]+ ) = /xo;
1017                                 printf STDERR "Error: %-35.35s: Missing 'const': %s\n", $filename, $1;
1018                                 $errorCount++;
1019                         }
1020                 }
1021         }
1022
1023         # Check and count APIs
1024         for my $apiGroup (@apiGroups) {
1025                 my $pfx = "Warning";
1026                 @foundAPIs = ();
1027
1028                 findAPIinFile($APIs{$apiGroup}, \$fileContents, \@foundAPIs);
1029
1030                 if ($APIs{$apiGroup}->{count_errors}) {
1031                         # the use of "prohibited" APIs is an error, increment the error count
1032                         $errorCount += @foundAPIs;
1033                         $pfx = "Error";
1034                 }
1035
1036                 if (@foundAPIs && ! $machine_readable_output) {
1037                         print STDERR $pfx . ": Found " . $apiGroup . " APIs in ".$filename.": ".join(',', @foundAPIs)."\n"
1038                 }
1039                 if (@foundAPIs && $machine_readable_output) {
1040                         for my $api (@foundAPIs) {
1041                                 printf STDERR "%-8.8s %-20.20s %-30.30s %-45.45s\n", $pfx, $apiGroup, $filename, $api; 
1042                         }
1043                 }
1044         }
1045 }
1046
1047 # Summary: Print Usage Counts of each API in each requested summary group
1048
1049 for my $apiGroup (@apiSummaryGroups)
1050 {
1051         printf "\n\nUsage Counts\n";
1052         for my $api (sort {"\L$a" cmp "\L$b"} (keys %{$APIs{$apiGroup}->{function_counts}}   )) {
1053                 printf "%-20.20s %5d  %-40.40s\n", $apiGroup . ':', $APIs{$apiGroup}{function_counts}{$api}, $api;
1054         }
1055 }
1056
1057 exit($errorCount);
1058
1059
1060