915dabe1 |
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 | Should be in module sub-directory (reve/ or alieve/). |
11 | Note that GL and Editor siffixes are not present! |
12 | fnord |
13 | exit 1; |
14 | } |
15 | |
16 | my $MODULE = $ARGV[0]; |
17 | # Flat structure now. |
18 | # die "'$MODULE' not a directory" unless -d $MODULE; |
19 | |
20 | %suff = ( 'gl' => 'GL', 'ged' => 'Editor'); |
21 | my $STEM = $ARGV[1]; |
22 | my $CLASS = $STEM . $suff{$MODULE}; |
23 | |
24 | # Flat structure now. |
25 | # my $H_NAME = "$MODULE/$CLASS.h"; |
26 | # my $C_NAME = "$MODULE/$CLASS.cxx"; |
27 | my $H_NAME = "$CLASS.h"; |
28 | my $C_NAME = "$CLASS.cxx"; |
29 | |
30 | die "File '$H_NAME' already exists" if -e $H_NAME; |
31 | die "File '$C_NAME' already exists" if -e $C_NAME; |
32 | |
33 | sub find_skel { |
34 | my ($stem, $suff) = @_; |
35 | my $file1 = "$stem-$MODULE.$suff"; |
36 | return $file1 if -e $file1; |
37 | my $file2 = "$stem.$suff"; |
38 | return $file2 if -e $file2; |
39 | die "Skeleton file not found neither as '$file 1' nor '$file2'"; |
40 | } |
41 | |
42 | my $SKEL_H_NAME = find_skel(".SKEL", "h"); |
43 | my $SKEL_C_NAME = find_skel(".SKEL", "cxx"); |
44 | |
45 | print "Using skeleton files '$SKEL_H_NAME' and '$SKEL_C_NAME'\n"; |
46 | |
47 | my ($skel_h, $skel_c); |
48 | { |
49 | my $ex_sla = $/; undef $/; |
50 | open H, "$SKEL_H_NAME" or die "can't open $SKEL_H_NAME"; |
51 | $skel_h = <H>; close H; |
52 | open C, "$SKEL_C_NAME" or die "can't open $SKEL_C_NAME"; |
53 | $skel_c = <C>; close C; |
54 | $/ = $ex_sla; |
55 | } |
56 | |
57 | print "Replacing CLASS -> $CLASS, STEM -> $STEM.\n"; |
58 | |
59 | for $f ($skel_h, $skel_c) { |
60 | $f =~ s/CLASS/$CLASS/g; |
61 | $f =~ s/STEM/$STEM/g; |
62 | } |
63 | |
64 | print "Writing files '$H_NAME', '$C_NAME'.\n"; |
65 | |
66 | open H, ">$H_NAME" or |
67 | die "can't open $H_NAME"; |
68 | print H $skel_h; close H; |
69 | open H, ">$C_NAME" or |
70 | die "can't open $C_NAME"; |
71 | print H $skel_c; close H; |
72 | |
73 | if($DUMPINFO) { |
74 | print "# Now you should also edit the link-def file.\n"; |
75 | print "# Remember to run 'make depend'.\n"; |
76 | } |