|
a/src/utils/conftree.cpp |
|
b/src/utils/conftree.cpp |
|
... |
|
... |
249 |
value = s->second;
|
249 |
value = s->second;
|
250 |
return 1;
|
250 |
return 1;
|
251 |
}
|
251 |
}
|
252 |
|
252 |
|
253 |
// Appropriately output a subkey (nm=="") or variable line.
|
253 |
// Appropriately output a subkey (nm=="") or variable line.
|
254 |
// Splits long lines
|
254 |
// We can't make any assumption about the data except that it does not
|
|
|
255 |
// contain line breaks.
|
|
|
256 |
// Avoid long lines if possible (for hand-editing)
|
|
|
257 |
// We used to break at arbitrary places, but this was ennoying for
|
|
|
258 |
// files with pure UTF-8 encoding (some files can be binary anyway),
|
|
|
259 |
// because it made later editing difficult, as the file would no
|
|
|
260 |
// longer have a valid encoding.
|
|
|
261 |
// Any ASCII byte would be a safe break point for utf-8, but could
|
|
|
262 |
// break some other encoding with, e.g. escape sequences? So break at
|
|
|
263 |
// whitespace (is this safe with all encodings?).
|
|
|
264 |
// Note that the choice of break point does not affect the validity of
|
|
|
265 |
// the file data (when read back by conftree), only its ease of
|
|
|
266 |
// editing with a normal editor.
|
255 |
static ConfSimple::WalkerCode varprinter(void *f, const string &nm,
|
267 |
static ConfSimple::WalkerCode varprinter(void *f, const string &nm,
|
256 |
const string &value)
|
268 |
const string &value)
|
257 |
{
|
269 |
{
|
258 |
ostream *output = (ostream *)f;
|
270 |
ostream& output = *((ostream *)f);
|
259 |
if (nm.empty()) {
|
271 |
if (nm.empty()) {
|
260 |
*output << "\n[" << value << "]\n";
|
272 |
output << "\n[" << value << "]\n";
|
261 |
} else {
|
273 |
} else {
|
262 |
string value1;
|
274 |
output << nm << " = ";
|
263 |
if (value.length() < 60) {
|
275 |
if (nm.length() + value.length() < 75) {
|
264 |
value1 = value;
|
276 |
output << value;
|
265 |
} else {
|
277 |
} else {
|
266 |
string::size_type pos = 0;
|
278 |
string::size_type ll = 0;
|
267 |
while (pos < value.length()) {
|
279 |
for (string::size_type pos = 0; pos < value.length(); pos++) {
|
268 |
string::size_type len = MIN(60, value.length() - pos);
|
280 |
string::value_type c = value[pos];
|
269 |
value1 += value.substr(pos, len);
|
281 |
output << c;
|
270 |
pos += len;
|
282 |
ll++;
|
271 |
if (pos < value.length())
|
283 |
// Break at whitespace if line too long and "a lot" of
|
272 |
value1 += "\\\n";
|
284 |
// remaining data
|
|
|
285 |
if (ll > 50 && (value.length() - pos) > 10 &&
|
|
|
286 |
(c == ' ' || c == '\t')) {
|
|
|
287 |
ll = 0;
|
|
|
288 |
output << "\\\n";
|
|
|
289 |
}
|
273 |
}
|
290 |
}
|
274 |
}
|
291 |
}
|
275 |
*output << nm << " = " << value1 << "\n";
|
292 |
output << "\n";
|
276 |
}
|
293 |
}
|
277 |
return ConfSimple::WALK_CONTINUE;
|
294 |
return ConfSimple::WALK_CONTINUE;
|
278 |
}
|
295 |
}
|
279 |
|
296 |
|
280 |
// Set variable and rewrite data
|
297 |
// Set variable and rewrite data
|