File: find_cvs_fpdoc_files.pl

package info (click to toggle)
lazarus 0.9.30.4-6
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 114,420 kB
  • sloc: pascal: 1,108,945; xml: 249,481; makefile: 120,941; sh: 2,651; perl: 395; sql: 174; ansic: 137
file content (140 lines) | stat: -rwxr-xr-x 3,602 bytes parent folder | download | duplicates (2)
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
140
#!/usr/bin/env perl
#
# *****************************************************************************
# *                                                                           *
# *  See the file COPYING.modifiedLGPL, included in this distribution,        *
# *  for details about the copyright.                                         *
# *                                                                           *
# *  This program is distributed in the hope that it will be useful,          *
# *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
# *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
# *                                                                           *
# *****************************************************************************
#
# Author: Mattias Gaertner

use vars qw/ %opt /;
use Getopt::Std;
my $opt_string = 'hs:l:o:x';
getopts( "$opt_string", \%opt ) or usage();
usage() if $opt{h};

sub usage(){
  print STDERR << "EOF";

Create fpdoc sceletons for pascal units

usage: $0 [-hsolx]

 -h                    : this (help) message
 -s <source directory> : the source directory with the .pp and .pas files
 -o <output directory> : the output directory for the xml files
 -l new|old            : new = show new fpdoc files, not yet in CVS
                         old = show old CVS files, not needed by fpdoc
 -x                    : call cvs

examples:
  find_cvs_fpdoc_files.pl -s ../../lcl -o lcl -l new

EOF
  exit;
}

($opt{s}) || usage(); # source directory needed
($opt{o}) || usage(); # output directory needed
($opt{l}) || usage(); # list option needed
($opt{l}=~/^(new|old)$/) || usage();

$SrcDir=$opt{s};
(-d $SrcDir) || die "source directory $SrcDir is not a directory\n";
$SrcDir=~s#//#/#;
$SrcDir=~s#/$##;

$OutDir=$opt{o};
(-d $OutDir) || die "output directory $OutDir is not a directory\n";
$OutDir=~s#//#/#;
$OutDir=~s#/$##;


# get pascal units
opendir(DIR, $SrcDir);
@SrcFiles = grep(/\.(pas|pp)$/,readdir(DIR));
for ($i=0; $i<=$#SrcFiles; $i++){
  ($SrcFiles[$i]=~/^([a-zA-Z0-9_]+)\./);
  $SrcUnits.=" ".$1;
}
closedir(DIR);
#print "$SrcUnits\n";

# get FPDoc xml files
opendir(DIR, $OutDir);
@XMLFiles = grep(/\.xml$/,readdir(DIR));
closedir(DIR);

# get CVS files
open(F, $OutDir."/CVS/Entries");
while($line=<F>){
  ($line=~/^\/([^\/]+)\//);
  $CVSEntries.="/".$1;
}
close(F);
#print "$CVSEntries\n";

for $XMLFile(@XMLFiles){
  ($XMLFile=~/^([a-zA-Z0-9_]+).xml/);
  $UnitName=$1;
  if($SrcUnits=~/\b$UnitName\b/){
    $UnitNeeded=1;
  } else {
    $UnitNeeded=0;
  }
  if($CVSEntries=~/\b$UnitName\.xml\b/){
    $UnitInCVS=1;
  } else {
    $UnitInCVS=0;
  }
  if (($UnitNeeded) && (! $UnitInCVS)){
    $NewFilesNotYetInCVS.=$OutDir."/".$XMLFile." ";
  }
  if ((! $UnitNeeded) && ($UnitInCVS)){
    $OldFilesInCVS.=$OutDir."/".$XMLFile." ";
  }
  #print $XMLFile." ".$UnitName." $UnitNeeded $UnitInCVS\n";
}

if ($opt{l} eq "new"){
  print "Adding new Files:\n";
  if ($NewFilesNotYetInCVS){
    $Command="cvs -z3 add $NewFilesNotYetInCVS";
    DoIt($Command);
  }
}
if ($opt{l} eq "old"){
  print "Removing unneeded files:\n";
  if ($OldFilesInCVS){
    $Command="rm $OldFilesInCVS";
    DoIt($Command);
    $Command="cvs -z3 remove $OldFilesInCVS";
    DoIt($Command);
  }
}


if(!$opt{x}){
  print "\nThis was a simulation. To really remove files and change cvs, use the -x option.\n";
}

sub DoIt(){
  (my $Command)=@_;
  print $Command."\n";
  if($opt{x}){
    my $Output=`$Command`;
    if($?){
      die "Command failed:\n".$Output;
    }
    print $Output;
  }
}

# end.