1
by brian
clean slate |
1 |
# -*- cperl -*- |
2 |
# Copyright (C) 2004-2006 MySQL AB |
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or modify |
|
5 |
# it under the terms of the GNU General Public License as published by |
|
6 |
# the Free Software Foundation; version 2 of the License. |
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful, |
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 |
# GNU General Public License for more details. |
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License |
|
14 |
# along with this program; if not, write to the Free Software |
|
15 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
16 |
||
17 |
# This is a library file used by the Perl version of mysql-test-run, |
|
18 |
# and is part of the translation of the Bourne shell script with the |
|
19 |
# same name. |
|
20 |
||
21 |
use strict; |
|
22 |
||
23 |
sub mtr_match_prefix ($$); |
|
24 |
sub mtr_match_extension ($$); |
|
25 |
sub mtr_match_any_exact ($$); |
|
26 |
||
27 |
##############################################################################
|
|
28 |
#
|
|
29 |
#
|
|
30 |
#
|
|
31 |
##############################################################################
|
|
32 |
||
33 |
# Match a prefix and return what is after the prefix |
|
34 |
||
35 |
sub mtr_match_prefix ($$) { |
|
36 |
my $string= shift; |
|
37 |
my $prefix= shift; |
|
38 |
||
39 |
if ( $string =~ /^\Q$prefix\E(.*)$/ ) # strncmp |
|
40 |
{
|
|
41 |
return $1; |
|
42 |
}
|
|
43 |
else
|
|
44 |
{
|
|
45 |
return undef; # NULL |
|
46 |
}
|
|
47 |
}
|
|
48 |
||
49 |
||
50 |
# Match extension and return the name without extension |
|
51 |
||
52 |
sub mtr_match_extension ($$) { |
|
53 |
my $file= shift; |
|
54 |
my $ext= shift; |
|
55 |
||
56 |
if ( $file =~ /^(.*)\.\Q$ext\E$/ ) # strchr+strcmp or something |
|
57 |
{
|
|
58 |
return $1; |
|
59 |
}
|
|
60 |
else
|
|
61 |
{
|
|
62 |
return undef; # NULL |
|
63 |
}
|
|
64 |
}
|
|
65 |
||
66 |
||
67 |
# Match a substring anywere in a string |
|
68 |
||
69 |
sub mtr_match_substring ($$) { |
|
70 |
my $string= shift; |
|
71 |
my $substring= shift; |
|
72 |
||
73 |
if ( $string =~ /(.*)\Q$substring\E(.*)$/ ) # strncmp |
|
74 |
{
|
|
75 |
return $1; |
|
76 |
}
|
|
77 |
else
|
|
78 |
{
|
|
79 |
return undef; # NULL |
|
80 |
}
|
|
81 |
}
|
|
82 |
||
83 |
||
84 |
sub mtr_match_any_exact ($$) { |
|
85 |
my $string= shift; |
|
86 |
my $mlist= shift; |
|
87 |
||
88 |
foreach my $m (@$mlist) |
|
89 |
{
|
|
90 |
if ( $string eq $m ) |
|
91 |
{
|
|
92 |
return 1; |
|
93 |
}
|
|
94 |
}
|
|
95 |
return 0; |
|
96 |
}
|
|
97 |
||
98 |
1; |