1 # This file is part of The New Aspell
2 # Copyright (C) 2001-2002 by Kevin Atkinson under the GNU LGPL
3 # license version 2.0 or 2.1. You should have received a copy of the
4 # LGPL license along with this library if you did not you can find it
5 # at http://www.gnu.org/.
11 our @ISA = qw(Exporter);
12 our @EXPORT = qw(create_cc_file create_file);
17 no warnings qw(uninitialized);
27 =item create_cc_file PARMS
31 Required Parms: type, dir, name, data
32 Boolean Parms: header, cxx
33 Optional Parms: namespace (required if cxx), pre_ext, accum
35 =item create_file FILENAME DATA
37 Writes DATA to FILENAME but only if DATA differs from the content of
38 the file and the string:
40 Automatically generated file.
42 is present in the existing file if it already exists.
48 sub create_cc_file ( % );
50 sub create_file ( $ $ );
52 sub create_cc_file ( % ) {
54 $p{name} = $p{data}{name} unless exists $p{name};
55 $p{ext} = $p{cxx} ? ($p{header} ? 'hpp' : 'cpp') : 'h';
57 my %accum = exists $p{accum} ? (%{$p{accum}}) : ();
58 foreach my $d (@{$p{data}{data}}) {
59 next unless exists $info{$d->{type}}{proc}{$p{type}};
60 $body .= $info{$d->{type}}{proc}{$p{type}}->($d, \%accum);
62 return unless length($body) > 0;
64 /* Automatically generated file. Do not edit directly. */
66 /* This file is part of The New Aspell
67 * Copyright (C) 2001-2002 by Kevin Atkinson under the GNU LGPL
68 * license version 2.0 or 2.1. You should have received a copy of the
69 * LGPL license along with this library if you did not you can find it
70 * at http://www.gnu.org/. */
73 my $hm = "ASPELL_". to_upper($p{name})."__".to_upper($p{ext});
74 $file .= "#ifndef $hm\n#define $hm\n\n" if $p{header};
75 $file .= "#include \"aspell.h\"\n" if $p{type} eq 'cxx';
76 $file .= "#include \"settings.h\"\n" if $p{type} eq 'native_impl' && $p{name} eq 'errors';
77 $file .= "#include \"gettext.h\"\n" if $p{type} eq 'native_impl' && $p{name} eq 'errors';
78 $file .= cmap {"#include \"".to_lower($_).".hpp\"\n"} sort keys %{$accum{headers}};
79 $file .= "#ifdef __cplusplus\nextern \"C\" {\n#endif\n" if $p{header} && !$p{cxx};
80 $file .= "\nnamespace $p{namespace} {\n\n" if $p{cxx};
81 if (defined $info{forward}{proc}{$p{type}}) {
82 my @types = sort {$a->{name} cmp $b->{name}} (values %{$accum{types}});
83 $file .= cmap {$info{forward}{proc}{$p{type}}->($_)} @types;
87 $file .= "\n\n}\n\n" if $p{cxx};
88 $file .= "#ifdef __cplusplus\n}\n#endif\n" if $p{header} && !$p{cxx};
89 $file .= "#endif /* $hm */\n" if $p{header};
90 create_file $p{dir}.'/'.to_lower($p{name}).$p{pre_ext}.'.'.$p{ext}, $file;
93 sub create_file ( $ $ ) {
94 my ($filename, $to_write) = @_;
97 open F,"../$filename" and $existing=<F>;
98 if ($to_write eq $existing) {
99 print "File \"$filename\" unchanged.\n";
100 } elsif (length $existing > 0 && $existing !~ /Automatically generated file\./) {
101 print "Will not write over \"$filename\".\n";
103 print "Creating \"$filename\".\n";
104 open F, ">../$filename" or die;