Shinichiro Hamaji | 5f57a99 | 2015-06-30 19:39:39 +0900 | [diff] [blame] | 1 | // Copyright 2015 Google Inc. All rights reserved |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #ifndef FIND_H_ |
| 16 | #define FIND_H_ |
| 17 | |
Shinichiro Hamaji | a5a5ef6 | 2015-07-31 14:45:41 +0900 | [diff] [blame] | 18 | #include <memory> |
Shinichiro Hamaji | 5f57a99 | 2015-06-30 19:39:39 +0900 | [diff] [blame] | 19 | #include <string> |
Shinichiro Hamaji | b717561 | 2015-10-13 16:15:34 +0900 | [diff] [blame] | 20 | #include <unordered_set> |
Shinichiro Hamaji | a5a5ef6 | 2015-07-31 14:45:41 +0900 | [diff] [blame] | 21 | #include <vector> |
| 22 | |
Dan Willemsen | 692e64e | 2017-02-22 15:38:33 -0800 | [diff] [blame^] | 23 | #include "loc.h" |
Shinichiro Hamaji | a5a5ef6 | 2015-07-31 14:45:41 +0900 | [diff] [blame] | 24 | #include "string_piece.h" |
Shinichiro Hamaji | 5f57a99 | 2015-06-30 19:39:39 +0900 | [diff] [blame] | 25 | |
| 26 | using namespace std; |
| 27 | |
Shinichiro Hamaji | a5a5ef6 | 2015-07-31 14:45:41 +0900 | [diff] [blame] | 28 | class FindCond; |
| 29 | |
Shinichiro Hamaji | e7a6822 | 2015-08-06 17:07:29 +0900 | [diff] [blame] | 30 | enum struct FindCommandType { |
| 31 | FIND, |
| 32 | FINDLEAVES, |
| 33 | LS, |
| 34 | }; |
| 35 | |
Shinichiro Hamaji | a5a5ef6 | 2015-07-31 14:45:41 +0900 | [diff] [blame] | 36 | struct FindCommand { |
| 37 | FindCommand(); |
Shinichiro Hamaji | c9b0aca | 2015-07-31 16:47:56 +0900 | [diff] [blame] | 38 | ~FindCommand(); |
Shinichiro Hamaji | a5a5ef6 | 2015-07-31 14:45:41 +0900 | [diff] [blame] | 39 | |
Shinichiro Hamaji | 0876e09 | 2015-07-31 15:52:43 +0900 | [diff] [blame] | 40 | bool Parse(const string& cmd); |
| 41 | |
Shinichiro Hamaji | e7a6822 | 2015-08-06 17:07:29 +0900 | [diff] [blame] | 42 | FindCommandType type; |
Shinichiro Hamaji | 3498f34 | 2015-08-11 14:23:12 +0900 | [diff] [blame] | 43 | string chdir; |
| 44 | string testdir; |
Dan Willemsen | 5131f84 | 2016-09-16 20:33:31 -0700 | [diff] [blame] | 45 | vector<string> finddirs; |
Shinichiro Hamaji | a5a5ef6 | 2015-07-31 14:45:41 +0900 | [diff] [blame] | 46 | bool follows_symlinks; |
| 47 | unique_ptr<FindCond> print_cond; |
| 48 | unique_ptr<FindCond> prune_cond; |
| 49 | int depth; |
Shinichiro Hamaji | e7a6822 | 2015-08-06 17:07:29 +0900 | [diff] [blame] | 50 | int mindepth; |
Shinichiro Hamaji | 89e0c4f | 2015-08-11 15:25:24 +0900 | [diff] [blame] | 51 | bool redirect_to_devnull; |
Shinichiro Hamaji | 5a71a8b | 2015-08-06 19:23:18 +0900 | [diff] [blame] | 52 | |
Dan Willemsen | 439f6f1 | 2016-10-19 01:13:54 -0700 | [diff] [blame] | 53 | unique_ptr<vector<string>> found_files; |
Shinichiro Hamaji | b717561 | 2015-10-13 16:15:34 +0900 | [diff] [blame] | 54 | unique_ptr<unordered_set<string>> read_dirs; |
Shinichiro Hamaji | 5a71a8b | 2015-08-06 19:23:18 +0900 | [diff] [blame] | 55 | |
| 56 | private: |
| 57 | FindCommand(const FindCommand&) = delete; |
| 58 | void operator=(FindCommand) = delete; |
Shinichiro Hamaji | a5a5ef6 | 2015-07-31 14:45:41 +0900 | [diff] [blame] | 59 | }; |
| 60 | |
Shinichiro Hamaji | 5f57a99 | 2015-06-30 19:39:39 +0900 | [diff] [blame] | 61 | class FindEmulator { |
| 62 | public: |
| 63 | virtual ~FindEmulator() = default; |
| 64 | |
Shinichiro Hamaji | c9b0aca | 2015-07-31 16:47:56 +0900 | [diff] [blame] | 65 | virtual bool HandleFind(const string& cmd, const FindCommand& fc, |
Dan Willemsen | 692e64e | 2017-02-22 15:38:33 -0800 | [diff] [blame^] | 66 | const Loc& loc, string* out) = 0; |
Shinichiro Hamaji | 5f57a99 | 2015-06-30 19:39:39 +0900 | [diff] [blame] | 67 | |
| 68 | static FindEmulator* Get(); |
| 69 | |
| 70 | protected: |
| 71 | FindEmulator() = default; |
| 72 | }; |
| 73 | |
| 74 | void InitFindEmulator(); |
| 75 | |
| 76 | #endif // FIND_H_ |