More robust yacc/bison failure output handling.
[p5sagit/p5-mst-13.2.git] / lib / cacheout.pl
CommitLineData
39c3038c 1# Open in their package.
2
3sub cacheout'open {
4 open($_[0], $_[1]);
5}
6
a0d0e21e 7# Close as well
8
9sub cacheout'close {
10 close($_[0]);
11}
12
39c3038c 13# But only this sub name is visible to them.
14
15sub cacheout {
16 package cacheout;
17
18 ($file) = @_;
39c3038c 19 if (!$isopen{$file}) {
20 if (++$numopen > $maxopen) {
55204971 21 local(@lru) = sort {$isopen{$a} <=> $isopen{$b};} keys(%isopen);
39c3038c 22 splice(@lru, $maxopen / 3);
23 $numopen -= @lru;
a0d0e21e 24 for (@lru) { &close($_); delete $isopen{$_}; }
39c3038c 25 }
26 &open($file, ($saw{$file}++ ? '>>' : '>') . $file)
27 || die "Can't create $file: $!\n";
28 }
29 $isopen{$file} = ++$seq;
30}
31
32package cacheout;
33
34$seq = 0;
35$numopen = 0;
36
37if (open(PARAM,'/usr/include/sys/param.h')) {
7adad424 38 local($_, $.);
39c3038c 39 while (<PARAM>) {
55204971 40 $maxopen = $1 - 4 if /^\s*#\s*define\s+NOFILE\s+(\d+)/;
39c3038c 41 }
42 close PARAM;
43}
44$maxopen = 16 unless $maxopen;
45
461;