File: convert.pl

package info (click to toggle)
libdate-calc-perl 4.2-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 584 kB
  • ctags: 171
  • sloc: perl: 3,382; ansic: 1,972; makefile: 56; sh: 54
file content (86 lines) | stat: -rw-r--r-- 2,316 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
#!perl

###############################################################################
##                                                                           ##
##    Copyright (c) 1998 by Steffen Beyer.                                   ##
##    All rights reserved.                                                   ##
##                                                                           ##
##    This program is free software; you can redistribute it                 ##
##    and/or modify it under the same terms as Perl itself.                  ##
##                                                                           ##
###############################################################################

$self = $0;
$self =~ s!^.*/!!;

use Config;

$cc = $Config{'cc'};
$flags = $Config{'ccflags'};
$charset = ($Config{'archname'} =~ /MSWin32/i) ? "-win" : "-dos";

&compile('iso2pc.c');
&compile('pc2iso.c');

&convert('../Calc.pm');
&convert('../DateCalc.c');
&convert('../DateCalc.h');
&convert('../examples/age_in_days_eu.pl');
&convert('../examples/age_in_days_us.pl');

exit;

sub compile
{
    my($source) = @_;
    my($target);

    $target = $source;
    $target =~ s!\.c$!!;
    if ((-f $target) || (-f "$target.exe"))
    {
        warn "$self: skipping compilation of '$source': '$target' exists!\n";
    }
    else
    {
        print "$self: compiling '$source'...\n";
        $rc = system("$cc $flags -o $target $source");
        if ($rc >> 8)
        {
            warn "$self: unable to compile '$source'!\n";
            die  "Please fix problem (or compile manually) and re-run $self.\n";
        }
    }
}

sub convert
{
    my($source) = @_;
    my($target);

    $target = $source;
    $target .= '_';

    if (-f $target)
    {
        warn "$self: skipping renaming of '$source': '$target' exists!\n";
    }
    else
    {
        print "$self: renaming '$source' to '$target'...\n";
        unless (rename($source,$target))
        {
            warn "$self: unable to rename '$source' to '$target'!\n";
            return;
        }
    }
    print "$self: converting '$target' to '$source'...\n";
    $rc = system("./iso2pc $charset <$target >$source");
    if ($rc >> 8)
    {
        warn "$self: unable to convert '$target' to '$source'!\n";
    }
}

__END__