~ubuntu-branches/ubuntu/edgy/rpm/edgy

« back to all changes in this revision

Viewing changes to scripts/magic.req

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2002-01-22 20:56:57 UTC
  • Revision ID: james.westby@ubuntu.com-20020122205657-l74j50mr9z8ofcl5
Tags: upstream-4.0.3
ImportĀ upstreamĀ versionĀ 4.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
# Given a list of filenames on the command line or on stdin this
 
4
# script returns the interpreter that is required to run the
 
5
# filenames.  Usually this is extracted from the #! line of the file
 
6
# but we also handle the various 'exec' tricks that people use to
 
7
# start the interpreter via an intermediate shell.  
 
8
 
 
9
# Also we want to convert:
 
10
#       /usr/local/bin/perl5.00404 
 
11
#       /usr/local/bin/tclsh8.0 
 
12
# into dependencies with RPM version numbers.
 
13
 
 
14
 
 
15
 
 
16
 
 
17
 
 
18
# These have all been seen on our system or are "recommended" in
 
19
# various man pages.
 
20
 
 
21
# Examples:
 
22
 
 
23
#   #!/bin/sh
 
24
#   # the next line restarts using wish \
 
25
#   exec wish "$0" "$@"
 
26
 
 
27
 
 
28
#   #!/bin/sh -- # -*- perl -*- -p
 
29
#     eval 'exec /usr/bin/perl -wS $0 ${1+"$@"}'
 
30
#       if $running_under_some_shell;
 
31
 
 
32
 
 
33
#   #!/bin/sh -- # -*- perl -*- -p
 
34
#   eval '(exit $?0)' && eval 'exec /usr/bin/perl -wS $0 ${1+"$@"}'
 
35
 
 
36
 
 
37
#   #!/bin/sh -- # -*- perl -*- -p
 
38
#   & eval 'exec /usr/bin/perl -wS $0 $argv:q'
 
39
#     if $running_under_some_shell;
 
40
 
 
41
 
 
42
#   #! /usr/bin/env python
 
43
 
 
44
 
 
45
use File::Basename;
 
46
 
 
47
if ("@ARGV") {
 
48
  foreach (@ARGV) {
 
49
    process_file($_);
 
50
  }
 
51
} else {
 
52
  
 
53
  # notice we are passed a list of filenames NOT as common in unix the
 
54
  # contents of the file.
 
55
  
 
56
  foreach (<>) {
 
57
    process_file($_);
 
58
  }
 
59
}
 
60
 
 
61
 
 
62
foreach $prog (sort keys %require) {
 
63
 
 
64
 
 
65
  # ignore variable interpolation and any program whose name is made
 
66
  # up only of non word characters ('<', '&&', etc).
 
67
 
 
68
  ( ( $prog != /\$/ ) || ( $prog =~ /^\W+$/ ) ) && 
 
69
    next;
 
70
 
 
71
  # filenames of the form './miniperl' will be reported in canonical
 
72
  # manner 'miniperl'
 
73
 
 
74
   $prog =~ s!^\./!!;
 
75
 
 
76
  if ( $prog !~ /\$/ ) {
 
77
    print "exectuable($prog)\n";
 
78
  }
 
79
 
 
80
  $prog=basename($prog);
 
81
 
 
82
  if ( $prog !~ /\$/ ) {
 
83
    print "exectuable($prog)\n";
 
84
 
 
85
    # get the correct version dependencies for magic numbers like:
 
86
    #   /usr/local/bin/perl5.00404 
 
87
    #   /usr/local/bin/tclsh8.0 
 
88
    # these are always PACKAGE versions since typical executables do not
 
89
    # have versions
 
90
 
 
91
    my $version = "";
 
92
    if ($module =~ s/([.0-9]+)$//) {
 
93
      $version = "$1";
 
94
      print "$prog>=$version\n";
 
95
    }
 
96
 
 
97
  }
 
98
 
 
99
}
 
100
 
 
101
exit 0;
 
102
 
 
103
 
 
104
sub process_file {
 
105
  
 
106
  my ($file) = @_;
 
107
  chomp $file;
 
108
  
 
109
  my ($version, $magic) = ();
 
110
  
 
111
  (-f $file) || return ;  
 
112
 
 
113
  open(FILE, "<$file")||
 
114
    die("$0: Could not open file: '$file' : $!\n");
 
115
  
 
116
  my $rc = sysread(FILE,$line,1000);
 
117
 
 
118
  $rc =~ s/\#.*\n//g;
 
119
 
 
120
  # Ignore all parameter substitution.
 
121
  # I have no hope of parsing something like: 
 
122
  #  exec ${SHELL:-/bin/sh}
 
123
  $rc =~ s/\$\{.*\}//g;
 
124
  $rc =~ s/echo\s+.*[\n;]//g;
 
125
  
 
126
  if  ( ($rc > 1) && ($line =~ m/^\#\!\s*/) )  {
 
127
    
 
128
    if ($line =~ m/\b(exec|env)\s+([\'\"\`\\]+)?([^ \t\n\r]+)/) {
 
129
      $require{$3} = 1;
 
130
    }
 
131
    
 
132
    # strip off extra lines and any arguments
 
133
    if ($line =~ m/^\#\!\s*([^ \t\n\r]+)/) {
 
134
      $require{$1} = 1;
 
135
    }
 
136
 
 
137
  }
 
138
 
 
139
  close(FILE) ||
 
140
    die("$0: Could not close file: '$file' : $!\n");
 
141
  
 
142
  return ; 
 
143
}