File: tools-toggle.pl

package info (click to toggle)
gasnet 2025.8.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,424 kB
  • sloc: ansic: 114,758; cpp: 5,158; sh: 4,847; makefile: 2,715; perl: 1,774
file content (44 lines) | stat: -rw-r--r-- 1,058 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env perl

require 5.005;
use strict;

my $toolsonly;

if ($ARGV[0] eq "-y") { $toolsonly = 1; }
elsif ($ARGV[0] eq "-n") { $toolsonly = 0; }
else {
  die "Usage: $0 [-y|-n] files...\n";
}
shift;

my $insec=0;
my $show=0;
my $cc;
while (@ARGV) {
  my $filename = $ARGV[0];
  print " + Processing $filename...\n";     

  open(FIN, "<$filename");                                              
  open(FOUT, ">$filename.tmp");                                                                 
  while (defined(my $line = <FIN>)) {
    if ($line =~ m/^(.+)GASNET_TOOLSONLY_(TRUE|FALSE)_BEGIN/) { 
      $cc = $1;
      $show = ($2 eq ($toolsonly?"TRUE":"FALSE"));
      $insec = 1; 
    } elsif ($line =~ m/GASNET_TOOLSONLY_(TRUE|FALSE)_END/) { 
      $insec = 0; 
    } elsif ($insec) { 
      if ($show) {
        $line =~ s/^(?:$cc)*(.*)$/$1/;
      } else {
        $line =~ s/^(?:$cc)*(.*)$/$cc$1/;
      } 
    }
    print FOUT $line;
  }
  close(FIN);
  close(FOUT);
  rename("$filename.tmp", $filename);                              
  shift;
}