Added an unknown VxD error code.
[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     my $progress_count = \${$self->{PROGRESS_COUNT}};
14     my $prefix = \${$self->{PREFIX}};
15
16     $$progress = "";
17     $$last_progress = "";
18     $$progress_count = 0;
19     $$prefix = "";
20
21     return $self;
22 }
23
24
25 sub show_progress {
26     my $self = shift;
27     my $progress = \${$self->{PROGRESS}};
28     my $last_progress = \${$self->{LAST_PROGRESS}};
29     my $progress_count = \${$self->{PROGRESS_COUNT}};
30
31     $$progress_count++;
32
33     if($$progress_count > 0 && $$progress) {
34         print STDERR $$progress;
35         $$last_progress = $$progress;
36     }
37 }
38
39 sub hide_progress  {
40     my $self = shift;
41     my $progress = \${$self->{PROGRESS}};
42     my $last_progress = \${$self->{LAST_PROGRESS}};
43     my $progress_count = \${$self->{PROGRESS_COUNT}};
44
45     $$progress_count--;
46
47     if($$last_progress) {
48         my $message;
49         for (1..length($$last_progress)) {
50             $message .= "\b \b";
51         }
52         print STDERR $message;
53         undef $$last_progress;
54     }
55 }
56
57 sub update_progress {
58     my $self = shift;
59     my $progress = \${$self->{PROGRESS}};
60     my $last_progress = \${$self->{LAST_PROGRESS}};
61     
62     my $prefix = "";
63     my $suffix = "";
64     if($$last_progress) {
65         for (1..length($$last_progress)) {
66             $prefix .= "\b";
67         }
68         
69         my $diff = length($$last_progress)-length($$progress);
70         if($diff > 0) {
71             for (1..$diff) {
72                 $suffix .= " ";
73             }
74             for (1..$diff) {
75                 $suffix .= "\b";
76             }
77         }
78     }
79     print STDERR $prefix . $$progress . $suffix;
80     $$last_progress = $$progress;
81 }
82
83 sub progress {
84     my $self = shift;
85     my $progress = \${$self->{PROGRESS}};
86
87     $$progress = shift;
88
89     $self->update_progress;
90 }
91
92 sub prefix {
93     my $self = shift;
94     my $prefix = \${$self->{PREFIX}};
95
96     $$prefix = shift;
97 }
98
99 sub write {
100     my $self = shift;
101
102     my $message = shift;
103
104     my $prefix = \${$self->{PREFIX}};
105
106     $self->hide_progress;
107     print $$prefix . $message;
108     $self->show_progress;
109 }
110
111 1;