line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package mqs::spool; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require 5.005_62; |
4
|
1
|
|
|
1
|
|
655
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
35
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
|
|
|
|
|
|
require DynaLoader; |
9
|
1
|
|
|
1
|
|
735
|
use AutoLoader qw(AUTOLOAD); |
|
1
|
|
|
|
|
1362
|
|
|
1
|
|
|
|
|
5
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter DynaLoader); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
14
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
15
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# This allows declaration use mqs::spool ':all'; |
18
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
19
|
|
|
|
|
|
|
# will save memory. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
) ] ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our @EXPORT = qw( |
28
|
|
|
|
|
|
|
initspooldirectory |
29
|
|
|
|
|
|
|
newfilename |
30
|
|
|
|
|
|
|
putinspool |
31
|
|
|
|
|
|
|
listfiles |
32
|
|
|
|
|
|
|
delfile |
33
|
|
|
|
|
|
|
readfile |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
bootstrap mqs::spool $VERSION; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Preloaded methods go here. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Autoload methods go after =cut, and are processed by the autosplit program. |
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
1
|
|
117
|
use Cwd; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
74
|
|
44
|
1
|
|
|
1
|
|
670
|
use POSIX; |
|
1
|
|
|
|
|
7498
|
|
|
1
|
|
|
|
|
11
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $size_spool = 32; |
47
|
|
|
|
|
|
|
my $spool_chmod = 0750; |
48
|
|
|
|
|
|
|
my $max_priority = 5; |
49
|
|
|
|
|
|
|
my $min_priority = 1; |
50
|
|
|
|
|
|
|
my $rnd_coeff = 64000; # value from 0 to $rnd_coeff to generate |
51
|
|
|
|
|
|
|
# randomized file names |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub initspooldirectory |
54
|
|
|
|
|
|
|
{ |
55
|
1
|
|
|
1
|
0
|
95
|
my %spool; |
56
|
1
|
|
|
|
|
4
|
my $dir = $_[0]; |
57
|
1
|
50
|
|
|
|
5
|
if($dir eq "") |
58
|
|
|
|
|
|
|
{ |
59
|
0
|
|
|
|
|
0
|
return -1; |
60
|
|
|
|
|
|
|
} |
61
|
1
|
50
|
|
|
|
30
|
unless(-d $dir) |
62
|
|
|
|
|
|
|
{ |
63
|
0
|
0
|
|
|
|
0
|
mkdir ($dir,$spool_chmod) or return $!; |
64
|
|
|
|
|
|
|
} |
65
|
1
|
|
|
|
|
12
|
my $currentdir = getcwd(); |
66
|
1
|
|
|
|
|
26
|
chdir($dir); |
67
|
1
|
|
|
|
|
2
|
my $it; |
68
|
1
|
|
|
|
|
8
|
for($it = 0; $it < $size_spool; $it++) |
69
|
|
|
|
|
|
|
{ |
70
|
32
|
50
|
|
|
|
350
|
unless(-d $it) |
71
|
|
|
|
|
|
|
{ |
72
|
0
|
0
|
|
|
|
0
|
mkdir ($it,$spool_chmod) or return $!; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
1
|
|
|
|
|
5
|
$spool{"type"} = "dir"; |
76
|
1
|
|
|
|
|
9
|
$spool{"directory"} = getcwd(); |
77
|
1
|
|
|
|
|
22
|
chdir $currentdir; |
78
|
1
|
|
|
|
|
11
|
return %spool; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub newfilename |
82
|
|
|
|
|
|
|
{ |
83
|
1050
|
|
|
1050
|
0
|
2045
|
my $dir = $_[0]; |
84
|
1050
|
|
|
|
|
4526
|
$dir = $dir."/".int(rand($size_spool)); |
85
|
1050
|
|
|
|
|
78716
|
my $entire_name = gen_name($dir); |
86
|
1050
|
|
|
|
|
6631
|
$entire_name = $entire_name.int(rand($rnd_coeff)); |
87
|
1050
|
|
|
|
|
3067
|
return $entire_name; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub putinspool |
91
|
|
|
|
|
|
|
{ |
92
|
1049
|
|
|
1049
|
0
|
4454525
|
my $spool_ref = $_[0]; |
93
|
1049
|
|
|
|
|
7072
|
my %spool = %$spool_ref; |
94
|
1049
|
|
|
|
|
2585
|
my $content = $_[1]; |
95
|
1049
|
|
|
|
|
1547
|
my $priority = $_[2]; |
96
|
1049
|
|
|
|
|
2967
|
my $filename; |
97
|
1049
|
50
|
33
|
|
|
12670
|
if($spool{'directory'} eq "" or $spool{'type'} ne "dir") |
98
|
|
|
|
|
|
|
{ |
99
|
0
|
|
|
|
|
0
|
return -1; |
100
|
|
|
|
|
|
|
} |
101
|
1049
|
50
|
|
|
|
37427
|
if(-d $spool{'directory'}) |
102
|
|
|
|
|
|
|
{ |
103
|
1049
|
|
|
|
|
4780
|
$filename = newfilename($spool{'directory'}); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
else |
106
|
|
|
|
|
|
|
{ |
107
|
0
|
|
|
|
|
0
|
return -1; |
108
|
|
|
|
|
|
|
} |
109
|
1049
|
|
|
|
|
2801
|
$filename = $filename.".".$priority; |
110
|
|
|
|
|
|
|
# if((write_file("$filename.tmp",$content)) == -1) |
111
|
|
|
|
|
|
|
# { |
112
|
|
|
|
|
|
|
# return -1; |
113
|
|
|
|
|
|
|
# } |
114
|
|
|
|
|
|
|
# C code has a bug with some caracthers, ... did not find why, I come |
115
|
|
|
|
|
|
|
# back in Perl code for this part |
116
|
1049
|
50
|
|
|
|
573359
|
open(OUT,">$filename.tmp") or return $!; |
117
|
1049
|
|
|
|
|
8500
|
print OUT"$content"; |
118
|
1049
|
|
|
|
|
74664
|
close(OUT); |
119
|
1049
|
|
|
|
|
75331
|
rename("$filename.tmp","$filename.mqs"); |
120
|
1049
|
|
|
|
|
5926
|
return 1; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub listfiles |
124
|
|
|
|
|
|
|
{ |
125
|
5
|
|
|
5
|
0
|
257
|
my $spool_ref = $_[0]; |
126
|
5
|
|
|
|
|
30
|
my %spool = %$spool_ref; |
127
|
5
|
|
|
|
|
10
|
my $priority = $_[1]; # not yet used |
128
|
5
|
50
|
33
|
|
|
40
|
if($spool{'directory'} eq "" or $spool{'type'} ne "dir") |
129
|
|
|
|
|
|
|
{ |
130
|
0
|
|
|
|
|
0
|
return -1; |
131
|
|
|
|
|
|
|
} |
132
|
5
|
|
|
|
|
10
|
my $dir; |
133
|
5
|
|
|
|
|
7
|
my $it = 0; |
134
|
5
|
|
|
|
|
7
|
my @files; |
135
|
5
|
|
|
|
|
19
|
for($dir = 0; $dir < $size_spool; $dir++) |
136
|
|
|
|
|
|
|
{ |
137
|
160
|
50
|
|
|
|
3551
|
opendir(DIR,$spool{'directory'}."/".$dir) or return $!; |
138
|
160
|
|
|
|
|
3279
|
while($files[$it] = readdir(DIR)) |
139
|
|
|
|
|
|
|
{ |
140
|
1369
|
100
|
|
|
|
4443
|
if($files[$it] =~ /.*\.mqs$/) |
141
|
|
|
|
|
|
|
{ |
142
|
1049
|
|
|
|
|
2087
|
$files[$it] = $spool{'directory'}."/".$dir."/".$files[$it]; |
143
|
1049
|
|
|
|
|
2823
|
$it++; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} |
146
|
160
|
|
|
|
|
1684
|
closedir(DIR); |
147
|
|
|
|
|
|
|
} |
148
|
5
|
|
|
|
|
38
|
$#files = $#files - 1; |
149
|
5
|
100
|
|
|
|
21
|
if($priority == 1) |
150
|
|
|
|
|
|
|
{ |
151
|
1
|
|
|
|
|
7
|
return &priority_spool(@files); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
else |
154
|
|
|
|
|
|
|
{ |
155
|
4
|
|
|
|
|
629
|
return @files; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub priority_spool |
160
|
|
|
|
|
|
|
{ |
161
|
1
|
|
|
1
|
0
|
7
|
my @files = @_; |
162
|
1
|
|
|
|
|
2
|
my $tmp; |
163
|
|
|
|
|
|
|
my @tab; |
164
|
0
|
|
|
|
|
0
|
my @return; |
165
|
1
|
|
|
|
|
2
|
my $pos = 0; |
166
|
1
|
|
|
|
|
3
|
my $i; |
167
|
1
|
|
|
|
|
7
|
for($i = $max_priority; $i != $min_priority - 1; $i--) |
168
|
|
|
|
|
|
|
{ |
169
|
5
|
|
|
|
|
7
|
foreach $tmp (@files) |
170
|
|
|
|
|
|
|
{ |
171
|
120
|
|
|
|
|
336
|
@tab = split(/\./,$tmp); |
172
|
120
|
100
|
|
|
|
284
|
if($tab[$#tab-1] == $i) |
173
|
|
|
|
|
|
|
{ |
174
|
24
|
|
|
|
|
26
|
$return[$pos] = $tmp; |
175
|
24
|
|
|
|
|
31
|
$pos++; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
} |
179
|
1
|
|
|
|
|
16
|
return @return; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub delfile |
183
|
|
|
|
|
|
|
{ |
184
|
1049
|
|
|
1049
|
0
|
26975
|
my $file = $_[0]; |
185
|
1049
|
50
|
|
|
|
4427061
|
unlink($file) or return $!; |
186
|
1049
|
|
|
|
|
2390
|
return 1; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub readfile |
190
|
|
|
|
|
|
|
{ |
191
|
1
|
|
|
1
|
0
|
11
|
my $file = $_[0]; |
192
|
1
|
|
|
|
|
8
|
my @tab = split(/\./,$file); |
193
|
1
|
|
|
|
|
3
|
my $priority = $tab[$#tab - 1]; |
194
|
1
|
|
|
|
|
2
|
my @line; |
195
|
1
|
50
|
|
|
|
43
|
open(IN,"<$file") or return -1; |
196
|
1
|
|
|
|
|
18
|
@line = ; |
197
|
1
|
|
|
|
|
11
|
close(IN); |
198
|
1
|
|
|
|
|
4
|
my $content = join("",@line); |
199
|
1
|
|
|
|
|
3
|
my @return = ($content,$priority); |
200
|
1
|
|
|
|
|
7
|
return @return; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
1; |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
__END__ |