-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcompile_servlet.pl
executable file
·118 lines (105 loc) · 2.46 KB
/
compile_servlet.pl
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/perl
use strict;
use XML::Simple;
use Data::Dumper;
our $inputfile;
our $outputdir;
our $move;
if(scalar(@ARGV) eq 0) {
print "compile_servlet.pl - Compiles an OSP servlet and its XML metadata\n";
print "Usage:\n\tcompile_servlet.pl [-d dir] <input file>\n\n";
exit(-1);
} elsif(scalar(@ARGV) eq 1) {
$inputfile = $ARGV[0];
$outputdir = "./";
$move = 0;
} else {
$inputfile = $ARGV[2];
$outputdir = $ARGV[1];
$move = 1;
}
our $tempdir;
our $basename = $inputfile;
$basename =~ s/\.[a-z]*$//;
$basename =~ s/^.*\///;
my $extension = $inputfile;
$extension =~ s/^(.*\.)([a-z]+)$/$2/;
my $ret;
if($extension =~ /erl/) {
$ret = erl();
} elsif($extension =~ /sdf/) {
$ret = sdf();
} elsif($extension =~ /sap/) {
$ret = sap();
} else {
print "Error, invalid filetype\n";
exit(-1);
}
if($ret eq 0) {
print "$basename - Compilation complete\n";
exit(0);
} else {
print "Error in compilation of $basename\n";
exit($ret);
}
sub sap {
`mkdir $basename`;
`unzip -d $basename $inputfile`;
opendir(DIR, $basename);
while(defined(my $file = readdir(DIR))) {
if($file =~ /^\.$/ || $file =~ /^\.\.$/) {
# Do nothing
} else {
my $ret = `./compile_servlet.pl $basename/$file`;
if($ret =~ /complete/) {
# Do nothing
my $generatedfile = $file;
$generatedfile =~ s/\.[a-z]*$//;
$generatedfile .= ".erl";
`mv -f $generatedfile $basename/`;
} else {
return -1;
}
}
}
closedir(DIR);
if($move eq 1) {
`mv $basename $outputdir`;
}
return 0;
}
sub erl {
`mv $inputfile $outputdir`;
return 0;
}
sub sdf {
my $parser = new XML::Simple;
my $data = $parser->XMLin($inputfile);
my $author = "'".$data->{author}."'";
my $module = $data->{name};
my $version = "'".$data->{version}."'";
my $code = $data->{code}->{server};
my $initfunc = $data->{code}->{init};
my $cleanup = $data->{code}->{cleanup};
my $proto = $data->{proto};
`cat header.erl | sed -e s/AUTHOR/$author/ -e s/PROTO/$proto/ -e s/VSN/$version/ -e s/MOD/$module/g > $module.erl`;
open(FP, ">>$module.erl");
print FP $code;
close(FP);
open(FP, ">>$module.erl");
print FP $initfunc;
close(FP);
open(FP, ">>$module.erl");
print FP $cleanup;
close(FP);
#`erlc $module.erl`;
#`rm $module.erl`;
if (-e "$module.erl") {
if($move eq 1) {
`mv $module.erl $outputdir`;
}
return 0;
} else {
return -1;
}
}