| 507 | */ |
| 508 | |
| 509 | bool ConfigFile::translate(const char* fileName, const String& from, String& to) const |
| 510 | { |
| 511 | if (from == "root") |
| 512 | { |
| 513 | to = Config::getRootDirectory(); |
| 514 | } |
| 515 | else if (from == "install") |
| 516 | { |
| 517 | to = Config::getInstallDirectory(); |
| 518 | } |
| 519 | else if (from == "this") |
| 520 | { |
| 521 | if (!fileName) |
| 522 | { |
| 523 | return false; |
| 524 | } |
| 525 | |
| 526 | PathName tempPath(fileName); |
| 527 | |
| 528 | #ifdef UNIX |
| 529 | if (PathUtils::isSymLink(tempPath)) |
| 530 | { |
| 531 | // If $(this) is a symlink, expand it. |
| 532 | TEXT temp[MAXPATHLEN]; |
| 533 | const int n = readlink(fileName, temp, sizeof(temp)); |
| 534 | |
| 535 | if (n != -1) |
| 536 | { |
| 537 | tempPath.assign(temp, n); |
| 538 | |
| 539 | if (PathUtils::isRelative(tempPath)) |
| 540 | { |
| 541 | PathName parent; |
| 542 | PathUtils::splitLastComponent(parent, tempPath, fileName); |
| 543 | PathUtils::concatPath(tempPath, parent, temp); |
| 544 | } |
| 545 | } |
| 546 | } |
| 547 | #endif |
| 548 | |
| 549 | PathName path, file; |
| 550 | PathUtils::splitLastComponent(path, file, tempPath); |
| 551 | to = path.ToString(); |
| 552 | } |
| 553 | else if (!substituteStandardDir(from, to)) |
| 554 | { |
| 555 | return false; |
| 556 | } |
| 557 | |
| 558 | return true; |
| 559 | } |
| 560 | |
| 561 | /****************************************************************************** |
| 562 | * |