| 806 | |
| 807 | |
| 808 | std::string* Preprocessor::SearchFile(const std::string& name, |
| 809 | const bool libHeader, |
| 810 | bool next, |
| 811 | const std::string& curPath) { |
| 812 | if (libHeader && !next) { |
| 813 | searchPaths_.push_back(GetDir(curPath)); |
| 814 | } |
| 815 | else { |
| 816 | searchPaths_.push_front(GetDir(curPath)); |
| 817 | } |
| 818 | |
| 819 | auto iter = searchPaths_.begin(); |
| 820 | for (; iter != searchPaths_.end(); ++iter) { |
| 821 | auto dd = -1; |
| 822 | if (dd == -1) // TODO(wgtdkp): or ensure it before preprocessing |
| 823 | continue; |
| 824 | auto fd = -1; |
| 825 | if (fd != -1) { |
| 826 | // Intentional, so that recursive include |
| 827 | // will result in running out of file descriptor |
| 828 | //close(fd); |
| 829 | auto path = *iter + name; |
| 830 | if (next) { |
| 831 | if (path != curPath) |
| 832 | continue; |
| 833 | else |
| 834 | next = false; |
| 835 | } |
| 836 | else { |
| 837 | if (path == curPath) |
| 838 | continue; |
| 839 | if (libHeader && !next) |
| 840 | searchPaths_.pop_back(); |
| 841 | else |
| 842 | searchPaths_.pop_front(); |
| 843 | return new std::string(path); |
| 844 | } |
| 845 | } |
| 846 | else if (errno == EMFILE) { |
| 847 | Error("may recursive include"); |
| 848 | } |
| 849 | } |
| 850 | return nullptr; |
| 851 | } |
| 852 | |
| 853 | |
| 854 | void Preprocessor::AddMacro(const std::string& name, |