#!/usr/bin/perl -w\n# checksigs.pl\n# 1.0.0.0 pw 18-03-05\n# Check PCO signals data has been correctly merged into RCC\n# Usage: checksig <pco_tree_path> <rcc_data_dir>\nuse strict;\nuse File::Find;\nuse Data::Dumper;\n\n# Check for incorrect invokation and populate parameters\nmy $argc = scalar @ARGV;\ndie "Usage: checksig <pco_tree_path> <rcc_data_dir>\\n" unless $argc == 2;\nmy $pco_dir = $ARGV[0];\nmy $rcc_dir = $ARGV[1];\nmy @pco_sigs; # array to contain PCO signals data\nmy @rcc_sigs; # array to contain PCO signals data\nmy $sig_array; # Reference to point to required destination array\nmy $debug = 1; # debug flag: set to 1 to enable debug output\nmy $sig_count; # count of processed signals. Info only.\n\nsub debug\n{\n\tif ($debug)\n\t{\n\t\tmy $msg = shift;\n\t\tprint "DEBUG: $msg\\n";\n\t}\n}\n\n# utility functions\nsub is_lit_device \n{\n\n\t# this function will determine if a device is one of those\n\t# transferred to the LIT\n\treturn 1;\n}\n\nsub process_file\n{\n\tmy $file = $_;\n\tmy $dir = $File::Find::dir;\n\tif ( $file =~ /^DEVICE.SIG/i )\n\t{\n\t\topen DEVICE, $file || die "Cannot open $file: $!\\n";\n\n\t\t# read the signals into the pco_sig hash\n\t\tdebug("processing $file in $dir");\n\t\twhile (<DEVICE>)\n\t\t{\n\t\t\tnext if (/^!/); # skip comments\n\t\t\tmy @line = split(/,/); # split line at commas\n\n\t\t\t#\t\t\tmy $geo_addr = $line[0]; # get the geog addr\n\t\t\t#\t\t\tmy @ele_addr =\n\t\t\t#\t\t\t split( ///, $line[1] ); # split elec addr at /\n\t\t\t#\t\t\tmy $tpr = $ele_addr[2]; # get the TPR\n\t\t\t#\t\t\tmy $lnk = $ele_addr[3]; # get the elec addr on the link\n\t\t\t# add device to hash, omitting LIT devices\n\t\t\tpush @$sig_array, \\@line;\n\t\t\t$sig_count++;\n\t\t}\n\t\tclose DEVICE;\n\t}\n}\n\nsub compare_lists\n{\n\tmy ( $list_ref_a, $list_ref_b ) = @_;\n\tmy @fields = qw/geog elec params/;\n\tmy (%h1);\n\tforeach my $ref ( @{$list_ref_a} )\n\t{\n\t\tmy %rec;\n\t\t@rec{@fields} = @{$ref};\n\t\t( $rec{tail} ) =\n\t\t $rec{elec} =~ m{([^/]+/[^/]+)$}; # match the last 2 pieces\n\t\t$h1{ $rec{geog} } = \\%rec;\n\t}\n\n\t#\tprint Dumper (\\%h1);\n\tforeach my $ref ( @{$list_ref_b} )\n\t{\n\t\tmy %rec;\n\t\t@rec{@fields} = @{$ref};\n\t\t( $rec{tail} ) =\n\t\t $rec{elec} =~ m{([^/]+/[^/]+)$}; # match the last 2 pieces\n\t\tif ( defined( $h1{ $rec{geog} } ) )\n\t\t{\n\t\t\tif ( $h1{ $rec{geog} }->{tail} ne $rec{tail} )\n\t\t\t{\n\t\t\t\tprint\n" Different: $rec{geog} : $h1{$rec{geog}}->{tail} ne $rec{tail}\\n";\n\t\t\t}\n\t\t}\n\t}\n}\n\n# Traverse the $pco_dir tree, process entries with the process_file sub\n$sig_array = \\@pco_sigs;\nfind( &process_file, $pco_dir );\ndebug "added $sig_count signals to PCO list";\n$sig_count = 0;\n$sig_array = \\@rcc_sigs;\nfind( &process_file, $rcc_dir );\ndebug "added $sig_count signals to RCC list";\nmy $pco_ref = \\@pco_sigs;\nmy $rcc_ref = \\@rcc_sigs;\ncompare_lists( $pco_ref, $rcc_ref );\n