summaryrefslogtreecommitdiff
path: root/methods/hd.update
blob: 2a277dd85c8c851a37ea6f76ebe4a84af4ca5a4d (plain)
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
# Return associative array of fields from control file $file.
$vardir = $ARGV[0];
sub slurp
{
  local ($file) = @_;
  local (%controlinfo);
  local (%ci);

  open (CONTROL, $file) || return 1;

  # Get entire text of control file.
  undef $/; $* = 1; $_ = <CONTROL>;

  # Join lines.
  s/\n[ \t]+/ /g;

  # Split on fields.
  %controlinfo = ('PRESTUFF', split (/^(\S+):\s*/));

  $/ = "\n"; $* = 0;
  foreach $key (keys %controlinfo)
    {
      $key2 = $key; $key2 =~ y/A-Z/a-z/;
      chop ($controlinfo{$key}) if (/\n/);
      $ci{$key2} = $controlinfo{$key};
    }

  return %ci;
}

$file = "$vardir/methods/hd/hd.status";
%info = slurp($file);
open (IN, "<$info{'avail'}") || die "can't open $info{'avail'}";
open (OUT, ">$vardir/available") || die "can't open $vardir/available";
print OUT while (<IN>);
close IN;
close OUT;