Home | History | Annotate | Download | only in kati
      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 
     18 #include <memory>
     19 #include <string>
     20 #include <unordered_set>
     21 #include <vector>
     22 
     23 #include "loc.h"
     24 #include "string_piece.h"
     25 
     26 using namespace std;
     27 
     28 class FindCond;
     29 
     30 enum struct FindCommandType {
     31   FIND,
     32   FINDLEAVES,
     33   LS,
     34 };
     35 
     36 struct FindCommand {
     37   FindCommand();
     38   ~FindCommand();
     39 
     40   bool Parse(const string& cmd);
     41 
     42   FindCommandType type;
     43   string chdir;
     44   string testdir;
     45   vector<string> finddirs;
     46   bool follows_symlinks;
     47   unique_ptr<FindCond> print_cond;
     48   unique_ptr<FindCond> prune_cond;
     49   int depth;
     50   int mindepth;
     51   bool redirect_to_devnull;
     52 
     53   unique_ptr<vector<string>> found_files;
     54   unique_ptr<unordered_set<string>> read_dirs;
     55 
     56  private:
     57   FindCommand(const FindCommand&) = delete;
     58   void operator=(FindCommand) = delete;
     59 };
     60 
     61 class FindEmulator {
     62  public:
     63   virtual ~FindEmulator() = default;
     64 
     65   virtual bool HandleFind(const string& cmd, const FindCommand& fc,
     66                           const Loc& loc, string* out) = 0;
     67 
     68   static FindEmulator* Get();
     69 
     70  protected:
     71   FindEmulator() = default;
     72 };
     73 
     74 void InitFindEmulator();
     75 
     76 #endif  // FIND_H_
     77