line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Ananke::Template; |
4
|
1
|
|
|
1
|
|
950
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11291
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.4'; |
7
|
|
|
|
|
|
|
my @my; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Processo para facilitar o print do template |
10
|
|
|
|
|
|
|
sub view_template { |
11
|
0
|
|
|
0
|
0
|
|
my ($template_dir,$template_file,$vars,$to_file) = @_; |
12
|
0
|
|
|
|
|
|
my $return; |
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
|
|
|
my $template = new Ananke::Template($template_dir); |
15
|
0
|
|
|
|
|
|
$return = $template->process($template_file,$vars,$to_file); |
16
|
|
|
|
|
|
|
|
17
|
0
|
0
|
|
|
|
|
return $return if ($to_file == 1); |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
undef $template_dir; undef $template_file; undef $vars; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
undef $template; undef $to_file; |
|
0
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Inicia modulo |
24
|
|
|
|
|
|
|
sub new { |
25
|
0
|
|
|
0
|
0
|
|
my($self,$templ_dir,$to_file) = @_; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Grava dados |
28
|
0
|
|
|
|
|
|
bless { |
29
|
|
|
|
|
|
|
'TEMPL_DIR' => $templ_dir, |
30
|
|
|
|
|
|
|
}, $self; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Processa página |
34
|
|
|
|
|
|
|
sub process { |
35
|
0
|
|
|
0
|
0
|
|
my($self,$file,$vars,$to_file) = @_; |
36
|
0
|
|
|
|
|
|
my($fdata,$output,$my,$return); |
37
|
0
|
|
|
|
|
|
$self->{TEMPL_FILE} = $file; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Retorna em var, sprintf |
40
|
0
|
0
|
|
|
|
|
if ($to_file == 1) { |
41
|
0
|
|
|
|
|
|
$self->{TO_RETURN} = 1; |
42
|
0
|
|
|
|
|
|
undef $to_file; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
$self->{TO_FILE} = $to_file; |
46
|
0
|
|
|
|
|
|
@my = (); |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
$fdata = $self->load(); |
49
|
0
|
|
|
|
|
|
$output = $self->parse($fdata,$vars); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
#$my = "my \$return;\n"; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
foreach (@my) { |
54
|
0
|
|
|
|
|
|
$my .= $_->{value}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
$output = $my.$output; |
58
|
0
|
|
|
|
|
|
$return = eval $output; |
59
|
|
|
|
|
|
|
#print $output."\n"; |
60
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
print $@ if ($@); |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
return $return if ($self->{TO_RETURN}); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
#open (FH,">/tmp/filexx"); |
66
|
|
|
|
|
|
|
#syswrite(FH,$output); |
67
|
|
|
|
|
|
|
#close(FH); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Trata arquivo |
71
|
|
|
|
|
|
|
sub parse { |
72
|
0
|
|
|
0
|
0
|
|
my($self,$fdata,$vars) = @_; |
73
|
0
|
|
|
|
|
|
my(@t,$ndata,$output); |
74
|
0
|
|
|
|
|
|
my $outype; |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
|
if ($self->{TO_FILE}) { |
77
|
0
|
|
|
|
|
|
$output .= "open(OUTFILE,\">".$self->{TO_FILE}."\");"; |
78
|
0
|
|
|
|
|
|
$outype = "OUTFILE"; |
79
|
|
|
|
|
|
|
} else { |
80
|
0
|
|
|
|
|
|
$outype = "STDOUT"; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Transfere dados para vars |
84
|
0
|
|
|
|
|
|
foreach (keys %{$vars}) { |
|
0
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
push(@my,{ |
86
|
|
|
|
|
|
|
var => "\$T$_", |
87
|
|
|
|
|
|
|
value => "my \$T$_ = \$vars->{$_};\n" |
88
|
|
|
|
|
|
|
}); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# Adiciona \ em caracteres nao permitidos |
92
|
0
|
|
|
|
|
|
my $Tstart = quotemeta("[%"); |
93
|
0
|
|
|
|
|
|
my $Tend = quotemeta("%]"); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# Faz o primeiro parse |
96
|
0
|
|
|
|
|
|
while ($fdata) { |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# Verifica parse |
99
|
0
|
0
|
|
|
|
|
if ($fdata =~ s/^(.*?)?(?:$Tstart\s?(.*?)\s?$Tend)//sx) { |
|
|
0
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
$t[1] = $1; $t[2] = $2; |
|
0
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
$t[1] =~ s/[\n|\s]//g if ($t[1] =~ /^[\n\s]+$/); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# Nao executa linhas comentadas e espacos desnecessarios |
105
|
0
|
|
|
|
|
|
$t[2] =~ s/^\s+?\#\s+(.*?)\s+?$//g; |
106
|
0
|
|
|
|
|
|
$t[2] =~ s/^\s+?(.*?)\s+?$/$1/g; |
107
|
|
|
|
|
|
|
|
108
|
0
|
0
|
|
|
|
|
if ($t[1]) { |
109
|
0
|
|
|
|
|
|
$t[1] = "\nsyswrite($outype,\"".&AddSlashes($t[1])."\");"; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# Retira espaços em branco no começo e final da var |
113
|
0
|
|
|
|
|
|
$t[2] =~ s/^[ ]+?(.*)[ ]+?$/$1/s; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# Trata if e elsif |
116
|
0
|
0
|
|
|
|
|
if ($t[2] =~ /^(IF|ELSIF|UNLESS)\s+(.*)$/i) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
$t[3] = lc($1); |
118
|
0
|
|
|
|
|
|
$t[4] = $2; |
119
|
0
|
|
|
|
|
|
$t[4] =~ s/AND/\&\&/g; $t[4] =~ s/OR/\|\|/g; |
|
0
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
0
|
0
|
|
|
|
|
$t[3] = "} ".$t[3] if ($t[3] eq "elsif"); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# Trata todos os tipos de vars |
124
|
0
|
|
|
|
|
|
while ($t[4] =~ /([\s\>\<\=\%\!\&\|]+)?([\&\;\w\"\'\.\+\-\/\^\$\á\é]+)([\&\>\<\=\%\!\|\&]+)?/g) { |
125
|
0
|
|
|
|
|
|
$t[5] = $1; $t[6] = $2; $t[7] = $3; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# Verifica qual metodo de comparacao deve usar |
128
|
0
|
|
|
|
|
|
$t[5] =~ s/\=\=/eq/g; $t[5] =~ s/\!\=/ne/g; |
|
0
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
$t[7] =~ s/\=\=/eq/g; $t[7] =~ s/\!\=/ne/g; |
|
0
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# vars scalares |
132
|
|
|
|
|
|
|
#if ($t[6] =~ /^(\w+)\.(\w+)$/) { |
133
|
|
|
|
|
|
|
# $t[6] = "\$T".$1."->{$2}"; |
134
|
|
|
|
|
|
|
# $self->my("\$T".$1."->{$2}"); |
135
|
|
|
|
|
|
|
#} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# Trata hash |
138
|
0
|
0
|
|
|
|
|
if ($t[6] =~ /(\w+)\.(\w+).?(\w+)?/) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
$self->my("\$T".$1."->{$2}"); |
140
|
0
|
|
|
|
|
|
$t[6] = "\$T".$1."->{".$2."}"; |
141
|
0
|
0
|
|
|
|
|
$t[6] .= "->{".$3."}" if ($3); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# Numeros |
145
|
|
|
|
|
|
|
elsif ($t[6] =~ /^([\d]+)$/) { |
146
|
0
|
|
|
|
|
|
$t[6] = $1; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# Demais variaveis |
150
|
|
|
|
|
|
|
elsif ($t[6] =~ /^(\w+)$/) { |
151
|
0
|
|
|
|
|
|
$self->my("\$T".$t[6]); |
152
|
0
|
|
|
|
|
|
$t[6] = "\$T".$t[6]; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# String |
156
|
|
|
|
|
|
|
elsif ($t[6] =~ /^([\w\"\']+)$/) { |
157
|
0
|
|
|
|
|
|
$t[6] = $1; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# vars normais |
161
|
|
|
|
|
|
|
#else { |
162
|
|
|
|
|
|
|
#} |
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
$t[8] .= $t[5].$t[6].$t[7]; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
$t[2] = "\n".$t[3]." (".$t[8].") {"; |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
# Verifica que tipo de comparacao deve usar |
170
|
0
|
0
|
|
|
|
|
if ($t[2] =~ /\s(eq|ne)\s\//) { |
171
|
0
|
0
|
|
|
|
|
if ($1 eq "eq") { $t[2] =~ s/ eq / =~ /g; } |
|
0
|
0
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
elsif ($1 eq "ne") { $t[2] =~ s/ ne / !~ /g; } |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
|
undef $t[3]; undef $t[4]; undef $t[5]; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
176
|
0
|
|
|
|
|
|
undef $t[6]; undef $t[7]; undef $t[8]; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
# Trata for |
180
|
|
|
|
|
|
|
elsif ($t[2] =~ /(FOR)\s(.*)/) { |
181
|
0
|
|
|
|
|
|
$t[8] = $1; |
182
|
0
|
|
|
|
|
|
$t[3] = $2; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
# Trata opcoes do for |
185
|
0
|
|
|
|
|
|
while ($t[3] =~ /([\;])?([\w\.\+\-]+)([\<\=\>\!]+)?/g) { |
186
|
0
|
|
|
|
|
|
$t[4] = $2; $t[5] = $3; $t[6] = $1; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
$t[6] =~ s/\=\=/eq/g; $t[6] =~ s/\!\=/ne/g; |
|
0
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
# Trata numeros |
190
|
0
|
0
|
|
|
|
|
if ($t[4] =~ /^[0-9]+$/) { |
|
|
0
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
$t[4] = $t[4]; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
# Trata hash |
195
|
|
|
|
|
|
|
elsif ($t[4] =~ /^(\w+)\.(\w+)$/) { |
196
|
0
|
|
|
|
|
|
$self->my("\$T".$1."->{$2}"); |
197
|
0
|
|
|
|
|
|
$t[4] = "\$T".$1."->{$2}"; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
# Trata vars |
201
|
|
|
|
|
|
|
else { |
202
|
0
|
|
|
|
|
|
$self->my("\$T".$t[4]); |
203
|
0
|
|
|
|
|
|
$t[4] = "\$T".$t[4]; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
0
|
|
|
|
|
|
$t[7] .= "$t[6]$t[4]$t[5]"; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
0
|
|
|
|
|
|
$t[2] = "\n".lc($t[8])." (".$t[7].") {"; |
210
|
|
|
|
|
|
|
|
211
|
0
|
|
|
|
|
|
undef $t[3]; undef $t[4]; undef $t[5]; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
212
|
0
|
|
|
|
|
|
undef $t[6]; undef $t[7]; undef $t[8]; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
# Trata foreach |
216
|
|
|
|
|
|
|
elsif ($t[2] =~ /(FOREACH) (.*) = (.*)/i) { |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
# Seta vars do if |
219
|
0
|
|
|
|
|
|
$t[3] = $1; $t[4] = $2; $t[5] = $3; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
# Verifica se é array |
222
|
0
|
0
|
|
|
|
|
if (ref $vars->{$t[5]} eq "ARRAY") { |
|
|
0
|
|
|
|
|
|
223
|
0
|
|
|
|
|
|
$t[2] = "\n".lc($t[3])." my \$T$t[4] (\@{\$T$t[5]}) {"; |
224
|
0
|
|
|
|
|
|
$self->my("\@T$t[5]"); |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
# Verifica se e' multi-array |
228
|
|
|
|
|
|
|
elsif ($t[5] =~ /^(.*)\.(.*)$/) { |
229
|
0
|
|
|
|
|
|
$t[2] = "\n".lc($t[3])." my \$T$t[4] (\@{\$T$1->\{$2\}}) {"; |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
# Caso nao exista array |
233
|
|
|
|
|
|
|
else { |
234
|
0
|
|
|
|
|
|
$t[2] = "\n".lc($t[3])." my \$T$t[4] (\@\{0\}) {"; |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
# apaga vars do if |
238
|
0
|
|
|
|
|
|
undef $t[3]; undef $t[4]; undef $t[5]; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
# Fecha sintaxy |
242
|
|
|
|
|
|
|
elsif ($t[2] eq "END") { |
243
|
0
|
|
|
|
|
|
$t[2] = "\n}"; |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
# Else |
247
|
|
|
|
|
|
|
elsif ($t[2] eq "ELSE") { |
248
|
0
|
|
|
|
|
|
$t[2] = "\n} else {"; |
249
|
|
|
|
|
|
|
} |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
# Adiciona include |
252
|
|
|
|
|
|
|
elsif ($t[2] =~ /^INCLUDE\s+(.*)$/) { |
253
|
0
|
|
|
|
|
|
$t[3] = $1; |
254
|
|
|
|
|
|
|
|
255
|
0
|
|
|
|
|
|
$t[3] =~ s/^\!(.*)$/$vars->{$1}/g; |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
# Verifica se arquivo existe para dar include |
258
|
0
|
0
|
|
|
|
|
if (-f $self->{TEMPL_DIR}."/".$t[3]) { |
259
|
0
|
|
|
|
|
|
$ndata = $self->load($t[3]); |
260
|
0
|
|
|
|
|
|
$t[2] = $self->parse($ndata,$vars); |
261
|
|
|
|
|
|
|
} else { |
262
|
0
|
|
|
|
|
|
$t[2] = undef; |
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
# Trata hash |
267
|
|
|
|
|
|
|
elsif ($t[2] =~ /(\w+)\.(\w+).?(\w+)?/) { |
268
|
0
|
|
|
|
|
|
$t[10] = "\$T".$1."->{".$2."}"; |
269
|
0
|
0
|
|
|
|
|
$t[10] .= "->{".$3."}" if ($3); |
270
|
|
|
|
|
|
|
|
271
|
0
|
|
|
|
|
|
$t[2] = "\nsyswrite($outype,".$t[10].");"; |
272
|
0
|
|
|
|
|
|
$self->my($t[10]); |
273
|
|
|
|
|
|
|
|
274
|
0
|
|
|
|
|
|
undef $t[10]; |
275
|
|
|
|
|
|
|
} |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
# Trata string |
278
|
|
|
|
|
|
|
elsif ($t[2] =~ /^\w$/) { |
279
|
0
|
|
|
|
|
|
$self->my("\$T".$t[2]); |
280
|
0
|
|
|
|
|
|
$t[2] = "\nsyswrite($outype,\$T".$t[2].");"; |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
# Seta vars |
284
|
|
|
|
|
|
|
elsif ($t[2] =~ /^([\w\+\-]+)\s?([\=\>\<\!]+)?\s?[\"]?(.*)?[\"]?$/) { |
285
|
0
|
|
|
|
|
|
$t[3] = $1; $t[4] = $2; $t[5] = $3; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
286
|
0
|
|
|
|
|
|
$t[4] =~ s/\=\=/eq/g; $t[4] =~ s/\!\=/ne/g; |
|
0
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
|
288
|
0
|
0
|
|
|
|
|
$t[5] =~ s/"$//g if ($t[5] =~ /"$/); |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
# Trata variaveis unica |
291
|
0
|
0
|
0
|
|
|
|
if ($t[3] && !$t[5]) { |
|
|
0
|
0
|
|
|
|
|
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
# Variaveis |
294
|
0
|
0
|
|
|
|
|
if ($t[3] =~ /^\w+$/) { |
|
|
0
|
|
|
|
|
|
295
|
0
|
|
|
|
|
|
$self->my("\$T".$t[3]); |
296
|
0
|
|
|
|
|
|
$t[2] = "\nsyswrite($outype,\$T".$t[3].");"; |
297
|
|
|
|
|
|
|
} |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
# Variaveis especiais |
300
|
|
|
|
|
|
|
elsif ($t[3] =~ /^[\w\+\-]+$/) { |
301
|
0
|
|
|
|
|
|
$self->my("\$T".$t[3]); |
302
|
0
|
|
|
|
|
|
$t[2] = "\n\$T".$t[3].";"; |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
# Seta variaveis |
307
|
|
|
|
|
|
|
elsif ($t[3] && $t[5]) { |
308
|
0
|
|
|
|
|
|
$self->my("\$T".$t[3]); |
309
|
0
|
|
|
|
|
|
$t[2] = "\n\$T".$t[3]." $t[4] \"".&AddSlashes($t[5])."\";"; |
310
|
|
|
|
|
|
|
} |
311
|
|
|
|
|
|
|
} |
312
|
|
|
|
|
|
|
|
313
|
0
|
|
|
|
|
|
$output .= $t[1].$t[2]; |
314
|
|
|
|
|
|
|
} |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
# Outros |
317
|
|
|
|
|
|
|
elsif ($fdata =~ s/^(.*)$//sx) { |
318
|
0
|
|
|
|
|
|
$output .= "\nsyswrite($outype,\"".&AddSlashes($1)."\");\n"; |
319
|
|
|
|
|
|
|
} |
320
|
|
|
|
|
|
|
} |
321
|
|
|
|
|
|
|
|
322
|
0
|
0
|
|
|
|
|
$output .= "close(OUTFILE);\n" if ($self->{TO_FILE}); |
323
|
0
|
0
|
|
|
|
|
$output =~ s/syswrite\(STDOUT,/\$return .= sprintf(/g if ($self->{TO_RETURN}); |
324
|
0
|
|
|
|
|
|
return $output; |
325
|
|
|
|
|
|
|
} |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
# Verifica se adicionou no array |
328
|
|
|
|
|
|
|
sub my { |
329
|
0
|
|
|
0
|
0
|
|
my($self,$var) = @_; |
330
|
0
|
|
|
|
|
|
my (@t,$t); |
331
|
|
|
|
|
|
|
|
332
|
0
|
0
|
|
|
|
|
if ($var =~ /^([\$\@\%])(.*)?$/) { |
333
|
0
|
|
|
|
|
|
$t[1] = $1; $t[2] = $2; |
|
0
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
# Trata array |
336
|
0
|
0
|
0
|
|
|
|
if ($t[1] eq "\@") { |
|
|
0
|
|
|
|
|
|
337
|
|
|
|
|
|
|
# Verifica se ja esta no array |
338
|
0
|
|
|
|
|
|
$t = 1; |
339
|
0
|
0
|
|
|
|
|
foreach (@my) { if ($_->{var} eq "\@".$t[2]) { undef $t } } |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
# Adiciona no array |
342
|
0
|
0
|
|
|
|
|
push(@my,{ |
343
|
|
|
|
|
|
|
var => "\@".$t[2], |
344
|
|
|
|
|
|
|
value => "my \@".$t[2].";\n", |
345
|
|
|
|
|
|
|
}) if ($t); |
346
|
|
|
|
|
|
|
|
347
|
0
|
|
|
|
|
|
undef $t; |
348
|
|
|
|
|
|
|
} |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
# Trata var |
351
|
|
|
|
|
|
|
elsif ($t[1] eq "\$" && $t[2] =~ /^([\w\+]+)([\-\>]+)?([\w\{\}]+)?/g) { |
352
|
0
|
|
|
|
|
|
$t[3] = $1; |
353
|
0
|
|
|
|
|
|
$t[3] =~ s/\+//g; $t[3] =~ s/\-//g; |
|
0
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
# Verifica se ja esta no array |
356
|
0
|
|
|
|
|
|
$t = 1; |
357
|
0
|
|
|
|
|
|
foreach (@my) { |
358
|
0
|
0
|
|
|
|
|
if ($_->{var} eq "\$".$t[3]) { |
359
|
0
|
|
|
|
|
|
undef $t; |
360
|
0
|
|
|
|
|
|
last; |
361
|
|
|
|
|
|
|
} |
362
|
|
|
|
|
|
|
} |
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
# Adiciona no array |
365
|
0
|
0
|
|
|
|
|
push(@my,{ |
366
|
|
|
|
|
|
|
var => "\$".$t[3], |
367
|
|
|
|
|
|
|
value => "my \$".$t[3].";\n", |
368
|
|
|
|
|
|
|
}) if ($t); |
369
|
|
|
|
|
|
|
|
370
|
0
|
|
|
|
|
|
undef $t; |
371
|
|
|
|
|
|
|
} |
372
|
|
|
|
|
|
|
} |
373
|
|
|
|
|
|
|
} |
374
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
# Abre aquivo |
376
|
|
|
|
|
|
|
sub load { |
377
|
0
|
|
|
0
|
0
|
|
my($self,$templ_file) = @_; |
378
|
0
|
|
|
|
|
|
my($r,$fdata); |
379
|
0
|
|
|
|
|
|
my $path; |
380
|
0
|
|
0
|
|
|
|
my $file = $templ_file || $self->{TEMPL_FILE}; |
381
|
0
|
|
|
|
|
|
my $templ_path = $self->{TEMPL_DIR}."/".$file; |
382
|
|
|
|
|
|
|
|
383
|
0
|
|
|
|
|
|
local $/ = undef; |
384
|
|
|
|
|
|
|
#local *FH; |
385
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
# Abre arquivo |
387
|
0
|
0
|
|
|
|
|
if (open(FH,$templ_path)) { |
388
|
0
|
|
|
|
|
|
$fdata = ; |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
#open(FH2,">>/tmp/filexx"); |
391
|
|
|
|
|
|
|
#syswrite(FH2,$fdata); |
392
|
|
|
|
|
|
|
#close(FH2); |
393
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
# Fecha arquivo |
395
|
0
|
|
|
|
|
|
close(FH); |
396
|
|
|
|
|
|
|
} |
397
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
# Retorna erro |
399
|
|
|
|
|
|
|
else { |
400
|
0
|
|
|
|
|
|
die "Erro abrindo arquivo $templ_path: $!\n"; |
401
|
|
|
|
|
|
|
} |
402
|
|
|
|
|
|
|
|
403
|
|
|
|
|
|
|
# Retorna dados |
404
|
0
|
|
|
|
|
|
return $fdata; |
405
|
|
|
|
|
|
|
} |
406
|
|
|
|
|
|
|
|
407
|
|
|
|
|
|
|
# Adiciona barras invertidas |
408
|
|
|
|
|
|
|
sub AddSlashes { |
409
|
0
|
|
|
0
|
0
|
|
my($str) = @_; |
410
|
|
|
|
|
|
|
|
411
|
0
|
|
|
|
|
|
$str =~ s/\\/\\\\/g; |
412
|
0
|
|
|
|
|
|
$str =~ s/\#/\\#/g; |
413
|
0
|
|
|
|
|
|
$str =~ s/\@/\\@/g; |
414
|
0
|
|
|
|
|
|
$str =~ s/\"/\\"/g; |
415
|
|
|
|
|
|
|
|
416
|
0
|
|
|
|
|
|
return $str; |
417
|
|
|
|
|
|
|
} |
418
|
|
|
|
|
|
|
|
419
|
|
|
|
|
|
|
1; |
420
|
|
|
|
|
|
|
__END__ |