1#!/usr/bin/env perl
2
3# Copyright 2010, Jeff Morriss <jeff.morriss.ws[AT]gmail.com>
4#
5# A simple tool to remove bogus blurbs from hf entries.
6# This has already been run so it may not be necessary any more, but
7# may as well check it in in case it can serve as a base for other, future,
8# global hf changes.
9#
10# Usage:
11# fixhf.pl file1 [file2 file3 ...]
12#
13# Wireshark - Network traffic analyzer
14# By Gerald Combs <gerald@wireshark.org>
15# Copyright 1998 Gerald Combs
16#
17# SPDX-License-Identifier: GPL-2.0-or-later
18#
19
20use strict;
21
22# Read through the files
23while ($_ = $ARGV[0])
24{
25        shift;
26        my $filename = $_;
27        my $fileContents = '';
28        my @foundAPIs = ();
29
30        die "No such file: \"$filename\"" if (! -e $filename);
31
32        # delete leading './'
33        $filename =~ s{ ^ \. / } {}xo;
34
35        # Read in the file (ouch, but it's easier that way)
36        open(FC, $filename) || die("Couldn't open $filename");
37        while (<FC>) { $fileContents .= $_; }
38        close(FC);
39
40	if ($fileContents =~ s{
41				  (\{
42				  \s*
43				  &\s*[A-Z0-9_\[\]-]+		# &hf
44				  \s*,\s*
45				  \{\s*
46				  ("[A-Z0-9 '\./\(\)_:-]+")	# name
47				  \s*,\s*
48				  "[A-Z0-9_\.-]+"		# abbrev
49				  \s*,\s*
50				  FT_[A-Z0-9_]+			# field type
51				  \s*,\s*
52				  [A-Z0-9x|_]+			# display
53				  \s*,\s*
54				  [A-Z0-9&_\(\)' -]+		# convert
55				  \s*,\s*
56				  [A-Z0-9x_]+			# bitmask
57				  \s*,\s*)
58				  \2				# blurb
59				} [$1NULL]xgios)
60				 # \s*HFILL)
61	{
62		print STDERR "Warning: field with name==blurb found in " .$filename. " FIXING IT!\n";
63
64		# Trim trailing white space while we're here
65		$fileContents =~ s{[ \t]+$} []gom;
66
67		open(FC, ">".$filename) || die("Couldn't open $filename");
68		print FC $fileContents;
69		close(FC);
70	}
71
72}
73