tools/filter_obyfile.pl
changeset 100 6dfa3bdbdfba
parent 99 e23a8d7ea8bb
child 135 b9832c8d3f36
equal deleted inserted replaced
99:e23a8d7ea8bb 100:6dfa3bdbdfba
    16 use strict;
    16 use strict;
    17 use Getopt::Long;
    17 use Getopt::Long;
    18 
    18 
    19 my $deleted_lines_oby = "filtered.oby";
    19 my $deleted_lines_oby = "filtered.oby";
    20 my $deletion_details_file = "filter.log";
    20 my $deletion_details_file = "filter.log";
       
    21 my @option_prefixes;
    21 GetOptions(
    22 GetOptions(
    22   "d|deleted=s" => \$deleted_lines_oby,   # file to hold the deleted lines
    23   "d|deleted=s" => \$deleted_lines_oby,   # file to hold the deleted lines
    23   "l|log=s" => \$deletion_details_file,   # log of whats deleted and why
    24   "l|log=s" => \$deletion_details_file,   # log of whats deleted and why
       
    25   "options=s" => \@option_prefixes,       # prefixes for provisional What commands
    24   );
    26   );
    25 
    27 
    26 if (scalar @ARGV < 2)
    28 if (scalar @ARGV < 2)
    27 	{
    29 	{
    28 	die ("Must specify at least two arguments: rom_content.csv and static_dependencies.txt");
    30 	die ("Must specify at least two arguments: rom_content.csv and static_dependencies.txt");
    37 
    39 
    38 my $rom_content_header = shift @rom_content;
    40 my $rom_content_header = shift @rom_content;
    39 die("Not a valid rom_content.csv file") if ($rom_content_header !~ /^ROM file,/);
    41 die("Not a valid rom_content.csv file") if ($rom_content_header !~ /^ROM file,/);
    40 
    42 
    41 # read through the rom_content_csv looking for direct instructions
    43 # read through the rom_content_csv looking for direct instructions
       
    44 my %prefixes;
       
    45 foreach my $prefix (split /,/, join(",", @option_prefixes))   # handle comma-separated lists
       
    46 	{
       
    47 	$prefixes{lc "$prefix"} = 1;
       
    48 	}
    42 my %stem_substitutions;
    49 my %stem_substitutions;
    43 my %rom_origins;
    50 my %rom_origins;
    44 my %deletions;
    51 my %deletions;
    45 my %must_have;
    52 my %must_have;
    46 my %check_import_details;
    53 my %check_import_details;
       
    54 my $optional_commands_ignored = 0;
    47 foreach my $line (@rom_content)
    55 foreach my $line (@rom_content)
    48 	{
    56 	{
    49 	my ($romfile,$hostfile,$ibyfile,$package,$cmd,@rest) = split /,/, $line;
    57 	my ($romfile,$hostfile,$ibyfile,$package,$cmd,@rest) = split /,/, $line;
    50 	
    58 	
    51 	$rom_origins{$romfile} = "$ibyfile,$package";
    59 	$rom_origins{$romfile} = "$ibyfile,$package";
    52 	next if ($cmd eq "");
    60 	next if ($cmd eq "");
    53 
    61 
    54 	$cmd = lc $cmd;
    62 	$cmd = lc $cmd;
       
    63 	if ($cmd =~ /^(\S+)_([^_]+)$/)
       
    64 		{
       
    65 		my $prefix = $1;
       
    66 		$cmd = $2;    # without the prefix
       
    67 		if (!defined $prefixes{$prefix})
       
    68 			{
       
    69 			$optional_commands_ignored++;
       
    70 			next;
       
    71 			}
       
    72 		# otherwise fall through and process the selected cmd
       
    73 		print STDERR "Option $prefix matched to give $cmd for >$romfile<\n";
       
    74 		}
    55 	if ($cmd eq "slim")
    75 	if ($cmd eq "slim")
    56 		{
    76 		{
    57 		$check_import_details{$romfile} = "";
    77 		$check_import_details{$romfile} = "";
    58 		$stem_substitutions{$romfile} = $hostfile;
    78 		$stem_substitutions{$romfile} = $hostfile;
    59 		$must_have{$romfile} = 1;
    79 		$must_have{$romfile} = 1;
    79 		$must_have{$romfile} = 1;
    99 		$must_have{$romfile} = 1;
    80 		next;
   100 		next;
    81 		}
   101 		}
    82 	}
   102 	}
    83 
   103 
    84 printf STDERR "%d in (including %d slim and %d stem), %d out\n", 
   104 printf STDERR "%d in (including %d slim and %d stem), %d out, (%d not selected)\n", 
    85 	scalar keys %must_have,
   105 	scalar keys %must_have,
    86 	scalar keys %check_import_details,
   106 	scalar keys %check_import_details,
    87 	(scalar keys %stem_substitutions) - (scalar keys %check_import_details), 
   107 	(scalar keys %stem_substitutions) - (scalar keys %check_import_details), 
    88 	scalar keys %deletions; 
   108 	scalar keys %deletions,
       
   109 	$optional_commands_ignored; 
    89 
   110 
    90 # read static dependencies file
   111 # read static dependencies file
    91 my %exe_to_romfile;     # exe -> original romfile
   112 my %exe_to_romfile;     # exe -> original romfile
    92 my %exe_dependencies;   # exe -> list of romfile
   113 my %exe_dependencies;   # exe -> list of romfile
    93 my %exe_prerequisites;  # exe -> list of exe
   114 my %exe_prerequisites;  # exe -> list of exe