File: test2.pl

package info (click to toggle)
source-highlight 3.1.7-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 10,332 kB
  • ctags: 5,233
  • sloc: sh: 11,270; cpp: 10,206; ansic: 9,515; makefile: 1,865; lex: 1,200; yacc: 1,021; php: 213; perl: 211; awk: 98; erlang: 94; lisp: 90; java: 75; ruby: 69; python: 61; asm: 43; ml: 38; ada: 36; haskell: 27; xml: 23; cs: 11; sql: 8; tcl: 6; sed: 4
file content (86 lines) | stat: -rw-r--r-- 3,122 bytes parent folder | download | duplicates (8)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#! /usr/bin/env perl

use strict;
use warnings;

"I'm happy because of $x!"
qq~I'm happy because of $x!~
qq{I'm happy because of $x!}
qq|I'm happy because of $x!|
qq#I'm happy because of $x!#
qq!I'm happy because of $x\!!

'The variable is called $var.'
q~The variable is called $var.~
q|The variable is called $var.|
q{The variable is called $var.}
q[The variable is called $var.]
q#The variable is called $var.#
q!The variable is called $var.! 

my $port = $ARGV[0];

# prepare freqently used regexes
my $trailing_comment      = qr#;\s*\#.*#;
my $leading_comment       = qr|(?:^\|\n)\s*#.*|;
my $leading_comment       = qr<(?:^\|\n)\s*#.*>;
my $leading_comment       = qr[(?:^\|\n)\]\s*#.*];
my $connecting_backslash  = qr@\s*\\\n\s*@;

my $quick_check = qr{:$port}i;

my $dependency  = qr{depends_(?=[brl])(?:build|run|lib)(?:-(?:append|delete))?
                  .*
                  (?=[plb])(?:port|(?:path|lib|bin):[^:]+):(?i:${port}|$port)(\{\})(?:\s|$)}x;

my $dependency  = qr{
                      (?=[plb])(?:port|(?:path|lib|bin):[^:]+)  # kind
                      :                                         # separator
                      (?i:${port})(?:\s|$)                      # name
                    }x; 

$/ = ".\n";

while (defined(my $portfile = <*/*/Portfile>)) { 
  @ARGV = $portfile;

  while (<>) {
    # make a quick and dirty check if the port has a remote chance of
    # depending on $port
    if ($_ =~ m\$quick_check|foo(.*)\i) {

      s#$connecting_backslash|a\#b#\# #g;      # merge backslash-connected lines
      s#$connecting_backslash|a\#b#\# #;      # merge backslash-connected lines
      s#$connecting_backslash|a\###;      # merge backslash-connected lines
      s/$leading_comment|a\/b/a\/b/g;            # remove leading comments
      s{$trailing_comment|\}}{\}}g;          # remove trailing comments
      s($trailing_comment|\))(\))g;          # remove trailing comments
      s<$trailing_comment|\>><\>>g;          # remove trailing comments
      s[$trailing_comment|\]][a\]b]g;          # remove trailing comments
      s|$trailing_comment\||a\|b|g;          # remove trailing comments
      s@$trailing_comment|(a\@b)@(bar\@)@g;          # just for test
      s_$connectingbackslash|a\_b_\_ _g;      # merge backslash-connected lines
      s\$trailing_comment|(a\\b)\(bar\\)\g;          # just for test

    s-[a\-z]{3}-fu- ;   # just for test
    s^\^foo^fu^ ;   # just for test
    s$foo(\w{3})\$$fu\$1$ ;   # just for test
    s!foo(\w{3})\!!fu\$1! ;   # just for test
    s?foo(\w{3})\??fu\$1? ;   # just for test
    s*foo(\w{3})\**fu\$1* ;   # just for test

    # let's some more exotic syntaxes ;-)
    s?foo(\w{3})\?\$?!fu\!1! ;   # just for test
    s$foo(\w{3})\$$^fu\^\$1^ ;   # just for test
    s$foo(\w{3})\$$ ^fu\^\$1^ ;   # just for test
    s$foo(\w{3})\$$ ^fu\^\$1^g ;   # just for test
    s#foo(\w{3})\## ^fu\^\$1^g ;   # just for test
    s$foo(\w{3})\$$ #fu\#\$1#g ;   # just for test

      if ($_ =~ m{$dependency}) {
        $portfile =~ s{/Portfile$}{};   # remove trailing '/Portfile'
        print "$portfile\n";
      }
    }
  }
}