1 ###################################################
2 # utility functions to support the build farm
3 # Copyright (C) tridge@samba.org, 2001
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 ##############################################
24 # load a list from a file, using : to separate
32 push (@lines,$_) unless (/^#/);
38 ##############################################
39 # load a hash from a file, using : to separate
43 my @lines = load_list($fname);
46 if ($l =~ /^([\w\-]*)\s*:\s*(.*)$/) {
53 #####################################################################
54 # check if a string is in an array
59 return 1 if ($v eq $s);
64 #####################################################################
65 # flatten an array of arrays into a single array
71 push(@b, $_) foreach (@{$d});
76 #####################################################################
77 # flatten an array of hashes into a single hash
83 for my $k (keys %{$d}) {
90 #####################################################################
91 # return the modification time of a file
94 my($filename) = shift;
95 return (stat($filename))[9];
98 #####################################################################
99 # read a file into a string
102 my($filename) = shift;
104 open(INPUTFILE, $filename) || return "";
105 my($saved_delim) = $/;
107 my($data) = <INPUTFILE>;
113 #####################################################################
114 # write a string into a file
117 my($filename) = shift;
120 open(FILE, ">$filename") || die "can't open $filename";
125 #####################################################################
126 # return a filename with a changed extension
127 sub ChangeExtension($$)
129 my($fname,$ext) = @_;
130 return "$1.$ext" if ($fname =~ /^(.*)\.(.*?)$/);
131 return "$fname.$ext";
134 #####################################################################
135 # save a data structure into a file
136 sub SaveStructure($$)
138 my($filename) = shift;
140 FileSave($filename, Dumper($v));
143 #####################################################################
144 # load a data structure from a file (as saved with SaveStructure)
147 return eval FileLoad(shift);
150 ##########################################
151 # count the number of lines in a buffer
156 $count++ while $s =~ /$/gm;
161 # display a time as days, hours, minutes
165 my $days = int($sec / (60*60*24));
166 my $hour = int($sec / (60*60)) % 24;
167 my $min = int($sec / 60) % 60;
176 return sprintf("%dd %dh %dm", $days, $hour, $min);
179 return sprintf("%dh %dm", $hour, $min);
182 return sprintf("%dm", $min);
184 return sprintf("%ds", $sec);
187 ##############################################
188 # simple html markup stripper
192 # get rid of comments
193 $string =~ s/<!\-\-(.*?)\-\->/$2/g;
196 while ($string =~ s&<(\w+).*?>(.*?)</\1>&$2&) {