Make TcGenDeriv warning-free
[ghc-hetmet.git] / utils / parallel / sn_filter.pl
1 #!/usr/local/bin/perl
2 # ############################################################################
3 # Time-stamp: <Wed Jun 19 1996 12:26:21 Stardate: [-31]7682.38 hwloidl>
4 #
5 # Usage: sn_filter [options] <gr-file> <sn>
6 #
7 # Extract all events out of <gr-file> that are related to threads whose 
8 # spark name component is <sn>.
9
10 # Options:
11 #  -H       ... Print header of the <gr-file>, too
12 #  -h       ... print help message (this text)
13 #  -v       ... be talkative
14 #
15 # ############################################################################
16
17 $gran_dir = $ENV{'GRANDIR'};
18 if ( $gran_dir eq "" ) {
19     print STDERR "Warning: Env variable GRANDIR is undefined\n";
20 }
21
22 push(@INC, $gran_dir, $gran_dir . "/bin");
23 # print STDERR "INC: " . join(':',@INC) . "\n";
24
25 require "get_SN";
26 require "getopts.pl";
27
28 &Getopts('hvH');  
29
30 do process_options();
31 if ( $opt_v ) { do print_verbose_message(); }
32
33 # ----------------------------------------------------------------------------
34
35 do get_SN($input);
36
37 open (FILE,$input) || die "Can't open $file\n";
38
39 $in_header = 1;
40 while (<FILE>) {
41     print  if $in_header && $opt_H;
42     $in_header = 0 if /^\++$/;
43     next if $in_header;
44     next unless /^PE\s*\d+\s*\[\d+\]:\s*\w*\s*([0-9a-fx]+)/;
45     $id = $1;
46     # print STDERR "$id --> " . $id2sn{hex($id)} . " sn: $sn  ==> " . ($sn eq $id2sn{hex($id)}) . "\n";
47     print if $sn == $id2sn{hex($id)};
48 }
49         
50 close (FILE);
51
52 exit 0;
53
54 # ----------------------------------------------------------------------------
55
56 sub process_options { 
57
58     if ( $#ARGV != 1 ) {
59         die "Usage: sn_filter <gr-file> <sn>\n";
60     }
61         
62     $input = $ARGV[0];
63     $sn = $ARGV[1];
64
65     print STDERR "File: |$file|; sn: |$sn|\n"  if $opt_v;
66
67  if ( $opt_h ) {
68      open (ME,$0) || die "!$: $0";
69      while (<ME>) {
70          last if /^$/;
71          print;
72      }
73      close (ME);
74      exit 1;
75  }
76 }
77
78 # ----------------------------------------------------------------------------
79
80 sub print_verbose_message { 
81
82     print "Input: $input\tOutput: stdout\tSN: $sn\n";
83     if ( $opt_H ) {
84         print "Prepending .gr header to the output.\n";
85     }
86
87 }
88
89 # ----------------------------------------------------------------------------
90
91
92