blob: 8cf36741af7f5850fec771ce6e2c9ea2e7817816 [file] [log] [blame]
Shinichiro Hamaji5f57a992015-06-30 19:39:39 +09001// 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 Hamajia5a5ef62015-07-31 14:45:41 +090018#include <memory>
Shinichiro Hamaji5f57a992015-06-30 19:39:39 +090019#include <string>
Shinichiro Hamajib7175612015-10-13 16:15:34 +090020#include <unordered_set>
Shinichiro Hamajia5a5ef62015-07-31 14:45:41 +090021#include <vector>
22
Dan Willemsen692e64e2017-02-22 15:38:33 -080023#include "loc.h"
Shinichiro Hamajia5a5ef62015-07-31 14:45:41 +090024#include "string_piece.h"
Shinichiro Hamaji5f57a992015-06-30 19:39:39 +090025
26using namespace std;
27
Shinichiro Hamajia5a5ef62015-07-31 14:45:41 +090028class FindCond;
29
Shinichiro Hamajie7a68222015-08-06 17:07:29 +090030enum struct FindCommandType {
31 FIND,
32 FINDLEAVES,
33 LS,
34};
35
Shinichiro Hamajia5a5ef62015-07-31 14:45:41 +090036struct FindCommand {
37 FindCommand();
Shinichiro Hamajic9b0aca2015-07-31 16:47:56 +090038 ~FindCommand();
Shinichiro Hamajia5a5ef62015-07-31 14:45:41 +090039
Shinichiro Hamaji0876e092015-07-31 15:52:43 +090040 bool Parse(const string& cmd);
41
Shinichiro Hamajie7a68222015-08-06 17:07:29 +090042 FindCommandType type;
Shinichiro Hamaji3498f342015-08-11 14:23:12 +090043 string chdir;
44 string testdir;
Dan Willemsen5131f842016-09-16 20:33:31 -070045 vector<string> finddirs;
Shinichiro Hamajia5a5ef62015-07-31 14:45:41 +090046 bool follows_symlinks;
47 unique_ptr<FindCond> print_cond;
48 unique_ptr<FindCond> prune_cond;
49 int depth;
Shinichiro Hamajie7a68222015-08-06 17:07:29 +090050 int mindepth;
Shinichiro Hamaji89e0c4f2015-08-11 15:25:24 +090051 bool redirect_to_devnull;
Shinichiro Hamaji5a71a8b2015-08-06 19:23:18 +090052
Dan Willemsen439f6f12016-10-19 01:13:54 -070053 unique_ptr<vector<string>> found_files;
Shinichiro Hamajib7175612015-10-13 16:15:34 +090054 unique_ptr<unordered_set<string>> read_dirs;
Shinichiro Hamaji5a71a8b2015-08-06 19:23:18 +090055
56 private:
57 FindCommand(const FindCommand&) = delete;
58 void operator=(FindCommand) = delete;
Shinichiro Hamajia5a5ef62015-07-31 14:45:41 +090059};
60
Shinichiro Hamaji5f57a992015-06-30 19:39:39 +090061class FindEmulator {
62 public:
63 virtual ~FindEmulator() = default;
64
Dan Willemsen3ce083f2017-10-11 22:17:48 -070065 virtual bool HandleFind(const string& cmd,
66 const FindCommand& fc,
67 const Loc& loc,
68 string* out) = 0;
Shinichiro Hamaji5f57a992015-06-30 19:39:39 +090069
70 static FindEmulator* Get();
71
72 protected:
73 FindEmulator() = default;
74};
75
76void InitFindEmulator();
77
78#endif // FIND_H_