forked from vit-project/vit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvitrc.pl
122 lines (103 loc) · 3.21 KB
/
vitrc.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
121
# Copyright 2013 - 2016, Scott Kostyshak
sub parse_vitrc {
my $vitrc = glob("~/.vitrc");
if ( open(IN,"<$vitrc") ) {
while (<IN>) {
chop;
my $parse_error = "ERROR: incorrect key bind line in .vitrc:\n $_\n";
if ( $_ =~ s/^map // ) {
my($scut, $cmd) = split(/=/, $_, 2);
my $skey;
if ($scut =~ s/([^ ]+)$//) {
$skey = $1;
}
else {
print STDERR "$parse_error";
exit(1);
}
$skey = &replace_keycodes("$skey");
$cmd = &replace_keycodes("$cmd");
# TODO: get rid of the eval().
# This shouldn't be too hard, but I need to figure out what exactly is happening here.
$skey = eval "\"$skey\"";
$shortcuts{$skey} = $cmd;
}
elsif ( $_ =~ s/^set // ) {
my($configname, $configval) = split(/=/, $_, 2);
&audit("CONFIG: user requests to set '$configname' to '$configval'");
if ($configname eq "burndown") {
# TODO: fix code duplication (see below)
if (!&sanitycheck_bool($configval)) {
print STDERR "ERROR: boolean config variable '$configname' must ".
"be set to 'yes' or 'no'.\n";
exit(1);
}
$burndown = $configval;
}
elsif ($configname eq "confirmation") {
# TODO: fix code duplication (see above)
if (!&sanitycheck_bool($configval)) {
print STDERR "ERROR: boolean config variable '$configname' must ".
"be set to 'yes' or 'no'.\n";
exit(1);
}
$confirmation = ( $configval eq "yes" ? 1 : undef );
}
elsif ($configname eq "wait") {
# TODO: more code duplication
if (!&sanitycheck_bool($configval)) {
print STDERR "ERROR: boolean config variable '$configname' must ".
"be set to 'yes' or 'no'.\n";
exit(1);
}
$nowait = ($configval eq "no");
}
}
}
close(IN);
}
}
#------------------------------------------------------------------
sub replace_keycodes {
my $str_ = $_[0];
$str_ =~ s/<F1>/KEY_F(1)/e;
$str_ =~ s/<F2>/KEY_F(2)/e;
$str_ =~ s/<F3>/KEY_F(3)/e;
$str_ =~ s/<F4>/KEY_F(4)/e;
$str_ =~ s/<F5>/KEY_F(5)/e;
$str_ =~ s/<F6>/KEY_F(6)/e;
$str_ =~ s/<F7>/KEY_F(7)/e;
$str_ =~ s/<F8>/KEY_F(8)/e;
$str_ =~ s/<F9>/KEY_F(9)/e;
$str_ =~ s/<F10>/KEY_F(10)/e;
$str_ =~ s/<F11>/KEY_F(11)/e;
$str_ =~ s/<F12>/KEY_F(12)/e;
$str_ =~ s/<Home>/KEY_HOME/e;
$str_ =~ s/<End>/KEY_END/e;
$str_ =~ s/<Insert>/KEY_IC/e;
$str_ =~ s/<Del>/KEY_DC/e;
$str_ =~ s/<PageUp>/KEY_PPAGE/e;
$str_ =~ s/<PageDown>/KEY_NPAGE/e;
$str_ =~ s/<Up>/KEY_UP/e;
$str_ =~ s/<Down>/KEY_DOWN/e;
$str_ =~ s/<Right>/KEY_RIGHT/e;
$str_ =~ s/<Left>/KEY_LEFT/e;
$str_ =~ s/<Backspace>/KEY_BACKSPACE/e;
# We don't evaluate these ones (no 'e').
$str_ =~ s/<Space>/ /;
$str_ =~ s/<Tab>/\t/;
$str_ =~ s/<Return>/\n/;
$str_ =~ s/<Esc>/\e/;
return $str_;
}
#------------------------------------------------------------------
sub sanitycheck_bool {
my $bool_ = $_[0];
if ($bool_ ne "yes" && $bool_ ne "no") {
return 0;
}
else {
return 1;
}
}
return 1;