- Fixed the long long problem.
[wine] / tools / winapi_check / output.pm
1 package output;
2
3 use strict;
4
5 sub new {
6     my $proto = shift;
7     my $class = ref($proto) || $proto;
8     my $self  = {};
9     bless ($self, $class);
10
11     my $progress = \${$self->{PROGRESS}};
12     my $last_progress = \${$self->{LAST_PROGRESS}};
13
14     $$progress = "";
15     $$last_progress = "";
16
17     return $self;
18 }
19
20
21 sub show_progress {
22     my $self = shift;
23     my $progress = \${$self->{PROGRESS}};
24     my $last_progress = \${$self->{LAST_PROGRESS}};
25
26     if($$progress) {
27         print STDERR $$progress;
28         $$last_progress = $$progress;
29     }
30 }
31
32 sub hide_progress  {
33     my $self = shift;
34     my $progress = \${$self->{PROGRESS}};
35     my $last_progress = \${$self->{LAST_PROGRESS}};
36
37     if($$last_progress) {
38         my $message;
39         for (1..length($$last_progress)) {
40             $message .= "\b \b";
41         }
42         print STDERR $message;
43         undef $$last_progress;
44     }
45 }
46
47 sub update_progress {
48     my $self = shift;
49     my $progress = \${$self->{PROGRESS}};
50     my $last_progress = \${$self->{LAST_PROGRESS}};
51     
52     my $prefix = "";
53     for (1..length($$last_progress)) {
54         $prefix .= "\b";
55     }
56
57     my $suffix = "";
58     my $diff = length($$last_progress)-length($$progress);
59     if($diff > 0) {
60         for (1..$diff) {
61             $suffix .= " ";
62         }
63         for (1..$diff) {
64             $suffix .= "\b";
65         }
66     }
67     print STDERR $prefix . $$progress . $suffix;
68     $$last_progress = $$progress;
69 }
70
71 sub progress {
72     my $self = shift;
73     my $progress = \${$self->{PROGRESS}};
74
75     $$progress = shift;
76
77     $self->update_progress;
78 }
79
80 sub write {
81     my $self = shift;
82     my $last_progress = \${$self->{LAST_PROGRESS}};
83
84     my $message = shift;
85      
86     $self->hide_progress;
87     print STDERR $message;
88     $self->show_progress;
89 }
90
91 1;