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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
// load_config.cc
//
// Copyright 2000,2001 Daniel Burrows
#include "aptitude.h"
#include <cwidget/config/keybindings.h>
#include <cwidget/style.h>
#include <apt-pkg/configuration.h>
#include <apt-pkg/error.h>
#include <generic/apt/apt.h>
#include <generic/apt/config_signal.h>
#include <cwidget/generic/util/transcode.h>
#include <ctype.h>
using namespace std;
namespace cw = cwidget;
static int parse_color(const string &s)
{
const char * const cs=s.c_str();
if(!strcasecmp(cs, "black"))
return COLOR_BLACK;
else if(!strcasecmp(cs, "red"))
return COLOR_RED;
else if(!strcasecmp(cs, "green"))
return COLOR_GREEN;
else if(!strcasecmp(cs, "yellow"))
return COLOR_YELLOW;
else if(!strcasecmp(cs, "blue"))
return COLOR_BLUE;
else if(!strcasecmp(cs, "magenta"))
return COLOR_MAGENTA;
else if(!strcasecmp(cs, "cyan"))
return COLOR_CYAN;
else if(!strcasecmp(cs, "white"))
return COLOR_WHITE;
else if(!strcasecmp(cs, "default"))
return -1;
else
{
_error->Error(_("Unrecognized color name \"%s\""), cs);
return -1;
}
}
static attr_t parse_attr(const char *s, size_t len)
{
if(!strncasecmp(s, "standout", len))
return A_STANDOUT;
else if(!strncasecmp(s, "underline", len))
return A_UNDERLINE;
else if(!strncasecmp(s, "reverse", len))
return A_REVERSE;
else if(!strncasecmp(s, "blink", len))
return A_BLINK;
else if(!strncasecmp(s, "dim", len))
return A_DIM;
else if(!strncasecmp(s, "bold", len))
return A_BOLD;
else if(!strncasecmp(s, "protect", len))
return A_PROTECT;
else if(!strncasecmp(s, "invisible", len))
return A_INVIS;
else if(!strncasecmp(s, "altcharset", len))
return A_ALTCHARSET;
else
{
_error->Error(_("Unrecognized attribute name \"%s\""), s);
return 0;
}
}
static attr_t parse_attrs(const string &s)
{
attr_t rval=0;
const char * const cs=s.c_str();
string::size_type start=0;
while(start<s.size())
{
while(start < s.size() && s[start] == ',')
++start;
string::size_type len=0;
while(start+len < s.size() && s[start+len] != ',')
++len;
rval|=parse_attr(cs+start, len);
start+=len;
}
return rval;
}
void load_styles(std::string group, bool use_theme)
{
Configuration::Item const *cfg_grp=aptcfg->get_cfg(use_theme)->Tree(group.c_str());
if(!cfg_grp)
return;
for(Configuration::Item const *i=cfg_grp->Child; i; i=i->Next)
{
if(!i->Value.empty())
_error->Error(_("Invalid entry in style definition group: \"%s\""), i->Tag.c_str());
else if(i->Tag.empty())
_error->Error(_("Invalid tagless entry in style definition group: \"%s\""), i->Value.c_str());
else
{
cw::style curr;
for(Configuration::Item const *j=i->Child; j; j=j->Next)
{
if(!strcasecmp(j->Tag.c_str(), "fg"))
{
int c = parse_color(j->Value);
if(c == -1)
_error->Error(_("The default color may only be used as a background."));
else
curr.set_fg(c);
}
else if(!strcasecmp(j->Tag.c_str(), "bg"))
curr.set_bg(parse_color(j->Value));
else
{
void (cw::style::*f)(attr_t)=NULL;
if(!strcasecmp(j->Tag.c_str(), "set"))
f=&cw::style::attrs_on;
else if(!strcasecmp(j->Tag.c_str(), "clear"))
f=&cw::style::attrs_off;
else if(!strcasecmp(j->Tag.c_str(), "flip"))
f=&cw::style::attrs_flip;
if(!f)
_error->Error(_("Unknown style attribute %s"),
j->Tag.c_str());
else
(curr.*f)(parse_attrs(j->Value));
}
}
set_style(i->Tag, curr);
}
}
}
void load_bindings(std::string group, cw::config::keybindings *toload, bool use_theme)
{
Configuration::Item const *cfg_grp=aptcfg->get_cfg(use_theme)->Tree(group.c_str());
if(!cfg_grp)
return;
for(Configuration::Item const *i=cfg_grp->Child; i; i=i->Next)
if(!i->Child)
{
if(i->Value.empty())
_error->Error(_("Invalid entry in keybinding group: \"%s\""), i->Tag.c_str());
else if(i->Tag.empty())
_error->Error(_("Invalid entry in keybinding group: \"%s\""), i->Value.c_str());
else
{
std::string::size_type split=0,newsplit;
cw::config::keybinding newbinding;
do
{
newsplit=i->Value.find(',',split);
string currval(i->Value, split, newsplit-split);
cw::config::key k = cw::config::parse_key(cw::util::transcode(currval));
if(k.ch!=(wint_t) ERR)
newbinding.push_back(k);
else
_error->Error(_("Ignoring invalid keybinding \"%s\" -> \"%s\""), i->Tag.c_str(), currval.c_str());
split=newsplit+1;
} while(newsplit!=string::npos);
cw::config::global_bindings.set(i->Tag, newbinding);
}
}
}
|