BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / text_search / Grepper.h
blobad977810eaa0eefd3cec19eb2ad536bed0c37b92
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
8 #include <Messenger.h>
10 class FileIterator;
11 class Model;
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();
21 bool IsValid() const;
23 void Start();
24 void Cancel();
26 private:
27 // Spawns the real grepper threads.
28 static int32 _SpawnRunnerThread(void* cookie);
29 static int32 _SpawnWriterThread(void* cookie);
31 // The threads functions that does the actual grepping.
32 int32 _RunnerThread();
33 int32 _WriterThread();
35 // Remembers, and possibly escapes, the search pattern.
36 void _SetPattern(const char* source);
38 // Prepends all quotes, dollars and backslashes with at backslash
39 // to prevent the shell from misinterpreting them.
40 bool _EscapeSpecialChars(char* buffer,
41 ssize_t bufferSize);
43 private:
44 // The (escaped) search pattern.
45 char* fPattern;
47 // The settings from the model.
48 BMessenger fTarget;
49 bool fRegularExpression : 1;
50 bool fCaseSensitive : 1;
51 uint32 fEncoding;
53 // The supplier of files to grep
54 FileIterator* fIterator;
56 // Our thread's ID.
57 thread_id fRunnerThreadId;
58 // xargs input pipe
59 int fXargsInput;
61 // Whether our thread must quit.
62 volatile bool fMustQuit;
65 #endif // GREPPER_H