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