williamr/sbs_findstr.pl
author Shabe Razvi <shaber@symbian.org>
Wed, 03 Feb 2010 16:24:44 +0000
changeset 146 44e403e0f4cd
parent 15 a5c7bdb47359
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
     1
#! perl
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
     2
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
     3
# Copyright (c) 2009 Symbian Foundation Ltd
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
     4
# This component and the accompanying materials are made available
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
     6
# which accompanies this distribution, and is available
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
     8
#
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
     9
# Initial Contributors:
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    10
# Symbian Foundation Ltd - initial contribution.
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    11
# 
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    12
# Contributors:
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    13
#
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    14
# Description:
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    15
# Filter an SBSv2 log to keep only recipes which match a specified RE
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    16
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    17
use strict;
15
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    18
use Getopt::Long;
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    19
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    20
my $sort_recipes = 0;
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    21
GetOptions(
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    22
  "s|sort" => \$sort_recipes,   # sort output by <recipe> line
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    23
  );
2
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    24
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    25
my $expression = shift @ARGV;
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    26
my $line;
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    27
my $skipping = 1;
7
705136d2022f sbs_findstr.pl inserts the target attribute into the status, for quick grepping. The sbs_quickstatus.pl does this for all <status> elements
William Roberts <williamr@symbian.org>
parents: 3
diff changeset
    28
my $current_target = "";
15
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    29
my @buffer = ();
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    30
my %recipes;
2
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    31
3
8b87ea768cb8 Add a utility to convert raptor timestamps back into localtime.
William Roberts <williamr@symbian.org>
parents: 2
diff changeset
    32
@ARGV = map {glob} @ARGV;
8b87ea768cb8 Add a utility to convert raptor timestamps back into localtime.
William Roberts <williamr@symbian.org>
parents: 2
diff changeset
    33
15
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    34
sub save_buffer
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    35
  {
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    36
  return if (scalar @buffer == 0);
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    37
  if ($sort_recipes)
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    38
    {
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    39
    my $recipe = shift @buffer;
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    40
    $recipes{$recipe} = join("",@buffer);
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    41
    }
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    42
  else
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    43
    {
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    44
    print @buffer;
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    45
    }
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    46
  @buffer = ();
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    47
  }
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    48
  
2
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    49
while ($line =<>)
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    50
  {
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    51
  if (substr($line,0,9) eq "</recipe>")
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    52
    {
15
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    53
    push @buffer, $line if ($skipping == 0);  
2
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    54
    $skipping = 1;    # set this to 0 to get the "between recipes" stuff
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    55
    next;
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    56
    }
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    57
  if (substr($line,0,8) eq "<recipe ")
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    58
    {
15
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    59
    save_buffer();
2
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    60
    if ($line =~ /$expression/io)
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    61
      {
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    62
      $skipping = 0;
7
705136d2022f sbs_findstr.pl inserts the target attribute into the status, for quick grepping. The sbs_quickstatus.pl does this for all <status> elements
William Roberts <williamr@symbian.org>
parents: 3
diff changeset
    63
      $current_target = "";
705136d2022f sbs_findstr.pl inserts the target attribute into the status, for quick grepping. The sbs_quickstatus.pl does this for all <status> elements
William Roberts <williamr@symbian.org>
parents: 3
diff changeset
    64
      if ($line =~ /(target='[^']+') /)
705136d2022f sbs_findstr.pl inserts the target attribute into the status, for quick grepping. The sbs_quickstatus.pl does this for all <status> elements
William Roberts <williamr@symbian.org>
parents: 3
diff changeset
    65
        {
705136d2022f sbs_findstr.pl inserts the target attribute into the status, for quick grepping. The sbs_quickstatus.pl does this for all <status> elements
William Roberts <williamr@symbian.org>
parents: 3
diff changeset
    66
        $current_target = $1;
705136d2022f sbs_findstr.pl inserts the target attribute into the status, for quick grepping. The sbs_quickstatus.pl does this for all <status> elements
William Roberts <williamr@symbian.org>
parents: 3
diff changeset
    67
        }
2
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    68
      }
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    69
    else
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    70
      {
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    71
      $skipping = 1;
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    72
      }
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    73
    }
7
705136d2022f sbs_findstr.pl inserts the target attribute into the status, for quick grepping. The sbs_quickstatus.pl does this for all <status> elements
William Roberts <williamr@symbian.org>
parents: 3
diff changeset
    74
  next if ($skipping == 1);  
705136d2022f sbs_findstr.pl inserts the target attribute into the status, for quick grepping. The sbs_quickstatus.pl does this for all <status> elements
William Roberts <williamr@symbian.org>
parents: 3
diff changeset
    75
  if (substr($line,0,8) eq "<status ")
705136d2022f sbs_findstr.pl inserts the target attribute into the status, for quick grepping. The sbs_quickstatus.pl does this for all <status> elements
William Roberts <williamr@symbian.org>
parents: 3
diff changeset
    76
    {
705136d2022f sbs_findstr.pl inserts the target attribute into the status, for quick grepping. The sbs_quickstatus.pl does this for all <status> elements
William Roberts <williamr@symbian.org>
parents: 3
diff changeset
    77
    substr($line,-3) = "$current_target />\n";
705136d2022f sbs_findstr.pl inserts the target attribute into the status, for quick grepping. The sbs_quickstatus.pl does this for all <status> elements
William Roberts <williamr@symbian.org>
parents: 3
diff changeset
    78
    }
15
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    79
  push @buffer, $line;
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    80
  }
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    81
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    82
save_buffer();
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    83
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    84
if ($sort_recipes)
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    85
  {
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    86
  foreach my $recipe (sort keys %recipes)
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    87
    {
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    88
    print $recipe, $recipes{$recipe};
a5c7bdb47359 Add "-sort" option to sort the recipes before printing, for comparing two logs
William Roberts <williamr@symbian.org>
parents: 7
diff changeset
    89
    }
2
a600c1a596f7 Create "williamr" directory in utilities, and add an assortment of Perl scripts
William Roberts <williamr@symbian.org>
parents:
diff changeset
    90
  }