Browse Subversion Repository
Contents of /common/SearchFilePath.cpp
Parent Directory
| Revision Log
Revision 379 -
( show annotations)
( download)
( as text)
Mon Apr 19 19:53:12 2010 UTC
(14 years, 1 month ago)
by satofumi
File MIME type: text/x-c++src
File size: 1091 byte(s)
コンパイルエラーを修正
| 1 |
/*! |
| 2 |
\file |
| 3 |
\brief ファイルのパス探索 |
| 4 |
|
| 5 |
\author Satofumi KAMIMURA |
| 6 |
|
| 7 |
$Id$ |
| 8 |
*/ |
| 9 |
|
| 10 |
#include "SearchFilePath.h" |
| 11 |
#include "ExistFile.h" |
| 12 |
#include <cstdlib> |
| 13 |
#include <cstring> |
| 14 |
|
| 15 |
using namespace beego; |
| 16 |
|
| 17 |
|
| 18 |
bool beego::searchFilePath(std::string& full_path, const char* fname, |
| 19 |
const std::vector<std::string>& dir_path) { |
| 20 |
|
| 21 |
// ファイルの存在を順に確認する |
| 22 |
std::vector<std::string> search_dir = dir_path; |
| 23 |
if (search_dir.empty()) { |
| 24 |
search_dir.push_back("."); |
| 25 |
} |
| 26 |
for (std::vector<std::string>::const_iterator it = search_dir.begin(); |
| 27 |
it != search_dir.end(); ++it) { |
| 28 |
|
| 29 |
// "~/" を環境変数 HOME の内容に置換する |
| 30 |
std::string replaced = *it; |
| 31 |
|
| 32 |
size_t match_index = it->find("~/"); |
| 33 |
if (match_index != std::string::npos) { |
| 34 |
const char* home = getenv("HOME"); |
| 35 |
if (home != NULL) { |
| 36 |
size_t n = strlen(home); |
| 37 |
replaced.replace(match_index, 1, home, n); |
| 38 |
} |
| 39 |
} |
| 40 |
std::string try_path = replaced + "/" + fname; |
| 41 |
if (existFile(try_path.c_str())) { |
| 42 |
full_path = try_path; |
| 43 |
return true; |
| 44 |
} |
| 45 |
} |
| 46 |
return false; |
| 47 |
} |
|