1 /* 2 * Copyright (c) 1998-2007 Matthijs Hollemans 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 #ifndef GREPPER_H 6 #define GREPPER_H 7 8 #include <Messenger.h> 9 10 class FileIterator; 11 class Model; 12 13 // Executes "grep" in a background thread. 14 class Grepper { 15 public: 16 Grepper(const char* pattern, const Model* model, 17 const BHandler* target, 18 FileIterator* iterator); 19 virtual ~Grepper(); 20 21 bool IsValid() const; 22 23 void Start(); 24 void Cancel(); 25 26 private: 27 // Spawns the real grepper thread. 28 static int32 _SpawnThread(void* cookie); 29 30 // The thread function that does the actual grepping. 31 int32 _GrepperThread(); 32 33 // Remembers, and possibly escapes, the search pattern. 34 void _SetPattern(const char* source); 35 36 // Prepends all quotes, dollars and backslashes with at backslash 37 // to prevent the shell from misinterpreting them. 38 bool _EscapeSpecialChars(char* buffer, 39 ssize_t bufferSize); 40 private: 41 // The (escaped) search pattern. 42 char* fPattern; 43 44 // The settings from the model. 45 BMessenger fTarget; 46 bool fEscapeText : 1; 47 bool fCaseSensitive : 1; 48 uint32 fEncoding; 49 50 // The supplier of files to grep 51 FileIterator* fIterator; 52 53 // Our thread's ID. 54 thread_id fThreadId; 55 56 // Whether our thread must quit. 57 volatile bool fMustQuit; 58 }; 59 60 #endif // GREPPER_H 61