forked from vit-project/vit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
misc.pl
120 lines (100 loc) · 2.19 KB
/
misc.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Copyright 2012 - 2013, Steve Rader
# Copyright 2013 - 2016, Scott Kostyshak
sub audit {
if ( $audit ) {
print AUDIT "$$ ";
print AUDIT @_;
print AUDIT "\r\n";
}
}
#------------------------------------------------------------------
sub clean_exit {
unless( $audit ) {
&shell_exec("clear", 'no-wait');
}
if ( $audit ) {
close(AUDIT) or die "$!";
}
endwin() unless isendwin();
exit();
}
#------------------------------------------------------------------
sub error_exit {
# do not exit VIT if we are in a try/catch block
if ( $during_try ) {
return
}
unless( $audit ) {
&shell_exec("clear", 'no-wait');
}
endwin();
print STDERR "VIT fatal error: @_\r\n";
if ( $audit ) {
close(AUDIT) or die "$!";
}
exit(1);
}
#------------------------------------------------------------------
sub debug {
print AUDIT @_;
print AUDIT "\r\n";
}
#------------------------------------------------------------------
sub is_printable {
my $char = $_[0];
if ( $char =~ /^[0-9]+$/ && $char >= KEY_MIN ) {
return 0;
}
if ( $char =~ /[[:cntrl:]]/ ) {
return 0;
}
return 1;
}
#------------------------------------------------------------------
sub task_version {
my $request = $_[0];
my $version;
open(IN,"task --version 2>&1 |");
while(<IN>) {
chop;
$version = $_;
}
close(IN);
if ( $request eq "major.minor" ) {
my @v_ = split(/\./,$version);
return "$v_[0].$v_[1]";
}
return $version;
}
#------------------------------------------------------------------
sub task_info {
my $n = $_[0];
my $id = $report2taskid[$task_selected_idx];
&audit("EXEC $task $id information 2>&1");
open(IN,"task $id information 2>&1 |");
while(<IN>) {
chop;
$_ =~ s/\x1b.*?m//g; # decolorize
if ( $_ =~ /^$n\s+(.*)/ ) {
my $v = $1;
$v =~ s/\s+$//;
close(IN);
return $v;
}
}
close(IN);
return '';
}
#------------------------------------------------------------------
sub ungetstr {
my $str = $_[0];
my $err;
foreach my $ch (reverse split('', $str)) {
$err = ungetch($ch);
if ( $err != 0 ) {
error_exit("Shortcut is too long.");
}
}
return '';
}
return 1;