summaryrefslogtreecommitdiff
path: root/lib/sbin/CopyParFiles.pl
blob: 5b2b9494103dad2af3eab15a2cab3936718d52ae (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/perl -s
#
# Script to copy parameter files
#
# Only copies those parameter files that used the compiled thorns
#
# Version: $Id$

$home = `pwd`;
chop($home);

$config = $ARGV[0];

open(THORNLIST,"<configs/$config/ThornList") || die "ThornList not available";

# Create examples directory if needed
if (! -d "examples")
{
    mkdir("examples", 0755) || die "Unable to create examples directory";
}

# Create configuration directory if needed
if (! -d "examples/$config")
{
  mkdir("examples/$config", 0755) || die "Unable to create examples/$config directory";
}

# Create an array of compiled thorns 
$nthorns = 0;
while (<THORNLIST>)
{
  /^(\S*)/;
  $line = $1;
  next if (m:^\#:);
  $thorns[$nthorns] = $line;
  $nthorns++;
}
close(THORNLIST);

@sorted = sort(@thorns);

for ($i=0;$i<$nthorns;$i++)
{
  $thorn = $sorted[$i];
  $thorn = "arrangements/$thorn/par";
  if (-d $thorn)
  {    
    $newthorn = 1;
    chdir $thorn;
    while ($parfile = <*.par>)
    { 
      $gotall = 1;
      $counter = 0;
      @ActiveThorns = &GetActiveThorns($parfile);
      $donothave = "";
      for ($j=0;$j<scalar(@ActiveThorns);$j++)
      {
	$gotit = 0;
	for ($k=0;$k<$nthorns;$k++)
	{
	  $sorted[$k] =~ m:.*/(\w*):;
	  if ($ActiveThorns[$j] =~ /^$1$/i)
	  {
	    $gotit = 1;
	  }
	}
	if ($gotit == 0)
	{
	  $counter++;
	  if ($counter%6 != 0)
	  {
	    $donothave .= "$ActiveThorns[$j] ";
	  }
	  else
	  {
	    $donothave .= "\n       $ActiveThorns[$j] ";
	  }
	  $gotall = 0;
	}
      }

      if ($newthorn == 1)
      {
	print "  $sorted[$i]:\n";
	$newthorn = 0;
      }
      
      if ($gotall == 1)
      {
	if (-e "$home/examples/$config/$parfile")
	{
	  print "    $parfile: Not copied, already exists\n";
	}
	else
	{
	  print "    $parfile: Copied\n";
	  system("cp $parfile $home/examples/$config/$parfile");
	}
      }
      else
      {
       $donothave =~ s/\s*$//;
       print "    $parfile: Not copied, missing thorns\n      ($donothave)\n";
     }
    }
    
    chdir "$home${sep}";

  }

}

# Parse the active thorns from a parameter file
sub GetActiveThorns
{
  my($parfile) = @_;
  my $i;
  my @ActiveThorns;

  open(PAR,"<$parfile");
  while (<PAR>)
  {
    if ($_ =~ /ActiveThorns\s*=\s*\"(.*)\"/)
    {
      @ActiveThorns = split(' ',$1);
    }
  }
  close(PAR);
  
  # Get rid of spaces and change to lower case
  for ($i=0;$i<scalar(@ActiveThorns);$i++)
  {
    $ActiveThorns[$i] =~ s/\s*//g;
    $ActiveThorns[$i] = lc $ActiveThorns[$i];
  } 
 
  return sort(@ActiveThorns);

}