Lookup and format message. Return as much of formatted string as fits in caller's buffer.
| 357 | |
| 358 | // Lookup and format message. Return as much of formatted string as fits in caller's buffer. |
| 359 | int fb_msg_format(void* handle, USHORT facility, USHORT number, unsigned int bsize, TEXT* buffer, |
| 360 | const MsgFormat::SafeArg& arg) |
| 361 | { |
| 362 | int total_msg = 0; |
| 363 | char msg[BUFFER_SMALL] = ""; |
| 364 | const int n = gds__msg_lookup(handle, facility, number, sizeof(msg), msg, NULL); |
| 365 | |
| 366 | if (n > 0 && unsigned(n) < sizeof(msg)) |
| 367 | { |
| 368 | // Shameful bridge, gds__msg_format emulation for old format messages. |
| 369 | if (strchr(msg, '%')) |
| 370 | { |
| 371 | const TEXT* rep[5]; |
| 372 | arg.dump(rep, 5); |
| 373 | total_msg = fb_utils::snprintf(buffer, bsize, msg, rep[0], rep[1], rep[2], rep[3], rep[4]); |
| 374 | } |
| 375 | else |
| 376 | total_msg = MsgPrint(buffer, bsize, msg, arg); |
| 377 | } |
| 378 | else |
| 379 | { |
| 380 | Firebird::string s; |
| 381 | s.printf("can't format message %d:%d -- ", facility, number); |
| 382 | if (n == -1) |
| 383 | s += "message text not found"; |
| 384 | else if (n == -2) |
| 385 | { |
| 386 | s += "message file "; |
| 387 | s += fb_utils::getPrefix(Firebird::IConfigManager::DIR_MSG, MSG_FILE).ToString(); |
| 388 | s += " not found"; |
| 389 | } |
| 390 | else |
| 391 | { |
| 392 | fb_utils::snprintf(buffer, bsize, "message system code %d", n); |
| 393 | s += buffer; |
| 394 | } |
| 395 | total_msg = s.copyTo(buffer, bsize); |
| 396 | } |
| 397 | |
| 398 | return (n > 0 ? total_msg : -total_msg); |
| 399 | } |
no test coverage detected