File: ConfigH.pm

package info (click to toggle)
libffi-platypus-perl 2.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,860 kB
  • sloc: perl: 7,388; ansic: 6,862; cpp: 53; sh: 19; makefile: 14
file content (46 lines) | stat: -rw-r--r-- 805 bytes parent folder | download | duplicates (3)
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
package My::ConfigH;

use strict;
use warnings;
use Carp qw( croak );
use File::Basename qw( basename );

sub new
{
  my($class, $filename) = @_;

  $filename ||= "include/ffi_platypus_config.h";

  my $self = bless {
    content  => '',
    filename => $filename,
  }, $class;

  $self;
}

sub define_var
{
  my($self, $key, $value) = @_;
  croak "value for $key is not defined" unless defined $value;
  $self->{content} .= "#define $key $value\n";
}

sub write_config_h
{
  my($self) = @_;

  my $once = uc basename($self->{filename});
  $once =~ s/\./_/g;

  my $fh;
  my $fn = $self->{filename};
  open $fh, '>', $fn or die "unable to write to $fn $!";
  print $fh "#ifndef $once\n";
  print $fh "#define $once\n\n";
  print $fh "@{[ $self->{content} ]}\n";
  print $fh "#endif\n";
  close $fh;
}

1;