]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/reve-genclass.pl
alice-data/gentle_geo_trd.root
[u/mrichter/AliRoot.git] / EVE / reve-genclass.pl
1 #!/usr/bin/perl
2
3 my ($BINDIR, $BINNAME) = $0 =~ m!^(.*)/(.*)!;
4 if ($#ARGV != 1) {
5   print STDERR <<"fnord";
6 usage: $BINNAME <module> <class-base>
7    eg: $BINNAME base     QuadSet
8        $BINNAME gl       QuadSet
9        $BINNAME ged      QuadSet
10        $BINNAME gedsubed QuadSet
11 Should be in module sub-directory (Reve/ or Alieve/).
12 Note that GL and Editor suffixes are not present!
13 fnord
14   exit 1;
15 }
16
17 my $MODULE = $ARGV[0];
18 # Flat structure now.
19 # die "'$MODULE' not a directory" unless -d $MODULE;
20
21 %suff = ( 'gl' => 'GL', 'ged' => 'Editor', 'gedsubed' => 'Editor');
22 my $STEM  = $ARGV[1];
23 my $CLASS = $STEM . $suff{$MODULE};
24
25 if ($MODULE eq 'gedsubed') {
26   $replace_xxclass = 1;
27   $XXCLASS = $STEM . 'SubEditor';
28 }
29
30 # Flat structure now.
31 # my $H_NAME = "$MODULE/$CLASS.h";
32 # my $C_NAME = "$MODULE/$CLASS.cxx";
33 my $H_NAME = "$CLASS.h";
34 my $C_NAME = "$CLASS.cxx";
35
36 die "File '$H_NAME' already exists" if -e $H_NAME;
37 die "File '$C_NAME' already exists" if -e $C_NAME;
38
39 sub find_skel {
40   my ($stem, $suff) = @_;
41   my $file1 = "$stem-$MODULE.$suff";
42   return $file1 if -e $file1;
43   my $file2 = "$stem.$suff";
44   return $file2 if -e $file2;
45   die "Skeleton file not found neither as '$file 1' nor '$file2'";
46 }
47
48 my $SKEL_H_NAME = find_skel(".SKEL", "h");
49 my $SKEL_C_NAME = find_skel(".SKEL", "cxx");
50
51 print "Using skeleton files '$SKEL_H_NAME' and '$SKEL_C_NAME'\n";
52
53 my ($skel_h, $skel_c);
54 {
55   my $ex_sla = $/; undef $/;
56   open H, "$SKEL_H_NAME" or die "can't open $SKEL_H_NAME";
57   $skel_h = <H>; close H;
58   open C, "$SKEL_C_NAME" or die "can't open $SKEL_C_NAME";
59   $skel_c = <C>; close C;
60   $/ = $ex_sla;
61 }
62
63 print "Replacing CLASS -> $CLASS, STEM -> $STEM.\n";
64
65 for $f ($skel_h, $skel_c) {
66   $f =~ s/XXCLASS/$XXCLASS/g if ($replace_xxclass);
67   $f =~ s/CLASS/$CLASS/g;
68   $f =~ s/STEM/$STEM/g;
69 }
70
71 print "Writing files '$H_NAME', '$C_NAME'.\n";
72
73 open H, ">$H_NAME" or
74   die "can't open $H_NAME";
75 print H $skel_h; close H;
76 open H, ">$C_NAME" or
77   die "can't open $C_NAME";
78 print H $skel_c; close H;
79
80 if($DUMPINFO) {
81   print "# Now you should also edit the link-def file.\n";
82   print "# Remember to run 'make depend'.\n";
83 }